1 7 package com.inversoft.verge.mvc.model.web; 8 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 import com.inversoft.beans.BeanException; 14 import com.inversoft.verge.mvc.MVCConstants; 15 import com.inversoft.verge.mvc.MVCException; 16 import com.inversoft.verge.mvc.MVCRegistry; 17 import com.inversoft.verge.mvc.model.AbstractMetaData; 18 import com.inversoft.verge.mvc.model.ModelHandler; 19 import com.inversoft.verge.util.ScopeTools; 20 import com.inversoft.verge.util.WebBean; 21 import com.inversoft.verge.util.WebBeanProperty; 22 23 24 36 public class WebMetaData extends AbstractMetaData { 37 38 42 public static final String CLASS_PARAMETER = "class"; 43 44 48 public static final String SCOPE_PARAMETER = "scope"; 49 50 private int scope; 51 private Class klass; 52 53 54 63 public WebMetaData(String definition, Map parameters) throws MVCException { 64 super(definition); 65 66 assert (parameters != null) : "parameters == null"; 67 68 String className = (String ) parameters.get(CLASS_PARAMETER); 69 try { 70 klass = Class.forName(className); 71 } catch (ClassNotFoundException cnfe) { 72 throw new MVCException("Invalid class: " + className); 73 } 74 75 String scopeStr = (String ) parameters.get(SCOPE_PARAMETER); 76 assert (scopeStr != null) : "scope not found in map"; 77 try { 78 scope = Integer.parseInt(scopeStr); 79 } catch (NumberFormatException nfe) { 80 assert (false) : "Invalid scope int: " + scopeStr; 81 } 82 } 83 84 93 public WebMetaData(String id, String property, String className, 94 int scope) 95 throws MVCException { 96 super(id, property); 97 assert (property != null) : "property == null"; 98 assert (className != null) : "className == null"; 99 assert (ScopeTools.isValidScope(scope)) : "Invalid scope int"; 100 101 this.scope = scope; 102 103 try { 104 this.klass = Class.forName(className); 105 } catch (ClassNotFoundException cnfe) { 106 throw new MVCException("Invalid class: " + className); 107 } 108 } 109 110 120 public WebMetaData(String id, String className, int scope) 121 throws MVCException { 122 super(id, null); 123 assert (id != null) : "id == null"; 124 assert (className != null) : "className == null"; 125 assert (ScopeTools.isValidScope(scope)) : "Invalid scope int"; 126 127 super.id = id; 128 this.scope = scope; 129 130 try { 131 this.klass = Class.forName(className); 132 } catch (ClassNotFoundException cnfe) { 133 throw new MVCException("Invalid class: " + className); 134 } 135 } 136 137 138 143 public void setProperty(String property) { 144 super.property = property; 145 } 146 147 152 public Class getModelClass() { 153 return klass; 154 } 155 156 161 public int getScope() { 162 return scope; 163 } 164 165 171 public Map getExtraParams() { 172 Map map = new HashMap (); 173 map.put(SCOPE_PARAMETER, Integer.toString(scope)); 174 map.put(CLASS_PARAMETER, klass.getName()); 175 176 return map; 177 } 178 179 183 public WebBean createWebBean() throws BeanException { 184 return new WebBean(id, scope, klass); 185 } 186 187 191 public WebBeanProperty createWebBeanProperty() throws BeanException { 192 assert (property != null) : "property == null"; 193 return new WebBeanProperty(getDefinition(), scope, klass); 194 } 195 196 202 public ModelHandler getModelHandler() { 203 return MVCRegistry.lookupModelHandler(MVCConstants.WEB_NAME); 204 } 205 206 211 public String getModelSystem() { 212 return MVCConstants.WEB_NAME; 213 } 214 } | Popular Tags |