Source Code Cross Referenced for FmtSelector.java in  » Test-Coverage » Quilt » org » quilt » reports » 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 » Test Coverage » Quilt » org.quilt.reports 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* FmtSelector.java */
002:
003:        package org.quilt.reports;
004:
005:        import java.io.File;
006:        import java.io.FileOutputStream;
007:        import java.io.OutputStream;
008:        import java.util.Hashtable;
009:
010:        import org.apache.tools.ant.BuildException;
011:
012:        public class FmtSelector {
013:
014:            private String classname;
015:            private String extension = ".txt";
016:            private OutputStream out = System.out;
017:            private File outFile;
018:            private boolean useFile = true;
019:
020:            /**
021:             * Ant-compatible method for creating formatters.  Either
022:             * the type or the classname must be specified in the build
023:             * file or on the command line.
024:             *
025:             * @todo Modify Textui to accept 'types' on the command line.
026:             * @todo Make sure extension corresponds to type.
027:             * 
028:             * @return Formatter as an object
029:             */
030:            public Formatter createFormatter() throws BuildException {
031:                // classname muat have been set either by setClassname or setType
032:                if (classname == null) {
033:                    throw new BuildException("missing formatter class name");
034:                }
035:                // particularly paranoid way of determining whether class is
036:                // suitable.  First, is it actually a class?
037:                Class fmtClass = null;
038:                try {
039:                    fmtClass = Class.forName(classname);
040:                } catch (ClassNotFoundException e) {
041:                    throw new BuildException(e);
042:                }
043:                // Get an instance of the class.  Is it a Formatter?
044:                Formatter fmt = null;
045:                try {
046:                    fmt = (Formatter) fmtClass.newInstance();
047:                } catch (IllegalAccessException e) {
048:                    throw new BuildException(e);
049:                } catch (InstantiationException e) {
050:                    throw new BuildException(e);
051:                } catch (ClassCastException e) {
052:                    throw new BuildException(classname + " is not a Formatter");
053:                }
054:                if (useFile && outFile != null) {
055:                    // we are supposed to write to a file 
056:                    try {
057:                        // open it
058:                        out = new FileOutputStream(outFile);
059:                    } catch (java.io.IOException e) {
060:                        throw new BuildException(e);
061:                    }
062:                }
063:                // set the formatter to write to the output file (defaults to 
064:                // System.out)
065:                fmt.setOutput(out);
066:                return fmt;
067:            }
068:
069:            // //////////////////////////////////////////////////////////////
070:            // SET TYPE 
071:            // //////////////////////////////////////////////////////////////
072:            /** File name extensions associated with formatters. */
073:            private static Hashtable extensions = null;
074:            /** Table of abbreviations for formatters. */
075:            private static Hashtable types = null;
076:            {
077:                types = new Hashtable();
078:                types.put("brief", "org.quilt.reports.BriefFormatter");
079:                types.put("plain", "org.quilt.reports.PlainFormatter");
080:                types.put("summary", "org.quilt.reports.SummaryFormatter");
081:                types.put("xml", "org.quilt.reports.XMLFormatter");
082:
083:                // could save work by just using default except when type is "xml"
084:                extensions = new Hashtable();
085:                extensions.put("org.quilt.reports.BriefFormatter", ".txt");
086:                extensions.put("org.quilt.reports.PlainFormatter", ".txt");
087:                extensions.put("org.quilt.reports.SummaryFormatter", ".txt");
088:                extensions.put("org.quilt.reports.XMLFormatter", ".xml");
089:            }
090:
091:            /** 
092:             * @return Whether the String passed is an alias for a standard formatter 
093:             */
094:            public boolean isKnownType(String t) {
095:                return types.containsKey(t);
096:            }
097:
098:            /** 
099:             * Routine called by Ant to set the formatter using an alias.  This 
100:             * is an attribute of the formatter element.  Example
101:             * <pre>
102:             *
103:             *      &lt;formatter type="plain"&gt;
104:             *
105:             * </pre>
106:             * @param t 'Type' of the formatter (brief, plain, summary, xml)
107:             */
108:            public void setType(String t) {
109:                if (!types.containsKey(t)) {
110:                    throw new BuildException("unknown formatter type " + t);
111:                }
112:                classname = (String) types.get(t);
113:                extension = (String) extensions.get(classname);
114:            }
115:
116:            // //////////////////////////////////////////////////////////////
117:            // OTHER GET/SET METHODS 
118:            // //////////////////////////////////////////////////////////////
119:            /** @return the class name of the formatter */
120:            public String getClassname() {
121:                return classname;
122:            }
123:
124:            /** Ant-compatible method for selecting formatter by class name. */
125:            public void setClassname(String classname) {
126:                this .classname = classname;
127:            }
128:
129:            /**
130:             * Get the extension of the formatter output file.  Defaults to 
131:             * ".txt".  (This differs from the Ant JUnitTask, which requires 
132:             * that the extension be specified if the formatter is selected by
133:             * class name.)
134:             * 
135:             * @return The extension as a String. 
136:             */
137:            public String getExtension() {
138:                return extension;
139:            }
140:
141:            /** 
142:             * Ant-compatible method for setting the extension of the 
143:             * formatter output file.
144:             * 
145:             * @see #setOutfile
146:             */
147:            public void setExtension(String ext) {
148:                extension = ext;
149:            }
150:
151:            /** 
152:             * Ant-compatible method for setting the base name of the output file. 
153:             * 
154:             * @see #setExtension
155:             */
156:            public void setOutfile(File out) {
157:                outFile = out;
158:            }
159:
160:            public void setOutput(OutputStream out) {
161:                out = out;
162:            }
163:
164:            /** @return Whether output to a file is enabled. */
165:            public boolean getUseFile() {
166:                return useFile;
167:            }
168:
169:            /** 
170:             * Ant-compatible method for enabling output to a file. Defaults to 
171:             * true.
172:             */
173:            public void setUseFile(boolean b) {
174:                this .useFile = b;
175:            }
176:
177:            /** 
178:             * Converts some class information to String format. 
179:             * @return The string.
180:             */
181:            public String toString() {
182:                return "Formatter: " + classname + ", extension: " + extension;
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.