KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > metainfo > lib > BasicPrimitiveElement


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.metainfo.lib;
25
26 import org.objectweb.jorm.metainfo.api.MetaObject;
27 import org.objectweb.jorm.metainfo.api.PrimitiveElement;
28 import org.objectweb.jorm.type.api.PType;
29
30 /**
31  * The BasicPrimitiveElement object is used to define fields which
32  * are primitive types. This object is defined by its name, its type,
33  * its parent, its size (if used) and a list of mappings for the field.
34  * @author X. Spengler
35  */

36 public class BasicPrimitiveElement
37     extends BasicTypedElement
38     implements PrimitiveElement {
39
40
41     boolean isAutoCalculated = false;
42
43     int status = VARIABLE_PERSISTENT;
44
45     /**
46      * The size of the field
47      */

48     private int size = PType.NOSIZE;
49     private int scale = PType.NOSIZE;
50
51
52     /**
53      * Builds a new PrimitiveElement object.
54      * This object is mainly defined by its name, its type and its parent.
55      *
56      * @param name the name of the primitive field
57      * @param type the type of the field (PType object)
58      * @param parent the parent of the current object
59      */

60     public BasicPrimitiveElement(String JavaDoc name,
61                                  PType type,
62                                  int size,
63                                  int scale,
64                                  MetaObject parent) {
65         super(name, type, parent);
66         this.size = size;
67         this.scale = scale;
68
69     }
70
71     ///////////////////////////////////////////////////////////////////
72
// from PrimitiveElement interface
73
///////////////////////////////////////////////////////////////////
74

75     /**
76      * Returns the size of the field in case of string, serialized, arrays, etc
77      * @return the size for this type
78      */

79     public int getSize() {
80         return size;
81     }
82
83     public int getScale() {
84         return scale;
85     }
86
87     /**
88      * Allows to know if the current Field is a scalar field or not.
89      *
90      * @return true, if the Field is scalar, else false, if the Field is not
91      * scalar
92      */

93     public boolean isScalar() {
94         // TBD return false for the moment
95
return false;
96     }
97
98     public boolean isAutoCalculated() {
99         return isAutoCalculated;
100     }
101
102     public void setIsAutoCalculated(boolean autocalculated) {
103         isAutoCalculated = autocalculated;
104     }
105
106     public int getStatus() {
107         return status;
108     }
109
110     public void setStatus(int status) {
111         this.status = status;
112     }
113
114     public boolean isConstant() {
115         return status == CONSTANT_NON_PERSISTENT
116                 || status == CONSTANT_PERSISTENT;
117     }
118
119     public boolean isPersistent() {
120         return status == CONSTANT_PERSISTENT || status == VARIABLE_PERSISTENT;
121     }
122 }
123
Popular Tags