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.type;
00032
00033 import java.io.Serializable;
00034 import java.lang.reflect.Method;
00035 import java.lang.reflect.ParameterizedType;
00036
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.fractal.api.Type;
00039 import org.objectweb.fractal.api.type.InterfaceType;
00040 import org.objectweb.proactive.core.ProActiveRuntimeException;
00041 import org.objectweb.proactive.core.util.log.Loggers;
00042 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00043
00044
00051 public class ProActiveInterfaceTypeImpl implements ProActiveInterfaceType, Serializable {
00052 protected static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS);
00056 private String name;
00057
00061 private String signature;
00062 private boolean isClient;
00063 private boolean isOptional;
00064 private String cardinality;
00065
00069 public ProActiveInterfaceTypeImpl() {
00070 super();
00071 }
00072
00077 public ProActiveInterfaceTypeImpl(final InterfaceType itfType) {
00078 this.name = itfType.getFcItfName();
00079 this.signature = itfType.getFcItfSignature();
00080 this.isClient = itfType.isFcClientItf();
00081 this.isOptional = itfType.isFcOptionalItf();
00082 if(itfType.isFcCollectionItf()) {
00083 cardinality = ProActiveTypeFactory.COLLECTION_CARDINALITY;
00084 } else {
00085 cardinality = ProActiveTypeFactory.SINGLETON_CARDINALITY;
00086 }
00087 }
00088
00092 public ProActiveInterfaceTypeImpl(String name, String signature,
00093 boolean isClient, boolean isOptional, String cardinality) {
00094 this.name = name;
00095 this.signature = signature;
00096 this.isClient = isClient;
00097 this.isOptional = isOptional;
00098 this.cardinality = cardinality;
00099 checkMethodsSignatures(signature, cardinality);
00100 }
00101
00102
00103 private boolean checkMethodsSignatures(String signature, String cardinality) {
00104 try {
00105 if (ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(cardinality)) {
00106 Class c = Class.forName(signature);
00107 Method[] methods = c.getMethods();
00108 for (Method m : methods) {
00109 if (!(m.getGenericReturnType() instanceof ParameterizedType) && !(Void.TYPE ==m.getReturnType())) {
00110 throw new ProActiveRuntimeException("methods of a multicast interface must return parameterized types or void, " +
00111 "which is not the case for method " + m.toString() + " in interface " + signature);
00112 }
00113 }
00114 }
00115 } catch (ClassNotFoundException e) {
00116 throw new ProActiveRuntimeException("cannot find interface defined in component interface signature : " + e.getMessage());
00117 }
00118 return true;
00119 }
00120
00121
00122
00123
00124
00125
00126
00130 public String getFcItfName() {
00131 return name;
00132 }
00133
00137 public String getFcItfSignature() {
00138 return signature;
00139 }
00140
00144 public boolean isFcClientItf() {
00145 return isClient;
00146 }
00147
00151 public boolean isFcOptionalItf() {
00152 return isOptional;
00153 }
00154
00159 public boolean isFcSubTypeOf(final Type type) {
00160 throw new RuntimeException("Not yet implemented.");
00161 }
00162
00163 public String getFcCardinality() {
00164 return cardinality;
00165 }
00166
00167 public boolean isFcCollective() {
00168 return (ProActiveTypeFactory.GATHER_CARDINALITY.equals(cardinality)
00169 || (ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(cardinality)));
00170 }
00171
00172 public boolean isFcGathercastItf() {
00173 return ProActiveTypeFactory.GATHER_CARDINALITY.equals(cardinality);
00174 }
00175
00176 public boolean isFcMulticastItf() {
00177 return ProActiveTypeFactory.MULTICAST_CARDINALITY.equals(cardinality);
00178 }
00179
00180 public boolean isFcSingletonItf() {
00181 return ProActiveTypeFactory.SINGLETON_CARDINALITY.equals(cardinality);
00182 }
00183
00184
00185
00186
00187 public boolean isFcCollectionItf() {
00188 return ProActiveTypeFactory.COLLECTION_CARDINALITY.equals(cardinality);
00189 }
00190
00191
00192 }