Source Code Cross Referenced for CoverageTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » serializable » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.test.serializable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2005-2006, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         *
007:         */
008:
009:        package com.ibm.icu.dev.test.serializable;
010:
011:        import java.io.ByteArrayInputStream;
012:        import java.io.ByteArrayOutputStream;
013:        import java.io.File;
014:        import java.io.FileOutputStream;
015:        import java.io.IOException;
016:        import java.io.ObjectOutputStream;
017:        import java.lang.reflect.Field;
018:        import java.lang.reflect.Modifier;
019:        import java.net.URL;
020:
021:        import com.ibm.icu.impl.URLHandler;
022:
023:        /**
024:         * @author emader
025:         *
026:         * TODO To change the template for this generated type comment go to
027:         * Window - Preferences - Java - Code Style - Code Templates
028:         */
029:        public class CoverageTest extends CompatibilityTest implements 
030:                URLHandler.URLVisitor {
031:
032:            private static Class serializable;
033:
034:            public void init() {
035:                try {
036:                    serializable = Class.forName("java.io.Serializable");
037:                } catch (Exception e) {
038:                    // we're in deep trouble...
039:                    warnln("Woops! Can't get class info for Serializable.");
040:                }
041:            }
042:
043:            private Target head = new Target(null);
044:            private Target tail = head;
045:
046:            private String path;
047:
048:            public CoverageTest() {
049:                this (null);
050:            }
051:
052:            public CoverageTest(String path) {
053:                this .path = path;
054:
055:                if (path != null) {
056:                    File dir = new File(path);
057:
058:                    if (!dir.exists()) {
059:                        dir.mkdirs();
060:                    }
061:                }
062:            }
063:
064:            private void writeFile(String className, byte bytes[]) {
065:                File file = new File(path + File.separator + className + ".dat");
066:                FileOutputStream stream;
067:
068:                try {
069:                    stream = new FileOutputStream(file);
070:
071:                    stream.write(bytes);
072:                    stream.close();
073:                } catch (Exception e) {
074:                    System.out.print(" - can't write file!");
075:                }
076:            }
077:
078:            private void add(String className, int classModifiers, byte bytes[]) {
079:                CoverageTarget newTarget = new CoverageTarget(className,
080:                        classModifiers, bytes);
081:
082:                tail.setNext(newTarget);
083:                tail = newTarget;
084:            }
085:
086:            public class CoverageTarget extends HandlerTarget {
087:                private byte bytes[];
088:                private int modifiers;
089:
090:                public CoverageTarget(String className, int classModifiers,
091:                        byte bytes[]) {
092:                    super (className, bytes == null ? null
093:                            : new ByteArrayInputStream(bytes));
094:
095:                    this .bytes = bytes;
096:                    modifiers = classModifiers;
097:                }
098:
099:                public boolean validate() {
100:                    return super .validate() || Modifier.isAbstract(modifiers);
101:                }
102:
103:                public void execute() throws Exception {
104:                    if (inputStream == null) {
105:                        params.testCount += 1;
106:                    } else {
107:                        Class c = Class.forName(name);
108:                        try {
109:                            Field uid = c.getDeclaredField("serialVersionUID");
110:                        } catch (Exception e) {
111:                            errln("No serialVersionUID");
112:                        }
113:
114:                        if (path != null) {
115:                            writeFile(name, bytes);
116:                        }
117:
118:                        super .execute();
119:                    }
120:                }
121:            }
122:
123:            public void visit(String str) {
124:                if (serializable == null) {
125:                    return;
126:                }
127:                int ix = str.lastIndexOf(".class");
128:
129:                if (ix >= 0) {
130:                    String className = "com.ibm.icu"
131:                            + str.substring(0, ix).replace('/', '.');
132:
133:                    // Skip things in com.ibm.icu.dev; they're not relevant.
134:                    if (className.startsWith("com.ibm.icu.dev.")) {
135:                        return;
136:                    }
137:
138:                    try {
139:                        Class c = Class.forName(className);
140:                        int m = c.getModifiers();
141:
142:                        if (serializable.isAssignableFrom(c)) {
143:                            if (Modifier.isPublic(m)) {
144:                                SerializableTest.Handler handler = SerializableTest
145:                                        .getHandler(className);
146:
147:                                if (handler != null) {
148:                                    Object objectsOut[] = handler
149:                                            .getTestObjects();
150:                                    Object objectsIn[];
151:                                    boolean passed = true;
152:
153:                                    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
154:                                    ObjectOutputStream out = new ObjectOutputStream(
155:                                            byteOut);
156:
157:                                    try {
158:                                        out.writeObject(objectsOut);
159:                                        out.close();
160:                                        byteOut.close();
161:                                    } catch (IOException e) {
162:                                        warnln("Error writing test objects: "
163:                                                + e.toString());
164:                                        return;
165:                                    }
166:
167:                                    add(className, m, byteOut.toByteArray());
168:                                } else {
169:                                    add(className, m, null);
170:                                }
171:                            }
172:                        }
173:                    } catch (Exception e) {
174:                        warnln("coverage of " + className + ": " + e.toString());
175:                    } catch (Throwable e) {
176:                        warnln("coverage of " + className + ": " + e.toString());
177:                    }
178:                }
179:            }
180:
181:            protected Target getTargets(String targetName) {
182:
183:                if (System.getSecurityManager() != null) {
184:                    // This test won't run under a security manager
185:                    return new CoverageTarget(
186:                            "Skipped Due To Security Manager",
187:                            Modifier.ABSTRACT, null);
188:                }
189:
190:                if (serializable == null) {
191:                    init();
192:                }
193:                URL url = getClass().getResource("/com/ibm/icu");
194:                URLHandler handler = URLHandler.get(url);
195:
196:                handler.guide(this , true, false);
197:
198:                return head.getNext();
199:            }
200:
201:            public static void main(String[] args) {
202:                CoverageTest test = new CoverageTest();
203:
204:                test.run(args);
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.