1 7 package com.inversoft.verge.mvc.controller.actionflow.config; 8 9 10 import java.util.Iterator ; 11 import java.util.Map ; 12 13 import org.jdom.Element; 14 15 import com.inversoft.config.ConfigurationException; 16 import com.inversoft.config.component.AbstractComponentConfigBuilder; 17 import com.inversoft.config.component.ComponentConfigBuilderRegistry; 18 import com.inversoft.error.ErrorList; 19 import com.inversoft.util.ReflectionException; 20 import com.inversoft.util.ReflectionTools; 21 import com.inversoft.util.StringTools; 22 import com.inversoft.verge.config.VergeConfigConstants; 23 import com.inversoft.verge.mvc.config.BaseFormConfig; 24 import com.inversoft.verge.mvc.config.BaseFormConfigBuilder; 25 import com.inversoft.verge.mvc.config.FormConfigRegistry; 26 import com.inversoft.verge.mvc.controller.LongTxnSetup; 27 import com.inversoft.verge.repository.config.RepositoryConfigRegistry; 28 29 30 38 public class BaseNamespaceBuilder extends AbstractComponentConfigBuilder 39 implements NamespaceBuilder { 40 41 44 public BaseNamespaceBuilder() { 45 } 46 47 48 57 public Namespace build(Element element) throws ConfigurationException { 58 59 String name = element.getAttributeValue(Constants.NAME_ATTRIBUTE); 60 String type = element.getAttributeValue(Constants.TYPE_ATTRIBUTE); 61 String errorPage = element.getAttributeValue(Constants.ERROR_PAGE_ATTRIBUTE); 62 String longTxnSetup = element.getAttributeValue(Constants.LONG_TXN_SETUP_ATTRIBUTE); 63 64 if (StringTools.isEmpty(name)) { 65 throw new ConfigurationException(Constants.NAME_ATTRIBUTE + 66 " is a required attribute of the " + Constants.NAMESPACE_ELEMENT); 67 } 68 69 if (StringTools.isEmpty(type)) { 70 type = DefaultTypes.NAMESPACE; 71 } 72 73 LongTxnSetup lts = null; 75 if (!StringTools.isEmpty(longTxnSetup)) { 76 try { 77 Class klass = ReflectionTools.findClass(longTxnSetup); 78 if (!LongTxnSetup.class.isAssignableFrom(klass)) { 79 throw new ConfigurationException("Invalid longTxnSetup" + 80 "attribute. Must reference a class of " + 81 "type com.inversoft.verge.mvc.controller.LongTxnSetup"); 82 } 83 84 lts = (LongTxnSetup) ReflectionTools.instantiate(klass); 85 } catch (ReflectionException re) { 86 throw new ConfigurationException(re); 87 } 88 } 89 90 return new BaseNamespace(name, type, errorPage, lts); 91 } 92 93 100 public void validate(Namespace namespace, ActionFlowConfigRegistry actionRegistry, 101 Map registries, ComponentConfigBuilderRegistry builderRegistry) 102 throws ConfigurationException { 103 104 RepositoryConfigRegistry repository = 106 (RepositoryConfigRegistry) registries.get(VergeConfigConstants.REPOSITORY_KEY); 107 Iterator iter = namespace.nodeIterator(); 108 Node node; 109 boolean found = false; 110 NodeBuilder nodeBuilder; 111 ErrorList errors = new ErrorList(); 112 113 while (iter.hasNext()) { 114 node = (Node) iter.next(); 115 if (node.isDefaultEntry() && found) { 116 errors.addError("Only one default entry node can be specified"); 117 } else if (node.isDefaultEntry()) { 118 found = true; 119 } 120 121 nodeBuilder = (NodeBuilder) builderRegistry.lookup( 123 ActionFlowConfigBuilder.NODE_PREFIX + node.getType()); 124 try { 125 nodeBuilder.postBuild(node, actionRegistry, repository); 126 } catch (ConfigurationException ce) { 127 errors.addErrorList(ce.getErrors()); 128 } 129 } 130 131 BaseFormConfigBuilder formBuilder = 133 (BaseFormConfigBuilder) builderRegistry.lookup( 134 com.inversoft.verge.mvc.config.Constants.FORM_BUILDER_NAME); 135 FormConfigRegistry formRegistry = 136 (FormConfigRegistry) registries.get(VergeConfigConstants.FORM_KEY); 137 iter = namespace.formIterator(); 138 BaseFormConfig formConfig; 139 while (iter.hasNext()) { 140 formConfig = (BaseFormConfig) iter.next(); 141 try { 142 formBuilder.validate(formConfig, repository, formRegistry); 143 } catch (ConfigurationException ce) { 144 errors.addErrorList(ce.getErrors()); 145 } 146 } 147 148 if (!errors.isEmpty()) { 149 throw new ConfigurationException(errors); 150 } 151 } 152 } 153 154 | Popular Tags |