KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > mi > Client


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-2005 by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// 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 public class Client
27 {
28     public static int PORT = 54321;
29     public static String JavaDoc USERNAME = "admin";
30     public static String JavaDoc PASSWORD = "admin";
31
32     public static void main(String JavaDoc args[]) throws Exception JavaDoc
33     {
34         org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoodb://localhost:" + PORT, USERNAME, PASSWORD);
35
36         org.myoodb.collectable.LinkedList root = (org.myoodb.collectable.LinkedList) db.getRoot("Gozillas");
37
38         if (root == null)
39         {
40             root = (org.myoodb.collectable.LinkedList) db.createRoot(org.myoodb.collectable.LinkedListDbImpl.class, "Gozillas");
41         }
42
43         //
44
// XXX: How to simulate multi-inhertance: ( object delegation )
45
//
46
// The first specified class is the primary. The second, third, etc. are delegated through the first.
47
// See GozillaDbImpl for details.
48
//
49

50         Gozilla gozilla = (Gozilla) db.createObject(new Class JavaDoc[] {org.myoodb.mi.GozillaDbImpl.class, org.myoodb.mi.FrogDbImpl.class});
51         //Gozilla gozilla = (Gozilla) db.createObject("org.myoodb.gozilla.GozillaDbImpl,org.myoodb.mi.FrogDbImpl");
52
if ((root.size() & 1) == 1)
53         {
54             gozilla.setType(Gozilla.Type.BAD_MONSTER);
55             gozilla.setPoisonousFlag(true);
56             gozilla.setDangerousFlag(true);
57         }
58         else
59         {
60             gozilla.setType(Gozilla.Type.GOOD_MONSTER);
61             gozilla.setPoisonousFlag(false);
62             gozilla.setDangerousFlag(false);
63         }
64
65         root.add(gozilla);
66
67         System.out.println("New Gozilla:");
68         System.out.println(" Type of gozilla: " + gozilla.getType());
69         System.out.println(" Is poisonous: " + gozilla.getPoisonousFlag());
70         System.out.println(" Is dangerous: " + gozilla.getDangerousFlag());
71         System.out.println(" Eye Color of gozilla: " + gozilla.getEyeColor());
72
73         System.out.println("\nList Exiting Gozilla(s):");
74         java.util.Iterator JavaDoc iter = root.toArrayList().iterator();
75         while (iter.hasNext())
76         {
77             gozilla = (Gozilla) iter.next();
78
79             System.out.println("Gozilla: " + gozilla.getType() + " " + gozilla.getEyeColor());
80         }
81     }
82 }
83
Popular Tags