KickJava   Java API By Example, From Geeks To Geeks.

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


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.PluginAttribute;
27
28 /**
29  * @version $Id: MockPluginAttribute.java,v 1.2 2006/09/14 18:10:39 ddimon Exp $
30  */

31 public class MockPluginAttribute extends MockPluginElement implements
32         PluginAttribute {
33     private LinkedList JavaDoc subAttributes = new LinkedList JavaDoc();
34     private PluginAttribute superAttribute;
35     private String JavaDoc value;
36     
37     /**
38      * No-arguments constructor.
39      */

40     public MockPluginAttribute() {
41         // no-op
42
}
43
44     /**
45      * @param id attribute ID
46      * @param aValue attribute value
47      */

48     public MockPluginAttribute(final String JavaDoc id, final String JavaDoc aValue) {
49         setId(id);
50         value = aValue;
51     }
52
53     /**
54      * @see org.java.plugin.registry.PluginAttribute#getSubAttribute(
55      * java.lang.String)
56      */

57     public PluginAttribute getSubAttribute(final String JavaDoc id) {
58         for (Iterator JavaDoc it = subAttributes.iterator(); it.hasNext();) {
59             PluginAttribute attr = (PluginAttribute) it.next();
60             if (attr.getId().equals(id)) {
61                 return attr;
62             }
63         }
64         throw new IllegalArgumentException JavaDoc("unknown attribute ID " + id); //$NON-NLS-1$
65
}
66
67     /**
68      * @see org.java.plugin.registry.PluginAttribute#getSubAttributes()
69      */

70     public Collection JavaDoc getSubAttributes() {
71         return Collections.unmodifiableCollection(subAttributes);
72     }
73
74     /**
75      * @see org.java.plugin.registry.PluginAttribute#getSubAttributes(
76      * java.lang.String)
77      */

78     public Collection JavaDoc getSubAttributes(final String JavaDoc id) {
79         LinkedList JavaDoc result = new LinkedList JavaDoc();
80         for (Iterator JavaDoc it = subAttributes.iterator(); it.hasNext();) {
81             PluginAttribute attr = (PluginAttribute) it.next();
82             if (attr.getId().equals(id)) {
83                 result.add(attr);
84             }
85         }
86         return result;
87     }
88     
89     /**
90      * @param attribute sub-attribute to add
91      * @return this instance
92      */

93     public MockPluginAttribute addSubAttribute(
94             final PluginAttribute attribute) {
95         subAttributes.add(attribute);
96         return this;
97     }
98
99     /**
100      * @see org.java.plugin.registry.PluginAttribute#getSuperAttribute()
101      */

102     public PluginAttribute getSuperAttribute() {
103         return superAttribute;
104     }
105     
106     /**
107      * @param attribute the super attribute to set
108      * @return this instance
109      */

110     public MockPluginAttribute setSuperAttribute(
111             final PluginAttribute attribute) {
112         superAttribute = attribute;
113         return this;
114     }
115
116     /**
117      * @see org.java.plugin.registry.PluginAttribute#getValue()
118      */

119     public String JavaDoc getValue() {
120         return value;
121     }
122     
123     /**
124      * @param attributeValue the attribute value to set
125      * @return this instance
126      */

127     public MockPluginAttribute setValue(final String JavaDoc attributeValue) {
128         value = attributeValue;
129         return this;
130     }
131 }
132
Popular Tags