1 31 package org.objectweb.proactive.core.component.type; 32 33 import java.io.Serializable ; 34 35 import org.apache.log4j.Logger; 36 37 import org.objectweb.fractal.api.NoSuchInterfaceException; 38 import org.objectweb.fractal.api.Type; 39 import org.objectweb.fractal.api.factory.InstantiationException; 40 import org.objectweb.fractal.api.type.ComponentType; 41 import org.objectweb.fractal.api.type.InterfaceType; 42 43 49 public class ProActiveComponentType implements ComponentType, Serializable { 50 protected static Logger logger = Logger.getLogger(ProActiveComponentType.class.getName()); 51 52 55 private final InterfaceType[] interfaceTypes; 56 57 60 public ProActiveComponentType(final InterfaceType[] interfaceTypes) throws InstantiationException { 61 this.interfaceTypes = clone(interfaceTypes); 62 for (int i = 0; i < interfaceTypes.length; ++i) { 64 String p = interfaceTypes[i].getFcItfName(); 65 boolean collection = interfaceTypes[i].isFcCollectionItf(); 66 for (int j = i + 1; j < interfaceTypes.length; ++j) { 67 String q = interfaceTypes[j].getFcItfName(); 68 if (p.equals(q)) { 69 throw new InstantiationException ( 70 "Two interfaces have the same name '" + q + "'"); 71 } 72 if (collection && q.startsWith(p)) { 73 throw new InstantiationException ( 74 "The name of the interface '" + q + "' starts with '" + 75 p + "', which is the name of a collection interface"); 76 } 77 if (interfaceTypes[j].isFcCollectionItf() && p.startsWith(q)) { 78 throw new InstantiationException ( 79 "The name of the interface '" + p + "' starts with '" + 80 q + "', which is the name of a collection interface"); 81 } 82 } 83 } 84 } 85 86 89 public ProActiveComponentType(final ComponentType componentType) { 90 InterfaceType[] tempItfTypes = componentType.getFcInterfaceTypes(); 91 this.interfaceTypes = new InterfaceType[tempItfTypes.length]; 92 for (int i=0; i<interfaceTypes.length; i++) { 93 interfaceTypes[i] = new ProActiveInterfaceType(tempItfTypes[i]); 95 } 96 } 97 98 101 public InterfaceType[] getFcInterfaceTypes() { 102 return interfaceTypes; 103 } 104 105 108 public InterfaceType getFcInterfaceType(String name) throws NoSuchInterfaceException{ 109 for (int i = 0; i < interfaceTypes.length; i++) { 110 InterfaceType type = interfaceTypes[i]; 111 if (type.getFcItfName().equals(name)) { 112 return type; 113 } 114 } 115 throw new NoSuchInterfaceException(name); 116 } 117 118 121 public boolean isFcSubTypeOf(Type type) { 122 throw new RuntimeException ("not yet implemented"); 123 } 124 125 134 135 private static InterfaceType[] clone (final InterfaceType[] types) { 136 if (types == null) { 137 return new InterfaceType[0]; 138 } else { 139 InterfaceType[] clone = new InterfaceType[types.length]; 140 System.arraycopy(types, 0, clone, 0, types.length); 141 return clone; 142 } 143 } 144 } | Popular Tags |