KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > registry > xml > PluginAttributeImpl


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-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.registry.xml;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.java.plugin.registry.Identity;
29 import org.java.plugin.registry.ManifestProcessingException;
30 import org.java.plugin.registry.PluginAttribute;
31
32 /**
33  * @version $Id: PluginAttributeImpl.java,v 1.3 2006/06/05 18:16:43 ddimon Exp $
34  */

35 class PluginAttributeImpl extends PluginElementImpl implements PluginAttribute {
36     private final PluginAttributeImpl superAttribute;
37     private final ModelAttribute model;
38     private List JavaDoc subAttributes;
39
40     PluginAttributeImpl(final PluginDescriptorImpl descr,
41             final PluginFragmentImpl aFragment, final ModelAttribute aModel,
42             final PluginAttributeImpl aSuperAttribute)
43             throws ManifestProcessingException {
44         super(descr, aFragment, aModel.getId(), aModel.getDocumentation());
45         model = aModel;
46         superAttribute = aSuperAttribute;
47         if (model.getValue() == null) {
48             model.setValue(""); //$NON-NLS-1$
49
}
50         subAttributes = new ArrayList JavaDoc(model.getAttributes().size());
51         for (Iterator JavaDoc it = model.getAttributes().iterator(); it.hasNext();) {
52             subAttributes.add(new PluginAttributeImpl(descr, aFragment,
53                     (ModelAttribute) it.next(), this));
54         }
55         subAttributes = Collections.unmodifiableList(subAttributes);
56         if (log.isDebugEnabled()) {
57             log.debug("object instantiated: " + this); //$NON-NLS-1$
58
}
59     }
60
61     /**
62      * @see org.java.plugin.registry.PluginAttribute#getSubAttribute(java.lang.String)
63      */

64     public PluginAttribute getSubAttribute(final String JavaDoc id) {
65         PluginAttributeImpl result = null;
66         for (Iterator JavaDoc it = subAttributes.iterator(); it.hasNext();) {
67             PluginAttributeImpl param = (PluginAttributeImpl) it.next();
68             if (param.getId().equals(id)) {
69                 if (result == null) {
70                     result = param;
71                 } else {
72                     throw new IllegalArgumentException JavaDoc(
73                         "more than one attribute with ID " + id //$NON-NLS-1$
74
+ " defined in plug-in " //$NON-NLS-1$
75
+ getDeclaringPluginDescriptor().getUniqueId());
76                 }
77             }
78         }
79         return result;
80     }
81     
82     /**
83      * @see org.java.plugin.registry.PluginAttribute#getSubAttributes()
84      */

85     public Collection JavaDoc getSubAttributes() {
86         return subAttributes;
87     }
88     
89     /**
90      * @see org.java.plugin.registry.PluginAttribute#getSubAttributes(java.lang.String)
91      */

92     public Collection JavaDoc getSubAttributes(final String JavaDoc id) {
93         List JavaDoc result = new LinkedList JavaDoc();
94         for (Iterator JavaDoc it = subAttributes.iterator(); it.hasNext();) {
95             PluginAttributeImpl param = (PluginAttributeImpl) it.next();
96             if (param.getId().equals(id)) {
97                 result.add(param);
98             }
99         }
100         return Collections.unmodifiableList(result);
101     }
102     
103     /**
104      * @see org.java.plugin.registry.PluginAttribute#getValue()
105      */

106     public String JavaDoc getValue() {
107         return model.getValue();
108     }
109     
110     /**
111      * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
112      * org.java.plugin.registry.Identity)
113      */

114     protected boolean isEqualTo(final Identity idt) {
115         if (!super.isEqualTo(idt)) {
116             return false;
117         }
118         PluginAttributeImpl other = (PluginAttributeImpl) idt;
119         if ((getSuperAttribute() == null)
120                 && (other.getSuperAttribute() == null)) {
121             return true;
122         }
123         if ((getSuperAttribute() == null)
124                 || (other.getSuperAttribute() == null)) {
125             return false;
126         }
127         return getSuperAttribute().equals(other.getSuperAttribute());
128     }
129
130     /**
131      * @see org.java.plugin.registry.PluginAttribute#getSuperAttribute()
132      */

133     public PluginAttribute getSuperAttribute() {
134         return superAttribute;
135     }
136 }
137
Popular Tags