KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > daemon > ApplicationInfo


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.daemon;
6
7 import java.util.Iterator JavaDoc;
8 import java.util.Set JavaDoc;
9 import java.util.LinkedHashSet JavaDoc;
10 import java.io.Serializable JavaDoc;
11 import java.io.ObjectInputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.InvalidObjectException JavaDoc;
14
15 import ve.luz.ica.jackass.deploy.daemon.NodeDeployer;
16
17 /**
18  * Contains Application related information. The information consists
19  * of a list of NodeDeployes and a list of name server entries of application
20  * components.
21  * @author Guido Urdaneta
22  */

23 public final class ApplicationInfo implements Serializable JavaDoc
24 {
25     private static final String JavaDoc ERR_NULL_VAR = "Invalid NULL instance variable";
26     private static final String JavaDoc ERR_NULL_ENTRY = "Invalid NULL entry";
27     private Set JavaDoc nodeDeployers;
28     private Set JavaDoc componentNSNames;
29
30     /**
31      * Creates an empty ApplicationInfo.
32      */

33     public ApplicationInfo()
34     {
35         nodeDeployers = new LinkedHashSet JavaDoc();
36         componentNSNames = new LinkedHashSet JavaDoc();
37     }
38
39     /**
40      * Adds a NodeDeployer to the application.
41      * @param nd the NodeDeployer
42      */

43     public void addNodeDeployer(NodeDeployer nd)
44     {
45         nodeDeployers.add(nd);
46     }
47
48     /**
49      * Adds a String with the Name Service entry of a component.
50      * @param name the NameService entry
51      */

52     public void addComponentNSName(String JavaDoc name)
53     {
54         componentNSNames.add(name);
55     }
56
57     /**
58      * Removes a NodeDeployer from the application. Do NOT use this
59      * method if you are iterating. In the latter case use Iterator.remove()
60      * @param nd the NodeDeployer to remove
61      */

62     public void removeNodeDeployer(NodeDeployer nd)
63     {
64         nodeDeployers.remove(nd);
65     }
66
67     /**
68      * Returns an iterator over the NodeDeployers associated to this application.
69      * @return the iterator
70      * @see NodeDeployer
71      */

72     public Iterator JavaDoc nodeDeployerIterator()
73     {
74         return nodeDeployers.iterator();
75     }
76
77     /**
78      * Returns an iterator over Strings with the name service
79      * entries of the components of the application
80      * @return the iterator
81      */

82     public Iterator JavaDoc componentNSNamesIterator()
83     {
84         return componentNSNames.iterator();
85     }
86
87     /**
88      * Verifies the validity of an instance when it is being deserialized.
89      * @param s the input stream
90      * @throws java.io.InvalidObjectException when the deserialized object is invalid
91      * @throws java.io.IOException when an IO error occurs
92      * @throws ClassNotFoundException when an unexpected error occurs
93      */

94     private void readObject(ObjectInputStream JavaDoc s) throws IOException JavaDoc, ClassNotFoundException JavaDoc
95     {
96         s.defaultReadObject();
97
98         if (this.nodeDeployers == null || this.componentNSNames == null)
99         {
100             throw new InvalidObjectException JavaDoc(ERR_NULL_VAR);
101         }
102
103         for (Iterator JavaDoc i = nodeDeployers.iterator(); i.hasNext();)
104         {
105             NodeDeployer nd = (NodeDeployer) i.next();
106             if (nd == null)
107             {
108                 throw new InvalidObjectException JavaDoc(ERR_NULL_ENTRY);
109             }
110         }
111
112         for (Iterator JavaDoc i = componentNSNames.iterator(); i.hasNext();)
113         {
114             String JavaDoc nsn = (String JavaDoc) i.next();
115             if (nsn == null)
116             {
117                 throw new InvalidObjectException JavaDoc(ERR_NULL_ENTRY);
118             }
119         }
120     }
121 }
122
Popular Tags