Source Code Cross Referenced for CommandLineApplicationEnvironment.java in  » Code-Analyzer » beautyJ » de » gulden » framework » amoda » environment » commandline » 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 » beautyJ » de.gulden.framework.amoda.environment.commandline 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Project: AMODA - Abstract Modeled Application
003:         * Class:   de.gulden.framework.amoda.environment.commandline.CommandLineApplicationEnvironment
004:         * Version: snapshot-beautyj-1.1
005:         *
006:         * Date:    2004-09-29
007:         *
008:         * This is a snapshot version of the AMODA 0.2 development branch,
009:         * it is not released as a seperate version.
010:         * For AMODA, see http://amoda.berlios.de/.
011:         *  
012:         * This is licensed under the GNU Lesser General Public License (LGPL)
013:         * and comes with NO WARRANTY.
014:         *
015:         * Author:  Jens Gulden
016:         * Email:   amoda@jensgulden.de
017:         */
018:
019:        package de.gulden.framework.amoda.environment.commandline;
020:
021:        import de.gulden.framework.amoda.environment.commandline.CommandLineArgsParser;
022:        import de.gulden.framework.amoda.generic.core.*;
023:        import de.gulden.framework.amoda.generic.core.GenericApplicationEnvironment;
024:        import de.gulden.framework.amoda.model.data.Value;
025:        import de.gulden.framework.amoda.model.interaction.*;
026:        import de.gulden.framework.amoda.model.option.*;
027:        import java.lang.*;
028:        import java.util.*;
029:
030:        /**
031:         * Class CommandLineApplicationEnvironment.
032:         *  
033:         * @author  Jens Gulden
034:         * @version  snapshot-beautyj-1.1
035:         */
036:        public class CommandLineApplicationEnvironment extends
037:                GenericApplicationEnvironment {
038:
039:            // ------------------------------------------------------------------------
040:            // --- constructor                                                      ---
041:            // ------------------------------------------------------------------------
042:
043:            public CommandLineApplicationEnvironment() {
044:                super ();
045:            }
046:
047:            // ------------------------------------------------------------------------
048:            // --- methods                                                          ---
049:            // ------------------------------------------------------------------------
050:
051:            public void doQuestion(Question question) {
052:                System.out.println(question.getText());
053:                de.gulden.framework.amoda.generic.interaction.GenericQuestion q = (de.gulden.framework.amoda.generic.interaction.GenericQuestion) question;
054:                de.gulden.framework.amoda.generic.option.GenericOptionChoice choice = new de.gulden.framework.amoda.generic.option.GenericOptionChoice();
055:                choice.setParent(getGenericApplication());
056:                choice.addAll(q.getAnswerOptions());
057:                askOption(choice);
058:                q.setAnswer(choice.getSelectedOption().getId());
059:            }
060:
061:            public void doMessage(Message message) {
062:                GenericApplication application = getGenericApplication();
063:                if ((application == null) || !application.isQuiet()) {
064:                    System.out.println(message.getText());
065:                    if ((message instanceof  de.gulden.framework.amoda.generic.interaction.GenericMessage)
066:                            && ((de.gulden.framework.amoda.generic.interaction.GenericMessage) message)
067:                                    .getTitle().equals("about")) {
068:                        System.out.println();
069:                    }
070:                }
071:            }
072:
073:            public void doErrorMessage(ErrorMessage errorMessage) {
074:                GenericApplication application = getGenericApplication();
075:                boolean verbose = (application == null)
076:                        || application.isVerbose();
077:                Throwable cause = errorMessage.getCause();
078:                String txt = errorMessage.getText();
079:                if ((txt != null) && (txt.length() > 1)) {
080:                    txt = txt.substring(0, 1).toUpperCase()
081:                            + txt.substring(1)
082:                            + (txt.length() > 10 ? (!txt.endsWith(".") ? "."
083:                                    : "") : "");
084:                }
085:                if ((cause != null) && (verbose || (txt == null))) {
086:                    if (txt == null) {
087:                        txt = "";
088:                    } else {
089:                        txt += " ";
090:                    }
091:                    txt += de.gulden.util.Toolbox.unqualify(cause.getClass()
092:                            .getName());
093:                    String causeMsg = cause.getMessage();
094:                    if (causeMsg != null) {
095:                        txt += ": " + causeMsg;
096:                    }
097:                    if (!txt.endsWith(".")) {
098:                        txt += ".";
099:                    }
100:                }
101:                boolean stacktrace = ((txt == null) || verbose);
102:                if (txt == null) {
103:                    txt = "(no message)";
104:                }
105:                txt = "Error: " + txt + " ('-help' for options)";
106:
107:                System.out.println(txt);
108:
109:                if (stacktrace && (cause != null)) {
110:                    cause.printStackTrace(System.out);
111:                }
112:                if (errorMessage.exitApplication()) {
113:                    System.exit(1); // (from OS point of view, 1 is a good value for returning from any Java program on error (no higher values, because OS is usually unaffected))
114:                }
115:            }
116:
117:            public void doDialog(Dialog dialog) {
118:                // your code here
119:            }
120:
121:            public void doWizard(Wizard wizard) {
122:                // your code here
123:            }
124:
125:            public void doExit(GenericApplication application, int code) {
126:                System.exit(code);
127:            }
128:
129:            protected void askOption(Option option) {
130:                if (option instanceof  de.gulden.framework.amoda.model.option.OptionEntry) {
131:                    de.gulden.framework.amoda.model.option.OptionEntry optionValue = (de.gulden.framework.amoda.model.option.OptionEntry) option;
132:                    Object value = optionValue.getValue(Option.STATE_DEFAULT)
133:                            .get();
134:                    String defaultMessage;
135:                    if (value instanceof  Boolean) {
136:                        Boolean bool = (Boolean) value;
137:                        boolean b = bool.booleanValue();
138:                        defaultMessage = "[" + (b ? "_j_/n" : "j/_n_") + "]"; // *********** VARIABLEN F?R "J" / "N"
139:                    } else {
140:                        String def = option.toString();
141:                        if ((def != null) && (def.length() > 0)) {
142:                            defaultMessage = "[default: " + def + "]";
143:                        } else {
144:                            defaultMessage = null;
145:                        }
146:                    }
147:                    do {
148:                        if (defaultMessage != null) {
149:                            System.out.println(defaultMessage);
150:                        }
151:                        try {
152:                            String r = (new java.io.BufferedReader(
153:                                    new java.io.InputStreamReader(System.in)))
154:                                    .readLine();
155:                            if (!r.equals("")) {
156:                                ((de.gulden.framework.amoda.generic.data.GenericValue) optionValue
157:                                        .getValue()).parseString(r);
158:                            } // if "", leave default
159:                        } catch (java.io.IOException ioe) {
160:                            System.out.println("ERROR: i/o exception");
161:                            // may lead to accepting default value or to retry
162:                        }
163:                    } while (!optionValue.isValid());
164:                } else if (option instanceof  de.gulden.framework.amoda.model.option.OptionsGroup) {
165:                    // ****** !!!! PROVISORISCH
166:                    Collection values = ((de.gulden.framework.amoda.model.option.OptionsGroup) option)
167:                            .getEntries().values();
168:                    for (Iterator it = values.iterator(); it.hasNext();) {
169:                        Option o = (Option) it.next();
170:                        askOption(o); // recurse
171:                    }
172:                }
173:            }
174:
175:            // ------------------------------------------------------------------------
176:            // --- static method                                                    ---
177:            // ------------------------------------------------------------------------
178:
179:            public static void invoke(Class applicationClass, String[] args)
180:                    throws Exception {
181:                GenericApplicationEnvironment.invoke(applicationClass, args,
182:                        CommandLineApplicationEnvironmentFactory.class);
183:            }
184:
185:        } // end CommandLineApplicationEnvironment
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.