1 30 package com.genimen.djeneric.tools.scriptengine.core.nodes; 31 32 import java.util.ArrayList ; 33 import java.util.HashMap ; 34 35 import com.genimen.djeneric.tools.scriptengine.core.DjScriptParserEngine; 36 import com.genimen.djeneric.tools.scriptengine.core.SimpleNode; 37 38 public class ControllerNode extends SimpleNode 39 { 40 41 public ControllerNode(int i) 42 { 43 super(i); 44 } 45 46 public ControllerNode(DjScriptParserEngine p, int i) 47 { 48 super(p, i); 49 } 50 51 public String getName() 52 { 53 return "controller"; 54 } 55 56 public String getNodeTitle() 57 { 58 return "Controller"; 59 } 60 61 public String toString() 62 { 63 return getName(); 64 } 65 66 HashMap _mappings = null; 67 68 public String [] getActionsForEvent(String eventName) 69 { 70 if (_mappings == null) 71 { 72 _mappings = new HashMap (); 73 ArrayList m = getChildren(EventMappingNode.class); 74 75 for (int i = 0; i < m.size(); i++) 76 { 77 EventMappingNode em = (EventMappingNode) m.get(i); 78 ArrayList actions = (ArrayList ) _mappings.get(em.getPath()); 79 80 if (actions == null) 81 { 82 actions = new ArrayList (); 83 String path = em.getPath(); 84 if ("*.*".equals(path)) path = "*"; 85 86 _mappings.put(path, actions); 87 } 88 89 ArrayList allActions = em.getActions(); 90 91 for (int aa = 0; aa < allActions.size(); aa++) 92 { 93 actions.add(allActions.get(aa).toString()); 94 } 95 } 96 } 97 98 103 ArrayList result = new ArrayList (); 104 105 ArrayList globals = (ArrayList ) _mappings.get("*"); 106 if (globals != null) result.addAll(globals); 107 108 int idx = eventName.indexOf('.'); 109 if (idx != -1) 110 { 111 String left = eventName.substring(0, idx); 112 String right = eventName.substring(idx + 1); 113 114 ArrayList all = (ArrayList ) _mappings.get("*." + right); 115 if (all != null) result.addAll(all); 116 117 all = (ArrayList ) _mappings.get(left + ".*"); 118 if (all != null) result.addAll(all); 119 } 120 121 ArrayList specific = (ArrayList ) _mappings.get(eventName); 122 if (specific != null) result.addAll(specific); 123 124 return (String []) result.toArray(new String [0]); 125 } 126 } | Popular Tags |