1 24 25 package org.objectweb.dream.adl.legacy; 26 27 import java.util.Map ; 28 29 import org.objectweb.dream.adl.Checker; 30 import org.objectweb.dream.adl.Resolver; 31 import org.objectweb.fractal.adl.ADLException; 32 import org.objectweb.fractal.adl.AbstractLoader; 33 import org.objectweb.fractal.adl.Definition; 34 import org.objectweb.fractal.adl.Node; 35 import org.objectweb.fractal.adl.components.Component; 36 import org.objectweb.fractal.adl.components.ComponentContainer; 37 38 41 public class LegacyLoader extends AbstractLoader 42 { 43 44 45 public static final String CHECKER_ITF_NAME = "checker"; 46 47 48 public static final String RESOLVER_ITF_NAME = "resolver"; 49 50 private Checker checkerItf; 51 52 private Resolver resolverItf; 53 54 57 public Definition load(final String name, final Map context) 58 throws ADLException 59 { 60 Object legacy = context.get("legacy:./"); 61 if (legacy == null) 62 { 63 throw new ADLException("Unable to find legacy component in context", null); 64 } 65 Definition d = clientLoader.load(name, context); 66 checkNode((Node) d, legacy, "legacy:./", context); 67 return d; 68 } 69 70 private void checkNode(final Node node, final Object legacy, 71 final String path, final Map context) throws ADLException 72 { 73 if (legacy != null) 74 { 75 checkerItf.check(legacy, node); 76 node.astSetDecoration("legacy", legacy); 77 } 78 if (node instanceof ComponentContainer) 79 { 80 ComponentContainer container = (ComponentContainer) node; 81 Component[] tab = container.getComponents(); 82 for (int i = 0; i < tab.length; i++) 83 { 84 Component subComponent = tab[i]; 85 String componentPath = (path.endsWith("/")) ? path 86 + subComponent.getName() : path + "/" + subComponent.getName(); 87 Object subLegacy = null; 88 if (subComponent instanceof LegacyContainer) 89 { 90 Legacy l = ((LegacyContainer) subComponent).getLegacy(); 92 if (l != null) 93 { 94 subLegacy = context.get(componentPath); 95 if (subLegacy == null && legacy != null) 96 { 97 if ("mandatory".equals(l.getContingency())) 98 { 99 try 100 { 101 subLegacy = resolverItf.resolve(legacy, subComponent 102 .getName(), context); 103 } 104 catch (ComponentNotFoundException e) 105 { 106 throw new ADLException( 107 "Unable to find mandatory legacy component.", 108 (Node) subComponent, e); 109 } 110 } 111 else if ("optionnal".equals(l.getContingency())) 112 { 113 try 114 { 115 subLegacy = resolverItf.resolve(legacy, subComponent 116 .getName(), context); 117 } 118 catch (ComponentNotFoundException e) 119 { 120 break; 122 } 123 } 124 } 125 } 126 } 127 checkNode((Node) subComponent, subLegacy, componentPath, context); 128 } 129 } 130 } 132 133 137 140 public String [] listFc() 141 { 142 return new String []{LOADER_BINDING, CHECKER_ITF_NAME, RESOLVER_ITF_NAME}; 143 } 144 145 148 public Object lookupFc(String s) 149 { 150 if (CHECKER_ITF_NAME.equals(s)) 151 { 152 return checkerItf; 153 } 154 else if (RESOLVER_ITF_NAME.equals(s)) 155 { 156 return resolverItf; 157 } 158 else 159 { 160 return super.lookupFc(s); 161 } 162 } 163 164 168 public void bindFc(String s, Object o) 169 { 170 if (CHECKER_ITF_NAME.equals(s)) 171 { 172 checkerItf = (Checker) o; 173 } 174 else if (RESOLVER_ITF_NAME.equals(s)) 175 { 176 resolverItf = (Resolver) o; 177 } 178 else 179 { 180 super.bindFc(s, o); 181 } 182 } 183 184 187 public void unbindFc(String s) 188 { 189 if (CHECKER_ITF_NAME.equals(s)) 190 { 191 checkerItf = null; 192 } 193 else if (RESOLVER_ITF_NAME.equals(s)) 194 { 195 resolverItf = null; 196 } 197 else 198 { 199 super.unbindFc(s); 200 } 201 } 202 203 } | Popular Tags |