Source Code Cross Referenced for Parameter.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » newbean » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.newbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         * 
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         * 
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer(s): Nicolas Christin
022:         * Contributor(s): ______________________________________.
023:         *
024:         * --------------------------------------------------------------------------
025:         * $Id: Parameter.java 3736 2003-11-21 01:13:25Z skrupanszky $
026:         * --------------------------------------------------------------------------
027:         */
028:
029:        package org.objectweb.jonas.newbean;
030:
031:        import java.io.BufferedReader;
032:        import java.io.InputStreamReader;
033:        import java.io.IOException;
034:
035:        import org.apache.velocity.VelocityContext;
036:
037:        /**
038:         * This class represents a parameter the user may be prompted for. It
039:         * is responsible for asking the user for a value, validating his
040:         * input, exporting relevant datas into Velocity's context, and
041:         * deciding what should be the next parameter to ask.<p>
042:         *
043:         * A parameter is created by subclassing this class and overriding the
044:         * following abstract methods:
045:         *
046:         * <ul>
047:         *   <li>{@link #getPrompt()}</li>
048:         *   <li>{@link #isValid()}</li>
049:         *   <li>{@link #export()}</li>
050:         *   <li>{@link #getNextParameter()}</li>
051:         * </ul>
052:         */
053:        public abstract class Parameter {
054:
055:            private static final String PROMPT = "> ";
056:            private static final int INPUT_BUFFER_SIZE = 80;
057:            private static BufferedReader reader = new BufferedReader(
058:                    new InputStreamReader(System.in));
059:
060:            /** 
061:             * The Velocity context into which this parameter's variables will
062:             * be exported.
063:             */
064:            protected VelocityContext vContext = null;
065:
066:            /**
067:             * This parameter's value, as entered by the user.
068:             */
069:            protected String value = null;
070:
071:            /**
072:             * Creates a new parameter that will export its variables into the
073:             * specified Velocity context.
074:             *
075:             * @param context the Velocity context into which variables will
076:             * be exported
077:             */
078:            public Parameter(VelocityContext context) {
079:                vContext = context;
080:            }
081:
082:            /**
083:             * Recusively walk through the parameters graph, obtaining
084:             * parameter ({@link #obtainValue()}) values and exporting ({@link
085:             * #export()}) them.<p>
086:             *
087:             * The path taken through the parameter graph may change depending
088:             * on the values entered by the user. It is determined after each
089:             * valid input by a call to {@link #getNextParameter()}.
090:             */
091:            public void walkThrough() {
092:                obtainValue();
093:                export();
094:                Parameter nextParameter = getNextParameter();
095:                if (nextParameter != null) {
096:                    nextParameter.walkThrough();
097:                }
098:            }
099:
100:            /**
101:             * Obtains the value of this parameter. This method prompts the
102:             * user for a value, stores it into {@link #value} through the
103:             * {@link #isValid()}. This process is repeated until the value is
104:             * valid.
105:             */
106:            public void obtainValue() {
107:
108:                // check first if a cmd-line value has been specified
109:                String inp = getCmdArg(getArgKeyword());
110:                if (inp != null) {
111:                    setValue(inp);
112:                    if (isValid()) {
113:                        return;
114:                    }
115:                }
116:
117:                for (;;) {
118:                    String input = null;
119:                    System.out.println(getPrompt());
120:                    System.out.print("> ");
121:                    try {
122:                        input = reader.readLine();
123:                    } catch (IOException e) {
124:                        NewBean.error(e.toString());
125:                    }
126:                    if (input == null) {
127:                        input = "";
128:                    }
129:                    setValue(input);
130:                    if (isValid())
131:                        break;
132:                    System.out.println("Invalid value, please retry");
133:                }
134:                System.out.println();
135:            }
136:
137:            /**
138:             * Sets the {@link #value} of this parameter. This method is
139:             * called each time a value is entered is entered by the user,
140:             * before its validity has been checked.<p>
141:             *
142:             * This implementation simply sets {@link #value} to
143:             * <code>input</code>. You can override this method if you need to
144:             * format this input, for example to convert it to uppercase.
145:             */
146:            public void setValue(String input) {
147:                value = input;
148:            }
149:
150:            /**
151:             * Returns the string used to prompt the user for a value.
152:             * @return the string used to prompt the user for a value.
153:             */
154:            public abstract String getPrompt();
155:
156:            /**
157:             * Indicates whether this parameter as a valid value. This method
158:             * can safely assume {@link #value} is not <code>null</code>.
159:             *
160:             * @return <code>true</code> if {@link #value} is valid,
161:             * <code>false</code> otherwise
162:             */
163:            public abstract boolean isValid();
164:
165:            /**
166:             * Exports the variables managed by this parameter into the
167:             * associated Velocity context (<i>ie</i> {@link #vContext}).
168:             */
169:            public abstract void export();
170:
171:            /**
172:             * Returns the parameter the user will be asked for after this
173:             * one. This method is not invoked before a valid value has been
174:             * entered for this parameter; therefor it is possible to decide
175:             * which object to return based on the value of {@link #value}.<p>
176:             *
177:             * This method returns <code>null</code> if their is no more
178:             * parameters.
179:             *
180:             * @return the next parameter the user should be prompted for
181:             */
182:            public abstract Parameter getNextParameter();
183:
184:            /**
185:             * @return the command line keyword string for this parameter
186:             */
187:            public abstract String getArgKeyword();
188:
189:            private String getCmdArg(String kwd) {
190:                return (String) NewBean.commandLine.get(kwd);
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.