1 /*
2 * Copyright 2008 Lukas Lang
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.exolab.castor.builder.info.nature;
18
19 import org.castor.core.nature.BaseNature;
20 import org.exolab.castor.builder.info.FieldInfo;
21
22 /**
23 * A JDO specific view of a {@link FieldInfo}. Implementation based on property access
24 * on {@link FieldInfo}.
25 *
26 * @author Lukas Lang
27 * @since 1.2.1
28 */
29 public final class JDOFieldInfoNature extends BaseNature {
30
31 /**
32 * Constant for the property name for the sql type of the column.
33 */
34 private static final String COLUMN_TYPE = "columntype";
35 /**
36 * Constant for the property name for the name of the column.
37 */
38 private static final String COLUMN_NAME = "columnname";
39 /**
40 * Constant for the property read only.
41 */
42 private static final String READONLY = "readonly";
43 /**
44 * Constant for the property dirty.
45 */
46 private static final String DIRTY = "dirty";
47
48 /**
49 * Constructor taking a FieldInfo.
50 *
51 * @param fieldInfo
52 * in focus.
53 */
54 public JDOFieldInfoNature(final FieldInfo fieldInfo) {
55 super(fieldInfo);
56 }
57
58 /**
59 * Returns the fully qualified class name of the Nature.
60 *
61 * @return the nature id.
62 * @see org.exolab.castor.builder.info.nature.Nature#getId()
63 */
64 public String getId() {
65 return getClass().getName();
66 }
67
68 /**
69 * Retrieves the sql column name.
70 *
71 * @return name of the column.
72 */
73 public String getColumnName() {
74 return (String) this.getProperty(COLUMN_NAME);
75 }
76
77 /**
78 * Returns the sql type of the column.
79 *
80 * @return the sql type.
81 */
82 public String getColumnType() {
83 return (String) this.getProperty(COLUMN_TYPE);
84 }
85
86 /**
87 * Sets the sql column name.
88 *
89 * @param columnName
90 * name of the column.
91 */
92 public void setColumnName(final String columnName) {
93 this.setProperty(COLUMN_NAME, columnName);
94 }
95
96 /**
97 * Sets the column sql type.
98 *
99 * @param sqlType
100 * of the column.
101 */
102 public void setColumnType(final String sqlType) {
103 this.setProperty(COLUMN_TYPE, sqlType);
104 }
105
106 /**
107 * Returns true if no update on the column can be performed, false
108 * otherwise. Default value is false.
109 *
110 * @return true if readonly, false if not or not set.
111 */
112 public boolean isReadOnly() {
113 return getBooleanPropertyDefaultFalse(READONLY);
114 }
115
116 /**
117 * Sets the column read only.
118 *
119 * @param readOnly
120 * true if read only.
121 */
122 public void setReadOnly(final boolean readOnly) {
123 setProperty(READONLY, new Boolean(readOnly));
124 }
125
126 /**
127 * Returns true if field will NOT be checked against the database for
128 * modification, otherwise false. Default value is false.
129 *
130 * @return true if field is not updated, false if not or not set.
131 */
132 public boolean isDirty() {
133 return getBooleanPropertyDefaultFalse(DIRTY);
134 }
135
136 /**
137 * If set true, field will NOT be checked against the database for
138 * modification, otherwise set false.
139 *
140 * @param dirty
141 * true if field should not be updated.
142 */
143 public void setDirty(final boolean dirty) {
144 setProperty(DIRTY, new Boolean(dirty));
145 }
146
147 }