KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jegg > impl > EggInfo


1 /*
2  * Copyright (c) 2004, Bruce Lowery
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * - Neither the name of GOSSIP nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without
15  * specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */

29 package jegg.impl;
30
31 import java.util.Collection JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Properties JavaDoc;
34
35
36 /**
37  *
38  *
39  * @author Bruce Lowery
40  */

41 class EggInfo
42 {
43     private final String JavaDoc _dispatcherName;
44     private final String JavaDoc _eggName;
45     private final String JavaDoc _handlerClass;
46     private final boolean _bindEarly;
47     
48     private EggShell _egg;
49     private boolean _resolved = false;
50     
51     private Collection JavaDoc _uses;
52     
53     private Properties JavaDoc _properties;
54     
55     EggInfo(final String JavaDoc eggName, final String JavaDoc handlerClass, final String JavaDoc dispatcherName, final boolean early)
56     {
57         super();
58         _eggName = eggName;
59         _handlerClass = handlerClass;
60         _dispatcherName = dispatcherName;
61         _bindEarly = early;
62     }
63     
64     EggInfo(EggInfo info)
65     {
66         this(info.getEggName(), info.getHandlerClassName(), info.getDispatcherName(), info.shouldBindEarly());
67         _resolved = info.isResolved();
68         _egg = info.getEgg();
69     }
70     
71     String JavaDoc getDispatcherName() {return _dispatcherName; }
72     String JavaDoc getEggName() { return _eggName; }
73     String JavaDoc getHandlerClassName() { return _handlerClass; }
74     
75     synchronized void addDependency(String JavaDoc n)
76     {
77         if ( null == _uses ) { _uses = new HashSet JavaDoc(); }
78         _uses.add(n);
79     }
80     synchronized String JavaDoc[] getDependencies()
81     {
82         if (null == _uses)
83             return new String JavaDoc[0];
84         else
85             return (String JavaDoc[]) _uses.toArray(new String JavaDoc[_uses.size()]);
86     }
87     
88     synchronized void addProperty(final String JavaDoc name, final String JavaDoc value)
89     {
90         if (null == _properties) {_properties = new Properties JavaDoc();}
91         _properties.put(name,value);
92     }
93     
94     synchronized Properties JavaDoc getProperties() {return _properties;}
95     
96     boolean shouldBindEarly()
97     {
98         return _bindEarly;
99     }
100     
101     synchronized void setEgg(EggShell egg)
102     {
103         if (null != _egg)
104             throw new IllegalStateException JavaDoc("Egg already set for "+_eggName);
105         _egg = egg;
106     }
107     
108     synchronized EggShell getEgg() { return _egg; }
109     
110     synchronized void setResolved(final boolean b) { _resolved = b; }
111     synchronized boolean isResolved() { return _resolved; }
112     
113     public String JavaDoc toString()
114     {
115         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("EggInfo[");
116         if (null != _eggName)
117             buf.append(_eggName);
118         buf.append("]");
119         return buf.toString();
120     }
121 }
122
Popular Tags