1 19 package org.java.plugin.registry.xml; 20 21 import org.java.plugin.registry.ExtensionPoint; 22 import org.java.plugin.registry.PluginPrerequisite; 23 import org.xml.sax.Attributes ; 24 import org.xml.sax.EntityResolver ; 25 import org.xml.sax.SAXException ; 26 27 30 final class ManifestHandler extends BaseHandler { 31 private ModelPluginManifest manifest = null; 32 private ModelDocumentation documentation = null; 33 private ModelPrerequisite prerequisite; 34 private ModelLibrary library; 35 private ModelExtensionPoint extensionPoint; 36 private ModelExtension extension; 37 private StringBuffer docText = null; 38 private SimpleStack attributeStack = null; 39 private ModelAttribute attribute; 40 private SimpleStack paramDefStack = null; 41 private ModelParameterDef paramDef; 42 private SimpleStack paramStack = null; 43 private ModelParameter param; 44 private StringBuffer paramValue = null; 45 46 ManifestHandler(final EntityResolver anEntityResolver) { 47 super(anEntityResolver); 48 } 49 50 54 public void startElement(final String uri, final String localName, 55 final String qName, final Attributes attributes) 56 throws SAXException { 57 if (log.isDebugEnabled()) { 58 log.debug("startElement - [" + uri + "]/[" + localName + "]/[" + qName + "]"); } 61 String name = qName; 62 if ("plugin".equals(name)) { if (manifest != null) { 64 throw new SAXException ("unexpected [" + name + "] element (manifest already defined)"); } 67 manifest = new ModelPluginDescriptor(); 68 manifest.setId(attributes.getValue("id")); manifest.setVersion(attributes.getValue("version")); manifest.setVendor(attributes.getValue("vendor")); manifest.setDocsPath(attributes.getValue("docs-path")); ((ModelPluginDescriptor) manifest).setClassName( 73 attributes.getValue("class")); } else if ("plugin-fragment".equals(name)) { if (manifest != null) { 76 throw new SAXException ("unexpected [" + name + "] element (manifest already defined)"); } 79 manifest = new ModelPluginFragment(); 80 manifest.setId(attributes.getValue("id")); manifest.setVersion(attributes.getValue("version")); manifest.setVendor(attributes.getValue("vendor")); manifest.setDocsPath(attributes.getValue("docs-path")); ((ModelPluginFragment) manifest).setPluginId( 85 attributes.getValue("plugin-id")); if (attributes.getValue("plugin-version") != null) { ((ModelPluginFragment) manifest).setPluginVersion( 88 attributes.getValue("plugin-version")); } 90 if (attributes.getValue("match") != null) { ((ModelPluginFragment) manifest).setMatch( 92 attributes.getValue("match")); } else { 94 ((ModelPluginFragment) manifest).setMatch(PluginPrerequisite.MATCH_COMPATIBLE); 95 } 96 } else if ("doc".equals(name)) { documentation = new ModelDocumentation(); 98 documentation.setCaption(attributes.getValue("caption")); } else if ("doc-ref".equals(name)) { if (documentation == null) { 101 if (entityResolver != null) { 102 throw new SAXException ("[doc-ref] element found " + "outside of [doc] element"); } 105 log.warn("[doc-ref] element found outside of [doc] element"); return; 108 } 109 ModelDocumentationReference docRef = 110 new ModelDocumentationReference(); 111 docRef.setPath(attributes.getValue("path")); docRef.setCaption(attributes.getValue("caption")); documentation.getReferences().add(docRef); 114 } else if ("doc-text".equals(name)) { if (documentation == null) { 116 if (entityResolver != null) { 117 throw new SAXException ("[doc-text] element found " + "outside of [doc] element"); } 120 log.warn("[doc-text] element found outside of [doc] element"); return; 123 } 124 docText = new StringBuffer (); 125 } else if ("attributes".equals(name)) { attributeStack = new SimpleStack(); 127 } else if ("attribute".equals(name)) { if (attributeStack == null) { 129 if (entityResolver != null) { 130 throw new SAXException ("[attribute] element found " + "outside of [attributes] element"); } 133 log.warn("[attribute] element found " + "outside of [attributes] element"); return; 137 } 138 if (attribute != null) { 139 attributeStack.push(attribute); 140 } 141 attribute = new ModelAttribute(); 142 attribute.setId(attributes.getValue("id")); attribute.setValue(attributes.getValue("value")); } else if ("requires".equals(name)) { } else if ("import".equals(name)) { prerequisite = new ModelPrerequisite(); 148 if (attributes.getValue("id") != null) { prerequisite.setId(attributes.getValue("id")); } 151 prerequisite.setPluginId(attributes.getValue("plugin-id")); if (attributes.getValue("plugin-version") != null) { prerequisite.setPluginVersion( 154 attributes.getValue("plugin-version")); } 156 if (attributes.getValue("match") != null) { prerequisite.setMatch(attributes.getValue("match")); } else { 159 prerequisite.setMatch(PluginPrerequisite.MATCH_COMPATIBLE); 160 } 161 prerequisite.setExported(attributes.getValue("exported")); prerequisite.setOptional(attributes.getValue("optional")); prerequisite.setReverseLookup( 164 attributes.getValue("reverse-lookup")); } else if ("runtime".equals(name)) { } else if ("library".equals(name)) { library = new ModelLibrary(); 169 library.setId(attributes.getValue("id")); library.setPath(attributes.getValue("path")); library.setCodeLibrary(attributes.getValue("type")); if (attributes.getValue("version") != null) { library.setVersion(attributes.getValue("version")); } 175 } else if ("export".equals(name)) { if (library == null) { 177 if (entityResolver != null) { 178 throw new SAXException ("[export] element found " + "outside of [library] element"); } 181 log.warn("[export] element found outside of [library] element"); return; 184 } 185 library.getExports().add(attributes.getValue("prefix")); } else if ("extension-point".equals(name)) { extensionPoint = new ModelExtensionPoint(); 188 extensionPoint.setId(attributes.getValue("id")); extensionPoint.setParentPluginId( 190 attributes.getValue("parent-plugin-id")); extensionPoint.setParentPointId( 192 attributes.getValue("parent-point-id")); if (attributes.getValue("extension-multiplicity") != null) { extensionPoint.setExtensionMultiplicity( 195 attributes.getValue("extension-multiplicity")); } else { 197 extensionPoint.setExtensionMultiplicity(ExtensionPoint.EXT_MULT_ANY); 198 } 199 paramDefStack = new SimpleStack(); 200 } else if ("parameter-def".equals(name)) { if (extensionPoint == null) { 202 if (entityResolver != null) { 203 throw new SAXException ("[parameter-def] element found " + "outside of [extension-point] element"); } 206 log.warn("[parameter-def] element found " + "outside of [extension-point] element"); return; 210 } 211 if (paramDef != null) { 212 paramDefStack.push(paramDef); 213 } 214 paramDef = new ModelParameterDef(); 215 paramDef.setId(attributes.getValue("id")); if (attributes.getValue("multiplicity") != null) { paramDef.setMultiplicity(attributes.getValue("multiplicity")); } else { 219 paramDef.setMultiplicity(ExtensionPoint.ParameterDefinition.MULT_ONE); 220 } 221 if (attributes.getValue("type") != null) { paramDef.setType(attributes.getValue("type")); } else { 224 paramDef.setType(ExtensionPoint.ParameterDefinition.TYPE_STRING); 225 } 226 paramDef.setCustomData(attributes.getValue("custom-data")); paramDef.setDefaultValue(attributes.getValue("default-value")); } else if ("extension".equals(name)) { extension = new ModelExtension(); 230 extension.setId(attributes.getValue("id")); extension.setPluginId(attributes.getValue("plugin-id")); extension.setPointId(attributes.getValue("point-id")); paramStack = new SimpleStack(); 234 } else if ("parameter".equals(name)) { if (extension == null) { 236 if (entityResolver != null) { 237 throw new SAXException ("[parameter] element found " + "outside of [extension] element"); } 240 log.warn("[parameter] element found " + "outside of [extension] element"); return; 244 } 245 if (param != null) { 246 paramStack.push(param); 247 } 248 param = new ModelParameter(); 249 param.setId(attributes.getValue("id")); param.setValue(attributes.getValue("value")); } else if ("value".equals(name)) { if (param == null) { 253 if (entityResolver != null) { 254 throw new SAXException ("[value] element found " + "outside of [parameter] element"); } 257 log.warn("[value] element found " + "outside of [parameter] element"); return; 261 } 262 paramValue = new StringBuffer (); 263 } else { 264 if (entityResolver != null) { 265 throw new SAXException ("unexpected manifest element - [" + uri + "]/[" + localName + "]/[" + qName + "]"); } 268 log.warn("unexpected manifest element - [" + uri + "]/[" + localName + "]/[" + qName + "]"); } 272 } 273 274 278 public void endElement(final String uri, final String localName, 279 final String qName) { 280 if (log.isDebugEnabled()) { 281 log.debug("endElement - [" + uri + "]/[" + localName + "]/[" + qName + "]"); } 284 String name = qName; 285 if ("plugin".equals(name)) { } else if ("plugin-fragment".equals(name)) { } else if ("doc".equals(name)) { if (param != null) { 291 param.setDocumentation(documentation); 292 } else if (extension != null) { 293 extension.setDocumentation(documentation); 294 } else if (paramDef != null) { 295 paramDef.setDocumentation(documentation); 296 } else if (extensionPoint != null) { 297 extensionPoint.setDocumentation(documentation); 298 } else if (library != null) { 299 library.setDocumentation(documentation); 300 } else if (prerequisite != null) { 301 prerequisite.setDocumentation(documentation); 302 } else if (attribute != null) { 303 attribute.setDocumentation(documentation); 304 } else { 305 manifest.setDocumentation(documentation); 306 } 307 documentation = null; 308 } else if ("doc-ref".equals(name)) { } else if ("doc-text".equals(name)) { documentation.setText(docText.toString()); 312 docText = null; 313 } else if ("attributes".equals(name)) { attributeStack = null; 315 } else if ("attribute".equals(name)) { if (attributeStack.size() == 0) { 317 manifest.getAttributes().add(attribute); 318 attribute = null; 319 } else { 320 ModelAttribute temp = attribute; 321 attribute = (ModelAttribute) attributeStack.pop(); 322 attribute.getAttributes().add(temp); 323 temp = null; 324 } 325 } else if ("requires".equals(name)) { } else if ("import".equals(name)) { manifest.getPrerequisites().add(prerequisite); 329 prerequisite = null; 330 } else if ("runtime".equals(name)) { } else if ("library".equals(name)) { manifest.getLibraries().add(library); 334 library = null; 335 } else if ("export".equals(name)) { } else if ("extension-point".equals(name)) { manifest.getExtensionPoints().add(extensionPoint); 339 extensionPoint = null; 340 paramDefStack = null; 341 } else if ("parameter-def".equals(name)) { if (paramDefStack.size() == 0) { 343 extensionPoint.getParamDefs().add(paramDef); 344 paramDef = null; 345 } else { 346 ModelParameterDef temp = paramDef; 347 paramDef = (ModelParameterDef) paramDefStack.pop(); 348 paramDef.getParamDefs().add(temp); 349 temp = null; 350 } 351 } else if ("extension".equals(name)) { manifest.getExtensions().add(extension); 353 extension = null; 354 paramStack = null; 355 } else if ("parameter".equals(name)) { if (paramStack.size() == 0) { 357 extension.getParams().add(param); 358 param = null; 359 } else { 360 ModelParameter temp = param; 361 param = (ModelParameter) paramStack.pop(); 362 param.getParams().add(temp); 363 temp = null; 364 } 365 } else if ("value".equals(name)) { param.setValue(paramValue.toString()); 367 paramValue = null; 368 } else { 369 log.warn("ignoring manifest element - [" + uri + "]/[" + localName + "]/[" + qName + "]"); } 373 } 374 375 378 public void characters(final char[] ch, final int start, final int length) 379 throws SAXException { 380 if (docText != null) { 381 docText.append(ch, start, length); 382 } else if (paramValue != null) { 383 paramValue.append(ch, start, length); 384 } else { 385 if (entityResolver != null) { 386 throw new SAXException ("unexpected character data"); } 388 log.warn("ignoring character data - [" + new String (ch, start, length) + "]"); } 392 } 393 394 ModelPluginManifest getResult() { 395 return manifest; 396 } 397 } 398 | Popular Tags |