KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > store > ProductFieldMetaData


1 /*
2  * Created on 17.10.2004
3  */

4 package com.nightlabs.ipanema.store;
5
6 import java.io.Serializable JavaDoc;
7
8 import com.nightlabs.inheritance.NotWritableException;
9
10 /**
11  * @author Marco Schulze - marco at nightlabs dot de
12  *
13  * @jdo.persistence-capable
14  * identity-type = "application"
15  * objectid-class = "com.nightlabs.ipanema.store.id.ProductFieldMetaDataID"
16  * detachable = "true"
17  *
18  * @jdo.inheritance strategy = "new-table"
19  */

20 public class ProductFieldMetaData
21     implements
22         com.nightlabs.inheritance.FieldMetaData,
23         Serializable JavaDoc
24 {
25     /**
26      * @jdo.field primary-key="true"
27      * @jdo.column length="100"
28      */

29     private String JavaDoc organisationID;
30
31     /**
32      * @jdo.field primary-key="true"
33      * @jdo.column length="100"
34      */

35     private String JavaDoc productID;
36
37     /**
38      * @jdo.field primary-key="true"
39      * @jdo.column length="100"
40      */

41     private String JavaDoc fieldName;
42
43     private Product product;
44
45     /**
46      * Whether or not the field may be changed by children.
47      */

48     private byte writableByChildren = ProductFieldMetaData.WRITABLEBYCHILDREN_YES;
49
50     /**
51      * writable is set to false if the mother has writableByChildren
52      * set to false.
53      */

54     private boolean writable = true;
55
56     /**
57      * If true, the value of the child is automatically updated if the
58      * mother's field is changed.
59      */

60     private boolean valueInherited = true;
61
62     protected ProductFieldMetaData() { }
63     public ProductFieldMetaData(Product product, String JavaDoc fieldName)
64     {
65         setProduct(product);
66         setFieldName(fieldName);
67     }
68
69     /**
70      * @return Returns the organisationID.
71      */

72     public String JavaDoc getOrganisationID()
73     {
74         return organisationID;
75     }
76
77     /**
78      * @return Returns the productID.
79      */

80     public String JavaDoc getProductID()
81     {
82         return productID;
83     }
84
85     /**
86      * @return Returns the fieldName.
87      */

88     public String JavaDoc getFieldName()
89     {
90         return fieldName;
91     }
92     /**
93      * @param fieldName The fieldName to set.
94      */

95     protected void setFieldName(String JavaDoc fieldName)
96     {
97         this.fieldName = fieldName;
98     }
99
100     /**
101      * @return Returns the product.
102      */

103     public Product getProduct()
104     {
105         return product;
106     }
107     /**
108      * @param product The product to set.
109      */

110     protected void setProduct(Product product)
111     {
112         if (product == null)
113             throw new NullPointerException JavaDoc("product must not be null!");
114         if (product.getOrganisationID() == null)
115             throw new NullPointerException JavaDoc("product.organisationID must not be null!");
116         if (product.getProductID() == null)
117             throw new NullPointerException JavaDoc("product.productID must not be null!");
118         this.organisationID = product.getOrganisationID();
119         this.productID = product.getProductID();
120         this.product = product;
121     }
122
123     /**
124      * @see com.nightlabs.inheritance.ProductInfoFieldMetaData#getWritableByChildren()
125      */

126     public byte getWritableByChildren()
127     {
128         return writableByChildren;
129     }
130     /**
131      * @see com.nightlabs.inheritance.ProductInfoFieldMetaData#setWritableByChildren(byte)
132      */

133     public void setWritableByChildren(byte writableByChildren)
134     {
135         this.writableByChildren = writableByChildren;
136     }
137
138     /**
139      * @return Returns the writable.
140      */

141     public boolean isWritable()
142     {
143         return writable;
144     }
145     /**
146      * @param writable The writable to set.
147      */

148     public void setWritable(boolean writable)
149     {
150         this.writable = writable;
151     }
152     /**
153      * @see com.nightlabs.inheritance.ProductInfoFieldMetaData#assertWritable()
154      */

155     public void assertWritable() throws NotWritableException
156     {
157         if (!isWritable())
158             throw new NotWritableException("Field \""+getFieldName()+"\" is not writeable!");
159     }
160
161     /**
162      * @return Returns the valueInherited.
163      */

164     public boolean isValueInherited()
165     {
166         return valueInherited;
167     }
168     /**
169      * @param valueInherited The valueInherited to set.
170      */

171     public void setValueInherited(boolean valueInherited)
172     {
173         if (!writable && !valueInherited)
174             throw new IllegalStateException JavaDoc("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