001
002
003
004
005
006 //
007 // This file is generated by MetaBoss Ver 1.4.0001 at Thu Dec 15 22:36:08 EST 2005
008 // MetaBoss is Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
009 // Content of this file is Copyright 2000-2005 © Softaris Pty. Ltd. All Rights Reserved.
010 // This content is licensed under Open Source Gnu Public License (GPL)
011 // Full terms and conditions of GPL can be found found at www.gnu.org
012 //
013
014 package com.almamater.crs.types.system.courses;
015
016 import java.io.Serializable;
017 import com.metaboss.enterprise.datatypes.DataType;
018 import com.metaboss.enterprise.datatypes.DataTypeTranslationMetadata;
019 import com.metaboss.enterprise.datatypes.DataTypeValidationException;
020 import com.metaboss.enterprise.datatypes.DefaultDataTypeTranslationMetadataImplementation;
021 import com.metaboss.enterprise.datatypes.DataTypeInstanceCreationFailureException;
022 import com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException;
023 import com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException;
024 import com.metaboss.enterprise.datatypes.sqltranslation.SqlVarcharTranslator;
025 import com.metaboss.enterprise.datatypes.primitivetranslation.PrimitiveStringTranslator;
026 import com.metaboss.enterprise.datatypes.xmltranslation.XmlTextTranslator;
027
028 /** Represents unique identifier for the Course entity instances. */
029 public final class CourseInstanceId implements DataType, Serializable
030 {
031 // Static storage for translation metadata. Create once and return many times
032 private static DataTypeTranslationMetadata sTranslationMetadata;
033 // Static storage for the empty string constant.
034 private static final String sEmptyString = "";
035 // Static storage for the concealed string constant."
036 private static final String sConcealedString = "xxxxxxxx";
037 // State is stored here : 0 - normal, 1 - empty, 2 - concealed
038 private byte mState = 0;
039 // Actual value stored here
040 private String mValue;
041
042 static
043 {
044 SqlVarcharTranslator lSqlTranslator = new SqlVarcharTranslator()
045 {
046 public String getSqlValue(DataType pDataTypeInstance) throws ClassCastException, DataTypeInvalidOperationForEmptyInstanceException, DataTypeInvalidOperationForConcealedInstanceException
047 {
048 CourseInstanceId lInstance = (CourseInstanceId)pDataTypeInstance;
049 if (lInstance.isConcealed())
050 throw new DataTypeInvalidOperationForConcealedInstanceException();
051 if (lInstance.isEmpty())
052 throw new DataTypeInvalidOperationForEmptyInstanceException();
053 return lInstance.mValue;
054 }
055 public DataType createFromSqlValue(String pSqlValue) throws DataTypeInstanceCreationFailureException
056 {
057 // Create instance
058 CourseInstanceId lValue = new CourseInstanceId();
059 lValue.mValue = pSqlValue;
060 return lValue;
061 }
062 };
063
064 PrimitiveStringTranslator lPrimitiveTranslator = new PrimitiveStringTranslator()
065 {
066 public String getPrimitiveValue(DataType pDataTypeInstance) throws ClassCastException, DataTypeInvalidOperationForEmptyInstanceException, DataTypeInvalidOperationForConcealedInstanceException
067 {
068 CourseInstanceId lInstance = (CourseInstanceId)pDataTypeInstance;
069 if (lInstance.isConcealed())
070 throw new DataTypeInvalidOperationForConcealedInstanceException();
071 if (lInstance.isEmpty())
072 throw new DataTypeInvalidOperationForEmptyInstanceException();
073 return lInstance.mValue;
074 }
075 public DataType createFromPrimitiveValue(String pPrimitiveValue) throws DataTypeInstanceCreationFailureException
076 {
077 // Create instance
078 CourseInstanceId lValue = new CourseInstanceId();
079 lValue.mValue = pPrimitiveValue;
080 return lValue;
081 }
082 };
083
084 XmlTextTranslator lXmlTranslator = new XmlTextTranslator()
085 {
086 public String getXmlValue(DataType pDataTypeInstance) throws ClassCastException, DataTypeInvalidOperationForEmptyInstanceException, DataTypeInvalidOperationForConcealedInstanceException
087 {
088 CourseInstanceId lInstance = (CourseInstanceId)pDataTypeInstance;
089 if (lInstance.isConcealed())
090 throw new DataTypeInvalidOperationForConcealedInstanceException();
091 if (lInstance.isEmpty())
092 throw new DataTypeInvalidOperationForEmptyInstanceException();
093 return lInstance.mValue;
094 }
095 public DataType createFromXmlValue(String pXmlValue) throws DataTypeInstanceCreationFailureException
096 {
097 if (pXmlValue == null)
098 throw new DataTypeInstanceCreationFailureException("Supplied Xml value is null.");
099 // Create instance
100 CourseInstanceId lValue = new CourseInstanceId();
101 lValue.mValue = pXmlValue;
102 return lValue;
103 }
104 };
105
106 java.util.Properties lProperties = new java.util.Properties();
107 lProperties.setProperty("minsize","6");
108 lProperties.setProperty("maxsize","40");
109 sTranslationMetadata = new DefaultDataTypeTranslationMetadataImplementation(DataTypeTranslationMetadata.SQL_VARCHAR, lProperties, lSqlTranslator, DataTypeTranslationMetadata.PRIMITIVE_STRING, null, lPrimitiveTranslator, DataTypeTranslationMetadata.XML_TEXT, null, lXmlTranslator);
110 }
111
112 /** Returns this datatype's translation metadata.
113 * See {@link com.metaboss.enterprise.datatypes.DataType DataType} for more details */
114 public static DataTypeTranslationMetadata getTranslationMetadata()
115 {
116 return sTranslationMetadata;
117 }
118
119 /** Returns string used to represent empty value in a toString() / createFromString() methods */
120 public static String getEmptyString()
121 {
122 return sEmptyString;
123 }
124
125 /** Returns string used to represent concealed value in a toString() / createFromString() methods */
126 public static String getConcealedString()
127 {
128 return sConcealedString;
129 }
130
131 /** Creates an instance of the datatype carrying an empty value */
132 public static CourseInstanceId createEmpty()
133 {
134 CourseInstanceId lValue = new CourseInstanceId();
135 lValue.mState = 1;
136 return lValue;
137 }
138
139 /** Creates an instance of the datatype carrying concealed value */
140 public static CourseInstanceId createConcealed()
141 {
142 CourseInstanceId lValue = new CourseInstanceId();
143 lValue.mState = 2;
144 return lValue;
145 }
146
147 /** Creates an instance of the datatype from given readable value */
148 public static CourseInstanceId createFromString( String pSourceString) throws DataTypeValidationException
149 {
150 // Perform validation
151 validateString(pSourceString);
152 // Create instance
153 if (pSourceString.equals(sEmptyString))
154 return createEmpty();
155 if (pSourceString.equals(sConcealedString))
156 return createConcealed();
157 // Create instance
158 CourseInstanceId lValue = new CourseInstanceId();
159 lValue.mValue = pSourceString;
160 return lValue;
161 }
162
163 /** Validates proposed readable value */
164 public static void validateString( String pProposedString) throws DataTypeValidationException
165 {
166 if (pProposedString == null)
167 throw new DataTypeValidationException("Null initialisation string is not allowed for CourseInstanceId. Use createEmpty() method to create an empty CourseInstanceId");
168 if (pProposedString.equals(sEmptyString) || pProposedString.equals(sConcealedString))
169 return; // Done validation for special values
170 int lLength = pProposedString.length();
171 if (lLength > 40 )
172 throw new DataTypeValidationException("String is too long for CourseInstanceId. Expected max length is 40 characters.");
173 if (lLength < 6 )
174 throw new DataTypeValidationException("String is too short for CourseInstanceId. Expected min length is 6 characters.");
175 }
176
177 /** Returns the value inside this instance of CourseInstanceId as readable string */
178 public String toString()
179 {
180 if (isEmpty())
181 return sEmptyString;
182 if (isConcealed())
183 return sConcealedString;
184 return mValue;
185 }
186
187 /** Indicates whether some other object is \"equal to\" this one
188 * @return true if this object is the same as the obj argument; false otherwise. */
189 public boolean equals(Object pOtherObject)
190 {
191 if (pOtherObject == null)
192 return false;
193 if ((pOtherObject instanceof CourseInstanceId) == false)
194 return false;
195 if (((CourseInstanceId)pOtherObject).isConcealed() || isConcealed())
196 return false; // One of the instances is concealed
197 if (((CourseInstanceId)pOtherObject).isEmpty() && isEmpty())
198 return true; // Both instances are empty.
199 if (((CourseInstanceId)pOtherObject).isEmpty() != isEmpty())
200 return false; // One of the instances is empty, the other one is not
201 return ((CourseInstanceId)pOtherObject).mValue.equals(mValue);
202 }
203
204 /** Returns a hash code value for the object. This method is supported for the benefit of hashtables
205 * @return instance's hash code or zero if this instance is empty or concealed */
206 public int hashCode()
207 {
208 if (isEmpty() || isConcealed())
209 return 0;
210 return mValue.hashCode();
211 }
212
213 /** Returns true if the instance contains an empty value */
214 public boolean isEmpty()
215 {
216 return mState == 1;
217 }
218
219 /** Returns true if the instance contains concealed value */
220 public boolean isConcealed()
221 {
222 return mState == 2;
223 }
224
225 // Private access. External callers must use one of the static creators
226 private CourseInstanceId()
227 {
228 }
229 }
|