Source Code Cross Referenced for ListOption.java in  » Code-Analyzer » doctorj » org » incava » jagol » 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 » Code Analyzer » doctorj » org.incava.jagol 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.incava.jagol;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import org.incava.lang.StringExt;
006:
007:        /**
008:         * Represents a list of objects that comprise this option.
009:         */
010:        public class ListOption extends Option {
011:            private List value;
012:
013:            /**
014:             * Creates the option.
015:             */
016:            public ListOption(String longName, String description) {
017:                this (longName, description, new ArrayList());
018:            }
019:
020:            /**
021:             * Creates the option, with a default list.
022:             */
023:            public ListOption(String longName, String description, List value) {
024:                super (longName, description);
025:                this .value = value;
026:            }
027:
028:            /**
029:             * Returns the value. This is empty by default.
030:             */
031:            public List getValue() {
032:                return value;
033:            }
034:
035:            /**
036:             * Sets the value.
037:             */
038:            public void setValue(List value) {
039:                this .value = value;
040:            }
041:
042:            /**
043:             * Sets the value from the string, for a list type. Assumes whitespace or
044:             * comma delimiter
045:             */
046:            public void setValue(String value) throws InvalidTypeException {
047:                tr.Ace.log("value: '" + value + "'");
048:                parse(value);
049:            }
050:
051:            /**
052:             * Sets from a list of command-line arguments. Returns whether this option
053:             * could be set from the current head of the list. Assumes whitespace or
054:             * comma delimiter.
055:             */
056:            public boolean set(String arg, List args) throws OptionException {
057:                tr.Ace.log("arg: " + arg + "; args: " + args);
058:
059:                if (arg.equals("--" + longName)) {
060:                    tr.Ace.log("matched long name");
061:
062:                    if (args.size() == 0) {
063:                        throw new InvalidTypeException(longName
064:                                + " expects following argument");
065:                    } else {
066:                        String value = (String) args.remove(0);
067:                        setValue(value);
068:                    }
069:                } else if (arg.startsWith("--" + longName + "=")) {
070:                    tr.Ace.log("matched long name + equals");
071:
072:                    // args.remove(0);
073:                    int pos = ("--" + longName + "=").length();
074:                    tr.Ace.log("position: " + pos);
075:                    if (pos >= arg.length()) {
076:                        throw new InvalidTypeException(longName
077:                                + " expects argument");
078:                    } else {
079:                        String value = arg.substring(pos);
080:                        setValue(value);
081:                    }
082:                } else if (shortName != 0 && arg.equals("-" + shortName)) {
083:                    tr.Ace.log("matched short name");
084:
085:                    if (args.size() == 0) {
086:                        throw new InvalidTypeException(shortName
087:                                + " expects following argument");
088:                    } else {
089:                        String value = (String) args.remove(0);
090:                        setValue(value);
091:                    }
092:                } else {
093:                    tr.Ace.log("not a match");
094:                    return false;
095:                }
096:                return true;
097:            }
098:
099:            /**
100:             * Parses the value into the value list. If subclasses want to convert the
101:             * string to their own data type, override the <code>convert</code> method.
102:             *
103:             * @see ListOption#convert(String)
104:             */
105:            protected void parse(String str) throws InvalidTypeException {
106:                List list = StringExt.listify(str);
107:                Iterator it = list.iterator();
108:                while (it.hasNext()) {
109:                    String s = (String) it.next();
110:                    if (!s.equals("+=")) {
111:                        value.add(convert(s));
112:                    }
113:                }
114:            }
115:
116:            /**
117:             * Returns the string, possibly converted to a different Object type. 
118:             * Subclasses can convert the string to their own data type.
119:             */
120:            protected Object convert(String str) throws InvalidTypeException {
121:                return str;
122:            }
123:
124:            public String toString() {
125:                StringBuffer buf = new StringBuffer();
126:                Iterator it = value.iterator();
127:                boolean isFirst = true;
128:                while (it.hasNext()) {
129:                    if (isFirst) {
130:                        isFirst = false;
131:                    } else {
132:                        buf.append(", ");
133:                    }
134:                    buf.append(it.next());
135:                }
136:                return buf.toString();
137:            }
138:
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.