KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > component > type > ProActiveComponentType


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2004 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 package org.objectweb.proactive.core.component.type;
32
33 import java.io.Serializable JavaDoc;
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 /**
44  * Implementation of ComponentType (@see org.objectweb.fractal.api.type.ComponentType)
45  *
46  * @author Matthieu Morel
47  *
48  */

49 public class ProActiveComponentType implements ComponentType, Serializable JavaDoc {
50     protected static Logger logger = Logger.getLogger(ProActiveComponentType.class.getName());
51
52     /**
53     * The types of the interfaces of components of this type.
54     */

55     private final InterfaceType[] interfaceTypes;
56
57     /**
58      * Constructor for ProActiveComponentType.
59      */

60     public ProActiveComponentType(final InterfaceType[] interfaceTypes) throws InstantiationException JavaDoc{
61         this.interfaceTypes = clone(interfaceTypes);
62         // verifications
63
for (int i = 0; i < interfaceTypes.length; ++i) {
64           String JavaDoc p = interfaceTypes[i].getFcItfName();
65           boolean collection = interfaceTypes[i].isFcCollectionItf();
66           for (int j = i + 1; j < interfaceTypes.length; ++j) {
67             String JavaDoc q = interfaceTypes[j].getFcItfName();
68             if (p.equals(q)) {
69               throw new InstantiationException JavaDoc(
70                  "Two interfaces have the same name '" + q + "'");
71             }
72             if (collection && q.startsWith(p)) {
73               throw new InstantiationException JavaDoc(
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 JavaDoc(
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     /**
87      * copy constructor
88      */

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             // deep copy
94
interfaceTypes[i] = new ProActiveInterfaceType(tempItfTypes[i]);
95         }
96     }
97
98     /**
99      * @see org.objectweb.fractal.api.type.ComponentType#getFcInterfaceTypes()
100      */

101     public InterfaceType[] getFcInterfaceTypes() {
102         return interfaceTypes;
103     }
104
105     /**
106      * @see org.objectweb.fractal.api.type.ComponentType#getFcInterfaceType(String)
107      */

108     public InterfaceType getFcInterfaceType(String JavaDoc 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     /**
119      * @see org.objectweb.fractal.api.Type#isFcSubTypeOf(Type)
120      */

121     public boolean isFcSubTypeOf(Type type) {
122         throw new RuntimeException JavaDoc("not yet implemented");
123     }
124     
125     /**
126      * Returns a copy of the given interface type array. This method is used to
127      * return a copy of the field of this class, instead of the field itself, so
128      * that its content can not be modified from outside.
129      *
130      * @param types the array to be cloned.
131      * @return a clone of the given array, or an empty array if <tt>type</tt> is
132      * <tt>null</tt>.
133      */

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