1 31 package org.objectweb.proactive.core.component.request; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.fractal.api.Component; 36 import org.objectweb.fractal.api.Interface; 37 import org.objectweb.fractal.api.NoSuchInterfaceException; 38 import org.objectweb.fractal.api.control.AttributeController; 39 import org.objectweb.fractal.api.control.BindingController; 40 import org.objectweb.fractal.api.control.ContentController; 41 import org.objectweb.fractal.api.control.LifeCycleController; 42 43 import org.objectweb.proactive.Body; 44 import org.objectweb.proactive.core.body.UniversalBody; 45 import org.objectweb.proactive.core.body.request.Request; 46 import org.objectweb.proactive.core.body.request.RequestImpl; 47 import org.objectweb.proactive.core.body.request.ServeException; 48 import org.objectweb.proactive.core.component.Constants; 49 import org.objectweb.proactive.core.component.Fractive; 50 import org.objectweb.proactive.core.component.body.ComponentBodyImpl; 51 import org.objectweb.proactive.core.component.controller.ComponentParametersController; 52 import org.objectweb.proactive.core.mop.MethodCall; 53 import org.objectweb.proactive.core.mop.MethodCallExecutionFailedException; 54 55 import java.io.Serializable ; 56 57 58 68 public class ComponentRequestImpl extends RequestImpl 69 implements ComponentRequest, Serializable { 70 protected static Logger logger = Logger.getLogger(ComponentRequestImpl.class.getName()); 71 72 public ComponentRequestImpl(MethodCall methodCall, UniversalBody sender, 73 boolean isOneWay, long nextSequenceID) { 74 super(methodCall, sender, isOneWay, nextSequenceID); 75 } 76 77 public ComponentRequestImpl(Request request) { 78 super(request.getMethodCall(), request.getSender(), request.isOneWay(), 79 request.getSequenceNumber()); 80 } 81 82 85 protected Object serveInternal(Body targetBody) throws ServeException { 86 try { 90 Object result = null; 91 Class target_class = methodCall.getReifiedMethod() 92 .getDeclaringClass(); 93 if (target_class.equals(BindingController.class)) { 94 result = methodCall.execute(((ComponentBodyImpl) targetBody).getProActiveComponent() 95 .getFcInterface(Constants.BINDING_CONTROLLER)); 96 } else if (target_class.equals(ContentController.class)) { 97 result = methodCall.execute(((ComponentBodyImpl) targetBody).getProActiveComponent() 98 .getFcInterface(Constants.CONTENT_CONTROLLER)); 99 } else if (target_class.equals(LifeCycleController.class)) { 100 result = methodCall.execute(((ComponentBodyImpl) targetBody).getProActiveComponent() 101 .getFcInterface(Constants.LIFECYCLE_CONTROLLER)); 102 } else if (target_class.equals(ComponentParametersController.class)) { 103 result = methodCall.execute(((ComponentBodyImpl) targetBody).getProActiveComponent() 104 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)); 105 } else if (target_class.equals(AttributeController.class)) { 106 result = methodCall.execute(targetBody.getReifiedObject()); 108 } else if (target_class.equals(Interface.class)) { 109 result = methodCall.execute((Interface) ((ComponentBodyImpl) targetBody).getProActiveComponent()); 110 } else if (target_class.equals(Component.class)) { 111 result = methodCall.execute(((ComponentBodyImpl) targetBody).getProActiveComponent() 112 .getFcInterface(Constants.COMPONENT)); 113 } else { 114 if (((ComponentBodyImpl) targetBody).getProActiveComponent() != null) { 115 String hierarchical_type = Fractive.getComponentParametersController(((ComponentBodyImpl) targetBody).getProActiveComponent()) 116 .getComponentParameters() 117 .getHierarchicalType(); 118 119 if (hierarchical_type.equals(Constants.COMPOSITE) || 121 hierarchical_type.equals(Constants.PARALLEL)) { 122 if (logger.isDebugEnabled()) { 128 logger.debug(" forwarding the call : " + 129 methodCall.getFcFunctionalInterfaceName() + 130 " to : " + 131 ((ComponentParametersController) ((ComponentBodyImpl) targetBody) 132 .getProActiveComponent().getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters() 133 .getName()); 134 } 135 try { 136 result = methodCall.execute(((ComponentBodyImpl) targetBody).getProActiveComponent() 137 .getFcInterface(methodCall.getFcFunctionalInterfaceName())); 138 } catch (Exception e) { 139 e.printStackTrace(); 140 } 141 } else { 142 if (logger.isDebugEnabled()) { 149 logger.debug(" directly executing the call : " + 150 methodCall.getFcFunctionalInterfaceName()); 151 } 152 result = methodCall.execute(targetBody.getReifiedObject()); 153 } 154 } else { 155 throw new ServeException( 156 "trying to execute a component method on an object that is not a component"); 157 } 158 } 159 return result; 160 } catch (NoSuchInterfaceException nsie) { 161 nsie.printStackTrace(); 162 throw new ServeException("cannot serve request : problem accessing a component controller", 163 nsie); 164 } catch (MethodCallExecutionFailedException e) { 165 e.printStackTrace(); 166 throw new ServeException("serve method " + 167 methodCall.getReifiedMethod().toString() + " failed", e); 168 } catch (java.lang.reflect.InvocationTargetException e) { 169 Throwable t = e.getTargetException(); 170 171 if (isOneWay) { 173 throw new ServeException("serve method " + 174 methodCall.getReifiedMethod().toString() + " failed", t); 175 } else { 176 return t; 177 } 178 } 179 } 180 181 184 public boolean isControllerRequest() { 185 Class declaring_class = methodCall.getReifiedMethod().getDeclaringClass(); 186 return (declaring_class.equals(ComponentParametersController.class) || 187 declaring_class.equals(ContentController.class) || 188 declaring_class.equals(BindingController.class) || 189 declaring_class.equals(LifeCycleController.class) || 190 declaring_class.equals(Interface.class)); 191 } 192 } 193 | Popular Tags |