1 package com.opensymphony.workflow.loader; 2 3 import java.io.PrintWriter ; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 7 import org.w3c.dom.Element ; 8 import org.w3c.dom.NodeList ; 9 import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle; 10 import com.opensymphony.workflow.designer.ResourceManager; 11 12 16 public class PaletteDescriptor extends AbstractDescriptor 17 { 18 protected List statusList = new ArrayList (); 19 protected List joinList = new ArrayList (); 20 protected List preList = new ArrayList (); 21 protected List permissionList = new ArrayList (); 22 protected List resultList = new ArrayList (); 23 protected String defaultOldStatus = null; 24 protected String defaultNextStatus = null; 25 private EnhancedResourceBundle bundle; 26 27 public PaletteDescriptor(Element root, EnhancedResourceBundle bundle) 28 { 29 this.bundle = bundle; 30 init(root); 31 } 32 33 public ConfigConditionDescriptor[] getJoinConditions() 34 { 35 ConfigConditionDescriptor[] config = new ConfigConditionDescriptor[joinList.size()]; 36 joinList.toArray(config); 37 return config; 38 } 39 40 public ConfigFunctionDescriptor[] getPreFunctions() 41 { 42 ConfigFunctionDescriptor[] array = new ConfigFunctionDescriptor[preList.size()]; 43 preList.toArray(array); 44 return array; 45 } 46 47 public PermissionConditionDescriptor[] getPermissionConditions() 48 { 49 PermissionConditionDescriptor[] array = new PermissionConditionDescriptor[permissionList.size()]; 50 permissionList.toArray(array); 51 return array; 52 } 53 54 public ConfigConditionDescriptor[] getResultConditions() 55 { 56 ConfigConditionDescriptor[] config = new ConfigConditionDescriptor[resultList.size()]; 57 resultList.toArray(config); 58 return config; 59 } 60 61 public String [] getStatusNames() 62 { 63 String [] names = new String [statusList.size()]; 64 65 for(int i = 0; i < names.length; i++) 66 { 67 StatusDescriptor status = (StatusDescriptor)statusList.get(i); 68 names[i] = status.getName(); 69 } 70 return names; 71 } 72 73 public ConfigConditionDescriptor getJoinCondition(String name) 74 { 75 if(name == null) 76 { 77 return null; 78 } 79 for(int i = 0; i < joinList.size(); i++) 80 { 81 ConfigConditionDescriptor join = (ConfigConditionDescriptor)joinList.get(i); 82 if(name.equals(join.getName())) 83 { 84 return join; 85 } 86 } 87 return null; 88 } 89 90 public ConfigFunctionDescriptor getPrefunction(String name) 91 { 92 if(name == null) 93 { 94 return null; 95 } 96 for(int i = 0; i < preList.size(); i++) 97 { 98 ConfigFunctionDescriptor pre = (ConfigFunctionDescriptor)preList.get(i); 99 if(name.equals(pre.getName())) 100 { 101 return pre; 102 } 103 } 104 return null; 105 } 106 107 public PermissionConditionDescriptor getPermissionCondition(String name) 108 { 109 if(name == null) 110 { 111 return null; 112 } 113 for(int i = 0; i < permissionList.size(); i++) 114 { 115 PermissionConditionDescriptor perm = (PermissionConditionDescriptor)permissionList.get(i); 116 if(name.equals(perm.getName())) 117 { 118 return perm; 119 } 120 } 121 return null; 122 } 123 124 public ConfigConditionDescriptor getResultCondition(String name) 125 { 126 if(name == null) 127 { 128 return null; 129 } 130 for(int i = 0; i < joinList.size(); i++) 131 { 132 ConfigConditionDescriptor result = (ConfigConditionDescriptor)resultList.get(i); 133 if(name.equals(result.getName())) 134 { 135 return result; 136 } 137 } 138 return null; 139 } 140 141 public String getDefaultOldStatus() 142 { 143 return defaultOldStatus; 144 } 145 146 public String getDefaultNextStatus() 147 { 148 return defaultNextStatus; 149 } 150 151 public void writeXML(PrintWriter writer, int indent) 152 { 153 throw new UnsupportedOperationException (); 154 } 155 156 protected void init(Element root) 157 { 158 Element s = XMLUtil.getChildElement(root, "statusvalues"); 160 defaultNextStatus = s.getAttribute("default-next"); 161 defaultOldStatus = s.getAttribute("default-old"); 162 List l = XMLUtil.getChildElements(s, "status"); 163 for(int i = 0; i < l.size(); i++) 164 { 165 Element status = (Element )l.get(i); 166 StatusDescriptor statusDescriptor = new StatusDescriptor(status); 167 statusDescriptor.setParent(this); 168 statusList.add(statusDescriptor); 169 } 170 Element j = XMLUtil.getChildElement(root, "joinconditions"); 171 if(j != null) 172 { 173 List joins = XMLUtil.getChildElements(j, "condition"); 174 for(int i = 0; i < joins.size(); i++) 175 { 176 Element condition = (Element )joins.get(i); 177 ConfigConditionDescriptor jcd = new ConfigConditionDescriptor(this, condition); 178 jcd.setDescription(bundle.getString(jcd.getName() + ".long")); 179 jcd.setDisplayName(bundle.getString(jcd.getName())); 180 jcd.setParent(this); 181 joinList.add(jcd); 182 } 183 } 184 185 Element p = XMLUtil.getChildElement(root, "functions"); 187 if(p != null) 188 { 189 List functions = XMLUtil.getChildElements(p, "function"); 190 for(int i = 0; i < functions.size(); i++) 191 { 192 Element function = (Element )functions.get(i); 193 ConfigFunctionDescriptor pd = new ConfigFunctionDescriptor(this, function); 194 pd.setDescription(bundle.getString(pd.getName() + ".long")); 195 pd.setDisplayName(bundle.getString(pd.getName())); 196 pd.setParent(this); 197 preList.add(pd); 198 } 199 } 200 201 Element pm = XMLUtil.getChildElement(root, "permissionconditions"); 203 if(pm != null) 204 { 205 List joins = XMLUtil.getChildElements(pm, "condition"); 206 for(int i = 0; i < joins.size(); i++) 207 { 208 Element condition = (Element )joins.get(i); 209 PermissionConditionDescriptor pcd = new PermissionConditionDescriptor(this, condition); 210 pcd.setDescription(bundle.getString(pcd.getName() + ".long")); 211 pcd.setDisplayName(bundle.getString(pcd.getName())); 212 pcd.setParent(this); 213 permissionList.add(pcd); 214 } 215 } 216 217 Element r = XMLUtil.getChildElement(root, "resultconditions"); 219 if(j != null) 220 { 221 List conditions = XMLUtil.getChildElements(r, "condition"); 222 for(int i = 0; i < conditions.size(); i++) 223 { 224 Element condition = (Element )conditions.get(i); 225 ConfigConditionDescriptor rcd = new ConfigConditionDescriptor(this, condition); 226 rcd.setDescription(bundle.getString(rcd.getName() + ".long")); 227 rcd.setDisplayName(bundle.getString(rcd.getName())); 228 rcd.setParent(this); 229 resultList.add(rcd); 230 } 231 } 232 233 } 234 235 public EnhancedResourceBundle getBundle() 236 { 237 return bundle; 238 } 239 } 240 | Popular Tags |