00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.component.controller;
00032
00033 import java.io.Serializable;
00034 import java.lang.reflect.InvocationTargetException;
00035
00036 import org.objectweb.fractal.api.Component;
00037 import org.objectweb.fractal.api.NoSuchInterfaceException;
00038 import org.objectweb.fractal.api.control.AttributeController;
00039 import org.objectweb.proactive.core.ProActiveRuntimeException;
00040 import org.objectweb.proactive.core.component.Constants;
00041 import org.objectweb.proactive.core.component.Fractive;
00042 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
00043 import org.objectweb.proactive.core.component.request.ComponentRequest;
00044 import org.objectweb.proactive.core.mop.MethodCallExecutionFailedException;
00045
00046
00056 public abstract class AbstractRequestHandler implements RequestHandler,
00057 Serializable {
00058 private RequestHandler nextHandler = null;
00059 protected ProActiveComponent owner;
00060
00061
00062
00063
00064 public RequestHandler nextHandler() {
00065 return nextHandler;
00066 }
00067
00068
00069
00070
00071 public void setNextHandler(RequestHandler handler) {
00072 nextHandler = handler;
00073 }
00074
00075 public Object handleRequest(ComponentRequest request)
00076 throws MethodCallExecutionFailedException, InvocationTargetException {
00077 if (request.getMethodCall().getComponentMetadata()
00078 .getComponentInterfaceName().equals(getFcItfName()) &&
00079 request.getTargetClass().isAssignableFrom(this.getClass())) {
00080 return request.getMethodCall().execute(this);
00081 }
00082 if (nextHandler() != null) {
00083 return nextHandler().handleRequest(request);
00084 }
00085
00086
00087 if (AttributeController.class.isAssignableFrom(request.getTargetClass()) &&
00088 isPrimitive()) {
00089
00090 return request.getMethodCall()
00091 .execute(((ProActiveComponent) getFcItfOwner()).getReferenceOnBaseObject());
00092 }
00093 throw new MethodCallExecutionFailedException(
00094 "cannot find a suitable handler for this request");
00095 }
00096
00097 abstract public String getFcItfName();
00098
00099 public Component getFcItfOwner() {
00100 return owner;
00101 }
00102
00103 protected String getHierarchicalType() {
00104 try {
00105 return Fractive.getComponentParametersController((ProActiveComponent) getFcItfOwner())
00106 .getComponentParameters().getHierarchicalType();
00107 } catch (NoSuchInterfaceException e) {
00108 throw new ProActiveRuntimeException(
00109 "There is no component parameters controller for this component");
00110 }
00111 }
00112
00113 protected boolean isPrimitive() {
00114 return Constants.PRIMITIVE.equals(getHierarchicalType());
00115 }
00116
00117 protected boolean isComposite() {
00118 return Constants.COMPOSITE.equals(getHierarchicalType());
00119 }
00120 }