001: /*
002: This file is part of BORG.
003:
004: BORG is free software; you can redistribute it and/or modify
005: it under the terms of the GNU General public final synchronized License as published by
006: the Free Software Foundation; either version 2 of the License, or
007: (at your option) any later version.
008:
009: BORG is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General public final synchronized License for more details.
013:
014: You should have received a copy of the GNU General public final synchronized License
015: along with BORG; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: Copyright 2003 by Mike Berger
019: */
020:
021: package net.sf.borg.model.db.remote;
022:
023: import java.util.Collection;
024:
025: import net.sf.borg.common.XTree;
026: import net.sf.borg.model.beans.Memo;
027: import net.sf.borg.model.db.MemoDB;
028:
029: class RemoteMemoDB implements MemoDB {
030: // BeanDB overrides
031: public final synchronized Collection getNames() throws Exception {
032: Collection col = (Collection) call("getNames", null);
033: return col;
034: }
035:
036: public final synchronized Collection readAll() throws Exception {
037: Collection col = (Collection) call("readAllMemos", null);
038: return col;
039: }
040:
041: public final synchronized Memo readMemo(String name)
042: throws Exception {
043: return (Memo) call("readMemo", name);
044: }
045:
046: public final synchronized Memo getMemoByPalmId(int id)
047: throws Exception {
048: return (Memo) call("getMemoByPalmId", new Integer(id));
049: }
050:
051: public final synchronized void addMemo(Memo m) throws Exception {
052: call("addMemo", new IRemoteProxy.ComposedObject(m, null));
053: }
054:
055: public final synchronized void updateMemo(Memo m) throws Exception {
056: call("updateMemo", new IRemoteProxy.ComposedObject(m, null));
057: }
058:
059: public final synchronized void delete(String name) throws Exception {
060: call("deleteMemo", name);
061: }
062:
063: public final synchronized void close() throws Exception {
064: // ignore this - we're sharing
065: }
066:
067: // protected //
068: protected Object call(String command, Object args) throws Exception {
069: IRemoteProxy.Parms parms = new IRemoteProxy.Parms(clsstr,
070: command, args, user);
071: XTree xmlParms = XmlObjectHelper.toXml(parms);
072: String xmlstr = xmlParms.toString();
073: // System.out.println(xmlstr);
074: RemoteProxyHome home = RemoteProxyHome.getInstance();
075: String result = home.getProxy(url).execute(xmlstr,
076: home.getProxyProvider());
077: // System.out.println("OutTrace - " + result);
078: // System.err.println("ErrTrace - " + result);
079: XTree xmlResult = XTree.readFromBuffer(result);
080: Object retval = XmlObjectHelper.fromXml(xmlResult);
081: if (retval instanceof Exception)
082: throw (Exception) retval;
083:
084: return retval;
085: }
086:
087: // package //
088: RemoteMemoDB(String url, String user) {
089: this .clsstr = "Memo";
090: this .url = url;
091: this .user = user;
092: }
093:
094: // private //
095:
096: private String clsstr;
097:
098: private String url;
099:
100: private String user;
101: }
|