1 7 package com.inversoft.verge.mvc.controller.form.config; 8 9 10 import org.jdom.Element; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.config.ConfigurationException; 14 import com.inversoft.error.ErrorList; 15 import com.inversoft.util.StringTools; 16 import com.inversoft.verge.mvc.config.BaseConfig; 17 import com.inversoft.verge.mvc.config.BaseConfigBuilder; 18 import com.inversoft.verge.mvc.controller.WebBeanHandle; 19 import com.inversoft.verge.mvc.controller.form.FormMVCConstants; 20 import com.inversoft.verge.mvc.controller.form.FormWebBeanHandle; 21 import com.inversoft.verge.repository.RepositoryBean; 22 import com.inversoft.verge.repository.config.Config; 23 import com.inversoft.verge.repository.config.RepositoryConfigRegistry; 24 import com.inversoft.verge.util.ScopeConstants; 25 26 27 33 public class ActionConfigBuilder extends BaseConfigBuilder { 34 35 36 39 public ActionConfigBuilder() { 40 } 41 42 43 52 public BaseConfig build(Element element) throws ConfigurationException { 53 54 ErrorList errors = new ErrorList(); 55 String name = element.getAttributeValue(Constants.NAME_ATTRIBUTE); 56 String isRepository = element.getAttributeValue( 57 Constants.IS_REPOSITORY_ATTRIBUTE); 58 String handler = element.getAttributeValue(Constants.HANDLER_ATTRIBUTE); 59 String modelEnabled = element.getAttributeValue( 60 Constants.MODEL_ENABLED_ATTRIBUTE); 61 String validationEnabled = element.getAttributeValue( 62 Constants.VALIDATION_ENABLED_ATTRIBUTE); 63 String longTxnEnabled = element.getAttributeValue( 64 Constants.LONG_TXN_ENABLED_ATTRIBUTE); 65 String longTxnStartURL = element.getAttributeValue( 66 Constants.LONG_TXN_START_URL_ATTRIBUTE); 67 String longTxnEndURL = element.getAttributeValue( 68 Constants.LONG_TXN_END_URL_ATTRIBUTE); 69 String longTxnCategory = element.getAttributeValue( 70 Constants.LONG_TXN_CATEGORY_ATTRIBUTE); 71 72 if (name == null) { 73 errors.addError("Actions must have a name"); 74 } 75 76 if (handler == null) { 77 errors.addError("The action named: " + name + 78 " must have a handler definition"); 79 } 80 81 boolean isRepositoryBool = false; 82 if (isRepository != null && !StringTools.isValidBoolean(isRepository)) { 83 errors.addError("The action named: " + name + 84 " has an invalid value for the isRepository attribute"); 85 } else if (isRepository != null) { 86 isRepositoryBool = Boolean.valueOf(isRepository).booleanValue(); 87 } 88 89 boolean isModelEnabled = true; 90 if (modelEnabled != null && !StringTools.isValidBoolean(modelEnabled)) { 91 errors.addError("The action named: " + name + 92 " has an invalid value for the modelEnabled attribute"); 93 } else if (modelEnabled != null) { 94 isModelEnabled = Boolean.valueOf(modelEnabled).booleanValue(); 95 } 96 97 boolean isValidationEnabled = true; 98 if (validationEnabled != null && 99 !StringTools.isValidBoolean(validationEnabled)) { 100 errors.addError("The action named: " + name + 101 " has an invalid value for the validationEnabled attribute"); 102 } else if (validationEnabled != null) { 103 isValidationEnabled = Boolean.valueOf(validationEnabled).booleanValue(); 104 } 105 106 boolean isLongTxnEnabled = false; 107 if (longTxnEnabled != null && 108 !StringTools.isValidBoolean(longTxnEnabled)) { 109 errors.addError("The action named: " + name + 110 " has an invalid value for the longTxnEnabled attribute"); 111 } else if (longTxnEnabled != null) { 112 isLongTxnEnabled = Boolean.valueOf(longTxnEnabled).booleanValue(); 113 } 114 115 WebBeanHandle handle = null; 116 117 if (errors.isEmpty()) { 118 if (!isRepositoryBool) { 119 try { 120 handle = new FormWebBeanHandle( 121 FormMVCConstants.ACTION_HANDLER_REQUEST_KEY, name, 122 ScopeConstants.REQUEST_INT, handler); 123 } catch (BeanException be) { 124 errors.addError(be.getMessage()); 125 } 126 } 127 } 128 129 if (!errors.isEmpty()) { 130 throw new ConfigurationException(errors); 131 } 132 133 ActionConfig config = null; 134 if (handle != null) { 135 config = new ActionConfig(name, handle, isModelEnabled, 136 isValidationEnabled, isLongTxnEnabled, longTxnStartURL, 137 longTxnEndURL, longTxnCategory); 138 } else { 139 config = new ActionConfig(name, handler, isModelEnabled, 140 isValidationEnabled, isLongTxnEnabled, longTxnStartURL, 141 longTxnEndURL, longTxnCategory); 142 } 143 144 return config; 145 } 146 147 157 public void validate(ActionConfig config, RepositoryConfigRegistry registry) 158 throws ConfigurationException { 159 160 if (config.getHandle() != null) { 162 return; 163 } 164 165 ErrorList errors = new ErrorList(); 166 String handleRID = config.getHandleRID(); 167 Config repositoryConfig = registry.lookup(handleRID); 168 169 if (repositoryConfig == null) { 170 errors.addError("Invalid repository id: " + handleRID); 171 } else { 172 173 try { 174 config.setHandle(new WebBeanHandle(new RepositoryBean(repositoryConfig), config.getName())); 175 } catch (BeanException be) { 176 errors.addError(be.getMessage()); 177 } 178 } 179 180 if (!errors.isEmpty()) { 181 throw new ConfigurationException(errors); 182 } 183 } 184 } 185 | Popular Tags |