01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-2005 by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
11: //
12: // This program is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // GNU General Public License and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.mi;
25:
26: import org.myoodb.objects.*;
27:
28: public class Client {
29: public static int PORT = 54321;
30: public static String USERNAME = "admin";
31: public static String PASSWORD = "admin";
32:
33: public static void main(String args[]) throws Exception {
34: org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open(
35: "tcp://localhost:" + PORT, USERNAME, PASSWORD);
36:
37: org.myoodb.collectable.LinkedList root = (org.myoodb.collectable.LinkedList) db
38: .getRoot("Gozillas");
39: if (root == null) {
40: root = (org.myoodb.collectable.LinkedList) db.createRoot(
41: "Gozillas",
42: "org.myoodb.collectable.LinkedListDbImpl");
43: //root = (org.myoodb.collectable.LinkedList) db.createRoot("Gozillas", org.myoodb.collectable.LinkedListDbImpl.class);
44: }
45:
46: //
47: // XXX: How to simulate multi-inhertance: ( object delegation )
48: //
49: // The first specified class is the primary. The second, third, etc. are delegated through the first.
50: // See GozillaDbImpl for details.
51: //
52:
53: Gozilla gozilla = (Gozilla) db
54: .createObject("org.myoodb.objects.GozillaDbImpl,org.myoodb.objects.FrogDbImpl");
55: //Gozilla gozilla = (Gozilla) db.createObject(new Class[] {GozillaDbImpl.class, FrogDbImpl.class});
56: if ((root.size() & 1) == 1) {
57: gozilla.setType(Gozilla.Type.BAD_MONSTER);
58: gozilla.setPoisonousFlag(true);
59: gozilla.setDangerousFlag(true);
60: } else {
61: gozilla.setType(Gozilla.Type.GOOD_MONSTER);
62: gozilla.setPoisonousFlag(false);
63: gozilla.setDangerousFlag(false);
64: }
65:
66: root.add(gozilla);
67:
68: System.out.println("New Gozilla:");
69: System.out.println(" Type of gozilla: " + gozilla.getType());
70: System.out.println(" Is poisonous: "
71: + gozilla.getPoisonousFlag());
72: System.out.println(" Is dangerous: "
73: + gozilla.getDangerousFlag());
74: System.out.println(" Eye Color of gozilla: "
75: + gozilla.getEyeColor());
76:
77: System.out.println("\nList Exiting Gozilla(s):");
78: java.util.Iterator iter = root.toArrayList().iterator();
79: while (iter.hasNext()) {
80: gozilla = (Gozilla) iter.next();
81:
82: System.out.println("Gozilla: " + gozilla.getType() + " "
83: + gozilla.getEyeColor());
84: }
85: }
86: }
|