diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 01:42:27 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 01:42:27 +0000 |
commit | 3c7c4a749baafcf375f4785a7668d3a25c9063e3 (patch) | |
tree | a66b8b031c5dc6c7744f44b44b6bcd371bd0b8df /sca-java-1.x/trunk/modules/interface | |
parent | eb03ff672236cddf65533f39b83ddd5e2984a2bb (diff) |
Moving 1.x trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/trunk/modules/interface')
30 files changed, 3782 insertions, 0 deletions
diff --git a/sca-java-1.x/trunk/modules/interface/LICENSE b/sca-java-1.x/trunk/modules/interface/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/sca-java-1.x/trunk/modules/interface/NOTICE b/sca-java-1.x/trunk/modules/interface/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/trunk/modules/interface/pom.xml b/sca-java-1.x/trunk/modules/interface/pom.xml new file mode 100644 index 0000000000..85b3244969 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/pom.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>1.6-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-interface</artifactId> + <name>Apache Tuscany SCA Interface Model</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy</artifactId> + <version>1.6-SNAPSHOT</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + + <configuration> + <instructions> + <Bundle-Version>${tuscany.version}</Bundle-Version> + <Bundle-SymbolicName>org.apache.tuscany.sca.interface</Bundle-SymbolicName> + <Bundle-Description>${pom.name}</Bundle-Description> + <Export-Package>org.apache.tuscany.sca.interfacedef*</Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java new file mode 100644 index 0000000000..247a432330 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java @@ -0,0 +1,29 @@ +/* + * 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; + +/** + * Enum of the Conversation Sequence values. + * + * @version $Rev$ $Date$ + */ +public enum ConversationSequence { + CONVERSATION_NONE, CONVERSATION_START, CONVERSATION_CONTINUE, CONVERSATION_END +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java new file mode 100644 index 0000000000..63e26ef7f7 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java @@ -0,0 +1,119 @@ +/* + * 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; + +import java.lang.reflect.Type; + +/** + * Representation of the type of data associated with an operation. Data is + * represented in two forms: the physical form used by the runtime and a logical + * form used by the assembly. The physical form is a Java Type because the + * runtime is written in Java. This may be the same form used by the application + * but it may not; for example, an application that is performing stream + * processing may want a physical form such as an + * {@link java.io.InputStream InputStream} to semantically operate on application + * data such as a purchase order. The logical description is that used by the + * assembly model and is an identifier into some well-known type space; examples + * may be a Java type represented by its Class or an XML type represented by its + * QName. Every data type may also contain metadata describing the expected + * data; for example, it could specify a preferred data binding technology or + * the size of a typical instance. + * + * @version $Rev$ $Date$ + */ +public interface DataType<L> extends Cloneable { + /** + * Set the java type for the data + * @param cls + */ + void setPhysical(Class<?> cls); + + /** + * Returns the physical type used by the runtime. + * + * @return the physical type used by the runtime + */ + Class<?> getPhysical(); + + /** + * Get the java generic type + * @return The java generic type + */ + Type getGenericType(); + + /** + * Set the java generic type + * @param genericType + */ + void setGenericType(Type genericType); + + /** + * Returns the logical identifier used by the assembly. The type of this + * value identifies the logical type system in use. Known values are: + * <ul> + * <li>a Class identifies a Java type by name and + * ClassLoader; this includes Java Classes as they are specializations of + * Type</li> + * <li>a XMLType identifies an XML type by local name and + * namespace</li> + * </ul> + * + * @return the logical type name + */ + L getLogical(); + + /** + * Get the databinding for the given data type + * @return the databinding + */ + String getDataBinding(); + + /** + * Set the databinding for the given data type + * @param dataBinding the dataBinding to set + */ + void setDataBinding(String dataBinding); + + /** + * Clone a data type + * @return The cloned data type + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + + /** + * Set the logical type of the data type + * @param logical the logical to set + */ + void setLogical(L logical); + + /** + * Get the databinding-specific metadata + * @param type The java type of the metadata + * @return the databinding-specific metadata + */ + <T> T getMetaData(Class<T> type); + /** + * Set the databinding-specific metadata + * @param type The java type of the metadata + * @param metaData the databinding-specific metadata, such as SDO's commonj.sdo.Type or + * JAXB's javax.xml.bind.JAXBContext + */ + <T> void setMetaData(Class<T> type, T metaData); +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java new file mode 100644 index 0000000000..70f6d5b403 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java @@ -0,0 +1,62 @@ +/* + * 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; + +/** + * This interface represents the mapping between WSDL faults and Java exceptions + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("unchecked") +public interface FaultExceptionMapper { + /** + * Introspect an exception class to find out the fault data type following the WSDL2Java + * mapping rules. The result will be populated into the logical type of the exception data + * type + * + * @param exceptionDataType The data type representing a java exception class + * @param operation TODO + * @param generatingFaultBean If JAXWS Section 3.7 Fault Bean will be generated + * @return true if the introspection can recognize the exception data type + */ + boolean introspectFaultDataType(DataType<DataType> exceptionDataType, Operation operation, boolean generatingFaultBean); + + /** + * Create a java exception to wrap the fault data + * + * @param exceptionType The DataType for the exception + * @param message message for the exception + * @param faultInfo The fault data + * @param cause of the exception + * @param operation TODO + * @return An instance of java exception to represent the fault + */ + Throwable wrapFaultInfo(DataType<DataType> exceptionType, String message, Object faultInfo, Throwable cause, Operation operation); + + /** + * Retrieve the fault info from a java exception + * + * @param exception The java exception that represents the fault data + * @param faultBeanClass + * @param operation TODO + * @return The fault data + */ + Object getFaultInfo(Throwable exception, Class<?> faultBeanClass, Operation operation); +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java new file mode 100644 index 0000000000..179dc1755e --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java @@ -0,0 +1,69 @@ +/* + * 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; + +/** + * Denotes incompatible service contracts for a wire + * + * @version $Rev$ $Date$ + */ +public class IncompatibleInterfaceContractException extends Exception { + private static final long serialVersionUID = 5127478601823295587L; + private final InterfaceContract source; + private final InterfaceContract target; + private final Operation sourceOperation; + private final Operation targetOperation; + + public IncompatibleInterfaceContractException(String message, InterfaceContract source, InterfaceContract target) { + super(message); + this.source = source; + this.target = target; + this.sourceOperation = null; + this.targetOperation = null; + } + + public IncompatibleInterfaceContractException(String message, + InterfaceContract source, + InterfaceContract target, + Operation sourceOperation, + Operation targetOperation) { + super(message); + this.source = source; + this.target = target; + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + } + + public InterfaceContract getTarget() { + return target; + } + + public InterfaceContract getSource() { + return source; + } + + public Operation getSourceOperation() { + return sourceOperation; + } + + public Operation getTargetOperation() { + return targetOperation; + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java new file mode 100644 index 0000000000..1e91dc6fdb --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java @@ -0,0 +1,111 @@ +/* + * 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; + +import java.util.List; + +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a service interface. This interface will typically be extended to + * support concrete interface type systems, such as Java interfaces, WSDL 1.1 + * portTypes and WSDL 2.0 interfaces. + * + * @version $Rev$ $Date$ + */ +public interface Interface extends Cloneable, PolicySetAttachPoint { + + /** + * Returns true if the interface is a remotable interface.. + * + * @return true if the interface is a remotable interface + */ + boolean isRemotable(); + + /** + * Sets whether the interface is a remotable or local interface. + * + * @param remotable indicates whether the interface is remotable or local + */ + void setRemotable(boolean remotable); + + + // FIXME: [rfeng] We need to re-consider the conversational as an intent + /** + * Test if the interface is conversational + * @return + */ + boolean isConversational(); + + /** + * Set whether the interface is conversational + * @param conversational + */ + void setConversational(boolean conversational); + + /** + * Returns the operations defined on this interface. + * + * @return the operations defined on this interface + */ + List<Operation> getOperations(); + + /** + * Set the databinding for the interface + * @param dataBinding + * @deprecated Please use resetDataBinding + */ + @Deprecated + void setDefaultDataBinding(String dataBinding); + + /** + * Reset the databinding for the interface + * @param dataBinding + */ + void resetDataBinding(String dataBinding); + + /** + * Set the interface input types by copying those from the + * interface provided + * + * @param newInterface + */ + public void resetInterfaceInputTypes(Interface newInterface); + + /** + * Set the interface output types by copying those from the + * interface provided + * + * @param newInterface + */ + public void resetInterfaceOutputTypes(Interface newInterface); + + /** + * Returns true if the Interface is dynamic. + * + * @return true if the Interface is dynamic. + */ + boolean isDynamic(); + + /** + * Implementations must support cloning. + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java new file mode 100644 index 0000000000..568a6c595c --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java @@ -0,0 +1,81 @@ +/* + * 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; + + +/** + * Interface contracts define one or more business functions. These business + * functions are provided by services and are used by references. + * + * @version $Rev$ $Date$ + */ +public interface InterfaceContract extends Cloneable { + + /** + * Returns the interface definition representing the interface for + * invocations from the requestor to the provider. + * + * @return the interface definition representing the interface for + * invocations from the requestor to the provider + */ + Interface getInterface(); + + /** + * Sets the interface definition representing the interface for invocations + * from the requestor to the provider. + * + * @param callInterface the interface definition representing the interface + * for invocations from the requestor to the provider + */ + void setInterface(Interface callInterface); + + /** + * Returns the interface definition representing the interface for + * invocations from the provider to the requestor. + * + * @return the interface definition representing the interface for + * invocations from the provider to the requestor. + */ + Interface getCallbackInterface(); + + /** + * Sets the interface definition representing the interface for invocations + * from the provider to the requestor. + * + * @param callbackInterface the interface definition representing the + * interface for invocations from the provider to the requestor. + */ + void setCallbackInterface(Interface callbackInterface); + + // FIXME: We need a better way to do this + /** + * Convert an interface contract to a unidirectional interface contract + * + * @param isCallback true for a callback interface contract, false for + * a forward interface contract + * @return A unidirectional interface contract, cloned if necessary + */ + InterfaceContract makeUnidirectional(boolean isCallback); + + /** + * Implementations must support cloning. + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java new file mode 100644 index 0000000000..5601b09660 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java @@ -0,0 +1,115 @@ +/* + * 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; + +/** + * The InterfaceContractMapper is responsible to match interfaces + * + * @version $Rev$ $Date$ + */ +public interface InterfaceContractMapper { + /** + * Check the compatibility of the source and the target interface contracts. + * <p> + * A wire may only connect a source to a target if the target implements an + * interface that is compatible with the interface required by the source. + * The source and the target are compatible if: <p/> + * <ol> + * <li>the source interface and the target interface MUST either both be + * remotable or they are both local + * <li>the methods on the target interface MUST be the same as or be a + * superset of the methods in the interface specified on the source + * <li>compatibility for the individual method is defined as compatibility + * of the signature, that is method name, input types, and output types MUST + * BE the same. + * <li>the order of the input and output types also MUST BE the same. + * <li>the set of Faults and Exceptions expected by the source MUST BE the + * same or be a superset of those specified by the service. + * <li>other specified attributes of the two interfaces MUST match, + * including Scope and Callback interface + * </ol> + * <p/> + * <p> + * Please note this test is not symmetric: the success of isCompatible(A, B) + * does NOT imply isCompatible(B, A) + * + * @param source The source interface contract + * @param target The target interface contract + * @return true if the source contract can be supported by the target + * contract + */ + boolean isCompatible(InterfaceContract source, InterfaceContract target); + + /** + * @param source + * @param target + * @param ignoreCallback + * @param silent + * @return + * @throws IncompatibleInterfaceContractException + */ + boolean checkCompatibility(InterfaceContract source, + InterfaceContract target, + boolean ignoreCallback, + boolean silent) throws IncompatibleInterfaceContractException; + + /** + * Test if the source data type is compatible with the target data type. The + * compatibility is defined as follows. + * <ul> + * <li>source's logical type is either the same or subtype of the target's + * logical type + * </ul> + * For example, if the source type is a SDO Customer and the target type is + * a JAXB Customer and both Customer are generated from the same XSD type. + * + * @param source The source data type + * @param target The target data type + * @return + */ + boolean isCompatible(DataType source, DataType target, boolean remotable); + + /** + * Check if source operation is compatible with the target operation + * + * @param source The source operation + * @param target The target operation + * @return true if the source operation is compatible with the target + * operation + */ + boolean isCompatible(Operation source, Operation target, boolean remotable); + + /** + * @param source + * @param target + * @return + */ + boolean isCompatible(Interface source, Interface target); + + /** + * Map the source operation to a compatible operation in the target + * interface + * + * @param target The target interface + * @param source The source operation + * @return A compatible operation + */ + Operation map(Interface target, Operation source); +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java new file mode 100644 index 0000000000..f952a86478 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java @@ -0,0 +1,34 @@ +/* + * 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; + + +/** + * Denotes an illegal callback interface + * + * @version $Rev$ $Date$ + */ + +public class InvalidCallbackException extends InvalidInterfaceException { + private static final long serialVersionUID = 2727755895702116397L; + + public InvalidCallbackException(String message) { + super(message); + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java new file mode 100644 index 0000000000..2a273c9a26 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java @@ -0,0 +1,41 @@ +/* + * 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; + +/** + * @version $Rev$ $Date$ + */ +public abstract class InvalidInterfaceException extends Exception { + + public InvalidInterfaceException() { + super(); + } + + public InvalidInterfaceException(String message) { + super(message); + } + + public InvalidInterfaceException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidInterfaceException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java new file mode 100644 index 0000000000..b19805c5b1 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java @@ -0,0 +1,42 @@ +/* + * 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; + +import java.lang.reflect.Method; + +/** + * Denotes an invalid conversational interface definition + * + * @version $Rev$ $Date$ + */ +public class InvalidOperationException extends InvalidInterfaceException { + + private static final long serialVersionUID = -1797615361821517091L; + private final Method operation; + + public InvalidOperationException(String message, Method operation) { + super(message); + this.operation = operation; + } + + public Method getOperation() { + return operation; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java new file mode 100644 index 0000000000..395960d04f --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java @@ -0,0 +1,226 @@ +/* + * 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; + +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents an operation on a service interface. + * + * @version $Rev$ $Date$ + */ +public interface Operation extends Cloneable, PolicySetAttachPoint { + /** + * Returns the name of the operation. + * + * @return the name of the operation + */ + String getName(); + + /** + * Sets the name of the operation. + * + * @param name the name of the operation + */ + void setName(String name); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + + /** + * Get the data type that represents the input of this operation. The logic + * type is a list of data types and each element represents a parameter + * + * @return the inputType + */ + DataType<List<DataType>> getInputType(); + + /** + * @param inputType + */ + void setInputType(DataType<List<DataType>> inputType); + + /** + * Get the data type for the output + * + * @return the outputType + */ + DataType getOutputType(); + + /** + * @param outputType + */ + void setOutputType(DataType outputType); + + /** + * Get a list of data types to represent the faults/exceptions + * + * @return the faultTypes + */ + List<DataType> getFaultTypes(); + + /** + * @param faultTypes + */ + void setFaultTypes(List<DataType> faultTypes); + + /** + * Get the owning interface + * @return + */ + Interface getInterface(); + + /** + * Set the owning interface + * @param interfaze + */ + void setInterface(Interface interfaze); + + /** + * Get the sequence of the conversation + * @return + */ + ConversationSequence getConversationSequence(); + + /** + * Set the sequence of conversation for the operation + * @param sequence + */ + void setConversationSequence(ConversationSequence sequence); + + /** + * Indicate if the operation is non-blocking + * @return + */ + boolean isNonBlocking(); + + /** + * Set the operation to be non-blocking + */ + void setNonBlocking(boolean nonBlocking); + + /** + * @return the inputWrapperInfo + */ + WrapperInfo getInputWrapper(); + + /** + * @param wrapperInfo the inputWrapperInfo to set + */ + void setInputWrapper(WrapperInfo wrapperInfo); + + /** + * @return the outputWrapperInfo + */ + WrapperInfo getOutputWrapper(); + + /** + * @param wrapperInfo the outputWrapperInfo to set + */ + // TODO - WI + void setOutputWrapper(WrapperInfo wrapperInfo); + + /** + * @return the inputWrapperStyle + */ + boolean isInputWrapperStyle(); + + /** + * @param inputWrapperStyle the wrapperStyle to set + */ + void setInputWrapperStyle(boolean wrapperStyle); + + /** + * @return the outputWrapperStyle + */ + boolean isOutputWrapperStyle(); + + /** + * @param outputWrapperStyle the wrapperStyle to set + */ + void setOutputWrapperStyle(boolean wrapperStyle); + + /** + * @deprecated This should be the WrapperInfo.getDataBinding() + * Get the databinding for the operation + * @return + */ + @Deprecated + String getDataBinding(); + + /** + * @deprecated This should be the WrapperInfo.setDataBinding() + * Set the databinding for the operation + * @param dataBinding + */ + @Deprecated + void setDataBinding(String dataBinding); + + /** + * Returns true if the operation is dynamic. + * + * @return true if the operation is dynamic otherwise false + */ + boolean isDynamic(); + + /** + * Set if the operation is dynamic + * @param b + */ + void setDynamic(boolean b); + + /** + * Get the synthesized fault beans for this operation + * + * @return the fault beans + */ + Map<QName, List<DataType<XMLType>>> getFaultBeans(); + + /** + * Set the synthesized fault beans for this operation + * @param faultBeans + */ + void setFaultBeans(Map<QName, List<DataType<XMLType>>> faultBeans); + + /** + * Implementations must support cloning. + */ + Object clone() throws CloneNotSupportedException; + + List<ParameterMode> getParameterModes(); + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java new file mode 100644 index 0000000000..6773b29088 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java @@ -0,0 +1,45 @@ +/* + * 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; + +import java.lang.reflect.Method; + +/** + * Exception thrown to indicate that a service contract specification contains + * an overloaded method. + * + * @version $Rev$ $Date$ + */ +public class OverloadedOperationException extends InvalidInterfaceException { + private static final long serialVersionUID = -4658711318608885638L; + private final Method operation; + + public OverloadedOperationException(Method operation) { + super(operation == null ? + null : "Cannot overload operation " + operation.getName() + + " on " + operation.getDeclaringClass().getName() + + " as it is a @Remotable interface"); + this.operation = operation; + } + + public Method getOperation() { + return operation; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ParameterMode.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ParameterMode.java new file mode 100644 index 0000000000..c4244a3480 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ParameterMode.java @@ -0,0 +1,28 @@ +/*
+ * 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;
+
+/**
+ * Parameter mode
+ * @see http://java.sun.com/javase/6/docs/api/javax/jws/WebParam.Mode.html
+ */
+public enum ParameterMode {
+ IN, OUT, INOUT;
+}
diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java new file mode 100644 index 0000000000..2065940c8d --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java @@ -0,0 +1,230 @@ +/* + * 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.impl; + +import java.lang.ref.WeakReference; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * Representation of the type of data associated with an operation. Data is + * represented in two forms: the physical form used by the runtime and a logical + * form used by the assembly. The physical form is a Java Type because the + * runtime is written in Java. This may be the same form used by the application + * but it may not; for example, an application that is performing stream + * processing may want a physical form such as an + * {@link java.io.InputStream InputStream} to semantially operate on application + * data such as a purchase order. The logical description is that used by the + * assembly model and is an identifier into some well-known type space; examples + * may be a Java type represented by its Class or an XML type represented by its + * QName. Every data type may also contain metadata describing the expected + * data; for example, it could specify a preferred data binding technology or + * the size of a typical instance. + * + * @version $Rev$ $Date$ + */ +public class DataTypeImpl<L> implements DataType<L> { + private String dataBinding; + private WeakReference<Class<?>> physical; + private WeakReference<Type> genericType; + private L logical; + private Map<Class<?>, Object> metaDataMap; + + /** + * Construct a data type specifying the physical and logical types. + * + * @param physical the physical class used by the runtime + * @param logical the logical type + * @see #getLogical() + */ + public DataTypeImpl(Class<?> physical, L logical) { + this(null, physical, physical, logical); + } + + /** + * @param dataBinding + * @param physical + * @param logical + */ + public DataTypeImpl(String dataBinding, Class<?> physical, L logical) { + this(dataBinding, physical, physical, logical); + } + + /** + * @param dataBinding + * @param physical + * @param genericType + * @param logical + */ + public DataTypeImpl(String dataBinding, Class<?> physical, Type genericType, L logical) { + super(); + this.dataBinding = dataBinding; + this.physical = new WeakReference<Class<?>>(physical); + this.genericType = new WeakReference<Type>(genericType); + this.logical = logical; + } + + /** + * Returns the physical type used by the runtime. + * + * @return the physical type used by the runtime + */ + public Class<?> getPhysical() { + return physical.get(); + } + + /** + * @param physical the physical to set + */ + public void setPhysical(Class<?> physical) { + this.physical = new WeakReference<Class<?>>(physical); + } + + /** + * Get the java generic type + * @return The java generic type + */ + public Type getGenericType() { + return genericType.get(); + } + + /** + * Set the java generic type + * @param genericType + */ + public void setGenericType(Type genericType) { + this.genericType = new WeakReference<Type>(genericType); + } + + /** + * Returns the logical identifier used by the assembly. The type of this + * value identifies the logical type system in use. Known values are: + * <ul> + * <li>a java.lang.reflect.Type identifies a Java type by name and + * ClassLoader; this includes Java Classes as they are specializations of + * Type</li> + * <li>a javax.xml.namespace.QName identifies an XML type by local name and + * namespace</li> + * </ul> + * + * @return the logical type name + */ + public L getLogical() { + return logical; + } + + /** + * @param logical the logical to set + */ + public void setLogical(L logical) { + this.logical = logical; + } + + public String getDataBinding() { + return dataBinding; + } + + /** + * @param dataBinding the dataBinding to set + */ + public void setDataBinding(String dataBinding) { + this.dataBinding = dataBinding; + } + + @SuppressWarnings("unchecked") + @Override + public Object clone() throws CloneNotSupportedException { + DataTypeImpl copy = (DataTypeImpl)super.clone(); + return copy; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((dataBinding == null) ? 0 : dataBinding.hashCode()); + result = prime * result + ((genericType == null || genericType.get() == null) ? 0 : genericType.get().hashCode()); + result = prime * result + ((logical == null) ? 0 : logical.hashCode()); + result = prime * result + ((physical == null || physical.get() == null) ? 0 : physical.get().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final DataTypeImpl other = (DataTypeImpl)obj; + if (dataBinding == null) { + if (other.dataBinding != null) + return false; + } else if (!dataBinding.equals(other.dataBinding)) + return false; + if (genericType == null || genericType.get() == null) { + if (other.genericType != null) + return false; + } else if (!genericType.get().equals(other.genericType.get())) + return false; + if (logical == null) { + if (other.logical != null) + return false; + } else if (!logical.equals(other.logical)) + return false; + if (physical == null || physical.get() == null) { + if (other.physical != null) + return false; + } else if (!physical.get().equals(other.physical.get())) + return false; + return true; + } + + public <T> T getMetaData(Class<T> type) { + return metaDataMap == null ? null : type.cast(metaDataMap.get(type)); + } + + public <T> void setMetaData(Class<T> type, T metaData) { + if (metaDataMap == null) { + metaDataMap = new ConcurrentHashMap<Class<?>, Object>(); + } + metaDataMap.put(type, metaData); + } + + @Override + public String toString() { + // private Class<?> physical; + // private Type genericType; + // private L logical; + // private Map<Class<?>, Object> metaDataMap; + StringBuilder b = new StringBuilder( 256 ); + b.append( "DataType[" ); + b.append( "dataBinding=" + ((dataBinding==null) ? "null" : dataBinding) ); + b.append( ", genericType=" + ((genericType==null || genericType.get()==null) ? "null" : genericType.get()) ); + b.append( ", physical=" + ((physical==null || physical.get()==null) ? "null" : physical.get()) ); + b.append( ", logical=" + ((logical==null) ? "null" : logical) ); + b.append( ", metaData size=" + ((metaDataMap==null) ? "0" : metaDataMap.size()) ); + b.append( "]" ); + return b.toString(); + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java new file mode 100644 index 0000000000..15581b5e04 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java @@ -0,0 +1,128 @@ +/* + * 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.impl; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * Represents an interface contract. InterfaceContractImpl + * + * @version $Rev$ $Date$ + */ +public abstract class InterfaceContractImpl implements InterfaceContract { + private Interface callInterface; + private Interface callbackInterface; + + public Interface getCallbackInterface() { + return callbackInterface; + } + + public Interface getInterface() { + return callInterface; + } + + public void setCallbackInterface(Interface callbackInterface) { + this.callbackInterface = callbackInterface; + } + + public void setInterface(Interface callInterface) { + this.callInterface = callInterface; + } + + public InterfaceContract makeUnidirectional(boolean isCallback) { + if (!isCallback && callbackInterface == null) + return this; // already a unidirectional forward interface contract + + if (isCallback && callInterface == null) + return this; // already a unidirectional callback interface contract + + // contract is bidirectional, so create a new unidirectional contract + try { + InterfaceContract newContract = clone(); + if (!isCallback) { + newContract.setCallbackInterface(null); // create unidirectional forward interface contract + } else { + newContract.setInterface(null); // create unidirectional callback interface contract + } + return newContract; + } catch (CloneNotSupportedException e) { + // will not happen + return null; + } + } + + @Override + public InterfaceContractImpl clone() throws CloneNotSupportedException { + InterfaceContractImpl copy = (InterfaceContractImpl)super.clone(); + if (this.callbackInterface != null) { + copy.callbackInterface = (Interface)this.callbackInterface.clone(); + } + if (this.callInterface != null) { + copy.callInterface = (Interface)this.callInterface.clone(); + } + return copy; + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((callInterface == null) ? 0 : callInterface.hashCode()); + result = prime * result + ((callbackInterface == null) ? 0 : callbackInterface.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final InterfaceContractImpl other = (InterfaceContractImpl)obj; + if (callInterface == null) { + if (other.callInterface != null) { + return false; + } + } else if (!callInterface.equals(other.callInterface)) { + return false; + } + if (callbackInterface == null) { + if (other.callbackInterface != null) { + return false; + } + } else if (!callbackInterface.equals(other.callbackInterface)) { + return false; + } + return true; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java new file mode 100644 index 0000000000..9aeeafe6b9 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java @@ -0,0 +1,302 @@ +/* + * 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.impl; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * @version $Rev$ $Date$ + */ +public class InterfaceContractMapperImpl implements InterfaceContractMapper { + + public boolean isCompatible(DataType source, DataType target, boolean remotable) { + if (source == target) { + return true; + } + if (!remotable) { + if (source == null || target == null) { + return false; + } + // For local case + return target.getPhysical().isAssignableFrom(source.getPhysical()); + } else { + // FIXME: How to test if two remotable data type is compatible? + // return target.getLogical().equals(source.getLogical()); + return true; + } + + } + + public boolean isCompatible(Operation source, Operation target, boolean remotable) { + if (source == target) { + return true; + } + + if (source.isDynamic() || target.isDynamic()) { + return true; + } + + // Check name + if (!source.getName().equals(target.getName())) { + return false; + } + + if (source.getInterface().isRemotable() != target.getInterface().isRemotable()) { + return false; + } + + // if (source.getInterface().isRemotable()) { + // return true; + // } + + // FIXME: We need to deal with wrapped<-->unwrapped conversion + + // Check output type + DataType sourceOutputType = source.getOutputType(); + DataType targetOutputType = target.getOutputType(); + + // Note the target output type is now the source for checking + // compatibility + if (!isCompatible(targetOutputType, sourceOutputType, remotable)) { + return false; + } + + boolean checkSourceWrapper = true; + List<DataType> sourceInputType = source.getInputType().getLogical(); + if (source.isInputWrapperStyle() && source.getInputWrapper() != null) { + sourceInputType = source.getInputWrapper().getUnwrappedInputType().getLogical(); + checkSourceWrapper = false; + } + boolean checkTargetWrapper = true; + List<DataType> targetInputType = target.getInputType().getLogical(); + if (target.isInputWrapperStyle() && target.getInputWrapper() != null) { + targetInputType = target.getInputWrapper().getUnwrappedInputType().getLogical(); + checkTargetWrapper = false; + } + + if (checkSourceWrapper != checkTargetWrapper) { + return true; + } + if (sourceInputType.size() != targetInputType.size()) { + return false; + } + + int size = sourceInputType.size(); + for (int i = 0; i < size; i++) { + if (!isCompatible(sourceInputType.get(i), targetInputType.get(i), remotable)) { + return false; + } + } + + // Check fault types + for (DataType targetFaultType : target.getFaultTypes()) { + // Source fault types must be the same or superset of target fault + // types + boolean found = true; + for (DataType sourceFaultType : source.getFaultTypes()) { + found = false; + if (isCompatible(targetFaultType, sourceFaultType, remotable)) { + // Target fault type can be covered by the source fault type + found = true; + break; + } + } + if (!found) { + return false; + } + } + + return true; + } + + // FIXME: How to improve the performance for the lookup + private Operation getOperation(List<Operation> operations, String name) { + for (Operation op : operations) { + if (op.getName().equals(name)) { + return op; + } + } + return null; + } + + public boolean checkCompatibility(InterfaceContract source, + InterfaceContract target, + boolean ignoreCallback, + boolean silent) throws IncompatibleInterfaceContractException { + if (source == target) { + // Shortcut for performance + return true; + } + + if (source.getInterface().isDynamic() || target.getInterface().isDynamic()) { + return true; + } + + if (source.getInterface().isRemotable() != target.getInterface().isRemotable()) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Remotable settings do not match", source, target); + } else { + return false; + } + } + if (source.getInterface().isConversational() != target.getInterface().isConversational()) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Interaction scopes do not match", source, target); + } else { + return false; + } + } + + for (Operation operation : source.getInterface().getOperations()) { + Operation targetOperation = map(target.getInterface(), operation); + if (targetOperation == null) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Operation not found on target", source, target); + } else { + return false; + } + } + if (!source.getInterface().isRemotable()) { + // FIXME: for remotable operation, only compare name for now + if (!isCompatible(operation, targetOperation, false)) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Target operations are not compatible", + source, target); + } else { + return false; + } + } + } + } + + if (ignoreCallback) { + return true; + } + + if (source.getCallbackInterface() == null && target.getCallbackInterface() == null) { + return true; + } + if (source.getCallbackInterface() == null || target.getCallbackInterface() == null) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Callback interface doesn't match", source, target); + } else { + return false; + } + } + + for (Operation operation : source.getCallbackInterface().getOperations()) { + Operation targetOperation = map(target.getCallbackInterface(), operation); + if (targetOperation == null) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Callback operation not found on target", source, + target, null, targetOperation); + } else { + return false; + } + } + if (!source.getCallbackInterface().isRemotable()) { + // FIXME: for remotable operation, only compare name for now + if (!isCompatible(operation, targetOperation, false)) { + if (!silent) { + throw new IncompatibleInterfaceContractException("Target callback operation is not compatible", + source, target, operation, targetOperation); + } else { + return false; + } + } + } + } + return true; + } + + public boolean isCompatible(Interface source, Interface target) { + if (source == target) { + // Shortcut for performance + return true; + } + if (source == null || target == null) { + return false; + } + + if (source.isDynamic() || target.isDynamic()) { + return true; + } + + if (source.isRemotable() != target.isRemotable()) { + return false; + } + if (source.isConversational() != target.isConversational()) { + return false; + } + + for (Operation operation : source.getOperations()) { + Operation targetOperation = getOperation(target.getOperations(), operation.getName()); + if (targetOperation == null) { + return false; + } + if (!isCompatible(operation, targetOperation, source.isRemotable())) { + return false; + } + } + return true; + } + + public boolean isCompatible(InterfaceContract source, InterfaceContract target) { + try { + return checkCompatibility(source, target, false, false); + } catch (IncompatibleInterfaceContractException e) { + return false; + } + } + + /** + * @see org.apache.tuscany.sca.interfacedef.InterfaceContractMapper#map(org.apache.tuscany.sca.interfacedef.Interface, + * org.apache.tuscany.sca.interfacedef.Operation) + */ + public Operation map(Interface target, Operation source) { + // TODO: How to handle the case that source operation is dynamic? + if (target == null || target.isDynamic()) { + return source; + } else if (target.isRemotable()) { + for (Operation op : target.getOperations()) { + if (op.getName().equals(source.getName())) { + return op; + } + } + return null; + } else { + for (Operation op : target.getOperations()) { + if (isCompatible(source, op, target.isRemotable())) { + return op; + } + } + return null; + } + + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java new file mode 100644 index 0000000000..449ca5af9e --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java @@ -0,0 +1,331 @@ +/* + * 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.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a service interface. + * + * @version $Rev$ $Date$ + */ +public class InterfaceImpl implements Interface { + + private boolean remotable; + private boolean conversational; + private OperationList operations = new OperationList(); + private boolean unresolved; + + private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>(); + private IntentAttachPointType type; + private List<PolicySet> policySets = new ArrayList<PolicySet>(); + private List<Intent> requiredIntents = new ArrayList<Intent>(); + + + public boolean isRemotable() { + return remotable; + } + + public void setRemotable(boolean local) { + this.remotable = local; + } + + public List<Operation> getOperations() { + return operations; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + /** + * @return the conversational + */ + public boolean isConversational() { + return conversational; + } + + /** + * @param conversational the conversational to set + */ + public void setConversational(boolean conversational) { + this.conversational = conversational; + } + + private class OperationList extends ArrayList<Operation> { + private static final long serialVersionUID = -903469106307606099L; + + @Override + public Operation set(int index, Operation element) { + element.setInterface(InterfaceImpl.this); + return super.set(index, element); + } + + @Override + public void add(int index, Operation element) { + element.setInterface(InterfaceImpl.this); + super.add(index, element); + } + + @Override + public boolean add(Operation o) { + o.setInterface(InterfaceImpl.this); + return super.add(o); + } + + @Override + public boolean addAll(Collection<? extends Operation> c) { + for (Operation op : c) { + op.setInterface(InterfaceImpl.this); + } + return super.addAll(c); + } + + @Override + public boolean addAll(int index, Collection<? extends Operation> c) { + for (Operation op : c) { + op.setInterface(InterfaceImpl.this); + } + return super.addAll(index, c); + } + + } + + @Deprecated + public void setDefaultDataBinding(String dataBinding) { + for (Operation op : getOperations()) { + if (op.getDataBinding() == null) { + op.setDataBinding(dataBinding); + DataType<List<DataType>> inputType = op.getInputType(); + if (inputType != null) { + for (DataType d : inputType.getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBinding); + } + } + } + DataType outputType = op.getOutputType(); + if (outputType != null && outputType.getDataBinding() == null) { + outputType.setDataBinding(dataBinding); + } + List<DataType> faultTypes = op.getFaultTypes(); + if (faultTypes != null) { + for (DataType d : faultTypes) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBinding); + } + DataType ft = (DataType) d.getLogical(); + if (ft.getDataBinding() == null) { + ft.setDataBinding(dataBinding); + } + + } + } + + if (op.isInputWrapperStyle()) { + WrapperInfo inputWrapperInfo = op.getInputWrapper(); + if (inputWrapperInfo != null) { + DataType<List<DataType>> unwrappedInputType = inputWrapperInfo.getUnwrappedInputType(); + if (unwrappedInputType != null) { + for (DataType d : unwrappedInputType.getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBinding); + } + } + } + } + } + + if (op.isOutputWrapperStyle()) { + WrapperInfo outputWrapperInfo = op.getOutputWrapper(); + if (outputWrapperInfo != null){ + DataType unwrappedOutputType = outputWrapperInfo.getUnwrappedOutputType(); + if (unwrappedOutputType != null && unwrappedOutputType.getDataBinding() == null) { + unwrappedOutputType.setDataBinding(dataBinding); + } + } + } + } + } + } + + private void setDataBinding(DataType dataType, String dataBinding) { + if ("java:array".equals(dataType.getDataBinding())) { + setDataBinding((DataType)dataType.getLogical(), dataBinding); + } else { + dataType.setDataBinding(dataBinding); + } + } + + public void resetInterfaceInputTypes(Interface newInterface){ + for (int i = 0; i < getOperations().size(); i++) { + // only remote interfaces only have a data type model defined + // and in this case operations cannot be overloaded so match + // operations by name + Operation oldOperation = getOperations().get(i); + Operation newOperation = null; + + for (Operation tmpOperation : newInterface.getOperations()){ + if (tmpOperation.getName().equals(oldOperation.getName())){ + newOperation = tmpOperation; + } + } + + if (newOperation == null){ + break; + } + + // set input types + oldOperation.setInputType(newOperation.getInputType()); + + // set wrapper + if (newOperation.isInputWrapperStyle()) { + oldOperation.setInputWrapperStyle(true); + oldOperation.setInputWrapper(newOperation.getInputWrapper()); + } + } + } + + public void resetInterfaceOutputTypes(Interface newInterface){ + for (int i = 0; i < getOperations().size(); i++) { + // only remote interfaces only have a data type model defined + // and in this case operations cannot be overloaded so match + // operations by name + Operation oldOperation = getOperations().get(i); + Operation newOperation = null; + + for (Operation tmpOperation : newInterface.getOperations()){ + if (tmpOperation.getName().equals(oldOperation.getName())){ + newOperation = tmpOperation; + } + } + + if (newOperation == null){ + break; + } + + // set output types + oldOperation.setOutputType(newOperation.getOutputType()); + + // set fault types + oldOperation.setFaultTypes(newOperation.getFaultTypes()); + + // set wrapper + if (newOperation.isOutputWrapperStyle()) { + oldOperation.setOutputWrapperStyle(true); + oldOperation.setOutputWrapper(newOperation.getOutputWrapper()); + } + } + } + + public void resetDataBinding(String dataBinding) { + for (Operation op : getOperations()) { + op.setDataBinding(dataBinding); + DataType<List<DataType>> inputType = op.getInputType(); + if (inputType != null) { + for (DataType d : inputType.getLogical()) { + setDataBinding(d, dataBinding); + } + } + DataType outputType = op.getOutputType(); + if (outputType != null) { + setDataBinding(outputType, dataBinding); + } + List<DataType> faultTypes = op.getFaultTypes(); + if (faultTypes != null) { + for (DataType d : faultTypes) { + setDataBinding(d, dataBinding); + setDataBinding((DataType) d.getLogical(), dataBinding); + } + } + + if (op.isInputWrapperStyle()) { + WrapperInfo inputWrapperInfo = op.getInputWrapper(); + if (inputWrapperInfo != null) { + DataType<List<DataType>> unwrappedInputType = inputWrapperInfo.getUnwrappedInputType(); + if (unwrappedInputType != null) { + for (DataType d : unwrappedInputType.getLogical()) { + setDataBinding(d, dataBinding); + } + } + } + } + + if (op.isOutputWrapperStyle()) { + WrapperInfo outputWrapperInfo = op.getOutputWrapper(); + if (outputWrapperInfo != null){ + DataType unwrappedOutputType = outputWrapperInfo.getUnwrappedOutputType(); + if (unwrappedOutputType != null) { + setDataBinding(unwrappedOutputType, dataBinding); + } + } + } + } + } + + public boolean isDynamic() { + return false; + } + + public List<PolicySet> getApplicablePolicySets() { + return applicablePolicySets; + } + + public List<PolicySet> getPolicySets() { + return policySets; + } + + public List<Intent> getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return type; + } + + public void setType(IntentAttachPointType type) { + this.type = type; + } + + @Override + public Object clone() throws CloneNotSupportedException { + InterfaceImpl copy = (InterfaceImpl)super.clone(); + copy.operations = new OperationList(); + for (Operation operation : this.operations) { + Operation clonedOperation = (Operation)operation.clone(); + copy.operations.add(clonedOperation); + } + return copy; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java new file mode 100644 index 0000000000..5d75db1281 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java @@ -0,0 +1,321 @@ +/* + * 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.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.ParameterMode; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents an operation on a service interface. + * + * @version $Rev$ $Date$ + */ +public class OperationImpl implements Operation { + + private String name; + private boolean unresolved; + private DataType outputType; + private DataType<List<DataType>> inputType; + private List<DataType> faultTypes; + private Interface interfaze; + private ConversationSequence conversationSequence = ConversationSequence.CONVERSATION_NONE; + private List<ParameterMode> parameterModes = new ArrayList<ParameterMode>(); + private boolean nonBlocking; + // TODO - WI + //private WrapperInfo wrapper; + private boolean inputWrapperStyle; + private boolean outputWrapperStyle; + private WrapperInfo inputWrapper; + private WrapperInfo outputWrapper; + private boolean dynamic; + private Map<QName, List<DataType<XMLType>>> faultBeans; + + private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>(); + private List<PolicySet> policySets = new ArrayList<PolicySet>(); + private List<Intent> requiredIntents = new ArrayList<Intent>(); + private IntentAttachPointType type; + + /** + * @param name + */ + public OperationImpl() { + inputType = new DataTypeImpl<List<DataType>>("idl:input", Object[].class, new ArrayList<DataType>()); + faultTypes = new ArrayList<DataType>(); + faultBeans = new HashMap<QName, List<DataType<XMLType>>>(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + /** + * @return the faultTypes + */ + public List<DataType> getFaultTypes() { + return faultTypes; + } + + /** + * @param faultTypes the faultTypes to set + */ + public void setFaultTypes(List<DataType> faultTypes) { + this.faultTypes = faultTypes; + } + + /** + * @return the inputType + */ + public DataType<List<DataType>> getInputType() { + return inputType; + } + + /** + * @param inputType the inputType to set + */ + public void setInputType(DataType<List<DataType>> inputType) { + this.inputType = inputType; + } + + /** + * @return the outputType + */ + public DataType getOutputType() { + return outputType; + } + + /** + * @param outputType the outputType to set + */ + public void setOutputType(DataType outputType) { + this.outputType = outputType; + } + + /** + * @return the interface + */ + public Interface getInterface() { + return interfaze; + } + + /** + * @param interfaze the interface to set + */ + public void setInterface(Interface interfaze) { + this.interfaze = interfaze; + } + + /** + * @return the conversationSequence + */ + public ConversationSequence getConversationSequence() { + return conversationSequence; + } + + /** + * @param conversationSequence the conversationSequence to set + */ + public void setConversationSequence(ConversationSequence conversationSequence) { + this.conversationSequence = conversationSequence; + } + + /** + * @return the nonBlocking + */ + public boolean isNonBlocking() { + return nonBlocking; + } + + /** + * @param nonBlocking the nonBlocking to set + */ + public void setNonBlocking(boolean nonBlocking) { + this.nonBlocking = nonBlocking; + } + + /** + * @return the wrapperInfo + */ + // TODO - WI + //public WrapperInfo getWrapper() { + // return wrapper; + //} + + /** + * @param wrapperInfo the wrapperInfo to set + */ + // TODO - WI + //public void setWrapper(WrapperInfo wrapperInfo) { + // this.wrapper = wrapperInfo; + //} + + public WrapperInfo getInputWrapper() { + return inputWrapper; + } + + public void setInputWrapper(WrapperInfo inputWrapper) { + this.inputWrapper = inputWrapper; + } + + public WrapperInfo getOutputWrapper() { + return outputWrapper; + } + + public void setOutputWrapper(WrapperInfo outputWrapper) { + this.outputWrapper = outputWrapper; + } + + /** + * @return the inputWrapperStyle + */ + public boolean isInputWrapperStyle() { + return inputWrapperStyle; + } + + /** + * @param inputWrapperStyle the wrapperStyle to set + */ + public void setInputWrapperStyle(boolean wrapperStyle) { + this.inputWrapperStyle = wrapperStyle; + } + + /** + * @return the outputWrapperStyle + */ + public boolean isOutputWrapperStyle() { + return outputWrapperStyle; + } + + /** + * @param outputWrapperStyle the wrapperStyle to set + */ + public void setOutputWrapperStyle(boolean wrapperStyle) { + this.outputWrapperStyle = wrapperStyle; + } + + // TODO - WI + // These are deprecated and are a little awkward now that + // we split input wrapper from output wrapper + public String getDataBinding() { + return inputWrapper != null ? inputWrapper.getDataBinding() : null; + } + + public void setDataBinding(String dataBinding) { + if (inputWrapper != null) { + inputWrapper.setDataBinding(dataBinding); + } + if (outputWrapper != null) { + outputWrapper.setDataBinding(dataBinding); + } + } + + public boolean isDynamic() { + return dynamic; + } + + public void setDynamic(boolean b) { + this.dynamic = b; + } + + public Map<QName, List<DataType<XMLType>>> getFaultBeans() { + return faultBeans; + } + + public void setFaultBeans(Map<QName, List<DataType<XMLType>>> faultBeans) { + this.faultBeans = faultBeans; + } + + @Override + public OperationImpl clone() throws CloneNotSupportedException { + OperationImpl copy = (OperationImpl) super.clone(); + + final List<DataType> clonedFaultTypes = new ArrayList<DataType>(this.faultTypes.size()); + for (DataType t : this.faultTypes) { + clonedFaultTypes.add((DataType) t.clone()); + } + copy.faultTypes = clonedFaultTypes; + + List<DataType> clonedLogicalTypes = new ArrayList<DataType>(); + for (DataType t : inputType.getLogical()) { + DataType type = (DataType) t.clone(); + clonedLogicalTypes.add(type); + } + DataType<List<DataType>> clonedInputType = + new DataTypeImpl<List<DataType>>(inputType.getPhysical(), clonedLogicalTypes); + clonedInputType.setDataBinding(inputType.getDataBinding()); + copy.inputType = clonedInputType; + + if (this.outputType != null) { + copy.outputType = (DataType) this.outputType.clone(); + } + + return copy; + } + + public List<PolicySet> getApplicablePolicySets() { + return applicablePolicySets; + } + + public List<PolicySet> getPolicySets() { + return policySets; + } + + public List<Intent> getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return type; + } + + public void setType(IntentAttachPointType type) { + this.type = type; + } + + public List<ParameterMode> getParameterModes() { + return parameterModes; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java new file mode 100644 index 0000000000..777fa567f1 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java @@ -0,0 +1,114 @@ +/* + * 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.util; + +import javax.xml.namespace.QName; + +/** + * An abstraction of XML schema elements. + * + * @version $Rev$ $Date$ + */ +public class ElementInfo { + private final QName name; + private final TypeInfo type; + private boolean many = false; + private boolean nillable = false; + + /** + * @param name + * @param type + */ + public ElementInfo(QName name, TypeInfo type) { + super(); + this.name = name; + this.type = type; + } + + /** + * @return the name + */ + public QName getQName() { + return name; + } + + /** + * @return the type + */ + public TypeInfo getType() { + return type; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("Element: ").append(name).append(" ").append(type); + return sb.toString(); + } + + public boolean isMany() { + return many; + } + + public void setMany(boolean many) { + this.many = many; + } + + public boolean isNillable() { + return nillable; + } + + public void setNillable(boolean nillable) { + this.nillable = nillable; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final ElementInfo other = (ElementInfo)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + /* + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + */ + return true; + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java new file mode 100644 index 0000000000..844b0af509 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java @@ -0,0 +1,82 @@ +/* + * 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.util; + +import javax.xml.namespace.QName; + +/** + * The generic java exception to wrap service faults + * + * @version $Rev$ $Date$ + */ +public class FaultException extends Exception { + private static final long serialVersionUID = -8002583655240625792L; + private transient Object faultInfo; // FIXME: How to serialize it? + private QName faultName; + + /** + * @param message + * @param faultInfo + */ + public FaultException(String message, Object faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param message + * @param faultInfo + * @param cause + */ + public FaultException(String message, Object faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return the faultInfo + */ + public Object getFaultInfo() { + return faultInfo; + } + + public QName getFaultName() { + return faultName; + } + + public void setFaultName(QName logical) { + this.faultName = logical; + } + + public boolean isMatchingType(Object type) { + if (faultName == null) { + return false; + } + + if ((type instanceof QName) && faultName.equals(type)) { + return true; + } + if (type instanceof XMLType && faultName.equals(((XMLType)type).getElementName())) { + return true; + } + return false; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java new file mode 100644 index 0000000000..54c0a3ec11 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java @@ -0,0 +1,143 @@ +/* + * 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.util; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +/** + * Utility class that can be used to map XSD types to Java classes and Java classes to XSD types. + * + * @version $Rev$ $Date$ + */ +public final class JavaXMLMapper { + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + private static final Map<Class, QName> JAVA2XML = new HashMap<Class, QName>(); + private static final Map<String, Class> XML2JAVA = new HashMap<String, Class>(); + + private JavaXMLMapper() { + } + + static { + JAVA2XML.put(boolean.class, getTypeName("boolean")); + JAVA2XML.put(byte.class, getTypeName("byte")); + JAVA2XML.put(short.class, getTypeName("short")); + JAVA2XML.put(int.class, getTypeName("int")); + JAVA2XML.put(long.class, getTypeName("long")); + JAVA2XML.put(float.class, getTypeName("float")); + JAVA2XML.put(double.class, getTypeName("double")); + JAVA2XML.put(Boolean.class, getTypeName("boolean")); + JAVA2XML.put(Byte.class, getTypeName("byte")); + JAVA2XML.put(Short.class, getTypeName("short")); + JAVA2XML.put(Integer.class, getTypeName("int")); + JAVA2XML.put(Long.class, getTypeName("long")); + JAVA2XML.put(Float.class, getTypeName("float")); + JAVA2XML.put(Double.class, getTypeName("double")); + JAVA2XML.put(java.lang.String.class, getTypeName("string")); + JAVA2XML.put(java.math.BigInteger.class, getTypeName("integer")); + JAVA2XML.put(java.math.BigDecimal.class, getTypeName("decimal")); + JAVA2XML.put(java.util.Calendar.class, getTypeName("dateTime")); + JAVA2XML.put(java.util.Date.class, getTypeName("dateTime")); + JAVA2XML.put(javax.xml.namespace.QName.class, getTypeName("QName")); + JAVA2XML.put(java.net.URI.class, getTypeName("string")); + JAVA2XML.put(javax.xml.datatype.XMLGregorianCalendar.class, getTypeName("anySimpleType")); + JAVA2XML.put(javax.xml.datatype.Duration.class, getTypeName("duration")); + JAVA2XML.put(java.lang.Object.class, getTypeName("anyType")); + JAVA2XML.put(java.awt.Image.class, getTypeName("base64Binary")); + JAVA2XML.put(byte[].class, getTypeName("base64Binary")); + // java2XSD.put(javax.activation.DataHandler.class, getTypeName("base64Binary")); + JAVA2XML.put(javax.xml.transform.Source.class, getTypeName("base64Binary")); + JAVA2XML.put(java.util.UUID.class, getTypeName("string")); + } + + static { + XML2JAVA.put("string", java.lang.String.class); + XML2JAVA.put("integer", java.math.BigInteger.class); + XML2JAVA.put("int", int.class); + XML2JAVA.put("long", long.class); + XML2JAVA.put("short", short.class); + XML2JAVA.put("decimal", java.math.BigDecimal.class); + XML2JAVA.put("float", float.class); + XML2JAVA.put("double", double.class); + XML2JAVA.put("boolean", boolean.class); + XML2JAVA.put("byte", byte.class); + XML2JAVA.put("QName", javax.xml.namespace.QName.class); + XML2JAVA.put("dateTime", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("base64Binary", byte[].class); + XML2JAVA.put("hexBinary", byte[].class); + XML2JAVA.put("unsignedInt", long.class); + XML2JAVA.put("unsignedShort", int.class); + XML2JAVA.put("unsignedByte", short.class); + XML2JAVA.put("time", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("date", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gDay", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gMonth", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gYear", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gYearMonth", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gMonthDay", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("anySimpleType", java.lang.Object.class); // For elements + // XML2JAVA.put("anySimpleType", java.lang.String.class); // For + // attributes + XML2JAVA.put("duration", javax.xml.datatype.Duration.class); + XML2JAVA.put("NOTATION", javax.xml.namespace.QName.class); + } + + public static Class getJavaType(QName xmlType) { + if (URI_2001_SCHEMA_XSD.equals(xmlType.getNamespaceURI())) { + return XML2JAVA.get(xmlType.getLocalPart()); + } else { + return null; + } + } + + private static QName getTypeName(String name) { + return new QName(URI_2001_SCHEMA_XSD, name); + } + + public static QName getXMLType(Class javaType) { + return JAVA2XML.get(javaType); + } + + private static String getPackageName(Class<?> cls) { + String name = cls.getName(); + int index = name.lastIndexOf('.'); + return index == -1 ? "" : name.substring(0, index); + } + + public static String getNamespace(Class<?> cls) { + String packageName = getPackageName(cls); + if ("".equals(packageName)) { + return ""; + } + StringBuffer ns = new StringBuffer("http://"); + String[] names = packageName.split("\\."); + for (int i = names.length - 1; i >= 0; i--) { + ns.append(names[i]); + if (i != 0) { + ns.append('.'); + } + } + ns.append('/'); + return ns.toString(); + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java new file mode 100644 index 0000000000..2598dc8545 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java @@ -0,0 +1,100 @@ +/* + * 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.util; + +import javax.xml.namespace.QName; + +/** + * An abstraction of XML schema types + * + * @version $Rev$ $Date$ + */ +public class TypeInfo { + private QName name; + + private boolean isSimpleType; + + private TypeInfo baseType; + + /** + * @param name + * @param isSimpleType + */ + public TypeInfo(QName name, boolean isSimpleType, TypeInfo baseType) { + super(); + this.name = name; + this.isSimpleType = isSimpleType; + this.baseType = baseType; + } + + /** + * @return the isSimpleType + */ + public boolean isSimpleType() { + return isSimpleType; + } + + /** + * @return the name + */ + public QName getQName() { + return name; + } + + /** + * @return the baseType + */ + public TypeInfo getBaseType() { + return baseType; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("Type: ").append(name); + return sb.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final TypeInfo other = (TypeInfo)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java new file mode 100644 index 0000000000..b5a7915a11 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java @@ -0,0 +1,140 @@ +/* + * 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.util; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * The "Wrapper Style" WSDL operation is defined by The Java API for XML-Based + * Web Services (JAX-WS) 2.0 specification, section 2.3.1.2 Wrapper Style. <p/> + * A WSDL operation qualifies for wrapper style mapping only if the following + * criteria are met: + * <ul> + * <li>(i) The operation is input and output messages (if present) each contain + * only a single part + * <li>(ii) The input message part refers to a global element declaration whose + * localname is equal to the operation name + * <li>(iii) The output message part refers to a global element declaration + * <li>(iv) The elements referred to by the input and output message parts + * (henceforth referred to as wrapper elements) are both complex types defined + * using the xsd:sequence compositor + * <li>(v) The wrapper elements only contain child elements, they must not + * contain other structures such as wildcards (element or attribute), + * xsd:choice, substitution groups (element references are not permitted) or + * attributes; furthermore, they must not be nillable. + * </ul> + * + * @version $Rev$ $Date$ + */ +public class WrapperInfo { + private String dataBinding; + private ElementInfo wrapperElement; + private List<ElementInfo> childElements; + private DataType<XMLType> wrapperType; + + // A cache for the derived data type of the unwrapped + // input child elements + private DataType<List<DataType>> unwrappedInputType; + + // A cache for the derived data type of the unwrapped + // output child element (we only support one child) + private DataType<XMLType> unwrappedOutputType; + + public WrapperInfo(String dataBinding, + ElementInfo wrapperElement, + List<ElementInfo> childElements) { + super(); + this.dataBinding = dataBinding; + this.wrapperElement = wrapperElement; + this.childElements = childElements; + } + + public List<ElementInfo> getChildElements() { + return childElements; + } + + public ElementInfo getWrapperElement() { + return wrapperElement; + } + + public String getDataBinding() { + return dataBinding; + } + + public void setDataBinding(String dataBinding) { + this.dataBinding = dataBinding; + } + + public DataType<XMLType> getWrapperType() { + return wrapperType; + } + + public void setWrapperType(DataType<XMLType> wrapperType) { + this.wrapperType = wrapperType; + } + + public Class<?> getWrapperClass() { + return wrapperType == null ? null : wrapperType.getPhysical(); + } + + + public DataType<List<DataType>> getUnwrappedInputType() { + if (unwrappedInputType == null) { + List<DataType> childTypes = new ArrayList<DataType>(); + for (ElementInfo element : getChildElements()) { + DataType type = getDataType(element); + childTypes.add(type); + } + unwrappedInputType = new DataTypeImpl<List<DataType>>("idl:unwrapped.input", Object[].class, childTypes); + } + return unwrappedInputType; + } + + public DataType getUnwrappedOutputType() { + if (unwrappedOutputType == null) { + List<ElementInfo> elements = getChildElements(); + if (elements != null && elements.size() > 0) { + if (elements.size() > 1) { + // We don't support output with multiple parts + // throw new IllegalArgumentException("Multi-part output is not supported"); + } + ElementInfo element = elements.get(0); + + unwrappedOutputType = getDataType(element); + } + } + return unwrappedOutputType; + } + + private DataType getDataType(ElementInfo element) { + DataType type = null; + if (element.isMany()) { + DataType logical = new DataTypeImpl<XMLType>(dataBinding, Object.class, new XMLType(element)); + type = new DataTypeImpl<DataType>("java:array", Object[].class, logical); + } else { + type = new DataTypeImpl<XMLType>(dataBinding, Object.class, new XMLType(element)); + } + return type; + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java new file mode 100644 index 0000000000..26ecf6e352 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java @@ -0,0 +1,152 @@ +/* + * 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.util; + +import javax.xml.namespace.QName; + +/** + * The metadata for an XML element or type. + * + * @version $Rev$ $Date$ + */ +public class XMLType { + public static final XMLType UNKNOWN = new XMLType(null, null); + protected QName element; + protected QName type; + protected boolean nillable = true; + protected boolean many = false; + + /** + * @param element + */ + public XMLType(ElementInfo element) { + super(); + this.element = element.getQName(); + if (element.getType() != null) { + this.type = element.getType().getQName(); + } + } + + /** + * @param element + */ + public XMLType(TypeInfo type) { + this.element = null; + this.type = type.getQName(); + } + + public XMLType(QName element, QName type) { + this.element = element; + this.type = type; + } + + /** + * @return the type + */ + public QName getTypeName() { + return type; + } + + public boolean isElement() { + return element != null; + } + + public QName getElementName() { + return element; + } + + public void setElementName(QName element) { + this.element = element; + } + + public void setTypeName(QName type) { + this.type = type; + } + + public static XMLType getType(QName type) { + return new XMLType(null, type); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((element == null) ? 0 : element.hashCode()); + result = PRIME * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final XMLType other = (XMLType)obj; + if (element == null) { + if (other.element != null) { + return false; + } + } else if (!element.equals(other.element)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Element: " + element + " Type: " + type; + } + + public boolean isNillable() { + return nillable; + } + + public void setNillable(boolean niable) { + this.nillable = niable; + } + + public boolean isMany() { + return many; + } + + public void setMany(boolean many) { + this.many = many; + } + +} diff --git a/sca-java-1.x/trunk/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper b/sca-java-1.x/trunk/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper new file mode 100644 index 0000000000..821c58bde1 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper @@ -0,0 +1,18 @@ +# 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.impl.InterfaceContractMapperImpl
diff --git a/sca-java-1.x/trunk/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java b/sca-java-1.x/trunk/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java new file mode 100644 index 0000000000..269a3dc038 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java @@ -0,0 +1,380 @@ +/* + * 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.impl; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * TODO some tests commented out due to DataType.equals() needing to be strict + * + * @version $Rev$ $Date$ + */ +public class ContractCompatibilityTestCase extends TestCase { + + private InterfaceContractMapper mapper; + + @Override + protected void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + mapper = utilities.getUtility(InterfaceContractMapper.class); + } + + public void testNoOperation() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + InterfaceContract target = new MockContract("FooContract"); + mapper.checkCompatibility(source, target, false, false); + } + + public void testBasic() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + Operation opSource1 = newOperation("op1"); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + InterfaceContract target = new MockContract("FooContract"); + Operation opSource2 = newOperation("op1"); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opSource2); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + public void testBasicIncompatibleOperationNames() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + Operation opSource1 = newOperation("op1"); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + InterfaceContract target = new MockContract("FooContract"); + Operation opSource2 = newOperation("op2"); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op2", opSource2); + target.getInterface().getOperations().addAll(targetOperations.values()); + try { + mapper.checkCompatibility(source, target, false, false); + fail(); + } catch (IncompatibleInterfaceContractException e) { + // expected + } + } + + public void testInputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + List<DataType> sourceInputTypes = new ArrayList<DataType>(); + sourceInputTypes.add(new DataTypeImpl<Type>(Object.class, Object.class)); + DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(String.class, sourceInputTypes); + Operation opSource1 = newOperation("op1"); + opSource1.setInputType(inputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + List<DataType> targetInputTypes = new ArrayList<DataType>(); + targetInputTypes.add(new DataTypeImpl<Type>(Object.class, Object.class)); + DataType<List<DataType>> targetInputType = new DataTypeImpl<List<DataType>>(String.class, targetInputTypes); + + Operation opTarget = newOperation("op1"); + opTarget.setInputType(targetInputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + public void testIncompatibleInputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + List<DataType> sourceInputTypes = new ArrayList<DataType>(); + sourceInputTypes.add(new DataTypeImpl<Type>(Integer.class, Integer.class)); + DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(String.class, sourceInputTypes); + Operation opSource1 = newOperation("op1"); + opSource1.setInputType(inputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + List<DataType> targetInputTypes = new ArrayList<DataType>(); + targetInputTypes.add(new DataTypeImpl<Type>(String.class, String.class)); + DataType<List<DataType>> targetInputType = new DataTypeImpl<List<DataType>>(String.class, targetInputTypes); + + Operation opTarget = newOperation("op1"); + opTarget.setInputType(targetInputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + try { + mapper.checkCompatibility(source, target, false, false); + fail(); + } catch (IncompatibleInterfaceContractException e) { + // expected + } + } + + /** + * Verfies source input types can be super types of the target + */ + public void testSourceSuperTypeInputCompatibility() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // List<DataType> sourceInputTypes = new ArrayList<DataType>(); + // sourceInputTypes.add(new DataTypeImpl<Type>(Object.class, + // Object.class)); + // DataType<List<DataType>> inputType = new + // DataTypeImpl<List<DataType>>(String.class, sourceInputTypes); + // Operation opSource1 = newOperationImpl("op1", inputType, null, null, + // false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // List<DataType> targetInputTypes = new ArrayList<DataType>(); + // targetInputTypes.add(new DataTypeImpl<Type>(String.class, + // String.class)); + // DataType<List<DataType>> targetInputType = + // new DataTypeImpl<List<DataType>>(String.class, targetInputTypes); + // + // Operation opTarget = newOperationImpl("op1", targetInputType, null, + // null, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + public void testOutputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class); + Operation opSource1 = newOperation("op1"); + opSource1.setOutputType(sourceOutputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + DataType targetOutputType = new DataTypeImpl<Type>(String.class, String.class); + Operation opTarget = newOperation("op1"); + opTarget.setOutputType(targetOutputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + /** + * Verifies a return type that is a supertype of of the target is compatible + */ + public void testSupertypeOutputTypes() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // DataType sourceOutputType = new DataTypeImpl<Type>(Object.class, + // Object.class); + // Operation opSource1 = newOperationImpl("op1", null, + // sourceOutputType, null, false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // DataType targetOutputType = new DataTypeImpl<Type>(String.class, + // String.class); + // Operation opTarget = newOperationImpl("op1", null, targetOutputType, + // null, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + public void testIncompatibleOutputTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class); + Operation opSource1 = newOperation("op1"); + opSource1.setOutputType(sourceOutputType); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + DataType targetOutputType = new DataTypeImpl<Type>(Integer.class, Integer.class); + Operation opTarget = newOperation("op1"); + opTarget.setOutputType(targetOutputType); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + try { + mapper.checkCompatibility(source, target, false, false); + fail(); + } catch (IncompatibleInterfaceContractException e) { + // expected + } + } + + public void testFaultTypes() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class); + List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + sourceFaultTypes.add(0, sourceFaultType); + Operation opSource1 = newOperation("op1"); + opSource1.setFaultTypes(sourceFaultTypes); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + DataType targetFaultType = new DataTypeImpl<Type>(String.class, String.class); + List<DataType> targetFaultTypes = new ArrayList<DataType>(); + targetFaultTypes.add(0, targetFaultType); + + Operation opTarget = newOperation("op1"); + opTarget.setFaultTypes(targetFaultTypes); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + public void testSourceFaultTargetNoFaultCompatibility() throws Exception { + InterfaceContract source = new MockContract("FooContract"); + DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class); + List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + sourceFaultTypes.add(0, sourceFaultType); + Operation opSource1 = newOperation("op1"); + opSource1.setFaultTypes(sourceFaultTypes); + Map<String, Operation> sourceOperations = new HashMap<String, Operation>(); + sourceOperations.put("op1", opSource1); + source.getInterface().getOperations().addAll(sourceOperations.values()); + + InterfaceContract target = new MockContract("FooContract"); + Operation opTarget = newOperation("op1"); + Map<String, Operation> targetOperations = new HashMap<String, Operation>(); + targetOperations.put("op1", opTarget); + target.getInterface().getOperations().addAll(targetOperations.values()); + mapper.checkCompatibility(source, target, false, false); + } + + /** + * Verifies a source's fault which is a supertype of the target's fault are + * compatible + * + * @throws Exception + */ + public void testFaultSuperTypes() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // DataType sourceFaultType = new DataTypeImpl<Type>(Exception.class, + // Exception.class); + // List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + // sourceFaultTypes.add(0, sourceFaultType); + // Operation opSource1 = newOperationImpl("op1", null, null, + // sourceFaultTypes, false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // DataType targetFaultType = new + // DataTypeImpl<Type>(TuscanyException.class, TuscanyException.class); + // List<DataType> targetFaultTypes = new ArrayList<DataType>(); + // targetFaultTypes.add(0, targetFaultType); + // + // Operation opTarget = newOperationImpl("op1", null, null, + // targetFaultTypes, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + /** + * Verifies a source's faults which are supertypes and a superset of the + * target's faults are compatible + */ + public void testFaultSuperTypesAndSuperset() throws Exception { + // InterfaceContract source = new MockContract("FooContract"); + // DataType sourceFaultType = new DataTypeImpl<Type>(Exception.class, + // Exception.class); + // DataType sourceFaultType2 = new + // DataTypeImpl<Type>(RuntimeException.class, RuntimeException.class); + // List<DataType> sourceFaultTypes = new ArrayList<DataType>(); + // sourceFaultTypes.add(0, sourceFaultType); + // sourceFaultTypes.add(1, sourceFaultType2); + // Operation opSource1 = newOperationImpl("op1", null, null, + // sourceFaultTypes, false, null); + // Map<String, Operation> sourceOperations = new HashMap<String, + // Operation>(); + // sourceOperations.put("op1", opSource1); + // source.getInterface().getOperations().addAll(sourceOperations.values()); + // + // InterfaceContract target = new MockContract("FooContract"); + // DataType targetFaultType = new + // DataTypeImpl<Type>(TuscanyException.class, TuscanyException.class); + // List<DataType> targetFaultTypes = new ArrayList<DataType>(); + // targetFaultTypes.add(0, targetFaultType); + // + // Operation opTarget = newOperationImpl("op1", null, null, + // targetFaultTypes, false, null); + // Map<String, Operation> targetOperations = new HashMap<String, + // Operation>(); + // targetOperations.put("op1", opTarget); + // target.getInterface().getOperations().addAll(targetOperations.values()); + // wireService.checkCompatibility(source, target, false); + } + + private static class MockInterface extends InterfaceImpl { + + } + + private class MockContract<T> extends InterfaceContractImpl { + public MockContract() { + } + + public MockContract(String interfaceClass) { + Interface jInterface = new MockInterface(); + setInterface(jInterface); + } + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/sca-java-1.x/trunk/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java b/sca-java-1.x/trunk/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java new file mode 100644 index 0000000000..12bb09eb95 --- /dev/null +++ b/sca-java-1.x/trunk/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java @@ -0,0 +1,71 @@ +/* + * 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.impl; + + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.junit.Before; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class InterfaceContractTestCase { + private InterfaceContract contract; + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + contract = new MockInterfaceContract(); + Interface i1 = new MockInterface(); + contract.setInterface(i1); + Operation op1 = newOperation("op1"); + i1.getOperations().add(op1); + Interface i2 = new MockInterface(); + contract.setCallbackInterface(i2); + Operation callbackOp1 = newOperation("callbackOp1"); + i2.getOperations().add(callbackOp1); + } + + @Test + public void testClone() throws Exception { + InterfaceContract copy = (InterfaceContract) contract.clone(); + Assert.assertNotNull(copy); + Assert.assertNotSame(copy.getCallbackInterface(), contract.getCallbackInterface()); + Assert.assertNotSame(copy.getInterface(), contract.getInterface()); + } + + private static class MockInterfaceContract extends InterfaceContractImpl implements InterfaceContract { + } + + private static class MockInterface extends InterfaceImpl implements Interface { + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} |