Source Code Cross Referenced for CLIPOption.java in  » Portal » Open-Portal » com » sun » portal » rewriter » util » clip » 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 » Portal » Open Portal » com.sun.portal.rewriter.util.clip 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         *
005:         * File:CLIPOption.java
006:         *
007:         *  Copyright (c) 2001 Sun Microsystems, Inc.
008:         *  All rights reserved.
009:         *
010:         * Date      - Dec/15/2001
011:         * Author    - alejandro.abdelnur@sun.com
012:         * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
013:         */
014:        package com.sun.portal.rewriter.util.clip;
015:
016:        import com.sun.portal.rewriter.util.i18n.LocaleHelper;
017:
018:        import java.util.ArrayList;
019:        import java.util.Arrays;
020:        import java.util.List;
021:        import java.util.StringTokenizer;
022:
023:        /**
024:         * The Option class defines a CLIP option.
025:         * <P>
026:         * It defines the long and short (if exists) names, if the option is mandatory, its type and default value (if any).
027:         * <P>
028:         */
029:        public class CLIPOption {
030:            static final CLIPOption[] EMTPY_CLIP_OPTION_ARRAY = new CLIPOption[0];
031:
032:            private String longName;
033:            private String shortName;
034:            private boolean mandatory;
035:            private int type;
036:            private String[] defaultValues = null;
037:            private final String helpMessageID;
038:
039:            /**
040:             * Creates a CLIPParser Option.
041:             * <P>
042:             * @param aLongName option's long name, it can not be NULL and it has to be at least 2 characters.
043:             * @param aShortName option's short name, it can be undefined (NULL) or it has to be exactly one character.
044:             * @param aType indicates the type of the option, it can be BOOLEAN, REGULAR or COLLECTION.
045:             * @param aDefaultValues specifies the option default value if any, NULL indicates no default value.
046:             *                      If the option has not default value the option is mandatory.
047:             *                      If the option is a collection the elements have to be separated with commas or white spaces,
048:             *                      if a white space is present then the commas are consider part of a single value.
049:             *                      For boolean options the default value can be 'true' or 'false'.
050:             * @param aHelpMessageID help message for the option.
051:             * @throws IllegalArgumentException if the information passed is invalid.
052:             */
053:            public CLIPOption(final String aLongName, final String aShortName,
054:                    final int aType, final String aDefaultValues,
055:                    final String aHelpMessageID)
056:                    throws IllegalArgumentException {
057:                setLongName(aLongName);
058:                setShortName(aShortName);
059:                setType(aType);
060:                setDefaultValues(aType, aDefaultValues, aShortName);
061:                helpMessageID = aHelpMessageID;
062:            }//constructor
063:
064:            public String getLongName() {
065:                return longName;
066:            }//getLongName()
067:
068:            public String getShortName() {
069:                return shortName;
070:            }//getShortName()
071:
072:            public boolean isMandatory() {
073:                return mandatory;
074:            }//isManadatory()
075:
076:            public int getType() {
077:                return type;
078:            }//getType()
079:
080:            public String[] getDefaultValues() {
081:                return defaultValues;
082:            }//getDefaultValues()
083:
084:            public String getHelpMessage() {
085:                return CLIPSpec.getLocaleHelper().getLocalizedString(
086:                        helpMessageID);
087:            }//getHelpMessage()
088:
089:            private void setLongName(final String aLongName) {
090:                CLIPParser.verifyName(aLongName,
091:                        "CLIPOption - Option's long name");
092:                longName = aLongName.trim();
093:            }//setLongName()
094:
095:            private void setMandatory(final String aDefaultValues) {
096:                mandatory = (aDefaultValues == null || aDefaultValues.trim()
097:                        .equalsIgnoreCase(""));
098:            }//setMandatory()
099:
100:            private void setShortName(final String aShortName) {
101:                if (aShortName == null) {
102:                    return;
103:                }
104:
105:                if (aShortName.length() > 1) {
106:                    throw new IllegalArgumentException(
107:                            "CLIPOption - Option's short name has to be undefined (NULL) or one character long");
108:                }
109:
110:                if (aShortName.equals("-")) {
111:                    throw new IllegalArgumentException(
112:                            "CLIPOption - Option's short name can not be '-'");
113:                }
114:
115:                shortName = aShortName.trim();
116:            }//setShortName()
117:
118:            private void setType(final int aType) {
119:                type = aType;
120:            }//setType()
121:
122:            private void setDefaultValues(final int aType,
123:                    final String aDefaultValues, final String aShortName) {
124:                setMandatory(aDefaultValues);
125:
126:                //let the default value be set only if this is not a mandatory option
127:                if (isMandatory()) {
128:                    return;
129:                }
130:
131:                switch (aType) {
132:                case CLIPConstants.BOOLEAN: {
133:                    String value = aDefaultValues.trim();
134:                    if (!value.equals("true") && !value.equals("false")) {
135:                        throw new IllegalArgumentException(
136:                                "CLIPOption - Boolean default value has to be 'true' or 'false'");
137:                    }
138:                    defaultValues = new String[1];
139:                    defaultValues[0] = value;
140:                    break;
141:                }
142:                case CLIPConstants.REGULAR: {
143:                    defaultValues = new String[1];
144:                    defaultValues[0] = aDefaultValues;
145:                    break;
146:                }
147:                case CLIPConstants.COLLECTION: {
148:                    if (aShortName != null) {
149:                        throw new IllegalArgumentException(
150:                                "CLIPOption - Collection options can not have short names");
151:                    }
152:                    List lCollection = new ArrayList();
153:                    String tokenSeparator = (aDefaultValues.indexOf(" ") > -1) ? " "
154:                            : ",";
155:                    StringTokenizer tokens = new StringTokenizer(
156:                            aDefaultValues, tokenSeparator);
157:                    while (tokens.hasMoreTokens()) {
158:                        String token = tokens.nextToken();
159:                        lCollection.add(token);
160:                    }
161:                    defaultValues = new String[lCollection.size()];
162:                    lCollection.toArray(defaultValues);
163:                    break;
164:                }
165:                default: {
166:                    throw new IllegalArgumentException(
167:                            "CLIPOption - Invalid type");
168:                }
169:                }//switch/case
170:            }//setDefaultValues()
171:
172:            public String toString() {
173:                return "\nLongName : " + getLongName() + "\n" + "ShortName : "
174:                        + getShortName() + "\n" + "Mandatory: " + isMandatory()
175:                        + "\n" + "Type: " + getType() + "\n"
176:                        + "DefaultValues: " + Arrays.asList(getDefaultValues())
177:                        + "\n" + "HelpMessage: " + getHelpMessage() + "\n";
178:            }//toString()
179:
180:            public static void main(String[] args) {
181:                LocaleHelper.store("psrwCLI", LocaleHelper.getLocale(null));
182:                CLIPOption clipOption = new CLIPOption("version", null,
183:                        CLIPConstants.COLLECTION, "a b c d e", "TestMessage");
184:                System.out.println(clipOption.getHelpMessage());
185:            }//main()
186:        }//class CLIPOption
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.