summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68>2011-06-13 15:02:01 +0000
committerbdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68>2011-06-13 15:02:01 +0000
commit6e8aa90f950cf8d8d98a0223fcea69d59da6a886 (patch)
tree06c841e11cdd0a530f3b3ee4b0893b4304e54522
parent153382cf88bcdde1d313cd16a276b7931edbcb53 (diff)
Add callback handling to PolicyAttachmentBuilder
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1135123 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java45
1 files changed, 34 insertions, 11 deletions
diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
index c7b48a47db..10e7c8ecb2 100644
--- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
+++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
@@ -32,6 +32,7 @@ import javax.xml.xpath.XPathExpression;
import org.apache.tuscany.sca.assembly.Base;
import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
@@ -248,6 +249,8 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
private static final QName COMPONENT = new QName(Base.SCA11_NS, "component");
private static final QName SERVICE = new QName(Base.SCA11_NS, "service");
private static final QName REFERENCE = new QName(Base.SCA11_NS, "reference");
+ private static final QName CALLBACK = new QName(Base.SCA11_NS, "callback");
+ private static final QName COMPOSITE = new QName(Base.SCA11_NS, "composite");
protected static String getStructuralURI(Node node) {
if (node != null) {
@@ -264,18 +267,26 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
Element component = (Element)node.getParentNode();
String uri = component.getAttributeNS(null, "uri");
String reference = ((Element)node).getAttributeNS(null, "name");
- return uri + "#reference(" + reference + ")";
- } else if ( new QName(Base.SCA11_NS, "composite").equals(name)) {
+ return uri + "#reference(" + reference + ")";
+ } else if ( COMPOSITE.equals(name)) {
return "";
} else {
String localName = node.getLocalName();
if (localName.startsWith("binding.")) {
+ boolean callback = false;
String bindingName = ((Element)node).getAttributeNS(null, "name");
- Element contract = (Element)node.getParentNode();
+ Element contract = (Element)node.getParentNode();
+ if ( "callback".equals(contract.getLocalName()) ) {
+ callback = true;
+ contract = (Element)contract.getParentNode();
+ }
String contractName = contract.getAttributeNS(null, "name");
- Element component = (Element)node.getParentNode().getParentNode();
+ Element component = (Element)contract.getParentNode();
String uri = component.getAttributeNS(null, "uri");
- return uri + "#" + contract.getLocalName() + "(" + contractName + "/" + bindingName + ")";
+ if ( callback )
+ return uri + "#" + contract.getLocalName() + "(" + contractName + "/callback/" + bindingName + ")";
+ else
+ return uri + "#" + contract.getLocalName() + "(" + contractName + "/" + bindingName + ")";
} else if (localName.startsWith("implementation.")) {
Element component = (Element)node.getParentNode();
String uri = component.getAttributeNS(null, "uri");
@@ -292,8 +303,15 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
return null;
}
- protected Binding getBinding(Contract contract, String name) {
- for (Binding binding : contract.getBindings()) {
+ protected Binding getBinding(Contract contract, String name, boolean isCallback) {
+ List<Binding> bindings = null;
+ if ( isCallback ) {
+ bindings = contract.getCallback().getBindings();
+ } else {
+ bindings = contract.getBindings();
+ }
+
+ for (Binding binding : bindings) {
if (name.equals(binding.getName())) {
return binding;
}
@@ -314,7 +332,8 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
String binding = null;
boolean isInterface = false;
boolean impl = false;
-
+ boolean isCallback = false;
+
if (index != -1) {
componentURI = structuralURI.substring(0, index);
String fragment = structuralURI.substring(index + 1);
@@ -325,10 +344,14 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
String prefix = fragment.substring(0, begin).trim();
if (prefix.equals("implementation")) {
impl = true;
- } else {
+ } else {
int pos = path.indexOf('/');
if (pos != -1) {
binding = path.substring(pos + 1);
+ if ( binding.startsWith("callback/")) {
+ binding = path.substring(pos + 10);
+ isCallback = true;
+ }
path = path.substring(0, pos);
if ("service-binding".equals(prefix)) {
service = path;
@@ -354,7 +377,7 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
if ( isInterface ) {
return componentService.getInterfaceContract().getInterface();
} else if (binding != null) {
- Binding b = getBinding(componentService, binding);
+ Binding b = getBinding(componentService, binding, isCallback);
if (b instanceof PolicySubject) {
return (PolicySubject)b;
}
@@ -364,7 +387,7 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
} else if (reference != null) {
ComponentReference componentReference = component.getReference(reference);
if (binding != null) {
- Binding b = getBinding(componentReference, binding);
+ Binding b = getBinding(componentReference, binding, isCallback);
if (b instanceof PolicySubject) {
return (PolicySubject)b;
}