summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java')
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java222
1 files changed, 0 insertions, 222 deletions
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
deleted file mode 100644
index b951e17fd2..0000000000
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
+++ /dev/null
@@ -1,222 +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.introspect.impl;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.tuscany.sca.assembly.Property;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.implementation.java.IntrospectionException;
-import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
-import org.apache.tuscany.sca.implementation.java.JavaImplementation;
-import org.apache.tuscany.sca.implementation.java.JavaParameterImpl;
-import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
-import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
-import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
-
-/**
- * Base class for ImplementationProcessors that handle annotations that add
- * Properties.
- *
- * @version $Rev$ $Date$
- */
-public abstract class AbstractPropertyProcessor<A extends Annotation> extends BaseJavaClassVisitor {
- private final Class<A> annotationClass;
-
- protected AbstractPropertyProcessor(ExtensionPointRegistry registry, Class<A> annotationClass) {
- super(registry);
- this.annotationClass = annotationClass;
- }
-
- private static boolean removeProperty(JavaElementImpl prop, JavaImplementation type) {
- if(prop==null) {
- return false;
- }
- List<Property> props = type.getProperties();
- for(int i=0;i<props.size();i++) {
- if(props.get(i).getName().equals(prop.getName())) {
- props.remove(i);
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
- A annotation = method.getAnnotation(annotationClass);
- if (annotation != null) {
-
- if (!JavaIntrospectionHelper.isSetter(method)) {
- throw new IllegalPropertyException("Annotated method is not a setter: " + method, method);
- }
-
- if(Modifier.isStatic(method.getModifiers())) {
- throw new IllegalPropertyException("Static method " + method.getName() +" in class " + method.getDeclaringClass().getName() + " can not be annotated as a Property");
- }
-
- String name = getName(annotation);
- if (name == null || "".equals(name)) {
- name = method.getName();
- if (name.startsWith("set")) {
- name = JavaIntrospectionHelper.toPropertyName(method.getName());
- }
- }
-
- Map<String, JavaElementImpl> properties = type.getPropertyMembers();
- JavaElementImpl prop = properties.get(name);
- // Setter override field
- if (prop != null && prop.getElementType() != ElementType.FIELD) {
- throw new DuplicatePropertyException(name);
- }
-
- removeProperty(prop, type);
-
- JavaElementImpl element = new JavaElementImpl(method, 0);
- Property property = createProperty(name, element);
-
- // add databinding available as annotations, as extensions
-
- initProperty(property, annotation);
- type.getProperties().add(property);
- properties.put(name, element);
- }
-
- // enforce the constraint that an ordinary method's argument can not be a Property
- Annotation paramsAnnotations[][] = method.getParameterAnnotations();
- for (int i = 0; i < paramsAnnotations.length; i++) {
- Annotation argAnnotations[] = paramsAnnotations[i];
- for (int j = 0; j < argAnnotations.length; j++) {
- if(argAnnotations[j].annotationType() == org.oasisopen.sca.annotation.Property.class) {
- throw new IllegalPropertyException("Argument " + (i+1) + " of method " + method.getName() + " in class " + method.getDeclaringClass() + " can not be a Property");
- }
- }
- }
- }
-
-
- @Override
- public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
-
- A annotation = field.getAnnotation(annotationClass);
- if (annotation == null) {
- return;
- }
-
- if(Modifier.isStatic(field.getModifiers())) {
- throw new IllegalPropertyException("Static field " + field.getName() +" in class " + field.getDeclaringClass().getName() + " can not be annotated as a Property");
- }
-
- if(Modifier.isFinal(field.getModifiers())) {
- throw new IllegalPropertyException("Final field " + field.getName() +" in class " + field.getDeclaringClass().getName() + " can not be annotated as a Property");
- }
-
- String name = getName(annotation);
- if (name == null) {
- name = "";
- }
- if ("".equals(name) || name.equals(field.getType().getName())) {
- name = field.getName();
- }
-
- Map<String, JavaElementImpl> properties = type.getPropertyMembers();
- JavaElementImpl prop = properties.get(name);
- // Setter override field
- if (prop != null && prop.getElementType() == ElementType.FIELD) {
- throw new DuplicatePropertyException(name);
- }
-
- if (prop == null) {
- JavaElementImpl element = new JavaElementImpl(field);
- Property property = createProperty(name, element);
- initProperty(property, annotation);
- type.getProperties().add(property);
- properties.put(name, element);
- }
- }
-
- @Override
- public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
- throws IntrospectionException {
-
- Map<String, JavaElementImpl> properties = type.getPropertyMembers();
- A annotation = parameter.getAnnotation(annotationClass);
- if (annotation != null) {
- String name = getName(annotation);
- if (name == null) {
- name = parameter.getType().getName();
- }
- if (!"".equals(name) && !"".equals(parameter.getName()) && !name.equals(parameter.getName())) {
- throw new InvalidConstructorException("Mismatched property name: " + parameter);
- }
- if ("".equals(name) && "".equals(parameter.getName())) {
- throw new InvalidPropertyException("Missing property name: " + parameter);
- }
- if ("".equals(name)) {
- name = parameter.getName();
- }
-
- if (!getRequired(annotation)) {
- throw new InvalidPropertyException("JCA_90014 Constructor property must not have required=false: " + type.getName());
- }
-
- JavaElementImpl prop = properties.get(name);
- // Setter override field
- if (prop != null && prop.getElementType() != ElementType.FIELD) {
- throw new DuplicatePropertyException(name);
- }
- removeProperty(prop, type);
-
- parameter.setName(name);
- parameter.setClassifer(annotationClass);
- Property property = createProperty(name, parameter);
- initProperty(property, annotation);
- type.getProperties().add(property);
- properties.put(name, parameter);
- }
- }
-
- protected abstract String getName(A annotation);
- protected abstract boolean getRequired(A annotation);
-
- protected abstract void initProperty(Property property, A annotation) throws IntrospectionException;
-
- protected Property createProperty(String name, JavaElementImpl element) throws IntrospectionException {
-
- Property property = assemblyFactory.createProperty();
- property.setName(name);
- Class<?> baseType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
- property.setXSDType(JavaXMLMapper.getXMLType(baseType));
-
- Class<?> javaType = element.getType();
- if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
- property.setMany(true);
- }
- return property;
-
- }
-
-}