From 7ad16a07b4288227c531c485939318768129fb54 Mon Sep 17 00:00:00 2001 From: antelder Date: Wed, 3 Aug 2011 09:20:48 +0000 Subject: Tag debug mod for TUSCANY-3909 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1153403 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/introspect/PropertyProcessor.java | 150 +++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 sca-java-1.x/tags/1.6.1-TUSCANY-3909/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/PropertyProcessor.java (limited to 'sca-java-1.x/tags/1.6.1-TUSCANY-3909/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/PropertyProcessor.java') diff --git a/sca-java-1.x/tags/1.6.1-TUSCANY-3909/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/PropertyProcessor.java b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/PropertyProcessor.java new file mode 100644 index 0000000000..4bf53e8336 --- /dev/null +++ b/sca-java-1.x/tags/1.6.1-TUSCANY-3909/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/introspect/PropertyProcessor.java @@ -0,0 +1,150 @@ +/* + * 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.web.introspect; + +import java.lang.annotation.ElementType; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.implementation.java.IntrospectionException; +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl; +import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.DuplicatePropertyException; +import org.apache.tuscany.sca.implementation.java.introspect.impl.IllegalPropertyException; +import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper; +import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; + +/** + * Class to handle annotations that add Properties. + * + * @version $Rev$ $Date$ + */ +public class PropertyProcessor extends BaseJavaClassVisitor { + public PropertyProcessor(AssemblyFactory assemblyFactory) { + super(assemblyFactory); + } + + private boolean removeProperty(JavaElementImpl prop, JavaImplementation type) { + if(prop==null) { + return false; + } + List props = type.getProperties(); + for(int i=0;i 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); + + property.setMustSupply(annotation.required()); + type.getProperties().add(property); + properties.put(name, element); + } + + @Override + public void visitField(Field field, JavaImplementation type) throws IntrospectionException { + + org.osoa.sca.annotations.Property annotation = field.getAnnotation(org.osoa.sca.annotations.Property.class); + if (annotation == null) { + return; + } + + String name = annotation.name(); + if (name == null) { + name = ""; + } + if ("".equals(name) || name.equals(field.getType().getName())) { + name = field.getName(); + } + + Map 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); + property.setMustSupply(annotation.required()); + type.getProperties().add(property); + properties.put(name, element); + } + } + + @Override + public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type) + 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; + } +} -- cgit v1.2.3