Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBJ Hargrave2006-04-08 04:30:19 +0000
committerBJ Hargrave2006-04-08 04:30:19 +0000
commitf9d15fd3fcd624255fb8524e30b37918dbe0b921 (patch)
treec884e5469277947abf7eff7cee2d871b8a79b4d1
parent3855c494ce8f2ca3abdfb880ca0d839352f54f2d (diff)
downloadrt.equinox.bundles-f9d15fd3fcd624255fb8524e30b37918dbe0b921.tar.gz
rt.equinox.bundles-f9d15fd3fcd624255fb8524e30b37918dbe0b921.tar.xz
rt.equinox.bundles-f9d15fd3fcd624255fb8524e30b37918dbe0b921.zip
Bug 135640: revamped the xml parsing code to ignore all attributes and elements which are not in the scr namespace.
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ComponentElement.java113
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ElementHandler.java64
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/IgnoredElement.java41
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ImplementationElement.java37
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ParserHandler.java10
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertiesElement.java37
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertyElement.java50
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ProvideElement.java35
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ReferenceElement.java93
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ServiceElement.java45
10 files changed, 284 insertions, 241 deletions
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ComponentElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ComponentElement.java
index 2c4085d9e..839407197 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ComponentElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ComponentElement.java
@@ -15,10 +15,8 @@ import org.eclipse.equinox.ds.model.PropertyValueDescription;
import org.osgi.service.component.ComponentConstants;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-class ComponentElement extends DefaultHandler {
- private ParserHandler root;
+class ComponentElement extends ElementHandler {
private ParserHandler parent;
private ComponentDescription component;
private boolean immediateSet;
@@ -29,79 +27,74 @@ class ComponentElement extends DefaultHandler {
component = new ComponentDescription(root.bundleContext);
immediateSet = false;
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
-
- if (key.equals(ParserConstants.NAME_ATTRIBUTE)) {
- component.setName(value);
- PropertyValueDescription nameProperty = new PropertyValueDescription();
- nameProperty.setName(ComponentConstants.COMPONENT_NAME);
- nameProperty.setValue(value);
- component.addPropertyDescription(nameProperty);
- continue;
- }
- if (key.equals(ParserConstants.ENABLED_ATTRIBUTE)) {
- component.setAutoenable(value.equalsIgnoreCase("true"));
- continue;
- }
- if (key.equals(ParserConstants.FACTORY_ATTRIBUTE)) {
- component.setFactory(value);
- continue;
- }
- if (key.equals(ParserConstants.IMMEDIATE_ATTRIBUTE)) {
- component.setImmediate(value.equalsIgnoreCase("true"));
- immediateSet = true;
- continue;
- }
- root.logError("unrecognized component element attribute: " + key);
- }
+ processAttributes(attributes);
if (component.getName() == null) {
root.logError("component name not specified");
}
}
-
- ComponentDescription getComponentDescription() {
- return component;
- }
-
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (localName.equals(ParserConstants.IMPLEMENTATION_ELEMENT)) {
- root.setHandler(new ImplementationElement(root, this, attributes));
+
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.NAME_ATTRIBUTE)) {
+ component.setName(value);
+ PropertyValueDescription nameProperty = new PropertyValueDescription();
+ nameProperty.setName(ComponentConstants.COMPONENT_NAME);
+ nameProperty.setValue(value);
+ component.addPropertyDescription(nameProperty);
return;
}
-
- if (localName.equals(ParserConstants.PROPERTY_ELEMENT)) {
- root.setHandler(new PropertyElement(root, this, attributes));
+ if (name.equals(ParserConstants.ENABLED_ATTRIBUTE)) {
+ component.setAutoenable(value.equalsIgnoreCase("true"));
return;
}
-
- if (localName.equals(ParserConstants.PROPERTIES_ELEMENT)) {
- root.setHandler(new PropertiesElement(root, this, attributes));
+ if (name.equals(ParserConstants.FACTORY_ATTRIBUTE)) {
+ component.setFactory(value);
return;
}
-
- if (localName.equals(ParserConstants.SERVICE_ELEMENT)) {
- root.setHandler(new ServiceElement(root, this, attributes));
+ if (name.equals(ParserConstants.IMMEDIATE_ATTRIBUTE)) {
+ component.setImmediate(value.equalsIgnoreCase("true"));
+ immediateSet = true;
return;
}
+
+ root.logError("unrecognized component element attribute: " + name);
+ }
- if (localName.equals(ParserConstants.REFERENCE_ELEMENT)) {
- root.setHandler(new ReferenceElement(root, this, attributes));
- return;
- }
- root.logError("unrecognized element of component: " + localName);
+
+
+ ComponentDescription getComponentDescription() {
+ return component;
}
- public void characters(char[] ch, int start, int length) {
- int end = start + length;
- for (int i = start; i < end; i++) {
- if (!Character.isWhitespace(ch[i])) {
- root.logError("element body must be empty");
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if (isSCRNamespace(uri)) {
+ if (localName.equals(ParserConstants.IMPLEMENTATION_ELEMENT)) {
+ root.setHandler(new ImplementationElement(root, this, attributes));
+ return;
+ }
+
+ if (localName.equals(ParserConstants.PROPERTY_ELEMENT)) {
+ root.setHandler(new PropertyElement(root, this, attributes));
+ return;
+ }
+
+ if (localName.equals(ParserConstants.PROPERTIES_ELEMENT)) {
+ root.setHandler(new PropertiesElement(root, this, attributes));
+ return;
+ }
+
+ if (localName.equals(ParserConstants.SERVICE_ELEMENT)) {
+ root.setHandler(new ServiceElement(root, this, attributes));
+ return;
+ }
+
+ if (localName.equals(ParserConstants.REFERENCE_ELEMENT)) {
+ root.setHandler(new ReferenceElement(root, this, attributes));
+ return;
}
}
+
+ super.startElement(uri, localName, qName, attributes);
}
public void endElement(String uri, String localName, String qName) {
@@ -125,4 +118,8 @@ class ComponentElement extends DefaultHandler {
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "component";
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ElementHandler.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ElementHandler.java
new file mode 100644
index 000000000..eb7a7c481
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ElementHandler.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.parser;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Base class for element handlers to provide some common behavior.
+ *
+ */
+abstract class ElementHandler extends DefaultHandler {
+
+ protected ParserHandler root;
+
+ /**
+ * Return the name of the handled element.
+ *
+ * @return The name of the handled element.
+ */
+ protected abstract String getElementName();
+
+ protected boolean isSCRNamespace(String uri) {
+ return (uri.length() == 0) || uri.equals(ParserConstants.SCR_NAMESPACE);
+ }
+
+ protected void processAttributes(Attributes attributes) {
+ int size = attributes.getLength();
+ for (int i = 0; i < size; i++) {
+ if (isSCRNamespace(attributes.getURI(i))) {
+ handleAttribute(attributes.getLocalName(i), attributes.getValue(i));
+ }
+ }
+ }
+
+ protected abstract void handleAttribute(String name, String value);
+
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if (isSCRNamespace(uri)) {
+ root.logError("unrecognized element "+ qName);
+ }
+
+ root.setHandler(new IgnoredElement(root, this));
+ }
+
+ public void characters(char[] ch, int start, int length) {
+ int end = start + length;
+ for (int i = start; i < end; i++) {
+ if (!Character.isWhitespace(ch[i])) {
+ root.logError(getElementName()+ " element body must be empty");
+ }
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/IgnoredElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/IgnoredElement.java
new file mode 100644
index 000000000..182182932
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/IgnoredElement.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.parser;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+class IgnoredElement extends DefaultHandler {
+
+ private ParserHandler root;
+ private DefaultHandler parent;
+
+ private int depth;
+
+ IgnoredElement(ParserHandler root, DefaultHandler parent) {
+ this.root = root;
+ this.parent = parent;
+ depth = 1;
+ }
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ depth++;
+ }
+
+
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ depth--;
+ if (depth == 0) {
+ root.setHandler(parent);
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ImplementationElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ImplementationElement.java
index 0e6f5aced..973d1d0fe 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ImplementationElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ImplementationElement.java
@@ -13,10 +13,8 @@ package org.eclipse.equinox.ds.parser;
import org.eclipse.equinox.ds.model.ComponentDescription;
import org.eclipse.equinox.ds.model.ImplementationDescription;
import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-class ImplementationElement extends DefaultHandler {
- private ParserHandler root;
+class ImplementationElement extends ElementHandler {
private ComponentElement parent;
private ImplementationDescription implementation;
@@ -25,34 +23,19 @@ class ImplementationElement extends DefaultHandler {
this.parent = parent;
implementation = new ImplementationDescription();
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
-
- if (key.equals(ParserConstants.CLASS_ATTRIBUTE)) {
- implementation.setClassname(value);
- continue;
- }
- root.logError("unrecognized implementation element attribute: " + key);
- }
-
+ processAttributes(attributes);
+
if (implementation.getClassname() == null) {
root.logError("implementation class not specified");
}
}
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- root.logError("implementation does not support nested elements");
- }
-
- public void characters(char[] ch, int start, int length) {
- int end = start + length;
- for (int i = start; i < end; i++) {
- if (!Character.isWhitespace(ch[i])) {
- root.logError("element body must be empty");
- }
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.CLASS_ATTRIBUTE)) {
+ implementation.setClassname(value);
+ return;
}
+ root.logError("unrecognized implementation element attribute: " + name);
}
public void endElement(String uri, String localName, String qName) {
@@ -64,4 +47,8 @@ class ImplementationElement extends DefaultHandler {
component.setImplementation(implementation);
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "implementation";
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ParserHandler.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ParserHandler.java
index ce0a61263..09b205e30 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ParserHandler.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ParserHandler.java
@@ -22,7 +22,7 @@ import org.xml.sax.helpers.DefaultHandler;
* parser. Each Service Component bundle contains a set of xml files which are
* parsed.
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.1 $
*/
class ParserHandler extends DefaultHandler {
@@ -125,9 +125,11 @@ class ParserHandler extends DefaultHandler {
public void endElement(String uri, String localName, String qName) throws SAXException {
if (DEBUG) {
- System.out.println("[endElement:uri]" + uri);
- System.out.println("[endElement:localName]" + localName);
- System.out.println("[endElement:qName]" + qName);
+ System.out.println("[endElement:begin]");
+ System.out.println(" [uri]" + uri);
+ System.out.println(" [localName]" + localName);
+ System.out.println(" [qName]" + qName);
+ System.out.println("[endElement:end]");
}
if (handler != this) {
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertiesElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertiesElement.java
index 883ab55d1..2ad426a99 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertiesElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertiesElement.java
@@ -13,10 +13,8 @@ package org.eclipse.equinox.ds.parser;
import org.eclipse.equinox.ds.model.ComponentDescription;
import org.eclipse.equinox.ds.model.PropertyResourceDescription;
import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-class PropertiesElement extends DefaultHandler {
- private ParserHandler root;
+class PropertiesElement extends ElementHandler {
private ComponentElement parent;
private PropertyResourceDescription properties;
@@ -25,34 +23,19 @@ class PropertiesElement extends DefaultHandler {
this.parent = parent;
properties = new PropertyResourceDescription();
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
-
- if (key.equals(ParserConstants.ENTRY_ATTRIBUTE)) {
- properties.setEntry(value);
- continue;
- }
- root.logError("unrecognized properties element attribute: " + key);
- }
-
+ processAttributes(attributes);
+
if (properties.getEntry() == null) {
root.logError("properties entry not specified");
}
}
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- root.logError("properties does not support nested elements");
- }
-
- public void characters(char[] ch, int start, int length) {
- int end = start + length;
- for (int i = start; i < end; i++) {
- if (!Character.isWhitespace(ch[i])) {
- root.logError("element body must be empty");
- }
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.ENTRY_ATTRIBUTE)) {
+ properties.setEntry(value);
+ return;
}
+ root.logError("unrecognized properties element attribute: " + name);
}
public void endElement(String uri, String localName, String qName) {
@@ -60,4 +43,8 @@ class PropertiesElement extends DefaultHandler {
component.addPropertyDescription(properties);
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "properties";
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertyElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertyElement.java
index 4055cc88c..63c259361 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertyElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/PropertyElement.java
@@ -14,10 +14,8 @@ import java.util.*;
import org.eclipse.equinox.ds.model.ComponentDescription;
import org.eclipse.equinox.ds.model.PropertyValueDescription;
import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-class PropertyElement extends DefaultHandler {
- private ParserHandler root;
+class PropertyElement extends ElementHandler {
private ComponentElement parent;
private PropertyValueDescription property;
private List values;
@@ -28,35 +26,29 @@ class PropertyElement extends DefaultHandler {
property = new PropertyValueDescription();
values = new ArrayList();
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
-
- if (key.equals(ParserConstants.NAME_ATTRIBUTE)) {
- property.setName(value);
- continue;
- }
-
- if (key.equals(ParserConstants.VALUE_ATTRIBUTE)) {
- property.setValue(value);
- continue;
- }
-
- if (key.equals(ParserConstants.TYPE_ATTRIBUTE)) {
- property.setType(value);
- continue;
- }
- root.logError("unrecognized properties element attribute: " + key);
- }
-
+ processAttributes(attributes);
+
if (property.getName() == null) {
root.logError("property name not specified");
}
}
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- root.logError("property does not support nested elements");
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.NAME_ATTRIBUTE)) {
+ property.setName(value);
+ return;
+ }
+
+ if (name.equals(ParserConstants.VALUE_ATTRIBUTE)) {
+ property.setValue(value);
+ return;
+ }
+
+ if (name.equals(ParserConstants.TYPE_ATTRIBUTE)) {
+ property.setType(value);
+ return;
+ }
+ root.logError("unrecognized properties element attribute: " + name);
}
public void characters(char[] ch, int start, int length) {
@@ -219,4 +211,8 @@ class PropertyElement extends DefaultHandler {
component.addPropertyDescription(property);
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "property";
+ }
}
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ProvideElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ProvideElement.java
index bc7ce8b3d..b2f0d7378 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ProvideElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ProvideElement.java
@@ -13,10 +13,8 @@ package org.eclipse.equinox.ds.parser;
import org.eclipse.equinox.ds.model.ProvideDescription;
import org.eclipse.equinox.ds.model.ServiceDescription;
import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-class ProvideElement extends DefaultHandler {
- private ParserHandler root;
+class ProvideElement extends ElementHandler {
private ServiceElement parent;
private ProvideDescription provide;
@@ -25,34 +23,19 @@ class ProvideElement extends DefaultHandler {
this.parent = parent;
provide = new ProvideDescription();
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
-
- if (key.equals(ParserConstants.INTERFACE_ATTRIBUTE)) {
- provide.setInterfacename(value);
- continue;
- }
- root.logError("unrecognized provide element attribute: " + key);
- }
+ processAttributes(attributes);
if (provide.getInterfacename() == null) {
root.logError("provide interface not specified");
}
}
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- root.logError("provide does not support nested elements");
- }
-
- public void characters(char[] ch, int start, int length) {
- int end = start + length;
- for (int i = start; i < end; i++) {
- if (!Character.isWhitespace(ch[i])) {
- root.logError("element body must be empty");
- }
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.INTERFACE_ATTRIBUTE)) {
+ provide.setInterfacename(value);
+ return;
}
+ root.logError("unrecognized provide element attribute: " + name);
}
public void endElement(String uri, String localName, String qName) {
@@ -61,4 +44,8 @@ class ProvideElement extends DefaultHandler {
service.addProvide(provide);
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "provide";
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ReferenceElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ReferenceElement.java
index f43a641b3..313cc0321 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ReferenceElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ReferenceElement.java
@@ -13,10 +13,8 @@ package org.eclipse.equinox.ds.parser;
import org.eclipse.equinox.ds.model.ComponentDescription;
import org.eclipse.equinox.ds.model.ReferenceDescription;
import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-class ReferenceElement extends DefaultHandler {
- private ParserHandler root;
+class ReferenceElement extends ElementHandler {
private ComponentElement parent;
private ReferenceDescription reference;
@@ -25,47 +23,7 @@ class ReferenceElement extends DefaultHandler {
this.parent = parent;
reference = new ReferenceDescription();
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
-
- if (key.equals(ParserConstants.NAME_ATTRIBUTE)) {
- reference.setName(value);
- continue;
- }
-
- if (key.equals(ParserConstants.INTERFACE_ATTRIBUTE)) {
- reference.setInterfacename(value);
- continue;
- }
-
- if (key.equals(ParserConstants.CARDINALITY_ATTRIBUTE)) {
- reference.setCardinality(value);
- continue;
- }
-
- if (key.equals(ParserConstants.POLICY_ATTRIBUTE)) {
- reference.setPolicy(value);
- continue;
- }
-
- if (key.equals(ParserConstants.TARGET_ATTRIBUTE)) {
- reference.setTarget(value);
- continue;
- }
-
- if (key.equals(ParserConstants.BIND_ATTRIBUTE)) {
- reference.setBind(value);
- continue;
- }
-
- if (key.equals(ParserConstants.UNBIND_ATTRIBUTE)) {
- reference.setUnbind(value);
- continue;
- }
- root.logError("unrecognized reference element attribute: " + key);
- }
+ processAttributes(attributes);
if (reference.getName() == null) {
root.logError("reference name not specified");
@@ -75,17 +33,42 @@ class ReferenceElement extends DefaultHandler {
}
}
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- root.logError("reference does not support nested elements");
- }
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.NAME_ATTRIBUTE)) {
+ reference.setName(value);
+ return;
+ }
+
+ if (name.equals(ParserConstants.INTERFACE_ATTRIBUTE)) {
+ reference.setInterfacename(value);
+ return;
+ }
+
+ if (name.equals(ParserConstants.CARDINALITY_ATTRIBUTE)) {
+ reference.setCardinality(value);
+ return;
+ }
- public void characters(char[] ch, int start, int length) {
- int end = start + length;
- for (int i = start; i < end; i++) {
- if (!Character.isWhitespace(ch[i])) {
- root.logError("element body must be empty");
- }
+ if (name.equals(ParserConstants.POLICY_ATTRIBUTE)) {
+ reference.setPolicy(value);
+ return;
}
+
+ if (name.equals(ParserConstants.TARGET_ATTRIBUTE)) {
+ reference.setTarget(value);
+ return;
+ }
+
+ if (name.equals(ParserConstants.BIND_ATTRIBUTE)) {
+ reference.setBind(value);
+ return;
+ }
+
+ if (name.equals(ParserConstants.UNBIND_ATTRIBUTE)) {
+ reference.setUnbind(value);
+ return;
+ }
+ root.logError("unrecognized reference element attribute: " + name);
}
public void endElement(String uri, String localName, String qName) {
@@ -93,4 +76,8 @@ class ReferenceElement extends DefaultHandler {
component.addReferenceDescription(reference);
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "reference";
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ServiceElement.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ServiceElement.java
index 0039192e5..18cf79dbc 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ServiceElement.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/ds/parser/ServiceElement.java
@@ -13,10 +13,9 @@ package org.eclipse.equinox.ds.parser;
import org.eclipse.equinox.ds.model.ComponentDescription;
import org.eclipse.equinox.ds.model.ServiceDescription;
import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.SAXException;
-class ServiceElement extends DefaultHandler {
- private ParserHandler root;
+class ServiceElement extends ElementHandler {
private ComponentElement parent;
private ServiceDescription service;
@@ -25,38 +24,30 @@ class ServiceElement extends DefaultHandler {
this.parent = parent;
service = new ServiceDescription();
- int size = attributes.getLength();
- for (int i = 0; i < size; i++) {
- String key = attributes.getQName(i);
- String value = attributes.getValue(i);
+ processAttributes(attributes);
+ }
- if (key.equals(ParserConstants.SERVICEFACTORY_ATTRIBUTE)) {
- service.setServicefactory(value.equalsIgnoreCase("true"));
- continue;
- }
- root.logError("unrecognized service element attribute: " + key);
+ protected void handleAttribute(String name, String value) {
+ if (name.equals(ParserConstants.SERVICEFACTORY_ATTRIBUTE)) {
+ service.setServicefactory(value.equalsIgnoreCase("true"));
+ return;
}
+ root.logError("unrecognized service element attribute: " + name);
}
ServiceDescription getServiceDescription() {
return service;
}
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- if (localName.equals(ParserConstants.PROVIDE_ELEMENT)) {
- root.setHandler(new ProvideElement(root, this, attributes));
- return;
- }
- root.logError("unrecognized element of service: " + localName);
- }
-
- public void characters(char[] ch, int start, int length) {
- int end = start + length;
- for (int i = start; i < end; i++) {
- if (!Character.isWhitespace(ch[i])) {
- root.logError("element body must be empty");
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ if (isSCRNamespace(uri)) {
+ if (localName.equals(ParserConstants.PROVIDE_ELEMENT)) {
+ root.setHandler(new ProvideElement(root, this, attributes));
+ return;
}
}
+
+ super.startElement(uri, localName, qName, attributes);
}
public void endElement(String uri, String localName, String qName) {
@@ -76,4 +67,8 @@ class ServiceElement extends DefaultHandler {
component.setService(service);
root.setHandler(parent);
}
+
+ protected String getElementName() {
+ return "service";
+ }
} \ No newline at end of file

Back to the top