[ 
https://issues.apache.org/jira/browse/TUSCANY-3874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13051453#comment-13051453
 ] 

Scott Kurz commented on TUSCANY-3874:
-------------------------------------

I recreated this by using the XMLStreamWriter in WebSphere.  So there's two 
levels you could approach this from.

1) the redundancy of two prefixes ns1 + sp_0, etc.for each 
implementation.widget element.
2) the fact that a single prefix can't be defined at an outer level, like the 
<composite> element, and used within.

2 might be trickier.. haven't given this much thought.. due to the independence 
of the StAXArtifactProcessor extensions.. not sure.

But 1) seems like it should be not so hard to fix.

Also note that I tried this with Woodstox running against the entire 1.7 
distribution and instead saw the following problem:

Exception in thread "main" javax.xml.stream.XMLStreamException: Unbound 
namespace URI 'http://tuscany.apache.org/xmlns/sca/1.0'
        at 
com.ctc.wstx.sw.SimpleNsStreamWriter.writeStartOrEmpty(SimpleNsStreamWriter.java:239)
        at 
com.ctc.wstx.sw.BaseNsStreamWriter.writeStartElement(BaseNsStreamWriter.java:312)
        at 
org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor.writeStart(BaseStAXArtifactProcessor.java:291)
        at 
org.apache.tuscany.sca.implementation.widget.WidgetImplementationProcessor.write(WidgetImplementationProcessor.java:164)

Not sure what the logic in BaseStAXArtifactProcessor relating to the prefixes 
is supposed to be doing, but that's where to look next I'm sure.

> Redundant namespace prefixes when creating new components
> ---------------------------------------------------------
>
>                 Key: TUSCANY-3874
>                 URL: https://issues.apache.org/jira/browse/TUSCANY-3874
>             Project: Tuscany
>          Issue Type: Bug
>          Components: Java SCA Assembly Model
>    Affects Versions: Java-SCA-1.5.1, Java-SCA-1.6.2
>         Environment: Windows XP, jre 1.6
>            Reporter: Adrian Padilla
>
> I am creating a couple of components using the following code:
> import java.io.FileOutputStream;
> import java.util.List;
> import javax.xml.namespace.QName;
> import javax.xml.stream.XMLInputFactory;
> import javax.xml.stream.XMLOutputFactory;
> import javax.xml.stream.XMLStreamWriter;
> import org.apache.tuscany.sca.assembly.AssemblyFactory;
> import org.apache.tuscany.sca.assembly.Component;
> import org.apache.tuscany.sca.assembly.Composite;
> import org.apache.tuscany.sca.assembly.xml.Constants;
> import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
> import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
> import 
> org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
> import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
> import org.apache.tuscany.sca.core.ExtensionPointRegistry;
> import org.apache.tuscany.sca.implementation.widget.WidgetImplementation;
> import 
> org.apache.tuscany.sca.implementation.widget.WidgetImplementationFactory;
> public class TuscanyCompositeSerializationTest {
>       public static void main(String[] args) throws Exception {
>               ExtensionPointRegistry registry = new 
> DefaultExtensionPointRegistry();
>               ModelFactoryExtensionPoint factories = registry
>                               
> .getExtensionPoint(ModelFactoryExtensionPoint.class);
>               AssemblyFactory assemblyFactory = 
> factories.getFactory(AssemblyFactory.class);
>               XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
>               XMLOutputFactory xmlOutputFactory = 
> XMLOutputFactory.newInstance();
>               factories.addFactory(xmlOutputFactory);
>               factories.addFactory(xmlInputFactory);
>               QName qName = new QName("http://www.example.org";, "test");
>               Composite composite = assemblyFactory.createComposite();
>               composite.setName(qName);
>               List<Component> components = composite.getComponents();
>               Component component = createWidgetComponent(factories, 
> assemblyFactory,"A");
>               components.add(component);
>               component = createWidgetComponent(factories, assemblyFactory, 
> "B");
>               components.add(component);
>               StAXArtifactProcessorExtensionPoint extensionPoint = registry
>                               
> .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
>               StAXArtifactProcessor<Composite> processor = extensionPoint
>                               .getProcessor(new QName(Constants.SCA10_NS, 
> Constants.COMPOSITE));
>               FileOutputStream fileOutputStream = new FileOutputStream(
>                               "test.composite");
>               XMLStreamWriter streamWriter = xmlOutputFactory
>                               .createXMLStreamWriter(fileOutputStream);
>               System.out.println(composite);
>               processor.write(composite, streamWriter);
>               fileOutputStream.close();
>       }
>       
>       private static Component createWidgetComponent(
>                       ModelFactoryExtensionPoint factories,
>                       AssemblyFactory assemblyFactory, String name) {
>               Component component = assemblyFactory.createComponent();
>               component.setName(name);
>               WidgetImplementationFactory widgetFactory = factories
>                               .getFactory(WidgetImplementationFactory.class);
>               WidgetImplementation widgetImpl = widgetFactory
>                               .createWidgetImplementation();
>               widgetImpl.setLocation(name + ".html");
>               component.setImplementation(widgetImpl);
>               return component;
>       }
> }
> And the output of this run is:
> <?xml version="1.0" encoding="UTF-8"?>
> <composite targetNamespace="http://www.example.org"; name="test" local="true" 
> xmlns="http://www.osoa.org/xmlns/sca/1.0";>
>       <component name="A">
>               <sp_0:implementation.widget 
>                       location="A.html" 
>                       xmlns:ns1="http://tuscany.apache.org/xmlns/sca/1.0"; 
>                       xmlns:sp_0="http://tuscany.apache.org/xmlns/sca/1.0";>
>               </sp_0:implementation.widget>
>       </component>
>       <component name="B">
>               <sp_1:implementation.widget 
>                       location="B.html" 
>                       xmlns:ns1="http://tuscany.apache.org/xmlns/sca/1.0"; 
>                       xmlns:sp_1="http://tuscany.apache.org/xmlns/sca/1.0";>
>               </sp_1:implementation.widget>
>       </component>
> </composite>
> Where http://tuscany.apache.org/xmlns/sca/1.0 is defined in every component I 
> add to the composite.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to