Author: jboynes
Date: Tue Nov 28 19:55:05 2006
New Revision: 480385
URL: http://svn.apache.org/viewvc?view=rev&rev=480385
Log:
TUSCANY-862 add method to WireService to generate proxy for a source-side
interface
Added:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
(with props)
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java?view=diff&rev=480385&r1=480384&r2=480385
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
Tue Nov 28 19:55:05 2006
@@ -146,6 +146,7 @@
private void init(InboundWire wire) {
this.chains = new HashMap<Method, ChainHolder>();
+ // FIXME: TUSCANY-862 we cannot assume there is a Java interface class
Class<?> interfaze = wire.getServiceContract().getInterfaceClass();
Method[] methods = interfaze.getMethods();
Map<Method, InboundInvocationChain> invocationChains =
WireUtils.createInboundMapping(wire, methods);
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?view=diff&rev=480385&r1=480384&r2=480385
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
Tue Nov 28 19:55:05 2006
@@ -81,6 +81,12 @@
public void init() {
}
+ public <T> T createProxy(Class<T> interfaze, InboundWire wire) throws
ProxyCreationException {
+ JDKInboundInvocationHandler handler = new
JDKInboundInvocationHandler(wire, context);
+ ClassLoader cl = interfaze.getClassLoader();
+ return interfaze.cast(Proxy.newProxyInstance(cl, new
Class[]{interfaze}, handler));
+ }
+
public Object createProxy(RuntimeWire wire) throws ProxyCreationException {
assert wire != null : "Wire was null";
if (wire instanceof InboundWire) {
Added:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java?view=auto&rev=480385
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
Tue Nov 28 19:55:05 2006
@@ -0,0 +1,64 @@
+/*
+ * 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.core.wire.jdk;
+
+import java.util.HashMap;
+import java.lang.reflect.Proxy;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKProxyTestCase extends TestCase {
+ private JDKWireService wireService;
+ private JavaServiceContract serviceContract;
+ private InboundWire inboundWire;
+ private HashMap<Operation<?>,InboundInvocationChain> chains;
+
+ public void testCreateProxy() {
+ EasyMock.expect(inboundWire.getServiceName()).andReturn("service");
+
EasyMock.expect(inboundWire.getServiceContract()).andReturn(serviceContract);
+ EasyMock.expect(inboundWire.getInvocationChains()).andReturn(chains);
+ EasyMock.replay(inboundWire);
+ TestInterface intf = wireService.createProxy(TestInterface.class,
inboundWire);
+ assertTrue(Proxy.isProxyClass(intf.getClass()));
+ EasyMock.verify(inboundWire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ wireService = new JDKWireService();
+ inboundWire = EasyMock.createMock(InboundWire.class);
+ serviceContract = new JavaServiceContract(TestInterface.class);
+ chains = new HashMap<Operation<?>, InboundInvocationChain>();
+ }
+
+ public static interface TestInterface {
+ int primitives(int i);
+
+ String objects(String object);
+ }
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java?view=diff&rev=480385&r1=480384&r2=480385
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java
(original)
+++
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java
Tue Nov 28 19:55:05 2006
@@ -35,6 +35,15 @@
*/
public interface WireService {
+ /**
+ * Create a proxy for the supplied wire that implements the supplied
interface.
+ *
+ * @param interfaze the interface that the proxy class must implement
+ * @param wire the wire to connect the proxy to
+ * @return a proxy that allows invocation of the wire
+ * @throws ProxyCreationException if there was a problem creating the proxy
+ */
+ <T> T createProxy(Class<T> interfaze, InboundWire wire) throws
ProxyCreationException;
/**
* Creates a Java proxy for the given wire
Modified:
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java?view=diff&rev=480385&r1=480384&r2=480385
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java
Tue Nov 28 19:55:05 2006
@@ -344,6 +344,10 @@
super(null, null);
}
+ public <T> T createProxy(Class<T> interfaze, InboundWire wire) throws
ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
public Object createProxy(RuntimeWire wire) throws
ProxyCreationException {
throw new UnsupportedOperationException();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]