001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2004-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.registry.xml;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.LinkedList;
024: import java.util.List;
025:
026: import org.java.plugin.registry.Identity;
027: import org.java.plugin.registry.ManifestProcessingException;
028: import org.java.plugin.registry.PluginAttribute;
029:
030: /**
031: * @version $Id$
032: */
033: class PluginAttributeImpl extends PluginElementImpl<PluginAttribute>
034: implements PluginAttribute {
035: private final PluginAttributeImpl super Attribute;
036: private final ModelAttribute model;
037: private List<PluginAttribute> subAttributes;
038:
039: PluginAttributeImpl(final PluginDescriptorImpl descr,
040: final PluginFragmentImpl aFragment,
041: final ModelAttribute aModel,
042: final PluginAttributeImpl aSuperAttribute)
043: throws ManifestProcessingException {
044: super (descr, aFragment, aModel.getId(), aModel
045: .getDocumentation());
046: model = aModel;
047: super Attribute = aSuperAttribute;
048: if (model.getValue() == null) {
049: model.setValue(""); //$NON-NLS-1$
050: }
051: subAttributes = new ArrayList<PluginAttribute>(model
052: .getAttributes().size());
053: for (ModelAttribute modelAttribute : model.getAttributes()) {
054: subAttributes.add(new PluginAttributeImpl(descr, aFragment,
055: modelAttribute, this ));
056: }
057: subAttributes = Collections.unmodifiableList(subAttributes);
058: if (log.isDebugEnabled()) {
059: log.debug("object instantiated: " + this ); //$NON-NLS-1$
060: }
061: }
062:
063: /**
064: * @see org.java.plugin.registry.PluginAttribute#getSubAttribute(java.lang.String)
065: */
066: public PluginAttribute getSubAttribute(final String id) {
067: PluginAttributeImpl result = null;
068: for (PluginAttribute pluginAttribute : subAttributes) {
069: PluginAttributeImpl param = (PluginAttributeImpl) pluginAttribute;
070: if (param.getId().equals(id)) {
071: if (result == null) {
072: result = param;
073: } else {
074: throw new IllegalArgumentException(
075: "more than one attribute with ID " + id //$NON-NLS-1$
076: + " defined in plug-in " //$NON-NLS-1$
077: + getDeclaringPluginDescriptor()
078: .getUniqueId());
079: }
080: }
081: }
082: return result;
083: }
084:
085: /**
086: * @see org.java.plugin.registry.PluginAttribute#getSubAttributes()
087: */
088: public Collection<PluginAttribute> getSubAttributes() {
089: return subAttributes;
090: }
091:
092: /**
093: * @see org.java.plugin.registry.PluginAttribute#getSubAttributes(java.lang.String)
094: */
095: public Collection<PluginAttribute> getSubAttributes(final String id) {
096: final List<PluginAttribute> result = new LinkedList<PluginAttribute>();
097: for (PluginAttribute pluginAttribute : subAttributes) {
098: PluginAttributeImpl param = (PluginAttributeImpl) pluginAttribute;
099: if (param.getId().equals(id)) {
100: result.add(param);
101: }
102: }
103: return Collections.unmodifiableList(result);
104: }
105:
106: /**
107: * @see org.java.plugin.registry.PluginAttribute#getValue()
108: */
109: public String getValue() {
110: return model.getValue();
111: }
112:
113: /**
114: * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
115: * org.java.plugin.registry.Identity)
116: */
117: @Override
118: protected boolean isEqualTo(final Identity idt) {
119: if (!super .isEqualTo(idt)) {
120: return false;
121: }
122: PluginAttributeImpl other = (PluginAttributeImpl) idt;
123: if ((getSuperAttribute() == null)
124: && (other.getSuperAttribute() == null)) {
125: return true;
126: }
127: if ((getSuperAttribute() == null)
128: || (other.getSuperAttribute() == null)) {
129: return false;
130: }
131: return getSuperAttribute().equals(other.getSuperAttribute());
132: }
133:
134: /**
135: * @see org.java.plugin.registry.PluginAttribute#getSuperAttribute()
136: */
137: public PluginAttribute getSuperAttribute() {
138: return superAttribute;
139: }
140: }
|