org/objectweb/proactive/core/component/type/ProActiveComponentTypeImpl.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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         // verifications
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             // deep copy
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 }

Generated on Mon Jan 22 15:16:07 2007 for ProActive by  doxygen 1.5.1