org.etsi.uri.gcm.util.GCM Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fractal-gcm-api Show documentation
Show all versions of fractal-gcm-api Show documentation
Grid Component Model Standardization
The newest version!
/*
* ################################################################
*
* Fractal GCM Management API
*
* Copyright (C) 2009 INRIA, University of
* Nice-Sophia Antipolis, ActiveEon
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: [email protected]
*
* Authors: INRIA, University of Nice-Sophia Antipolis, ActiveEon.
*
* ################################################################
*/
package org.etsi.uri.gcm.util;
import java.util.Map;
import org.etsi.uri.gcm.api.control.GCMLifeCycleController;
import org.etsi.uri.gcm.api.control.GathercastController;
import org.etsi.uri.gcm.api.control.MigrationController;
import org.etsi.uri.gcm.api.control.MonitorController;
import org.etsi.uri.gcm.api.control.MulticastController;
import org.etsi.uri.gcm.api.control.PriorityController;
import org.etsi.uri.gcm.api.type.GCMTypeFactory;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.AttributeController;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.control.ContentController;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.api.control.NameController;
import org.objectweb.fractal.api.control.SuperController;
import org.objectweb.fractal.api.factory.Factory;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.TypeFactory;
/**
* Provides static methods to access standard interfaces of GCM components.
*
* @author INRIA, University of Nice-Sophia Antipolis, ActiveEon
*/
public class GCM {
/**
* Private constructor (uninstantiable class).
*/
private GCM() {
}
/**
* Returns a bootstrap component to create other components. This method
* just calls the corresponding method of the org.etsi.uri.gcm.GCM
* class.
*
* @return Bootstrap component to create other components.
* @throws InstantiationException
* If the bootstrap component cannot be created.
*/
public static Component getBootstrapComponent()
throws InstantiationException {
return org.etsi.uri.gcm.api.GCM.getBootstrapComponent();
}
/**
* Returns a bootstrap component to create other components. This method
* creates an instance of the class whose name is associated to the
* "gcm.provider" key, which must implement the {@link Factory} or
* {@link GenericFactory} interface, and returns the component instantiated
* by this factory.
*
* @param hints
* {@link Map} which must associate a value to the "gcm.provider"
* key, and which may associate a {@link ClassLoader} to the
* "classloader" key. This class loader will be used to load the
* bootstrap component.
* @return Bootstrap component to create other components.
* @throws InstantiationException
* If the bootstrap component cannot be created.
*/
public static Component getBootstrapComponent(final Map, ?> hints)
throws InstantiationException {
String bootTmplClassName = (String) hints.get("gcm.provider");
if (bootTmplClassName == null) {
bootTmplClassName = System.getProperty("gcm.provider");
}
if (bootTmplClassName == null) {
throw new InstantiationException(
"The gcm.provider value is not defined");
}
Object bootTmpl;
try {
ClassLoader cl = (ClassLoader) hints.get("classloader");
if (cl == null) {
cl = new GCM().getClass().getClassLoader();
}
Class> bootTmplClass = cl.loadClass(bootTmplClassName);
bootTmpl = bootTmplClass.newInstance();
} catch (Exception e) {
throw new InstantiationException("Cannot find or instantiate the '"
+ bootTmplClassName
+ "' class associated to the gcm.provider key");
}
if (bootTmpl instanceof GenericFactory) {
return ((GenericFactory) bootTmpl).newFcInstance(null, null, hints);
} else {
return ((Factory) bootTmpl).newFcInstance();
}
}
/**
* Returns the {@link AttributeController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link AttributeController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static AttributeController getAttributeController(final Component component)
throws NoSuchInterfaceException {
return (AttributeController) component.getFcInterface("attribute-controller");
}
/**
* Returns the {@link BindingController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link BindingController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static BindingController getBindingController(final Component component)
throws NoSuchInterfaceException {
return (BindingController) component.getFcInterface("binding-controller");
}
/**
* Returns the {@link ContentController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link ContentController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static ContentController getContentController(final Component component)
throws NoSuchInterfaceException {
return (ContentController) component.getFcInterface("content-controller");
}
/**
* Returns the {@link SuperController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link SuperController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static SuperController getSuperController(final Component component)
throws NoSuchInterfaceException {
return (SuperController) component.getFcInterface("super-controller");
}
/**
* Returns the {@link NameController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link NameController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static NameController getNameController(final Component component)
throws NoSuchInterfaceException {
return (NameController) component.getFcInterface("name-controller");
}
/**
* Returns the {@link LifeCycleController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link LifeCycleController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static LifeCycleController getLifeCycleController(final Component component)
throws NoSuchInterfaceException {
return (LifeCycleController) component.getFcInterface("lifecycle-controller");
}
/**
* Returns the {@link GCMLifeCycleController} interface of the given
* component.
*
* @param component
* Reference on a component.
* @return {@link GCMLifeCycleController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static GCMLifeCycleController getGCMLifeCycleController(final Component component)
throws NoSuchInterfaceException {
try {
return (GCMLifeCycleController) component.getFcInterface("lifecycle-controller");
} catch (ClassCastException cce) {
throw new NoSuchInterfaceException("lifecycle-controller");
}
}
/**
* Returns the {@link MulticastController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link MulticastController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static MulticastController getMulticastController(final Component component)
throws NoSuchInterfaceException {
return (MulticastController) component.getFcInterface("multicast-controller");
}
/**
* Returns the {@link GathercastController} interface of the given
* component.
*
* @param component
* Reference on a component.
* @return {@link GathercastController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static GathercastController getGathercastController(final Component component)
throws NoSuchInterfaceException {
return (GathercastController) component.getFcInterface("gathercast-controller");
}
/**
* Returns the {@link MigrationController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link MigrationController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static MigrationController getMigrationController(final Component component)
throws NoSuchInterfaceException {
return (MigrationController) component.getFcInterface("migration-controller");
}
/**
* Returns the {@link MonitorController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link MonitorController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static MonitorController getMonitorController(final Component component)
throws NoSuchInterfaceException {
return (MonitorController) component.getFcInterface("monitor-controller");
}
/**
* Returns the {@link PriorityController} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link PriorityController} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static PriorityController getPriorityController(final Component component)
throws NoSuchInterfaceException {
return (PriorityController) component.getFcInterface("priority-controller");
}
/**
* Returns the {@link Factory} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link Factory} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static Factory getFactory(final Component component)
throws NoSuchInterfaceException {
return (Factory) component.getFcInterface("factory");
}
/**
* Returns the {@link GenericFactory} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link GenericFactory} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static GenericFactory getGenericFactory(final Component component)
throws NoSuchInterfaceException {
return (GenericFactory) component.getFcInterface("generic-factory");
}
/**
* Returns the {@link TypeFactory} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link TypeFactory} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static TypeFactory getTypeFactory(final Component component)
throws NoSuchInterfaceException {
return (TypeFactory) component.getFcInterface("type-factory");
}
/**
* Returns the {@link GCMTypeFactory} interface of the given component.
*
* @param component
* Reference on a component.
* @return {@link GCMTypeFactory} interface of the given component.
* @throws NoSuchInterfaceException
* If there is no such interface.
*/
public static GCMTypeFactory getGCMTypeFactory(final Component component)
throws NoSuchInterfaceException {
try {
return (GCMTypeFactory) component.getFcInterface("type-factory");
} catch (ClassCastException cce) {
throw new NoSuchInterfaceException("type-factory");
}
}
}