1 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 40 public class FractalTypeChecker extends AbstractDelagatingChecker 41 { 42 43 46 protected void doChek(Object legacy, Object 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 |