1 4 package com.nightlabs.ipanema.store; 5 6 import java.io.Serializable ; 7 8 import com.nightlabs.inheritance.NotWritableException; 9 10 20 public class ProductFieldMetaData 21 implements 22 com.nightlabs.inheritance.FieldMetaData, 23 Serializable 24 { 25 29 private String organisationID; 30 31 35 private String productID; 36 37 41 private String fieldName; 42 43 private Product product; 44 45 48 private byte writableByChildren = ProductFieldMetaData.WRITABLEBYCHILDREN_YES; 49 50 54 private boolean writable = true; 55 56 60 private boolean valueInherited = true; 61 62 protected ProductFieldMetaData() { } 63 public ProductFieldMetaData(Product product, String fieldName) 64 { 65 setProduct(product); 66 setFieldName(fieldName); 67 } 68 69 72 public String getOrganisationID() 73 { 74 return organisationID; 75 } 76 77 80 public String getProductID() 81 { 82 return productID; 83 } 84 85 88 public String getFieldName() 89 { 90 return fieldName; 91 } 92 95 protected void setFieldName(String fieldName) 96 { 97 this.fieldName = fieldName; 98 } 99 100 103 public Product getProduct() 104 { 105 return product; 106 } 107 110 protected void setProduct(Product product) 111 { 112 if (product == null) 113 throw new NullPointerException ("product must not be null!"); 114 if (product.getOrganisationID() == null) 115 throw new NullPointerException ("product.organisationID must not be null!"); 116 if (product.getProductID() == null) 117 throw new NullPointerException ("product.productID must not be null!"); 118 this.organisationID = product.getOrganisationID(); 119 this.productID = product.getProductID(); 120 this.product = product; 121 } 122 123 126 public byte getWritableByChildren() 127 { 128 return writableByChildren; 129 } 130 133 public void setWritableByChildren(byte writableByChildren) 134 { 135 this.writableByChildren = writableByChildren; 136 } 137 138 141 public boolean isWritable() 142 { 143 return writable; 144 } 145 148 public void setWritable(boolean writable) 149 { 150 this.writable = writable; 151 } 152 155 public void assertWritable() throws NotWritableException 156 { 157 if (!isWritable()) 158 throw new NotWritableException("Field \""+getFieldName()+"\" is not writeable!"); 159 } 160 161 164 public boolean isValueInherited() 165 { 166 return valueInherited; 167 } 168 171 public void setValueInherited(boolean valueInherited) 172 { 173 if (!writable && !valueInherited) 174 throw new IllegalStateException ("The field is not writable, thus the value must be inherited. Cannot set valueInherited to false!"); 175 176 this.valueInherited = valueInherited; 177 } 178 179 } 180 | Popular Tags |