KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedList JavaDoc;
25
26 import org.java.plugin.registry.Extension;
27 import org.java.plugin.registry.PluginDescriptor;
28
29 /**
30  * @version $Id: MockExtension.java,v 1.2 2006/09/14 18:10:39 ddimon Exp $
31  */

32 public class MockExtension extends MockPluginElement implements Extension {
33     private String JavaDoc extendedPluginId;
34     private String JavaDoc extendedPointId;
35     private boolean isValid = true;
36     private LinkedList JavaDoc parameters = new LinkedList JavaDoc();
37     
38     /**
39      * No-arguments constructor.
40      */

41     public MockExtension() {
42         // no-op
43
}
44
45     /**
46      * @param id extension ID
47      */

48     public MockExtension(final String JavaDoc id) {
49         setId(id);
50     }
51
52     /**
53      * @param id extension ID
54      * @param declaringPluginDescriptor declaring plug-in descriptor
55      */

56     public MockExtension(final String JavaDoc id,
57             final PluginDescriptor declaringPluginDescriptor) {
58         setDeclaringPluginDescriptor(declaringPluginDescriptor);
59         setId(id);
60     }
61
62     /**
63      * @see org.java.plugin.registry.Extension#getExtendedPluginId()
64      */

65     public String JavaDoc getExtendedPluginId() {
66         return extendedPluginId;
67     }
68     
69     /**
70      * @param value the extended plug-in id to set
71      * @return this instance
72      */

73     public MockExtension setExtendedPluginId(final String JavaDoc value) {
74         extendedPluginId = value;
75         return this;
76     }
77
78     /**
79      * @see org.java.plugin.registry.Extension#getExtendedPointId()
80      */

81     public String JavaDoc getExtendedPointId() {
82         return extendedPointId;
83     }
84     
85     /**
86      * @param value the extended point id to set
87      * @return this instance
88      */

89     public MockExtension setExtendedPointId(final String JavaDoc value) {
90         extendedPointId = value;
91         return this;
92     }
93
94     /**
95      * @see org.java.plugin.registry.Extension#getParameter(java.lang.String)
96      */

97     public Parameter getParameter(final String JavaDoc id) {
98         for (Iterator JavaDoc it = parameters.iterator(); it.hasNext();) {
99             Parameter param = (Parameter) it.next();
100             if (param.getId().equals(id)) {
101                 return param;
102             }
103         }
104         throw new IllegalArgumentException JavaDoc("unknown parameter ID " + id); //$NON-NLS-1$
105
}
106
107     /**
108      * @see org.java.plugin.registry.Extension#getParameters()
109      */

110     public Collection JavaDoc getParameters() {
111         return Collections.unmodifiableCollection(parameters);
112     }
113
114     /**
115      * @see org.java.plugin.registry.Extension#getParameters(java.lang.String)
116      */

117     public Collection JavaDoc getParameters(final String JavaDoc id) {
118         LinkedList JavaDoc result = new LinkedList JavaDoc();
119         for (Iterator JavaDoc it = parameters.iterator(); it.hasNext();) {
120             Parameter param = (Parameter) it.next();
121             if (param.getId().equals(id)) {
122                 result.add(param);
123             }
124         }
125         return result;
126     }
127     
128     /**
129      * @param parameter parameter to add
130      * @return this instance
131      */

132     public MockExtension addParameter(final Parameter parameter) {
133         parameters.add(parameter);
134         return this;
135     }
136
137     /**
138      * @see org.java.plugin.registry.Extension#isValid()
139      */

140     public boolean isValid() {
141         return isValid;
142     }
143     
144     /**
145      * @param value the valid flag to set
146      * @return this instance
147      */

148     public MockExtension setValid(final boolean value) {
149         isValid = value;
150         return this;
151     }
152
153     /**
154      * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
155      */

156     public String JavaDoc getUniqueId() {
157         return getDeclaringPluginDescriptor().getId() + '@' + getId();
158     }
159 }
160
Popular Tags