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.group;
00032
00033 import java.lang.reflect.Constructor;
00034
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.fractal.api.Component;
00037 import org.objectweb.fractal.api.Interface;
00038 import org.objectweb.fractal.api.factory.InstantiationException;
00039 import org.objectweb.fractal.api.type.ComponentType;
00040 import org.objectweb.proactive.core.component.ControllerDescription;
00041 import org.objectweb.proactive.core.component.ProActiveInterface;
00042 import org.objectweb.proactive.core.component.ProActiveInterfaceImpl;
00043 import org.objectweb.proactive.core.component.exceptions.InterfaceGenerationFailedException;
00044 import org.objectweb.proactive.core.component.gen.RepresentativeInterfaceClassGenerator;
00045 import org.objectweb.proactive.core.component.group.ProxyForComponentGroup;
00046 import org.objectweb.proactive.core.component.group.ProxyForComponentInterfaceGroup;
00047 import org.objectweb.proactive.core.component.representative.ProActiveComponentRepresentative;
00048 import org.objectweb.proactive.core.component.representative.ProActiveComponentRepresentativeImpl;
00049 import org.objectweb.proactive.core.component.type.ProActiveInterfaceType;
00050 import org.objectweb.proactive.core.mop.ClassNotReifiableException;
00051 import org.objectweb.proactive.core.mop.ConstructionOfProxyObjectFailedException;
00052 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException;
00053 import org.objectweb.proactive.core.mop.ConstructorCall;
00054 import org.objectweb.proactive.core.mop.InvalidProxyClassException;
00055 import org.objectweb.proactive.core.mop.MOP;
00056 import org.objectweb.proactive.core.mop.StubObject;
00057 import org.objectweb.proactive.core.util.log.Loggers;
00058 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00059
00060
00073 public class ProActiveComponentGroup {
00074 protected static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS);
00075
00084 public static ProActiveInterface newComponentInterfaceGroup(
00085 ProActiveInterfaceType interfaceType, Component owner)
00086 throws ClassNotFoundException, ClassNotReifiableException {
00087 try {
00088 Object result = MOP.newInstance(ProActiveInterfaceImpl.class.getName(),
00089 null, null, ProxyForComponentInterfaceGroup.class.getName(), null);
00090
00091 ProxyForComponentInterfaceGroup proxy = (ProxyForComponentInterfaceGroup) ((StubObject) result).getProxy();
00092 proxy.className = Interface.class.getName();
00093
00094
00095 ProActiveInterface generated = RepresentativeInterfaceClassGenerator.instance()
00096 .generateFunctionalInterface(interfaceType.getFcItfName(),
00097 owner, interfaceType);
00098 ((StubObject) generated).setProxy(proxy);
00099
00100 proxy.setInterfaceType(interfaceType);
00101 proxy.setOwner(owner);
00102
00103 return generated;
00104 } catch (InvalidProxyClassException e) {
00105 logger.error("**** InvalidProxyClassException ****");
00106 } catch (ConstructionOfProxyObjectFailedException e) {
00107 logger.error("**** ConstructionOfProxyObjectFailedException ****");
00108 } catch (ConstructionOfReifiedObjectFailedException e) {
00109 logger.error("**** ConstructionOfReifiedObjectFailedException ****");
00110 } catch (InterfaceGenerationFailedException e) {
00111 logger.error("**** Interface could not be generated **** " +
00112 e.getMessage());
00113 }
00114 return null;
00115 }
00116
00127 public static ProActiveComponentRepresentative newComponentRepresentativeGroup(
00128 ComponentType componentType, ControllerDescription controllerDesc)
00129 throws ClassNotFoundException, InstantiationException {
00130 try {
00131 ProActiveComponentRepresentative result = null;
00132
00133
00134 Constructor constructor = ProActiveComponentRepresentativeImpl.class.getConstructor(new Class[] {
00135 ComponentType.class, String.class, String.class
00136 });
00137 result = (ProActiveComponentRepresentative) constructor.newInstance(new Object[] {
00138 componentType,
00139 controllerDesc.getHierarchicalType(),
00140 controllerDesc.getControllersConfigFileLocation()
00141 });
00142
00143
00144 ConstructorCall reifiedCall = MOP.buildTargetObjectConstructorCall(ProActiveComponentRepresentativeImpl.class,
00145 new Object[] {
00146 componentType,
00147 controllerDesc.getHierarchicalType(),
00148 controllerDesc.getControllersConfigFileLocation()
00149 });
00150
00151
00152 ProxyForComponentGroup proxy = (ProxyForComponentGroup) MOP.createProxyObject(ProxyForComponentGroup.class.getName(),
00153 MOP.EMPTY_OBJECT_ARRAY, reifiedCall);
00154
00155
00156 result.setProxy(proxy);
00157
00158 proxy.className = Component.class.getName();
00159 proxy.setComponentType(componentType);
00160 proxy.setControllerDesc(controllerDesc);
00161
00162 return result;
00163 } catch (Exception e) {
00164 throw new InstantiationException(
00165 "cannot create group of component representatives : " +
00166 e.getMessage());
00167 }
00168 }
00169 }