You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/03/20 09:38:55 UTC
svn commit: r387164 -
/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java
Author: gnodet
Date: Mon Mar 20 00:38:51 2006
New Revision: 387164
URL: http://svn.apache.org/viewcvs?rev=387164&view=rev
Log:
Remove unneeded directory
Reformat ScaEndpoint
Modified:
incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java
Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java?rev=387164&r1=387163&r2=387164&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java Mon Mar 20 00:38:51 2006
@@ -37,7 +37,6 @@
import org.apache.servicemix.common.ExchangeProcessor;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.tuscany.core.context.EntryPointContext;
-import org.apache.tuscany.core.invocation.spi.ProxyFactory;
import org.apache.tuscany.model.assembly.ConfiguredReference;
import org.apache.tuscany.model.assembly.ConfiguredService;
import org.apache.tuscany.model.assembly.EntryPoint;
@@ -46,28 +45,30 @@
*
* @author gnodet
* @version $Revision: 366467 $
- * @org.apache.xbean.XBean element="endpoint"
- * description="A sca endpoint"
+ * @org.apache.xbean.XBean element="endpoint" description="A sca endpoint"
*
*/
public class ScaEndpoint extends Endpoint implements ExchangeProcessor {
protected ServiceEndpoint activated;
+
protected EntryPoint entryPoint;
- protected Object proxy;
+
protected Map<Class, Method> methodMap;
+
protected JAXBContext jaxbContext;
+
protected DeliveryChannel channel;
-
- public ScaEndpoint(EntryPoint entryPoint) {
- this.entryPoint = entryPoint;
- }
-
- public Role getRole() {
- return Role.PROVIDER;
- }
- public void activate() throws Exception {
+ public ScaEndpoint(EntryPoint entryPoint) {
+ this.entryPoint = entryPoint;
+ }
+
+ public Role getRole() {
+ return Role.PROVIDER;
+ }
+
+ public void activate() throws Exception {
logger = this.serviceUnit.getComponent().getLogger();
ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
activated = ctx.activateEndpoint(service, endpoint);
@@ -75,53 +76,51 @@
// Get the target service
ConfiguredReference referenceValue = entryPoint.getConfiguredReference();
ConfiguredService targetServiceEndpoint = referenceValue.getTargetConfiguredServices().get(0);
- // Create a proxy
- ProxyFactory proxyFactory = (ProxyFactory) targetServiceEndpoint.getProxyFactory();
- proxy = proxyFactory.createProxy();
// Get the business interface
Class serviceInterface = targetServiceEndpoint.getService().getServiceContract().getInterface();
List<Class> classes = new ArrayList<Class>();
methodMap = new HashMap<Class, Method>();
for (Method mth : serviceInterface.getMethods()) {
- Class[] params = mth.getParameterTypes();
- if (params.length != 1) {
- throw new IllegalStateException("Supports only methods with one parameter");
- }
- methodMap.put(params[0], mth);
- classes.add(mth.getReturnType());
- classes.add(params[0]);
+ Class[] params = mth.getParameterTypes();
+ if (params.length != 1) {
+ throw new IllegalStateException("Supports only methods with one parameter");
+ }
+ methodMap.put(params[0], mth);
+ classes.add(mth.getReturnType());
+ classes.add(params[0]);
}
jaxbContext = JAXBContext.newInstance(classes.toArray(new Class[0]));
- }
+ }
- public void deactivate() throws Exception {
+ public void deactivate() throws Exception {
ServiceEndpoint ep = activated;
activated = null;
ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
ctx.deactivateEndpoint(ep);
- }
+ }
- public ExchangeProcessor getProcessor() {
- return this;
- }
-
- public void process(MessageExchange exchange) throws Exception {
- if (exchange.getStatus() == ExchangeStatus.DONE) {
- return;
- } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
- return;
- }
- Object input = jaxbContext.createUnmarshaller().unmarshal(exchange.getMessage("in").getContent());
- Method method = methodMap.get(input.getClass());
- if (method == null) {
- throw new IllegalStateException("Could not determine invoked web method");
- }
- boolean oneWay = method.getReturnType() == null;
- Object output;
- try {
- EntryPointContext entryPointContext = (EntryPointContext) ((ScaServiceUnit) serviceUnit).getTuscanyRuntime().getModuleContext().getContext(entryPoint.getName());
+ public ExchangeProcessor getProcessor() {
+ return this;
+ }
+
+ public void process(MessageExchange exchange) throws Exception {
+ if (exchange.getStatus() == ExchangeStatus.DONE) {
+ return;
+ } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ return;
+ }
+ Object input = jaxbContext.createUnmarshaller().unmarshal(exchange.getMessage("in").getContent());
+ Method method = methodMap.get(input.getClass());
+ if (method == null) {
+ throw new IllegalStateException("Could not determine invoked web method");
+ }
+ boolean oneWay = method.getReturnType() == null;
+ Object output;
+ try {
+ EntryPointContext entryPointContext = (EntryPointContext) ((ScaServiceUnit) serviceUnit)
+ .getTuscanyRuntime().getModuleContext().getContext(entryPoint.getName());
InvocationHandler handler = (InvocationHandler) entryPointContext.getImplementationInstance();
- output = handler.invoke(null, method, new Object[] { input });
+ output = handler.invoke(null, method, new Object[] { input });
} catch (UndeclaredThrowableException e) {
throw e;
} catch (RuntimeException e) {
@@ -130,26 +129,26 @@
throw e;
} catch (Exception e) {
throw e;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- if (oneWay) {
- exchange.setStatus(ExchangeStatus.DONE);
- channel.send(exchange);
- } else {
- NormalizedMessage msg = exchange.createMessage();
- exchange.setMessage(msg, "out");
- StringWriter writer = new StringWriter();
- jaxbContext.createMarshaller().marshal(output, writer);
- msg.setContent(new StringSource(writer.toString()));
- channel.send(exchange);
- }
- }
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ if (oneWay) {
+ exchange.setStatus(ExchangeStatus.DONE);
+ channel.send(exchange);
+ } else {
+ NormalizedMessage msg = exchange.createMessage();
+ exchange.setMessage(msg, "out");
+ StringWriter writer = new StringWriter();
+ jaxbContext.createMarshaller().marshal(output, writer);
+ msg.setContent(new StringSource(writer.toString()));
+ channel.send(exchange);
+ }
+ }
- public void start() throws Exception {
- }
+ public void start() throws Exception {
+ }
- public void stop() throws Exception {
- }
+ public void stop() throws Exception {
+ }
}