1 19 package org.java.plugin.registry.xml; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.LinkedList ; 26 import java.util.List ; 27 28 import org.java.plugin.registry.Identity; 29 import org.java.plugin.registry.ManifestProcessingException; 30 import org.java.plugin.registry.PluginAttribute; 31 32 35 class PluginAttributeImpl extends PluginElementImpl implements PluginAttribute { 36 private final PluginAttributeImpl superAttribute; 37 private final ModelAttribute model; 38 private List 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(""); } 50 subAttributes = new ArrayList (model.getAttributes().size()); 51 for (Iterator 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); } 59 } 60 61 64 public PluginAttribute getSubAttribute(final String id) { 65 PluginAttributeImpl result = null; 66 for (Iterator 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 ( 73 "more than one attribute with ID " + id + " defined in plug-in " + getDeclaringPluginDescriptor().getUniqueId()); 76 } 77 } 78 } 79 return result; 80 } 81 82 85 public Collection getSubAttributes() { 86 return subAttributes; 87 } 88 89 92 public Collection getSubAttributes(final String id) { 93 List result = new LinkedList (); 94 for (Iterator 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 106 public String getValue() { 107 return model.getValue(); 108 } 109 110 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 133 public PluginAttribute getSuperAttribute() { 134 return superAttribute; 135 } 136 } 137 | Popular Tags |