1 19 package org.java.plugin.registry.xml; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.java.plugin.registry.Documentation; 24 import org.java.plugin.registry.ManifestProcessingException; 25 import org.java.plugin.registry.PluginDescriptor; 26 import org.java.plugin.registry.PluginFragment; 27 import org.java.plugin.registry.PluginPrerequisite; 28 import org.java.plugin.registry.Version; 29 30 33 class PluginPrerequisiteImpl implements PluginPrerequisite { 34 private static Log log = LogFactory.getLog(PluginPrerequisiteImpl.class); 35 36 static boolean matches(final Version source, final Version target, 37 final String match) { 38 if (source == null) { 39 return true; 40 } 41 if (MATCH_EQUAL.equals(match)) { 42 return target.equals(source); 43 } else if (MATCH_EQUIVALENT.equals(match)) { 44 return target.isEquivalentTo(source); 45 } else if (MATCH_COMPATIBLE.equals(match)) { 46 return target.isCompatibleWith(source); 47 } else if (MATCH_GREATER_OR_EQUAL.equals(match)) { 48 return target.isGreaterOrEqualTo(source); 49 } 50 return target.isCompatibleWith(source); 51 } 52 53 private final PluginDescriptorImpl descriptor; 54 private final PluginFragmentImpl fragment; 55 private final ModelPrerequisite model; 56 private DocumentationImpl doc; 57 58 PluginPrerequisiteImpl(final PluginDescriptorImpl descr, 59 final PluginFragmentImpl aFragment, final ModelPrerequisite aModel) 60 throws ManifestProcessingException { 61 super(); 62 descriptor = descr; 63 fragment = aFragment; 64 model = aModel; 65 if ((model.getPluginId() == null) 66 || (model.getPluginId().trim().length() == 0)) { 67 throw new ManifestProcessingException( 68 PluginRegistryImpl.PACKAGE_NAME, 69 "prerequisitePliginIdIsBlank", descr.getId()); } 71 if (descr.getId().equals(model.getPluginId())) { 72 throw new ManifestProcessingException( 73 PluginRegistryImpl.PACKAGE_NAME, 74 "invalidPrerequisitePluginId", descr.getId()); } 76 if ((model.getId() == null) || (model.getId().trim().length() == 0)) { 77 model.setId("prerequisite:" + model.getPluginId()); } 79 if (model.getDocumentation() != null) { 80 doc = new DocumentationImpl(this, model.getDocumentation()); 81 } 82 if (log.isDebugEnabled()) { 83 log.debug("object instantiated: " + this); } 85 } 86 87 90 public String getPluginId() { 91 return model.getPluginId(); 92 } 93 94 97 public Version getPluginVersion() { 98 return model.getPluginVersion(); 99 } 100 101 104 public PluginDescriptor getDeclaringPluginDescriptor() { 105 return descriptor; 106 } 107 108 111 public PluginFragment getDeclaringPluginFragment() { 112 return fragment; 113 } 114 115 118 public boolean isOptional() { 119 return model.isOptional(); 120 } 121 122 125 public boolean isReverseLookup() { 126 return model.isReverseLookup(); 127 } 128 129 132 public boolean matches() { 133 PluginDescriptor descr = null; 134 try { 135 descr = this.descriptor.getRegistry().getPluginDescriptor( 136 model.getPluginId()); 137 } catch (IllegalArgumentException iae) { 138 return false; 139 } 140 return matches(model.getPluginVersion(), descr.getVersion(), 141 model.getMatch()); 142 } 143 144 147 public String getMatch() { 148 return model.getMatch(); 149 } 150 151 154 public boolean isExported() { 155 return model.isExported(); 156 } 157 158 161 public String getId() { 162 return model.getId(); 163 } 164 165 168 public String getDocsPath() { 169 return (fragment != null) ? fragment.getDocsPath() 170 : descriptor.getDocsPath(); 171 } 172 173 176 public Documentation getDocumentation() { 177 return doc; 178 } 179 180 183 public String getUniqueId() { 184 return descriptor.getRegistry().makeUniqueId(descriptor.getId(), 185 getId()); 186 } 187 188 191 public String toString() { 192 return "{Prerequisite: uid=" + getUniqueId() + "}"; } 194 } 195 | Popular Tags |