1 7 package com.inversoft.verge.repository; 8 9 10 import javax.servlet.http.HttpServletRequest ; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.util.StringTools; 14 import com.inversoft.util.typeconverter.TypeConversionException; 15 import com.inversoft.verge.repository.config.Config; 16 import com.inversoft.verge.util.WebBean; 17 import com.inversoft.verge.util.WebBeanProperty; 18 19 20 35 public class RepositoryBeanProperty extends WebBeanProperty { 36 37 String repositoryProperty; 38 39 40 57 public RepositoryBeanProperty(String repositoryProperty, 58 HttpServletRequest request) 59 throws BeanException { 60 super(); 62 assert (!StringTools.isEmpty(repositoryProperty)) : 63 "repositoryProperty is null or empty"; 64 65 int index = repositoryProperty.indexOf("."); 66 if (index == -1) { 67 throw new BeanException("Invalid repository property String"); 68 } 69 70 initialize(repositoryProperty.substring(0, index), 71 repositoryProperty.substring(index + 1), request); 72 73 this.repositoryProperty = repositoryProperty; 74 } 75 76 87 public RepositoryBeanProperty(String id, String property, 88 HttpServletRequest request) 89 throws BeanException { 90 super(); 92 assert (!StringTools.isEmpty(id)) : "id is null or empty"; 93 assert (!StringTools.isEmpty(property)) : "property is null or empty"; 94 95 initialize(id, property, request); 96 this.repositoryProperty = id + "." + property; 97 } 98 99 100 101 protected void initialize(String id, String property, 102 HttpServletRequest request) 103 throws BeanException { 104 propertyName = property; 105 106 try { 108 Config config = Repository.getInstance().lookupConfig(request, id); 109 if (config == null) { 110 throw new BeanException("Invalid repository id '" + id + "'"); 111 } 112 113 beanClass = config.getJavaBean().getBeanClass(); 114 webBean = new WebBean(id, config.getScope(), beanClass); 115 } catch (RepositoryException re) { 116 throw new BeanException(re.toString()); 117 } 118 119 super.initialize(); 120 } 121 122 125 public String getRepositoryId() { 126 return webBean.getID(); 127 } 128 129 133 public String getFullName() { 134 return repositoryProperty; 135 } 136 137 147 public Object getPropertyValue(HttpServletRequest request) throws BeanException { 148 149 Repository rep = Repository.getInstance(); 152 if (!rep.isItemLoaded(request, webBean.getID())) { 153 rep.lookupItem(request, webBean.getID()); 154 } 155 156 return super.getPropertyValue(request); 157 } 158 159 175 public void setPropertyValue(HttpServletRequest request, Object value, 176 boolean convert) 177 throws BeanException, TypeConversionException { 178 179 assert (request != null) : "request == null"; 180 181 Repository rep = Repository.getInstance(); 184 if (!rep.isItemLoaded(request, webBean.getID())) { 185 rep.lookupItem(request, webBean.getID()); 186 } 187 super.setPropertyValue(request, value, convert); 188 } 189 190 210 public void setPropertyValue(HttpServletRequest request, Object value) 211 throws BeanException, TypeConversionException { 212 213 assert (request != null) : "request == null"; 214 215 Repository rep = Repository.getInstance(); 218 if (!rep.isItemLoaded(request, webBean.getID())) { 219 rep.lookupItem(request, webBean.getID()); 220 } 221 super.setPropertyValue(request, value, true); 222 } 223 } | Popular Tags |