KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > profile > psml > PsmlConfigElement


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.om.profile.psml;
18
19 import java.util.Vector JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.jetspeed.om.profile.*;
23
24 /**
25  * Base simple bean-like implementation of the ConfigElement interface
26  * suitable for Castor XML serialization.
27  *
28  * @author <a HREF="mailto:raphael@apache.org">Raphaël Luta</a>
29  * @author <a HREF="mailto:taylor@apache.org">David Sean Taylor</a>
30  * @version $Id: PsmlConfigElement.java,v 1.6 2004/02/23 03:02:54 jford Exp $
31  */

32 public /*abstract*/ class PsmlConfigElement implements ConfigElement, java.io.Serializable JavaDoc
33 {
34
35     private String JavaDoc name = null;
36     
37     private Vector JavaDoc parameters = new Vector JavaDoc();
38
39
40     public PsmlConfigElement()
41     {}
42          
43     /** @see org.apache.jetspeed.om.registry.RegistryEntry#getName */
44     public String JavaDoc getName()
45     {
46         return this.name;
47     }
48                                 
49     /** @see org.apache.jetspeed.om.registry.RegistryEntry#setName */
50     public void setName( String JavaDoc name )
51     {
52         this.name = name;
53     }
54
55     /** @return the parameters */
56     public Vector JavaDoc getParameters()
57     {
58         return this.parameters;
59     }
60                                 
61     /** Sets the parameters for this element
62      * @param parameters
63      */

64     public void setParameters(Vector JavaDoc parameters)
65     {
66         this.parameters = parameters;
67     }
68
69     public String JavaDoc getParameterValue(String JavaDoc name)
70     {
71         if (parameters == null)
72             return null;
73
74         for (int ix=0; ix < parameters.size(); ix++)
75         {
76             Parameter param = (Parameter)parameters.elementAt(ix);
77             if (param.getName().equals(name))
78                 return param.getValue();
79         }
80         return null;
81    }
82
83     public Parameter getParameter(String JavaDoc name)
84     {
85         if (parameters == null)
86             return null;
87
88         for (int ix=0; ix < parameters.size(); ix++)
89         {
90             Parameter param = (Parameter)parameters.elementAt(ix);
91             if (param.getName().equals(name))
92                 return param;
93         }
94         return null;
95    }
96
97     public Iterator JavaDoc getParameterIterator()
98     {
99         return parameters.iterator();
100     }
101
102     public Parameter getParameter(int index)
103         throws java.lang.IndexOutOfBoundsException JavaDoc
104     {
105         //-- check bounds for index
106
if ((index < 0) || (index > parameters.size())) {
107             throw new IndexOutOfBoundsException JavaDoc();
108         }
109         
110         return (Parameter) parameters.elementAt(index);
111     } //-- Parameter getParameter(int)
112

113     public int getParameterCount()
114     {
115         return parameters.size();
116     } //-- int getParameterCount()
117

118     public void removeAllParameter()
119     {
120         parameters.removeAllElements();
121     } //-- void removeAllParameter()
122

123     public Parameter removeParameter(int index)
124     {
125         Object JavaDoc obj = parameters.elementAt(index);
126         parameters.removeElementAt(index);
127         return (Parameter) obj;
128     } //-- Parameter removeParameter(int)
129

130     public void setParameter(int index, Parameter vParameter)
131         throws java.lang.IndexOutOfBoundsException JavaDoc
132     {
133         //-- check bounds for index
134
if ((index < 0) || (index > parameters.size())) {
135             throw new IndexOutOfBoundsException JavaDoc();
136         }
137         parameters.setElementAt(vParameter, index);
138     } //-- void setParameter(int, Parameter)
139

140     public Parameter[] getParameter()
141     {
142         int size = parameters.size();
143         Parameter[] mArray = new Parameter[size];
144         for (int index = 0; index < size; index++) {
145             mArray[index] = (Parameter) parameters.elementAt(index);
146         }
147         return mArray;
148     } //-- Parameter[] getParameter()
149

150     public void addParameter(Parameter vParameter)
151         throws java.lang.IndexOutOfBoundsException JavaDoc
152     {
153         parameters.addElement(vParameter);
154     } //-- void addParameter(Parameter)
155

156     /**
157      * Create a clone of this object
158      */

159     public Object JavaDoc clone()
160         throws java.lang.CloneNotSupportedException JavaDoc
161     {
162         Object JavaDoc cloned = super.clone();
163
164         // clone the vector's Parameter contents
165
if (this.parameters != null)
166         {
167             ((PsmlConfigElement)cloned).parameters = new Vector JavaDoc(this.parameters.size());
168             Iterator JavaDoc it = this.parameters.iterator();
169             while (it.hasNext())
170             {
171                 ((PsmlConfigElement)cloned).parameters.add((Parameter) ((Parameter)it.next()).clone());
172             }
173         }
174         
175         return cloned;
176
177     } // clone
178

179 }
180
Popular Tags