1 23 24 package org.objectweb.fractal.adl.implementations; 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.attributes.Attributes; 33 import org.objectweb.fractal.adl.attributes.AttributesContainer; 34 import org.objectweb.fractal.adl.components.Component; 35 import org.objectweb.fractal.adl.components.ComponentContainer; 36 import org.objectweb.fractal.adl.interfaces.Interface; 37 import org.objectweb.fractal.adl.interfaces.InterfaceContainer; 38 import org.objectweb.fractal.adl.types.TypeInterface; 39 40 45 46 public class ImplementationLoader extends AbstractLoader { 47 48 52 public Definition load (final String name, final Map context) 53 throws ADLException 54 { 55 Definition d = clientLoader.load(name, context); 56 checkNode(d, context); 57 return d; 58 } 59 60 64 private void checkNode (final Object node, final Map context) 65 throws ADLException 66 { 67 if (node instanceof ImplementationContainer) { 68 checkImplementationContainer((ImplementationContainer)node, context); 69 } 70 if (node instanceof ControllerContainer) { 71 checkControllerContainer((ControllerContainer)node); 72 } 73 if (node instanceof ComponentContainer) { 74 Component[] comps = ((ComponentContainer)node).getComponents(); 75 for (int i = 0; i < comps.length; i++) { 76 checkNode(comps[i], context); 77 } 78 } 79 } 80 81 private void checkImplementationContainer ( 82 final ImplementationContainer container, 83 final Map context) throws ADLException 84 { 85 Implementation impl = container.getImplementation(); 86 if (impl != null) { 87 String className = impl.getClassName(); 88 if (className == null) { 89 throw new ADLException( 90 "Implementation class name missing", (Node)impl); 91 } 92 Class c; 93 try { 94 c = getClassLoader(context).loadClass(className); 95 } catch (ClassNotFoundException e) { 96 throw new ADLException( 97 "Invalid signature '" + className + "'", (Node)impl, e); 98 } 99 if (container instanceof InterfaceContainer) { 100 Interface[] itfs = ((InterfaceContainer)container).getInterfaces(); 101 for (int i = 0; i < itfs.length; ++i) { 102 if (itfs[i] instanceof TypeInterface) { 103 TypeInterface itf = (TypeInterface)itfs[i]; 104 if (itf.getRole().equals("server")) { 105 Class d; 106 try { 107 d = getClassLoader(context).loadClass(itf.getSignature()); 108 } catch (Exception e) { 109 continue; 110 } 111 if (!d.isAssignableFrom(c)) { 112 throw new ADLException( 113 "The implementation class does not implement " + 114 "all the server interfaces of the component", 115 (Node)impl); 116 } 117 } 118 } 119 } 120 } 121 if (container instanceof AttributesContainer) { 122 Attributes attrs = ((AttributesContainer)container).getAttributes(); 123 if (attrs != null) { 124 Class d; 125 try { 126 d = getClassLoader(context).loadClass(attrs.getSignature()); 127 } catch (Exception e) { 128 return; 129 } 130 if (!d.isAssignableFrom(c)) { 131 throw new ADLException( 132 "The implementation class does not implement " + 133 "all the attribute controller interface of the component", 134 (Node)impl); 135 } 136 } 137 } 138 } 139 } 140 141 private void checkControllerContainer ( 142 final ControllerContainer container) throws ADLException 143 { 144 Controller ctrl = container.getController(); 145 if (ctrl != null) { 146 if (ctrl.getDescriptor() == null) { 147 throw new ADLException( 148 "Controller descriptor missing", (Node)ctrl); 149 } 150 } 151 } 152 } 153 | Popular Tags |