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.adl.implementations;
00032
00033 import java.util.Map;
00034
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.fractal.adl.ADLException;
00037 import org.objectweb.fractal.api.Component;
00038 import org.objectweb.fractal.api.control.BindingController;
00039 import org.objectweb.fractal.api.type.ComponentType;
00040 import org.objectweb.fractal.util.Fractal;
00041 import org.objectweb.proactive.core.component.Constants;
00042 import org.objectweb.proactive.core.component.ContentDescription;
00043 import org.objectweb.proactive.core.component.ControllerDescription;
00044 import org.objectweb.proactive.core.component.adl.RegistryManager;
00045 import org.objectweb.proactive.core.component.adl.nodes.VirtualNode;
00046 import org.objectweb.proactive.core.component.adl.vnexportation.ExportedVirtualNodesList;
00047 import org.objectweb.proactive.core.component.adl.vnexportation.LinkedVirtualNode;
00048 import org.objectweb.proactive.core.component.factory.ProActiveGenericFactory;
00049 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00050 import org.objectweb.proactive.core.group.Group;
00051 import org.objectweb.proactive.core.util.log.Loggers;
00052 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00053
00054
00058 public class ProActiveImplementationBuilderImpl
00059 implements ProActiveImplementationBuilder, BindingController {
00060 public final static String REGISTRY_BINDING = "registry";
00061 public RegistryManager registry;
00062 private static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS_ADL);
00063
00064
00065
00066
00067 public String[] listFc() {
00068 return new String[] { REGISTRY_BINDING };
00069 }
00070
00071 public Object lookupFc(final String itf) {
00072 if (itf.equals(REGISTRY_BINDING)) {
00073 return registry;
00074 }
00075 return null;
00076 }
00077
00078 public void bindFc(final String itf, final Object value) {
00079 if (itf.equals(REGISTRY_BINDING)) {
00080 registry = (RegistryManager) value;
00081 }
00082 }
00083
00084 public void unbindFc(final String itf) {
00085 if (itf.equals(REGISTRY_BINDING)) {
00086 registry = null;
00087 }
00088 }
00089
00090
00091
00092
00093 public Object createComponent(Object arg0, String arg1, String arg2,
00094 Object arg3, Object arg4, Object arg5) throws Exception {
00095 return null;
00096 }
00097
00098 public Object createComponent(Object type, String name, String definition,
00099 ControllerDescription controllerDesc, ContentDescription contentDesc,
00100 VirtualNode adlVN, Map context) throws Exception {
00101 org.objectweb.proactive.core.descriptor.data.VirtualNode deploymentVN = null;
00102 Component bootstrap = null;
00103 if (context != null) {
00104 bootstrap = (Component) ((Map) context).get("bootstrap");
00105 }
00106 if (bootstrap == null) {
00107 bootstrap = Fractal.getBootstrapComponent();
00108 }
00109
00110 if (adlVN != null) {
00111
00112 LinkedVirtualNode exported = ExportedVirtualNodesList.instance()
00113 .getNode(name,
00114 adlVN.getName(), false);
00115 if (exported != null) {
00116 adlVN.setName(exported.getExportedVirtualNodeNameAfterComposition());
00117 adlVN.setCardinality(exported.isMultiple()
00118 ? VirtualNode.MULTIPLE : VirtualNode.SINGLE);
00119 } else {
00120
00121
00122 ExportedVirtualNodesList.instance().addLeafVirtualNode(name,
00123 adlVN.getName(), adlVN.getCardinality());
00124 }
00125 if (context.get("deployment-descriptor") != null) {
00126 deploymentVN =
00127 ((ProActiveDescriptor) context.get("deployment-descriptor")).getVirtualNode(adlVN.getName());
00128 if (deploymentVN == null) {
00129 if (adlVN.getName().equals("null")) {
00130 logger.info(name +
00131 " will be instantiated in the current virtual machine (\"null\" was specified as the virtual node name)");
00132 } else {
00133 throw new ADLException("Could not find virtual node " +
00134 adlVN.getName() + " in the deployment descriptor",
00135 null);
00136 }
00137 } else {
00138 if (deploymentVN.isMultiple() &&
00139 (adlVN.getCardinality().equals(VirtualNode.SINGLE))) {
00140
00141 contentDesc.forceSingleInstance();
00142 } else if (!(deploymentVN.isMultiple()) &&
00143 (adlVN.getCardinality().equals(VirtualNode.MULTIPLE))) {
00144 throw new ADLException(
00145 "Cannot deploy on a single virtual node when the cardinality of this virtual node named " +
00146 adlVN.getName() + " in the ADL is set to multiple",
00147 null);
00148 }
00149 }
00150 }
00151 }
00152 Component result;
00153
00154
00155 if (deploymentVN!=null && VirtualNode.MULTIPLE.equals(adlVN.getCardinality()) && controllerDesc.getHierarchicalType().equals(Constants.PRIMITIVE) && !contentDesc.uniqueInstance()) {
00156 result = (Component)((Group)((ProActiveGenericFactory)Fractal.getGenericFactory(bootstrap)).newFcInstanceAsList((ComponentType) type,
00157 controllerDesc, contentDesc, deploymentVN)).getGroupByType();
00158 } else {
00159 result = ((ProActiveGenericFactory)Fractal.getGenericFactory(bootstrap)).newFcInstance((ComponentType) type,
00160 controllerDesc, contentDesc, deploymentVN);
00161 }
00162
00163
00164 return result;
00165 }
00166 }