You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2008/05/03 22:52:58 UTC

svn commit: r653133 [6/33] - in /incubator/tuscany/sandbox/mobile-android: android-jdk-classes/ android-jdk-classes/src/ android-jdk-classes/src/javax/ android-jdk-classes/src/javax/xml/ android-jdk-classes/src/javax/xml/namespace/ android-jdk-classes/...

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java Sat May  3 13:52:41 2008
@@ -0,0 +1,512 @@
+/*
+ * 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: 639257 $ $Date: 2008-03-20 05:12:00 -0700 (Thu, 20 Mar 2008) $
+ */
+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);
+        writeAttributePrefixes(writer, attrs);
+        writer.writeStartElement(uri, name);
+        
+        if (prefix != null){
+            writer.writeNamespace(prefix,uri); 
+        }
+        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 SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+        private String uri = SCA10_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, 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 && prefix.length() > 0) {
+
+                    // Use the prefix already bound to the given URI
+                    return prefix + ":" + 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);
+                }
+            }
+        }
+
+        /**
+         * 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(SCA10_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);
+                    }
+                }
+            }
+        }
+    }
+    
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,66 @@
+/*
+ * 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: 616114 $ $Date: 2008-01-28 16:05:37 -0800 (Mon, 28 Jan 2008) $
+ */
+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);
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,129 @@
+/*
+ * 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.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a package processor extension point.
+ * 
+ * @version $Rev: 632642 $ $Date: 2008-03-01 10:16:44 -0800 (Sat, 01 Mar 2008) $
+ */
+public class DefaultPackageProcessorExtensionPoint implements PackageProcessorExtensionPoint {
+
+    private Map<String, PackageProcessor> processors = new HashMap<String, PackageProcessor>();
+    private boolean loaded;
+
+    public DefaultPackageProcessorExtensionPoint() {
+    }
+
+    public void addPackageProcessor(PackageProcessor processor) {
+        processors.put(processor.getPackageType(), processor);
+    }
+
+    public void removePackageProcessor(PackageProcessor processor) {
+        processors.remove(processor.getPackageType());
+    }
+
+    public PackageProcessor getPackageProcessor(String contentType) {
+        loadProcessors();
+        return processors.get(contentType);
+    }
+
+    private void loadProcessors() {
+        if (loaded)
+            return;
+
+        // Get the processor service declarations
+        Set<ServiceDeclaration> processorDeclarations; 
+        try {
+            processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(PackageProcessor.class);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+        
+        for (ServiceDeclaration processorDeclaration: processorDeclarations) {
+            Map<String, String> attributes = processorDeclaration.getAttributes();
+            
+            // Load a URL artifact processor
+            String packageType = attributes.get("type");
+            
+            // Create a processor wrapper and register it
+            PackageProcessor processor = new LazyPackageProcessor(packageType, processorDeclaration);
+            addPackageProcessor(processor);
+        }
+        
+        loaded = true;
+    }
+
+    /**
+     * A facade for package processors.
+     */
+    private static class LazyPackageProcessor implements PackageProcessor {
+        
+        private ServiceDeclaration processorDeclaration;
+        private String packageType;
+        private PackageProcessor processor;
+        
+        private LazyPackageProcessor(String packageType, ServiceDeclaration processorDeclaration) {
+            this.processorDeclaration = processorDeclaration;
+            this.packageType = packageType;
+        }
+
+        public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException {
+            return getProcessor().getArtifactURL(packageSourceURL, artifact);
+        }
+
+        public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException {
+            return getProcessor().getArtifacts(packageSourceURL, inputStream);
+        }
+
+        public String getPackageType() {
+            return packageType;
+        }
+        
+        @SuppressWarnings("unchecked")
+        private PackageProcessor getProcessor() {
+            if (processor == null) {
+                try {
+                    Class<PackageProcessor> processorClass = (Class<PackageProcessor>)processorDeclaration.loadClass();
+                    Constructor<PackageProcessor> constructor = processorClass.getConstructor();
+                    processor = constructor.newInstance();
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return processor;
+        }
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,256 @@
+/*
+ * 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.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * The default implementation of an extension point for StAX artifact processors.
+ * 
+ * @version $Rev: 639257 $ $Date: 2008-03-20 05:12:00 -0700 (Thu, 20 Mar 2008) $
+ */
+public class DefaultStAXArtifactProcessorExtensionPoint extends
+    DefaultArtifactProcessorExtensionPoint<StAXArtifactProcessor> implements StAXArtifactProcessorExtensionPoint {
+
+    private ModelFactoryExtensionPoint modelFactories;
+    private boolean loaded;
+
+    /**
+     * Constructs a new extension point.
+     */
+    public DefaultStAXArtifactProcessorExtensionPoint(ModelFactoryExtensionPoint modelFactories) {
+        this.modelFactories = modelFactories;
+    }
+
+    public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) {
+        processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+        processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
+    }
+
+    public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) {
+        processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType());
+        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 void loadArtifactProcessors() {
+        if (loaded)
+            return;
+
+        // Get the processor service declarations
+        Set<ServiceDeclaration> processorDeclarations;
+        try {
+            processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+
+        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(modelFactories, artifactType, modelTypeName, factoryName,
+                                              processorDeclaration);
+            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 ModelFactoryExtensionPoint modelFactories;
+        private QName artifactType;
+        private String modelTypeName;
+        private String factoryName;
+        private ServiceDeclaration processorDeclaration;
+        private StAXArtifactProcessor processor;
+        private Class<?> modelType;
+
+        LazyStAXArtifactProcessor(ModelFactoryExtensionPoint modelFactories,
+                                  QName artifactType,
+                                  String modelTypeName,
+                                  String factoryName,
+                                  ServiceDeclaration processorDeclaration) {
+
+            this.modelFactories = modelFactories;
+            this.artifactType = artifactType;
+            this.modelTypeName = modelTypeName;
+            this.factoryName = factoryName;
+            this.processorDeclaration = processorDeclaration;
+        }
+
+        public QName getArtifactType() {
+            return artifactType;
+        }
+
+        @SuppressWarnings("unchecked")
+        private StAXArtifactProcessor getProcessor() {
+            if (processor == null) {
+
+                if (processorDeclaration.getClassName()
+                    .equals("org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor")) {
+
+                    // Specific initialization for the DefaultBeanModelProcessor
+                    AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+                    PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.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(AssemblyFactory.class,
+                                                          PolicyFactory.class,
+                                                          QName.class,
+                                                          Class.class,
+                                                          Object.class);
+                        processor =
+                            constructor.newInstance(assemblyFactory,
+                                                    policyFactory,
+                                                    artifactType,
+                                                    getModelType(),
+                                                    modelFactory);
+                    } catch (Exception e) {
+                        throw new IllegalStateException(e);
+                    }
+                } else {
+
+                    // Load and instantiate the processor class
+                    try {
+                        Class<StAXArtifactProcessor> processorClass =
+                            (Class<StAXArtifactProcessor>)processorDeclaration.loadClass();
+                        Constructor<StAXArtifactProcessor> constructor =
+                            processorClass.getConstructor(ModelFactoryExtensionPoint.class);
+                        processor = constructor.newInstance(modelFactories);
+                    } catch (Exception e) {
+                        throw new IllegalStateException(e);
+                    }
+                }
+            }
+            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 (modelType == null) {
+                try {
+                    modelType = processorDeclaration.loadClass(modelTypeName);
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return modelType;
+        }
+
+        @SuppressWarnings("unchecked")
+        public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+            getProcessor().resolve(model, resolver);
+        }
+
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,167 @@
+/*
+ * 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 org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * The default implementation of a URL artifact processor extension point.
+ * 
+ * @version $Rev: 632642 $ $Date: 2008-03-01 10:16:44 -0800 (Sat, 01 Mar 2008) $
+ */
+public class DefaultURLArtifactProcessorExtensionPoint
+    extends DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor>
+    implements URLArtifactProcessorExtensionPoint {
+    
+    private ModelFactoryExtensionPoint modelFactories;
+    private boolean loaded;
+
+    /**
+     * Constructs a new extension point.
+     */
+    public DefaultURLArtifactProcessorExtensionPoint(ModelFactoryExtensionPoint modelFactories) {
+        this.modelFactories = modelFactories;
+    }
+
+    public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) {
+        processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+        processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
+    }
+    
+    public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) {
+        processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType());
+        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 void loadProcessors() {
+        if (loaded)
+            return;
+
+        // Get the processor service declarations
+        Set<ServiceDeclaration> processorDeclarations; 
+        try {
+            processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+        
+        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(modelFactories, artifactType, modelTypeName, processorDeclaration);
+            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 ModelFactoryExtensionPoint modelFactories;
+        private String artifactType;
+        private String modelTypeName;
+        private ServiceDeclaration processorDeclaration;
+        private URLArtifactProcessor processor;
+        private Class<?> modelType;
+        
+        LazyURLArtifactProcessor(ModelFactoryExtensionPoint modelFactories, 
+        		String artifactType, 
+        		String modelTypeName, 
+        		ServiceDeclaration processorDeclaration) {
+            this.modelFactories = modelFactories;
+            this.artifactType = artifactType;
+            this.modelTypeName = modelTypeName;
+            this.processorDeclaration = processorDeclaration;
+        }
+
+        public String getArtifactType() {
+            return artifactType;
+        }
+        
+        @SuppressWarnings("unchecked")
+        private URLArtifactProcessor getProcessor() {
+            if (processor == null) {
+                try {
+                    Class<URLArtifactProcessor> processorClass = (Class<URLArtifactProcessor>)processorDeclaration.loadClass();
+                    Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class);
+                    processor = constructor.newInstance(modelFactories);
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return processor;
+        }
+
+        public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
+            return getProcessor().read(contributionURL, artifactURI, artifactURL);
+        }
+        
+        public Class<?> getModelType() {
+            if (modelType == null) {
+                try {
+                    modelType = processorDeclaration.loadClass(modelTypeName);
+                } catch (Exception e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return modelType;
+        }
+
+        @SuppressWarnings("unchecked")
+        public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+            getProcessor().resolve(model, resolver);
+        }
+
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java Sat May  3 13:52:41 2008
@@ -0,0 +1,236 @@
+/*
+ * 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.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.net.URLConnection;
+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.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Default implementation of an XMLInputFactory that creates validating
+ * XMLStreamReaders.
+ *
+ * @version $Rev: 641645 $ $Date: 2008-03-26 15:37:28 -0800 (Wed, 26 Mar 2008) $
+ */
+public class DefaultValidatingXMLInputFactory extends XMLInputFactory {
+    
+    private XMLInputFactory inputFactory;
+    private ValidationSchemaExtensionPoint schemas;
+    private boolean initialized;
+    private Schema aggregatedSchema;
+
+    /**
+     * Constructs a new XMLInputFactory.
+     * 
+     * @param inputFactory
+     * @param schemas
+     */
+    public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas) {
+        this.inputFactory = inputFactory;
+        this.schemas = schemas;
+    }
+    
+    /**
+     * 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();
+            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) {
+                    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) {
+                throw (SAXException)e.getException();
+            }
+
+        } catch (Error e) {
+            // FIXME Log this, some old JDKs don't support XMLSchema validation
+            //e.printStackTrace();
+        } catch (SAXParseException e) {
+            throw new IllegalStateException(e);
+        } catch (Exception e) {
+            //FIXME Log this, some old JDKs don't support XMLSchema validation
+            e.printStackTrace();
+        }
+    }
+
+    public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException {
+        return inputFactory.createFilteredReader(arg0, arg1);
+    }
+
+    public XMLStreamReader createFilteredReader(XMLStreamReader arg0, StreamFilter arg1) throws XMLStreamException {
+        return inputFactory.createFilteredReader(arg0, arg1);
+    }
+
+    public XMLEventReader createXMLEventReader(InputStream arg0, String arg1) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0, arg1);
+    }
+
+    public XMLEventReader createXMLEventReader(InputStream arg0) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0);
+    }
+
+    public XMLEventReader createXMLEventReader(Reader arg0) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0);
+    }
+
+    public XMLEventReader createXMLEventReader(Source arg0) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0);
+    }
+
+    public XMLEventReader createXMLEventReader(String arg0, InputStream arg1) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0, arg1);
+    }
+
+    public XMLEventReader createXMLEventReader(String arg0, Reader arg1) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0, arg1);
+    }
+
+    public XMLEventReader createXMLEventReader(XMLStreamReader arg0) throws XMLStreamException {
+        return inputFactory.createXMLEventReader(arg0);
+    }
+
+    public XMLStreamReader createXMLStreamReader(InputStream arg0, String arg1) throws XMLStreamException {
+        initializeSchemas();
+        return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema);
+    }
+
+    public XMLStreamReader createXMLStreamReader(InputStream arg0) throws XMLStreamException {
+        initializeSchemas();
+        return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema);
+    }
+
+    public XMLStreamReader createXMLStreamReader(Reader arg0) throws XMLStreamException {
+        initializeSchemas();
+        return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema);
+    }
+
+    public XMLStreamReader createXMLStreamReader(Source arg0) throws XMLStreamException {
+        initializeSchemas();
+        return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema);
+    }
+
+    public XMLStreamReader createXMLStreamReader(String arg0, InputStream arg1) throws XMLStreamException {
+        initializeSchemas();
+        return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema);
+    }
+
+    public XMLStreamReader createXMLStreamReader(String arg0, Reader arg1) throws XMLStreamException {
+        initializeSchemas();
+        return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema);
+    }
+
+    public XMLEventAllocator getEventAllocator() {
+        return inputFactory.getEventAllocator();
+    }
+
+    public Object getProperty(String arg0) throws IllegalArgumentException {
+        return inputFactory.getProperty(arg0);
+    }
+
+    public XMLReporter getXMLReporter() {
+        return inputFactory.getXMLReporter();
+    }
+
+    public XMLResolver getXMLResolver() {
+        return inputFactory.getXMLResolver();
+    }
+
+    public boolean isPropertySupported(String arg0) {
+        return inputFactory.isPropertySupported(arg0);
+    }
+
+    public void setEventAllocator(XMLEventAllocator arg0) {
+        inputFactory.setEventAllocator(arg0);
+    }
+
+    public void setProperty(String arg0, Object arg1) throws IllegalArgumentException {
+        inputFactory.setProperty(arg0, arg1);
+    }
+
+    public void setXMLReporter(XMLReporter arg0) {
+        inputFactory.setXMLReporter(arg0);
+    }
+
+    public void setXMLResolver(XMLResolver arg0) {
+        inputFactory.setXMLResolver(arg0);
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,83 @@
+/*
+ * 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: 632642 $ $Date: 2008-03-01 10:16:44 -0800 (Sat, 01 Mar 2008) $
+ */
+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 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);
+        }
+        
+        // Find each schema
+        for (ServiceDeclaration schemaDeclaration: schemaDeclarations) {
+            URL url = schemaDeclaration.getResource();
+            if (url == null) {
+                throw new IllegalArgumentException(new FileNotFoundException(schemaDeclaration.getClassName()));
+            }
+            schemas.add(url.toString());
+        }
+        
+        loaded = true;
+    }
+    
+    public List<String> getSchemas() {
+        loadSchemas();
+        return schemas;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java Sat May  3 13:52:41 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.contribution.service.TypeDescriber;
+import org.apache.tuscany.sca.contribution.service.UnsupportedPackageTypeException;
+
+/**
+ * Implementation of an extensible package processor.
+ * 
+ * Takes a package processor extension point and delegates to the proper package
+ * processor from the extension point based on the package's content type.
+ * 
+ * @version $Rev: 616149 $ $Date: 2008-01-28 19:10:32 -0800 (Mon, 28 Jan 2008) $
+ */
+public class ExtensiblePackageProcessor implements PackageProcessor {
+
+    private PackageProcessorExtensionPoint processors;
+    private TypeDescriber packageTypeDescriber;
+
+    public ExtensiblePackageProcessor(PackageProcessorExtensionPoint processors, TypeDescriber packageTypeDescriber) {
+        this.processors = processors; 
+        this.packageTypeDescriber = packageTypeDescriber;
+    }
+
+    public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) 
+        throws ContributionException, IOException {
+        String packageType = this.packageTypeDescriber.getType(packageSourceURL, null);
+        if (packageType == null) {
+            throw new UnsupportedPackageTypeException("Unsupported contribution package type: " + packageSourceURL.toString());
+        }
+
+        PackageProcessor packageProcessor = this.processors.getPackageProcessor(packageType);
+        if (packageProcessor == null) {
+            throw new UnsupportedPackageTypeException("Unsupported contribution package type: " + packageType);
+        }
+
+        return packageProcessor.getArtifacts(packageSourceURL, inputStream);
+    }
+
+    public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException {
+        String contentType = this.packageTypeDescriber.getType(packageSourceURL, null);
+        PackageProcessor packageProcessor = this.processors.getPackageProcessor(contentType);
+        return packageProcessor.getArtifactURL(packageSourceURL, artifact);
+    }
+    
+    public String getPackageType() {
+        return null;
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java Sat May  3 13:52:41 2008
@@ -0,0 +1,185 @@
+/*
+ * 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.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException;
+
+/**
+ * Implementation of an extensible StAX artifact processor.
+ * 
+ * Takes a StAXArtifactProcessorExtensionPoint and delegates to the proper
+ * StAXArtifactProcessor by element QName
+ * 
+ * @version $Rev: 639257 $ $Date: 2008-03-20 05:12:00 -0700 (Thu, 20 Mar 2008) $
+ */
+public class ExtensibleStAXArtifactProcessor
+    implements StAXArtifactProcessor<Object> {
+
+    private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName()); 
+    private XMLInputFactory inputFactory;
+    private XMLOutputFactory outputFactory;
+    private StAXArtifactProcessorExtensionPoint processors;
+
+    /**
+     * Constructs a new ExtensibleStAXArtifactProcessor.
+     * @param processors
+     * @param inputFactory
+     * @param outputFactory
+     */
+    public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors, XMLInputFactory inputFactory, XMLOutputFactory outputFactory) {
+        super();
+        this.processors = processors;
+        this.inputFactory = inputFactory;
+        this.outputFactory = outputFactory;
+        //this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
+    }
+
+    public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException {
+        
+        // Delegate to the processor associated with the element QName
+        QName name = source.getName();
+        StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>)processors.getProcessor(name);
+        if (processor == null) {
+            if (logger.isLoggable(Level.WARNING)) {
+                Location location = source.getLocation();
+                logger.warning("Element " + name + " cannot be processed. (" + location + ")");
+            }
+            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());
+                }
+            }
+        }
+    }
+    
+    @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 {
+                        UnrecognizedElementException e = new UnrecognizedElementException(name);
+                        throw e;
+                    }
+                } catch (ContributionReadException e) {
+                    Location location = reader.getLocation();
+                    e.setLine(location.getLineNumber());
+                    e.setColumn(location.getColumnNumber());
+                    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);
+            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) {
+            throw new ContributionWriteException(e);
+        }
+    }
+
+    public QName getArtifactType() {
+        return null;
+    }
+    
+    public Class<Object> getModelType() {
+        return null;
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java Sat May  3 13:52:41 2008
@@ -0,0 +1,122 @@
+/*
+ * 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.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException;
+
+/**
+ * Implementation of an extensible URL artifact processor.
+ * 
+ * Takes a URLArtifactProcessorExtensionPoint and delegates to the proper URLArtifactProcessor
+ * by either fileName or fileExtention
+ * 
+ * @version $Rev: 616114 $ $Date: 2008-01-28 16:05:37 -0800 (Mon, 28 Jan 2008) $
+ */
+public class ExtensibleURLArtifactProcessor
+    implements URLArtifactProcessor<Object> {
+    
+    private URLArtifactProcessorExtensionPoint processors;
+
+    /**
+     * Constructs a new ExtensibleURLArtifactProcessor.
+     * 
+     * @param processors
+     */
+    public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors) {
+        this.processors = processors;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException {
+        URLArtifactProcessor<Object> 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) {
+                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());
+            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);
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java Sat May  3 13:52:41 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+
+/**
+ * Interface for contribution package processors
+ * 
+ * Package processors understand the format of the contribution and how to get the
+ * artifacts in the contribution.
+ * 
+ * @version $Rev: 616114 $ $Date: 2008-01-28 16:05:37 -0800 (Mon, 28 Jan 2008) $
+ */
+public interface PackageProcessor {
+    
+    /**
+     * Returns the type of package supported by this package processor.
+     * 
+     * @return the package type
+     */
+    String getPackageType();
+
+    /**
+     * Returns a list of artifacts in the contribution.
+     * 
+     * @param packageSourceURL Contribution package location URL
+     * @param inputStream Optional content of the package
+     * @return List of artifact URIs
+     * @throws ContributionException
+     * @throws IOException
+     */
+    List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException;
+
+    /**
+     * Return the URL for an artifact in the package.
+     * 
+     * This is needed for archives such as jar files that have specific URL schemes
+     * for the artifacts they contain.
+     * 
+     * @param packageSourceURL Contribution package location URL
+     * @param artifact The relative URI for the artifact
+     * @return The artifact URL
+     */
+    URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException;
+
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,50 @@
+/*
+ * 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 package processors
+ * 
+ * @version $Rev: 616114 $ $Date: 2008-01-28 16:05:37 -0800 (Mon, 28 Jan 2008) $
+ */
+public interface PackageProcessorExtensionPoint {
+    
+    /**
+     * Register a PackageProcessor using the package type as the key.
+     * 
+     * @param processor The package processor
+     */
+    void addPackageProcessor(PackageProcessor processor);
+    
+    /**
+     * Unregister a PackageProcessor.
+     * 
+     * @param processor The package processor
+     */
+    void removePackageProcessor(PackageProcessor processor);
+    
+    /**
+     * Returns the PackageProcessor for the given package type.
+     * 
+     * @param packageType The package type
+     * @return The package processor
+     */
+    PackageProcessor getPackageProcessor(String packageType);
+    
+}
\ No newline at end of file

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java Sat May  3 13:52:41 2008
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+/**
+ * An artifact processor that can read models from a StAX XMLStreamReader.
+ * 
+ * @version $Rev: 572267 $ $Date: 2007-09-03 02:46:41 -0700 (Mon, 03 Sep 2007) $
+ */
+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();
+}

Added: incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java?rev=653133&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java Sat May  3 13:52:41 2008
@@ -0,0 +1,29 @@
+/*
+ * 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: 616114 $ $Date: 2008-01-28 16:05:37 -0800 (Mon, 28 Jan 2008) $
+ */
+public interface StAXArtifactProcessorExtensionPoint extends 
+    ArtifactProcessorExtensionPoint<StAXArtifactProcessor> {
+
+}