1 package org.jboss.aspects.remoting.interceptors.invoker; 2 3 import org.jboss.aop.advice.Interceptor; 4 import org.jboss.aop.joinpoint.Invocation; 5 import org.jboss.aspects.remoting.interceptors.marshall.MarshallInterceptor; 6 import org.jboss.aspects.remoting.interceptors.transport.TransportInterceptor; 7 import org.jboss.remoting.Client; 8 import org.jboss.remoting.InvokerLocator; 9 import org.jboss.remoting.marshal.MarshalFactory; 10 import org.jboss.remoting.marshal.Marshaller; 11 12 import java.util.ArrayList ; 13 import java.util.Map ; 14 15 18 public class RemotingInterceptorFactory 19 { 20 public static final String REMOTING = "REMOTING"; 21 public static final String INVOKER_LOCATOR = "INVOKER_LOCATOR"; 22 public static final String SUBSYSTEM = "SUBSYSTEM"; 23 public static final String MARSHALLER = "MARSHALLER"; 24 public static final String LOADER = "LOADER"; 25 26 27 public static Invocation injectRemotingInterceptors(Invocation invocation) 28 { 29 Invocation newInvocation = null; 30 31 InvokerLocator locator = (InvokerLocator) invocation.getMetaData(REMOTING, INVOKER_LOCATOR); 33 if (locator != null) 34 { 35 Interceptor[] newInterceptor = null; 36 ArrayList interceptorList = new ArrayList (); 37 38 String dataType = (String ) invocation.getMetaData(REMOTING, InvokerLocator.DATATYPE); 40 if (dataType == null) 41 { 42 dataType = getDataType(locator); 43 } 44 45 if (dataType != null) 46 { 47 Marshaller marshaller = MarshalFactory.getMarshaller(dataType); 50 MarshallInterceptor marshallInterceptor = new MarshallInterceptor(marshaller); 51 interceptorList.add(marshallInterceptor); 52 } 53 54 ClassLoader loader = (ClassLoader ) invocation.getMetaData(REMOTING, LOADER); 56 String subsystem = (String ) invocation.getMetaData(REMOTING, SUBSYSTEM); 57 58 Client client = null; 59 try 60 { 61 if (loader != null) 62 { 63 client = new Client(loader, locator, subsystem, null); 64 } 65 else 66 { 67 client = new Client(locator, subsystem); 68 } 69 } 70 catch (Exception e) 71 { 72 throw new RuntimeException ("Could not create remoting client.", e); 73 } 74 75 TransportInterceptor transportInterceptor = new TransportInterceptor(client); 76 interceptorList.add(transportInterceptor); 77 78 83 newInterceptor = (Interceptor[]) interceptorList.toArray(new Interceptor[interceptorList.size()]); 85 newInvocation = invocation.getWrapper(newInterceptor); 86 } 87 else 88 { 89 throw new RuntimeException ("Require InvokerLocator to make remote invocations."); 90 } 91 92 return newInvocation; 93 } 94 95 private static String getDataType(InvokerLocator locator) 96 { 97 String type = null; 98 99 if (locator != null) 100 { 101 Map params = locator.getParameters(); 102 if (params != null) 103 { 104 type = (String ) params.get(InvokerLocator.DATATYPE); 105 } 106 } 107 return type; 108 } 109 } 110 | Popular Tags |