Author: lresende
Date: Wed Jan 21 16:02:32 2009
New Revision: 736500

URL: http://svn.apache.org/viewvc?rev=736500&view=rev
Log:
TUSCANY-2663 - Merging latest code to support extended elements to 2.x 
development stream

Added:
    
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
   (with props)
Removed:
    
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java
    
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteUnknownElementTestCase.java
Modified:
    tuscany/java/sca/modules/assembly-xml/pom.xml
    
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
    
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java
    
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java
    
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
    
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java
    
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java

Modified: tuscany/java/sca/modules/assembly-xml/pom.xml
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/pom.xml?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly-xml/pom.xml (original)
+++ tuscany/java/sca/modules/assembly-xml/pom.xml Wed Jan 21 16:02:32 2009
@@ -52,7 +52,13 @@
             <artifactId>tuscany-contribution</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution-xml</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+                
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-contribution-namespace</artifactId>

Added: 
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java?rev=736500&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
 (added)
+++ 
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
 Wed Jan 21 16:02:32 2009
@@ -0,0 +1,147 @@
+/*
+ * 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.assembly.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import 
org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import 
org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ReadWriteAnyElementTestCase {
+    private static final String XML_RECURSIVE_EXTENDED_ELEMENT =
+        "<?xml version='1.0' encoding='UTF-8'?>" +
+        "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"; 
xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\"; targetNamespace=\"http://temp\"; 
name=\"RecursiveExtendedElement\">" +
+         "<unknownElement>" +
+           "<subUnknownElement1 attribute=\"anyAttribute\" />" +
+           "<subUnknownElement2 />" +
+         "</unknownElement>" +
+        "</composite>";
+
+    private static final String XML_UNKNOWN_IMPL =
+        "<?xml version='1.0' encoding='UTF-8'?>" + 
+        "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"; 
xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\"; targetNamespace=\"http://temp\"; 
name=\"aaaa\" autowire=\"false\">" +
+         "<component name=\"unknownImpl\">" +
+           "<implementation.unknown class=\"raymond\" />" +
+           "<service name=\"service\">" +
+             "<binding.ws />" +
+           "</service>" +
+         "</component>" +
+        "</composite>";
+
+    private static final String XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE =
+        "<?xml version='1.0' encoding='UTF-8'?>" + 
+        "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"; 
xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\"; targetNamespace=\"http://temp\"; 
name=\"aaaa\" autowire=\"false\">" +
+         "<component name=\"unknownImpl\">" +
+           "<implementation.unknown class=\"raymond\" />" +
+           "<service name=\"service\" requires=\"\">" +
+             "<binding.ws />" +
+           "</service>" +
+         "</component>" +
+        "</composite>";
+    
+    
+    private XMLInputFactory inputFactory;
+    private ExtensibleStAXArtifactProcessor staxProcessor;
+
+    @Before
+    public void setUp() throws Exception {
+        ExtensionPointRegistry extensionPoints = new 
DefaultExtensionPointRegistry();
+        FactoryExtensionPoint modelFactories = 
extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+        inputFactory = 
modelFactories.getFactory(ValidatingXMLInputFactory.class);
+
+        StAXArtifactProcessorExtensionPoint staxProcessors = 
extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+        staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, 
inputFactory, XMLOutputFactory.newInstance(), null);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @Test
+    public void testReadWriteExtendedRecursiveElement() throws Exception {
+        XMLStreamReader reader = inputFactory.createXMLStreamReader(new 
StringReader(XML_RECURSIVE_EXTENDED_ELEMENT));
+        Composite composite = (Composite)staxProcessor.read(reader);
+        assertNotNull(composite);
+        reader.close();
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        staxProcessor.write(composite, bos);
+
+        // used for debug comparison
+        // System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT);
+        // System.out.println(bos.toString());
+
+        assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString());
+        bos.close();
+    }
+
+    @Test
+    public void testReadWriteUnknwonImpl() throws Exception {
+        XMLStreamReader reader = inputFactory.createXMLStreamReader(new 
StringReader(XML_UNKNOWN_IMPL));
+        Composite composite = (Composite)staxProcessor.read(reader);
+        assertNotNull(composite);
+        reader.close();
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        staxProcessor.write(composite, bos);
+
+        // used for debug comparison
+        // System.out.println(XML_UNKNOWN_IMPL);
+        // System.out.println(bos.toString());
+
+        assertEquals(XML_UNKNOWN_IMPL, bos.toString());
+        bos.close();
+    }
+
+    // @Test
+    @Ignore()
+    public void testReadWriteInvalidAttribute() throws Exception {
+        XMLStreamReader reader = inputFactory.createXMLStreamReader(new 
StringReader(XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE));
+        Composite composite = (Composite)staxProcessor.read(reader);
+        assertNotNull(composite);
+        reader.close();
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        staxProcessor.write(composite, bos);
+
+        // used for debug comparison
+        // System.out.println(XML_UNKNOWN_IMPL);
+        // System.out.println(bos.toString());
+
+        assertEquals(XML_UNKNOWN_IMPL, bos.toString());
+        bos.close();
+    }
+}
\ No newline at end of file

Propchange: 
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
 Wed Jan 21 16:02:32 2009
@@ -18,50 +18,45 @@
  */
 package org.apache.tuscany.sca.contribution.processor.xml;
 
+import static javax.xml.stream.XMLStreamConstants.CDATA;
+import static javax.xml.stream.XMLStreamConstants.CHARACTERS;
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 
 import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.XMLEvent;
 
+import org.apache.tuscany.sca.contribution.Constants;
 import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
 import 
org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.Problem;
-import org.apache.tuscany.sca.monitor.Problem.Severity;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.traversal.DocumentTraversal;
-import org.w3c.dom.traversal.NodeFilter;
-import org.w3c.dom.traversal.NodeIterator;
-import org.w3c.dom.traversal.TreeWalker;
 
 public class AnyElementProcessor implements StAXArtifactProcessor<Object> {
-       private static final QName ANY_ELEMENT = new 
QName("http://www.w3.org/2001/XMLSchema";, "anyElement");
-       
-       private static final Logger logger = 
Logger.getLogger(AnyElementProcessor.class.getName());
-       private DocumentBuilderFactory documentBuilderFactory;
-       private Document document;
-       private Monitor monitor;
-       
-       public AnyElementProcessor(FactoryExtensionPoint modelFactories, 
Monitor monitor) {
-               documentBuilderFactory = 
modelFactories.getFactory(DocumentBuilderFactory.class);
-               this.monitor = monitor;
-       }
-       
+    private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, 
"anyElement");
+
+    private XMLInputFactory xmlInputFactory;
+    @SuppressWarnings("unused")
+    private Monitor monitor;
+
+
+    public AnyElementProcessor(FactoryExtensionPoint modelFactories, Monitor 
monitor) {
+        xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class);
+        this.monitor = monitor;
+    }
 
     public QName getArtifactType() {
         return ANY_ELEMENT;
@@ -70,240 +65,97 @@
     public Class<Object> getModelType() {
         return Object.class;
     }
-    
-       /**
-        * Reads the contetns of the unknown elements and generates the DOM     
-        * @param reader
-        * @param name
-        * @return
-        * @throws XMLStreamException
-        */
+
+    /**
+     * Reads the contetns of the unknown elements and generates a custom
+     * implementation of XMLStreamReader i.e. XMLEventsStreamReader
+     * 
+     * @param reader
+     * @return
+     * @throws XMLStreamException
+     */
+    @SuppressWarnings("unchecked")
     public Object read(XMLStreamReader reader) throws 
ContributionReadException, XMLStreamException {
-               
-               int event = reader.getEventType();
-               int level = 0;
-               ArrayList<String> elementList = new ArrayList<String>();
-               document = createDocument();
-               
-               QName name = reader.getName();
-               
-               while(reader.hasNext()){
-               switch(event){
-                       case START_ELEMENT:
-                               
elementList.add(reader.getName().getLocalPart());
-                               if(level == 0){
-                                       generateDOM(reader,null);
-                                       level++;
-                               }
-                               else{
-                                       
generateDOM(reader,elementList.get(elementList.size()-2).toString());
-                               }
-                               
-                               break;
-                       case END_ELEMENT:
-                               
elementList.remove(reader.getName().getLocalPart());
-               }
-               if(reader.hasNext()){
-                       event = reader.next();
-               }
-               
-               if(event == START_ELEMENT || event == END_ELEMENT){
-                       if(reader.getName().equals(name)){
-                               break;
-                       }
-               }
-           }
-               return document;
-       }
-
-       /**
-        * Writes unknown portions back to the writer
-        * @param model
-        * @param writer
-        */
-       public void write(Object model, XMLStreamWriter writer) {
-               
-               if( ! (model instanceof Document)) {
-                       return;
-               }
-               
-               Document doc = (Document)model;
-               try{
-                       DocumentTraversal traversal = (DocumentTraversal)doc;
-                       TreeWalker walker = 
traversal.createTreeWalker(doc.getDocumentElement(),NodeFilter.SHOW_ALL, null, 
true);
-                       writeDOM(walker,writer);
-               }
-               catch(Exception e){
-                       if (logger.isLoggable(Level.SEVERE)) {
-                logger.log(Level.SEVERE, "Document not created ");
-            }
-                       error("Document not created",document,e);
-               }
-       }
 
-    public void resolve(Object arg0, ModelResolver arg1) throws 
ContributionResolveException {
-       
-    }
-    
-       /**
-        * Method to generate the DOM
-        * @param reader
-        * @param parent
-        * @throws Exception 
-        */
-       //private void generateDOM(String elementText, String parent) {
-       private void generateDOM(XMLStreamReader reader, String parent) {
-               try{
-                       String elePrefix = reader.getPrefix();
-                       String eleQName = reader.getLocalName();
-                       if (elePrefix != null && elePrefix.length() != 0) {
-                eleQName = elePrefix + ":" + eleQName;
-            }
-                       
-                       Element element = 
document.createElementNS(reader.getNamespaceURI(), eleQName);
-                               
-                       int attributeCount = reader.getAttributeCount();
-                       for(int i = 0;i < attributeCount;i++){
-                               String ns = reader.getAttributeNamespace(i);
-                String prefix = reader.getAttributePrefix(i);
-                String qname = reader.getAttributeLocalName(i);
-                String value = reader.getAttributeValue(i);
-                if (prefix != null && prefix.length() != 0) {
-                    qname = prefix + ":" + qname;
+        // Custom variables
+        String currentElement = null;
+        List eventsList = new ArrayList();
+
+        Map<String, NamespaceContext> eventContext = new HashMap<String, 
NamespaceContext>();
+
+        try {
+            // Cast the block of unknown elements into document
+            XMLDocumentStreamReader docReader = new 
XMLDocumentStreamReader(reader);
+
+            XMLEventReader xmlEventReader = 
xmlInputFactory.createXMLEventReader(docReader);
+
+            while (xmlEventReader.hasNext()) {
+                XMLEvent event = xmlEventReader.nextEvent();
+
+                // Populate the eventContext map with the current element's 
name
+                // and corresponding NamesapceContext
+                if (currentElement != null && 
!(eventContext.containsKey(currentElement))) {
+                    eventContext.put(currentElement, 
reader.getNamespaceContext());
+                }
+
+                // Populate the list with the XMLEvents
+                eventsList.add(event);
+                if (event.isStartElement()) {
+                    currentElement = reader.getName().getLocalPart();
+                }
+                if (event.isEndDocument()) {
+                    return new XMLEventsStreamReader(eventsList, eventContext);
                 }
-                element.setAttributeNS(ns,qname,value);
-                       }
-                       if(parent == null){
-                               if(document != null){
-                                       document.appendChild(element);
-                               }
-                               else{
-                                       if (logger.isLoggable(Level.SEVERE)) {
-                           logger.log(Level.SEVERE, "Document not created ");
-                       }
-                                       error("Document not 
created",document,element);
-                               }
-                       }
-                       else{
-                               Node parentNode = 
getParentNode(document,parent);
-                               if(parentNode != null){
-                                       parentNode.appendChild(element);
-                               }
-                               else{
-                                       if (logger.isLoggable(Level.SEVERE)) {
-                                               logger.log(Level.SEVERE, 
"Parent node not found");
-                                       }
-                                       error("Parent node not 
found",document,parentNode.getNodeName());
-                               }
-                       }
-               }
-               catch(Exception e){
-                       e.printStackTrace();
-                       if (logger.isLoggable(Level.SEVERE)) {
-                logger.log(Level.SEVERE, "Document not created ");
             }
-                       error("Document not created",document,e);
-               }
-       }
-
-       /**
-        * Method to create an empty document
-        * @return
-        */
-       private Document createDocument() {
-               try {
-               document = 
documentBuilderFactory.newDocumentBuilder().newDocument();
-               return document;
-           } catch (ParserConfigurationException e) {
-               e.printStackTrace();
-           }
-           return null;
-       }
-
-       /**
-        * Method to traverse the DOM structure and write the elements 
-        * @param walker
-        * @param writer
-        * @throws XMLStreamException
-        */
-       private void writeDOM(TreeWalker walker,XMLStreamWriter writer) throws 
XMLStreamException {
-         
-           Node parent = walker.getCurrentNode();
-           
-           writer.writeStartElement(parent.getPrefix(), parent.getLocalName(), 
parent.getNamespaceURI());
-           
-           NamedNodeMap attributes = parent.getAttributes();
-          
-           for(int i = 0;i<attributes.getLength();i++){
-                  writer.writeAttribute(attributes.item(i).getPrefix(), 
attributes.item(i).getNamespaceURI(), attributes.item(i).getLocalName(), 
attributes.item(i).getNodeValue());
-           }
-                  
-           for (Node n = walker.firstChild();n != null;n = 
walker.nextSibling()) {
-             writeDOM(walker,writer);
-           }
-           writer.writeEndElement();
-           
-           walker.setCurrentNode(parent);
-       }
-
-       /**
-        * Method to get the Parent node out of the DOM structure
-        * @param doc
-        * @param parent
-        * @return
-        */
-       private Node getParentNode(Node doc,String parent) {
-               Node parentNode = null;
-               try{
-                       DocumentTraversal traversal = (DocumentTraversal)doc;
-                       
-                       CharSequence prefixChar = ":";
-                       NodeIterator iterator = 
traversal.createNodeIterator(document.getDocumentElement(), 
NodeFilter.SHOW_ELEMENT, null, true);
-                       for (Node n = iterator.nextNode(); n != null; n = 
iterator.nextNode()) {
-                               String nodeName = n.getNodeName();
-                               String[] str = null;
-                               if(n.getNodeName().contains(prefixChar)){
-                                       str = nodeName.split(":");
-                                       nodeName = str[str.length-1];
-                               }
-                               if(parent.equalsIgnoreCase(nodeName)){
-                                 parentNode = n;
-                               }
-                           }
-                       return parentNode;
-               }
-               catch(Exception e){
-                       e.printStackTrace();
-               }
-               return parentNode;
-       }
-       
-        /**
-     * Marshals exceptions into the monitor
-     * 
-     * @param problems
-     * @param message
-     * @param model
-     */
-    private void error(String message, Object model, Exception ex) {
-       if (monitor != null) {
-               Problem problem = 
monitor.createProblem(this.getClass().getName(), 
"contribution-validation-messages", Severity.ERROR, model, message, ex);
-               monitor.problem(problem);
-       }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
     }
-    
+
     /**
-     * Report a error.
+     * Writes unknown portions back to the writer
      * 
-     * @param problems
-     * @param message
      * @param model
+     * @param writer
      */
-    private void error(String message, Object model, Object... 
messageParameters) {
-       if (monitor != null) {
-               Problem problem = 
monitor.createProblem(this.getClass().getName(), 
"contribution-validation-messages", Severity.ERROR, model, message, 
(Object[])messageParameters);
-               monitor.problem(problem);
-       }
+    public void write(Object model, XMLStreamWriter writer) throws 
XMLStreamException {
+        if (!(model instanceof XMLStreamReader)) {
+            return;
+        }
+        XMLStreamReader reader = (XMLStreamReader)model;
+
+        int event = reader.getEventType();
+        while (reader.hasNext()) {
+            switch (event) {
+                case START_ELEMENT:
+
+                    writer.writeStartElement(reader.getPrefix(), 
reader.getLocalName(), reader.getNamespaceURI());
+                    for (int i = 1; i <= reader.getAttributeCount(); i++) {
+                        writer.writeAttribute(reader.getAttributePrefix(i), 
reader.getAttributeNamespace(i), reader
+                            .getAttributeLocalName(i), 
reader.getAttributeValue(i));
+                    }
+                    break;
+
+                case CHARACTERS:
+                    writer.writeCharacters(reader.getText());
+                    break;
+
+                case CDATA:
+                    writer.writeCData(reader.getText());
+                    break;
+
+                case END_ELEMENT:
+                    writer.writeEndElement();
+                    break;
+            }
+            if (reader.hasNext()) {
+                event = reader.next();
+            }
+        }
+    }
+
+    public void resolve(Object model, ModelResolver resolver) throws 
ContributionResolveException {
+
     }
-       
 }

Modified: 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java
 (original)
+++ 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLDocumentStreamReader.java
 Wed Jan 21 16:02:32 2009
@@ -37,16 +37,16 @@
  */
 public class XMLDocumentStreamReader implements XMLStreamReader {
     private static final int STATE_COMPLETE_AT_NEXT = 2; // The wrapper
-    // will produce
-    // END_DOCUMENT
+                                                                               
                             // will produce
+                                                                               
                             // END_DOCUMENT
 
-    private static final int STATE_COMPLETED = 3; // Done
+    private static final int STATE_COMPLETED = 3;        // Done
 
-    private static final int STATE_INIT = 0; // The wrapper will produce
-    // START_DOCUMENT
+    private static final int STATE_INIT = 0;             // The wrapper will 
produce
+                                                                               
             // START_DOCUMENT
 
-    private static final int STATE_SWITCHED = 1; // The real reader will
-    // produce events
+    private static final int STATE_SWITCHED = 1;         // The real reader 
will
+                                                                               
                 // produce events
 
     private XMLStreamReader realReader;
     private boolean fragment;

Modified: 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java
 (original)
+++ 
tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/XMLEventsStreamReader.java
 Wed Jan 21 16:02:32 2009
@@ -20,9 +20,11 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Stack;
+
+import java.util.Iterator;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
@@ -39,12 +41,14 @@
 
        @SuppressWarnings("unused")
        private ArrayList<XMLEvent> events = null;
+       @SuppressWarnings("unchecked")
        private HashMap<String, NamespaceContext> eventContext = null;
 
        private int state;
        private java.util.Iterator<XMLEvent> iterator;
        private XMLEvent current;
 
+       @SuppressWarnings("unchecked")
        public XMLEventsStreamReader(List<XMLEvent> events,Map<String, 
NamespaceContext> map) {
                this.events = (ArrayList<XMLEvent>) events;
                this.eventContext = (HashMap<String, NamespaceContext>) map;

Modified: 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
 Wed Jan 21 16:02:32 2009
@@ -142,17 +142,6 @@
             } else {
                return null;
             }
-            
-            
-            //FIXME Re-enable feature after complete merge is done
-            /*
-            StAXArtifactProcessor<?> anyElementProcessor = 
processors.getProcessor(ANY_ELEMENT);
-            if (anyElementProcessor != null) {
-                return anyElementProcessor.read(source);
-            } else {
-                return null;
-            }
-            */
         }
         return processor.read(source);
     }

Modified: 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java
 (original)
+++ 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyNamespaceContext.java
 Wed Jan 21 16:02:32 2009
@@ -1,93 +1,114 @@
+/*
+ * 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.Collections;
 import java.util.Iterator;
-import java.util.List;
+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;
+    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;
-    }
-
-} //end of Class
+    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

Modified: 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java?rev=736500&r1=736499&r2=736500&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java
 (original)
+++ 
tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java
 Wed Jan 21 16:02:32 2009
@@ -1,5 +1,3 @@
-package org.apache.tuscany.sca.contribution.processor;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,6 +16,9 @@
  * 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;
@@ -29,7 +30,7 @@
 import javax.xml.stream.util.StreamReaderDelegate;
 
 /*
- * Custom implementation of the XMLStreamReader to keep track of the namespace 
context for each element
+ * Custom implementaion of the XMLStreamReader to keep track of the namespace 
context for each element
  */
 public class TuscanyXMLStreamReader extends StreamReaderDelegate implements 
XMLStreamReader {
 
@@ -106,4 +107,4 @@
     public NamespaceContext getNamespaceContext() {
         return new 
TuscanyNamespaceContext((Stack<List<String>[]>)context.clone());
     }
-}
+}
\ No newline at end of file


Reply via email to