1 4 package com.nightlabs.ipanema.accounting; 5 6 import java.io.Serializable ; 7 import java.util.Collection ; 8 import java.util.HashMap ; 9 import java.util.HashSet ; 10 import java.util.Map ; 11 import java.util.Set ; 12 13 import com.nightlabs.inheritance.FieldInheriter; 14 import com.nightlabs.inheritance.FieldMetaData; 15 import com.nightlabs.inheritance.Inheritable; 16 import com.nightlabs.ipanema.store.Product; 17 18 32 public class ProductInfo implements Inheritable, Serializable 33 { 34 38 private String organisationID; 39 40 44 private String productID; 45 46 49 private Product product; 50 51 54 private ProductInfo extendedProductInfo; 55 56 59 private PriceConfig priceConfig = null; 60 61 76 private Map packagedProductInfos = new HashMap (); 77 78 81 96 protected Map fieldMetaDataMap = new HashMap (); 97 98 protected ProductInfo() { } 99 public ProductInfo(Product product, ProductInfo extendedProductInfo) 100 { 101 if (product == null) 102 throw new NullPointerException ("product must not be null!"); 103 this.organisationID = product.getOrganisationID(); 104 this.productID = product.getProductID(); 105 this.product = product; 106 setExtendedProductInfo(extendedProductInfo); 107 } 108 109 115 private ProductInfoFactory productInfoFactory; 116 117 120 public String getOrganisationID() 121 { 122 return organisationID; 123 } 124 127 public String getProductID() 128 { 129 return productID; 130 } 131 134 public ProductInfo getExtendedProductInfo() 135 { 136 return extendedProductInfo; 137 } 138 141 protected void setExtendedProductInfo(ProductInfo extendedProductInfo) 142 { 143 if (extendedProductInfo != null) { 144 if (!(extendedProductInfo.getClass().isInstance(this))) 145 throw new IllegalArgumentException ("This productInfo (\""+this.getPrimaryKey()+"\") is of type " + this.getClass().getName() + " and cannot extend the productInfo \""+extendedProductInfo.getPrimaryKey()+"\" which is of type "+extendedProductInfo.getClass().getName()); 146 } 147 148 this.extendedProductInfo = extendedProductInfo; 149 } 150 151 public void addPackagedProductInfo(ProductInfo productInfo) 152 { 153 packagedProductInfos.put(productInfo.getPrimaryKey(), productInfo); 154 } 155 public Collection getPackagedProductInfos() 156 { 157 return packagedProductInfos.values(); 158 } 159 public ProductInfo getPackagedProductInfo(String productPK, boolean throwExceptionIfNotExistent) 160 { 161 ProductInfo res = (ProductInfo)packagedProductInfos.get(productPK); 162 if (res == null && throwExceptionIfNotExistent) 163 throw new IllegalArgumentException ("No packaged ProductInfo existing with productPK=\""+productPK+"\"!"); 164 return res; 165 } 166 public ProductInfo getPackagedProductInfo(String organisationID, String productID, boolean throwExceptionIfNotExistent) 167 { 168 ProductInfo res = (ProductInfo)packagedProductInfos.get(getPrimaryKey(organisationID, productID)); 169 if (res == null && throwExceptionIfNotExistent) 170 throw new IllegalArgumentException ("No packaged ProductInfo existing with organisationID=\""+organisationID+"\", productID=\""+productID+"\"!"); 171 return res; 172 } 173 178 public void removePackagedProductInfo(String organisationID, String productID) 179 { 180 packagedProductInfos.remove(getPrimaryKey(organisationID, productID)); 181 } 182 183 public static String getPrimaryKey(String organisationID, String productID) 184 { 185 return organisationID + '/' + productID; 186 } 187 public String getPrimaryKey() 188 { 189 return organisationID + '/' + productID; 190 } 191 192 197 public Product getProduct() 198 { 199 return product; 200 } 201 202 205 public PriceConfig getPriceConfig() 206 { 207 return priceConfig; 208 } 209 212 public void setPriceConfig(PriceConfig priceConfig) 213 { 214 this.priceConfig = priceConfig; 215 } 216 217 220 public ProductInfoFactory getProductInfoFactory() 221 { 222 return productInfoFactory; 223 } 224 227 public void setProductInfoFactory(ProductInfoFactory productInfoFactory) 228 { 229 this.productInfoFactory = productInfoFactory; 230 } 231 232 private static Set nonInheritableFields = new HashSet (); 234 235 238 public FieldMetaData getFieldMetaData(String fieldName) 239 { 240 if (fieldName.startsWith("jdo")) 241 return null; 242 243 synchronized (nonInheritableFields) { 244 if (nonInheritableFields.isEmpty()) { 245 nonInheritableFields.add("organisationID"); 246 nonInheritableFields.add("productID"); 247 nonInheritableFields.add("extendedProduct"); 248 nonInheritableFields.add("nature"); 249 nonInheritableFields.add("fieldMetaDataMap"); 250 nonInheritableFields.add("names"); 251 } 252 if (nonInheritableFields.contains(fieldName)) 253 return null; 254 } 255 256 ProductInfoFieldMetaData fmd = (ProductInfoFieldMetaData)fieldMetaDataMap.get(fieldName); 257 if (fmd == null) { 258 if ("properties".equals(fieldName) || "packagedProducts".equals(fieldName)) 259 fmd = new MapFieldMetaData(this, fieldName); 260 else 261 fmd = new ProductInfoFieldMetaData(this, fieldName); 262 263 fieldMetaDataMap.put(fieldName, fmd); 264 } 266 return fmd; 267 } 268 271 public FieldInheriter getFieldInheriter(String fieldName) 272 { 273 return null; 275 } 276 } 278 | Popular Tags |