From 8d2678027fa767584fc1b618115933fb0314694b Mon Sep 17 00:00:00 2001 From: lresende Date: Sat, 3 Oct 2009 16:45:57 +0000 Subject: TUSCANY-3290 - Adding support for @Remote attribute in git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@821362 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tuscany/sca/interfacedef/Interface.java | 12 +++++++- .../interfacedef/InvalidAnnotationException.java | 36 ++++++++++++++++++++++ .../sca/interfacedef/impl/InterfaceImpl.java | 16 +++++++--- .../java/impl/JavaInterfaceIntrospectorImpl.java | 7 +++++ .../sca/interfacedef/java/xml/JavaConstants.java | 1 + .../java/xml/JavaInterfaceProcessor.java | 16 +++++++--- 6 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidAnnotationException.java (limited to 'java/sca/modules') diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java index b72cade0cc..cab7057b57 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java @@ -45,7 +45,17 @@ public interface Interface extends Cloneable, PolicySubject { * @param remotable indicates whether the interface is remotable or local */ void setRemotable(boolean remotable); - + + /** + * Returns true if the interface remotable property is set.. + * + * This is used to verify if a @remotable attribute is used in the + * SCDL element. If true, use isRemotable to verify the + * current value + * + * @return + */ + boolean isRemotableSet(); // FIXME: [rfeng] We need to re-consider the conversational as an intent /** diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidAnnotationException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidAnnotationException.java new file mode 100644 index 0000000000..b24872bf96 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidAnnotationException.java @@ -0,0 +1,36 @@ +/* + * 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; + + +public class InvalidAnnotationException extends InvalidInterfaceException { + + private static final long serialVersionUID = 4923028138353415223L; + private final Class clazz; + + public InvalidAnnotationException(String message, Class clazz) { + super(message); + this.clazz = clazz; + } + + public Class getAnnotation() { + return clazz; + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java index 37929c3242..08f859fc8a 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java @@ -39,7 +39,7 @@ import org.apache.tuscany.sca.policy.PolicySet; */ public class InterfaceImpl implements Interface { - private boolean remotable; + private Boolean remotable; private boolean conversational; private OperationList operations = new OperationList(); private boolean unresolved; @@ -50,11 +50,19 @@ public class InterfaceImpl implements Interface { private Map attributes = new ConcurrentHashMap(); public boolean isRemotable() { - return remotable; + boolean value = false; + if (remotable != null && remotable.booleanValue()) { + value = true; + } + return value; } - public void setRemotable(boolean local) { - this.remotable = local; + public void setRemotable(boolean remotable) { + this.remotable = Boolean.valueOf(remotable); + } + + public boolean isRemotableSet() { + return remotable == null ? false : true; } public List getOperations() { diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java index 894b2f705c..e659d3a658 100644 --- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java +++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java @@ -35,6 +35,7 @@ import java.util.Set; import javax.xml.namespace.QName; import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidAnnotationException; import org.apache.tuscany.sca.interfacedef.InvalidCallbackException; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.InvalidOperationException; @@ -71,6 +72,12 @@ public class JavaInterfaceIntrospectorImpl { javaInterface.setJavaClass(clazz); boolean remotable = clazz.isAnnotationPresent(Remotable.class); + + if (remotable) { + if (javaInterface.isRemotableSet() && javaInterface.isRemotable() == false) { + throw new InvalidAnnotationException("@Remotable annotation present in a interface marked as not remotable in the SCDL", Remotable.class); + } + } // Consider @javax.ejb.Remote, java.rmi.Remote and javax.ejb.EJBObject // equivalent to @Remotable diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java index 5e8cf6a433..75816b1d36 100644 --- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java +++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java @@ -31,5 +31,6 @@ public interface JavaConstants { QName INTERFACE_JAVA_QNAME = new QName(SCA11_NS, "interface.java"); String INTERFACE = "interface"; String CALLBACK_INTERFACE = "callbackInterface"; + String REMOTABLE = "remotable"; } diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java index 1eb38592b7..b7c953813a 100644 --- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java +++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java @@ -63,11 +63,11 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor