1 23 24 package org.objectweb.fractal.adl.interfaces; 25 26 import org.objectweb.fractal.adl.ADLException; 27 import org.objectweb.fractal.adl.Definition; 28 import org.objectweb.fractal.adl.AbstractLoader; 29 import org.objectweb.fractal.adl.Node; 30 import org.objectweb.fractal.adl.components.Component; 31 import org.objectweb.fractal.adl.components.ComponentContainer; 32 33 import java.util.HashSet ; 34 import java.util.Map ; 35 import java.util.Set ; 36 37 41 42 public class InterfaceLoader extends AbstractLoader { 43 44 48 public Definition load (final String name, final Map context) 49 throws ADLException 50 { 51 Definition d = clientLoader.load(name, context); 52 checkNode(d); 53 return d; 54 } 55 56 60 private void checkNode (final Object node) throws ADLException { 61 if (node instanceof InterfaceContainer) { 62 checkInterfaceContainer((InterfaceContainer)node); 63 } 64 if (node instanceof ComponentContainer) { 65 Component[] comps = ((ComponentContainer)node).getComponents(); 66 for (int i = 0; i < comps.length; i++) { 67 checkNode(comps[i]); 68 } 69 } 70 } 71 72 private void checkInterfaceContainer (final InterfaceContainer container) 73 throws ADLException 74 { 75 Set names = new HashSet (); 76 Interface[] itfs = container.getInterfaces(); 77 for (int i = 0; i < itfs.length; i++) { 78 Interface itf = itfs[i]; 79 if (itf.getName() == null) { 80 throw new ADLException("Interface name missing", (Node)itf); 81 } 82 if (names.contains(itf.getName())) { 83 throw new ADLException( 84 "Duplicate interface name '" + itf.getName() + "'", (Node)itf); 85 } else { 86 names.add(itf.getName()); 87 } 88 } 89 } 90 } 91 | Popular Tags |