KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > jdo > impl > PersistenceFieldElementImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * PersistenceFieldElementImpl.java
26  *
27  * Created on March 2, 2000, 6:16 PM
28  */

29
30 package com.sun.jdo.api.persistence.model.jdo.impl;
31
32 import java.beans.PropertyVetoException JavaDoc;
33
34 import com.sun.jdo.api.persistence.model.ModelException;
35 import com.sun.jdo.api.persistence.model.ModelVetoException;
36 import com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement;
37 import com.sun.jdo.spi.persistence.utility.JavaTypeHelper;
38
39 /**
40  *
41  * @author raccah
42  * @version %I%
43  */

44 public class PersistenceFieldElementImpl extends PersistenceMemberElementImpl
45     implements PersistenceFieldElement.Impl
46 {
47     /** Constant representing read sensitive. */
48     private static final int READ_SENSITIVE = 1;
49
50     /** Constant representing write sensitive. */
51     private static final int WRITE_SENSITIVE = 2;
52
53     /** Persistence type of the field element. */
54     private int _persistenceType;
55
56     /** Derived modifier of the field element. */
57     private int _derivedModifier;
58
59     /** Key field flag of the field element. */
60     private boolean _isKey;
61
62     /** Create new PersistenceFieldElementImpl with no corresponding name.
63      * This constructor should only be used for cloning and archiving.
64      */

65     public PersistenceFieldElementImpl ()
66     {
67         this(null);
68     }
69
70     /** Creates new PersistenceFieldElementImpl with the corresponding name
71      * @param name the name of the element
72      */

73     public PersistenceFieldElementImpl (String JavaDoc name)
74     {
75         super(name);
76         _persistenceType = PersistenceFieldElement.PERSISTENT;
77     }
78
79     /** Get the persistence type of this field element.
80      * @return the persistence type, one of
81      * {@link PersistenceFieldElement#PERSISTENT} or
82      * {@link PersistenceFieldElement#DERIVED}. The default is PERSISTENT.
83      */

84     public int getPersistenceType() { return _persistenceType; }
85
86     /** Set the persistence type of this field element.
87      * @param type - an integer indicating the persistence type, one of:
88      * {@link PersistenceFieldElement#PERSISTENT} or
89      * {@link PersistenceFieldElement#DERIVED}
90      * @exception ModelException if impossible
91      */

92     public void setPersistenceType (int type) throws ModelException
93     {
94         Integer JavaDoc old = new Integer JavaDoc(getPersistenceType());
95         Integer JavaDoc newType = new Integer JavaDoc(type);
96         
97         try
98         {
99             fireVetoableChange(PROP_PERSISTENCE, old, newType);
100             _persistenceType = type;
101             firePropertyChange(PROP_PERSISTENCE, old, newType);
102         }
103         catch (PropertyVetoException JavaDoc e)
104         {
105             throw new ModelVetoException(e);
106         }
107     }
108
109     /** Determines whether this field element is read sensitive or not.
110      * This value is only used if <code>getPersistenceType</code> returns
111      * <code>DERIVED</code>
112      * @return <code>true</code> if the field is read sensitive,
113      * <code>false</code> if it is not or if the persistence type is not
114      * derived
115      * @see #isWriteSensitive
116      * @see #setPersistenceType
117      * @see PersistenceFieldElement#DERIVED
118      *
119      */

120     public boolean isReadSensitive ()
121     {
122         return ((PersistenceFieldElement.DERIVED == getPersistenceType()) ?
123             ((_derivedModifier & READ_SENSITIVE) != 0) : false);
124     }
125     
126     /** Set whether this field element is read sensitive or not.
127      * @param flag - if <code>true</code> and this is a derived field, the
128      * field element is marked as read sensitive; otherwise, it is not
129      * This value is only used if <code>getPersistenceType</code> returns
130      * <code>DERIVED</code>
131      * @exception ModelException if impossible
132      * @see #setWriteSensitive
133      * @see #setPersistenceType
134      * @see PersistenceFieldElement#DERIVED
135      */

136     public void setReadSensitive (boolean flag) throws ModelException
137     {
138         Boolean JavaDoc old = JavaTypeHelper.valueOf(isReadSensitive());
139         Boolean JavaDoc newFlag = JavaTypeHelper.valueOf(flag);
140
141         try
142         {
143             fireVetoableChange(PROP_SENSITIVITY, old, newFlag);
144
145             if (flag)
146                 _derivedModifier |= READ_SENSITIVE;
147             else
148                 _derivedModifier &= READ_SENSITIVE;
149
150             firePropertyChange(PROP_SENSITIVITY, old, newFlag);
151         }
152         catch (PropertyVetoException JavaDoc e)
153         {
154             throw new ModelVetoException(e);
155         }
156     }
157
158     /** Determines whether this field element is write sensitive or not.
159      * This value is only used if <code>getPersistenceType</code> returns
160      * <code>DERIVED</code>
161      * @return <code>true</code> if the field is write sensitive,
162      * <code>false</code> if it is not or if the persistence type is not
163      * derived
164      * @see #isReadSensitive
165      * @see #setPersistenceType
166      * @see PersistenceFieldElement#DERIVED
167      *
168      */

169     public boolean isWriteSensitive ()
170     {
171         return ((PersistenceFieldElement.DERIVED == getPersistenceType()) ?
172             ((_derivedModifier & WRITE_SENSITIVE) != 0) : false);
173     }
174
175     /** Set whether this field element is write sensitive or not.
176      * @param flag - if <code>true</code> and this is a derived field, the
177      * field element is marked as write sensitive; otherwise, it is not
178      * This value is only used if <code>getPersistenceType</code> returns
179      * <code>DERIVED</code>
180      * @exception ModelException if impossible
181      * @see #setReadSensitive
182      * @see #setPersistenceType
183      * @see PersistenceFieldElement#DERIVED
184      */

185     public void setWriteSensitive (boolean flag) throws ModelException
186     {
187         Boolean JavaDoc old = JavaTypeHelper.valueOf(isWriteSensitive());
188         Boolean JavaDoc newFlag = JavaTypeHelper.valueOf(flag);
189
190         try
191         {
192             fireVetoableChange(PROP_SENSITIVITY, old, newFlag);
193
194             if (flag)
195                 _derivedModifier |= WRITE_SENSITIVE;
196             else
197                 _derivedModifier &= WRITE_SENSITIVE;
198
199             firePropertyChange(PROP_SENSITIVITY, old, newFlag);
200         }
201         catch (PropertyVetoException JavaDoc e)
202         {
203             throw new ModelVetoException(e);
204         }
205     }
206
207     /** Determines whether this field element is a key field or not.
208      * @return <code>true</code> if the field is a key field,
209      * <code>false</code> otherwise
210      * @see PersistenceClassElement#getKeyClass
211      */

212     public boolean isKey () { return _isKey; }
213
214     /** Set whether this field element is a key field or not.
215      * @param flag - if <code>true</code>, the field element is marked
216      * as a key field; otherwise, it is not
217      * @exception ModelException if impossible
218      * @see PersistenceClassElement#getKeyClass
219      */

220     public void setKey (boolean flag) throws ModelException
221     {
222         Boolean JavaDoc old = JavaTypeHelper.valueOf(isKey());
223         Boolean JavaDoc newFlag = JavaTypeHelper.valueOf(flag);
224
225         try
226         {
227             fireVetoableChange(PROP_KEY_FIELD, old, newFlag);
228             _isKey = flag;
229             firePropertyChange(PROP_KEY_FIELD, old, newFlag);
230         }
231         catch (PropertyVetoException JavaDoc e)
232         {
233             throw new ModelVetoException(e);
234         }
235     }
236 }
237
Popular Tags