Author: jmarino
Date: Sun Apr 23 16:54:08 2006
New Revision: 396350
URL: http://svn.apache.org/viewcvs?rev=396350&view=rev
Log:
annotation processor refactor; adding back context factory
Added:
incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/config/WebServiceEntryPointContextFactory.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceAndPropertyProcessor.java
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/AnnotationProcessor.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/AnnotationProcessorSupport.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceInterfaceProcessor.java
Added:
incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/config/WebServiceEntryPointContextFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/config/WebServiceEntryPointContextFactory.java?rev=396350&view=auto
==============================================================================
---
incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/config/WebServiceEntryPointContextFactory.java
(added)
+++
incubator/tuscany/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/config/WebServiceEntryPointContextFactory.java
Sun Apr 23 16:54:08 2006
@@ -0,0 +1,35 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as
applicable.
+ *
+ * Licensed 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.binding.axis2.config;
+
+import org.apache.tuscany.core.builder.impl.EntryPointContextFactory;
+import org.apache.tuscany.core.message.MessageFactory;
+
+/**
+ * Creates instances of [EMAIL PROTECTED]
org.apache.tuscany.core.context.EntryPointContext}
+ * configured with the appropriate wire chains and bindings. This
implementation
+ * serves as a marker for
+ *
+ * @version $Rev$ $Date$
+ */
+public class WebServiceEntryPointContextFactory extends
EntryPointContextFactory {
+
+ public WebServiceEntryPointContextFactory(String name,MessageFactory
messageFactory) {
+ super(name, messageFactory);
+ }
+
+}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/AnnotationProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/AnnotationProcessor.java?rev=396350&r1=396349&r2=396350&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/AnnotationProcessor.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/AnnotationProcessor.java
Sun Apr 23 16:54:08 2006
@@ -14,6 +14,8 @@
package org.apache.tuscany.core.config;
import org.apache.tuscany.model.assembly.ComponentInfo;
+import org.apache.tuscany.model.assembly.Service;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
@@ -26,9 +28,13 @@
*/
public interface AnnotationProcessor {
- public void visitClass(Class clazz, Annotation annotation, ComponentInfo
type);
+ public void visitImplementationClass(Class clazz, Annotation annotation,
ComponentInfo type);
+
+ public void visitServiceInterface(Class clazz, Annotation annotation,
Service service);
+
+ public void visitImplementationMethod(Method method, Annotation
annotation, ComponentInfo type);
- public void visitMethod(Method method, Annotation annotation,
ComponentInfo type);
+ public void visitServiceMethod(Method method, Annotation annotation,
Service service);
public void visitConstructor(Constructor constructor, Annotation
annotation, ComponentInfo type);
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/AnnotationProcessorSupport.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/AnnotationProcessorSupport.java?rev=396350&r1=396349&r2=396350&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/AnnotationProcessorSupport.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/AnnotationProcessorSupport.java
Sun Apr 23 16:54:08 2006
@@ -18,6 +18,7 @@
import org.apache.tuscany.core.system.annotation.Autowire;
import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory;
import org.apache.tuscany.model.assembly.ComponentInfo;
+import org.apache.tuscany.model.assembly.Service;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Scope;
@@ -52,11 +53,19 @@
this.factory = factory;
}
- public void visitClass(Class clazz, Annotation annotation, ComponentInfo
type) {
+ public void visitImplementationClass(Class clazz, Annotation annotation,
ComponentInfo type) {
}
- public void visitMethod(Method method, Annotation annotation,
ComponentInfo type) {
+ public void visitServiceInterface(Class clazz, Annotation annotation,
Service service) {
+
+ }
+
+ public void visitServiceMethod(Method method, Annotation annotation,
Service service){
+
+ }
+
+ public void visitImplementationMethod(Method method, Annotation
annotation, ComponentInfo type) {
}
Added:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceAndPropertyProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceAndPropertyProcessor.java?rev=396350&view=auto
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceAndPropertyProcessor.java
(added)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceAndPropertyProcessor.java
Sun Apr 23 16:54:08 2006
@@ -0,0 +1,288 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as
applicable.
+ *
+ * Licensed 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.core.config.processor;
+
+import org.apache.tuscany.core.config.ConfigurationLoadException;
+import org.apache.tuscany.core.config.InvalidSetterException;
+import org.apache.tuscany.model.assembly.ComponentInfo;
+import org.apache.tuscany.model.assembly.Multiplicity;
+import org.apache.tuscany.model.assembly.Property;
+import org.apache.tuscany.model.assembly.Reference;
+import org.apache.tuscany.model.assembly.ServiceContract;
+import org.osoa.sca.annotations.Remotable;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class ReferenceAndPropertyProcessor extends AnnotationProcessorSupport {
+
+
+ public void visitImplementationMethod(Method method, Annotation
annotation, ComponentInfo type) {
+
+ }
+
+ public void visitField(Field field, Annotation annotation, ComponentInfo
type) {
+
+ }
+
+ /**
+ * Root method for determining public field and method metadata
+ *
+ * @throws org.apache.tuscany.core.config.ConfigurationLoadException
+ *
+ */
+ protected void introspectAnnotatedMembers(ComponentInfo compType, Class<?>
implClass) throws ConfigurationLoadException {
+
+ introspectPublicFields(compType, implClass);
+ introspectPrivateFields(compType, implClass);
+
+ introspectPublicMethods(compType, implClass);
+ introspectPrivateMethods(compType, implClass);
+ }
+
+ /**
+ * Introspects metdata for all public fields and methods for a class
hierarchy
+ */
+ protected void introspectMembers(ComponentInfo compType, Class<?>
implClass) {
+ List<Property> properties = compType.getProperties();
+ List<Reference> references = compType.getReferences();
+
+ // inspect public fields from class and all superclasses
+ Field[] fields = implClass.getFields();
+ for (Field field : fields) {
+ if (Modifier.isStatic(field.getModifiers())) {
+ continue;
+ }
+ if (field.getType().isAnnotationPresent(Remotable.class)) {
+ addReference(references, field);
+ } else {
+ addProperty(properties, field);
+ }
+ }
+
+ // add public methods from class and all superclasses
+ Method[] methods = implClass.getMethods();
+ for (Method method : methods) {
+ if (Void.class.equals(method.getReturnType()) &&
method.getName().startsWith("set")
+ && method.getParameterTypes().length == 1
+ &&
!method.getParameterTypes()[0].isAnnotationPresent(Remotable.class)) {
+ String name = method.getName();
+ name = Character.toLowerCase(name.charAt(3)) +
name.substring(4);
+ Class<?> type = method.getParameterTypes()[0];
+ if (type.isAnnotationPresent(Remotable.class)) {
+ addReference(references, name, type, false);
+ } else {
+ addProperty(properties, name, type, false);
+ }
+ }
+ }
+ }
+
+ private void introspectPublicFields(ComponentInfo compType, Class<?>
implClass) {
+ List<Property> properties = compType.getProperties();
+ List<Reference> references = compType.getReferences();
+
+ // inspect public fields from class and all superclasses
+ Field[] fields = implClass.getFields();
+ for (Field field : fields) {
+ if (Modifier.isStatic(field.getModifiers())) {
+ continue;
+ }
+ if
(field.isAnnotationPresent(org.osoa.sca.annotations.Property.class)) {
+ addProperty(properties, field);
+ } else if
(field.isAnnotationPresent(org.osoa.sca.annotations.Reference.class)) {
+ addReference(references, field);
+ }
+ }
+ }
+
+ private void introspectPrivateFields(ComponentInfo compType, Class<?>
implClass) {
+ List<Property> properties = compType.getProperties();
+ List<Reference> references = compType.getReferences();
+
+ // inspect private fields declared in class
+ Field[] fields = implClass.getDeclaredFields();
+ for (Field field : fields) {
+ if (!Modifier.isPrivate(field.getModifiers())) {
+ continue;
+ }
+ if
(field.isAnnotationPresent(org.osoa.sca.annotations.Property.class)) {
+ addProperty(properties, field);
+ } else if
(field.isAnnotationPresent(org.osoa.sca.annotations.Reference.class)) {
+ addReference(references, field);
+ }
+ }
+ }
+
+ private void introspectPublicMethods(ComponentInfo compType, Class<?>
implClass) throws ConfigurationLoadException {
+ List<Property> properties = compType.getProperties();
+ List<Reference> references = compType.getReferences();
+
+ // add public methods from class and all superclasses
+ Method[] methods = implClass.getMethods();
+ for (Method method : methods) {
+ if
(method.isAnnotationPresent(org.osoa.sca.annotations.Property.class)) {
+ addProperty(properties, method);
+ } else if
(method.isAnnotationPresent(org.osoa.sca.annotations.Reference.class)) {
+ addReference(references, method);
+ }
+ }
+ }
+
+ private void introspectPrivateMethods(ComponentInfo compType, Class<?>
implClass) throws ConfigurationLoadException {
+ List<Property> properties = compType.getProperties();
+ List<Reference> references = compType.getReferences();
+
+ // add private methods declared on class
+ Method[] methods = implClass.getDeclaredMethods();
+ for (Method method : methods) {
+ if (!Modifier.isPrivate(method.getModifiers())) {
+ continue;
+ }
+ if
(method.isAnnotationPresent(org.osoa.sca.annotations.Property.class)) {
+ addProperty(properties, method);
+ } else if
(method.isAnnotationPresent(org.osoa.sca.annotations.Reference.class)) {
+ addReference(references, method);
+ }
+ }
+ }
+
+ protected void addProperty(List<Property> properties, Field field) {
+ String name;
+ boolean required;
+ org.osoa.sca.annotations.Property annotation =
field.getAnnotation(org.osoa.sca.annotations.Property.class);
+ if (annotation != null) {
+ name = annotation.name();
+ if (name.length() == 0) {
+ name = field.getName();
+ }
+ required = annotation.required();
+ } else {
+ name = field.getName();
+ required = false;
+ }
+ addProperty(properties, name, field.getType(), required);
+ }
+
+ protected void addProperty(List<Property> properties, Method method)
throws ConfigurationLoadException {
+ if (!Void.class.equals(method.getReturnType())) {
+ throw new InvalidSetterException(method.toString());
+ }
+ Class<?>[] params = method.getParameterTypes();
+ if (params.length != 1) {
+ throw new InvalidSetterException(method.toString());
+ }
+
+ String name;
+ boolean required;
+ org.osoa.sca.annotations.Property annotation =
method.getAnnotation(org.osoa.sca.annotations.Property.class);
+ if (annotation != null) {
+ name = annotation.name();
+ required = annotation.required();
+ } else {
+ name = "";
+ required = false;
+ }
+ if (name.length() == 0) {
+ name = method.getName();
+ if (name.length() > 3 && name.startsWith("set")) {
+ name = Character.toLowerCase(name.charAt(3)) +
name.substring(4);
+ }
+ }
+ addProperty(properties, name, params[0], required);
+ }
+
+ protected void addProperty(List<Property> properties, String name,
Class<?> type, boolean required) {
+ Property prop = factory.createProperty();
+ prop.setName(name);
+ prop.setType(type);
+ prop.setRequired(required);
+
+ // a java.util.Map is not a "many"
+ prop.setMany(type.isArray() ||
Collection.class.isAssignableFrom(type));
+
+ // todo how is the default specified using annotations?
+ prop.setDefaultValue(null);
+
+ properties.add(prop);
+ }
+
+ protected void addReference(List<Reference> references, Field field) {
+ String name;
+ boolean required;
+ org.osoa.sca.annotations.Reference annotation =
field.getAnnotation(org.osoa.sca.annotations.Reference.class);
+ if (annotation != null) {
+ name = annotation.name();
+ if (name.length() == 0) {
+ name = field.getName();
+ }
+ required = annotation.required();
+ } else {
+ name = field.getName();
+ required = false;
+ }
+ addReference(references, name, field.getType(), required);
+ }
+
+ protected void addReference(List<Reference> references, Method method)
throws ConfigurationLoadException {
+ if (!Void.TYPE.equals(method.getReturnType())) {
+ throw new InvalidSetterException(method.toString());
+ }
+ Class<?>[] params = method.getParameterTypes();
+ if (params.length != 1) {
+ throw new InvalidSetterException(method.toString());
+ }
+
+ String name;
+ boolean required;
+ org.osoa.sca.annotations.Reference annotation =
method.getAnnotation(org.osoa.sca.annotations.Reference.class);
+ if (annotation != null) {
+ name = annotation.name();
+ required = annotation.required();
+ } else {
+ name = "";
+ required = false;
+ }
+ if (name.length() == 0) {
+ name = method.getName();
+ if (name.length() > 3 && name.startsWith("set")) {
+ name = Character.toLowerCase(name.charAt(3)) +
name.substring(4);
+ }
+ }
+ addReference(references, name, params[0], required);
+ }
+
+ protected void addReference(List<Reference> references, String name,
Class<?> type, boolean required) {
+ Reference ref = factory.createReference();
+ ref.setName(name);
+ boolean many = type.isArray() ||
Collection.class.isAssignableFrom(type);
+ Multiplicity multiplicity;
+ if (required)
+ multiplicity = many ? Multiplicity.ONE_N : Multiplicity.ONE_ONE;
+ else
+ multiplicity = many ? Multiplicity.ZERO_N : Multiplicity.ZERO_ONE;
+ ref.setMultiplicity(multiplicity);
+ ServiceContract javaInterface = factory.createJavaServiceContract();
+ javaInterface.setInterface(type);
+ ref.setServiceContract(javaInterface);
+ references.add(ref);
+ }
+}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java?rev=396350&r1=396349&r2=396350&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java
Sun Apr 23 16:54:08 2006
@@ -13,23 +13,49 @@
*/
package org.apache.tuscany.core.config.processor;
-import org.apache.tuscany.model.assembly.ComponentInfo;
import org.apache.tuscany.model.assembly.Scope;
import org.apache.tuscany.model.assembly.Service;
-import org.apache.tuscany.model.assembly.ServiceContract;
+import org.apache.tuscany.model.assembly.ComponentInfo;
import java.lang.annotation.Annotation;
/**
* @version $$Rev$$ $$Date$$
*/
-public class ScopeProcessor extends AnnotationProcessorSupport{
+public class ScopeProcessor extends AnnotationProcessorSupport {
- public void visitClass(Class clazz, Annotation annotation, ComponentInfo
type) {
- if (!(annotation instanceof org.osoa.sca.annotations.Scope)){
+ public void visitImplementationClass(Class clazz, Annotation annotation,
ComponentInfo type) {
+ if (!(annotation instanceof org.osoa.sca.annotations.Scope)) {
return;
}
+ Scope scope = getScope(annotation); // hack for now - set scope to
implementation scope
+ for(Service service: type.getServices()){
+ Scope serviceScope = service.getServiceContract().getScope();
+ if (serviceScope == Scope.INSTANCE || serviceScope == null){
+ service.getServiceContract().setScope(scope);
+ }
+ }
+ }
+ @Override
+ public void visitServiceInterface(Class clazz, Annotation annotation,
Service service) {
+ if (!(annotation instanceof org.osoa.sca.annotations.Scope)) {
+ return;
+ }
+ service.getServiceContract().setScope(getScope(annotation));
+ }
+
+ private Scope getScope(Annotation annotation){
+ org.osoa.sca.annotations.Scope scopeAnnotation =
(org.osoa.sca.annotations.Scope) annotation;
+ if ("MODULE".equalsIgnoreCase(scopeAnnotation.value())) {
+ return Scope.MODULE;
+ } else if ("SESSION".equalsIgnoreCase(scopeAnnotation.value())) {
+ return Scope.SESSION;
+ } else if ("REQUEST".equalsIgnoreCase(scopeAnnotation.value())) {
+ return Scope.REQUEST;
+ } else {
+ return Scope.INSTANCE;
+ }
}
}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceInterfaceProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceInterfaceProcessor.java?rev=396350&r1=396349&r2=396350&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceInterfaceProcessor.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceInterfaceProcessor.java
Sun Apr 23 16:54:08 2006
@@ -30,7 +30,7 @@
@Override
- public void visitClass(Class clazz, Annotation annotation, ComponentInfo
type) {
+ public void visitImplementationClass(Class clazz, Annotation annotation,
ComponentInfo type) {
if (!(annotation instanceof org.osoa.sca.annotations.Service)) {
return;
}