diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-29 01:04:17 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-29 01:04:17 +0000 |
commit | 52cae7f873d9c547d756d8c2da11e6bcd0e9aba0 (patch) | |
tree | 37c08452c7195c95e478c4a1437b9a3dfa98c576 | |
parent | 5ad36bb5f350dd6ab49f74d802841f6fdc049c5b (diff) |
Adding support for extended attributes to java interface
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@738691 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 52 insertions, 2 deletions
diff --git a/branches/sca-java-1.x/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java b/branches/sca-java-1.x/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java index ae5bf4c56d..b8f7a4b93b 100644 --- a/branches/sca-java-1.x/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java +++ b/branches/sca-java-1.x/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java @@ -26,10 +26,13 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; 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.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.contribution.service.ContributionReadException; @@ -50,10 +53,17 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfaceContract>, JavaConstants { private JavaInterfaceFactory javaFactory; + private ExtensionFactory extensionFactory; + private StAXAttributeProcessor<Object> extensionAttributeProcessor; private Monitor monitor; - public JavaInterfaceProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + public JavaInterfaceProcessor(ModelFactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.extensionAttributeProcessor = extensionAttributeProcessor; this.monitor = monitor; } @@ -108,6 +118,23 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa javaInterfaceContract.setCallbackInterface(javaCallbackInterface); } + // Handle extended attributes + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { + if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) && + (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension) attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + javaInterfaceContract.getAttributeExtensions().add(attributeExtension); + } + } + } // Skip to end element while (reader.hasNext()) { if (reader.next() == END_ELEMENT && INTERFACE_JAVA_QNAME.equals(reader.getName())) { @@ -131,6 +158,13 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa if (javaCallbackInterface != null && javaCallbackInterface.getName() != null) { writer.writeAttribute(CALLBACK_INTERFACE, javaCallbackInterface.getName()); } + + // Write extended attributes + for(Extension extension : javaInterfaceContract.getAttributeExtensions()) { + if(extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } writer.writeEndElement(); } diff --git a/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java b/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java index e3a84c63f0..ac747d579d 100644 --- a/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java +++ b/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.interfacedef.java; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.interfacedef.InterfaceContract; /** @@ -27,6 +28,6 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContract; * * @version $Rev$ $Date$ */ -public interface JavaInterfaceContract extends InterfaceContract { +public interface JavaInterfaceContract extends InterfaceContract, Extensible { } diff --git a/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java b/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java index d43ebe558b..009eaf90c9 100644 --- a/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java +++ b/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java @@ -18,6 +18,10 @@ */ package org.apache.tuscany.sca.interfacedef.java.impl; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; @@ -27,6 +31,8 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; * @version $Rev$ $Date$ */ public class JavaInterfaceContractImpl extends InterfaceContractImpl implements JavaInterfaceContract { + private List<Object> extensions = new ArrayList<Object>(); + private List<Extension> attributeExtensions = new ArrayList<Extension>(); protected JavaInterfaceContractImpl() { } @@ -36,4 +42,13 @@ public class JavaInterfaceContractImpl extends InterfaceContractImpl implements return (JavaInterfaceContractImpl) super.clone(); } + public List<Object> getExtensions() { + return extensions; + } + + public List<Extension> getAttributeExtensions() { + return attributeExtensions; + } + + } |