KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > adl > type > FractalTypeChecker


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.adl.type;
26
27 import org.objectweb.dream.adl.AbstractDelagatingChecker;
28 import org.objectweb.fractal.adl.ADLException;
29 import org.objectweb.fractal.adl.Node;
30 import org.objectweb.fractal.adl.interfaces.Interface;
31 import org.objectweb.fractal.adl.interfaces.InterfaceContainer;
32 import org.objectweb.fractal.adl.types.TypeInterface;
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.api.type.ComponentType;
35 import org.objectweb.fractal.api.type.InterfaceType;
36
37 /**
38  * Type checker for fractal component.
39  */

40 public class FractalTypeChecker extends AbstractDelagatingChecker
41 {
42
43   /**
44    * @see AbstractDelagatingChecker#doChek(Object, Object)
45    */

46   protected void doChek(Object JavaDoc legacy, Object JavaDoc node) throws ADLException
47   {
48     ComponentType legacyType = (ComponentType) ((Component) legacy).getFcType();
49     if (node instanceof InterfaceContainer)
50     {
51       Interface[] itfs = ((InterfaceContainer) node).getInterfaces();
52       for (int i = 0; i < itfs.length; i++)
53       {
54         TypeInterface itfType = (TypeInterface) itfs[i];
55         InterfaceType legacyItfType = getLegacyInterfaceType(legacyType,
56             itfType);
57
58         if (legacyItfType.isFcClientItf() != "client".equals(itfType.getRole()))
59         {
60           throw new ADLException(
61               "Legacy interface and node interface has not the same role",
62               (Node) itfType);
63         }
64         if (legacyItfType.isFcCollectionItf() != "collection".equals(itfType
65             .getCardinality()))
66         {
67           throw new ADLException(
68               "Legacy interface and node interface has not the same cardinality",
69               (Node) itfType);
70         }
71       }
72     }
73   }
74
75   InterfaceType getLegacyInterfaceType(ComponentType legacyType,
76       TypeInterface adlType) throws ADLException
77   {
78     boolean collection = "collection".equals(adlType.getCardinality());
79     InterfaceType[] interfaceTypes = legacyType.getFcInterfaceTypes();
80     if (collection)
81     {
82       for (int i = 0; i < interfaceTypes.length; i++)
83       {
84         InterfaceType itfType = interfaceTypes[i];
85         if (adlType.getName().startsWith(itfType.getFcItfName()))
86         {
87           return itfType;
88         }
89       }
90     }
91     else
92     {
93       for (int i = 0; i < interfaceTypes.length; i++)
94       {
95         InterfaceType itfType = interfaceTypes[i];
96         if (adlType.getName().equals(itfType.getFcItfName()))
97         {
98           return itfType;
99         }
100       }
101     }
102     throw new ADLException(
103         "The legacy component has not the specified interface", (Node) adlType);
104   }
105 }
Popular Tags