You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/04/12 01:50:23 UTC

svn commit: r527726 [2/2] - in /incubator/tuscany/java/sca/modules: ./ core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/ core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/ core-databinding/src/m...

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCaseFIXME.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCaseFIXME.java?view=diff&rev=527726&r1=527725&r2=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCaseFIXME.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCaseFIXME.java Wed Apr 11 16:50:20 2007
@@ -39,7 +39,7 @@
         Wire wire = new WireImpl();
         wire.setSourceUri(uri);
         Contract contract = new DefaultAssemblyFactory().createComponentReference();
-        wire.setSourceContract(contract);
+        wire.setSourceContract(contract.getInterfaceContract());
         TestInterface proxy = proxyService.createProxy(TestInterface.class, wire);
         assertTrue(Proxy.isProxyClass(proxy.getClass()));
     }

Modified: incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/interfacedef/java/impl/JavaInterfaceUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/interfacedef/java/impl/JavaInterfaceUtil.java?view=diff&rev=527726&r1=527725&r2=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/interfacedef/java/impl/JavaInterfaceUtil.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/interfacedef/java/impl/JavaInterfaceUtil.java Wed Apr 11 16:50:20 2007
@@ -27,9 +27,10 @@
 import org.apache.tuscany.interfacedef.Operation;
 
 /**
- * Contains methods for mapping between an operation in a {@link org.apache.tuscany.spi.model.ServiceContract} and a
- * method defined by a Java interface
- *
+ * Contains methods for mapping between an operation in a
+ * {@link org.apache.tuscany.spi.model.ServiceContract} and a method defined by
+ * a Java interface
+ * 
  * @version $Rev$ $Date$
  */
 public final class JavaInterfaceUtil {
@@ -39,7 +40,7 @@
 
     /**
      * Return the method on the implementation class that matches the operation.
-     *
+     * 
      * @param implClass the implementation class or interface
      * @param operation the operation to match
      * @return the method described by the operation
@@ -57,6 +58,9 @@
      */
     private static  Class<?>[] getPhysicalTypes(Operation operation) {
         DataType<List<DataType>> inputType = operation.getInputType();
+        if(inputType==null) {
+            return new Class<?>[] {};
+        }
         List<DataType> types = inputType.getLogical();
         Class<?>[] javaTypes = new Class<?>[types.size()];
         for (int i = 0; i < javaTypes.length; i++) {
@@ -72,8 +76,8 @@
 
     /**
      * Searches a collection of operations for a match against the given method
-     *
-     * @param method     the method to match
+     * 
+     * @param method the method to match
      * @param operations the operations to match against
      * @return a matching operation or null
      * @Deprecated
@@ -89,7 +93,7 @@
 
     /**
      * Determines if the given operation matches the given method
-     *
+     * 
      * @return true if the operation matches, false if does not
      */
     private static  boolean match(Operation operation, Method method) {

Added: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/IncompatibleInterfaceContractException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/IncompatibleInterfaceContractException.java?view=auto&rev=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/IncompatibleInterfaceContractException.java (added)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/IncompatibleInterfaceContractException.java Wed Apr 11 16:50:20 2007
@@ -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.interfacedef;
+
+/**
+ * Denotes imcompatible 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;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/IncompatibleInterfaceContractException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/IncompatibleInterfaceContractException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/InterfaceContractMapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/InterfaceContractMapper.java?view=auto&rev=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/InterfaceContractMapper.java (added)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/InterfaceContractMapper.java Wed Apr 11 16:50:20 2007
@@ -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.interfacedef;
+
+/**
+ * The InterfaceContractMapper is responsible to match interfaces
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface InterfaceContractMapper {
+    /**
+     * Check the compatiblity 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 symetric: 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);
+}

Propchange: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/InterfaceContractMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/InterfaceContractMapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/Operation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/Operation.java?view=diff&rev=527726&r1=527725&r2=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/Operation.java (original)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/Operation.java Wed Apr 11 16:50:20 2007
@@ -20,6 +20,8 @@
 
 import java.util.List;
 
+import org.apache.tuscany.interfacedef.util.WrapperInfo;
+
 /**
  * Represents an operation on a service interface.
  */
@@ -118,5 +120,26 @@
      * Set the operation to be non-blocking
      */
     void setNonBlocking(boolean nonBlocking);
+    
+    /**
+     * @return the wrapperInfo
+     */
+    WrapperInfo getWrapper();
+
+    /**
+     * @param wrapperInfo the wrapperInfo to set
+     */
+    void setWrapper(WrapperInfo wrapperInfo);
+
+    /**
+     * @return the wrapperStyle
+     */
+    boolean isWrapperStyle();
+
+    /**
+     * @param wrapperStyle the wrapperStyle to set
+     */
+    void setWrapperStyle(boolean wrapperStyle);
+    
 
 }

Added: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/DefaultInterfaceContractMapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/DefaultInterfaceContractMapper.java?view=auto&rev=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/DefaultInterfaceContractMapper.java (added)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/DefaultInterfaceContractMapper.java Wed Apr 11 16:50:20 2007
@@ -0,0 +1,250 @@
+/*
+ * 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.interfacedef.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.interfacedef.DataType;
+import org.apache.tuscany.interfacedef.IncompatibleInterfaceContractException;
+import org.apache.tuscany.interfacedef.Interface;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.interfacedef.Operation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultInterfaceContractMapper implements InterfaceContractMapper {
+
+    public boolean isCompatible(DataType source, DataType target, boolean remotable) {
+        if (source == target) {
+            return true;
+        }
+        if (!remotable) {
+            // For local case
+            return target.getPhysical() == source.getPhysical();
+        } else {
+            return target.getLogical().equals(source.getLogical());
+        }
+
+    }
+
+    public boolean isCompatible(Operation source, Operation target, boolean remotable) {
+        if (source == target) {
+            return true;
+        }
+
+        // Check name
+        if (!source.getName().equals(target.getName())) {
+            return false;
+        }
+
+        // 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;
+        }
+
+        List<DataType> sourceInputType = source.getInputType().getLogical();
+        List<DataType> targetInputType = target.getInputType().getLogical();
+
+        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 = false;
+            for (DataType sourceFaultType : source.getFaultTypes()) {
+                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().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 = getOperation(target.getInterface().getOperations(), operation.getName());
+            if (targetOperation == null) {
+                if (!silent) {
+                    throw new IncompatibleInterfaceContractException("Operation not found on target", source, target);
+                } else {
+                    return false;
+                }
+            }
+            if (!operation.equals(targetOperation)) {
+                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 = getOperation(target.getCallbackInterface().getOperations(), operation.getName());
+            if (targetOperation == null) {
+                if (!silent) {
+                    throw new IncompatibleInterfaceContractException("Callback operation not found on target", source,
+                                                                     target, null, targetOperation);
+                } else {
+                    return false;
+                }
+            }
+            if (!operation.equals(targetOperation)) {
+                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.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 (!operation.equals(targetOperation)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public boolean isCompatible(InterfaceContract source, InterfaceContract target) {
+        try {
+            return checkCompatibility(source, target, false, true);
+        } catch (IncompatibleInterfaceContractException e) {
+            return false;
+        }
+    }
+
+    /**
+     * @see org.apache.tuscany.interfacedef.InterfaceContractMapper#map(org.apache.tuscany.interfacedef.Interface,
+     *      org.apache.tuscany.interfacedef.Operation)
+     */
+    public Operation map(Interface target, Operation source) {
+        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;
+        }
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/DefaultInterfaceContractMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/DefaultInterfaceContractMapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/OperationImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/OperationImpl.java?view=diff&rev=527726&r1=527725&r2=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/OperationImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/interfacedef/impl/OperationImpl.java Wed Apr 11 16:50:20 2007
@@ -23,6 +23,7 @@
 import org.apache.tuscany.interfacedef.DataType;
 import org.apache.tuscany.interfacedef.Interface;
 import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.util.WrapperInfo;
 
 /**
  * Represents an operation on a service interface.
@@ -39,6 +40,9 @@
     private Interface interfaze;
     private ConversationSequence conversationSequence = ConversationSequence.NO_CONVERSATION;
     private boolean nonBlocking;
+    private boolean wrapperStyle;
+    private WrapperInfo wrapper;
+    
 
     /**
      * @param name
@@ -227,6 +231,34 @@
             return false;
         }
         return true;
+    }
+
+    /**
+     * @return the wrapperInfo
+     */
+    public WrapperInfo getWrapper() {
+        return wrapper;
+    }
+
+    /**
+     * @param wrapperInfo the wrapperInfo to set
+     */
+    public void setWrapper(WrapperInfo wrapperInfo) {
+        this.wrapper = wrapperInfo;
+    }
+
+    /**
+     * @return the wrapperStyle
+     */
+    public boolean isWrapperStyle() {
+        return wrapperStyle;
+    }
+
+    /**
+     * @param wrapperStyle the wrapperStyle to set
+     */
+    public void setWrapperStyle(boolean wrapperStyle) {
+        this.wrapperStyle = wrapperStyle;
     }
 
 }

Added: incubator/tuscany/java/sca/modules/interface/src/test/java/org/apache/tuscany/interfacedef/impl/ContractCompatibilityTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/test/java/org/apache/tuscany/interfacedef/impl/ContractCompatibilityTestCase.java?view=auto&rev=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/test/java/org/apache/tuscany/interfacedef/impl/ContractCompatibilityTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/interface/src/test/java/org/apache/tuscany/interfacedef/impl/ContractCompatibilityTestCase.java Wed Apr 11 16:50:20 2007
@@ -0,0 +1,366 @@
+/*
+ * 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.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.interfacedef.DataType;
+import org.apache.tuscany.interfacedef.IncompatibleInterfaceContractException;
+import org.apache.tuscany.interfacedef.Interface;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.interfacedef.Operation;
+
+/**
+ * TODO some tests commented out due to DataType.equals() needing to be strict
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ContractCompatibilityTestCase extends TestCase {
+    private static final Operation.ConversationSequence NO_CONVERSATION = Operation.ConversationSequence.NO_CONVERSATION;
+    private InterfaceContractMapper mapper = new DefaultInterfaceContractMapper();
+
+    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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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);
+    }
+
+    /**
+     * Verfies 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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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 = new OperationImpl("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
+     * compatibile
+     * 
+     * @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 = new OperationImpl("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 = new OperationImpl("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 compatibile
+     */
+    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 = new OperationImpl("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 = new OperationImpl("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();
+            jInterface.setUnresolved(true);
+            setInterface(jInterface);
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/interface/src/test/java/org/apache/tuscany/interfacedef/impl/ContractCompatibilityTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/interface/src/test/java/org/apache/tuscany/interfacedef/impl/ContractCompatibilityTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/pom.xml?view=diff&rev=527726&r1=527725&r2=527726
==============================================================================
--- incubator/tuscany/java/sca/modules/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/pom.xml Wed Apr 11 16:50:20 2007
@@ -54,6 +54,7 @@
                 <module>core-spring</module>
                 <module>databinding</module>
                 <module>databinding-axiom</module>
+                <module>core-databinding</module>
                 <!--
                 <module>databinding-jaxb</module>
                 <module>databinding-sdo</module>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org