diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-27 21:42:45 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-27 21:42:45 +0000 |
commit | 047ade832c6f41b92256a968bbb3bcabbaf8f5c0 (patch) | |
tree | a38a7fbd88f04213bada81bb4d4130582973c1b5 /sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main | |
parent | ff352b9f0baf505697990cccaf8dbf3067019eaf (diff) |
Initial support for introspecting JAX-RS annotations during interface contract introspection
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@938681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main')
2 files changed, 124 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java new file mode 100644 index 0000000000..563be43a6b --- /dev/null +++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxrs/JAXRSJavaInterfaceProcessor.java @@ -0,0 +1,107 @@ +/* + * 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.interfacedef.java.jaxrs; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; + +public class JAXRSJavaInterfaceProcessor implements JavaInterfaceVisitor { + + public void visitInterface(JavaInterface contract) throws InvalidInterfaceException { + + final Class<?> clazz = contract.getJavaClass(); + + List<Operation> getOperations = new ArrayList<Operation>(); + List<Operation> putOperations = new ArrayList<Operation>(); + List<Operation> postOperations = new ArrayList<Operation>(); + List<Operation> deleteOperations = new ArrayList<Operation>(); + + boolean hasJAXRSAnnotarions = false; + + for (Iterator<Operation> it = contract.getOperations().iterator(); it.hasNext();) { + final JavaOperation operation = (JavaOperation)it.next(); + final Method method = operation.getJavaMethod(); + + GET get = method.getAnnotation(GET.class); + if(get != null) { + hasJAXRSAnnotarions = true; + operation.getAttributes().put(GET.class.getClass(), true); + getOperations.add(operation); + } + + if(! getOperations.isEmpty()) { + contract.getAttributes().put(GET.class.getClass(), getOperations); + } + + PUT put = method.getAnnotation(PUT.class); + if(put != null) { + hasJAXRSAnnotarions = true; + operation.getAttributes().put(PUT.class.getClass(), true); + putOperations.add(operation); + } + + if(! putOperations.isEmpty()) { + contract.getAttributes().put(PUT.class.getClass(), putOperations); + } + + + POST post = method.getAnnotation(POST.class); + if(post != null) { + hasJAXRSAnnotarions = true; + operation.getAttributes().put(POST.class.getClass(), true); + postOperations.add(operation); + } + + if(! postOperations.isEmpty()) { + contract.getAttributes().put(POST.class.getClass(), postOperations); + } + + DELETE delete = method.getAnnotation(DELETE.class); + if(delete != null) { + hasJAXRSAnnotarions = true; + operation.getAttributes().put(DELETE.class.getClass(), true); + deleteOperations.add(operation); + } + + if(! deleteOperations.isEmpty()) { + contract.getAttributes().put(GET.class.getClass(), deleteOperations); + } + + } + + // Always set JAX-RS annotated interfaces as remotables + if (hasJAXRSAnnotarions) { + contract.setRemotable(true); + } + } +} diff --git a/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor new file mode 100644 index 0000000000..9101d744b3 --- /dev/null +++ b/sca-java-2.x/trunk/modules/interface-java-jaxrs/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.interfacedef.java.jaxrs.JAXRSJavaInterfaceProcessor;ranking=100
|