summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-12-04 23:08:49 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-12-04 23:08:49 +0000
commitd15ee677eeba5b76444202ed18862faa19296d63 (patch)
tree0737ece92d7d6066869966aab9a981ffdf2a6d7f
parentbc1c8ab4c48c3a81824dac27ba71a8d1277797b9 (diff)
Java implementation clean up in preparation for some refactoring
- removal of unused code - review of code visibility - renaming of exception to follow best practices naming convention - etc git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@723484 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java3
-rw-r--r--java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java140
-rw-r--r--java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java4
-rw-r--r--java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java126
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java2
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java6
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java233
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementationException.java (renamed from java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java)6
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceTypeException.java (renamed from java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java)6
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java297
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java83
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java22
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java42
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java50
14 files changed, 509 insertions, 511 deletions
diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java
index 4a8c8f31b8..fbc2ace341 100644
--- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java
+++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java
@@ -25,8 +25,9 @@ package org.apache.tuscany.sca.implementation.java.injection;
* @version $Rev$ $Date$
*/
public abstract class InjectionRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = -2264137603099898773L;
- public InjectionRuntimeException() {
+ public InjectionRuntimeException() {
super();
}
diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
index 6dfa6b132b..1eac9ce7a6 100644
--- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
+++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
@@ -98,8 +98,8 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
}
-
- public ObjectFactory createValueFactory(Property property, Object propertyValue, Class javaType) {
+
+ public ObjectFactory createValueFactory(Property property, Object propertyValue, Class<?> javaType) {
isSimpleType = isSimpleType(property);
Document doc = (Document)propertyValue;
Element rootElement = doc.getDocumentElement();
@@ -133,61 +133,24 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
}
- private boolean isSimpleType(Property property) {
- if (property.getXSDType() != null) {
- return SimpleTypeMapperImpl.isSimpleXSDType(property.getXSDType());
- } else {
- if (property instanceof Document) {
- Document doc = (Document)property;
- Element element = doc.getDocumentElement();
- if (element.getChildNodes().getLength() == 1 && element.getChildNodes().item(0).getNodeType() == Element.TEXT_NODE) {
- return true;
- }
- }
- }
- return false;
- }
- private List<String> getSimplePropertyValues(String concatenatedValue, Class<?> javaType) {
- List<String> propValues = new ArrayList<String>();
- StringTokenizer st = null;
- if (javaType.getName().equals("java.lang.String")) {
- st = new StringTokenizer(concatenatedValue, "\"");
- } else {
- st = new StringTokenizer(concatenatedValue);
- }
- String aToken = null;
- while (st.hasMoreTokens()) {
- aToken = st.nextToken();
- if (aToken.trim().length() > 0) {
- propValues.add(aToken);
- }
- }
- return propValues;
+ public <B> B createPropertyValue(ComponentProperty property, Class<B> type)
+ {
+ ObjectFactory<B> factory = this.createValueFactory(property, property.getValue(), type);
+ return factory.getInstance();
}
- private List<Node> getComplexPropertyValues(Document document) {
- Element rootElement = document.getDocumentElement();
- List<Node> propValues = new ArrayList<Node>();
- NodeList nodes = rootElement.getChildNodes();
- for (int count = 0; count < nodes.getLength(); ++count) {
- if (nodes.item(count).getNodeType() == Document.ELEMENT_NODE) {
- propValues.add(DOMHelper.promote(nodes.item(count)));
- }
- }
- return propValues;
- }
- public abstract class ObjectFactoryImplBase implements ObjectFactory {
+ abstract class ObjectFactoryImplBase implements ObjectFactory {
protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl();
protected Property property;
protected Object propertyValue;
- protected Class javaType;
+ protected Class<?> javaType;
protected DataType<XMLType> sourceDataType;
protected DataType<?> targetDataType;
boolean isSimpleType;
- public ObjectFactoryImplBase(Property property, Object propertyValue, boolean isSimpleType, Class javaType) {
+ public ObjectFactoryImplBase(Property property, Object propertyValue, boolean isSimpleType, Class<?> javaType) {
this.isSimpleType = isSimpleType;
this.property = property;
this.propertyValue = propertyValue;
@@ -216,8 +179,8 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
}
- public class ObjectFactoryImpl extends ObjectFactoryImplBase {
- public ObjectFactoryImpl(Property property, Object propertyValue, boolean isSimpleType, Class javaType) {
+ class ObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ObjectFactoryImpl(Property property, Object propertyValue, boolean isSimpleType, Class<?> javaType) {
super(property, propertyValue, isSimpleType, javaType);
}
@@ -239,8 +202,8 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
}
- public class ListObjectFactoryImpl extends ObjectFactoryImplBase {
- public ListObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class javaType) {
+ class ListObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ListObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class<?> javaType) {
super(property, propertyValues, isSimpleType, javaType);
}
@@ -272,8 +235,8 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
}
- public class ArrayObjectFactoryImpl extends ObjectFactoryImplBase {
- public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class javaType) {
+ class ArrayObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class<?> javaType) {
super(property, propertyValues, isSimpleType, javaType);
}
@@ -307,18 +270,71 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
}
+
+
+ /**
+ * Utility methods
+ */
+
/**
- * This method will create an instance of the value for the specified Property.
- *
- * @param property The Property from which to retrieve the property value
- * @param type The type of the property value being retrieved from the Property
- * @param <B> Type type of the property value being looked up
*
- * @return the value for the Property
+ * @param property
+ * @return
*/
- public <B> B createPropertyValue(ComponentProperty property, Class<B> type)
- {
- ObjectFactory<B> factory = this.createValueFactory(property, property.getValue(), type);
- return factory.getInstance();
+ private static boolean isSimpleType(Property property) {
+ if (property.getXSDType() != null) {
+ return SimpleTypeMapperImpl.isSimpleXSDType(property.getXSDType());
+ } else {
+ if (property instanceof Document) {
+ Document doc = (Document)property;
+ Element element = doc.getDocumentElement();
+ if (element.getChildNodes().getLength() == 1 && element.getChildNodes().item(0).getNodeType() == Element.TEXT_NODE) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * Retrieve list of simple property values
+ * @param concatenatedValue
+ * @param javaType
+ * @return
+ */
+ private static List<String> getSimplePropertyValues(String concatenatedValue, Class<?> javaType) {
+ List<String> propValues = new ArrayList<String>();
+ StringTokenizer st = null;
+ if (javaType.getName().equals("java.lang.String")) {
+ st = new StringTokenizer(concatenatedValue, "\"");
+ } else {
+ st = new StringTokenizer(concatenatedValue);
+ }
+ String aToken = null;
+ while (st.hasMoreTokens()) {
+ aToken = st.nextToken();
+ if (aToken.trim().length() > 0) {
+ propValues.add(aToken);
+ }
+ }
+ return propValues;
+ }
+
+ /**
+ * Retrieve the list of complex property values
+ * @param document
+ * @return
+ */
+ private static List<Node> getComplexPropertyValues(Document document) {
+ Element rootElement = document.getDocumentElement();
+ List<Node> propValues = new ArrayList<Node>();
+ NodeList nodes = rootElement.getChildNodes();
+ for (int count = 0; count < nodes.getLength(); ++count) {
+ if (nodes.item(count).getNodeType() == Document.ELEMENT_NODE) {
+ propValues.add(DOMHelper.promote(nodes.item(count)));
+ }
+ }
+ return propValues;
}
}
diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
index 9f587f58de..2906897e96 100644
--- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
+++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
@@ -30,7 +30,7 @@ import org.apache.tuscany.sca.core.factory.ObjectFactory;
*
* @version $Rev$ $Date$
*/
-public class ListMultiplicityObjectFactory implements ObjectFactory<List> {
+public class ListMultiplicityObjectFactory implements ObjectFactory<List<?>> {
private ObjectFactory[] factories;
@@ -39,7 +39,7 @@ public class ListMultiplicityObjectFactory implements ObjectFactory<List> {
this.factories = factories.toArray(new ObjectFactory[factories.size()]);
}
- public List getInstance() throws ObjectCreationException {
+ public List<?> getInstance() throws ObjectCreationException {
List<Object> list = new ArrayList<Object>();
for (ObjectFactory factory : factories) {
list.add(factory.getInstance());
diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
deleted file mode 100644
index ee3507ef80..0000000000
--- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.implementation.java.invocation;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.ConfiguredOperation;
-import org.apache.tuscany.sca.assembly.OperationsConfigurator;
-import org.apache.tuscany.sca.implementation.java.JavaImplementation;
-import org.apache.tuscany.sca.invocation.InvocationChain;
-import org.apache.tuscany.sca.invocation.Phase;
-import org.apache.tuscany.sca.policy.PolicySet;
-import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
-import org.apache.tuscany.sca.policy.util.PolicyHandler;
-import org.apache.tuscany.sca.policy.util.PolicyHandlerUtils;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeWire;
-import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
-
-/**
- * Processor to inject policy handling interceptor whenever PolicySets are specified in a Java Implementation
- *
- * @version $Rev$ $Date$
- */
-public class JavaPolicyHandlingRuntimeWireProcessor implements RuntimeWireProcessor {
- private static final Logger logger = Logger.getLogger(JavaPolicyHandlingRuntimeWireProcessor.class.getName());
-
- public JavaPolicyHandlingRuntimeWireProcessor() {
- super();
- }
-
- public void process(RuntimeWire wire) {
- /*Contract contract = wire.getSource().getContract();
- if (!(contract instanceof RuntimeComponentReference)) {
- return;
- }*/
-
- RuntimeComponent component = wire.getTarget().getComponent();
- if (component != null && component.getImplementation() instanceof JavaImplementation) {
- JavaImplementation javaImpl = (JavaImplementation)component.getImplementation();
- if (javaImpl instanceof PolicySetAttachPoint) {
- PolicyHandler policyHandler = null;
- List<PolicyHandler> implPolicyHandlers = new ArrayList<PolicyHandler>();
- PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)javaImpl;
-
- try {
- //for ( PolicySet policySet : policiedImpl.getPolicySets() ) {
- for (PolicySet policySet : component.getPolicySets()) {
- policyHandler =
- PolicyHandlerUtils.findPolicyHandler(policySet, javaImpl.getPolicyHandlerClassNames());
- if (policyHandler != null) {
- policyHandler.setUp(javaImpl);
- implPolicyHandlers.add(policyHandler);
- } else {
- //FIXME: to be removed after the PolicyHandler story has crystalized..
- //maybe replace with exception then...
- logger.warning("No PolicyHandler registered for PolicySet - " + policySet.getName());
- }
- }
-
- List<PolicyHandler> applicablePolicyHandlers = null;
- for (InvocationChain chain : wire.getInvocationChains()) {
- applicablePolicyHandlers = new ArrayList<PolicyHandler>();
- if (javaImpl instanceof OperationsConfigurator) {
- String operationName = chain.getTargetOperation().getName();
- OperationsConfigurator opConfigurator = (OperationsConfigurator)component;
- for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
- if (confOp.getName().equals(operationName)) {
- for (PolicySet policySet : confOp.getPolicySets()) {
- policyHandler =
- PolicyHandlerUtils.findPolicyHandler(policySet, javaImpl
- .getPolicyHandlerClassNames());
- if (policyHandler != null) {
- policyHandler.setUp(javaImpl);
- applicablePolicyHandlers.add(policyHandler);
- } else {
- logger.warning("No PolicyHandler registered for " + policySet);
- }
- }
- break;
- }
- }
-
- //if no policies have been specified at the operation level then simply
- //apply whatever is specified for the implementation level
- if (applicablePolicyHandlers.isEmpty()) {
- applicablePolicyHandlers = implPolicyHandlers;
- }
- }
-
- if (!applicablePolicyHandlers.isEmpty()) {
- String phase =
- (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_POLICY
- : Phase.SERVICE_POLICY;
-
- chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, new PolicyHandlingInterceptor(chain.getTargetOperation(),
- applicablePolicyHandlers));
- }
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
index 6d27dff9c9..e7f2638255 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
@@ -50,7 +50,7 @@ public abstract class AbstractPropertyProcessor<A extends Annotation> extends Ba
this.annotationClass = annotationClass;
}
- private boolean removeProperty(JavaElementImpl prop, JavaImplementation type) {
+ private static boolean removeProperty(JavaElementImpl prop, JavaImplementation type) {
if(prop==null) {
return false;
}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java
index 327bd97564..814ca8ca6c 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java
@@ -65,7 +65,7 @@ public class ConversationProcessor extends BaseJavaClassVisitor {
type.setMaxAge(maxAge);
}
} catch (NumberFormatException e) {
- throw new InvalidConversationalImplementation("Invalid maximum age", e);
+ throw new InvalidConversationalImplementationException("Invalid maximum age", e);
}
try {
if (maxIdleTimeVal.length() > 0) {
@@ -73,7 +73,7 @@ public class ConversationProcessor extends BaseJavaClassVisitor {
type.setMaxIdleTime(maxIdleTime);
}
} catch (NumberFormatException e) {
- throw new InvalidConversationalImplementation("Invalid maximum idle time", e);
+ throw new InvalidConversationalImplementationException("Invalid maximum idle time", e);
}
}
@@ -99,7 +99,7 @@ public class ConversationProcessor extends BaseJavaClassVisitor {
type.addConversationIDMember(field);
}
- protected long convertTimeMillis(String expr) throws NumberFormatException {
+ static long convertTimeMillis(String expr) throws NumberFormatException {
expr = expr.trim().toUpperCase();
int i = expr.lastIndexOf(SECONDS);
if (i >= 0) {
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
index f4c88e61ad..ab07870086 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
@@ -134,17 +134,6 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
}
- private boolean isPublicSetter(Method method) {
- return method.getParameterTypes().length == 1 && Modifier.isPublic(method.getModifiers())
- && method.getName().startsWith("set")
- && method.getReturnType() == void.class;
- }
-
- private boolean isProtectedSetter(Method method) {
- return method.getParameterTypes().length == 1 && Modifier.isProtected(method.getModifiers())
- && method.getName().startsWith("set")
- && method.getReturnType() == void.class;
- }
private <T> void calcPropRefs(Set<Method> methods,
List<org.apache.tuscany.sca.assembly.Service> services,
@@ -360,10 +349,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
}
- private static boolean areUnique(Class<?>[] collection) {
- Set<Class<?>> set = new HashSet<Class<?>>(Arrays.asList(collection));
- return set.size() == collection.length;
- }
+
/**
* Returns true if the union of the given collections of properties and
@@ -440,6 +426,119 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
/**
+ * Creates a mapped property.
+ *
+ * @param name the property name
+ * @param paramType the property type
+ */
+ private org.apache.tuscany.sca.assembly.Property createProperty(String name, Class<?> paramType) {
+ org.apache.tuscany.sca.assembly.Property property = assemblyFactory.createProperty();
+ property.setName(name);
+ property.setXSDType(JavaXMLMapper.getXMLType(paramType));
+ return property;
+ }
+
+ private org.apache.tuscany.sca.assembly.Reference createReference(String name, Class<?> paramType)
+ throws IntrospectionException {
+ org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
+ reference.setName(name);
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ reference.setInterfaceContract(interfaceContract);
+ try {
+ JavaInterface callInterface = javaFactory.createJavaInterface(paramType);
+ reference.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ reference.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
+ } catch (InvalidInterfaceException e1) {
+ throw new IntrospectionException(e1);
+ }
+
+ // FIXME: This part seems to have already been taken care above!!
+ try {
+ processCallback(paramType, reference);
+ } catch (InvalidServiceTypeException e) {
+ throw new IntrospectionException(e);
+ }
+ return reference;
+ }
+
+ private org.apache.tuscany.sca.assembly.Service createService(Class<?> interfaze) throws InvalidInterfaceException {
+ org.apache.tuscany.sca.assembly.Service service = assemblyFactory.createService();
+ service.setName(interfaze.getSimpleName());
+
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+
+ JavaInterface callInterface = javaFactory.createJavaInterface(interfaze);
+ service.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ service.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+
+ Interface javaInterface = service.getInterfaceContract().getInterface();
+ javaInterface.setRemotable(interfaze.getAnnotation(Remotable.class) != null);
+ service.getInterfaceContract().setInterface(javaInterface);
+ return service;
+ }
+
+ private void processCallback(Class<?> interfaze, Contract contract) throws InvalidServiceTypeException {
+ Callback callback = interfaze.getAnnotation(Callback.class);
+ if (callback != null && !Void.class.equals(callback.value())) {
+ Class<?> callbackClass = callback.value();
+ JavaInterface javaInterface;
+ try {
+ javaInterface = javaFactory.createJavaInterface(callbackClass);
+ contract.getInterfaceContract().setCallbackInterface(javaInterface);
+ } catch (InvalidInterfaceException e) {
+ throw new InvalidServiceTypeException("Invalid callback interface "+callbackClass, interfaze);
+ }
+ } else if (callback != null && Void.class.equals(callback.value())) {
+ throw new InvalidServiceTypeException("No callback interface specified on annotation", interfaze);
+ }
+ }
+
+
+ /**
+ * Utility methods
+ */
+
+
+ /**
+ * Verify if the method is a public setter
+ * @param method
+ * @return
+ */
+ private static boolean isPublicSetter(Method method) {
+ return method.getParameterTypes().length == 1 && Modifier.isPublic(method.getModifiers())
+ && method.getName().startsWith("set")
+ && method.getReturnType() == void.class;
+ }
+
+ /**
+ * Verify if the method is a protected setter
+ * @param method
+ * @return
+ */
+ private static boolean isProtectedSetter(Method method) {
+ return method.getParameterTypes().length == 1 && Modifier.isProtected(method.getModifiers())
+ && method.getName().startsWith("set")
+ && method.getReturnType() == void.class;
+ }
+
+ /**
+ * @param collection
+ * @return
+ */
+ private static boolean areUnique(Class<?>[] collection) {
+ Set<Class<?>> set = new HashSet<Class<?>>(Arrays.asList(collection));
+ return set.size() == collection.length;
+ }
+
+ /**
* Returns true if a given type is reference according to the SCA
* specification rules for determining reference types The following rules
* are used to determine whether an unannotated field or setter method is a
@@ -462,7 +561,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
* The name of the reference or of the property is derived from the
* name found on the setter method or on the field.
*/
- private boolean isReferenceType(Class<?> cls, Type genericType) {
+ private static boolean isReferenceType(Class<?> cls, Type genericType) {
Class<?> baseType = JavaIntrospectionHelper.getBaseType(cls, genericType);
return baseType.isInterface() && baseType.isAnnotationPresent(Remotable.class);
}
@@ -470,8 +569,11 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
/**
* Returns true if the given operation is defined in the collection of
* service interfaces
+ * @param operation
+ * @param services
+ * @return
*/
- private boolean isInServiceInterface(Method operation, List<org.apache.tuscany.sca.assembly.Service> services) {
+ private static boolean isInServiceInterface(Method operation, List<org.apache.tuscany.sca.assembly.Service> services) {
for (org.apache.tuscany.sca.assembly.Service service : services) {
Interface interface1 = service.getInterfaceContract().getInterface();
if (interface1 instanceof JavaInterface) {
@@ -492,7 +594,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
* @param method
* @return
*/
- private boolean isMethodMatched(Class<?> clazz, Method method) {
+ private static boolean isMethodMatched(Class<?> clazz, Method method) {
if (method.getDeclaringClass() == clazz) {
return true;
}
@@ -506,19 +608,11 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
/**
- * Creates a mapped property.
- *
- * @param name the property name
- * @param paramType the property type
+ * Verify if there is any SCA annotation on the parameter
+ * @param parameter
+ * @return
*/
- private org.apache.tuscany.sca.assembly.Property createProperty(String name, Class<?> paramType) {
- org.apache.tuscany.sca.assembly.Property property = assemblyFactory.createProperty();
- property.setName(name);
- property.setXSDType(JavaXMLMapper.getXMLType(paramType));
- return property;
- }
-
- private boolean isAnnotated(JavaParameterImpl parameter) {
+ private static boolean isAnnotated(JavaParameterImpl parameter) {
for (Annotation annotation : parameter.getAnnotations()) {
Class<? extends Annotation> annotType = annotation.annotationType();
if (annotType.equals(Property.class) || annotType.equals(Reference.class)
@@ -529,7 +623,12 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
return false;
}
- public boolean areUnique(JavaParameterImpl[] parameters) {
+ /**
+ * Verify if the parameters are unique
+ * @param parameters
+ * @return
+ */
+ private static boolean areUnique(JavaParameterImpl[] parameters) {
Set<Class<?>> set = new HashSet<Class<?>>(parameters.length);
for (JavaParameterImpl p : parameters) {
if (!set.add(p.getType())) {
@@ -538,71 +637,13 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
return true;
}
-
- public org.apache.tuscany.sca.assembly.Reference createReference(String name, Class<?> paramType)
- throws IntrospectionException {
- org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
- reference.setName(name);
- JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
- reference.setInterfaceContract(interfaceContract);
- try {
- JavaInterface callInterface = javaFactory.createJavaInterface(paramType);
- reference.getInterfaceContract().setInterface(callInterface);
- if (callInterface.getCallbackClass() != null) {
- JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
- reference.getInterfaceContract().setCallbackInterface(callbackInterface);
- }
- reference.setMultiplicity(Multiplicity.ZERO_ONE);
- } catch (InvalidInterfaceException e1) {
- throw new IntrospectionException(e1);
- }
-
- // FIXME: This part seems to have already been taken care above!!
- try {
- processCallback(paramType, reference);
- } catch (InvalidServiceType e) {
- throw new IntrospectionException(e);
- }
- return reference;
- }
-
- public org.apache.tuscany.sca.assembly.Service createService(Class<?> interfaze) throws InvalidInterfaceException {
- org.apache.tuscany.sca.assembly.Service service = assemblyFactory.createService();
- service.setName(interfaze.getSimpleName());
-
- JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
- service.setInterfaceContract(interfaceContract);
-
- JavaInterface callInterface = javaFactory.createJavaInterface(interfaze);
- service.getInterfaceContract().setInterface(callInterface);
- if (callInterface.getCallbackClass() != null) {
- JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
- service.getInterfaceContract().setCallbackInterface(callbackInterface);
- }
-
- Interface javaInterface = service.getInterfaceContract().getInterface();
- javaInterface.setRemotable(interfaze.getAnnotation(Remotable.class) != null);
- service.getInterfaceContract().setInterface(javaInterface);
- return service;
- }
-
- public void processCallback(Class<?> interfaze, Contract contract) throws InvalidServiceType {
- Callback callback = interfaze.getAnnotation(Callback.class);
- if (callback != null && !Void.class.equals(callback.value())) {
- Class<?> callbackClass = callback.value();
- JavaInterface javaInterface;
- try {
- javaInterface = javaFactory.createJavaInterface(callbackClass);
- contract.getInterfaceContract().setCallbackInterface(javaInterface);
- } catch (InvalidInterfaceException e) {
- throw new InvalidServiceType("Invalid callback interface "+callbackClass, interfaze);
- }
- } else if (callback != null && Void.class.equals(callback.value())) {
- throw new InvalidServiceType("No callback interface specified on annotation", interfaze);
- }
- }
-
- public boolean injectionAnnotationsPresent(Annotation[][] annots) {
+
+ /**
+ * Verify if the annotations are SCA annotation
+ * @param annots
+ * @return
+ */
+ private static boolean injectionAnnotationsPresent(Annotation[][] annots) {
for (Annotation[] annotations : annots) {
for (Annotation annotation : annotations) {
Class<? extends Annotation> annotType = annotation.annotationType();
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementationException.java
index a1e1d01ab3..079495e4db 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementationException.java
@@ -25,14 +25,14 @@ import org.apache.tuscany.sca.implementation.java.IntrospectionException;
*
* @version $Rev$ $Date$
*/
-public class InvalidConversationalImplementation extends IntrospectionException {
+public class InvalidConversationalImplementationException extends IntrospectionException {
private static final long serialVersionUID = -5487291552769408149L;
- public InvalidConversationalImplementation(String message) {
+ public InvalidConversationalImplementationException(String message) {
super(message);
}
- public InvalidConversationalImplementation(String message, Throwable cause) {
+ public InvalidConversationalImplementationException(String message, Throwable cause) {
super(message, cause);
}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceTypeException.java
index 7147da55b4..c65e7179f5 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceTypeException.java
@@ -26,15 +26,15 @@ import org.apache.tuscany.sca.implementation.java.IntrospectionException;
*
* @version $Rev$ $Date$
*/
-public class InvalidServiceType extends IntrospectionException {
+public class InvalidServiceTypeException extends IntrospectionException {
private static final long serialVersionUID = -1076466639416644386L;
private Class<?> serviceType;
- public InvalidServiceType(String message) {
+ public InvalidServiceTypeException(String message) {
super(message);
}
- public InvalidServiceType(String message, Class<?> clazz) {
+ public InvalidServiceTypeException(String message, Class<?> clazz) {
super(message);
this.serviceType = clazz;
}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
index c2e1e33432..2344ce49fc 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
@@ -58,93 +58,45 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
this.policyFactory = policyFactory;
}
- private QName getQName(String intentName) {
- QName qname;
- if (intentName.startsWith("{")) {
- int i = intentName.indexOf('}');
- if (i != -1) {
- qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
- } else {
- qname = new QName("", intentName);
- }
- } else {
- qname = new QName("", intentName);
- }
- return qname;
- }
- /**
- * Read policy intents on the given interface or class
- * @param clazz
- * @param requiredIntents
- */
- private void readIntentsAndPolicySets(Class<?> clazz,
- List<Intent> requiredIntents,
- List<PolicySet> policySets) {
- Requires intentAnnotation = clazz.getAnnotation(Requires.class);
- if (intentAnnotation != null) {
- String[] intentNames = intentAnnotation.value();
- if (intentNames.length != 0) {
- for (String intentName : intentNames) {
-
- // Add each intent to the list
- Intent intent = policyFactory.createIntent();
- intent.setName(getQName(intentName));
- requiredIntents.add(intent);
- }
- }
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ org.osoa.sca.annotations.Reference annotation =
+ field.getAnnotation( org.osoa.sca.annotations.Reference.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = field.getName();
}
- PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
- if (policySetAnnotation != null) {
- String[] policySetNames = policySetAnnotation.value();
- if (policySetNames.length != 0) {
- for (String policySetName : policySetNames) {
-
- // Add each intent to the list
- PolicySet policySet = policyFactory.createPolicySet();
- policySet.setName(getQName(policySetName));
- policySets.add(policySet);
- }
- }
+ Reference reference = null;
+ if ( (reference = getReferenceByName(name, type)) != null ) {
+ readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets());
}
}
-
- private void readIntents(Requires intentAnnotation, List<Intent> requiredIntents) {
- //Requires intentAnnotation = method.getAnnotation(Requires.class);
- if (intentAnnotation != null) {
- String[] intentNames = intentAnnotation.value();
- if (intentNames.length != 0) {
- //Operation operation = assemblyFactory.createOperation();
- //operation.setName(method.getName());
- //operation.setUnresolved(true);
- for (String intentName : intentNames) {
- // Add each intent to the list, associated with the
- // operation corresponding to the annotated method
- Intent intent = policyFactory.createIntent();
- intent.setName(getQName(intentName));
- //intent.getOperations().add(operation);
- requiredIntents.add(intent);
- }
- }
- }
- }
-
- private void readPolicySets(PolicySets policySetAnnotation, List<PolicySet> policySets) {
- if (policySetAnnotation != null) {
- String[] policySetNames = policySetAnnotation.value();
- if (policySetNames.length != 0) {
- //Operation operation = assemblyFactory.createOperation();
- //operation.setName(method.getName());
- //operation.setUnresolved(true);
- for (String policySetName : policySetNames) {
- // Add each intent to the list, associated with the
- // operation corresponding to the annotated method
- PolicySet policySet = policyFactory.createPolicySet();
- policySet.setName(getQName(policySetName));
- //intent.getOperations().add(operation);
- policySets.add(policySet);
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ Reference reference = null;
+ if ( (reference = getReference(method, type)) != null ) {
+ readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets());
+ } else {
+ if ( type instanceof OperationsConfigurator ) {
+ //Read the intents specified on the given implementation method
+ if ( (method.getAnnotation(Requires.class) != null ||
+ method.getAnnotation(PolicySets.class) != null ) &&
+ (type instanceof PolicySetAttachPoint )) {
+ ConfiguredOperation confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ ((OperationsConfigurator)type).getConfiguredOperations().add(confOp);
+
+
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
}
}
}
@@ -223,24 +175,126 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
}
}
- private Reference getReference(Method method, JavaImplementation type) {
- //since the ReferenceProcessor is called ahead of the PolicyProcessor the type should have
- //picked up the reference setter method
- org.osoa.sca.annotations.Reference annotation =
- method.getAnnotation(org.osoa.sca.annotations.Reference.class);
- if (annotation != null) {
- if (JavaIntrospectionHelper.isSetter(method)) {
- String name = annotation.name();
- if ("".equals(name)) {
- name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ /**
+ * Read policy intents on the given interface or class
+ * @param clazz
+ * @param requiredIntents
+ */
+ private void readIntentsAndPolicySets(Class<?> clazz,
+ List<Intent> requiredIntents,
+ List<PolicySet> policySets) {
+ Requires intentAnnotation = clazz.getAnnotation(Requires.class);
+ if (intentAnnotation != null) {
+ String[] intentNames = intentAnnotation.value();
+ if (intentNames.length != 0) {
+ for (String intentName : intentNames) {
+
+ // Add each intent to the list
+ Intent intent = policyFactory.createIntent();
+ intent.setName(getQName(intentName));
+ requiredIntents.add(intent);
+ }
+ }
+ }
+
+ PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ for (String policySetName : policySetNames) {
+
+ // Add each intent to the list
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ policySets.add(policySet);
}
- return getReferenceByName(name, type);
}
}
- return null;
}
- private Reference getReferenceByName(String name, JavaImplementation type) {
+ /**
+ * Read intent annotations on the given interface or class
+ * @param intentAnnotation
+ * @param requiredIntents
+ */
+ private void readIntents(Requires intentAnnotation, List<Intent> requiredIntents) {
+ //Requires intentAnnotation = method.getAnnotation(Requires.class);
+ if (intentAnnotation != null) {
+ String[] intentNames = intentAnnotation.value();
+ if (intentNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String intentName : intentNames) {
+
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ Intent intent = policyFactory.createIntent();
+ intent.setName(getQName(intentName));
+ //intent.getOperations().add(operation);
+ requiredIntents.add(intent);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Read policy set annotations on a given interface or class
+ * @param policySetAnnotation
+ * @param policySets
+ */
+ private void readPolicySets(PolicySets policySetAnnotation, List<PolicySet> policySets) {
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String policySetName : policySetNames) {
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ //intent.getOperations().add(operation);
+ policySets.add(policySet);
+ }
+ }
+ }
+ }
+
+ /**
+ * Utility methods
+ */
+
+ /**
+ *
+ * @param intentName
+ * @return
+ */
+ private static QName getQName(String intentName) {
+ QName qname;
+ if (intentName.startsWith("{")) {
+ int i = intentName.indexOf('}');
+ if (i != -1) {
+ qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
+ } else {
+ qname = new QName("", intentName);
+ }
+ } else {
+ qname = new QName("", intentName);
+ }
+ return qname;
+ }
+
+
+ /**
+ *
+ * @param name
+ * @param type
+ * @return
+ */
+ private static Reference getReferenceByName(String name, JavaImplementation type) {
for ( Reference reference : type.getReferences() ) {
if ( reference.getName().equals(name) ) {
return reference;
@@ -249,46 +303,27 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
return null;
}
- @Override
- public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
- org.osoa.sca.annotations.Reference annotation =
- field.getAnnotation( org.osoa.sca.annotations.Reference.class);
- if (annotation == null) {
- return;
- }
- String name = annotation.name();
- if ("".equals(name)) {
- name = field.getName();
- }
-
- Reference reference = null;
- if ( (reference = getReferenceByName(name, type)) != null ) {
- readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents());
- readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets());
- }
- }
- @Override
- public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
- Reference reference = null;
- if ( (reference = getReference(method, type)) != null ) {
- readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents());
- readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets());
- } else {
- if ( type instanceof OperationsConfigurator ) {
- //Read the intents specified on the given implementation method
- if ( (method.getAnnotation(Requires.class) != null ||
- method.getAnnotation(PolicySets.class) != null ) &&
- (type instanceof PolicySetAttachPoint )) {
- ConfiguredOperation confOp = assemblyFactory.createConfiguredOperation();
- confOp.setName(method.getName());
- ((OperationsConfigurator)type).getConfiguredOperations().add(confOp);
-
-
- readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
- readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
+ /**
+ *
+ * @param method
+ * @param type
+ * @return
+ */
+ private static Reference getReference(Method method, JavaImplementation type) {
+ //since the ReferenceProcessor is called ahead of the PolicyProcessor the type should have
+ //picked up the reference setter method
+ org.osoa.sca.annotations.Reference annotation =
+ method.getAnnotation(org.osoa.sca.annotations.Reference.class);
+ if (annotation != null) {
+ if (JavaIntrospectionHelper.isSetter(method)) {
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
}
+ return getReferenceByName(name, type);
}
}
+ return null;
}
}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java
index 911f1f1bb9..29a872e27a 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java
@@ -83,19 +83,6 @@ public class ReferenceProcessor extends BaseJavaClassVisitor {
type.getReferenceMembers().put(name, element);
}
- private boolean removeReference(JavaElementImpl ref, JavaImplementation type) {
- if (ref == null) {
- return false;
- }
- List<org.apache.tuscany.sca.assembly.Reference> refs = type.getReferences();
- for (int i = 0; i < refs.size(); i++) {
- if (refs.get(i).getName().equals(ref.getName())) {
- refs.remove(i);
- return true;
- }
- }
- return false;
- }
@Override
public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
@@ -145,20 +132,13 @@ public class ReferenceProcessor extends BaseJavaClassVisitor {
parameter.setName(name);
}
- private String getReferenceName(String paramName, int pos, String name) throws InvalidConstructorException {
- if ("".equals(name)) {
- name = paramName;
- }
- if ("".equals(name)) {
- return "_ref" + pos;
- }
- if (!"".equals(paramName) && !name.equals(paramName)) {
- throw new InvalidConstructorException("Mismatching names specified for reference parameter " + pos);
- } else {
- return name;
- }
- }
-
+ /**
+ * Create a SCA reference for a java Element
+ * @param element
+ * @param name
+ * @return
+ * @throws IntrospectionException
+ */
private org.apache.tuscany.sca.assembly.Reference createReference(JavaElementImpl element, String name)
throws IntrospectionException {
org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
@@ -207,4 +187,53 @@ public class ReferenceProcessor extends BaseJavaClassVisitor {
}
return reference;
}
+
+
+ /**
+ * Utility methods
+ */
+
+ /**
+ *
+ * @param paramName
+ * @param pos
+ * @param name
+ * @return
+ * @throws InvalidConstructorException
+ */
+ private static String getReferenceName(String paramName, int pos, String name) throws InvalidConstructorException {
+ if ("".equals(name)) {
+ name = paramName;
+ }
+ if ("".equals(name)) {
+ return "_ref" + pos;
+ }
+ if (!"".equals(paramName) && !name.equals(paramName)) {
+ throw new InvalidConstructorException("Mismatching names specified for reference parameter " + pos);
+ } else {
+ return name;
+ }
+ }
+
+ /**
+ *
+ * @param ref
+ * @param type
+ * @return
+ */
+ private static boolean removeReference(JavaElementImpl ref, JavaImplementation type) {
+ if (ref == null) {
+ return false;
+ }
+ List<org.apache.tuscany.sca.assembly.Reference> refs = type.getReferences();
+ for (int i = 0; i < refs.size(); i++) {
+ if (refs.get(i).getName().equals(ref.getName())) {
+ refs.remove(i);
+ return true;
+ }
+ }
+ return false;
+ }
+
+
}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java
index 5498a792a3..49320579d0 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java
@@ -96,12 +96,6 @@ public class ResourceProcessor extends BaseJavaClassVisitor {
type.getResources().put(resource.getName(), resource);
}
- public JavaResourceImpl createResource(String name, JavaElementImpl element) {
- element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
- element.setName(name);
- return new JavaResourceImpl(element);
- }
-
@Override
public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
throws IntrospectionException {
@@ -135,4 +129,20 @@ public class ResourceProcessor extends BaseJavaClassVisitor {
}
}
+
+ /**
+ * Utility methods
+ */
+
+ /**
+ *
+ * @param name
+ * @param element
+ * @return
+ */
+ private static JavaResourceImpl createResource(String name, JavaElementImpl element) {
+ element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ element.setName(name);
+ return new JavaResourceImpl(element);
+ }
}
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
index 7a5dbb01f9..52c68c1976 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
@@ -135,12 +135,34 @@ public class ServiceProcessor extends BaseJavaClassVisitor {
createCallback(type, element);
}
+ public Service createService(Class<?> interfaze) throws InvalidInterfaceException {
+ Service service = assemblyFactory.createService();
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+
+ // create a relative URI
+ service.setName(interfaze.getSimpleName());
+
+ JavaInterface callInterface = javaFactory.createJavaInterface(interfaze);
+ service.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ service.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+ return service;
+ }
+
+ /**
+ * Utility methods
+ */
+
+
/**
* @param type
* @param element
* @throws IllegalCallbackReferenceException
*/
- private void createCallback(JavaImplementation type, JavaElementImpl element)
+ private static void createCallback(JavaImplementation type, JavaElementImpl element)
throws IllegalCallbackReferenceException {
Service callbackService = null;
Class<?> callbackClass = element.getType();
@@ -165,22 +187,4 @@ public class ServiceProcessor extends BaseJavaClassVisitor {
}
type.getCallbackMembers().get(baseType.getName()).add(element);
}
-
- public Service createService(Class<?> interfaze) throws InvalidInterfaceException {
- Service service = assemblyFactory.createService();
- JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
- service.setInterfaceContract(interfaceContract);
-
- // create a relative URI
- service.setName(interfaze.getSimpleName());
-
- JavaInterface callInterface = javaFactory.createJavaInterface(interfaze);
- service.getInterfaceContract().setInterface(callInterface);
- if (callInterface.getCallbackClass() != null) {
- JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
- service.getInterfaceContract().setCallbackInterface(callbackInterface);
- }
- return service;
- }
-
}
diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
index 728c6c89b8..4e5a2dfee6 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
@@ -22,21 +22,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
-import org.junit.Before;
import org.junit.Test;
/**
* @version $Rev$ $Date$
*/
public class ConvertTimeMillisTestCase {
- private MockProcessor registy;
- @Test
+ @Test
public void testConvertSeconds() throws Exception {
- assertEquals(10000L, registy.convertTimeMillis("10 seconds"));
- assertEquals(10000L, registy.convertTimeMillis("10 SECONDS"));
+ assertEquals(10000L, MockProcessor.convertTimeMillis("10 seconds"));
+ assertEquals(10000L, MockProcessor.convertTimeMillis("10 SECONDS"));
try {
- registy.convertTimeMillis("10seconds");
+ MockProcessor.convertTimeMillis("10seconds");
fail();
} catch (NumberFormatException e) {
// expected
@@ -45,10 +43,10 @@ public class ConvertTimeMillisTestCase {
@Test
public void testConvertMinutes() throws Exception {
- assertEquals(600000L, registy.convertTimeMillis("10 minutes"));
- assertEquals(600000L, registy.convertTimeMillis("10 MINUTES"));
+ assertEquals(600000L, MockProcessor.convertTimeMillis("10 minutes"));
+ assertEquals(600000L, MockProcessor.convertTimeMillis("10 MINUTES"));
try {
- registy.convertTimeMillis("10minutes");
+ MockProcessor.convertTimeMillis("10minutes");
fail();
} catch (NumberFormatException e) {
// expected
@@ -57,10 +55,10 @@ public class ConvertTimeMillisTestCase {
@Test
public void testConvertHours() throws Exception {
- assertEquals(36000000L, registy.convertTimeMillis("10 hours"));
- assertEquals(36000000L, registy.convertTimeMillis("10 HOURS"));
+ assertEquals(36000000L, MockProcessor.convertTimeMillis("10 hours"));
+ assertEquals(36000000L, MockProcessor.convertTimeMillis("10 HOURS"));
try {
- registy.convertTimeMillis("10hours");
+ MockProcessor.convertTimeMillis("10hours");
fail();
} catch (NumberFormatException e) {
// expected
@@ -69,10 +67,10 @@ public class ConvertTimeMillisTestCase {
@Test
public void testConvertDays() throws Exception {
- assertEquals(864000000L, registy.convertTimeMillis("10 days"));
- assertEquals(864000000L, registy.convertTimeMillis("10 DAYS"));
+ assertEquals(864000000L, MockProcessor.convertTimeMillis("10 days"));
+ assertEquals(864000000L, MockProcessor.convertTimeMillis("10 DAYS"));
try {
- registy.convertTimeMillis("10days");
+ MockProcessor.convertTimeMillis("10days");
fail();
} catch (NumberFormatException e) {
// expected
@@ -81,10 +79,10 @@ public class ConvertTimeMillisTestCase {
@Test
public void testConvertYears() throws Exception {
- assertEquals(315569260000L, registy.convertTimeMillis("10 years"));
- assertEquals(315569260000L, registy.convertTimeMillis("10 YEARS"));
+ assertEquals(315569260000L, MockProcessor.convertTimeMillis("10 years"));
+ assertEquals(315569260000L, MockProcessor.convertTimeMillis("10 YEARS"));
try {
- registy.convertTimeMillis("10years");
+ MockProcessor.convertTimeMillis("10years");
fail();
} catch (NumberFormatException e) {
// expected
@@ -93,34 +91,24 @@ public class ConvertTimeMillisTestCase {
@Test
public void testConvertDefault() throws Exception {
- assertEquals(10000L, registy.convertTimeMillis("10 "));
- assertEquals(10000L, registy.convertTimeMillis("10"));
+ assertEquals(10000L, MockProcessor.convertTimeMillis("10 "));
+ assertEquals(10000L, MockProcessor.convertTimeMillis("10"));
}
@Test
public void testInvalid() throws Exception {
try {
- registy.convertTimeMillis("foo");
+ MockProcessor.convertTimeMillis("foo");
fail();
} catch (NumberFormatException e) {
// expected
}
}
- @Before
- public void setUp() throws Exception {
- registy = new MockProcessor();
- }
-
private class MockProcessor extends ConversationProcessor {
public MockProcessor() {
super(new DefaultAssemblyFactory());
}
-
- @Override
- protected long convertTimeMillis(String expr) throws NumberFormatException {
- return super.convertTimeMillis(expr);
- }
}
}