KickJava   Java API By Example, From Geeks To Geeks.

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


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ 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.simpleSslWeb;
25
26 import java.awt.*;
27 import java.awt.event.*;
28
29 // TODO: don't be lazy and use swing
30

31 public class Client extends java.applet.Applet JavaDoc implements Runnable JavaDoc, ActionListener
32 {
33     //public static int PORT = 80;
34
public static int PORT = 443;
35     public static String JavaDoc USERNAME = "admin";
36     public static String JavaDoc PASSWORD = "admin";
37
38     private Thread JavaDoc m_thread;
39     private Button m_addButton;
40     private TextArea m_textArea;
41
42     private synchronized void waitForAddPersonRequest()
43     {
44     try
45         {
46             wait();
47         }
48         catch (InterruptedException JavaDoc e)
49         {
50         }
51     }
52
53     private synchronized void addPersonNotify()
54     {
55     notify();
56     }
57
58     public void init()
59     {
60     m_textArea = new TextArea(60, 60);
61     m_textArea.setEditable(false);
62
63     m_addButton = new Button("Add Person");
64     m_addButton.addActionListener(this);
65
66         setLayout(new BorderLayout());
67
68     add("Center", m_textArea);
69     add("South", m_addButton);
70     }
71
72     public void run()
73     {
74         try
75         {
76             //org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myooweb://" + getCodeBase().getHost() + ":" + PORT, USERNAME, PASSWORD);
77
org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoowebs://" + getCodeBase().getHost() + ":" + PORT, USERNAME, PASSWORD);
78
79             org.myoodb.collectable.LinkedList root = (org.myoodb.collectable.LinkedList) db.getRoot("Persons");
80
81             if (root == null)
82             {
83                 root = (org.myoodb.collectable.LinkedList) db.createRoot(org.myoodb.collectable.LinkedListDbImpl.class, "Persons");
84                 //root = (org.myoodb.collectable.LinkedList) db.createRoot("org.myoodb.collectable.LinkedListDbImpl", "Persons");
85
}
86
87             while (m_thread != null)
88             {
89                 waitForAddPersonRequest();
90
91                 org.myoodb.simple.Person person = (org.myoodb.simple.Person) db.createObject(org.myoodb.simple.PersonDbImpl.class);
92                 //org.myoodb.simple.Person person = (org.myoodb.simple.Person) db.createObject("org.myoodb.simple.PersonDbImpl");
93
person.setName("John Smith the " + root.size());
94
95                 root.add(person);
96
97                 System.out.println("New persons in database: " + person);
98             m_textArea.append("New persons in database: " + person + "\n");
99
100                 java.util.Iterator JavaDoc iter = root.toArrayList().iterator();
101                 while (iter.hasNext())
102                 {
103                     person = (org.myoodb.simple.Person) iter.next();
104
105                     long start = System.currentTimeMillis();
106                     String JavaDoc name = person.getName();
107                     long stop = System.currentTimeMillis();
108
109                     System.out.println(" - Existing persons in database: " + name + " / getTime:" + (stop-start));
110                     m_textArea.append(" - Existing persons in database: " + name + " / getTime: " + (stop-start) + "\n");
111                 }
112             }
113         }
114         catch (Exception JavaDoc e)
115         {
116             e.printStackTrace();
117         }
118     }
119
120     public void start()
121     {
122         if (m_thread == null)
123         {
124             m_thread = new Thread JavaDoc(this);
125             m_thread.setDaemon(true);
126             m_thread.start();
127         }
128     }
129
130     public void stop()
131     {
132         if (m_thread != null)
133         {
134             m_thread = null;
135             addPersonNotify();
136         }
137     }
138
139     public void actionPerformed(ActionEvent evt)
140     {
141         addPersonNotify();
142     }
143 }
144
Popular Tags