1 23 24 package org.objectweb.fractal.adl.types; 25 26 import java.util.Map ; 27 28 import org.objectweb.fractal.adl.ADLException; 29 import org.objectweb.fractal.adl.Definition; 30 import org.objectweb.fractal.adl.AbstractLoader; 31 import org.objectweb.fractal.adl.Node; 32 import org.objectweb.fractal.adl.components.Component; 33 import org.objectweb.fractal.adl.components.ComponentContainer; 34 import org.objectweb.fractal.adl.components.ComponentDefinition; 35 import org.objectweb.fractal.adl.interfaces.Interface; 36 import org.objectweb.fractal.adl.interfaces.InterfaceContainer; 37 38 43 44 public class TypeLoader extends AbstractLoader { 45 46 50 public Definition load (final String name, final Map context) 51 throws ADLException 52 { 53 Definition d = clientLoader.load(name, context); 54 boolean extend = false; 55 if (d instanceof ComponentDefinition) { 56 extend = ((ComponentDefinition)d).getExtends() != null; 57 } 58 checkNode(d, extend, context); 59 return d; 60 } 61 62 66 private void checkNode ( 67 final Object node, 68 final boolean extend, 69 final Map context) throws ADLException 70 { 71 if (node instanceof InterfaceContainer) { 72 checkInterfaceContainer((InterfaceContainer)node, extend, context); 73 } 74 if (node instanceof ComponentContainer) { 75 Component[] comps = ((ComponentContainer)node).getComponents(); 76 for (int i = 0; i < comps.length; i++) { 77 checkNode(comps[i], extend, context); 78 } 79 } 80 } 81 82 private void checkInterfaceContainer ( 83 final InterfaceContainer container, 84 final boolean extend, 85 final Map context) throws ADLException 86 { 87 Interface[] itfs = container.getInterfaces(); 88 for (int i = 0; i < itfs.length; i++) { 89 Interface itf = itfs[i]; 90 if (itf instanceof TypeInterface) { 91 String signature = ((TypeInterface)itf).getSignature(); 92 if (signature == null) { 93 if (!extend) { 94 throw new ADLException("Signature missing", (Node)itf); 95 } 96 } else { 97 try { 98 getClassLoader(context).loadClass(signature); 99 } catch (ClassNotFoundException e) { 100 throw new ADLException( 101 "Invalid signature '" + signature + "'", (Node)itf, e); 102 } 103 } 104 String role = ((TypeInterface)itf).getRole(); 105 if (role == null) { 106 if (!extend) { 107 throw new ADLException("Role missing", (Node)itf); 108 } 109 } else { 110 if (!role.equals("client") && !role.equals("server")) { 111 throw new ADLException("Invalid role '" + role + "'", (Node)itf); 112 } 113 } 114 String contingency = ((TypeInterface)itf).getContingency(); 115 if (contingency != null) { 116 if (!contingency.equals("mandatory") && !contingency.equals("optional")) { 117 throw new ADLException("Invalid contingency '" + contingency + "'", (Node)itf); 118 } 119 } 120 String cardinality = ((TypeInterface)itf).getCardinality(); 121 if (cardinality != null) { 122 if (!cardinality.equals("singleton") && !cardinality.equals("collection")) { 123 throw new ADLException("Invalid cardinality '" + cardinality + "'", (Node)itf); 124 } 125 } 126 } 127 } 128 } 129 } 130 | Popular Tags |