KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > binding > BaseContainer


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.binding;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24
25 /**
26  * <p>
27  * <code>{@link Container}</code> implements the
28  * <code>{@link org.enhydra.zeus.Binding}</code>
29  * interface and defines behavior for a binding that can contain other
30  * bindings (usually <code>{@link Property}</code> implementations). It
31  * is used to represent objects which have nested objects.
32  * </p><p>
33  * This base implementation of <code>Container</code> defines the common
34  * functionality for all <code>Container</code> implementations, removing
35  * a need for them to duplicate code for this functionality. All
36  * implementations of <code>Container</code> should extend this class
37  * rather than directly implementing the <code>Container</code> interface.
38  * </p>
39  *
40  * @author Brett McLaughlin
41  */

42 public abstract class BaseContainer extends BaseBinding implements Container {
43
44     /**
45      * The <code>{@link Property}</code> objects this
46      * <code>Container</code> holds.
47      */

48     protected List JavaDoc properties;
49     
50     /**
51      * <p>
52      * This will add a <code>{@link Property}</code> to
53      * the member variables of this <code>Container</code>.
54      * </p><p>
55      * It is important to note that this is simply an instance
56      * variable being added to (in most cases) a custom
57      * Java class definition. That variable/property
58      * doesn't have a value (although it might have a
59      * default value) until marshalling and unmarshalling
60      * occurs.
61      * </p>
62      *
63      * @param property <code>Property</code> to add.
64      */

65     public void addProperty(Property property) {
66         if (property == null) {
67             throw new IllegalArgumentException JavaDoc("A Container cannot have " +
68                 "null properties as children.");
69         }
70         
71         if (properties == null) {
72             properties = new LinkedList JavaDoc();
73         }
74         
75         properties.add(property);
76     }
77     
78     /**
79      * <p>
80      * This will remove a <code>{@link Property}</code>
81      * from this <code>Container</code>, given the
82      * property's name. If a successful removal occurs,
83      * the boolean value <code>true</code> is retruned.
84      * If no <code>Property<code> is found with the supplied
85      * Java name, the boolean value <code>false</code> is returned.
86      * </p>
87      *
88      * @param javaName <code>String</code> Java name of
89      * <code>Property</code> to remove.
90      * @return <code>boolean</code> - indicates whether
91      * the specified named <code>Property</code>
92      * was found and removed.
93      */

94     public boolean removeProperty(String JavaDoc javaName) {
95         if (properties == null) {
96             return false;
97         }
98         
99         for (Iterator JavaDoc i = properties.iterator(); i.hasNext(); ) {
100             Property property = (Property)i.next();
101             if (property.getJavaName().equals(javaName)) {
102                 i.remove();
103                 return true;
104             }
105         }
106         
107         return false;
108     }
109     
110     /**
111      * <p>
112      * This does a wholesale replacement of this binding's current
113      * properties, removing all current ones and replacing with the
114      * supplied <code>List</code> of new properties.
115      * </p>
116      *
117      * @param properties <code>List</code> of properties to use for this
118      * container.
119      */

120     public void setProperties(List JavaDoc properties) {
121         if (properties == null) {
122             throw new IllegalArgumentException JavaDoc("A Container cannot have a " +
123                 "null property set.");
124         }
125         
126         this.properties = properties;
127     }
128     
129     /**
130      * <p>
131      * This will return a list of all the
132      * <code>{@link Property}</code> objects that
133      * this <code>Container</code> has. If there are
134      * none, this will return an empty <code>List</code>.
135      * </p>
136      *
137      * @return <code>List</code> - properties for this
138      * <code>Container</code>.
139      */

140     public List JavaDoc getProperties() {
141         if (properties == null) {
142             return new LinkedList JavaDoc();
143         }
144         
145         return properties;
146     }
147     
148     /**
149      * <p>
150      * This will clear all the properties for this <code>Container</code>.
151      * </p>
152      */

153     public void clearProperties() {
154         if (properties != null) {
155             properties.clear();
156         }
157     }
158 }
159
Popular Tags