diff options
Diffstat (limited to 'tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor')
13 files changed, 0 insertions, 1040 deletions
diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ComponentNameProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ComponentNameProcessor.java deleted file mode 100644 index 0314bcc9bf..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ComponentNameProcessor.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - * 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 java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.extension.config.extensibility.ComponentNameExtensibilityElement; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.osoa.sca.annotations.ComponentName; - -/** - * Processes the {@link ComponentName} annotation - * - * @version $$Rev$$ $$Date$$ - */ -public class ComponentNameProcessor extends ImplementationProcessorSupport { - - public ComponentNameProcessor(AssemblyFactory factory) { - super(factory); - } - - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - ComponentName name = method.getAnnotation(ComponentName.class); - if (name == null) { - return; - } - type.getExtensibilityElements().add(new ComponentNameExtensibilityElement(method)); - } - - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - ComponentName name = field.getAnnotation(ComponentName.class); - if (name == null) { - return; - } - type.getExtensibilityElements().add(new ComponentNameExtensibilityElement(field)); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ContextProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ContextProcessor.java deleted file mode 100644 index ff5c3736b7..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ContextProcessor.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * - * 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 java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.extension.config.extensibility.ContextExtensibilityElement; -import org.apache.tuscany.model.assembly.ComponentType; -import org.osoa.sca.annotations.Context; - -/** - * Processes the {@link org.osoa.sca.annotations.Context} annotation - * - * @version $$Rev$$ $$Date$$ - */ -public class ContextProcessor extends ImplementationProcessorSupport { - - public ContextProcessor() { - } - - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - Context context = method.getAnnotation(Context.class); - if (context == null) { - return; - } - type.getExtensibilityElements().add(new ContextExtensibilityElement(method)); - } - - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - Context context = field.getAnnotation(Context.class); - if (context == null) { - return; - } - type.getExtensibilityElements().add(new ContextExtensibilityElement(field)); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/DefaultProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/DefaultProcessor.java deleted file mode 100644 index 8445526dc8..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/DefaultProcessor.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * - * 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 java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Set; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.Reference; - -/** - * Adds public methods and public/protected fields as properties that are not declared explicitly with an - * {@link org.osoa.sca.annotations.Property} or {@link org.osoa.sca.annotations.Reference} annotation - * - * @version $$Rev$$ $$Date$$ - */ -public class DefaultProcessor extends ImplementationProcessorSupport { - - public DefaultProcessor(AssemblyFactory factory) { - super(factory); - } - - public DefaultProcessor() { - } - - public void visitEnd(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - // add any public/protected fields and public setter methods as properties - Set<Field> fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz); - List<Property> properties = type.getProperties(); - List<Reference> references = type.getReferences(); - boolean contains; - Method[] methods = clazz.getMethods(); - String name; - for (Method method : methods) { - if (Object.class.equals(method.getDeclaringClass()) || method.getParameterTypes().length != 1 - || method.isAnnotationPresent(org.osoa.sca.annotations.Property.class) - || method.isAnnotationPresent(org.osoa.sca.annotations.Reference.class)) { - continue; - } - contains = containsProperty(properties, method.getName()); - if (contains) { - continue; - } - name = method.getName(); - if (name.length() > 3 && name.startsWith("set")) { - // follow JavaBeans conventions - name = JavaIntrospectionHelper.toPropertyName(name); - } - contains = containsReference(references, name); - if (!contains) { - addProperty(name, method.getParameterTypes()[0], type); - } - } - for (Field field : fields) { - if (field.isAnnotationPresent(org.osoa.sca.annotations.Property.class) - || field.isAnnotationPresent(org.osoa.sca.annotations.Reference.class)) { - continue; - } - contains = containsProperty(properties, field.getName()); - if (contains) { - continue; - } - contains = containsReference(references, field.getName()); - if (!contains) { - addProperty(field.getName(), field.getType(), type); - } - } - } - - private boolean containsProperty(List<Property> properties, String name) { - for (Property prop : properties) { - if (prop.getName().equals(name)) { - return true; - } - } - return false; - } - - private boolean containsReference(List<Reference> references, String name) { - for (Reference ref : references) { - if (ref.getName().equals(name)) { - return true; - } - } - return false; - } - - private void addProperty(String name, Class<?> propType, ComponentType type) { - Property property = factory.createProperty(); - property.setName(name); - property.setRequired(false); - property.setType(propType); - type.getProperties().add(property); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/DestroyProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/DestroyProcessor.java deleted file mode 100644 index a16845bbf8..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/DestroyProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * - * 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 java.lang.reflect.Method; - -import org.apache.tuscany.core.extension.config.extensibility.DestroyInvokerExtensibilityElement; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.osoa.sca.annotations.Destroy; - -/** - * Processes a {@link Destroy} - * - * @version $$Rev$$ $$Date$$ - */ -public class DestroyProcessor extends ImplementationProcessorSupport { - - public DestroyProcessor() { - } - - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - Destroy destroy = method.getAnnotation(Destroy.class); - if (destroy == null) { - return; - } - if (method.getParameterTypes().length != 0) { - throw new ConfigurationLoadException("Destroy methods cannot take parameters"); - } - type.getExtensibilityElements().add(new DestroyInvokerExtensibilityElement(method)); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ImplementationProcessorSupport.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ImplementationProcessorSupport.java deleted file mode 100644 index 175de28a92..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ImplementationProcessorSupport.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * - * 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 java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.config.ComponentTypeIntrospector; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.extension.config.ImplementationProcessor; -import org.apache.tuscany.core.system.annotation.Autowire; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Scope; - -/** - * A base implementation of an <code>ImplementationProcessor</code> - * - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -public abstract class ImplementationProcessorSupport implements ImplementationProcessor { - - protected ComponentTypeIntrospector introspector; - protected AssemblyFactory factory; - - protected ImplementationProcessorSupport(AssemblyFactory factory) { - this.factory = factory; - } - - protected ImplementationProcessorSupport() { - } - - @Init(eager = true) - public void init() throws Exception { - introspector.registerProcessor(this); - } - - @Autowire - public void setIntrospector(ComponentTypeIntrospector introspector) { - this.introspector = introspector; - } - - @Autowire - public void setFactory(AssemblyFactory factory) { - this.factory = factory; - - } - - public void visitClass(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitSuperClass(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitConstructor(Constructor<?> constructor, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitInterface(Class clazz, Annotation[] annotations, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitInterfaceMethod(Method method, Annotation[] annotations, ComponentType type) throws ConfigurationLoadException { - - } - - public void visitEnd(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - - } - -// /** -// * Creates a {@link JavaExtensibilityElement} subclasses may update while processing annotations -// */ -// protected JavaExtensibilityElement getExtensibilityElement(ComponentType type) { -// JavaExtensibilityElement element = (JavaExtensibilityElement) type.getExtensibilityElements().get(JAVA_ELEMENT); -// if (element == null) { -// element = new JavaExtensibilityElementImpl(); -// type.getExtensibilityElements().put(JAVA_ELEMENT, element); -// } -// return element; -// } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/InitProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/InitProcessor.java deleted file mode 100644 index 9f4a53a651..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/InitProcessor.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - * 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 java.lang.reflect.Method; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.extension.config.extensibility.InitInvokerExtensibilityElement; -import org.apache.tuscany.model.assembly.ComponentType; -import org.osoa.sca.annotations.Init; - -/** - * Processes the {@link org.osoa.sca.annotations.Init} annotation - * - * @version $$Rev$$ $$Date$$ - */ -public class InitProcessor extends ImplementationProcessorSupport { - - public InitProcessor() { - } - - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - Init init = method.getAnnotation(Init.class); - if (init == null) { - return; - } - if (method.getParameterTypes().length != 0) { - throw new ConfigurationLoadException("Initialize methods cannot take parameters"); - } - type.getExtensibilityElements().add(new InitInvokerExtensibilityElement(method, init.eager())); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ProcessorHelper.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ProcessorHelper.java deleted file mode 100644 index d4c6c4a40e..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ProcessorHelper.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * - * 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 java.util.List; - -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; - -/** - * Provides utility functions for {@link org.apache.tuscany.core.extension.config.ImplementationProcessor}s - * - * @version $$Rev$$ $$Date$$ - */ -public class ProcessorHelper { - - private ProcessorHelper() { - } - - /** - * Returns the first <code>Service</code> from a collection matching the interface type - */ - public static Service getService(Class<?> interfaceType, List<Service> services) { - for (Service service : services) { - Class serviceInterface = service.getServiceContract().getInterface(); - if (serviceInterface.equals(interfaceType)) { - return service; - } - } - return null; - } - - /** - * Returns the scope enum specified by the annotation - */ - public static Scope getScope(org.osoa.sca.annotations.Scope annotation) { - if ("MODULE".equalsIgnoreCase(annotation.value())) { - return Scope.MODULE; - } else if ("SESSION".equalsIgnoreCase(annotation.value())) { - return Scope.SESSION; - } else if ("REQUEST".equalsIgnoreCase(annotation.value())) { - return Scope.REQUEST; - } else { - return Scope.INSTANCE; - } - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ProcessorUtils.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ProcessorUtils.java deleted file mode 100644 index b0400c183f..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ProcessorUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - * 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 java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.core.extension.config.ImplementationProcessor; -import org.apache.tuscany.core.system.config.processor.AutowireProcessor; -import org.apache.tuscany.core.system.config.processor.MonitorProcessor; -import org.apache.tuscany.core.system.config.processor.ParentContextProcessor; -import org.apache.tuscany.core.config.ComponentTypeIntrospector; -import org.apache.tuscany.core.config.impl.Java5ComponentTypeIntrospector; -import org.apache.tuscany.core.sdo.helper.SDOHelperProcessor; -import org.apache.tuscany.model.assembly.AssemblyFactory; - -/** - * Temporary class to create bootstrap {@link ImplementationProcessor}s - * - * @version $$Rev$$ $$Date$$ - */ -public class ProcessorUtils { - - private ProcessorUtils() { - } - - public static List<ImplementationProcessor> createCoreProcessors(AssemblyFactory factory) { - List<ImplementationProcessor> processors = new ArrayList<ImplementationProcessor>(); - processors.add(new PropertyProcessor(factory)); - processors.add(new ReferenceProcessor(factory)); - processors.add(new ScopeProcessor()); - processors.add(new ServiceProcessor(factory)); - processors.add(new InitProcessor()); - processors.add(new DestroyProcessor()); - processors.add(new ContextProcessor()); - processors.add(new ComponentNameProcessor(factory)); - processors.add(new DefaultProcessor(factory)); - processors.add(new AutowireProcessor()); - processors.add(new MonitorProcessor()); - processors.add(new ParentContextProcessor()); - processors.add(new SDOHelperProcessor()); - return processors; - } - - public static ComponentTypeIntrospector createCoreIntrospector(AssemblyFactory factory){ - ComponentTypeIntrospector introspector = new Java5ComponentTypeIntrospector(factory); - List<ImplementationProcessor> processors = createCoreProcessors(factory); - for (ImplementationProcessor processor : processors) { - introspector.registerProcessor(processor); - } - return introspector; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/PropertyProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/PropertyProcessor.java deleted file mode 100644 index 9191b75793..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/PropertyProcessor.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * - * 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 java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.InvalidSetterException; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Property; -import org.osoa.sca.annotations.Scope; - -/** - * Processes the {@link org.osoa.sca.annotations.Property} annotation - * - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -public class PropertyProcessor extends ImplementationProcessorSupport { - - public PropertyProcessor(AssemblyFactory factory) { - super(factory); - } - - public PropertyProcessor() { - } - - @Override - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - if (method.getDeclaringClass().equals(Object.class)) { - return; - } - org.osoa.sca.annotations.Property annotation = method.getAnnotation(org.osoa.sca.annotations.Property.class); - if (annotation != null) { - if (!Modifier.isPublic(method.getModifiers())) { - InvalidSetterException e = new InvalidSetterException("Property setter method is not public"); - e.setIdentifier(method.toString()); - throw e; - } - Class<?>[] params = method.getParameterTypes(); - if (params.length != 1) { - InvalidSetterException e = new InvalidSetterException("Property setter method must have one parameter"); - e.setIdentifier(method.toString()); - throw e; - } - String name = annotation.name(); - if (name.length() == 0) { - name = method.getName(); - if (name.length() > 3 && name.startsWith("set")) { - // follow JavaBeans conventions - name = JavaIntrospectionHelper.toPropertyName(name); - } - } - addProperty(name, method.getParameterTypes()[0], annotation.required(), type); - } - - - } - - @Override - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - if (field.getDeclaringClass().equals(Object.class)) { - return; - } - int modifiers = field.getModifiers(); - org.osoa.sca.annotations.Property annotation = field.getAnnotation(org.osoa.sca.annotations.Property.class); - if (annotation != null) { - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - InvalidSetterException e = new InvalidSetterException("Property field is not public or protected"); - e.setIdentifier(field.getName()); - throw e; - } - String name = annotation.name(); - if (name.length() == 0) { - name = field.getName(); - } - addProperty(name, field.getType(), annotation.required(), type); - } - } - - private void addProperty(String name, Class<?> propType, boolean required, ComponentType type) { - Property property = factory.createProperty(); - property.setName(name); - property.setRequired(required); - property.setType(propType); - type.getProperties().add(property); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/PropertyReferenceValidator.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/PropertyReferenceValidator.java deleted file mode 100644 index bc8ef02777..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/PropertyReferenceValidator.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * - * 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 java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Field; -import java.util.Set; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.MetaDataException; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; - -/** - * Validates the use of {@link org.osoa.sca.annotations.Property} and {@link - * org.osoa.sca.annotations.Reference} annotations beyond native Java syntactic capabilities - * - * @version $$Rev$$ $$Date$$ - */ -public class PropertyReferenceValidator extends ImplementationProcessorSupport { - - public PropertyReferenceValidator(AssemblyFactory factory) { - super(factory); - } - - public void visitEnd(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - // validate methods do not contain both @Reference and @Property annotations - Method[] methods = clazz.getMethods(); - boolean found; - for (Method method : methods) { - found = false; - Annotation[] anotations = method.getAnnotations(); - for (Annotation annotation : anotations) { - if (Property.class.equals(annotation.annotationType()) - || Reference.class.equals(annotation.annotationType())) { - if (found) { - MetaDataException e = new MetaDataException("Method cannot specify both property and reference"); - e.setIdentifier(method.getName()); - throw e; - } - found = true; - } - } - } - // validate fields do not contain both @Reference and @Property annotations - Set<Field> fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz); - for (Field field : fields) { - found = false; - Annotation[] anotations = field.getAnnotations(); - for (Annotation annotation : anotations) { - if (Property.class.equals(annotation.annotationType()) - || Reference.class.equals(annotation.annotationType())) { - if (found) { - MetaDataException e = new MetaDataException("Field cannot specify both property and reference"); - e.setIdentifier(field.getName()); - throw e; - } - found = true; - } - } - } - - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceProcessor.java deleted file mode 100644 index 007410b500..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ReferenceProcessor.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * - * 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 java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Collection; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.InvalidSetterException; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Multiplicity; -import org.apache.tuscany.model.assembly.Reference; -import org.apache.tuscany.model.assembly.ServiceContract; -import org.osoa.sca.annotations.Scope; - -/** - * Processes the {@link org.osoa.sca.annotations.Reference} annotation - * - * @version $$Rev$$ $$Date$$ - */ -@Scope("MODULE") -public class ReferenceProcessor extends ImplementationProcessorSupport { - - public ReferenceProcessor() { - } - - public ReferenceProcessor(AssemblyFactory factory) { - super(factory); - } - - @Override - public void visitMethod(Method method, ComponentType type) throws ConfigurationLoadException { - if(method.getDeclaringClass().equals(Object.class)){ - return; - } - int modifiers = method.getModifiers(); - org.osoa.sca.annotations.Reference annotation = method.getAnnotation(org.osoa.sca.annotations.Reference.class); - if (annotation != null) { - if (!Modifier.isPublic(modifiers)) { - InvalidSetterException e = new InvalidSetterException("Reference setter method is not public"); - e.setIdentifier(method.getName()); - throw e; - } - if (!Void.TYPE.equals(method.getReturnType())) { - InvalidSetterException e = new InvalidSetterException("Refence setter method must return void"); - e.setIdentifier(method.toString()); - throw e; - } - Class<?>[] params = method.getParameterTypes(); - if (params.length != 1) { - InvalidSetterException e = new InvalidSetterException("Reference setter method must have one parameter"); - e.setIdentifier(method.toString()); - throw e; - } - String name = annotation.name(); - if (name.length() == 0) { - name = method.getName(); - if (name.length() > 3 && name.startsWith("set")) { - // follow JavaBeans conventions - name = JavaIntrospectionHelper.toPropertyName(name); - } - } - addReference(name, params[0], annotation.required(), type); - } - } - - @Override - public void visitField(Field field, ComponentType type) throws ConfigurationLoadException { - if(field.getDeclaringClass().equals(Object.class)){ - return; - } - int modifiers = field.getModifiers(); - org.osoa.sca.annotations.Reference annotation = field.getAnnotation(org.osoa.sca.annotations.Reference.class); - if (annotation != null) { - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - InvalidSetterException e = new InvalidSetterException("Reference field is not public or protected"); - e.setIdentifier(field.getName()); - throw e; - } - String name = annotation.name(); - if (name.length() == 0) { - name = field.getName(); - } - addReference(name, field.getType(), annotation.required(), type); - } - } - - private void addReference(String name, Class<?> paramType, boolean required, ComponentType type) { - Reference reference = factory.createReference(); - reference.setName(name); - ServiceContract contract = factory.createJavaServiceContract(); - contract.setInterface(paramType); - reference.setServiceContract(contract); - boolean many = paramType.isArray() || Collection.class.isAssignableFrom(paramType); - Multiplicity multiplicity; - if (required) - multiplicity = many ? Multiplicity.ONE_N : Multiplicity.ONE_ONE; - else - multiplicity = many ? Multiplicity.ZERO_N : Multiplicity.ZERO_ONE; - reference.setMultiplicity(multiplicity); - type.getReferences().add(reference); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java deleted file mode 100644 index e81430115a..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ScopeProcessor.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - * 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.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; - -/** - * Processes the {@link org.osoa.sca.annotations.Scope} annotation - * - * @version $$Rev$$ $$Date$$ - */ -public class ScopeProcessor extends ImplementationProcessorSupport { - - public ScopeProcessor() { - } - - @Override - public void visitEnd(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - Scope scope = null; - org.osoa.sca.annotations.Scope annotation = clazz.getAnnotation(org.osoa.sca.annotations.Scope.class); - if (annotation != null) { - scope = ProcessorHelper.getScope(annotation); - } else { - Class<?> superClass = clazz.getSuperclass(); - if (superClass != null) { - scope = recurseScope(superClass); - } - } - if (scope == null) { - scope = Scope.INSTANCE; - } - //FIXME hack for now - set scope to implementation scope - //This will be clean up with spec change - for (Service service : type.getServices()) { - Scope serviceScope = service.getServiceContract().getScope(); - if (serviceScope == Scope.INSTANCE || serviceScope == null) { - service.getServiceContract().setScope(scope); - } - } - - } - - /** - * Walks the class hierarchy until a scope annotation is found - */ - private Scope recurseScope(Class<?> superClass) { - if (Object.class.equals(superClass)) { - return null; - } - org.osoa.sca.annotations.Scope scope = superClass.getAnnotation(org.osoa.sca.annotations.Scope.class); - if (scope == null) { - superClass = superClass.getSuperclass(); - if (superClass != null) { - return recurseScope(superClass); - } - } - return ProcessorHelper.getScope(scope); - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceProcessor.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceProcessor.java deleted file mode 100644 index 2c7ba823f2..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/config/processor/ServiceProcessor.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * - * 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 java.util.List; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.config.InvalidMetaDataException; -import org.apache.tuscany.core.config.JavaIntrospectionHelper; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.types.java.JavaServiceContract; -import org.osoa.sca.annotations.Callback; - -/** - * Processes the {@link org.osoa.sca.annotations.Service} annotation - * - * @version $$Rev$$ $$Date$$ - */ -public class ServiceProcessor extends ImplementationProcessorSupport { - - public ServiceProcessor() { - } - - public ServiceProcessor(AssemblyFactory factory) { - super(factory); - } - - @Override - public void visitClass(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - if (!clazz.isInterface()) { - processImplementation(clazz,type); - } else { - processInterface(clazz, type); - } - } - - private void processImplementation(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - // visiting the base implementation class - List<org.apache.tuscany.model.assembly.Service> services = type.getServices(); - Class[] interfaces = clazz.getInterfaces(); - org.osoa.sca.annotations.Service serviceAnnotation = clazz.getAnnotation(org.osoa.sca.annotations.Service.class); - if (interfaces.length == 0) { - // no interfaces so the class is the service - addService(services, clazz); - } else if (serviceAnnotation == null && interfaces.length == 1) { - // the impl has one interface, assign it to be the service - addService(services, interfaces[0]); - } else { - // visiting the implementation class - if (serviceAnnotation == null) { - return; - } - Class<?>[] serviceInterfaces = serviceAnnotation.interfaces(); - Class<?> value = serviceAnnotation.value(); - if (serviceInterfaces.length > 0) { - if (!Void.class.equals(value)) { - InvalidMetaDataException e = new InvalidMetaDataException("Both interfaces and value specified in @Service on "); - e.setIdentifier(clazz.getName()); - throw e; - } - for (Class<?> intf : interfaces) { - addService(services, intf); - } - } else if (!Void.class.equals(value)) { - addService(services, value); - } - } - } - - - @Override - public void visitEnd(Class<?> clazz, ComponentType type) throws ConfigurationLoadException { - List<Service> services = type.getServices(); - if (services.size() == 0) { - // no services processed so the class is the service - addService(services, clazz); - } - } - - private void processInterface(Class<?> clazz, ComponentType type) { - List<org.apache.tuscany.model.assembly.Service> services = type.getServices(); - // the interface is a remotable service, add it - org.osoa.sca.annotations.Remotable remotableAnnotation = clazz.getAnnotation(org.osoa.sca.annotations.Remotable.class); - if (remotableAnnotation != null) { - // check to see if service added previously b/c it was specified on @Service - if (ProcessorHelper.getService(clazz, services) == null) { - addService(services, clazz); - } - } - } - - - private void addService(List<Service> services, Class<?> serviceClass) { - //FIXME how do we support specifying remotable? - JavaServiceContract javaInterface = factory.createJavaServiceContract(); - javaInterface.setInterface(serviceClass); - org.osoa.sca.annotations.Scope scopeAnnotation = serviceClass.getAnnotation(org.osoa.sca.annotations.Scope.class); - Scope scope; - if (scopeAnnotation == null) { - scope = Scope.INSTANCE; - } else { - scope = ProcessorHelper.getScope(scopeAnnotation); - } - javaInterface.setScope(scope); - Callback callback = serviceClass.getAnnotation(Callback.class); - if (callback != null && !Void.class.equals(callback.value())) { - javaInterface.setCallbackInterface(callback.value()); - } - String name = JavaIntrospectionHelper.getBaseName(serviceClass); - Service service = factory.createService(); - service.setName(name); - service.setServiceContract(javaInterface); - services.add(service); - } -} |