1 23 24 package org.objectweb.fractal.adl.arguments; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.util.StringTokenizer ; 32 33 import org.objectweb.fractal.adl.ADLException; 34 import org.objectweb.fractal.adl.Definition; 35 import org.objectweb.fractal.adl.components.ComponentLoader; 36 37 public class ArgumentComponentLoader extends ComponentLoader { 38 39 public Definition load ( 40 final List loaded, 41 final String name, 42 final Map context) throws ADLException 43 { 44 String n = name; 45 Map c = context; 46 int i = name.indexOf('('); 47 if (i != -1) { 48 if (!name.endsWith(")")) { 49 throw new ADLException("Syntax error in definition name", null); 50 } 51 52 n = name.substring(0, i); 53 c = new HashMap (); 54 Iterator j = context.keySet().iterator(); 55 while (j.hasNext()) { 56 String key = (String )j.next(); 57 if (!key.startsWith(" arg ")) { 58 c.put(key, context.get(key)); 59 } 60 } 61 62 String args = name.substring(i + 1, name.length() - 1); 63 StringTokenizer st = new StringTokenizer (args, ","); 64 i = 0; 65 while (st.hasMoreTokens()) { 66 c.put(" arg " + (i++), st.nextToken()); 67 } 68 } 69 return super.load(loaded, n, c); 70 } 71 72 public List parseDefinitions (String nameList) { 73 List l = new ArrayList (); 74 int c = nameList.lastIndexOf('('); 75 int p = c == -1 ? nameList.lastIndexOf(',') : nameList.lastIndexOf(',', c); 76 while (p != -1) { 77 l.add(0, nameList.substring(p+1)); 78 nameList = nameList.substring(0, p); 79 c = nameList.lastIndexOf('('); 80 p = c == -1 ? nameList.lastIndexOf(',') : nameList.lastIndexOf(',', c); 81 } 82 l.add(0, nameList); 83 return l; 84 } 85 86 public boolean isShared (String definition) { 87 return definition.indexOf('/') != -1 && definition.indexOf('(') == -1; 88 } 89 } 90 | Popular Tags |