summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/contribution-xml
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-11-19 05:27:58 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-11-19 05:27:58 +0000
commit5f3869c451e46aadc943d00087d6847877dd1c50 (patch)
treee22baaff1fb9ea42606b7d04af52e032e3bc03bc /java/sca/modules/contribution-xml
parent60744a36aae604ac3c4499ed54f1082ab8f5947d (diff)
Merging the 1.x delta on top of the equinox based modules
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@718858 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/contribution-xml')
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java13
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java347
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java482
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java448
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java53
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java3
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java100
-rw-r--r--java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties7
8 files changed, 1155 insertions, 298 deletions
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
index 503a9c96d2..36e959ea21 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
@@ -23,13 +23,14 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.contribution.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
import org.apache.tuscany.sca.monitor.Monitor;
/**
@@ -38,9 +39,9 @@ import org.apache.tuscany.sca.monitor.Monitor;
* @version $Rev$ $Date$
*/
public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor<String> {
- private static final QName ANY_ATTRIBUTE = new QName("http://www.w3.org/2001/XMLSchema", "anyAttribute");
+ private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute");
- public AnyAttributeProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public AnyAttributeProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
index 38da7740cd..2b868b9e45 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
@@ -20,290 +20,155 @@ package org.apache.tuscany.sca.contribution.processor.xml;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.CHARACTERS;
+import static javax.xml.stream.XMLStreamConstants.COMMENT;
+import static javax.xml.stream.XMLStreamConstants.CDATA;
import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.XMLEvent;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.Problem;
-import org.apache.tuscany.sca.monitor.Problem.Severity;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.traversal.DocumentTraversal;
-import org.w3c.dom.traversal.NodeFilter;
-import org.w3c.dom.traversal.NodeIterator;
-import org.w3c.dom.traversal.TreeWalker;
+import org.apache.tuscany.sca.contribution.processor.xml.XMLEventsStreamReader;
public class AnyElementProcessor implements StAXArtifactProcessor<Object> {
- private static final QName ANY_ELEMENT = new QName("http://www.w3.org/2001/XMLSchema", "anyElement");
-
- private static final Logger logger = Logger.getLogger(AnyElementProcessor.class.getName());
- private DocumentBuilderFactory documentBuilderFactory;
- private Document document;
+ private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS,
+ "anyElement");
+
+ private XMLInputFactory xmlInputFactory;
+ @SuppressWarnings("unused")
private Monitor monitor;
-
- public AnyElementProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
- documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class);
+ //Map<String, NamespaceContext> map = new HashMap<String, NamespaceContext>();
+
+ public AnyElementProcessor(ModelFactoryExtensionPoint modelFactories,
+ Monitor monitor) {
+ xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class);
this.monitor = monitor;
}
-
- public QName getArtifactType() {
- return ANY_ELEMENT;
- }
+ public QName getArtifactType() {
+ return ANY_ELEMENT;
+ }
+
+ public Class<Object> getModelType() {
+ return Object.class;
+ }
- public Class<Object> getModelType() {
- return Object.class;
- }
-
/**
- * Reads the contetns of the unknown elements and generates the DOM
+ * Reads the contetns of the unknown elements and generates a custom
+ * implementation of XMLStreamReader i.e. XMLEventsStreamReader
+ *
* @param reader
- * @param name
* @return
* @throws XMLStreamException
*/
- public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
-
- int event = reader.getEventType();
- int level = 0;
- ArrayList<String> elementList = new ArrayList<String>();
- document = createDocument();
-
- QName name = reader.getName();
-
- while(reader.hasNext()){
- switch(event){
- case START_ELEMENT:
- elementList.add(reader.getName().getLocalPart());
- if(level == 0){
- generateDOM(reader,null);
- level++;
- }
- else{
- generateDOM(reader,elementList.get(elementList.size()-2).toString());
- }
-
- break;
- case END_ELEMENT:
- elementList.remove(reader.getName().getLocalPart());
- }
- if(reader.hasNext()){
- event = reader.next();
- }
-
- if(event == START_ELEMENT || event == END_ELEMENT){
- if(reader.getName().equals(name)){
- break;
- }
- }
- }
- return document;
- }
+ @SuppressWarnings("unchecked")
+ public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
- /**
- * Writes unknown portions back to the writer
- * @param model
- * @param writer
- */
- public void write(Object model, XMLStreamWriter writer) {
+ //Custom variables
+ String currentElement = null;
+ List eventsList = new ArrayList();
- if( ! (model instanceof Document)) {
- return;
- }
+ Map<String, NamespaceContext> eventContext = new HashMap<String, NamespaceContext>();
- Document doc = (Document)model;
try{
- DocumentTraversal traversal = (DocumentTraversal)doc;
- TreeWalker walker = traversal.createTreeWalker(doc.getDocumentElement(),NodeFilter.SHOW_ALL, null, true);
- writeDOM(walker,writer);
- }
- catch(Exception e){
- if (logger.isLoggable(Level.SEVERE)) {
- logger.log(Level.SEVERE, "Document not created ");
- }
- error("Document not created",document,e);
- }
- }
-
- public void resolve(Object arg0, ModelResolver arg1) throws ContributionResolveException {
-
- }
-
- /**
- * Method to generate the DOM
- * @param reader
- * @param parent
- * @throws Exception
- */
- //private void generateDOM(String elementText, String parent) {
- private void generateDOM(XMLStreamReader reader, String parent) {
- try{
- String elePrefix = reader.getPrefix();
- String eleQName = reader.getLocalName();
- if (elePrefix != null && elePrefix.length() != 0) {
- eleQName = elePrefix + ":" + eleQName;
- }
+ //Cast the block of unknown elements into document
+ XMLDocumentStreamReader docReader = new XMLDocumentStreamReader(reader);
+
+ XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(docReader);
- Element element = document.createElementNS(reader.getNamespaceURI(), eleQName);
+ while (xmlEventReader.hasNext()) {
+ XMLEvent event = xmlEventReader.nextEvent();
- int attributeCount = reader.getAttributeCount();
- for(int i = 0;i < attributeCount;i++){
- String ns = reader.getAttributeNamespace(i);
- String prefix = reader.getAttributePrefix(i);
- String qname = reader.getAttributeLocalName(i);
- String value = reader.getAttributeValue(i);
- if (prefix != null && prefix.length() != 0) {
- qname = prefix + ":" + qname;
- }
- element.setAttributeNS(ns,qname,value);
- }
- if(parent == null){
- if(document != null){
- document.appendChild(element);
- }
- else{
- if (logger.isLoggable(Level.SEVERE)) {
- logger.log(Level.SEVERE, "Document not created ");
- }
- error("Document not created",document,element);
+ //Populate the eventContext map with the current element's name and corresponding NamesapceContext
+ if (currentElement != null && !(eventContext.containsKey(currentElement))) {
+ eventContext.put(currentElement, reader.getNamespaceContext());
}
- }
- else{
- Node parentNode = getParentNode(document,parent);
- if(parentNode != null){
- parentNode.appendChild(element);
+
+ //Populate the list with the XMLEvents
+ eventsList.add(event);
+ if (event.isStartElement()) {
+ currentElement = reader.getName().getLocalPart();
}
- else{
- if (logger.isLoggable(Level.SEVERE)) {
- logger.log(Level.SEVERE, "Parent node not found");
- }
- error("Parent node not found",document,parentNode.getNodeName());
+ if (event.isEndDocument()) {
+ return new XMLEventsStreamReader(eventsList, eventContext);
}
}
}
catch(Exception e){
e.printStackTrace();
- if (logger.isLoggable(Level.SEVERE)) {
- logger.log(Level.SEVERE, "Document not created ");
- }
- error("Document not created",document,e);
}
+ return null;
}
/**
- * Method to create an empty document
- * @return
- */
- private Document createDocument() {
- try {
- document = documentBuilderFactory.newDocumentBuilder().newDocument();
- return document;
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Method to traverse the DOM structure and write the elements
- * @param walker
+ * Writes unknown portions back to the writer
+ *
+ * @param model
* @param writer
- * @throws XMLStreamException
*/
- private void writeDOM(TreeWalker walker,XMLStreamWriter writer) throws XMLStreamException {
-
- Node parent = walker.getCurrentNode();
-
- writer.writeStartElement(parent.getPrefix(), parent.getLocalName(), parent.getNamespaceURI());
-
- NamedNodeMap attributes = parent.getAttributes();
-
- for(int i = 0;i<attributes.getLength();i++){
- writer.writeAttribute(attributes.item(i).getPrefix(), attributes.item(i).getNamespaceURI(), attributes.item(i).getLocalName(), attributes.item(i).getNodeValue());
- }
-
- for (Node n = walker.firstChild();n != null;n = walker.nextSibling()) {
- writeDOM(walker,writer);
- }
- writer.writeEndElement();
-
- walker.setCurrentNode(parent);
- }
-
- /**
- * Method to get the Parent node out of the DOM structure
- * @param doc
- * @param parent
- * @return
- */
- private Node getParentNode(Node doc,String parent) {
- Node parentNode = null;
- try{
- DocumentTraversal traversal = (DocumentTraversal)doc;
-
- CharSequence prefixChar = ":";
- NodeIterator iterator = traversal.createNodeIterator(document.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
- for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
- String nodeName = n.getNodeName();
- String[] str = null;
- if(n.getNodeName().contains(prefixChar)){
- str = nodeName.split(":");
- nodeName = str[str.length-1];
- }
- if(parent.equalsIgnoreCase(nodeName)){
- parentNode = n;
- }
- }
- return parentNode;
+ public void write(Object model, XMLStreamWriter writer)
+ throws XMLStreamException {
+ if (!(model instanceof XMLStreamReader)) {
+ return;
}
- catch(Exception e){
- e.printStackTrace();
+ XMLStreamReader reader = (XMLStreamReader) model;
+
+ int event = reader.getEventType();
+ while (reader.hasNext()) {
+ switch (event) {
+ case START_ELEMENT:
+
+ writer.writeStartElement(reader.getPrefix(), reader
+ .getLocalName(), reader.getNamespaceURI());
+ for (int i = 1; i <= reader.getAttributeCount(); i++) {
+ writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i),
+ reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+ }
+ break;
+
+ case CHARACTERS:
+ writer.writeCharacters(reader.getText());
+ break;
+
+ case CDATA:
+ writer.writeCData(reader.getText());
+ break;
+
+ case END_ELEMENT:
+ writer.writeEndElement();
+ break;
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ }
}
- return parentNode;
}
-
- /**
- * Marshals exceptions into the monitor
- *
- * @param problems
- * @param message
- * @param model
- */
- private void error(String message, Object model, Exception ex) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
- monitor.problem(problem);
- }
- }
-
- /**
- * Report a error.
- *
- * @param problems
- * @param message
- * @param model
- */
- private void error(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
- monitor.problem(problem);
- }
- }
-
+
+ public void resolve(Object model, ModelResolver resolver)
+ throws ContributionResolveException {
+ // TODO Auto-generated method stub
+
+ }
+
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java
new file mode 100644
index 0000000000..70398deaa9
--- /dev/null
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java
@@ -0,0 +1,482 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor.xml;
+
+import java.util.NoSuchElementException;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * This class is derived from Apache Axis2 class
+ * org.apache.axis2.util.StreamWrapper</a>. It's used wrap a XMLStreamReader to
+ * create a XMLStreamReader representing a document and it will produce
+ * START_DOCUMENT, END_DOCUMENT events.
+ *
+ * @version $Rev: 659153 $ $Date: 2008-05-22 09:43:58 -0700 (Thu, 22 May 2008) $
+ */
+public class XMLDocumentStreamReader implements XMLStreamReader {
+ private static final int STATE_COMPLETE_AT_NEXT = 2; // The wrapper
+ // will produce
+ // END_DOCUMENT
+
+ private static final int STATE_COMPLETED = 3; // Done
+
+ private static final int STATE_INIT = 0; // The wrapper will produce
+ // START_DOCUMENT
+
+ private static final int STATE_SWITCHED = 1; // The real reader will
+ // produce events
+
+ private XMLStreamReader realReader;
+ private boolean fragment;
+ private int level = 0;
+
+ private int state = STATE_INIT;
+
+ public XMLDocumentStreamReader(XMLStreamReader realReader) {
+ if (realReader == null) {
+ throw new UnsupportedOperationException("Reader cannot be null");
+ }
+
+ this.realReader = realReader;
+
+ if (realReader instanceof XMLFragmentStreamReader) {
+ ((XMLFragmentStreamReader)realReader).init();
+ }
+
+ // If the real reader is positioned at START_DOCUMENT, always use
+ // the real reader
+ if (realReader.getEventType() == START_DOCUMENT) {
+ fragment = false;
+ state = STATE_SWITCHED;
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ realReader.close();
+ }
+
+ public int getAttributeCount() {
+ if (isDelegating()) {
+ return realReader.getAttributeCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeLocalName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public QName getAttributeName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeNamespace(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeType(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(String s, String s1) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(s, s1);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getCharacterEncodingScheme() {
+ return realReader.getCharacterEncodingScheme();
+ }
+
+ public String getElementText() throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.getElementText();
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public String getEncoding() {
+ return realReader.getEncoding();
+ }
+
+ public int getEventType() {
+ int event = -1;
+ switch (state) {
+ case STATE_SWITCHED:
+ case STATE_COMPLETE_AT_NEXT:
+ event = realReader.getEventType();
+ break;
+ case STATE_INIT:
+ event = START_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ event = END_DOCUMENT;
+ break;
+ }
+ return event;
+ }
+
+ public String getLocalName() {
+ if (isDelegating()) {
+ return realReader.getLocalName();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Location getLocation() {
+ if (isDelegating()) {
+ return realReader.getLocation();
+ } else {
+ return null;
+ }
+ }
+
+ public QName getName() {
+ if (isDelegating()) {
+ return realReader.getName();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return realReader.getNamespaceContext();
+ }
+
+ public int getNamespaceCount() {
+ if (isDelegating()) {
+ return realReader.getNamespaceCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespacePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getNamespacePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI() {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI(int i) {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI(String s) {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI(s);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPIData() {
+ if (isDelegating()) {
+ return realReader.getPIData();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPITarget() {
+ if (isDelegating()) {
+ return realReader.getPITarget();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPrefix() {
+ if (isDelegating()) {
+ return realReader.getPrefix();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object getProperty(String s) throws IllegalArgumentException {
+ if (isDelegating()) {
+ return realReader.getProperty(s);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public String getText() {
+ if (isDelegating()) {
+ return realReader.getText();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (isDelegating()) {
+ return realReader.getTextCharacters();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.getTextCharacters(i, chars, i1, i2);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (isDelegating()) {
+ return realReader.getTextLength();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextStart() {
+ if (isDelegating()) {
+ return realReader.getTextStart();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getVersion() {
+ if (isDelegating()) {
+ return realReader.getVersion();
+ } else {
+ return null;
+ }
+ }
+
+ public boolean hasName() {
+ if (isDelegating()) {
+ return realReader.hasName();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ if (state == STATE_COMPLETE_AT_NEXT) {
+ return true;
+ } else if (state == STATE_COMPLETED) {
+ return false;
+ } else if (state == STATE_SWITCHED) {
+ return realReader.hasNext();
+ } else {
+ return true;
+ }
+ }
+
+ public boolean hasText() {
+ if (isDelegating()) {
+ return realReader.hasText();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ if (isDelegating()) {
+ return realReader.isAttributeSpecified(i);
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isCharacters() {
+ if (isDelegating()) {
+ return realReader.isCharacters();
+ } else {
+ return false;
+ }
+ }
+
+ private boolean isDelegating() {
+ return state == STATE_SWITCHED || state == STATE_COMPLETE_AT_NEXT;
+ }
+
+ public boolean isEndElement() {
+ if (isDelegating()) {
+ return realReader.isEndElement();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isStandalone() {
+ if (isDelegating()) {
+ return realReader.isStandalone();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isStartElement() {
+ if (isDelegating()) {
+ return realReader.isStartElement();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isWhiteSpace() {
+ if (isDelegating()) {
+ return realReader.isWhiteSpace();
+ } else {
+ return false;
+ }
+ }
+
+ public int next() throws XMLStreamException {
+ int returnEvent;
+
+ switch (state) {
+ case STATE_SWITCHED:
+ returnEvent = realReader.next();
+ if (returnEvent == END_DOCUMENT) {
+ state = STATE_COMPLETED;
+ } else if (!realReader.hasNext()) {
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ if (fragment && returnEvent == END_ELEMENT) {
+ level--;
+ if (level == -1) {
+ // We are now at the end of the top-level element in the fragment
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ }
+ if (fragment && returnEvent == START_ELEMENT) {
+ level++;
+ }
+ break;
+ case STATE_INIT:
+ state = STATE_SWITCHED;
+ returnEvent = realReader.getEventType();
+ if (returnEvent == START_ELEMENT) {
+ // The real reader is positioned at the top-level element in the fragment
+ level = 0;
+ fragment = true;
+ }
+ break;
+ case STATE_COMPLETE_AT_NEXT:
+ state = STATE_COMPLETED;
+ returnEvent = END_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ // oops - no way we can go beyond this
+ throw new NoSuchElementException("End of stream has reached.");
+ default:
+ throw new UnsupportedOperationException();
+ }
+
+ return returnEvent;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ if (isDelegating()) {
+ int returnEvent = realReader.nextTag();
+ if (fragment && returnEvent == END_ELEMENT) {
+ level--;
+ if (level == 0) {
+ // We are now at the end of the top-level element in the fragment
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ }
+ if (fragment && returnEvent == START_ELEMENT) {
+ level++;
+ }
+ return returnEvent;
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public void require(int i, String s, String s1) throws XMLStreamException {
+ if (isDelegating()) {
+ realReader.require(i, s, s1);
+ }
+ }
+
+ public boolean standaloneSet() {
+ if (isDelegating()) {
+ return realReader.standaloneSet();
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java
new file mode 100644
index 0000000000..351929d8a1
--- /dev/null
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java
@@ -0,0 +1,448 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor.xml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Namespace;
+import javax.xml.stream.events.ProcessingInstruction;
+import javax.xml.stream.events.XMLEvent;
+
+
+public class XMLEventsStreamReader implements XMLStreamReader {
+
+ @SuppressWarnings("unused")
+ private ArrayList<XMLEvent> events = null;
+ @SuppressWarnings("unchecked")
+ private HashMap<String, NamespaceContext> eventContext = null;
+
+ private int state;
+ private java.util.Iterator<XMLEvent> iterator;
+ private XMLEvent current;
+
+ @SuppressWarnings("unchecked")
+ public XMLEventsStreamReader(List<XMLEvent> events,Map<String, NamespaceContext> map) {
+ this.events = (ArrayList<XMLEvent>) events;
+ this.eventContext = (HashMap<String, NamespaceContext>) map;
+ this.iterator = events.iterator();
+ this.current = iterator.next();
+ this.state = current.getEventType();
+ }
+
+ public void close() throws XMLStreamException {
+ this.events = null;
+ this.eventContext = null;
+ this.iterator = null;
+ this.current = null;
+ }
+
+ private void checkElementState() {
+ if (getEventType() != START_ELEMENT && getEventType() != END_ELEMENT) {
+ throw new IllegalStateException();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public int getAttributeCount() {
+ checkElementState();
+ int count = 0;
+ Iterator<Attribute> iterator = current.asStartElement().getAttributes();
+ while (iterator.hasNext()) {
+ count++;
+ iterator.next();
+ }
+ return count;
+ }
+
+ /*
+ * Custom method to get attribute from the specified index
+ */
+ @SuppressWarnings("unchecked")
+ private Attribute getAttribute(int index) {
+ checkElementState();
+ int count = 0;
+ Attribute attribute = null;
+ Iterator<Attribute> iterator = current.asStartElement().getAttributes();
+ while (iterator.hasNext()) {
+ count++;
+ if (count == index) {
+ attribute = iterator.next();
+ } else {
+ iterator.next();
+ }
+ }
+ return attribute;
+ }
+
+
+ public String getAttributeLocalName(int index) {
+ checkElementState();
+ return getAttribute(index).getName().getLocalPart();
+ }
+
+ public QName getAttributeName(int index) {
+ checkElementState();
+ return getAttribute(index).getName();
+ }
+
+ public String getAttributeNamespace(int index) {
+ checkElementState();
+ return getAttributeName(index).getNamespaceURI();
+ }
+
+ public String getAttributePrefix(int index) {
+ checkElementState();
+ return getAttributeName(index).getPrefix();
+ }
+
+ public String getAttributeType(int index) {
+ checkElementState();
+ return getAttribute(index).getDTDType();
+ }
+
+ public String getAttributeValue(int index) {
+ checkElementState();
+ return getAttribute(index).getValue();
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getAttributeValue(String namespaceURI, String localName) {
+ checkElementState();
+ Iterator<Attribute> iterator = current.asStartElement().getAttributes();
+ Attribute attribute;
+ while (iterator.hasNext()) {
+ attribute = iterator.next();
+ if (attribute.getName().getNamespaceURI().equalsIgnoreCase(
+ namespaceURI)
+ && attribute.getName().getLocalPart().equalsIgnoreCase(
+ localName)) {
+ return attribute.getValue();
+ }
+ }
+ return null;
+
+ }
+
+ public String getCharacterEncodingScheme() {
+ return "UTF-8";
+ }
+
+ public String getElementText() throws XMLStreamException {
+ checkElementState();
+ int eventType = getEventType();
+ String elementText = null;
+
+ if (eventType == START_ELEMENT) {
+ elementText = current.asStartElement().getName().getLocalPart();
+ } else if (eventType == END_ELEMENT) {
+ elementText = current.asEndElement().getName().getLocalPart();
+ }
+ return elementText;
+ }
+
+ public String getEncoding() {
+ return "UTF-8";
+ }
+
+ public int getEventType() {
+ return state;
+ }
+
+ public String getLocalName() {
+ checkElementState();
+ switch (current.getEventType()) {
+ case START_ELEMENT:
+ return current.asStartElement().getName().getLocalPart();
+ case END_ELEMENT:
+ return current.asEndElement().getName().getLocalPart();
+ }
+ return null;
+ }
+
+ public Location getLocation() {
+ return current.getLocation();
+ }
+
+ public QName getName() {
+ checkElementState();
+ switch (current.getEventType()) {
+ case START_ELEMENT:
+ return current.asStartElement().getName();
+ case END_ELEMENT:
+ return current.asEndElement().getName();
+ }
+ return null;
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ checkElementState();
+ //return new TuscanyNamespaceContext(eventContext.get(getLocalName()));
+ return eventContext.get(getLocalName());
+ }
+
+ @SuppressWarnings("unchecked")
+ public int getNamespaceCount() {
+ int count = 0;
+ Iterator<Namespace> itr = current.asStartElement().getNamespaces();
+ while (itr.hasNext()) {
+ count++;
+ itr.next();
+ }
+ return count;
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getNamespacePrefix(int index) {
+ Iterator<Namespace> itr = current.asStartElement().getNamespaces();
+ int level = 0;
+ Namespace ns = null;
+ while (itr.hasNext()) {
+ ns = itr.next();
+ if (level == index) {
+ return ns.getPrefix();
+ }
+ level++;
+ }
+ return null;
+ }
+
+ public String getNamespaceURI() {
+ checkElementState();
+ switch (current.getEventType()) {
+ case START_ELEMENT:
+ return current.asStartElement().getName().getNamespaceURI();
+ case END_ELEMENT:
+ return current.asEndElement().getName().getNamespaceURI();
+ }
+ return null;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return getNamespaceContext().getNamespaceURI(prefix);
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getNamespaceURI(int index) {
+ Iterator<Namespace> itr = current.asStartElement().getNamespaces();
+ int level = 0;
+ Namespace ns = null;
+ while (itr.hasNext()) {
+ ns = itr.next();
+ if (level == index) {
+ return ns.getNamespaceURI();
+ }
+ level++;
+ }
+ return null;
+ }
+
+ public String getPIData() {
+ if (current.isProcessingInstruction()) {
+ ProcessingInstruction pi = (ProcessingInstruction) current;
+ return pi.getData();
+ } else {
+ throw new IllegalStateException(current.toString());
+ }
+ }
+
+ public String getPITarget() {
+ if (current.isProcessingInstruction()) {
+ ProcessingInstruction pi = (ProcessingInstruction) current;
+ return pi.getTarget();
+ } else {
+ throw new IllegalStateException(current.toString());
+ }
+ }
+
+ public String getPrefix() {
+ checkElementState();
+ if (current.isStartElement()) {
+ return current.asStartElement().getName().getPrefix();
+ }
+ return null;
+ }
+
+ /*
+ * FIXME: Implementation pending...
+ *
+ * @see (non-Javadoc)
+ * javax.xml.stream.util.StreamReaderDelegate#getProperty(java.lang.String)
+ */
+ public Object getProperty(String name) throws IllegalArgumentException {
+ // TODO Auto-generated method stub
+
+ return null;
+ }
+
+ public String getText() {
+ if (current.isCharacters()) {
+ return current.asCharacters().getData();
+ } else {
+ throw new IllegalStateException(current.toString());
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (current.isCharacters()) {
+ return current.asCharacters().getData().toCharArray();
+ } else {
+ throw new IllegalStateException(current.toString());
+ }
+ }
+
+ /*
+ * FIXME: Implementation pending... (non-Javadoc)
+ *
+ * @see javax.xml.stream.util.StreamReaderDelegate#getTextCharacters(int,
+ * char[], int, int)
+ */
+ public int getTextCharacters(int sourceStart, char[] target,
+ int targetStart, int length) throws XMLStreamException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * FIXME:Implementaion can be improved (non-Javadoc)
+ *
+ * @see javax.xml.stream.util.StreamReaderDelegate#getTextLength()
+ */
+ public int getTextLength() {
+ if (current.isCharacters()) {
+ return current.asCharacters().getData().length();
+ } else {
+ throw new IllegalStateException(current.toString());
+ }
+ }
+
+ /*
+ * FIXME: Implementation pending... (non-Javadoc)
+ *
+ * @see javax.xml.stream.util.StreamReaderDelegate#getTextStart()
+ */
+ public int getTextStart() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * FIXME: Implementation pending... (non-Javadoc)
+ *
+ * @see javax.xml.stream.util.StreamReaderDelegate#getTextStart()
+ */
+ public String getVersion() {
+ // TODO Auto-generated method stub
+
+ return null;
+ }
+
+ public boolean hasName() {
+ return false;
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ return iterator.hasNext() || state != END_DOCUMENT;
+
+ }
+
+ public boolean hasText() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * FIXME: Implementation pending... (non-Javadoc)
+ *
+ * @see javax.xml.stream.util.StreamReaderDelegate#getTextStart()
+ */
+ public boolean isAttributeSpecified(int index) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isCharacters() {
+ return current.isCharacters();
+ }
+
+ public boolean isEndElement() {
+ return current.isEndElement();
+ }
+
+ public boolean isStandalone() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isStartElement() {
+ return current.isStartElement();
+ }
+
+ public boolean isWhiteSpace() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public int next() throws XMLStreamException {
+ if (!hasNext()) {
+ throw new IllegalStateException("No more events");
+ }
+ if (!iterator.hasNext()) {
+ state = END_DOCUMENT;
+ current = null;
+ return state;
+ }
+ current = iterator.next();
+ state = current.getEventType();
+ return state;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ return iterator.next().getEventType();
+ }
+
+ public void require(int type, String namespaceURI, String localName)
+ throws XMLStreamException {
+ boolean require = false;
+ String uri = getNamespaceURI();
+ String name = getLocalName();
+ if (state == type && namespaceURI.equals(uri) && localName.equals(name)) {
+ require = true;
+ }
+ if (require != true) {
+ throw new XMLStreamException();
+ }
+ }
+
+ public boolean standaloneSet() {
+ return false;
+ }
+
+}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java
new file mode 100644
index 0000000000..66361e1d76
--- /dev/null
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLFragmentStreamReader.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+public interface XMLFragmentStreamReader extends XMLStreamReader {
+ QName NIL_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");
+ String NIL_VALUE_TRUE = "true";
+
+ /**
+ * this will help to handle Text within the current element. user should
+ * pass the element text to the property list as this ELEMENT_TEXT as the
+ * key. This key deliberately has a space in it so that it is not a valid
+ * XML name
+ */
+ String ELEMENT_TEXT = "Element Text";
+
+ /**
+ * Extra method to query the state of the pullparser
+ */
+ boolean isDone();
+
+ /**
+ * add the parent namespace context to this parser
+ */
+ void setParentNamespaceContext(NamespaceContext nsContext);
+
+ /**
+ * Initiate the parser - this will do whatever the needed tasks to initiate
+ * the parser and must be called before attempting any specific parsing
+ * using this parser
+ */
+ void init();
+}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
index c293649135..f080f23797 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
@@ -33,6 +33,7 @@ import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
@@ -60,7 +61,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
public ContributionMetadataDocumentProcessor(FactoryExtensionPoint modelFactories,
StAXArtifactProcessor staxProcessor,
Monitor monitor) {
- this.inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
this.staxProcessor = staxProcessor;
this.monitor = monitor;
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
index 02c5d48eb3..631308d2f7 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
@@ -105,63 +105,69 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
return ContributionMetadata.class;
}
- public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException {
ContributionMetadata contribution = null;
QName name = null;
- while (reader.hasNext()) {
- int event = reader.getEventType();
- switch (event) {
- case START_ELEMENT:
- name = reader.getName();
-
- if (CONTRIBUTION_QNAME.equals(name)) {
-
- // Read <contribution>
- contribution = this.contributionFactory.createContributionMetadata();
- contribution.setUnresolved(true);
-
- } else if (DEPLOYABLE_QNAME.equals(name)) {
+ try {
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
- // Read <deployable>
- QName compositeName = getQName(reader, "composite");
- if (compositeName == null) {
- error("AttributeCompositeMissing", reader);
- //throw new ContributionReadException("Attribute 'composite' is missing");
+ if (CONTRIBUTION_QNAME.equals(name)) {
+
+ // Read <contribution>
+ contribution = this.contributionFactory.createContributionMetadata();
+ contribution.setUnresolved(true);
+
+ } else if (DEPLOYABLE_QNAME.equals(name)) {
+
+ // Read <deployable>
+ QName compositeName = getQName(reader, "composite");
+ if (compositeName == null) {
+ error("AttributeCompositeMissing", reader);
+ //throw new ContributionReadException("Attribute 'composite' is missing");
+ } else {
+ if (contribution != null) {
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(compositeName);
+ composite.setUnresolved(true);
+ contribution.getDeployables().add(composite);
+ }
+ }
} else {
- if (contribution != null) {
- Composite composite = assemblyFactory.createComposite();
- composite.setName(compositeName);
- composite.setUnresolved(true);
- contribution.getDeployables().add(composite);
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null && contribution != null) {
+ if (extension instanceof Import) {
+ contribution.getImports().add((Import)extension);
+ } else if (extension instanceof Export) {
+ contribution.getExports().add((Export)extension);
+ }
}
}
- } else {
-
- // Read an extension element
- Object extension = extensionProcessor.read(reader);
- if (extension != null && contribution != null) {
- if (extension instanceof Import) {
- contribution.getImports().add((Import)extension);
- } else if (extension instanceof Export) {
- contribution.getExports().add((Export)extension);
- }
+ break;
+
+ case XMLStreamConstants.END_ELEMENT:
+ if (CONTRIBUTION_QNAME.equals(reader.getName())) {
+ return contribution;
}
- }
- break;
-
- case XMLStreamConstants.END_ELEMENT:
- if (CONTRIBUTION_QNAME.equals(reader.getName())) {
- return contribution;
- }
- break;
- }
-
- //Read the next element
- if (reader.hasNext()) {
- reader.next();
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
}
}
+ catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", reader, ex);
+ }
return contribution;
}
diff --git a/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties b/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
index 3e1a0187fe..4827fd5e94 100644
--- a/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
+++ b/java/sca/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
@@ -18,6 +18,7 @@
# under the License.
#
#
-XMLStreamException = XMLStreamException occured due to:
-IOException = IOException occured due to:
-AttributeCompositeMissing = Attribute 'composite' is missing \ No newline at end of file
+XMLStreamException = XMLStreamException occured due to : {0}
+IOException = IOException occured due to : {0}
+AttributeCompositeMissing = Attribute 'composite' is missing
+