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 
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.fractal.api.NoSuchInterfaceException;
00037 import org.objectweb.fractal.api.Type;
00038 import org.objectweb.fractal.api.factory.InstantiationException;
00039 import org.objectweb.fractal.api.type.ComponentType;
00040 import org.objectweb.fractal.api.type.InterfaceType;
00041 import org.objectweb.proactive.core.util.log.Loggers;
00042 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00043 
00044 
00051 public class ProActiveComponentTypeImpl implements ComponentType, Serializable {
00052     protected static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS);
00053 
00057     private final InterfaceType[] interfaceTypes;
00058 
00062     public ProActiveComponentTypeImpl(final InterfaceType[] interfaceTypes)
00063         throws InstantiationException {
00064         this.interfaceTypes = clone(interfaceTypes);
00065         
00066         for (int i = 0; i < interfaceTypes.length; ++i) {
00067             String p = interfaceTypes[i].getFcItfName();
00068             boolean collection = interfaceTypes[i].isFcCollectionItf();
00069             for (int j = i + 1; j < interfaceTypes.length; ++j) {
00070                 String q = interfaceTypes[j].getFcItfName();
00071                 if (p.equals(q)) {
00072                     throw new InstantiationException(
00073                         "Two interfaces have the same name '" + q + "'");
00074                 }
00075                 if (collection && q.startsWith(p)) {
00076                     throw new InstantiationException(
00077                         "The name of the interface '" + q + "' starts with '" +
00078                         p + "', which is the name of a collection interface");
00079                 }
00080                 if (interfaceTypes[j].isFcCollectionItf() && p.startsWith(q)) {
00081                     throw new InstantiationException(
00082                         "The name of the interface '" + p + "' starts with '" +
00083                         q + "', which is the name of a collection interface");
00084                 }
00085             }
00086         }
00087     }
00088 
00092     public ProActiveComponentTypeImpl(final ComponentType componentType) {
00093         InterfaceType[] tempItfTypes = componentType.getFcInterfaceTypes();
00094         this.interfaceTypes = new InterfaceType[tempItfTypes.length];
00095         for (int i = 0; i < interfaceTypes.length; i++) {
00096             
00097             interfaceTypes[i] = new ProActiveInterfaceTypeImpl(tempItfTypes[i]);
00098         }
00099     }
00100 
00104     public InterfaceType[] getFcInterfaceTypes() {
00105         return interfaceTypes;
00106     }
00107 
00111     public InterfaceType getFcInterfaceType(String name)
00112         throws NoSuchInterfaceException {
00113         for (int i = 0; i < interfaceTypes.length; i++) {
00114             InterfaceType type = interfaceTypes[i];
00115             if (type.getFcItfName().equals(name)) {
00116                 return type;
00117             }
00118         }
00119         throw new NoSuchInterfaceException(name);
00120     }
00121 
00125     public boolean isFcSubTypeOf(Type type) {
00126         throw new RuntimeException("not yet implemented");
00127     }
00128 
00138     private static InterfaceType[] clone(final InterfaceType[] types) {
00139         if (types == null) {
00140             return new InterfaceType[0];
00141         } else {
00142             InterfaceType[] clone = new InterfaceType[types.length];
00143             System.arraycopy(types, 0, clone, 0, types.length);
00144             return clone;
00145         }
00146     }
00147 }