diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main')
5 files changed, 99 insertions, 6 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java index 89c87ad1d1..66cb3c76fc 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaNamespaceHandler.java @@ -16,7 +16,15 @@ */ package org.apache.tuscany.sca.implementation.spring.namespace; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; + import org.springframework.beans.factory.xml.NamespaceHandlerSupport; +import org.w3c.dom.Element; +import org.w3c.dom.Node; /** * Handler for the <sca:> namespace in an application context @@ -35,4 +43,51 @@ public class ScaNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("property", new ScaPropertyBeanDefinitionParser()); } + private static String getNamespaceURI(Element element, String prefix) { + if (element == null) { + return null; + } + String name = ("".equals(prefix)) ? "xmlns" : "xmlns:" + prefix; + String ns = element.getAttribute(name); + if (ns != null && !"".equals(ns)) { + return ns; + } + Node parent = element.getParentNode(); + if (parent instanceof Element) { + return getNamespaceURI((Element)parent, prefix); + } else { + return null; + } + } + + public static List<QName> resolve(Element element, String listOfNames) { + List<QName> qnames = new ArrayList<QName>(); + StringTokenizer tokenizer = new StringTokenizer(listOfNames); + while (tokenizer.hasMoreTokens()) { + String qname = tokenizer.nextToken(); + String prefix = ""; + String local = qname; + int index = qname.indexOf(':'); + if (index != -1) { + local = qname.substring(index + 1); + prefix = qname.substring(0, index); + } + String ns = getNamespaceURI(element, prefix); + if (ns != null) { + qnames.add(new QName(ns, local, prefix)); + } else { + throw new IllegalArgumentException("Prefix " + prefix + "is not bound to a namespace"); + } + } + return qnames; + } + + public static String getAttribute(Element element, String name) { + String attr = element.getAttributeNS(null, name); + if ("".equals(attr)) { + return null; + } else { + return attr; + } + } } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java index 6cb4978a47..ab797c1e52 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaReferenceBeanDefinitionParser.java @@ -16,6 +16,12 @@ */ package org.apache.tuscany.sca.implementation.spring.namespace; +import static org.apache.tuscany.sca.implementation.spring.namespace.ScaNamespaceHandler.getAttribute; + +import java.util.List; + +import javax.xml.namespace.QName; + import org.apache.tuscany.sca.implementation.spring.SpringSCAReferenceElement; import org.apache.tuscany.sca.implementation.spring.context.SCAGenericApplicationContext; import org.springframework.beans.factory.config.BeanDefinition; @@ -36,9 +42,21 @@ public class ScaReferenceBeanDefinitionParser implements BeanDefinitionParser { if (registry instanceof SCAGenericApplicationContext) { SCAGenericApplicationContext context = (SCAGenericApplicationContext)registry; SpringSCAReferenceElement referenceElement = - new SpringSCAReferenceElement(element.getAttributeNS(null, "name"), - element.getAttributeNS(null, "type")); - referenceElement.setDefaultBean(element.getAttributeNS(null, "default")); + new SpringSCAReferenceElement(getAttribute(element, "name"), getAttribute(element, "type")); + referenceElement.setDefaultBean(getAttribute(element, "default")); + + String requires = getAttribute(element, "requires"); + if (requires != null) { + List<QName> qnames = ScaNamespaceHandler.resolve(element, requires); + referenceElement.getIntentNames().addAll(qnames); + } + + String policySets = getAttribute(element, "policySets"); + if (policySets != null) { + List<QName> qnames = ScaNamespaceHandler.resolve(element, policySets); + referenceElement.getPolicySetNames().addAll(qnames); + } + context.addSCAReferenceElement(referenceElement); } diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java index e5eabd2a4b..6a3beebcff 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/namespace/ScaServiceBeanDefinitionParser.java @@ -16,6 +16,12 @@ */ package org.apache.tuscany.sca.implementation.spring.namespace; +import static org.apache.tuscany.sca.implementation.spring.namespace.ScaNamespaceHandler.getAttribute; + +import java.util.List; + +import javax.xml.namespace.QName; + import org.apache.tuscany.sca.implementation.spring.SpringSCAServiceElement; import org.apache.tuscany.sca.implementation.spring.context.SCAGenericApplicationContext; import org.springframework.beans.factory.config.BeanDefinition; @@ -36,9 +42,21 @@ public class ScaServiceBeanDefinitionParser implements BeanDefinitionParser { if (registry instanceof SCAGenericApplicationContext) { SCAGenericApplicationContext context = (SCAGenericApplicationContext)registry; SpringSCAServiceElement serviceElement = - new SpringSCAServiceElement(element.getAttributeNS(null, "name"), - element.getAttributeNS(null, "target")); - serviceElement.setType(element.getAttributeNS(null, "type")); + new SpringSCAServiceElement(getAttribute(element, "name"), getAttribute(element, "target")); + serviceElement.setType(getAttribute(element, "type")); + + String requires = getAttribute(element, "requires"); + if (requires != null) { + List<QName> qnames = ScaNamespaceHandler.resolve(element, requires); + serviceElement.getIntentNames().addAll(qnames); + } + + String policySets = getAttribute(element, "policySets"); + if (policySets != null) { + List<QName> qnames = ScaNamespaceHandler.resolve(element, policySets); + serviceElement.getPolicySetNames().addAll(qnames); + } + context.addSCAServiceElement(serviceElement); } // do nothing, handled by Tuscany diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java index 71feddb9f5..6ba2c65ef0 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/SpringXMLBeanDefinitionLoaderImpl.java @@ -67,6 +67,7 @@ public class SpringXMLBeanDefinitionLoaderImpl implements SpringXMLBeanDefinitio List<SpringSCAPropertyElement> propertyElements, List<SpringBeanElement> beanElements, ProcessorContext context) { + // FIXME: [rfeng] We should try to avoid parsing the Spring xml twice for the deployment and runtime SCAGenericApplicationContext applicationContext = createApplicationContext(null, null, resources); serviceElements.addAll(applicationContext.getServiceElements()); referenceElements.addAll(applicationContext.getReferenceElements()); diff --git a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/spring.handlers b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/spring.handlers index 6d29e21024..1e1f558382 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/spring.handlers +++ b/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/resources/META-INF/spring.handlers @@ -1 +1,2 @@ http\://www.springframework.org/schema/sca=org.apache.tuscany.sca.implementation.spring.namespace.ScaNamespaceHandler
+http\://docs.oasis-open.org/ns/opencsa/sca-j/spring/200810=org.apache.tuscany.sca.implementation.spring.namespace.ScaNamespaceHandler
|