Source Code Cross Referenced for MainClass.java in  » IDE-Eclipse » jdt » org » eclipse » debug » jdi » tests » program » 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 » IDE Eclipse » jdt » org.eclipse.debug.jdi.tests.program 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         * 
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.debug.jdi.tests.program;
011:
012:        import java.io.OutputStream;
013:        import java.io.PrintWriter;
014:        import java.util.Date;
015:
016:        import org.eclipse.debug.jdi.tests.ClassTypeTest;
017:
018:        /**
019:         * Main class for target VM tests.
020:         * This class is intended to be run by the target VM. 
021:         * It will use other classes in this package, and it will create and terminate
022:         * threads as a regular program would do.
023:         *
024:         * WARNING, WARNING:
025:         * Tests in org.eclipse.debug.jdi.tests assume the content of this class, 
026:         * as well as its behavior. So if this class or one of the types in this
027:         * package is changed, the corresponding tests must also be changed.
028:         */
029:        public class MainClass extends Date implements  Runnable, Printable {
030:
031:            private static byte[] byteArray = new byte[0];
032:            private static byte[][] byteDoubleArray = new byte[0][0];
033:            private static short[] shortArray = new short[0];
034:            private static short[][] shortDoubleArray = new short[0][0];
035:            private static int[] intArray = new int[0];
036:            private static int[][] intDoubleArray = new int[0][0];
037:            private static long[] longArray = new long[0];
038:            private static long[][] longDoubleArray = new long[0][0];
039:            private static double[] doubleArray = new double[0];
040:            private static double[][] doubleDoubleArray = new double[0][0];
041:            private static float[] floatArray = new float[0];
042:            private static float[][] floatDoubleArray = new float[0][0];
043:            private static char[] charArray = new char[0];
044:            private static char[][] charDoubleArray = new char[0][0];
045:            private static boolean[] booleanArray = new boolean[0];
046:            private static boolean[][] booleanDoubleArray = new boolean[0][0];
047:
048:            private String string = "";
049:            private String[] stringArray = new String[0];
050:            private String[][] stringDoubleArray = new String[0][0];
051:
052:            /**
053:             * An integer value
054:             */
055:            public static int fInt = 0;
056:
057:            /**
058:             * The instance of the <code>MainClass</code>
059:             */
060:            public static MainClass fObject = new MainClass();
061:
062:            /**
063:             * A string initialized to 'hello world'
064:             */
065:            public static String fString = "Hello World";
066:
067:            /**
068:             * A <code>Thread</code> object
069:             */
070:            public static Thread fThread;
071:
072:            /**
073:             * A <code>Thread</code> object representing the main thread
074:             */
075:            public static Thread fMainThread;
076:
077:            /**
078:             */
079:            public static String[] fArray = new String[] { "foo", "bar", "hop" };
080:
081:            /**
082:             * A pre-initialized array of doubles
083:             */
084:            public static double[] fDoubleArray = new double[] { 1, 2.2, 3.33 };
085:
086:            /**
087:             * The name of an event type
088:             */
089:            public static String fEventType = "";
090:
091:            /**
092:             * A boolean value initialized to <code>false</code>
093:             */
094:            public boolean fBool = false;
095:
096:            private char fChar = 'a';
097:
098:            private String fString2 = "Hello";
099:
100:            protected final String fString3 = "HEY";
101:
102:            /**
103:             * Constructor
104:             */
105:            public MainClass() {
106:            }
107:
108:            /**
109:             * Constructor
110:             * Used to test ClassType.newInstance
111:             * @see ClassTypeTest
112:             * @param i
113:             * @param o1
114:             * @param o2
115:             */
116:            public MainClass(int i, Object o1, Object o2) {
117:            }
118:
119:            /** 
120:             * For invocation tests
121:             * @param x the integer
122:             * @param o
123:             * @return a string object representing the specified interger value
124:             */
125:            private static String invoke1(int x, Object o) {
126:                if (o == null)
127:                    return (new Integer(x)).toString();
128:                else
129:                    return "";
130:            }
131:
132:            /** 
133:             * For invocation tests
134:             */
135:            private static void invoke2() {
136:                throw new IndexOutOfBoundsException();
137:            }
138:
139:            /**
140:             * For invocation tests
141:             * @param str
142:             * @param o
143:             * @return an the integer value of the specified string
144:             */
145:            private int invoke3(String str, Object o) {
146:                return Integer.parseInt(str);
147:            }
148:
149:            /**
150:             * For invocation tests
151:             * @return nothing, only throws an exception
152:             * @throws java.io.EOFException
153:             */
154:            private long invoke4() throws java.io.EOFException {
155:                throw new java.io.EOFException();
156:            }
157:
158:            /**
159:             * For variables test
160:             * @param l
161:             */
162:            private void variablesTest(long l) {
163:            }
164:
165:            /**
166:             * Runs the test program 
167:             * @param args
168:             */
169:            public static void main(java.lang.String[] args) {
170:                // Start the test program
171:                ThreadGroup group = new ThreadGroup("Test ThreadGroup");
172:                fThread = new Thread(group, fObject, "Test Thread");
173:                fThread.start();
174:
175:                fMainThread = Thread.currentThread();
176:
177:                // Prevent this thread from dying
178:                while (true)
179:                    try {
180:                        Thread.sleep(1000);
181:                    } catch (InterruptedException e) {
182:                    }
183:            }
184:
185:            /**
186:             * @see org.eclipse.debug.jdi.tests.program.Printable#print(java.io.OutputStream)
187:             */
188:            public void print(OutputStream out) {
189:                String string = fInt++ + ". " + fString;
190:                PrintWriter writer = new PrintWriter(out);
191:                writer.println(string);
192:                writer.flush();
193:            }
194:
195:            /**
196:             * Prints out a specified integer. This method is used in the force early return tests to ensure we
197:             * can specify a different, type compatible return value
198:             * @param out a stream to print out to
199:             * @param num the number we want to print and return
200:             * @return the specified number parameter, just pass it through
201:             * @since 3.3
202:             */
203:            public int printNumber(OutputStream out, int num) {
204:                String blah = "foo" + foo();
205:                PrintWriter writer = new PrintWriter(out);
206:                writer.println("The specified number is: " + num);
207:                writer.flush();
208:                return num;
209:            }
210:
211:            /**
212:             * Returns 20
213:             * 
214:             * @return 20
215:             */
216:            public int getInt() {
217:                int x = Math.max(20, 10);
218:                return x;
219:            }
220:
221:            /**
222:             * Returns true.
223:             * 
224:             * @return true
225:             */
226:            public boolean getBoolean() {
227:                boolean bool = Boolean.valueOf("true").booleanValue();
228:                return bool;
229:            }
230:
231:            /**
232:             * Returns 123L.
233:             * 
234:             * @return 123
235:             */
236:            public long getLong() {
237:                long l = Long.valueOf("123").longValue();
238:                return l;
239:            }
240:
241:            /**
242:             * dump out a string
243:             * @return a String
244:             * @since 3.3
245:             */
246:            public String foo() {
247:                System.out.println("foobar");
248:                return "man";
249:            }
250:
251:            /**
252:             * make a sync'd method so we can stop in it to gather monitor information
253:             * @since 3.3
254:             */
255:            synchronized public void sync() {
256:                System.out.println("sync'd to the moon");
257:            }
258:
259:            /**
260:             * suspend on the first line of the method to get the argument values from the stackframe.
261:             * used in testing the new 1.6VM capability to get argument values when no debugging info is available.
262:             * @param str a string
263:             * @param num a number
264:             * @param obj an object
265:             * @since 3.3
266:             */
267:            public void argValues(String str, int num, Object obj) {
268:                System.out.println("get the arg values");
269:            }
270:
271:            /**
272:             * Prints to System.out and throws an exception to indicate readiness
273:             */
274:            synchronized public void printAndSignal() {
275:                print(System.out);
276:                // Signal readiness by throwing an exception
277:                try {
278:                    throw new NegativeArraySizeException();
279:                } catch (NegativeArraySizeException exc) {
280:                }
281:            }
282:
283:            /**
284:             * @see java.lang.Runnable#run()
285:             */
286:            public void run() {
287:                try {
288:                    Thread t = Thread.currentThread();
289:                    MainClass o = new OtherClass();
290:                    // The front-end tests use the class load event to determine that the program has started
291:
292:                    if (CONSTANT == 2)
293:                        System.out.println("CONSTANT=2");
294:
295:                    while (true) {
296:                        printAndSignal();
297:                        triggerEvent();
298:                        useLocalVars(t, o);
299:                        try {
300:                            Thread.sleep(1000);
301:                        } catch (InterruptedException e) {
302:                        }
303:                    }
304:                } finally {
305:                    System.out
306:                            .println("Running finally block in MainClass.run()");
307:                }
308:            }
309:
310:            /**
311:             *	Trigger an access watchpoint event for the front-end.
312:             */
313:            private void triggerAccessWatchpointEvent() {
314:                if (fBool)
315:                    System.out.println("fBool is true");
316:            }
317:
318:            /**
319:             *	Trigger a breakpoint event for the front-end.
320:             */
321:            private void triggerBreakpointEvent() {
322:                System.out.println("Breakpoint");
323:            }
324:
325:            /**
326:             *	Trigger a class prepare event for the front-end.
327:             */
328:            private void triggerClassPrepareEvent() {
329:                new TestClass();
330:            }
331:
332:            /**
333:             *	Trigger a class prepare event for the front-end.
334:             */
335:            private void triggerClassPrepareEvent1() {
336:                new TestClass1();
337:            }
338:
339:            /**
340:             *	Trigger a class prepare event for the front-end.
341:             */
342:            private void triggerClassPrepareEvent2() {
343:                new TestClass2();
344:            }
345:
346:            /**
347:             *	Trigger a class prepare event for the front-end.
348:             */
349:            private void triggerClassPrepareEvent3() {
350:                new TestClass3();
351:            }
352:
353:            /**
354:             *	Trigger a class prepare event for the front-end.
355:             */
356:            private void triggerClassPrepareEvent4() {
357:                new TestClass4();
358:            }
359:
360:            /**
361:             *	Trigger a class prepare event for the front-end.
362:             */
363:            private void triggerClassPrepareEvent5() {
364:                new TestClass5();
365:            }
366:
367:            /**
368:             *	Trigger a class prepare event for the front-end.
369:             */
370:            private void triggerClassPrepareEvent6() {
371:                new TestClass6();
372:            }
373:
374:            /**
375:             *	Trigger a class prepare event for the front-end.
376:             */
377:            private void triggerClassPrepareEvent7() {
378:                new TestClass7();
379:                new TestClazz8();
380:            }
381:
382:            /**
383:             *	Trigger a class prepare event for the front-end.
384:             */
385:            private void triggerClassPrepareEvent8() {
386:                new TestClazz9();
387:                new TestClazz10();
388:            }
389:
390:            /**
391:             *	Trigger an event for the front-end.
392:             */
393:            private void triggerEvent() {
394:                /* Ensure we do it only once */
395:                String eventType = fEventType;
396:                fEventType = "";
397:
398:                /* Trigger event according to the field fEventType */
399:                if (eventType.equals(""))
400:                    return;
401:                else if (eventType.equals("refclassload")) {
402:                    new RefClass();
403:                } else if (eventType.equals("fooreturn")) {
404:                    foo();
405:                } else if (eventType.equals("argvalues")) {
406:                    argValues("teststr", 5, new Double(1.33));
407:                } else if (eventType.equals("forcereturn2")) {
408:                    printNumber(System.out, 1);
409:                } else if (eventType.equals("forcereturn")) {
410:                    print(System.out);
411:                } else if (eventType.equals("monitorinfo")) {
412:                    sync();
413:                } else if (eventType.equals("refclass1load")) {
414:                    new RefClass1();
415:                } else if (eventType.equals("refclass2load")) {
416:                    new RefClass2();
417:                } else if (eventType.equals("refclass3load")) {
418:                    new RefClass3();
419:                } else if (eventType.equals("refclass4load")) {
420:                    new RefClass4();
421:                } else if (eventType.equals("getInt")) {
422:                    getInt();
423:                } else if (eventType.equals("getBoolean")) {
424:                    getBoolean();
425:                } else if (eventType.equals("getLong")) {
426:                    getLong();
427:                } else if (eventType.equals("AccessWatchpointEvent"))
428:                    triggerAccessWatchpointEvent();
429:                else if (eventType.equals("StaticAccessWatchpointEvent"))
430:                    triggerStaticAccessWatchpointEvent();
431:                else if (eventType.equals("BreakpointEvent"))
432:                    triggerBreakpointEvent();
433:                else if (eventType.equals("ClassPrepareEvent"))
434:                    triggerClassPrepareEvent();
435:                else if (eventType.equals("ClassPrepareEvent1"))
436:                    triggerClassPrepareEvent1();
437:                else if (eventType.equals("ClassPrepareEvent2"))
438:                    triggerClassPrepareEvent2();
439:                else if (eventType.equals("ClassPrepareEvent3"))
440:                    triggerClassPrepareEvent3();
441:                else if (eventType.equals("ClassPrepareEvent4"))
442:                    triggerClassPrepareEvent4();
443:                else if (eventType.equals("ClassPrepareEvent5"))
444:                    triggerClassPrepareEvent5();
445:                else if (eventType.equals("ClassPrepareEvent6"))
446:                    triggerClassPrepareEvent6();
447:                else if (eventType.equals("ClassPrepareEvent7"))
448:                    triggerClassPrepareEvent7();
449:                else if (eventType.equals("ClassPrepareEvent8"))
450:                    triggerClassPrepareEvent8();
451:                else if (eventType.equals("ExceptionEvent"))
452:                    triggerExceptionEvent();
453:                else if (eventType.equals("ModificationWatchpointEvent"))
454:                    triggerModificationWatchpointEvent();
455:                else if (eventType.equals("StaticModificationWatchpointEvent"))
456:                    triggerStaticModificationWatchpointEvent();
457:                else if (eventType.equals("ThreadStartEvent"))
458:                    triggerThreadStartEvent();
459:                else if (eventType.equals("ThreadDeathEvent"))
460:                    triggerThreadDeathEvent();
461:                else
462:                    System.out.println("Unknown event type: " + eventType);
463:            }
464:
465:            /**
466:             *	Trigger an exception event for the front-end.
467:             */
468:            private void triggerExceptionEvent() {
469:                Thread t = new Thread(new Runnable() {
470:                    public void run() {
471:                        throw new Error();
472:                    }
473:                }, "Test Exception Event");
474:                t.start();
475:            }
476:
477:            /**
478:             *	Trigger a modification watchpoint event for the front-end.
479:             */
480:            private void triggerModificationWatchpointEvent() {
481:                fBool = true;
482:            }
483:
484:            /**
485:             * Trigger an access watchpoint event to a static field
486:             * for the front-end.
487:             */
488:            private void triggerStaticAccessWatchpointEvent() {
489:                if (fObject == null)
490:                    System.out.println("fObject is null");
491:            }
492:
493:            /**
494:             * Trigger a modification watchpoint event of a static field
495:             * for the front-end.
496:             */
497:            private void triggerStaticModificationWatchpointEvent() {
498:                fString = "Hello Universe";
499:            }
500:
501:            /**
502:             *	Trigger a thread end event for the front-end.
503:             */
504:            private void triggerThreadDeathEvent() {
505:                new Thread("Test Thread Death Event").start();
506:            }
507:
508:            /**
509:             *	Trigger a thread start event for the front-end.
510:             */
511:            private void triggerThreadStartEvent() {
512:                new Thread("Test Thread Start Event").start();
513:            }
514:
515:            private void useLocalVars(Thread t, MainClass o) {
516:                if (t == null)
517:                    System.out.println("t is null");
518:                if (o == null)
519:                    System.out.println("o is null");
520:
521:            }
522:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.