org/objectweb/proactive/core/group/ProActiveComponentGroup.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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             //return a reference on the generated interface reference corresponding to the interface type
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             // create the stub with the appropriate parameters
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             // build the constructor call for the proxy object to create
00144             ConstructorCall reifiedCall = MOP.buildTargetObjectConstructorCall(ProActiveComponentRepresentativeImpl.class,
00145                     new Object[] {
00146                         componentType,
00147                         controllerDesc.getHierarchicalType(),
00148                         controllerDesc.getControllersConfigFileLocation()
00149                     });
00150 
00151             // Instanciates the proxy object
00152             ProxyForComponentGroup proxy = (ProxyForComponentGroup) MOP.createProxyObject(ProxyForComponentGroup.class.getName(),
00153                     MOP.EMPTY_OBJECT_ARRAY, reifiedCall);
00154 
00155             // connect the stub to the proxy
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 }

Generated on Mon Jan 22 15:16:08 2007 for ProActive by  doxygen 1.5.1