diff options
Diffstat (limited to 'java/sca/modules/binding-gdata-gsoc')
5 files changed, 205 insertions, 1 deletions
diff --git a/java/sca/modules/binding-gdata-gsoc/pom.xml b/java/sca/modules/binding-gdata-gsoc/pom.xml index 131b50f054..173dcbe0b8 100644 --- a/java/sca/modules/binding-gdata-gsoc/pom.xml +++ b/java/sca/modules/binding-gdata-gsoc/pom.xml @@ -32,6 +32,18 @@ <dependencies> <dependency> <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core-spi</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-assembly</artifactId> <version>1.4-SNAPSHOT</version> </dependency> diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java index db7641f060..ab2acef234 100644 --- a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java +++ b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/GdataBinding.java @@ -40,4 +40,10 @@ public interface GdataBinding extends Binding { */ void setTitle(String title); + String getUsername(); + String getPassword(); + String getServiceType(); + void setUsername(String username); + void setPassword(String password); + void setServiceType(String serviceType); } diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java index 791f10b7df..03891f9228 100644 --- a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java +++ b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingImpl.java @@ -41,6 +41,9 @@ class GdataBindingImpl implements GdataBinding, OptimizableBinding, PolicySetAtt private String name; private String uri; private String title; + private String username; + private String password; + private String serviceType; private List<Intent> requiredIntents = new ArrayList<Intent>(); private List<PolicySet> policySets = new ArrayList<PolicySet>(); private IntentAttachPointType intentAttachPointType; @@ -57,6 +60,18 @@ class GdataBindingImpl implements GdataBinding, OptimizableBinding, PolicySetAtt public String getURI() { return uri; } + + public String getUsername(){ + return username; + } + + public String getPassword(){ + return password; + } + + public String getServiceType(){ + return serviceType; + } public void setName(String name) { this.name = name; @@ -65,6 +80,19 @@ class GdataBindingImpl implements GdataBinding, OptimizableBinding, PolicySetAtt public void setURI(String uri) { this.uri = uri; } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + public String getTitle() { return title; diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java new file mode 100644 index 0000000000..1cd0f72a93 --- /dev/null +++ b/java/sca/modules/binding-gdata-gsoc/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GdataBindingProcessor.java @@ -0,0 +1,158 @@ +/* + * 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.binding.gdata.impl; + +import java.util.ArrayList; +import java.util.List; + +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.xml.PolicyAttachPointProcessor; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +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.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.impl.IntentAttachPointTypeFactoryImpl; + +import org.apache.tuscany.sca.binding.gdata.GdataBinding; +import org.apache.tuscany.sca.binding.gdata.GdataBindingFactory; + +/** + * A processor for <binding.gdata> elements. + */ +public class GdataBindingProcessor implements StAXArtifactProcessor<GdataBinding> { + + private QName BINDING_GDATA = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "binding.gdata"); + + private final GdataBindingFactory factory; + + //private PolicyAttachPointProcessor policyProcessor; + + public GdataBindingProcessor(ModelFactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(GdataBindingFactory.class); + System.out.println("[Debug Info]GdataBindingProcessor reached"); + //this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + public QName getArtifactType() { + return BINDING_GDATA; + } + + public Class<GdataBinding> getModelType() { + return GdataBinding.class; + } + + public GdataBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + GdataBinding gdataBinding = factory.createGdataBinding(); + IntentAttachPointType bindingType = new IntentAttachPointTypeFactoryImpl().createBindingType(); + bindingType.setName(getArtifactType()); + bindingType.setUnresolved(true); + ((PolicySetAttachPoint)gdataBinding).setType(bindingType); + + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + gdataBinding.setName(name); + } + + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + gdataBinding.setURI(uri); + } + + String serviceType = reader.getAttributeValue(null, "serviceType"); + if (serviceType != null) { + gdataBinding.setServiceType(serviceType); + } + + String username = reader.getAttributeValue(null, "username"); + if (username != null) { + gdataBinding.setUsername(username); + } + + String password = reader.getAttributeValue(null, "password"); + if (password != null) { + gdataBinding.setPassword(password); + } + + //policyProcessor.readPolicies(echoBinding, reader); + + return gdataBinding; + } + + public void write(GdataBinding gdataBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + //policyProcessor.writePolicyPrefixes(gdataBinding, writer); + writer.writeStartElement(BINDING_GDATA.getNamespaceURI(), BINDING_GDATA.getLocalPart()); + //policyProcessor.writePolicyAttributes(gdataBinding, writer); + + if (gdataBinding.getName() != null) { + writer.writeAttribute("name", gdataBinding.getName()); + } + + if (gdataBinding.getURI() != null) { + writer.writeAttribute("uri", gdataBinding.getURI()); + } + + if (gdataBinding.getServiceType() != null) { + writer.writeAttribute("serviceType", gdataBinding.getServiceType()); + } + + if (gdataBinding.getUsername() != null) { + writer.writeAttribute("username", gdataBinding.getUsername()); + } + + if (gdataBinding.getPassword() != null) { + writer.writeAttribute("password", gdataBinding.getPassword()); + } + + writer.writeEndElement(); + } + + + //FIXME: Resolve the attached policySet, might not needed (the echo binding implementation example) + public void resolve(GdataBinding gdataBinding, ModelResolver resolver) throws ContributionResolveException { + PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)gdataBinding; + List<Intent> requiredIntents = new ArrayList<Intent>(); + Intent resolvedIntent = null; + for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) { + resolvedIntent = resolver.resolveModel(Intent.class, intent); + requiredIntents.add(resolvedIntent); + } + policySetAttachPoint.getRequiredIntents().clear(); + policySetAttachPoint.getRequiredIntents().addAll(requiredIntents); + + List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>(); + PolicySet resolvedPolicySet = null; + for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) { + resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet); + resolvedPolicySets.add(resolvedPolicySet); + } + policySetAttachPoint.getPolicySets().clear(); + policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets); + } +} diff --git a/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 9b4a5648f9..4e71818f7b 100644 --- a/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/java/sca/modules/binding-gdata-gsoc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -16,4 +16,4 @@ # under the License. # Implementation class for the artifact processor extension -org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GdataBinding,factory=org.apache.tuscany.sca.binding.gdata.GdataBindingFactory
\ No newline at end of file +org.apache.tuscany.sca.binding.gdata.impl.GdataBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GdataBinding,factory=org.apache.tuscany.sca.binding.gdata.GdataBindingFactory
\ No newline at end of file |