KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > tools > mocks > MockParameter


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2006 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.tools.mocks;
20
21 import java.net.URL JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.LinkedList JavaDoc;
27
28 import org.java.plugin.PathResolver;
29 import org.java.plugin.registry.Extension;
30 import org.java.plugin.registry.ExtensionPoint;
31 import org.java.plugin.registry.PluginDescriptor;
32 import org.java.plugin.registry.Extension.Parameter;
33 import org.java.plugin.registry.ExtensionPoint.ParameterDefinition;
34
35 /**
36  * @version $Id: MockParameter.java,v 1.3 2006/09/14 18:15:45 ddimon Exp $
37  */

38 public class MockParameter extends MockPluginElement implements Parameter {
39     private Extension declaringExtension;
40     private ParameterDefinition definition;
41     private Parameter superParameter;
42     private String JavaDoc rawValue;
43     private Object JavaDoc typedValue;
44     private LinkedList JavaDoc subParameters = new LinkedList JavaDoc();
45     
46     /**
47      * No-arguments constructor.
48      */

49     public MockParameter() {
50         // no-op
51
}
52
53     /**
54      * @param id parameter ID
55      * @param aRawValue raw parameter value
56      * @param aTypedValue typed parameter value
57      */

58     public MockParameter(final String JavaDoc id, final String JavaDoc aRawValue,
59             final Object JavaDoc aTypedValue) {
60         setId(id);
61         rawValue = aRawValue;
62         typedValue = aTypedValue;
63     }
64
65     /**
66      * @param id parameter ID
67      * @param aRawValue raw parameter value
68      * @param aTypedValue typed parameter value
69      * @param aDeclaringExtension declaring extension
70      */

71     public MockParameter(final String JavaDoc id, final String JavaDoc aRawValue,
72             final Object JavaDoc aTypedValue, final Extension aDeclaringExtension) {
73         setId(id);
74         rawValue = aRawValue;
75         typedValue = aTypedValue;
76         declaringExtension = aDeclaringExtension;
77     }
78
79     /**
80      * @see org.java.plugin.registry.Extension.Parameter#getDeclaringExtension()
81      */

82     public Extension getDeclaringExtension() {
83         return declaringExtension;
84     }
85     
86     /**
87      * @param value the declaring extension to set
88      * @return this instance
89      */

90     public MockParameter setDeclaringExtension(final Extension value) {
91         declaringExtension = value;
92         return this;
93     }
94
95     /**
96      * @see org.java.plugin.registry.Extension.Parameter#getDefinition()
97      */

98     public ParameterDefinition getDefinition() {
99         return definition;
100     }
101     
102     /**
103      * @param value the parameter definition to set
104      * @return this instance
105      */

106     public MockParameter setDefinition(final ParameterDefinition value) {
107         definition = value;
108         return this;
109     }
110
111     /**
112      * @see org.java.plugin.registry.Extension.Parameter#getSubParameter(
113      * java.lang.String)
114      */

115     public Parameter getSubParameter(final String JavaDoc id) {
116         for (Iterator JavaDoc it = subParameters.iterator(); it.hasNext();) {
117             Parameter param = (Parameter) it.next();
118             if (param.getId().equals(id)) {
119                 return param;
120             }
121         }
122         throw new IllegalArgumentException JavaDoc("unknown parameter ID " + id); //$NON-NLS-1$
123
}
124
125     /**
126      * @see org.java.plugin.registry.Extension.Parameter#getSubParameters()
127      */

128     public Collection JavaDoc getSubParameters() {
129         return Collections.unmodifiableCollection(subParameters);
130     }
131
132     /**
133      * @see org.java.plugin.registry.Extension.Parameter#getSubParameters(
134      * java.lang.String)
135      */

136     public Collection JavaDoc getSubParameters(final String JavaDoc id) {
137         LinkedList JavaDoc result = new LinkedList JavaDoc();
138         for (Iterator JavaDoc it = subParameters.iterator(); it.hasNext();) {
139             Parameter param = (Parameter) it.next();
140             if (param.getId().equals(id)) {
141                 result.add(param);
142             }
143         }
144         return result;
145     }
146     
147     /**
148      * @param parameter sub-parameter to add
149      * @return this instance
150      */

151     public MockParameter addParameter(final Parameter parameter) {
152         subParameters.add(parameter);
153         return this;
154     }
155
156     /**
157      * @see org.java.plugin.registry.Extension.Parameter#getSuperParameter()
158      */

159     public Parameter getSuperParameter() {
160         return superParameter;
161     }
162     
163     /**
164      * @param value the super parameter to set
165      * @return this instance
166      */

167     public MockParameter setSuperParameter(final Parameter value) {
168         superParameter = value;
169         return this;
170     }
171
172     /**
173      * @see org.java.plugin.registry.Extension.Parameter#rawValue()
174      */

175     public String JavaDoc rawValue() {
176         return rawValue;
177     }
178     
179     /**
180      * @param raw raw parameter value
181      * @param typed typed parameter value
182      * @return this instance
183      */

184     public MockParameter setValue(final String JavaDoc raw, final Object JavaDoc typed) {
185         rawValue = raw;
186         typedValue = typed;
187         return this;
188     }
189
190     /**
191      * @see org.java.plugin.registry.Extension.Parameter#valueAsBoolean()
192      */

193     public Boolean JavaDoc valueAsBoolean() {
194         return (Boolean JavaDoc) typedValue;
195     }
196
197     /**
198      * @see org.java.plugin.registry.Extension.Parameter#valueAsDate()
199      */

200     public Date JavaDoc valueAsDate() {
201         return (Date JavaDoc) typedValue;
202     }
203
204     /**
205      * @see org.java.plugin.registry.Extension.Parameter#valueAsExtension()
206      */

207     public Extension valueAsExtension() {
208         return (Extension) typedValue;
209     }
210
211     /**
212      * @see org.java.plugin.registry.Extension.Parameter#valueAsExtensionPoint()
213      */

214     public ExtensionPoint valueAsExtensionPoint() {
215         return (ExtensionPoint) typedValue;
216     }
217
218     /**
219      * @see org.java.plugin.registry.Extension.Parameter#valueAsNumber()
220      */

221     public Number JavaDoc valueAsNumber() {
222         return (Number JavaDoc) typedValue;
223     }
224
225     /**
226      * @see org.java.plugin.registry.Extension.Parameter#valueAsPluginDescriptor()
227      */

228     public PluginDescriptor valueAsPluginDescriptor() {
229         return (PluginDescriptor) typedValue;
230     }
231
232     /**
233      * @see org.java.plugin.registry.Extension.Parameter#valueAsString()
234      */

235     public String JavaDoc valueAsString() {
236         return (String JavaDoc) typedValue;
237     }
238
239     /**
240      * @see org.java.plugin.registry.Extension.Parameter#valueAsUrl()
241      */

242     public URL JavaDoc valueAsUrl() {
243         return (URL JavaDoc) typedValue;
244     }
245
246     /**
247      * @see org.java.plugin.registry.Extension.Parameter#valueAsUrl(
248      * org.java.plugin.PathResolver)
249      */

250     public URL JavaDoc valueAsUrl(final PathResolver pathResolver) {
251         return (URL JavaDoc) typedValue;
252     }
253 }
254
Popular Tags