1 5 6 package org.infohazard.maverick.flow; 7 8 import java.util.HashMap ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 import java.util.Map ; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.infohazard.maverick.util.XML; 16 import org.jdom.Element; 17 18 22 abstract class ViewRegistry 23 { 24 29 public static final String ANONYMOUS_VIEW_NAME = "anonymous view"; 30 31 33 protected static final String TAG_VIEW = "view"; 34 protected static final String ATTR_VIEW_ID = "id"; 35 protected static final String ATTR_VIEW_MODE = "mode"; 36 protected static final String ATTR_VIEW_NAME = "name"; 37 protected static final String ATTR_VIEW_REF = "ref"; 38 39 42 private static Log log = LogFactory.getLog(ViewRegistry.class); 43 44 46 protected MasterFactory masterFact; 47 48 50 public ViewRegistry(MasterFactory masterFact) 51 { 52 this.masterFact = masterFact; 53 } 54 55 57 public void defineGlobalViews(Element viewsNode) throws ConfigException 58 { 59 String defaultMode = viewsNode.getAttributeValue(ATTR_VIEW_MODE); 60 61 Iterator it = viewsNode.getChildren(TAG_VIEW).iterator(); 62 while (it.hasNext()) 63 { 64 Element viewNode = (Element)it.next(); 65 66 String id = viewNode.getAttributeValue(ATTR_VIEW_ID); 67 String mode = viewNode.getAttributeValue(ATTR_VIEW_MODE); 68 if (mode == null) 69 mode = defaultMode; 70 71 View v = this.masterFact.createView(viewNode); 72 73 this.defineGlobalView(id, mode, v); 74 } 75 } 76 77 82 public Map createViewsMap(List viewNodes) throws ConfigException 83 { 84 Map result = new HashMap (); 85 86 Iterator it = viewNodes.iterator(); 87 while (it.hasNext()) 88 { 89 Element viewNode = (Element)it.next(); 90 91 String viewName = viewNode.getAttributeValue(ATTR_VIEW_NAME); 92 String ref = viewNode.getAttributeValue(ATTR_VIEW_REF); 93 94 if (viewName == null) 96 viewName = ref; 97 98 if (viewName == null) 100 { 101 if (viewNodes.size() > 1) 102 throw new ConfigException("You cannot have views without names if there are more than one: " + XML.toString(viewNode)); 103 else 104 viewName = ANONYMOUS_VIEW_NAME; 105 106 log.info("Has single unnamed view"); 107 } 108 else 109 { 110 log.info("Has view named: " + viewName); 111 } 112 113 if (ref != null) 115 { 116 this.addView(result, viewName, ref); 117 } 118 else { 120 String mode = viewNode.getAttributeValue(ATTR_VIEW_MODE); 121 122 View v = this.masterFact.createView(viewNode); 123 124 this.addView(result, viewName, mode, v); 125 } 126 } 127 128 if (result.isEmpty()) 129 throw new ConfigException("No views defined."); 130 131 return result; 132 } 133 134 140 abstract protected void defineGlobalView(String id, String mode, View v) throws ConfigException; 141 142 145 abstract protected void addView(Map target, String viewName, String ref) throws ConfigException; 146 147 152 abstract protected void addView(Map target, String viewName, String mode, View v) throws ConfigException; 153 } | Popular Tags |