Source Code Cross Referenced for EnumerableValueField.java in  » UML » MetaBoss » MetaLib » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » MetaBoss » MetaLib.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012:        // POSSIBILITY OF SUCH DAMAGE.
0013:        //
0014:        // Copyright 2001-2003 © Softaris Pty.Ltd. All Rights Reserved.
0015:        package metalib.core;
0016:
0017:        import java.io.PrintWriter;
0018:        import java.util.HashMap;
0019:        import java.util.HashSet;
0020:        import java.util.ArrayList;
0021:        import java.util.Iterator;
0022:        import com.metaboss.util.StringUtils;
0023:        import com.metaboss.javatemplate.*;
0024:
0025:        /** The basic enumerated value datatype. */
0026:        public final class EnumerableValueField implements  JavaTemplate {
0027:            // This comment is inserted in javadoc when description of the object is miissing from the model
0028:            private static final String sMissingDescriptionComment = "<font color=\"red\">Description is missing in the model</font>";
0029:
0030:            // This class keeps the enumerable value metadata
0031:            private class ValueMetadata {
0032:                public String Name;
0033:                public String Description;
0034:                public String VariableName;
0035:            }
0036:
0037:            // This class keeps the category metadata
0038:            private class CategoryMetadata {
0039:                public String Name;
0040:                public String Description;
0041:                public String PartOfIdentifierName;
0042:                public ValueMetadata[] CategoryValues;
0043:            }
0044:
0045:            // Holds details for a jargon
0046:            private class JargonMetadata {
0047:                public String Name;
0048:                public String Description;
0049:                public String PartOfIdentifierName;
0050:                public String EmptyString;
0051:                public String ConcealedString;
0052:                public String[] JargonValueNames;
0053:            }
0054:
0055:            /* This method is called to perform the template merge with the values supplied in context */
0056:            public void mergeTemplate(PrintWriter pOutputWriter,
0057:                    JavaTemplateContext pContext) throws JavaTemplateException {
0058:                String lDatatypeName = pContext
0059:                        .getMandatoryString("DatatypeName");
0060:                String lDatatypeDescription = pContext.getString(
0061:                        "DatatypeDescription", sMissingDescriptionComment);
0062:                String lEmptyString = pContext.getString(
0063:                        "TemplateProperties.EmptyString", "");
0064:                String lConcealedString = pContext.getString(
0065:                        "TemplateProperties.ConcealedString", "xxxxxx");
0066:                int lMaxValueLength = 1;
0067:
0068:                // Work with values
0069:                HashMap lValuesMap = new HashMap(); // ValueMetadata indexed by value name
0070:                ValueMetadata[] lValues; // Array of value metadatas as they where specified important for looking up by index
0071:                {
0072:                    HashSet lUsedNames = new HashSet();
0073:                    HashSet lUsedVariableNames = new HashSet();
0074:                    ArrayList lValuesArray = new ArrayList();
0075:                    for (int i = 1;; i++) {
0076:                        String lName = pContext.getString(
0077:                                "TemplateProperties.Value[" + i + "].Name",
0078:                                null);
0079:                        if (lName == null)
0080:                            break; //no more names
0081:                        if (!lUsedNames.add(lName))
0082:                            throw new JavaTemplateException("Property Value["
0083:                                    + i + "].Name contains duplicate value '"
0084:                                    + lName + "'.");
0085:                        ValueMetadata lMetadata = new ValueMetadata();
0086:                        lMetadata.Name = lName;
0087:                        // Work on the name for variable    
0088:                        lMetadata.VariableName = StringUtils
0089:                                .suggestJavaIdentifier(lMetadata.Name);
0090:                        if (lMetadata.VariableName == null
0091:                                || lMetadata.VariableName.length() == 0)
0092:                            throw new JavaTemplateException(
0093:                                    "Unable to create Java identifier from the given Name '"
0094:                                            + lMetadata.Name + "'");
0095:                        lMetadata.VariableName = lMetadata.VariableName
0096:                                .toUpperCase();
0097:                        // Work on description
0098:                        lMetadata.Description = pContext.getString(
0099:                                "TemplateProperties.Value[" + i
0100:                                        + "].Description", null);
0101:                        if (lMetadata.Description == null
0102:                                || lMetadata.Description.trim().length() == 0)
0103:                            lMetadata.Description = sMissingDescriptionComment;
0104:                        // Add to collections
0105:                        lValuesMap.put(lName, lMetadata);
0106:                        lValuesArray.add(lMetadata);
0107:                        // Accumulate maximum value length
0108:                        int lValueLength = lName.length();
0109:                        if (lValueLength > lMaxValueLength)
0110:                            lMaxValueLength = lValueLength;
0111:                    }
0112:                    lValues = (ValueMetadata[]) lValuesArray
0113:                            .toArray(new ValueMetadata[lValuesArray.size()]);
0114:                }
0115:
0116:                // Work with categories
0117:                CategoryMetadata[] lCategories = new CategoryMetadata[0];
0118:                {
0119:                    HashSet lUsedNames = new HashSet();
0120:                    ArrayList lCategoriesArray = new ArrayList();
0121:                    for (int i = 1;; i++) {
0122:                        String lName = pContext.getString(
0123:                                "TemplateProperties.Category[" + i + "].Name",
0124:                                null);
0125:                        if (lName == null)
0126:                            break; //no more names
0127:                        if (!lUsedNames.add(lName))
0128:                            throw new JavaTemplateException(
0129:                                    "Property Category["
0130:                                            + i
0131:                                            + "].Name contains duplicate value '"
0132:                                            + lName + "'.");
0133:                        CategoryMetadata lMetadata = new CategoryMetadata();
0134:                        lMetadata.Name = lName;
0135:                        lMetadata.Description = pContext.getString(
0136:                                "TemplateProperties.Category[" + i
0137:                                        + "].Description", null);
0138:                        if (lMetadata.Description == null
0139:                                || lMetadata.Description.trim().length() == 0)
0140:                            lMetadata.Description = sMissingDescriptionComment;
0141:                        lMetadata.PartOfIdentifierName = StringUtils
0142:                                .suggestName(lName, true, false);
0143:                        // Watch for clashes with isEmpty() and isConcealed() methods
0144:                        if (lMetadata.PartOfIdentifierName.equals("Empty")
0145:                                || lMetadata.PartOfIdentifierName
0146:                                        .equals("Concealed"))
0147:                            throw new JavaTemplateException(
0148:                                    "Category name "
0149:                                            + lName
0150:                                            + " can not be used. This name is reserved for generated constant or method names.");
0151:                        ArrayList lCategoryValues = new ArrayList();
0152:                        for (int j = 1;; j++) {
0153:                            String lCategoryValueName = pContext.getString(
0154:                                    "TemplateProperties.Category[" + i
0155:                                            + "].ValueName[" + j + "]", null);
0156:                            if (lCategoryValueName == null)
0157:                                break;
0158:                            ValueMetadata lValueMetadata = (ValueMetadata) lValuesMap
0159:                                    .get(lCategoryValueName);
0160:                            if (lValueMetadata == null)
0161:                                throw new JavaTemplateException(
0162:                                        "Undefined value '"
0163:                                                + lCategoryValueName
0164:                                                + "' listed in " + lName
0165:                                                + " category.");
0166:                            lCategoryValues.add(lValueMetadata);
0167:                        }
0168:                        lMetadata.CategoryValues = (ValueMetadata[]) lCategoryValues
0169:                                .toArray(new ValueMetadata[lCategoryValues
0170:                                        .size()]);
0171:                        lCategoriesArray.add(lMetadata);
0172:                    }
0173:                    lCategories = (CategoryMetadata[]) lCategoriesArray
0174:                            .toArray(new CategoryMetadata[lCategoriesArray
0175:                                    .size()]);
0176:                }
0177:                // Work with jargons
0178:                JargonMetadata[] lJargons; // Array of jargon metadatas as they where specified
0179:                {
0180:                    HashSet lUsedNames = new HashSet();
0181:                    ArrayList lJargonsArray = new ArrayList();
0182:                    for (int i = 1;; i++) {
0183:                        String lName = pContext.getString(
0184:                                "TemplateProperties.Jargon[" + i + "].Name",
0185:                                null);
0186:                        if (lName == null)
0187:                            break; //no more jargons
0188:                        if (!lUsedNames.add(lName))
0189:                            throw new JavaTemplateException("Property Jargon["
0190:                                    + i + "].Name contains duplicate value '"
0191:                                    + lName + "'.");
0192:                        JargonMetadata lMetadata = new JargonMetadata();
0193:                        lMetadata.Name = lName;
0194:                        lMetadata.PartOfIdentifierName = StringUtils
0195:                                .suggestName(lName, true, false);
0196:                        lMetadata.Description = pContext.getString(
0197:                                "TemplateProperties.Jargon[" + i
0198:                                        + "].Description", null);
0199:                        if (lMetadata.Description == null
0200:                                || lMetadata.Description.trim().length() == 0)
0201:                            lMetadata.Description = sMissingDescriptionComment;
0202:                        lMetadata.EmptyString = pContext.getString(
0203:                                "TemplateProperties.Jargon[" + i
0204:                                        + "].EmptyString", lEmptyString);
0205:                        lMetadata.ConcealedString = pContext
0206:                                .getString("TemplateProperties.Jargon[" + i
0207:                                        + "].ConcealedString", lConcealedString);
0208:                        HashSet lUsedJargonValueNames = new HashSet();
0209:                        lMetadata.JargonValueNames = new String[lValues.length];
0210:                        for (int j = 0; j < lValues.length; j++) {
0211:                            String lJargonValueName = lMetadata.JargonValueNames[j] = pContext
0212:                                    .getString("TemplateProperties.Jargon[" + i
0213:                                            + "].Value["
0214:                                            + Integer.toString(j + 1)
0215:                                            + "].Name", lValues[j].Name);
0216:                            if (!lUsedJargonValueNames.add(lJargonValueName))
0217:                                throw new JavaTemplateException(
0218:                                        "Property Jargon["
0219:                                                + i
0220:                                                + "].Value["
0221:                                                + Integer.toString(j + 1)
0222:                                                + "].Name contains duplicate value '"
0223:                                                + lJargonValueName + "'.");
0224:                        }
0225:                        lJargonsArray.add(lMetadata);
0226:                    }
0227:                    lJargons = (JargonMetadata[]) lJargonsArray
0228:                            .toArray(new JargonMetadata[lJargonsArray.size()]);
0229:                }
0230:                boolean lComparable = Boolean.valueOf(
0231:                        pContext.getString("TemplateProperties.Comparable",
0232:                                "false")).booleanValue();
0233:
0234:                pOutputWriter.println("import java.util.Locale;");
0235:                pOutputWriter.println("import java.io.Serializable;");
0236:                pOutputWriter
0237:                        .println("import com.metaboss.util.ResourceUtils;");
0238:                pOutputWriter
0239:                        .println("import com.metaboss.enterprise.datatypes.DataType;");
0240:                pOutputWriter
0241:                        .println("import com.metaboss.enterprise.datatypes.DataTypeTranslationMetadata;");
0242:                pOutputWriter
0243:                        .println("import com.metaboss.enterprise.datatypes.DataTypeValidationException;");
0244:                pOutputWriter
0245:                        .println("import com.metaboss.enterprise.datatypes.DefaultDataTypeTranslationMetadataImplementation;");
0246:                pOutputWriter
0247:                        .println("import com.metaboss.enterprise.datatypes.DataTypeInstanceCreationFailureException;");
0248:                pOutputWriter
0249:                        .println("import com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException;");
0250:                pOutputWriter
0251:                        .println("import com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException;");
0252:                pOutputWriter
0253:                        .println("import com.metaboss.enterprise.datatypes.sqltranslation.SqlVarcharTranslator;");
0254:                pOutputWriter
0255:                        .println("import com.metaboss.enterprise.datatypes.primitivetranslation.PrimitiveStringTranslator;");
0256:                pOutputWriter
0257:                        .println("import com.metaboss.enterprise.datatypes.xmltranslation.XmlTextTranslator;");
0258:
0259:                pOutputWriter.println("/** " + lDatatypeDescription);
0260:                pOutputWriter
0261:                        .println("  * <p>This datatype is an 'enumerable type', which means that it has a limited set of valid constant values.");
0262:                pOutputWriter
0263:                        .println("  * Each valid value is represented by public member constant, which must be used as concrete instance of this type. </p>");
0264:                if (lJargons.length > 0) {
0265:                    pOutputWriter
0266:                            .println("  * <p><b>Additional jargons are:</b>");
0267:                    pOutputWriter.println("  * <table border=\"1\">");
0268:                    pOutputWriter
0269:                            .println("  * <tr><th>Jargon Name</th><th>Jargon Description</th></tr>");
0270:                    for (int i = 0; i < lJargons.length; i++)
0271:                        pOutputWriter.println("<tr><td>" + lJargons[i].Name
0272:                                + "</td><td>" + lJargons[i].Description
0273:                                + "</td></tr>");
0274:                    pOutputWriter.println("  * </table></p>");
0275:                }
0276:                pOutputWriter.println("  * <p><b>Valid values"
0277:                        + ((lComparable) ? "(<i> in ascending order</i>)" : "")
0278:                        + " are:</b>");
0279:                pOutputWriter.println("  * <table border=\"1\">");
0280:                pOutputWriter.print("  * <tr><th>Value</th>");
0281:                // Optional jargons
0282:                for (int i = 0; i < lJargons.length; i++)
0283:                    pOutputWriter.print("<th>" + lJargons[i].Name
0284:                            + " Jargon Value</th>");
0285:                pOutputWriter
0286:                        .println("<th>Member Variable</th><th>Value Description</th></tr>");
0287:                // Write out table rows
0288:                for (int i = 0; i < lValues.length; i++) {
0289:                    ValueMetadata lValueMetadata = lValues[i];
0290:                    pOutputWriter.print("  * <tr><td>" + lValueMetadata.Name
0291:                            + "</td>");
0292:                    // Optional jargons
0293:                    for (int j = 0; j < lJargons.length; j++)
0294:                        pOutputWriter.print("<td>"
0295:                                + lJargons[j].JargonValueNames[i] + "</td>");
0296:                    pOutputWriter.println("<td><a href=\"#"
0297:                            + lValueMetadata.VariableName + "\">"
0298:                            + lValueMetadata.VariableName + "</a></td><td>"
0299:                            + lValueMetadata.Description + "</td></tr>");
0300:                }
0301:                pOutputWriter.println("  * </table></p>");
0302:                if (lCategories.length > 0) {
0303:                    pOutputWriter
0304:                            .println("  * <p><b>Value categories are:</b>");
0305:                    pOutputWriter
0306:                            .println("  * <p><table border=\"1\"><caption><b>Value categories</b></caption>");
0307:                    pOutputWriter
0308:                            .println("  * <tr><th>Category Name</th><th>Testing Method</th><th>Category Description</th><th>Category Values</th></tr>");
0309:                    for (int i = 0; i < lCategories.length; i++) {
0310:                        CategoryMetadata lCategoryMetadata = lCategories[i];
0311:                        // Build up value names belonging to category
0312:                        String lCategoryValues = null;
0313:                        if (lCategoryMetadata.CategoryValues.length > 0) {
0314:                            StringBuffer lBuffer = new StringBuffer();
0315:                            for (int j = 0; j < lCategoryMetadata.CategoryValues.length; j++) {
0316:                                if (j > 0)
0317:                                    lBuffer.append(" , ");
0318:                                lBuffer
0319:                                        .append(lCategoryMetadata.CategoryValues[j].Name);
0320:                            }
0321:                            lCategoryValues = lBuffer.toString();
0322:                        } else
0323:                            lCategoryValues = "<font color=\"red\">missing in the model</font>";
0324:                        pOutputWriter.println("  * <tr><td>"
0325:                                + lCategoryMetadata.Name
0326:                                + "</td><td><a href=\"#is"
0327:                                + lCategoryMetadata.PartOfIdentifierName
0328:                                + "()\">is"
0329:                                + lCategoryMetadata.PartOfIdentifierName
0330:                                + "()</a></td><td>"
0331:                                + lCategoryMetadata.Description + "</td><td>"
0332:                                + lCategoryValues + "</td></tr>");
0333:                    }
0334:                }
0335:                pOutputWriter.println("  * </table></p>");
0336:                pOutputWriter.println("  */");
0337:                pOutputWriter.println("public final class " + lDatatypeName
0338:                        + " implements DataType, Serializable"
0339:                        + (lComparable ? ",Comparable" : ""));
0340:                pOutputWriter.println("{");
0341:                pOutputWriter
0342:                        .println("    // Static storage for translation metadata. Create once and return many times");
0343:                pOutputWriter
0344:                        .println("    private static DataTypeTranslationMetadata sTranslationMetadata = null;");
0345:                pOutputWriter
0346:                        .println("    // Static storage for the empty string constant.");
0347:                pOutputWriter
0348:                        .println("    private static final String sEmptyString = \""
0349:                                + lEmptyString + "\";");
0350:                pOutputWriter
0351:                        .println("    // Static storage for the concealed string constant.");
0352:                pOutputWriter
0353:                        .println("    private static final String sConcealedString = \""
0354:                                + lConcealedString + "\";");
0355:                pOutputWriter
0356:                        .println("    // Static storage for all valid string constants except empty and concealed");
0357:                pOutputWriter
0358:                        .print("    private static final String[] sAllStrings = new String[] {");
0359:                // Write out public final values
0360:                {
0361:                    for (int i = 0; i < lValues.length; i++) {
0362:                        ValueMetadata lValueMetadata = lValues[i];
0363:                        pOutputWriter.print("\"" + lValueMetadata.Name + "\"");
0364:                        if (i < (lValues.length - 1))
0365:                            pOutputWriter.print(",");
0366:                        else
0367:                            pOutputWriter.println("};");
0368:                    }
0369:                }
0370:                pOutputWriter
0371:                        .println("    // Static storage for all description string constants except empty and concealed");
0372:                pOutputWriter
0373:                        .println("    // This storage is for default locale only, Descriptions will be loaded dynamically for all other locales");
0374:                pOutputWriter
0375:                        .print("    private static final String[] sAllDescriptions = new String[] {");
0376:                // Write out public final values
0377:                {
0378:                    for (int i = 0; i < lValues.length; i++) {
0379:                        ValueMetadata lValueMetadata = lValues[i];
0380:                        pOutputWriter
0381:                                .print("ResourceUtils.getClassResourceString("
0382:                                        + lDatatypeName + ".class,\"Value["
0383:                                        + Integer.toString(i + 1)
0384:                                        + "].Description\",\"\")");
0385:                        if (i < (lValues.length - 1))
0386:                            pOutputWriter.print(",");
0387:                        else
0388:                            pOutputWriter.println("};");
0389:                    }
0390:                }
0391:                // Generate string constants for alternative jargons
0392:                for (int i = 0; i < lJargons.length; i++) {
0393:                    JargonMetadata lJargonMetadata = lJargons[i];
0394:                    pOutputWriter
0395:                            .println("    // Static storage for the empty string constant in "
0396:                                    + lJargonMetadata.Name + " jargon.");
0397:                    pOutputWriter
0398:                            .println("    private static final String sEmpty"
0399:                                    + lJargonMetadata.PartOfIdentifierName
0400:                                    + "String = \""
0401:                                    + lJargonMetadata.EmptyString + "\";");
0402:                    pOutputWriter
0403:                            .println("    // Static storage for the concealed string constant in "
0404:                                    + lJargonMetadata.Name + " jargon.");
0405:                    pOutputWriter
0406:                            .println("    private static final String sConcealed"
0407:                                    + lJargonMetadata.PartOfIdentifierName
0408:                                    + "String = \""
0409:                                    + lJargonMetadata.ConcealedString + "\";");
0410:                    pOutputWriter
0411:                            .println("    // Static storage for all valid string constants  in "
0412:                                    + lJargonMetadata.Name
0413:                                    + " jargon except empty and concealed");
0414:                    pOutputWriter
0415:                            .print("    private static final String[] sAll"
0416:                                    + lJargonMetadata.PartOfIdentifierName
0417:                                    + "Strings = new String[] {");
0418:                    // Write out public final values
0419:                    {
0420:                        for (int j = 0; j < lValues.length; j++) {
0421:                            pOutputWriter.print("\""
0422:                                    + lJargonMetadata.JargonValueNames[j]
0423:                                    + "\"");
0424:                            if (j < (lValues.length - 1))
0425:                                pOutputWriter.print(",");
0426:                            else
0427:                                pOutputWriter.println("};");
0428:                        }
0429:                    }
0430:                }
0431:                pOutputWriter
0432:                        .println("    // Special constant representing empty value");
0433:                pOutputWriter.println("    private static final "
0434:                        + lDatatypeName + " sEmptyInstance = new "
0435:                        + lDatatypeName + "((byte)1, sEmptyString"
0436:                        + ((lComparable) ? (", " + Integer.toString(-2)) : "")
0437:                        + ");");
0438:                pOutputWriter
0439:                        .println("    // Special value to carry concealed value around");
0440:                pOutputWriter.println("    private static final "
0441:                        + lDatatypeName + " sConcealedInstance = new "
0442:                        + lDatatypeName + "((byte)2, sConcealedString"
0443:                        + ((lComparable) ? (", " + Integer.toString(-1)) : "")
0444:                        + ");");
0445:                pOutputWriter
0446:                        .println("    // State is stored here : 0 - normal, 1 - empty, 2 - concealed");
0447:                pOutputWriter.println("    private byte mState = 0;");
0448:                pOutputWriter.println("    // Actual value stored here");
0449:                pOutputWriter.println("    private String mValue;");
0450:                if (lComparable)
0451:                    pOutputWriter.println("    private int mComparableWeight;");
0452:                // Write out public final values
0453:                for (int i = 0; i < lValues.length; i++) {
0454:                    ValueMetadata lValueMetadata = lValues[i];
0455:                    pOutputWriter
0456:                            .println("    /** Constant, which represents '"
0457:                                    + lValueMetadata.Name
0458:                                    + "' value (one of the possible values of "
0459:                                    + lDatatypeName + ").");
0460:                    pOutputWriter.println("      * Value description is : <i> "
0461:                            + lValueMetadata.Description + " </i> */");
0462:                    pOutputWriter.println("    public static final "
0463:                            + lDatatypeName
0464:                            + " "
0465:                            + lValueMetadata.VariableName
0466:                            + " = new "
0467:                            + lDatatypeName
0468:                            + "((byte)0, \""
0469:                            + lValueMetadata.Name
0470:                            + "\""
0471:                            + ((lComparable) ? (", " + Integer.toString(i))
0472:                                    : "") + ");");
0473:                }
0474:
0475:                pOutputWriter.println("    static");
0476:                pOutputWriter.println("    {");
0477:                pOutputWriter
0478:                        .println("        SqlVarcharTranslator lSqlTranslator = new SqlVarcharTranslator()");
0479:                pOutputWriter.println("        {");
0480:                pOutputWriter
0481:                        .println("            public String getSqlValue(DataType pDataTypeInstance) throws ClassCastException, DataTypeInvalidOperationForEmptyInstanceException, DataTypeInvalidOperationForConcealedInstanceException");
0482:                pOutputWriter.println("            {");
0483:                pOutputWriter.println("                " + lDatatypeName
0484:                        + " lInstance = (" + lDatatypeName
0485:                        + ")pDataTypeInstance;");
0486:                pOutputWriter
0487:                        .println("                if (lInstance.isConcealed())");
0488:                pOutputWriter
0489:                        .println("                    throw new DataTypeInvalidOperationForConcealedInstanceException();");
0490:                pOutputWriter
0491:                        .println("                if (lInstance.isEmpty())");
0492:                pOutputWriter
0493:                        .println("                    throw new DataTypeInvalidOperationForEmptyInstanceException();");
0494:                pOutputWriter
0495:                        .println("                return lInstance.mValue;");
0496:                pOutputWriter.println("            }");
0497:                pOutputWriter
0498:                        .println("            public DataType createFromSqlValue(String pSqlValue) throws DataTypeInstanceCreationFailureException");
0499:                pOutputWriter.println("            {");
0500:                pOutputWriter.println("                if (pSqlValue == null)");
0501:                pOutputWriter
0502:                        .println("                    throw new DataTypeInstanceCreationFailureException(\"Supplied Sql value is null.\");");
0503:                {
0504:                    for (int i = 0; i < lValues.length; i++) {
0505:                        ValueMetadata lValueMetadata = lValues[i];
0506:                        pOutputWriter
0507:                                .println("                if (pSqlValue.equals("
0508:                                        + lValueMetadata.VariableName
0509:                                        + ".mValue))");
0510:                        pOutputWriter.println("                    return "
0511:                                + lValueMetadata.VariableName + ";");
0512:                    }
0513:                }
0514:                pOutputWriter
0515:                        .println("                throw new DataTypeInstanceCreationFailureException(\"'\" + pSqlValue + \"' is not a legal value for "
0516:                                + lDatatypeName + ".\");");
0517:                pOutputWriter.println("            }");
0518:                pOutputWriter.println("        };");
0519:                pOutputWriter
0520:                        .println("        PrimitiveStringTranslator lPrimitiveTranslator = new PrimitiveStringTranslator()");
0521:                pOutputWriter.println("        {");
0522:                pOutputWriter
0523:                        .println("            public String getPrimitiveValue(DataType pDataTypeInstance) throws ClassCastException, DataTypeInvalidOperationForEmptyInstanceException, DataTypeInvalidOperationForConcealedInstanceException");
0524:                pOutputWriter.println("            {");
0525:                pOutputWriter.println("                " + lDatatypeName
0526:                        + " lInstance = (" + lDatatypeName
0527:                        + ")pDataTypeInstance;");
0528:                pOutputWriter
0529:                        .println("                if (lInstance.isConcealed())");
0530:                pOutputWriter
0531:                        .println("                    throw new DataTypeInvalidOperationForConcealedInstanceException();");
0532:                pOutputWriter
0533:                        .println("                if (lInstance.isEmpty())");
0534:                pOutputWriter
0535:                        .println("                    throw new DataTypeInvalidOperationForEmptyInstanceException();");
0536:                pOutputWriter
0537:                        .println("                return lInstance.mValue;");
0538:                pOutputWriter.println("            }");
0539:                pOutputWriter
0540:                        .println("            public DataType createFromPrimitiveValue(String pPrimitiveValue) throws DataTypeInstanceCreationFailureException");
0541:                pOutputWriter.println("            {");
0542:                pOutputWriter
0543:                        .println("                if (pPrimitiveValue == null)");
0544:                pOutputWriter
0545:                        .println("                    throw new DataTypeInstanceCreationFailureException(\"Supplied Primitive value is null.\");");
0546:                {
0547:                    for (int i = 0; i < lValues.length; i++) {
0548:                        ValueMetadata lValueMetadata = lValues[i];
0549:                        pOutputWriter
0550:                                .println("                if (pPrimitiveValue.equals("
0551:                                        + lValueMetadata.VariableName
0552:                                        + ".mValue))");
0553:                        pOutputWriter.println("                    return "
0554:                                + lValueMetadata.VariableName + ";");
0555:                    }
0556:                }
0557:                pOutputWriter
0558:                        .println("                throw new DataTypeInstanceCreationFailureException(\"'\" + pPrimitiveValue + \"' is not a legal value for "
0559:                                + lDatatypeName + ".\");");
0560:                pOutputWriter.println("            }");
0561:                pOutputWriter.println("        };");
0562:                pOutputWriter
0563:                        .println("        XmlTextTranslator lXmlTranslator = new XmlTextTranslator()");
0564:                pOutputWriter.println("        {");
0565:                pOutputWriter
0566:                        .println("            public String getXmlValue(DataType pDataTypeInstance) throws ClassCastException, DataTypeInvalidOperationForEmptyInstanceException, DataTypeInvalidOperationForConcealedInstanceException");
0567:                pOutputWriter.println("        	   {");
0568:                pOutputWriter.println("                " + lDatatypeName
0569:                        + " lInstance = (" + lDatatypeName
0570:                        + ")pDataTypeInstance;");
0571:                pOutputWriter
0572:                        .println("                if (lInstance.isConcealed())");
0573:                pOutputWriter
0574:                        .println("                    throw new DataTypeInvalidOperationForConcealedInstanceException();");
0575:                pOutputWriter
0576:                        .println("                if (lInstance.isEmpty())");
0577:                pOutputWriter
0578:                        .println("                    throw new DataTypeInvalidOperationForEmptyInstanceException();");
0579:                pOutputWriter
0580:                        .println("                return lInstance.mValue;");
0581:                pOutputWriter.println("            }");
0582:                pOutputWriter
0583:                        .println("            public DataType createFromXmlValue(String pXmlValue) throws DataTypeInstanceCreationFailureException");
0584:                pOutputWriter.println("            {");
0585:                pOutputWriter.println("                if (pXmlValue == null)");
0586:                pOutputWriter
0587:                        .println("                    throw new DataTypeInstanceCreationFailureException(\"Supplied Xml value is null.\");");
0588:                {
0589:                    for (int i = 0; i < lValues.length; i++) {
0590:                        ValueMetadata lValueMetadata = lValues[i];
0591:                        pOutputWriter
0592:                                .println("                if (pXmlValue.equals("
0593:                                        + lValueMetadata.VariableName
0594:                                        + ".mValue))");
0595:                        pOutputWriter.println("                    return "
0596:                                + lValueMetadata.VariableName + ";");
0597:                    }
0598:                }
0599:                pOutputWriter
0600:                        .println("                throw new DataTypeInstanceCreationFailureException(\"'\" + pXmlValue + \"' is not a legal value for "
0601:                                + lDatatypeName + ".\");");
0602:                pOutputWriter.println("            }");
0603:                pOutputWriter.println("        };");
0604:                pOutputWriter
0605:                        .println("        java.util.Properties lProperties = new java.util.Properties();");
0606:                pOutputWriter
0607:                        .println("        lProperties.setProperty(\"maxsize\",\""
0608:                                + lMaxValueLength + "\");");
0609:                pOutputWriter
0610:                        .println("        sTranslationMetadata = new DefaultDataTypeTranslationMetadataImplementation(DataTypeTranslationMetadata.SQL_VARCHAR, lProperties, lSqlTranslator, DataTypeTranslationMetadata.PRIMITIVE_STRING, null, lPrimitiveTranslator, DataTypeTranslationMetadata.XML_TEXT, null, lXmlTranslator);");
0611:                pOutputWriter.println("    }");
0612:
0613:                pOutputWriter
0614:                        .println("    /** Returns this datatype's translation metadata.");
0615:                pOutputWriter
0616:                        .println("      * See {@link com.metaboss.enterprise.datatypes.DataType DataType} for more details */");
0617:                pOutputWriter
0618:                        .println("    public static DataTypeTranslationMetadata getTranslationMetadata()");
0619:                pOutputWriter.println("    {");
0620:                pOutputWriter.println("        return sTranslationMetadata;");
0621:                pOutputWriter.println("    }");
0622:
0623:                pOutputWriter
0624:                        .println("    /** Returns string used to represent empty value in a toString() / createFromString() methods */");
0625:                pOutputWriter
0626:                        .println("    public static String getEmptyString()");
0627:                pOutputWriter.println("    {");
0628:                pOutputWriter.println("        return sEmptyString;");
0629:                pOutputWriter.println("    }");
0630:
0631:                pOutputWriter
0632:                        .println("    /** Returns string used to represent concealed value in a toString() / createFromString() methods */");
0633:                pOutputWriter
0634:                        .println("    public static String getConcealedString()");
0635:                pOutputWriter.println("    {");
0636:                pOutputWriter.println("        return sConcealedString;");
0637:                pOutputWriter.println("    }");
0638:
0639:                pOutputWriter
0640:                        .println("    /** Returns array of all valid value strings in a toString() / createFromString() methods, except empty and concealed. */");
0641:                pOutputWriter
0642:                        .println("    public static String[] getAllStrings()");
0643:                pOutputWriter.println("    {");
0644:                pOutputWriter.println("        return sAllStrings;");
0645:                pOutputWriter.println("    }");
0646:
0647:                pOutputWriter
0648:                        .println("    /** Returns array of all valid value descriptions, except descriptions for empty and concealed.");
0649:                pOutputWriter
0650:                        .println("      * Descriptions are returned in the same order as values returned from getAllStrings() method.");
0651:                pOutputWriter
0652:                        .println("      * Note that this method uses default locale for description texts. Use getAllLocalisedDescriptions() to");
0653:                pOutputWriter
0654:                        .println("      * obtain description texts for the specific locale */");
0655:                pOutputWriter
0656:                        .println("    public static String[] getAllDescriptions()");
0657:                pOutputWriter.println("    {");
0658:                pOutputWriter.println("        return sAllDescriptions;");
0659:                pOutputWriter.println("    }");
0660:
0661:                pOutputWriter
0662:                        .println("    /** Returns array of all valid value descriptions, except descriptions for empty and concealed.");
0663:                pOutputWriter
0664:                        .println("      * Descriptions are returned in the same order as values returned from getAllStrings() method.");
0665:                pOutputWriter
0666:                        .println("      * Note that this method uses specified locale for description texts. Use getAllDescriptions() to");
0667:                pOutputWriter
0668:                        .println("      * obtain description texts for the default locale.");
0669:                pOutputWriter
0670:                        .println("      * @param pDesiredLocale the locale to use for sourcing localised description strings */");
0671:                pOutputWriter
0672:                        .println("    public static String[] getAllLocalisedDescriptions(Locale pDesiredLocale)");
0673:                pOutputWriter.println("    {");
0674:                pOutputWriter.print("        return new String[] {");
0675:                // Write out public final values
0676:                {
0677:                    for (int i = 0; i < lValues.length; i++) {
0678:                        ValueMetadata lValueMetadata = lValues[i];
0679:                        pOutputWriter
0680:                                .print("ResourceUtils.getLocalisedClassResourceString(pDesiredLocale, "
0681:                                        + lDatatypeName
0682:                                        + ".class,\"Value["
0683:                                        + Integer.toString(i + 1)
0684:                                        + "].Description\",\"\")");
0685:                        if (i < (lValues.length - 1))
0686:                            pOutputWriter.print(",");
0687:                        else
0688:                            pOutputWriter.println("};");
0689:                    }
0690:                }
0691:                pOutputWriter.println("    }");
0692:                // Generate string constants for alternative jargons
0693:                for (int i = 0; i < lJargons.length; i++) {
0694:                    JargonMetadata lJargonMetadata = lJargons[i];
0695:                    pOutputWriter
0696:                            .println("    /** Returns string used to represent empty value in a toString() / createFromString() methods in "
0697:                                    + lJargonMetadata.Name + " jargon. */");
0698:                    pOutputWriter
0699:                            .println("    public static String getEmpty"
0700:                                    + lJargonMetadata.PartOfIdentifierName
0701:                                    + "String()");
0702:                    pOutputWriter.println("    {");
0703:                    pOutputWriter.println("        return sEmpty"
0704:                            + lJargonMetadata.PartOfIdentifierName + "String;");
0705:                    pOutputWriter.println("    }");
0706:
0707:                    pOutputWriter
0708:                            .println("    /** Returns string used to represent concealed value in a toString() / createFromString() methods in "
0709:                                    + lJargonMetadata.Name + " jargon. */");
0710:                    pOutputWriter
0711:                            .println("    public static String getConcealed"
0712:                                    + lJargonMetadata.PartOfIdentifierName
0713:                                    + "String()");
0714:                    pOutputWriter.println("    {");
0715:                    pOutputWriter.println("        return sConcealed"
0716:                            + lJargonMetadata.PartOfIdentifierName + "String;");
0717:                    pOutputWriter.println("    }");
0718:
0719:                    pOutputWriter
0720:                            .println("    /** Returns array of all valid value strings in a toString() / createFromString() methods in "
0721:                                    + lJargonMetadata.Name
0722:                                    + " jargon, except empty and concealed. */");
0723:                    pOutputWriter.println("    public static String[] getAll"
0724:                            + lJargonMetadata.PartOfIdentifierName
0725:                            + "Strings()");
0726:                    pOutputWriter.println("    {");
0727:                    pOutputWriter
0728:                            .println("        return sAll"
0729:                                    + lJargonMetadata.PartOfIdentifierName
0730:                                    + "Strings;");
0731:                    pOutputWriter.println("    }");
0732:                }
0733:
0734:                pOutputWriter
0735:                        .println("    /** Creates an instance of the datatype carrying an empty value */");
0736:                pOutputWriter.println("    public static " + lDatatypeName
0737:                        + " createEmpty()");
0738:                pOutputWriter.println("    {");
0739:                pOutputWriter.println("        return sEmptyInstance;");
0740:                pOutputWriter.println("    }");
0741:
0742:                pOutputWriter
0743:                        .println("    /** Creates an instance of the datatype carrying concealed value */");
0744:                pOutputWriter.println("    public static " + lDatatypeName
0745:                        + " createConcealed()");
0746:                pOutputWriter.println("    {");
0747:                pOutputWriter.println("        return sConcealedInstance;");
0748:                pOutputWriter.println("    }");
0749:
0750:                pOutputWriter
0751:                        .println("    /** Creates an instance of the datatype from given readable value */");
0752:                pOutputWriter
0753:                        .println("    public static "
0754:                                + lDatatypeName
0755:                                + " createFromString( String pSourceString) throws DataTypeValidationException");
0756:                pOutputWriter.println("    {");
0757:                pOutputWriter
0758:                        .println("        // No need to specially validate - we will either return appropriate constant or throw exception at the end");
0759:                pOutputWriter.println("        if (pSourceString == null)");
0760:                pOutputWriter
0761:                        .println("            throw new DataTypeValidationException(\"Null initialisation string is not allowed for "
0762:                                + lDatatypeName
0763:                                + ". Use createEmpty() method to create an empty "
0764:                                + lDatatypeName + "\");");
0765:                pOutputWriter
0766:                        .println("        if (pSourceString.equals(sEmptyString))");
0767:                pOutputWriter.println("            return createEmpty();");
0768:                pOutputWriter
0769:                        .println("        if (pSourceString.equals(sConcealedString))");
0770:                pOutputWriter.println("            return createConcealed();");
0771:                // Write out individual creations
0772:                for (int i = 0; i < lValues.length; i++) {
0773:                    ValueMetadata lValueMetadata = lValues[i];
0774:                    pOutputWriter.println("        if (pSourceString.equals( "
0775:                            + lValueMetadata.VariableName + ".mValue))");
0776:                    pOutputWriter.println("            return "
0777:                            + lValueMetadata.VariableName + ";");
0778:                }
0779:                pOutputWriter
0780:                        .println("        throw new DataTypeValidationException(\"'\" + pSourceString + \"' is not a legal value for "
0781:                                + lDatatypeName + ".\");");
0782:                pOutputWriter.println("    }");
0783:
0784:                pOutputWriter
0785:                        .println("    /** Validates proposed readable string */");
0786:                pOutputWriter
0787:                        .println("    public static void validateString( String pProposedString) throws DataTypeValidationException");
0788:                pOutputWriter.println("    {");
0789:                pOutputWriter.println("        if (pProposedString == null)");
0790:                pOutputWriter
0791:                        .println("            throw new DataTypeValidationException(\"Null initialisation string is not allowed for "
0792:                                + lDatatypeName
0793:                                + ". Use createEmpty() method to create an empty "
0794:                                + lDatatypeName + "\");");
0795:                pOutputWriter
0796:                        .println("        if (pProposedString.equals(sEmptyString))");
0797:                pOutputWriter.println("            return; // Done validation");
0798:                pOutputWriter
0799:                        .println("        if (pProposedString.equals(sConcealedString))");
0800:                pOutputWriter
0801:                        .println("            return; //  Done validation");
0802:                // Write out individual creations
0803:                for (int i = 0; i < lValues.length; i++) {
0804:                    ValueMetadata lValueMetadata = lValues[i];
0805:                    pOutputWriter
0806:                            .println("        if (pProposedString.equals( "
0807:                                    + lValueMetadata.VariableName + ".mValue))");
0808:                    pOutputWriter
0809:                            .println("            return; //  Done validation");
0810:                }
0811:                pOutputWriter
0812:                        .println("        throw new DataTypeValidationException(\"'\" + pProposedString + \"' is not a legal value for "
0813:                                + lDatatypeName + ".\");");
0814:                pOutputWriter.println("    }");
0815:
0816:                pOutputWriter
0817:                        .println("    /** Returns the value inside this instance of "
0818:                                + lDatatypeName + " as readable string */");
0819:                pOutputWriter.println("    public String toString()");
0820:                pOutputWriter.println("    {");
0821:                pOutputWriter.println("        if (isEmpty())");
0822:                pOutputWriter.println("            return sEmptyString;");
0823:                pOutputWriter.println("        if (isConcealed())");
0824:                pOutputWriter.println("            return sConcealedString;");
0825:                pOutputWriter.println("        return mValue;");
0826:                pOutputWriter.println("    }");
0827:
0828:                pOutputWriter
0829:                        .println("    /** Indicates whether some other object is \"equal to\" this one");
0830:                pOutputWriter
0831:                        .println("      * @return true if this object is the same as the obj argument; false otherwise. */");
0832:                pOutputWriter
0833:                        .println("    public boolean equals(Object pOtherObject)");
0834:                pOutputWriter.println("    {");
0835:                pOutputWriter.println("        if (pOtherObject == null)");
0836:                pOutputWriter.println("            return false;");
0837:                pOutputWriter.println("        if ((pOtherObject instanceof "
0838:                        + lDatatypeName + ") == false)");
0839:                pOutputWriter.println("            return false;");
0840:                pOutputWriter.println("        if (((" + lDatatypeName
0841:                        + ")pOtherObject).isConcealed() || isConcealed())");
0842:                pOutputWriter
0843:                        .println("            return false; // One of the instances is concealed");
0844:                pOutputWriter.println("        if (((" + lDatatypeName
0845:                        + ")pOtherObject).isEmpty() && isEmpty())");
0846:                pOutputWriter
0847:                        .println("            return true; // Both instances are empty.");
0848:                pOutputWriter.println("        if (((" + lDatatypeName
0849:                        + ")pOtherObject).isEmpty() != isEmpty())");
0850:                pOutputWriter
0851:                        .println("            return false; // One of the instances is empty, the other one is not");
0852:                pOutputWriter.println("        return ((" + lDatatypeName
0853:                        + ")pOtherObject).mValue.equals(mValue);");
0854:                pOutputWriter.println("    }");
0855:                if (lComparable) {
0856:                    pOutputWriter
0857:                            .println("    /** Compares this object with the specified object for order.");
0858:                    pOutputWriter
0859:                            .println("      * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object");
0860:                    pOutputWriter
0861:                            .println("      * @exception java.lang.ClassCastException - if the specified object's type prevents it from being compared to this Object. */");
0862:                    pOutputWriter
0863:                            .println("    public int compareTo(Object pOtherObject)");
0864:                    pOutputWriter.println("    {");
0865:                    pOutputWriter.println("        if (pOtherObject == null)");
0866:                    pOutputWriter
0867:                            .println("            return 1; // Anything is greater than null");
0868:                    pOutputWriter
0869:                            .println("        int lOtherObjectComparableWeight = (("
0870:                                    + lDatatypeName
0871:                                    + ")pOtherObject).mComparableWeight;");
0872:                    pOutputWriter
0873:                            .println("        if (mComparableWeight < lOtherObjectComparableWeight)");
0874:                    pOutputWriter.println("            return -1;");
0875:                    pOutputWriter
0876:                            .println("        if (mComparableWeight > lOtherObjectComparableWeight)");
0877:                    pOutputWriter.println("            return 1;");
0878:                    pOutputWriter.println("        return 0;");
0879:                    pOutputWriter.println("    }");
0880:                }
0881:
0882:                pOutputWriter
0883:                        .println("    /** Returns a hash code value for the object. This method is supported for the benefit of hashtables");
0884:                pOutputWriter
0885:                        .println("      * @return instance's hash code or zero if this instance is empty or concealed */");
0886:                pOutputWriter.println("    public int hashCode()");
0887:                pOutputWriter.println("    {");
0888:                pOutputWriter
0889:                        .println("        if (isEmpty() || isConcealed())");
0890:                pOutputWriter.println("            return 0;");
0891:                pOutputWriter.println("         return mValue.hashCode();");
0892:                pOutputWriter.println("    }");
0893:
0894:                pOutputWriter
0895:                        .println("    /** Returns true if the instance contains an empty value */");
0896:                pOutputWriter.println("    public boolean isEmpty()");
0897:                pOutputWriter.println("    {");
0898:                pOutputWriter.println("        return mState == 1;");
0899:                pOutputWriter.println("    }");
0900:
0901:                pOutputWriter
0902:                        .println("    /** Returns true if the instance contains concealed value */");
0903:                pOutputWriter.println("    public boolean isConcealed()");
0904:                pOutputWriter.println("    {");
0905:                pOutputWriter.println("        return mState == 2;");
0906:                pOutputWriter.println("    }");
0907:
0908:                // Generate methods for custom categories
0909:                for (int i = 0; i < lCategories.length; i++) {
0910:                    CategoryMetadata lCategoryMetadata = lCategories[i];
0911:                    pOutputWriter
0912:                            .println("    /** Returns true if the instance belongs to the '"
0913:                                    + lCategoryMetadata.Name + "' category.");
0914:                    pOutputWriter
0915:                            .println("      * Category description is : <i> "
0916:                                    + lCategoryMetadata.Description
0917:                                    + " </i> */");
0918:                    pOutputWriter.println("    public boolean is"
0919:                            + lCategoryMetadata.PartOfIdentifierName + "()");
0920:                    pOutputWriter.println("    {");
0921:                    if (lCategoryMetadata.CategoryValues.length > 0) {
0922:                        for (int j = 0; j < lCategoryMetadata.CategoryValues.length; j++) {
0923:                            if (j == 0)
0924:                                pOutputWriter.print("        return ");
0925:                            else {
0926:                                pOutputWriter.println(" ||");
0927:                                pOutputWriter.print("               ");
0928:                            }
0929:                            pOutputWriter
0930:                                    .print("(this == "
0931:                                            + lCategoryMetadata.CategoryValues[j].VariableName
0932:                                            + ")");
0933:                        }
0934:                        pOutputWriter.println(";");
0935:                    } else {
0936:                        pOutputWriter.println("        return false;");
0937:                    }
0938:                    pOutputWriter.println("    }");
0939:                }
0940:
0941:                // Generate methods for alternative jargons
0942:                for (int i = 0; i < lJargons.length; i++) {
0943:                    JargonMetadata lJargonMetadata = lJargons[i];
0944:
0945:                    // Generate creator method. 
0946:                    pOutputWriter
0947:                            .println("    /** Creates an instance of the datatype from given readable string in "
0948:                                    + lJargonMetadata.Name + " jargon */");
0949:                    pOutputWriter
0950:                            .println("    public static "
0951:                                    + lDatatypeName
0952:                                    + " createFrom"
0953:                                    + lJargonMetadata.PartOfIdentifierName
0954:                                    + "String( String pSourceString) throws DataTypeValidationException");
0955:                    pOutputWriter.println("    {");
0956:                    pOutputWriter
0957:                            .println("        // No need to specially validate - we will either return appropriate constant or throw exception at the end");
0958:                    pOutputWriter.println("        if (pSourceString == null)");
0959:                    pOutputWriter
0960:                            .println("            throw new DataTypeValidationException(\"Null initialisation string is not allowed for "
0961:                                    + lDatatypeName
0962:                                    + ". Use createEmpty() method to create an empty "
0963:                                    + lDatatypeName + "\");");
0964:                    pOutputWriter
0965:                            .println("        if (pSourceString.equals(sEmpty"
0966:                                    + lJargonMetadata.PartOfIdentifierName
0967:                                    + "String))");
0968:                    pOutputWriter.println("            return createEmpty();");
0969:                    pOutputWriter
0970:                            .println("        if (pSourceString.equals(sConcealed"
0971:                                    + lJargonMetadata.PartOfIdentifierName
0972:                                    + "String))");
0973:                    pOutputWriter
0974:                            .println("            return createConcealed();");
0975:                    // Write out individual creations
0976:                    for (int j = 0; j < lValues.length; j++) {
0977:                        pOutputWriter
0978:                                .println("        if (pSourceString.equals(\""
0979:                                        + lJargonMetadata.JargonValueNames[j]
0980:                                        + "\"))");
0981:                        pOutputWriter.println("            return "
0982:                                + lValues[j].VariableName + ";");
0983:                    }
0984:                    pOutputWriter
0985:                            .println("        throw new DataTypeValidationException(\"'\" + pSourceString + \"' is not a legal value for "
0986:                                    + lDatatypeName
0987:                                    + " in "
0988:                                    + lJargonMetadata.Name + " jargon.\");");
0989:                    pOutputWriter.println("    }");
0990:
0991:                    // Generate validator method. 
0992:                    pOutputWriter
0993:                            .println("    /** Validates proposed readable string in "
0994:                                    + lJargonMetadata.Name + " jargon */");
0995:                    pOutputWriter
0996:                            .println("    public static void validate"
0997:                                    + lJargonMetadata.PartOfIdentifierName
0998:                                    + "String( String pProposedString) throws DataTypeValidationException");
0999:                    pOutputWriter.println("    {");
1000:                    pOutputWriter
1001:                            .println("        if (pProposedString == null)");
1002:                    pOutputWriter
1003:                            .println("            throw new DataTypeValidationException(\"Null initialisation string is not allowed for "
1004:                                    + lDatatypeName
1005:                                    + ". Use createEmpty() method to create an empty "
1006:                                    + lDatatypeName + "\");");
1007:                    pOutputWriter
1008:                            .println("        if (pProposedString.equals(sEmpty"
1009:                                    + lJargonMetadata.PartOfIdentifierName
1010:                                    + "String))");
1011:                    pOutputWriter
1012:                            .println("            return; // Done validation");
1013:                    pOutputWriter
1014:                            .println("        if (pProposedString.equals(sConcealed"
1015:                                    + lJargonMetadata.PartOfIdentifierName
1016:                                    + "String))");
1017:                    pOutputWriter
1018:                            .println("            return; //  Done validation");
1019:                    // Write out individual creations
1020:                    for (int j = 0; j < lValues.length; j++) {
1021:                        pOutputWriter
1022:                                .println("        if (pProposedString.equals(\""
1023:                                        + lJargonMetadata.JargonValueNames[j]
1024:                                        + "\"))");
1025:                        pOutputWriter
1026:                                .println("            return; //  Done validation");
1027:                    }
1028:                    pOutputWriter
1029:                            .println("        throw new DataTypeValidationException(\"'\" + pProposedString + \"' is not a legal value for "
1030:                                    + lDatatypeName
1031:                                    + " in "
1032:                                    + lJargonMetadata.Name + " jargon.\");");
1033:                    pOutputWriter.println("    }");
1034:
1035:                    // Generate getter method. using to<JargonName>String() to higlight that it is an alternative to toString() nothing elese
1036:                    pOutputWriter
1037:                            .println("    /** Returns the value inside this instance of "
1038:                                    + lDatatypeName
1039:                                    + " as readable string in "
1040:                                    + lJargonMetadata.Name + " jargon */");
1041:                    pOutputWriter
1042:                            .println("    public String to"
1043:                                    + lJargonMetadata.PartOfIdentifierName
1044:                                    + "String()");
1045:                    pOutputWriter.println("    {");
1046:                    pOutputWriter.println("        if (isEmpty())");
1047:                    pOutputWriter.println("            return sEmpty"
1048:                            + lJargonMetadata.PartOfIdentifierName + "String;");
1049:                    pOutputWriter.println("        if (isConcealed())");
1050:                    pOutputWriter.println("            return sConcealed"
1051:                            + lJargonMetadata.PartOfIdentifierName + "String;");
1052:                    // Write out other values
1053:                    for (int j = 0; j < lValues.length; j++) {
1054:                        pOutputWriter.println("        if (mValue.equals("
1055:                                + lValues[j].VariableName + ".mValue))");
1056:                        pOutputWriter.println("            return \""
1057:                                + lJargonMetadata.JargonValueNames[j] + "\";");
1058:                    }
1059:                    pOutputWriter
1060:                            .println("        throw new com.metaboss.enterprise.datatypes.DataTypeRuntimeException(\"Unexpected program condition. Detected illegal internal state of the enumerable type instance.\");");
1061:                    pOutputWriter.println("    }");
1062:                }
1063:
1064:                pOutputWriter
1065:                        .println("    // Private access. External callers must use one of the static creators");
1066:                pOutputWriter.println("    private " + lDatatypeName
1067:                        + "( byte pState, String pValue"
1068:                        + ((lComparable) ? ", int pComparableWeight" : "")
1069:                        + ")");
1070:                pOutputWriter.println("    {");
1071:                pOutputWriter.println("        mState = pState;");
1072:                pOutputWriter.println("        mValue = pValue;");
1073:                if (lComparable)
1074:                    pOutputWriter
1075:                            .println("        mComparableWeight = pComparableWeight;");
1076:                pOutputWriter.println("    }");
1077:                pOutputWriter.println("}");
1078:            }
1079:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.