KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjoram > admin > AdministeredObject


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): Nicolas Tachker (ScalAgent)
23  */

24 package com.scalagent.kjoram.admin;
25
26 import java.util.Hashtable JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 /**
30  * The <code>AdministeredObject</code> class is the parent class of all
31  * JORAM administered objects.
32  */

33 public abstract class AdministeredObject
34 {
35   /**
36    * Class table holding the <code>AdministeredObject</code> instances.
37    * <p>
38    * <b>Key:</b> object's identifier<br>
39    * <b>Object:</b> object's instance
40    */

41   protected static Hashtable JavaDoc instancesTable = new Hashtable JavaDoc();
42
43   /** Identifier of the object. */
44   protected String JavaDoc id;
45
46
47   /**
48    * Constructs an administered object.
49    *
50    * @param id Identifier of the object.
51    */

52   protected AdministeredObject(String JavaDoc id)
53   {
54     this.id = this.getClass().getName() + ":" + id;
55
56     // Registering this instance in the table:
57
instancesTable.put(this.id, this);
58   }
59
60   /**
61    * Constructs an empty administered object.
62    */

63   protected AdministeredObject()
64   {}
65
66   /** Retrieves an instance from the table. */
67   public static Object JavaDoc getInstance(String JavaDoc name)
68   {
69     if (name == null)
70       return null;
71     return instancesTable.get(name);
72   }
73
74   public void setId(String JavaDoc id) {
75     this.id = id;
76   }
77
78   public String JavaDoc getId() {
79     return id;
80   }
81
82   public void addInstanceTable(String JavaDoc key, Object JavaDoc value) {
83     instancesTable.put(key,value);
84   }
85
86   /**
87    * Codes a <code>AdministeredObject</code> as a Hashtable for travelling
88    * through the SOAP protocol.
89    */

90   public Hashtable JavaDoc code() {
91     Hashtable JavaDoc h = new Hashtable JavaDoc();
92     String JavaDoc className = this.getClass().getName();
93     String JavaDoc end = className.substring(
94       className.lastIndexOf((int)'.'),
95       className.length());
96
97     if (className.startsWith("com.scalagent.kjoram.admin")) {
98       className = "org.objectweb.joram.client.jms.admin";
99     } else if (className.startsWith("com.scalagent.kjoram.excepts")) {
100       className = "org.objectweb.joram.shared.excepts";
101     } else if (className.startsWith("com.scalagent.kjoram.jms")) {
102       className = "org.objectweb.joram.shared.client";
103     } else if (className.startsWith("com.scalagent.kjoram.ksoap")) {
104       className = "org.objectweb.joram.client.jms.ksoap";
105     } else if (className.startsWith("com.scalagent.kjoram.messages")) {
106       className = "org.objectweb.joram.shared.messages";
107     } else if (className.startsWith("com.scalagent.kjoram")) {
108       className = "org.objectweb.joram.client.jms";
109     }
110     className = className + end;
111     h.put("className",className);
112     return h;
113   }
114 }
115
Popular Tags