KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > config > element > ConfigElementAdapter


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.config.element;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.alfresco.config.ConfigElement;
26
27 /**
28  * Adapter class for implementing ConfigElement's. Extend this class and
29  * provide the implementation specific behaviour.
30  *
31  * @author gavinc
32  */

33 public abstract class ConfigElementAdapter implements ConfigElement
34 {
35     protected String JavaDoc name;
36     protected String JavaDoc value;
37     protected Map JavaDoc<String JavaDoc, String JavaDoc> attributes;
38     protected List JavaDoc<ConfigElement> children;
39
40     /**
41      * Default constructor
42      *
43      * @param name Name of the config element
44      */

45     public ConfigElementAdapter(String JavaDoc name)
46     {
47         this.name = name;
48         this.attributes = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
49         this.children = new ArrayList JavaDoc<ConfigElement>();
50     }
51
52     /**
53      * @see org.alfresco.web.config.ConfigElement#getAttribute(java.lang.String)
54      */

55     public String JavaDoc getAttribute(String JavaDoc name)
56     {
57         return attributes.get(name);
58     }
59
60     /**
61      * @see org.alfresco.web.config.ConfigElement#getAttributes()
62      */

63     public Map JavaDoc<String JavaDoc, String JavaDoc> getAttributes()
64     {
65         return Collections.unmodifiableMap(this.attributes);
66     }
67     
68     /**
69      * @see org.alfresco.config.ConfigElement#getAttributeCount()
70      */

71     public int getAttributeCount()
72     {
73        return this.attributes.size();
74     }
75
76     /**
77      * @see org.alfresco.web.config.ConfigElement#getChildren()
78      */

79     public List JavaDoc<ConfigElement> getChildren()
80     {
81         return Collections.unmodifiableList(this.children);
82     }
83     
84     /**
85      * @see org.alfresco.config.ConfigElement#getChildCount()
86      */

87     public int getChildCount()
88     {
89        return this.children.size();
90     }
91
92     /**
93      * @see org.alfresco.config.ConfigElement#getChild(java.lang.String)
94      */

95     public ConfigElement getChild(String JavaDoc name)
96     {
97        ConfigElement child = null;
98        
99        if (hasChildren())
100        {
101           for (ConfigElement ce : this.children)
102           {
103              if (ce.getName().equals(name))
104              {
105                 child = ce;
106                 break;
107              }
108           }
109        }
110        
111        return child;
112     }
113     
114     /**
115      * @see org.alfresco.web.config.ConfigElement#getName()
116      */

117     public String JavaDoc getName()
118     {
119         return this.name;
120     }
121
122     /**
123      * @see org.alfresco.web.config.ConfigElement#getValue()
124      */

125     public String JavaDoc getValue()
126     {
127         return this.value;
128     }
129
130     /**
131      * Sets the value of this config element
132      *
133      * @param value
134      * The value to set.
135      */

136     public void setValue(String JavaDoc value)
137     {
138         this.value = value;
139     }
140
141     /**
142      * @see org.alfresco.web.config.ConfigElement#hasAttribute(java.lang.String)
143      */

144     public boolean hasAttribute(String JavaDoc name)
145     {
146         return attributes.containsKey(name);
147     }
148
149     /**
150      * @see org.alfresco.web.config.ConfigElement#hasChildren()
151      */

152     public boolean hasChildren()
153     {
154         return !children.isEmpty();
155     }
156
157     /**
158      * @see java.lang.Object#toString()
159      */

160     public String JavaDoc toString()
161     {
162         StringBuilder JavaDoc buffer = new StringBuilder JavaDoc(super.toString());
163         buffer.append(" (name=").append(this.name).append(")");
164         return buffer.toString();
165     }
166     
167     /**
168      * @see org.alfresco.web.config.ConfigElement#combine(org.alfresco.web.config.ConfigElement)
169      */

170     public abstract ConfigElement combine(ConfigElement configElement);
171 }
172
Popular Tags