diff options
Diffstat (limited to 'sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor')
31 files changed, 0 insertions, 4102 deletions
diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java deleted file mode 100644 index 5be0b188f4..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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; - -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; - -/** - * Base interface for artifact processors. - * - * @version $Rev$ $Date$ - */ -public interface ArtifactProcessor<M> { - - /** - * Resolve references from this model to other models. For example references - * from a composite to another one, or references from a composite to a WSDL - * model. - * - * @param model The model to resolve - * @param resolver The resolver to use to resolve referenced models - */ - void resolve(M model, ModelResolver resolver) throws ContributionResolveException; - - /** - * Returns the type of model handled by this artifact processor. - * - * @return The type of model handled by this artifact processor - */ - Class<M> getModelType(); - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java deleted file mode 100644 index 029df61f0f..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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; - -/** - * An extension point for artifact processors. - * - * @version $Rev$ $Date$ - */ -public interface ArtifactProcessorExtensionPoint<P extends ArtifactProcessor> { - - /** - * Add an artifact processor. - * - * @param artifactProcessor The artifact processor to add - */ - void addArtifactProcessor(P artifactProcessor); - - /** - * Remove an artifact processor. - * - * @param artifactProcessor The artifact processor to remove - */ - void removeArtifactProcessor(P artifactProcessor); - - /** - * Returns the processor associated with the given artifact type. - * - * @param artifactType An artifact type - * @return The processor associated with the given artifact type - */ - P getProcessor(Object artifactType); - - /** - * Returns the processor associated with the given model type. - * - * @param modelType A model type - * @return The processor associated with the given model type - */ - P getProcessor(Class<?> modelType); - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java deleted file mode 100644 index 158b3d7e64..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java +++ /dev/null @@ -1,539 +0,0 @@ -/* - * 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; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - - -/** - * A base class with utility methods for the other artifact processors in this module. - * - * @version $Rev$ $Date$ - */ -public abstract class BaseStAXArtifactProcessor { - - /** - * Returns a QName from a string. - * @param reader - * @param value - * @return - */ - protected QName getQNameValue(XMLStreamReader reader, String value) { - if (value != null) { - int index = value.indexOf(':'); - String prefix = index == -1 ? "" : value.substring(0, index); - String localName = index == -1 ? value : value.substring(index + 1); - String ns = reader.getNamespaceContext().getNamespaceURI(prefix); - if (ns == null) { - ns = ""; - } - return new QName(ns, localName, prefix); - } else { - return null; - } - } - - /** - * Returns the boolean value of an attribute. - * @param reader - * @param name - * @return - */ - protected boolean getBoolean(XMLStreamReader reader, String name) { - String value = reader.getAttributeValue(null, name); - if (value == null) { - return false; - } - return Boolean.valueOf(value); - } - - /** - * Returns the QName value of an attribute. - * @param reader - * @param name - * @return - */ - protected QName getQName(XMLStreamReader reader, String name) { - String qname = reader.getAttributeValue(null, name); - return getQNameValue(reader, qname); - } - - /** - * Returns the value of an attribute as a list of QNames. - * @param reader - * @param name - * @return - */ - protected List<QName> getQNames(XMLStreamReader reader, String name) { - String value = reader.getAttributeValue(null, name); - if (value != null) { - List<QName> qnames = new ArrayList<QName>(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - qnames.add(getQName(reader, tokens.nextToken())); - } - return qnames; - } else { - return Collections.emptyList(); - } - } - - /** - * Returns the string value of an attribute. - * @param reader - * @param name - * @return - */ - protected String getString(XMLStreamReader reader, String name) { - return reader.getAttributeValue(null, name); - } - - /** - * Test if an attribute is explicitly set - * @param reader - * @param name - * @return - */ - protected boolean isSet(XMLStreamReader reader, String name) { - return reader.getAttributeValue(null, name) != null; - } - - /** - * Returns the value of xsi:type attribute - * @param reader The XML stream reader - * @return The QName of the type, if the attribute is not present, null is - * returned. - */ - protected QName getXSIType(XMLStreamReader reader) { - String qname = reader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); - return getQNameValue(reader, qname); - } - - /** - * Parse the next child element. - * @param reader - * @return - * @throws XMLStreamException - */ - protected boolean nextChildElement(XMLStreamReader reader) throws XMLStreamException { - while (reader.hasNext()) { - int event = reader.next(); - if (event == END_ELEMENT) { - return false; - } - if (event == START_ELEMENT) { - return true; - } - } - return false; - } - - /** - * Advance the stream to the next END_ELEMENT event skipping any nested - * content. - * @param reader the reader to advance - * @throws XMLStreamException if there was a problem reading the stream - */ - protected void skipToEndElement(XMLStreamReader reader) throws XMLStreamException { - int depth = 0; - while (reader.hasNext()) { - int event = reader.next(); - if (event == XMLStreamConstants.START_ELEMENT) { - depth++; - } else if (event == XMLStreamConstants.END_ELEMENT) { - if (depth == 0) { - return; - } - depth--; - } - } - } - - /** - * - * @param writer - * @param uri - * @throws XMLStreamException - */ - private String writeElementPrefix(XMLStreamWriter writer, String uri) throws XMLStreamException { - if (uri == null) { - return null; - } - String prefix = writer.getPrefix(uri); - if (prefix != null) { - return null; - } else { - - // Find an available prefix and bind it to the given URI - NamespaceContext nsc = writer.getNamespaceContext(); - for (int i=1; ; i++) { - prefix = "ns" + i; - if (nsc.getNamespaceURI(prefix) == null) { - break; - } - } - writer.setPrefix(prefix, uri); - return prefix; - } - - } - - /** - * Start an element. - * @param uri - * @param name - * @param attrs - * @throws XMLStreamException - */ - protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException { - String prefix = writeElementPrefix(writer, uri); - writer.writeStartElement(uri, name); - if (prefix != null){ - writer.writeNamespace(prefix,uri); - } - writeAttributePrefixes(writer, attrs); - writeAttributes(writer, attrs); - } - - /** - * Start an element. - * @param qname - * @param attrs - * @throws XMLStreamException - */ - protected void writeStart(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException { - writeStart(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs); - } - - /** - * End an element. - * @param writer - * @throws XMLStreamException - */ - protected void writeEnd(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEndElement(); - } - - /** - * Start a document. - * @param writer - * @throws XMLStreamException - */ - protected void writeStartDocument(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException { - writer.writeStartDocument(); - writer.setDefaultNamespace(uri); - writeStart(writer, uri, name, attrs); - writer.writeDefaultNamespace(uri); - } - - /** - * Start a document. - * @param writer - * @param qname - * @param attrs - * @throws XMLStreamException - */ - protected void writeStartDocument(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException { - writeStartDocument(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs); - } - - /** - * End a document. - * @param writer - * @throws XMLStreamException - */ - protected void writeEndDocument(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEndDocument(); - } - - /** - * Write attributes to the current element. - * @param writer - * @param attrs - * @throws XMLStreamException - */ - protected void writeAttributes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException { - for (XAttr attr : attrs) { - if (attr != null) - attr.write(writer); - } - } - - /** - * Write attribute prefixes to the current element. - * @param writer - * @param attrs - * @throws XMLStreamException - */ - protected void writeAttributePrefixes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException { - for (XAttr attr : attrs) { - if (attr != null) - attr.writePrefix(writer); - } - } - - /** - * Represents an XML attribute that needs to be written to a document. - */ - public static class XAttr { - - private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - - private String uri = SCA11_NS; - private String name; - private Object value; - - public XAttr(String uri, String name, String value) { - this.uri = uri; - this.name = name; - this.value = value; - } - - public XAttr(String name, String value) { - this(null, name, value); - } - - public XAttr(String uri, String name, List<?> values) { - this.uri = uri; - this.name = name; - this.value = values; - } - - public XAttr(String name, List<?> values) { - this(null, name, values); - } - - public XAttr(String uri, String name, Boolean value) { - this.uri = uri; - this.name = name; - this.value = value; - } - - public XAttr(String name, Boolean value) { - this(null, name, value); - } - - public XAttr(String uri, String name, Integer value) { - this.uri = uri; - this.name = name; - this.value = value; - } - - public XAttr(String name, Integer value) { - this(null, name, value); - } - - public XAttr(String uri, String name, Double value) { - this.uri = uri; - this.name = name; - this.value = value; - } - - public XAttr(String name, Double value) { - this(null, name, value); - } - - public XAttr(String uri, String name, QName value) { - this.uri = uri; - this.name = name; - this.value = value; - } - - public XAttr(String name, QName value) { - this(null, name, value); - } - - /** - * Writes a string from a QName and registers a prefix for its namespace. - * @param reader - * @param value - * @return - */ - private String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException { - if (qname != null) { - String prefix = qname.getPrefix(); - String uri = qname.getNamespaceURI(); - prefix = writer.getPrefix(uri); - if (prefix != null) { - - // Use the prefix already bound to the given URI - if (prefix.length() > 0) { - return prefix + ":" + qname.getLocalPart(); - } else { - - // Empty prefix, just return the local part of the given qname - return qname.getLocalPart(); - } - - } else { - - // Find an available prefix and bind it to the given URI - NamespaceContext nsc = writer.getNamespaceContext(); - for (int i=1; ; i++) { - prefix = "ns" + i; - if (nsc.getNamespaceURI(prefix) == null) { - break; - } - } - writer.setPrefix(prefix, uri); - writer.writeNamespace(prefix, uri); - return prefix + ":" + qname.getLocalPart(); - } - } else { - return null; - } - } - - /** - * Registers a prefix for the namespace of a QName. - * @param reader - * @param value - * @return - */ - private void writeQNamePrefix(XMLStreamWriter writer, QName qname) throws XMLStreamException { - if (qname != null) { - String prefix = qname.getPrefix(); - String uri = qname.getNamespaceURI(); - prefix = writer.getPrefix(uri); - if (prefix != null) { - return; - } else { - - // Find an available prefix and bind it to the given URI - NamespaceContext nsc = writer.getNamespaceContext(); - for (int i=1; ; i++) { - prefix = "ns" + i; - if (nsc.getNamespaceURI(prefix) == null) { - break; - } - } - writer.setPrefix(prefix, uri); - writer.writeNamespace(prefix, uri); - } - } - } - - /** - * Write to document - * @param writer - * @throws XMLStreamException - */ - public void write(XMLStreamWriter writer) throws XMLStreamException { - String str; - if (value instanceof QName) { - - // Write a QName - str = writeQNameValue(writer, (QName)value); - - } else if (value instanceof List) { - - // Write a list of values - List<?> values = (List<?>)value; - if (values.isEmpty()) { - return; - } - StringBuffer buffer = new StringBuffer(); - for (Object v: values) { - if (v == null) { - // Skip null values - continue; - } - - if (v instanceof XAttr) { - // Write an XAttr value - ((XAttr)v).write(writer); - continue; - } - - if (buffer.length() != 0) { - buffer.append(' '); - } - if (v instanceof QName) { - // Write a QName value - buffer.append(writeQNameValue(writer, (QName)v)); - } else { - // Write value as a string - buffer.append(String.valueOf(v)); - } - } - str = buffer.toString(); - - } else { - - // Write a string - if (value == null) { - return; - } - str = String.valueOf(value); - } - if (str.length() == 0) { - return; - } - - // Write the attribute - if (uri != null && !uri.equals(SCA11_NS)) { - writer.writeAttribute(uri, name, str); - } else { - writer.writeAttribute(name,str); - } - } - - /** - * Registers a prefix for the namespace of a QName or list of QNames - * @param writer - * @throws XMLStreamException - */ - public void writePrefix(XMLStreamWriter writer) throws XMLStreamException { - if (value instanceof QName) { - - // Write prefix for a single QName value - writeQNamePrefix(writer, (QName)value); - - } else if (value instanceof List) { - - // Write prefixes for a list of values - for (Object v: (List<?>)value) { - if (v instanceof QName) { - // Write prefix for a QName value - writeQNamePrefix(writer, (QName)v); - - } else if (v instanceof XAttr) { - // Write prefix for an XAttr value - ((XAttr)v).writePrefix(writer); - } - } - } - } - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionException.java deleted file mode 100644 index 3b99eba586..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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; - -/** - * Base class for exceptions raised by contribution services. - * - * @version $Rev$ $Date$ - */ -public class ContributionException extends Exception { - - private static final long serialVersionUID = 4432880414927652578L; - - protected ContributionException() { - super(); - } - - protected ContributionException(String message) { - super(message); - } - - protected ContributionException(String message, Throwable cause) { - super(message, cause); - } - - public ContributionException(Throwable cause) { - super(cause); - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionReadException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionReadException.java deleted file mode 100644 index 6fd7d0c91e..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionReadException.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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; - - -/** - * Denotes an exception while reading artifacts inside an SCA contribution. - * - * @version $Rev$ $Date$ - */ -public class ContributionReadException extends ContributionException { - public static final int UNDEFINED = -1; - private static final long serialVersionUID = -7459051598906813461L; - private String resourceURI; - private int line = UNDEFINED; - private int column = UNDEFINED; - - public ContributionReadException(String message) { - super(message); - } - - public ContributionReadException(String message, Throwable cause) { - super(message, cause); - } - - public ContributionReadException(Throwable cause) { - super(cause); - } - - /** - * Returns the location of the resource that was being read. - * - * @return the location of the resource that was being read - */ - public String getResourceURI() { - return resourceURI; - } - - /** - * Sets the location of the resource that was being read. - * - * @param resourceURI the location of the resource that was being read - */ - public void setResourceURI(String resourceURI) { - this.resourceURI = resourceURI; - } - - /** - * Returns the line inside the resource that was being read. - * @return the line inside the resource that was being read - */ - public int getLine() { - return line; - } - - /** - * Sets the line inside the resource that was being read. - * @param line the line inside the resource that was being read - */ - public void setLine(int line) { - this.line = line; - } - - /** - * Returns the column inside the resource that was being read. - * @return the column inside the resource that was being read - */ - public int getColumn() { - return column; - } - - /** - * Sets the column inside the resource that was being read. - * @param column the column inside the resource that was being read - */ - public void setColumn(int column) { - this.column = column; - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionResolveException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionResolveException.java deleted file mode 100644 index fe1a09d398..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionResolveException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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; - - -/** - * Denotes a problem while resolving models inside an SCA contribution. - * - * @version $Rev$ $Date$ - */ -public class ContributionResolveException extends ContributionException { - private static final long serialVersionUID = -7459051598906813461L; - - public ContributionResolveException(String message) { - super(message); - } - - public ContributionResolveException(String message, Throwable cause) { - super(message, cause); - } - - public ContributionResolveException(Throwable cause) { - super(cause); - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionRuntimeException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionRuntimeException.java deleted file mode 100644 index 0039dd9f8b..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionRuntimeException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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; - -/** - * Base class for runtime exceptions raised by contribution services. - * - * @version $Rev$ $Date$ - */ -public class ContributionRuntimeException extends RuntimeException { - private static final long serialVersionUID = 7711215366287498896L; - - protected ContributionRuntimeException() { - super(); - } - - protected ContributionRuntimeException(String message) { - super(message); - } - - protected ContributionRuntimeException(String message, Throwable cause) { - super(message, cause); - } - - public ContributionRuntimeException(Throwable cause) { - super(cause); - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionWriteException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionWriteException.java deleted file mode 100644 index 286c9dc791..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionWriteException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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; - - - -/** - * Denotes an exception while writing artifacts inside an SCA contribution. - * - * @version $Rev$ $Date$ - */ -public class ContributionWriteException extends ContributionException { - private static final long serialVersionUID = -7459051598906813461L; - private String resourceURI; - - public ContributionWriteException(String message) { - super(message); - } - - public ContributionWriteException(String message, Throwable cause) { - super(message, cause); - } - - public ContributionWriteException(Throwable cause) { - super(cause); - } - - /** - * Returns the location of the resource that was being written. - * - * @return the location of the resource that was being written - */ - public String getResourceURI() { - return resourceURI; - } - - /** - * Sets the location of the resource that was being written. - * - * @param resourceURI the location of the resource that was being written - */ - public void setResourceURI(String resourceURI) { - this.resourceURI = resourceURI; - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java deleted file mode 100644 index 3c67a8c550..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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; - -import java.util.HashMap; -import java.util.Map; - -/** - * The default implementation of an artifact processor extension point. - * - * @version $Rev$ $Date$ - */ -abstract class DefaultArtifactProcessorExtensionPoint<P> { - protected final Map<Object, P> processorsByArtifactType = new HashMap<Object, P>(); - protected final Map<Class<?>, P> processorsByModelType = new HashMap<Class<?>, P>(); - - /** - * Constructs a new loader registry. - */ - DefaultArtifactProcessorExtensionPoint() { - } - - /** - * Returns the processor associated with the given artifact type. - * - * @param artifactType An artifact type - * @return The processor associated with the given artifact type - */ - public P getProcessor(Object artifactType) { - return processorsByArtifactType.get(artifactType); - } - - /** - * Returns the processor associated with the given model type. - * - * @param modelType A model type - * @return The processor associated with the given model type - */ - public P getProcessor(Class<?> modelType) { - Class<?>[] classes = modelType.getInterfaces(); - for (Class<?> c : classes) { - P processor = processorsByModelType.get(c); - if (processor != null) { - return processor; - } - } - return processorsByModelType.get(modelType); - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java deleted file mode 100644 index a531eb9ddd..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,378 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.util.Map; -import java.util.Set; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * The default implementation of an extension point for StAX artifact processors. - * - * @version $Rev$ $Date$ - */ -public class DefaultStAXArtifactProcessorExtensionPoint extends - DefaultArtifactProcessorExtensionPoint<StAXArtifactProcessor> implements StAXArtifactProcessorExtensionPoint { - - private ExtensionPointRegistry extensionPoints; - private FactoryExtensionPoint modelFactories; - private MonitorFactory monitorFactory; - private boolean loaded; - private StAXArtifactProcessor<Object> extensibleStAXProcessor; - private StAXAttributeProcessor<Object> extensibleStAXAttributeProcessor; - private Monitor monitor = null; - - /** - * Constructs a new extension point. - */ - public DefaultStAXArtifactProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) { - this.extensionPoints = extensionPoints; - this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); - XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); - UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) - this.monitor = monitorFactory.createMonitor(); - this.extensibleStAXProcessor = new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor); - - StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); - this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor); - } - - /** - * Report a exception. - * - * @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); - } - } - - public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) { - if (artifactProcessor.getArtifactType() != null) { - processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); - } - if (artifactProcessor.getModelType() != null) { - processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); - } - } - - public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) { - if (artifactProcessor.getArtifactType() != null) { - processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); - } - if (artifactProcessor.getModelType() != null) { - processorsByModelType.remove(artifactProcessor.getModelType()); - } - } - - @Override - public StAXArtifactProcessor getProcessor(Class<?> modelType) { - loadArtifactProcessors(); - return super.getProcessor(modelType); - } - - @Override - public StAXArtifactProcessor getProcessor(Object artifactType) { - loadArtifactProcessors(); - return super.getProcessor(artifactType); - } - - /** - * Returns a QName object from a QName expressed as {ns}name - * or ns#name. - * - * @param qname - * @return - */ - private static QName getQName(String qname) { - if (qname == null) { - return null; - } - qname = qname.trim(); - if (qname.startsWith("{")) { - int h = qname.indexOf('}'); - if (h != -1) { - return new QName(qname.substring(1, h), qname.substring(h + 1)); - } - } else { - int h = qname.indexOf('#'); - if (h != -1) { - return new QName(qname.substring(0, h), qname.substring(h + 1)); - } - } - throw new IllegalArgumentException("Invalid qname: "+qname); - } - - /** - * Lazily load artifact processors registered in the extension point. - */ - private synchronized void loadArtifactProcessors() { - if (loaded) - return; - - // Get the processor service declarations - Set<ServiceDeclaration> processorDeclarations; - try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class.getName()); - } catch (IOException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", extensibleStAXProcessor, ie); - throw ie; - } - - for (ServiceDeclaration processorDeclaration : processorDeclarations) { - Map<String, String> attributes = processorDeclaration.getAttributes(); - - // Load a StAX artifact processor - - // Get the model QName - QName artifactType = getQName(attributes.get("qname")); - - // Get the model class name - String modelTypeName = attributes.get("model"); - - // Get the model factory class name - String factoryName = attributes.get("factory"); - - // Create a processor wrapper and register it - StAXArtifactProcessor processor = - new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName, - processorDeclaration, extensionPoints, modelFactories, - extensibleStAXProcessor,extensibleStAXAttributeProcessor, monitor); - addArtifactProcessor(processor); - } - - loaded = true; - } - - /** - * A wrapper around an Artifact processor class allowing lazy loading and - * initialization of artifact processors. - */ - private static class LazyStAXArtifactProcessor implements StAXArtifactProcessor { - - private ExtensionPointRegistry extensionPoints; - private QName artifactType; - private String modelTypeName; - private String factoryName; - private ServiceDeclaration processorDeclaration; - private StAXArtifactProcessor processor; - private Class<?> modelType; - private StAXArtifactProcessor<Object> extensionProcessor; - private StAXAttributeProcessor<Object> extensionAttributeProcessor; - private Monitor monitor; - - LazyStAXArtifactProcessor(QName artifactType, - String modelTypeName, - String factoryName, - ServiceDeclaration processorDeclaration, - ExtensionPointRegistry extensionPoints, - FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> extensionProcessor, - StAXAttributeProcessor<Object> extensionAttributeProcessor, - Monitor monitor) { - - this.extensionPoints = extensionPoints; - this.artifactType = artifactType; - this.modelTypeName = modelTypeName; - this.factoryName = factoryName; - this.processorDeclaration = processorDeclaration; - this.extensionProcessor = extensionProcessor; - this.extensionAttributeProcessor = extensionAttributeProcessor; - this.monitor = monitor; - } - - public QName getArtifactType() { - return artifactType; - } - - 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); - } - } - - @SuppressWarnings("unchecked") - private StAXArtifactProcessor getProcessor() { - if (processor == null) { - - if (processorDeclaration.getClassName() - .equals("org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor")) { - - // Specific initialization for the DefaultBeanModelProcessor - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - try { - Class<StAXArtifactProcessor> processorClass = - (Class<StAXArtifactProcessor>)processorDeclaration.loadClass(); - Object modelFactory; - if (factoryName != null) { - Class<?> factoryClass = (Class<?>)processorDeclaration.loadClass(factoryName); - modelFactory = modelFactories.getFactory(factoryClass); - } else { - modelFactory = null; - } - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, - QName.class, - Class.class, - Object.class, - Monitor.class); - processor = - constructor.newInstance(modelFactories, - artifactType, - getModelType(), - modelFactory, - monitor); - } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); - throw ie; - } - } else { - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - - // Load and instantiate the processor class - try { - Class<StAXArtifactProcessor> processorClass = - (Class<StAXArtifactProcessor>)processorDeclaration.loadClass(); - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); - } catch (NoSuchMethodException e) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, monitor); - } catch (NoSuchMethodException e1) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); - } catch (NoSuchMethodException e2) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, extensionAttributeProcessor, monitor); - } catch (NoSuchMethodException e2a) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); - } catch (NoSuchMethodException e3) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, extensionAttributeProcessor, monitor); - } catch (NoSuchMethodException e3a) { - - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class); - processor = constructor.newInstance(modelFactories); - } catch (NoSuchMethodException e4) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class); - processor = constructor.newInstance(extensionPoints); - } catch (NoSuchMethodException e4a) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor); - } catch (NoSuchMethodException e5) { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor); - } - } - } - } - } - } - } - } - } - } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); - throw ie; - } - } - } - return processor; - } - - public Object read(XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException { - return getProcessor().read(inputSource); - } - - @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, - XMLStreamException { - getProcessor().write(model, outputSource); - } - - public Class<?> getModelType() { - if (modelTypeName != null && modelType == null) { - try { - modelType = processorDeclaration.loadClass(modelTypeName); - } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); - throw ie; - } - } - return modelType; - } - - @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - getProcessor().resolve(model, resolver); - } - - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java deleted file mode 100644 index 3cdcddc976..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.util.Map; -import java.util.Set; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * The default implementation of an extension point for StAX artifact processors. - * - * @version $Rev$ $Date$ - */ -public class DefaultStAXAttributeProcessorExtensionPoint extends - DefaultArtifactProcessorExtensionPoint<StAXAttributeProcessor> implements StAXAttributeProcessorExtensionPoint { - - private ExtensionPointRegistry extensionPoints; - private FactoryExtensionPoint modelFactories; - private StAXAttributeProcessor<Object> extensibleStAXAttributeProcessor; - private boolean loaded; - private Monitor monitor = null; - - /** - * Constructs a new extension point. - */ - public DefaultStAXAttributeProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) { - this.extensionPoints = extensionPoints; - this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); - XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); - UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) { - this.monitor = monitorFactory.createMonitor(); - } - this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor); - } - - /** - * Report a exception. - * - * @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); - } - } - - public void addArtifactProcessor(StAXAttributeProcessor artifactProcessor) { - if (artifactProcessor.getArtifactType() != null) { - processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); - } - if (artifactProcessor.getModelType() != null) { - processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); - } - } - - public void removeArtifactProcessor(StAXAttributeProcessor artifactProcessor) { - if (artifactProcessor.getArtifactType() != null) { - processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); - } - if (artifactProcessor.getModelType() != null) { - processorsByModelType.remove(artifactProcessor.getModelType()); - } - } - - @Override - public StAXAttributeProcessor getProcessor(Class<?> modelType) { - loadArtifactProcessors(); - return super.getProcessor(modelType); - } - - @Override - public StAXAttributeProcessor getProcessor(Object artifactType) { - loadArtifactProcessors(); - return super.getProcessor(artifactType); - } - - /** - * Returns a QName object from a QName expressed as {ns}name - * or ns#name. - * - * @param qname - * @return - */ - private static QName getQName(String qname) { - if (qname == null) { - return null; - } - qname = qname.trim(); - if (qname.startsWith("{")) { - int h = qname.indexOf('}'); - if (h != -1) { - return new QName(qname.substring(1, h), qname.substring(h + 1)); - } - } else { - int h = qname.indexOf('#'); - if (h != -1) { - return new QName(qname.substring(0, h), qname.substring(h + 1)); - } - } - throw new IllegalArgumentException("Invalid qname: "+qname); - } - - /** - * Lazily load artifact processors registered in the extension point. - */ - private synchronized void loadArtifactProcessors() { - if (loaded) - return; - - // Get the processor service declarations - Set<ServiceDeclaration> processorDeclarations; - try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class.getName()); - } catch (IOException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", extensibleStAXAttributeProcessor, ie); - throw ie; - } - - for (ServiceDeclaration processorDeclaration : processorDeclarations) { - Map<String, String> attributes = processorDeclaration.getAttributes(); - - // Load a StAX artifact processor - - // Get the model QName - QName artifactType = getQName(attributes.get("qname")); - - // Get the model class name - String modelTypeName = attributes.get("model"); - - // Get the model factory class name - String factoryName = attributes.get("factory"); - - // Create a processor wrapper and register it - StAXAttributeProcessor processor = - new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName, - processorDeclaration, extensionPoints, modelFactories, - extensibleStAXAttributeProcessor, monitor); - addArtifactProcessor(processor); - } - - loaded = true; - } - - /** - * A wrapper around an Artifact processor class allowing lazy loading and - * initialization of artifact processors. - */ - private static class LazyStAXAttributeProcessor implements StAXAttributeProcessor { - - private ExtensionPointRegistry extensionPoints; - private QName artifactType; - private String modelTypeName; - private String factoryName; - private ServiceDeclaration processorDeclaration; - private StAXAttributeProcessor processor; - private Class<?> modelType; - private StAXAttributeProcessor<Object> extensionProcessor; - private Monitor monitor; - - LazyStAXAttributeProcessor(QName artifactType, - String modelTypeName, - String factoryName, - ServiceDeclaration processorDeclaration, - ExtensionPointRegistry extensionPoints, - FactoryExtensionPoint modelFactories, - StAXAttributeProcessor<Object> extensionProcessor, - Monitor monitor) { - - this.extensionPoints = extensionPoints; - this.artifactType = artifactType; - this.modelTypeName = modelTypeName; - this.factoryName = factoryName; - this.processorDeclaration = processorDeclaration; - this.extensionProcessor = extensionProcessor; - this.monitor = monitor; - } - - public QName getArtifactType() { - return artifactType; - } - - 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); - } - } - - @SuppressWarnings("unchecked") - private StAXAttributeProcessor getProcessor() { - if (processor == null) { - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - - // Load and instantiate the processor class - try { - Class<StAXAttributeProcessor> processorClass = - (Class<StAXAttributeProcessor>)processorDeclaration.loadClass(); - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); - } catch (NoSuchMethodException e) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, monitor); - } catch (NoSuchMethodException e1) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); - } catch (NoSuchMethodException e2) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); - } catch (NoSuchMethodException e3) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class); - processor = constructor.newInstance(modelFactories); - } catch (NoSuchMethodException e4) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class); - processor = constructor.newInstance(extensionPoints); - } catch (NoSuchMethodException e4a) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor); - } catch (NoSuchMethodException e5) { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor); - } - } - } - } - } - } - } - } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); - throw ie; - } - - } - return processor; - } - - public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException { - return getProcessor().read(attributeName, inputSource); - } - - @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { - getProcessor().write(model, outputSource); - } - - public Class<?> getModelType() { - if (modelTypeName != null && modelType == null) { - try { - modelType = processorDeclaration.loadClass(modelTypeName); - } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); - throw ie; - } - } - return modelType; - } - - @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - getProcessor().resolve(model, resolver); - } - - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java deleted file mode 100644 index 86206d4ab2..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.net.URI; -import java.net.URL; -import java.util.Map; -import java.util.Set; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - - -/** - * The default implementation of a URL artifact processor extension point. - * - * @version $Rev$ $Date$ - */ -public class DefaultURLArtifactProcessorExtensionPoint - extends DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor> - implements URLArtifactProcessorExtensionPoint { - - private ExtensionPointRegistry extensionPoints; - private StAXArtifactProcessor<?> staxProcessor; - private boolean loaded; - private Monitor monitor = null; - - /** - * Constructs a new extension point. - */ - public DefaultURLArtifactProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) { - this.extensionPoints = extensionPoints; - FactoryExtensionPoint modelFactories = this.extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); - XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); - UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) - this.monitor = monitorFactory.createMonitor(); - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, this.monitor); - } - - /** - * Report a exception. - * - * @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); - } - } - - public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) { - if (artifactProcessor.getArtifactType() != null) { - processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); - } - if (artifactProcessor.getModelType() != null) { - processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); - } - } - - public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) { - if (artifactProcessor.getArtifactType() != null) { - processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); - } - if (artifactProcessor.getModelType() != null) { - processorsByModelType.remove(artifactProcessor.getModelType()); - } - } - - @Override - public URLArtifactProcessor getProcessor(Class<?> modelType) { - loadProcessors(); - return super.getProcessor(modelType); - } - - @Override - public URLArtifactProcessor getProcessor(Object artifactType) { - loadProcessors(); - return super.getProcessor(artifactType); - } - - /** - * Lazily load artifact processors registered in the extension point. - */ - private synchronized void loadProcessors() { - if (loaded) - return; - - // Get the processor service declarations - Set<ServiceDeclaration> processorDeclarations; - try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class.getName()); - } catch (IOException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", staxProcessor, ie); - throw ie; - } - - for (ServiceDeclaration processorDeclaration: processorDeclarations) { - Map<String, String> attributes = processorDeclaration.getAttributes(); - // Load a URL artifact processor - String artifactType = attributes.get("type"); - String modelTypeName = attributes.get("model"); - - // Create a processor wrapper and register it - URLArtifactProcessor processor = new LazyURLArtifactProcessor(artifactType, modelTypeName, - processorDeclaration, extensionPoints, staxProcessor, monitor); - addArtifactProcessor(processor); - } - - loaded = true; - } - - /** - * A wrapper around an Artifact processor class allowing lazy loading and - * initialization of artifact processors. - */ - private static class LazyURLArtifactProcessor implements URLArtifactProcessor { - - private ExtensionPointRegistry extensionPoints; - private String artifactType; - private String modelTypeName; - private ServiceDeclaration processorDeclaration; - private URLArtifactProcessor processor; - private Class<?> modelType; - private StAXArtifactProcessor<?> staxProcessor; - private Monitor monitor; - - LazyURLArtifactProcessor(String artifactType, - String modelTypeName, - ServiceDeclaration processorDeclaration, - ExtensionPointRegistry extensionPoints, - StAXArtifactProcessor<?> staxProcessor, - Monitor monitor) { - this.artifactType = artifactType; - this.modelTypeName = modelTypeName; - this.processorDeclaration = processorDeclaration; - this.extensionPoints = extensionPoints; - this.staxProcessor = staxProcessor; - this.monitor = monitor; - } - - public String getArtifactType() { - return artifactType; - } - - 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); - } - } - - @SuppressWarnings("unchecked") - private URLArtifactProcessor getProcessor() { - if (processor == null) { - try { - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - Class<URLArtifactProcessor> processorClass = (Class<URLArtifactProcessor>)processorDeclaration.loadClass(); - try { - Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); - } catch (NoSuchMethodException e) { - try { - Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, staxProcessor, monitor); - } catch (NoSuchMethodException e2) { - Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, staxProcessor, monitor); - } - } - } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); - throw ie; - } - } - return processor; - } - - public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { - return getProcessor().read(contributionURL, artifactURI, artifactURL); - } - - public Class<?> getModelType() { - if (modelTypeName != null && modelType == null) { - try { - modelType = processorDeclaration.loadClass(modelTypeName); - } catch (ClassNotFoundException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); - throw ie; - } - } - return modelType; - } - - @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - getProcessor().resolve(model, resolver); - } - - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java deleted file mode 100644 index 9258a837d8..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.net.URL; -import java.net.URLConnection; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.List; - -import javax.xml.XMLConstants; -import javax.xml.stream.EventFilter; -import javax.xml.stream.StreamFilter; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLReporter; -import javax.xml.stream.XMLResolver; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.util.XMLEventAllocator; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * Default implementation of an XMLInputFactory that creates validating - * XMLStreamReaders. - * - * @version $Rev$ $Date$ - */ -public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory { - - private XMLInputFactory inputFactory; - private ValidationSchemaExtensionPoint schemas; - private Monitor monitor; - private boolean initialized; - private boolean hasSchemas; - private Schema aggregatedSchema; - - public DefaultValidatingXMLInputFactory(ExtensionPointRegistry registry) { - FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class); - XMLInputFactory factory = factoryExtensionPoint.getFactory(XMLInputFactory.class); - this.inputFactory = factory; - this.schemas = registry.getExtensionPoint(ValidationSchemaExtensionPoint.class); - this.monitor = - registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class).createMonitor(); - } - - /** - * Constructs a new XMLInputFactory. - * - * @param inputFactory - * @param schemas - */ - public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas, Monitor monitor) { - this.inputFactory = inputFactory; - this.schemas = schemas; - this.monitor = monitor; - } - - /** - * Report a exception. - * - * @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); - } - } - - /** - * Initialize the registered schemas and create an aggregated schema for - * validation. - */ - private void initializeSchemas() { - if (initialized) { - return; - } - initialized = true; - - // Load the XSDs registered in the validation schema extension point - try { - List<String> uris = schemas.getSchemas(); - int n = uris.size(); - if (n ==0) { - return; - } else { - hasSchemas = true; - } - final Source[] sources = new Source[n]; - for (int i =0; i < n; i++) { - final String uri = uris.get(i); - // Allow privileged access to open URL stream. Requires FilePermission in security policy. - final URL url = new URL( uri ); - InputStream urlStream; - try { - urlStream = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() { - public InputStream run() throws IOException { - URLConnection connection = url.openConnection(); - connection.setUseCaches(false); - return connection.getInputStream(); - } - }); - } catch (PrivilegedActionException e) { - error("PrivilegedActionException", url, (IOException)e.getException()); - throw (IOException)e.getException(); - } - sources[i] = new StreamSource(urlStream, uri); - } - - // Create an aggregated validation schemas from all the XSDs - final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - // Allow privileged access to check files. Requires FilePermission - // in security policy. - try { - aggregatedSchema = AccessController.doPrivileged(new PrivilegedExceptionAction<Schema>() { - public Schema run() throws SAXException { - return schemaFactory.newSchema(sources); - } - }); - } catch (PrivilegedActionException e) { - error("PrivilegedActionException", schemaFactory, (SAXException)e.getException()); - throw (SAXException)e.getException(); - } - - } catch (Error e) { - // FIXME Log this, some old JDKs don't support XMLSchema validation - //e.printStackTrace(); - } catch (SAXParseException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", schemas, ie); - throw ie; - } catch (Exception e) { - //FIXME Log this, some old JDKs don't support XMLSchema validation - e.printStackTrace(); - } - } - - @Override - public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException { - return inputFactory.createFilteredReader(arg0, arg1); - } - - @Override - public XMLStreamReader createFilteredReader(XMLStreamReader arg0, StreamFilter arg1) throws XMLStreamException { - return inputFactory.createFilteredReader(arg0, arg1); - } - - @Override - public XMLEventReader createXMLEventReader(InputStream arg0, String arg1) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0, arg1); - } - - @Override - public XMLEventReader createXMLEventReader(InputStream arg0) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0); - } - - @Override - public XMLEventReader createXMLEventReader(Reader arg0) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0); - } - - @Override - public XMLEventReader createXMLEventReader(Source arg0) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0); - } - - @Override - public XMLEventReader createXMLEventReader(String arg0, InputStream arg1) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0, arg1); - } - - @Override - public XMLEventReader createXMLEventReader(String arg0, Reader arg1) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0, arg1); - } - - @Override - public XMLEventReader createXMLEventReader(XMLStreamReader arg0) throws XMLStreamException { - return inputFactory.createXMLEventReader(arg0); - } - - @Override - public XMLStreamReader createXMLStreamReader(InputStream arg0, String arg1) throws XMLStreamException { - initializeSchemas(); - if (hasSchemas) { - return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); - }else { - return inputFactory.createXMLStreamReader(arg0, arg1); - } - } - - @Override - public XMLStreamReader createXMLStreamReader(InputStream arg0) throws XMLStreamException { - initializeSchemas(); - if (hasSchemas) { - return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); - } else { - return inputFactory.createXMLStreamReader(arg0); - } - } - - @Override - public XMLStreamReader createXMLStreamReader(Reader arg0) throws XMLStreamException { - initializeSchemas(); - if (hasSchemas) { - return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); - } else { - return inputFactory.createXMLStreamReader(arg0); - } - } - - @Override - public XMLStreamReader createXMLStreamReader(Source arg0) throws XMLStreamException { - initializeSchemas(); - if (hasSchemas) { - return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); - } else { - return inputFactory.createXMLStreamReader(arg0); - } - } - - @Override - public XMLStreamReader createXMLStreamReader(String arg0, InputStream arg1) throws XMLStreamException { - initializeSchemas(); - if (hasSchemas) { - return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); - } else { - return inputFactory.createXMLStreamReader(arg0, arg1); - } - } - - @Override - public XMLStreamReader createXMLStreamReader(String arg0, Reader arg1) throws XMLStreamException { - initializeSchemas(); - if (hasSchemas) { - return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); - } else { - return inputFactory.createXMLStreamReader(arg0, arg1); - } - } - - @Override - public XMLEventAllocator getEventAllocator() { - return inputFactory.getEventAllocator(); - } - - @Override - public Object getProperty(String arg0) throws IllegalArgumentException { - return inputFactory.getProperty(arg0); - } - - @Override - public XMLReporter getXMLReporter() { - return inputFactory.getXMLReporter(); - } - - @Override - public XMLResolver getXMLResolver() { - return inputFactory.getXMLResolver(); - } - - @Override - public boolean isPropertySupported(String arg0) { - return inputFactory.isPropertySupported(arg0); - } - - @Override - public void setEventAllocator(XMLEventAllocator arg0) { - inputFactory.setEventAllocator(arg0); - } - - @Override - public void setProperty(String arg0, Object arg1) throws IllegalArgumentException { - inputFactory.setProperty(arg0, arg1); - } - - @Override - public void setXMLReporter(XMLReporter arg0) { - inputFactory.setXMLReporter(arg0); - } - - @Override - public void setXMLResolver(XMLResolver arg0) { - inputFactory.setXMLResolver(arg0); - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java deleted file mode 100644 index 9f4094aa12..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; - -/** - * Default implementation of an extension point for XML schemas. - * - * @version $Rev$ $Date$ - */ -public class DefaultValidationSchemaExtensionPoint implements ValidationSchemaExtensionPoint { - - private List<String> schemas = new ArrayList<String>(); - private boolean loaded; - - public void addSchema(String uri) { - schemas.add(uri); - } - - public void removeSchema(String uri) { - schemas.remove(uri); - } - - /** - * Load schema declarations from META-INF/services/ - * org.apache.tuscany.sca.contribution.processor.ValidationSchema files - */ - private synchronized void loadSchemas() { - if (loaded) - return; - - // Get the schema declarations - Set<ServiceDeclaration> schemaDeclarations; - try { - schemaDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations("org.apache.tuscany.sca.contribution.processor.ValidationSchema"); - } catch (IOException e) { - throw new IllegalStateException(e); - } - - // TODO - temp fix to ensure that the schema tuscany-sca.xsd always comes first - String tuscanyScaXsd = null; - - // Find each schema - for (ServiceDeclaration schemaDeclaration: schemaDeclarations) { - URL url = schemaDeclaration.getResource(schemaDeclaration.getClassName()); - if (url == null) { - throw new IllegalArgumentException(new FileNotFoundException(schemaDeclaration.getClassName())); - } - - if (url.toString().contains("tuscany-sca.xsd")){ - tuscanyScaXsd = url.toString(); - } else { - schemas.add(url.toString()); - } - } - - if (tuscanyScaXsd != null){ - schemas.add(0, tuscanyScaXsd); - } - - loaded = true; - } - - public List<String> getSchemas() { - loadSchemas(); - return schemas; - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java deleted file mode 100644 index 7578a24ea8..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; -import javax.xml.stream.Location; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamConstants; -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.resolver.ModelResolver; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * Implementation of an extensible StAX artifact processor. - * - * Takes a StAXArtifactProcessorExtensionPoint and delegates to the proper - * StAXArtifactProcessor by element QName - * - * @version $Rev$ $Date$ - */ -public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Object> { - private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName()); - - private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement"); - - private XMLInputFactory inputFactory; - private XMLOutputFactory outputFactory; - private StAXArtifactProcessorExtensionPoint processors; - private Monitor monitor; - - /** - * Constructs a new ExtensibleStAXArtifactProcessor. - * @param processors - * @param inputFactory - * @param outputFactory - */ - public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors, - XMLInputFactory inputFactory, - XMLOutputFactory outputFactory, - Monitor monitor) { - super(); - this.processors = processors; - this.inputFactory = inputFactory; - this.outputFactory = outputFactory; - if (this.outputFactory != null) { - this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); - } - this.monitor = monitor; - } - - /** - * Report a warning. - * - * @param problems - * @param message - * @param model - */ - private void warning(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); - 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); - } - } - - /** - * Report a exception. - * - * @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); - } - } - - - public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException { - - // Delegate to the processor associated with the element QName - int event = source.getEventType(); - if (event == XMLStreamConstants.START_DOCUMENT) { - source.nextTag(); - } - QName name = source.getName(); - StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>)processors.getProcessor(name); - if (processor == null) { - Location location = source.getLocation(); - if (logger.isLoggable(Level.WARNING)) { - logger.warning("Element " + name + " cannot be processed. (" + location + ")"); - } - warning("ElementCannotBeProcessed", processors, name, location); - - StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); - if(anyElementProcessor != null) { - return anyElementProcessor.read(source); - } else { - return null; - } - } - return processor.read(source); - } - - @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { - - // Delegate to the processor associated with the model type - if (model != null) { - StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); - if (processor != null) { - processor.write(model, outputSource); - } else { - if (logger.isLoggable(Level.WARNING)) { - logger.warning("No StAX processor is configured to handle " + model.getClass()); - } - warning("NoStaxProcessor", processors, model.getClass()); - StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); - if(anyElementProcessor != null) { - anyElementProcessor.write(model, outputSource); - } - } - } - } - - @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - - // Delegate to the processor associated with the model type - if (model != null) { - StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); - if (processor != null) { - processor.resolve(model, resolver); - } - } - } - - /** - * Read a model from an InputStream. - * @param is The artifact InputStream - * @param type Model type - * @return The model - * @throws ContributionReadException - */ - public <M> M read(InputStream is, Class<M> type) throws ContributionReadException { - try { - XMLStreamReader reader; - try { - reader = inputFactory.createXMLStreamReader(is); - try { - reader.nextTag(); - QName name = reader.getName(); - Object mo = read(reader); - if (type.isInstance(mo)) { - return type.cast(mo); - } else { - error("UnrecognizedElementException", reader, name); - UnrecognizedElementException e = new UnrecognizedElementException(name); - throw e; - } - } catch (ContributionReadException e) { - Location location = reader.getLocation(); - e.setLine(location.getLineNumber()); - e.setColumn(location.getColumnNumber()); - error("ContributionReadException", reader, e); - throw e; - } finally { - try { - reader.close(); - } catch (XMLStreamException e) { - // ignore - } - } - } finally { - try { - is.close(); - } catch (IOException e) { - // ignore - } - } - } catch (XMLStreamException e) { - ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); - throw ce; - } - } - - /** - * Write a model to an OutputStream. - * @param model - * @param os - * @throws ContributionWriteException - */ - public void write(Object model, OutputStream os) throws ContributionWriteException { - try { - XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); - write(model, writer); - writer.flush(); - writer.close(); - } catch (XMLStreamException e) { - ContributionWriteException cw = new ContributionWriteException(e); - error("ContributionWriteException", outputFactory, cw); - throw cw; - } - } - - public QName getArtifactType() { - return null; - } - - public Class<Object> getModelType() { - return null; - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java deleted file mode 100644 index c336cb3431..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * 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; - -import java.io.InputStream; -import java.io.OutputStream; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; -import javax.xml.stream.Location; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamConstants; -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.resolver.ModelResolver; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * Implementation of an extensible StAX attribute processor. - * - * Takes a StAXAttributeProcessorExtensionPoint and delegates to the proper - * StAXAttributeProcessor by attribute QName - * - * @version $Rev$ $Date$ - */ -public class ExtensibleStAXAttributeProcessor - implements StAXAttributeProcessor<Object> { - - private static final Logger logger = Logger.getLogger(ExtensibleStAXAttributeProcessor.class.getName()); - - private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute"); - - private XMLInputFactory inputFactory; - private XMLOutputFactory outputFactory; - private StAXAttributeProcessorExtensionPoint processors; - private Monitor monitor; - - /** - * Constructs a new ExtensibleStAXArtifactProcessor. - * @param processors - * @param inputFactory - * @param outputFactory - */ - public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors, - XMLInputFactory inputFactory, - XMLOutputFactory outputFactory, - Monitor monitor) { - super(); - this.processors = processors; - this.inputFactory = inputFactory; - this.outputFactory = outputFactory; - if (this.outputFactory != null) { - this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); - } - this.monitor = monitor; - } - - /** - * Report a warning. - * - * @param problems - * @param message - * @param model - */ - private void warning(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); - 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); - } - } - - /** - * Report a exception. - * - * @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); - } - } - - - public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException, XMLStreamException { - // Delegate to the processor associated with the attribute QName - int event = source.getEventType(); - if (event == XMLStreamConstants.START_DOCUMENT) { - source.nextTag(); - } - - StAXAttributeProcessor<?> processor = null; - - //lookup for registered attribute processors - processor = (StAXAttributeProcessor<?>)processors.getProcessor(attributeName); - if (processor == null) { - Location location = source.getLocation(); - if (logger.isLoggable(Level.WARNING)) { - logger.warning("Attribute " + attributeName + " cannot be processed. (" + location + ")"); - } - warning("AttributeCannotBeProcessed", processors, attributeName, location); - } else { - return processor.read(attributeName, source); - } - - - //handle extension attributes without processors - processor = (StAXAttributeProcessor<?>)processors.getProcessor(ANY_ATTRIBUTE); - if (processor == null) { - Location location = source.getLocation(); - if (logger.isLoggable(Level.WARNING)) { - logger.warning("Could not find Default Attribute processor !"); - } - warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location); - } - - return processor == null ? null : processor.read(attributeName, source); - } - - @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { - - if(model == null) { - return; - } - - // Delegate to the processor associated with the model type - StAXAttributeProcessor processor = processors.getProcessor(model.getClass()); - if(processor == null) { - if (logger.isLoggable(Level.WARNING)) { - logger.warning("No StAX processor is configured to handle " + model.getClass()); - } - warning("NoStaxProcessor", processors, model.getClass()); - } else { - processor.write(model, outputSource); - return; - } - - //handle extension attributes without processors - processor = (StAXAttributeProcessor<?>)processors.getProcessor(ANY_ATTRIBUTE); - if(processor == null) { - if (logger.isLoggable(Level.WARNING)) { - logger.warning("No Default StAX processor is configured to handle " + model.getClass()); - } - warning("NoDefaultStaxProcessor", processors, model.getClass()); - } else { - processor.write(model, outputSource); - return; - } - } - - - - @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - - // Delegate to the processor associated with the model type - if (model != null) { - StAXAttributeProcessor processor = processors.getProcessor(model.getClass()); - if (processor != null) { - processor.resolve(model, resolver); - } - } - } - - /** - * Read a model from an InputStream. - * @param is The artifact InputStream - * @param type Model type - * @return The model - * @throws ContributionReadException - */ - public <M> M read(InputStream is, Class<M> type) throws ContributionReadException { - return null; - } - - /** - * Write a model to an OutputStream. - * @param model - * @param os - * @throws ContributionWriteException - */ - public void write(Object model, OutputStream os) throws ContributionWriteException { - try { - XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); - write(model, writer); - writer.flush(); - writer.close(); - } catch (XMLStreamException e) { - ContributionWriteException cw = new ContributionWriteException(e); - error("ContributionWriteException", outputFactory, cw); - throw cw; - } - } - - public QName getArtifactType() { - return null; - } - - public Class<Object> getModelType() { - return null; - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java deleted file mode 100644 index d867667eae..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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; - -import java.net.URI; -import java.net.URL; - -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * Implementation of an extensible URL artifact processor. - * - * Takes a URLArtifactProcessorExtensionPoint and delegates to the proper URLArtifactProcessor - * by either fileName or fileExtention - * - * @version $Rev$ $Date$ - */ -public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Object> { - - private URLArtifactProcessorExtensionPoint processors; - private Monitor monitor; - - /** - * Constructs a new ExtensibleURLArtifactProcessor. - * - * @param processors - */ - public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors, Monitor monitor) { - this.processors = processors; - this.monitor = monitor; - } - - /** - * 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); - } - } - - @SuppressWarnings("unchecked") - public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException { - URLArtifactProcessor<Object> processor = null; - if (sourceURI != null) { - //try to retrieve a processor for the specific URI - String uri = sourceURI.toString(); - if (!uri.startsWith("/")) { - uri = "/" + uri; - } - // Register the URI as the artifact type starts with / - processor = (URLArtifactProcessor<Object>)processors.getProcessor(uri); - } - if (processor == null) { - // Delegate to the processor associated with file extension - String fileName = getFileName(sourceURL); - - //try to retrieve a processor for the specific filename - processor = (URLArtifactProcessor<Object>)processors.getProcessor(fileName); - } - - if (processor == null) { - //try to find my file type (extension) - String extension = sourceURL.getPath(); - - int extensionStart = extension.lastIndexOf('.'); - //handle files without extension (e.g NOTICE) - if (extensionStart > 0) { - // File extensions are registered as .<extension> - extension = extension.substring(extensionStart); - processor = (URLArtifactProcessor<Object>)processors.getProcessor(extension); - } - } - - if (processor == null) { - return null; - } - return processor.read(contributionURL, sourceURI, sourceURL); - } - - @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - - // Delegate to the processor associated with the model type - if (model != null) { - URLArtifactProcessor processor = processors.getProcessor(model.getClass()); - if (processor != null) { - processor.resolve(model, resolver); - } - } - } - - public <M> M read(URL contributionURL, URI artifactURI, URL artifactUrl, Class<M> type) - throws ContributionReadException { - Object mo = read(contributionURL, artifactURI, artifactUrl); - if (type.isInstance(mo)) { - return type.cast(mo); - } else { - UnrecognizedElementException e = new UnrecognizedElementException(null); - e.setResourceURI(artifactURI.toString()); - error("UnrecognizedElementException", processors, artifactURI.toString()); - throw e; - } - } - - public String getArtifactType() { - return null; - } - - public Class<Object> getModelType() { - return null; - } - - /** - * Returns the file name from a URL. - * @param url - * @return - */ - private static String getFileName(URL url) { - String fileName = url.getPath(); - int pos = fileName.lastIndexOf("/"); - - return fileName.substring(pos + 1); - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java deleted file mode 100644 index 1bf9b4d494..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - - -/** - * An artifact processor that can read models from a StAX XMLStreamReader. - * - * @version $Rev$ $Date$ - */ -public interface StAXArtifactProcessor<M> extends ArtifactProcessor<M> { - - /** - * Reads a model from an XMLStreamReader. - * - * @param reader The XMLStreamReader - * @return A model representation of the input. - */ - M read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException; - - /** - * Writes a model to an XMLStreamWriter. - * - * @param model A model representing the source - * @param writer The XML stream writer - * @throws ContributionWriteException - * @throws XMLStreamException - */ - void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException; - - /** - * Returns the type of artifact handled by this artifact processor. - * - * @return The type of artifact handled by this artifact processor - */ - QName getArtifactType(); -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java deleted file mode 100644 index 9700e2bc60..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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; - -/** - * An extension point for StAX artifact processors. - * - * @version $Rev$ $Date$ - */ -public interface StAXArtifactProcessorExtensionPoint extends - ArtifactProcessorExtensionPoint<StAXArtifactProcessor> { - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java deleted file mode 100644 index b25bf0d669..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - - - -/** - * An artifact processor that can read attributes from a StAX XMLStreamReader. - * - * @version $Rev$ $Date$ - */ -public interface StAXAttributeProcessor<M> extends ArtifactProcessor<M>{ - - /** - * Reads a model from an XMLStreamReader. - * - * @param reader The XMLStreamReader - * @return A model representation of the input. - */ - M read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException; - - /** - * Writes a model to an XMLStreamWriter. - * - * @param model A model representing the source - * @param writer The XML stream writer - * @throws ContributionWriteException - * @throws XMLStreamException - */ - void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException; - - /** - * Returns the type of artifact handled by this artifact processor. - * - * @return The type of artifact handled by this artifact processor - */ - QName getArtifactType(); - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java deleted file mode 100644 index ebad243c1c..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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; - -/** - * An extension point for StAX artifact processors. - * - * @version $Rev$ $Date$ - */ -public interface StAXAttributeProcessorExtensionPoint extends - ArtifactProcessorExtensionPoint<StAXAttributeProcessor> { - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java deleted file mode 100644 index 2ddba7527e..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Stack; - -import javax.xml.namespace.NamespaceContext; - -/** - * Tuscany specialized class to handle NamespaceContext - * - */ -public class TuscanyNamespaceContext implements NamespaceContext { - - private Stack<List<String>[]> context = null; - - public TuscanyNamespaceContext(Stack<List<String>[]> context) { - this.context = context; - } - - public String getNamespaceURI(String prefix) { - if (prefix == null) { - throw new IllegalArgumentException(); - } - return (String)getResult("getNSUri", prefix); - } - - public String getPrefix(String namespaceURI) { - if (namespaceURI == null) { - throw new IllegalArgumentException(); - } - return (String)getResult("getPrefix", namespaceURI); - } - - @SuppressWarnings("unchecked") - public Iterator<String> getPrefixes(String namespaceURI) { - if (namespaceURI == null) { - throw new IllegalArgumentException(); - } - - Iterator<String> iterator = (Iterator<String>)getResult("getPrefixes", namespaceURI); - return iterator; - } - - /* - * Generic method to Iterate through the Stack and return required result(s) - */ - private Object getResult(String operation, String arg) { - - List<String>[] contextList = null; - Iterator<String> prefItr = null; - Iterator<String> uriItr = null; - - List<String> list = new ArrayList<String>(); - - String toCompare = null; - - String tempPrefix = null; - String tempUri = null; - - for (int i = context.size() - 1; i >= 0; i--) { - contextList = context.get(i); - prefItr = contextList[0].iterator(); - uriItr = contextList[1].iterator(); - while (uriItr.hasNext()) { - tempPrefix = prefItr.next(); - tempUri = uriItr.next(); - if (operation.equalsIgnoreCase("getNSUri")) { - toCompare = tempPrefix; - } else if (operation.equalsIgnoreCase("getPrefix")) { - toCompare = tempUri; - } else if (operation.equalsIgnoreCase("getPrefixes")) { - toCompare = tempUri; - } - if (toCompare != null && arg.equalsIgnoreCase(toCompare)) { - if (operation.equalsIgnoreCase("getNSUri")) { - return tempUri; - } else if (operation.equalsIgnoreCase("getPrefix")) { - return tempPrefix; - } else if (operation.equalsIgnoreCase("getPrefixes")) { - list.add(tempPrefix); - } - - } - } - } - - if (operation.equalsIgnoreCase("getPrefixes")) { - return Collections.unmodifiableList(list).iterator(); - } - - return null; - } -}
\ No newline at end of file diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java deleted file mode 100644 index 3352e76a0d..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.util.StreamReaderDelegate; - -/* - * Custom implementaion of the XMLStreamReader to keep track of the namespace context for each element - */ -public class TuscanyXMLStreamReader extends StreamReaderDelegate implements XMLStreamReader { - - Stack<List<String>[]> context = new Stack<List<String>[]>(); - - List<String>[] contextList; - List<String> prefixList; - List<String> uriList; - - public TuscanyXMLStreamReader(XMLStreamReader reader) { - super(reader); - } - - public void pushContext() throws XMLStreamException { - contextList = new List[2]; - prefixList = new ArrayList<String>(); - uriList = new ArrayList<String>(); - int namespaceCount = this.getNamespaceCount(); - for (int i = 0; i < namespaceCount; i++) { - prefixList.add(checkString(this.getNamespacePrefix(i))); - uriList.add(this.getNamespaceURI(i)); - } - contextList[0] = prefixList; - contextList[1] = uriList; - context.push(contextList); - } - - private String checkString(String namespacePrefix) { - if (namespacePrefix == null) { - return XMLConstants.DEFAULT_NS_PREFIX; - } else { - return namespacePrefix; - } - } - - public void popContext() throws XMLStreamException { - context.pop(); - } - - /* - * Overriding the next() method to perform PUSH and POP operations - * for the NamespaceContext for the current element - */ - - @Override - public int next() throws XMLStreamException { - // POP the context if the element ends - if (this.getEventType() == END_ELEMENT) { - popContext(); - } - - //get the next event - int nextEvent = super.next(); - //PUSH the events info onto the Stack - if (nextEvent == START_ELEMENT) { - pushContext(); - } - return nextEvent; - } - - @Override - public int nextTag() throws XMLStreamException { - int event = super.nextTag(); - if (event == START_ELEMENT) { - pushContext(); - } - if (event == END_ELEMENT) { - popContext(); - } - return event; - } - - @Override - public NamespaceContext getNamespaceContext() { - return new TuscanyNamespaceContext((Stack<List<String>[]>)context.clone()); - } -}
\ No newline at end of file diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java deleted file mode 100644 index c44ca0c66a..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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; - -import java.net.URI; -import java.net.URL; - - -/** - * An artifact processor that can read models from a URL. - * - * @version $Rev$ $Date$ - */ -public interface URLArtifactProcessor<M> extends ArtifactProcessor<M> { - - /** - * Reads a model from a URL. - * - * @param contributionURL Contribution location URL - * @param artifactURI Artifact URI - * @param artifactURL Artifact location URL - * @return A model representation of the input. - */ - M read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException; - - /** - * Returns the type of artifact handled by this artifact processor. - * - * @return The type of artifact handled by this artifact processor - */ - String getArtifactType(); - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java deleted file mode 100644 index 7714586951..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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; - -/** - * An extension point for URL artifact processors. - * - * @version $Rev$ $Date$ - */ -public interface URLArtifactProcessorExtensionPoint extends - ArtifactProcessorExtensionPoint<URLArtifactProcessor> { - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnrecognizedElementException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnrecognizedElementException.java deleted file mode 100644 index 4c6f0b7282..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnrecognizedElementException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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; - -import javax.xml.namespace.QName; - -/** - * Exception that indicates an element was encountered that could not be handled. - * - * @version $Rev$ $Date$ - */ -public class UnrecognizedElementException extends ContributionReadException { - private static final long serialVersionUID = 2549543622209829032L; - private final QName element; - - /** - * Constructor that indicates which element could not be handled. - * @param element the element that could not be handled - */ - public UnrecognizedElementException(QName element) { - super("Unrecognized element: " + element); - this.element = element; - } - - /** - * Returns the element that could not be handled. - * @return the element that could not be handled. - */ - public QName getElement() { - return element; - } -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnsupportedContentTypeException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnsupportedContentTypeException.java deleted file mode 100644 index 8a166e42f0..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnsupportedContentTypeException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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; - - -/** - * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain. - * The Content-Type value supplied will be returned as the message text for this exception. - * - * FIXME Don't use as it's deprecated and replaced by UnsupportedPackageTypeException. - * - * @version $Rev$ $Date$ - */ -@Deprecated -public class UnsupportedContentTypeException extends ContributionException { - private static final long serialVersionUID = -1831797280021355672L; - - /** - * Constructs a new UnsupportedContentTypeException. - * - * @param message - */ - public UnsupportedContentTypeException(String message) { - super(message); - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnsupportedPackageTypeException.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnsupportedPackageTypeException.java deleted file mode 100644 index ce94cef6a0..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/UnsupportedPackageTypeException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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; - - -/** - * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain. - * The Content-Type value supplied will be returned as the message text for this exception. - * - * @version $Rev$ $Date$ - */ -public class UnsupportedPackageTypeException extends ContributionException { - private static final long serialVersionUID = -1831797280021355672L; - - /** - * Constructs a new UnsupportedPackageTypeException. - * - * @param message - */ - public UnsupportedPackageTypeException(String message) { - super(message); - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java deleted file mode 100644 index c0eef5a7a8..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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; - -import javax.xml.stream.XMLInputFactory; - -/** - * Base marker class for validating XML input factories. - * - * @version $Rev$ $Date$ - */ -public abstract class ValidatingXMLInputFactory extends XMLInputFactory { -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java deleted file mode 100644 index 3f5582d4e7..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * 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; - -import java.util.logging.Logger; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.Location; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.validation.Schema; -import javax.xml.validation.ValidatorHandler; - -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; -import org.xml.sax.Attributes; -import org.xml.sax.ErrorHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.AttributesImpl; - -/** - * - * A validating XMLStreamReader that reports XMLSchema validation errors. - * - * @version $Rev$ $Date$ - */ -class ValidatingXMLStreamReader extends TuscanyXMLStreamReader implements XMLStreamReader { - - private static final Logger logger = Logger.getLogger(ValidatingXMLStreamReader.class.getName()); - - private int level; - private ValidatorHandler handler; - private final Monitor monitor; - - /** - * Constructs a new ValidatingXMLStreamReader. - * - * @param reader - * @param schema - * @throws XMLStreamException - */ - ValidatingXMLStreamReader(XMLStreamReader reader, Schema schema, Monitor monitor) throws XMLStreamException { - super(reader); - this.monitor = monitor; - if (schema == null) { - return; - } - - handler = schema.newValidatorHandler(); - handler.setDocumentLocator(new LocatorAdapter()); - try { - handler.setFeature("http://xml.org/sax/features/namespace-prefixes", true); - } catch (SAXException e) { - XMLStreamException xse = new XMLStreamException(e); - error("XMLStreamException", handler, xse); - throw xse; - } - - // These validation errors are just warnings for us as we want to support - // running from an XML document with XSD validation errors, as long as we can - // get the metadata we need from the document - handler.setErrorHandler(new ErrorHandler() { - private String getMessage(SAXParseException e) { - return "XMLSchema validation problem in: " + e.getSystemId() + ", line: " + e.getLineNumber() + ", column: " + e.getColumnNumber() + "\n" + e.getMessage(); - } - - public void error(SAXParseException exception) throws SAXException { - if (ValidatingXMLStreamReader.this.monitor == null) - logger.warning(getMessage(exception)); - else - ValidatingXMLStreamReader.this.error("SchemaError", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(), - exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); - } - - public void fatalError(SAXParseException exception) throws SAXException { - if (ValidatingXMLStreamReader.this.monitor == null) - logger.warning(getMessage(exception)); - else - ValidatingXMLStreamReader.this.error("SchemaFatalError", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(), - exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); - } - - public void warning(SAXParseException exception) throws SAXException { - if (ValidatingXMLStreamReader.this.monitor == null) - logger.warning(getMessage(exception)); - else - ValidatingXMLStreamReader.this.warning("SchemaWarning", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(), - exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage()); - } - }); - } - - /** - * Report a warning. - * - * @param problems - * @param message - * @param model - */ - private void warning(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); - 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); - } - } - - @Override - public int next() throws XMLStreamException { - if (handler == null) { - return super.next(); - } - - int event = super.next(); - try { - switch (event) { - case XMLStreamConstants.START_DOCUMENT: - level++; - handler.startDocument(); - break; - case XMLStreamConstants.START_ELEMENT: - level++; - handleStartElement(); - break; - case XMLStreamConstants.PROCESSING_INSTRUCTION: - handler.processingInstruction(super.getPITarget(), super.getPIData()); - break; - case XMLStreamConstants.CHARACTERS: - case XMLStreamConstants.CDATA: - case XMLStreamConstants.SPACE: - case XMLStreamConstants.ENTITY_REFERENCE: - handler.characters(super.getTextCharacters(), super.getTextStart(), super.getTextLength()); - break; - case XMLStreamConstants.END_ELEMENT: - handleEndElement(); - level--; - break; - case XMLStreamConstants.END_DOCUMENT: - handler.endDocument(); - break; - } - } catch (SAXException e) { - XMLStreamException xse = new XMLStreamException(e.getMessage(), e); - error("XMLStreamException", handler, xse); - throw xse; - } - return event; - } - - @Override - public int nextTag() throws XMLStreamException { - if (handler == null) { - return super.nextTag(); - } - - for (;;) { - int event = super.getEventType(); - try { - switch (event) { - case XMLStreamConstants.START_DOCUMENT: - level++; - handler.startDocument(); - break; - case XMLStreamConstants.START_ELEMENT: - level++; - handleStartElement(); - pushContext(); - return event; - case XMLStreamConstants.PROCESSING_INSTRUCTION: - handler.processingInstruction(super.getPITarget(), super.getPIData()); - break; - case XMLStreamConstants.CHARACTERS: - case XMLStreamConstants.CDATA: - case XMLStreamConstants.SPACE: - case XMLStreamConstants.ENTITY_REFERENCE: - handler.characters(super.getTextCharacters(), super.getTextStart(), super.getTextLength()); - break; - case XMLStreamConstants.END_ELEMENT: - handleEndElement(); - level--; - popContext(); - return event; - case XMLStreamConstants.END_DOCUMENT: - handler.endDocument(); - return event; - } - } catch (SAXException e) { - XMLStreamException xse = new XMLStreamException(e); - error("XMLStreamException", handler, xse); - throw xse; - } - super.next(); - } - } - - @Override - public String getElementText() throws XMLStreamException { - if (handler == null) { - return super.getElementText(); - } - - if (getEventType() != XMLStreamConstants.START_ELEMENT) { - return super.getElementText(); - } - StringBuffer text = new StringBuffer(); - - for (;;) { - int event = next(); - switch (event) { - case XMLStreamConstants.END_ELEMENT: - return text.toString(); - - case XMLStreamConstants.COMMENT: - case XMLStreamConstants.PROCESSING_INSTRUCTION: - continue; - - case CHARACTERS: - case CDATA: - case SPACE: - case ENTITY_REFERENCE: - text.append(getText()); - break; - - default: - break; - } - } - } - - @Override - public NamespaceContext getNamespaceContext(){ - return super.getNamespaceContext(); - } - - /** - * Handle a start element event. - * - * @throws SAXException - */ - private void handleStartElement() throws SAXException { - - // send startPrefixMapping events immediately before startElement event - int nsCount = super.getNamespaceCount(); - for (int i = 0; i < nsCount; i++) { - String prefix = super.getNamespacePrefix(i); - if (prefix == null) { // true for default namespace - prefix = ""; - } - handler.startPrefixMapping(prefix, super.getNamespaceURI(i)); - } - - // fire startElement - QName qname = super.getName(); - String prefix = qname.getPrefix(); - String rawname; - if (prefix == null || prefix.length() == 0) { - rawname = qname.getLocalPart(); - } else { - rawname = prefix + ':' + qname.getLocalPart(); - } - Attributes attrs = getAttributes(); - handler.startElement(qname.getNamespaceURI(), qname.getLocalPart(), rawname, attrs); - } - - /** - * Handle an endElement event. - * - * @throws SAXException - */ - private void handleEndElement() throws SAXException { - - // fire endElement - QName qname = super.getName(); - handler.endElement(qname.getNamespaceURI(), qname.getLocalPart(), qname.toString()); - - // send endPrefixMapping events immediately after endElement event - // we send them in the opposite order to that returned but this is not - // actually required by SAX - int nsCount = super.getNamespaceCount(); - for (int i = nsCount - 1; i >= 0; i--) { - String prefix = super.getNamespacePrefix(i); - if (prefix == null) { // true for default namespace - prefix = ""; - } - handler.endPrefixMapping(prefix); - } - } - - /** - * Get the attributes associated with the current START_ELEMENT event. - * - * @return the StAX attributes converted to org.xml.sax.Attributes - */ - private Attributes getAttributes() { - AttributesImpl attrs = new AttributesImpl(); - - // add namespace declarations - for (int i = 0; i < super.getNamespaceCount(); i++) { - String prefix = super.getNamespacePrefix(i); - String uri = super.getNamespaceURI(i); - if (prefix == null) { - attrs.addAttribute("", "", "xmlns", "CDATA", uri); - } else { - attrs.addAttribute("", "", "xmlns:" + prefix, "CDATA", uri); - } - } - - // Regular attributes - for (int i = 0; i < super.getAttributeCount(); i++) { - String uri = super.getAttributeNamespace(i); - if (uri == null) { - uri = ""; - } - String localName = super.getAttributeLocalName(i); - String prefix = super.getAttributePrefix(i); - String qname; - if (prefix == null || prefix.length() == 0) { - qname = localName; - } else { - qname = prefix + ':' + localName; - } - String type = super.getAttributeType(i); - String value = super.getAttributeValue(i); - - attrs.addAttribute(uri, localName, qname, type, value); - } - - return attrs; - } - - /** - * Adapter for mapping Locator information. - */ - private final class LocatorAdapter implements Locator { - - private LocatorAdapter() { - } - - public int getColumnNumber() { - Location location = getLocation(); - return location == null ? 0 : location.getColumnNumber(); - } - - public int getLineNumber() { - Location location = getLocation(); - return location == null ? 0 : location.getLineNumber(); - } - - public String getPublicId() { - Location location = getLocation(); - return location == null ? "" : location.getPublicId(); - } - - public String getSystemId() { - Location location = getLocation(); - return location == null ? "" : location.getSystemId(); - } - } - -} diff --git a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java b/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java deleted file mode 100644 index cc3bb59a5b..0000000000 --- a/sandbox/ant/sca/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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; - -import java.util.List; - - -/** - * An extension point for XML schemas used for validation. - * - * @version $Rev$ $Date$ - */ -public interface ValidationSchemaExtensionPoint { - - /** - * Add a schema. - * - * @param uri the URI of the schema - */ - void addSchema(String uri); - - /** - * Remove a schema. - * - * @param uri the URI of the schema - */ - void removeSchema(String uri); - - /** - * Returns the list of schemas registered in the extension point. - * @return the list of schemas - */ - List<String> getSchemas(); - -} |