Source Code Cross Referenced for ContentDescriberForTestsOnly.java in  » IDE-Eclipse » ui » org » eclipse » ui » tests » performance » 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 » ui » org.eclipse.ui.tests.performance 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2006 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.ui.tests.performance;
011:
012:        import java.io.IOException;
013:        import java.io.InputStream;
014:        import java.io.Reader;
015:
016:        import org.eclipse.core.runtime.QualifiedName;
017:        import org.eclipse.core.runtime.content.IContentDescriber;
018:        import org.eclipse.core.runtime.content.IContentDescription;
019:        import org.eclipse.core.runtime.content.ITextContentDescriber;
020:
021:        /**
022:         * This test ContentDescriber added specifically for OpenNavigatorFolderTest.
023:         * 
024:         */
025:
026:        public final class ContentDescriberForTestsOnly implements 
027:                ITextContentDescriber {
028:
029:            /*
030:             * this "simulated time" represents how long a content describer might
031:             * take parsing a file. Offhand (i.e. just guessing) 2000 msecs would be "bad case" examples. 
032:             * 20 msecs would be near a good, optimistic case.
033:             * I've picked 75 msecs for this test, to represent "normal" case 
034:             * (such as the HTML parser that gave rise to the original bug :)  
035:             * 
036:             * Note: unlike a "real" ContentDescriber, this one only effects "elapsed
037:             * time", not "CPU Time", since all it is doing is sleeping.
038:             */
039:            private static final int SIMULATED_CALCULATION_TIME = 75;
040:            private static final QualifiedName[] SUPPORTED_OPTIONS = {
041:                    IContentDescription.CHARSET,
042:                    IContentDescription.BYTE_ORDER_MARK };
043:
044:            public int describe(InputStream contents,
045:                    IContentDescription description) throws IOException {
046:                int result = IContentDescriber.INDETERMINATE;
047:
048:                if (description == null) {
049:                    result = computeValidity(contents);
050:                } else {
051:                    calculateSupportedOptions(contents, description);
052:                    // assummming we should return same 'validity' value we did
053:                    // when called before. (technically, could be a performance issue
054:                    // in future, so might want to check if any 'ol value would
055:                    // be ok here.
056:                    result = computeValidity(contents);
057:                }
058:
059:                return result;
060:            }
061:
062:            public int describe(Reader contents, IContentDescription description)
063:                    throws IOException {
064:                int result = IContentDescriber.INDETERMINATE;
065:
066:                if (description == null) {
067:                    result = computeValidity(contents);
068:                } else {
069:                    calculateSupportedOptions(contents, description);
070:                    // assummming we should return same 'validity' value we did
071:                    // when called before. (technically, could be a performance issue
072:                    // in future, so might want to check if hard coded 'valid' would
073:                    // be ok here.
074:                    result = computeValidity(contents);
075:                }
076:
077:                return result;
078:            }
079:
080:            public QualifiedName[] getSupportedOptions() {
081:
082:                return SUPPORTED_OPTIONS;
083:            }
084:
085:            private void calculateSupportedOptions(InputStream contents,
086:                    IContentDescription description) throws IOException {
087:                if (isRelevent(description)) {
088:                    makeBusy();
089:                }
090:            }
091:
092:            private void makeBusy() {
093:                // for this test "content type", we don't
094:                // really calculate anything. We just
095:                // just take a long time doing nothing.
096:                try {
097:                    Thread.sleep(SIMULATED_CALCULATION_TIME);
098:                } catch (InterruptedException e) {
099:                    // never expected
100:                    e.printStackTrace();
101:                }
102:            }
103:
104:            /**
105:             * @param contents
106:             * @param description
107:             * @throws IOException
108:             */
109:            private void calculateSupportedOptions(Reader contents,
110:                    IContentDescription description) throws IOException {
111:                if (isRelevent(description)) {
112:                    makeBusy();
113:                }
114:            }
115:
116:            private int computeValidity(InputStream inputStream) {
117:                // currently no contents specific check for valid HTML contents
118:                // (this may change once we add XHTML content type)
119:                return IContentDescriber.INDETERMINATE;
120:            }
121:
122:            private int computeValidity(Reader reader) {
123:                // no contents specific check for valid HTML contents
124:                // (this may change once we add XHTML content type)
125:                return IContentDescriber.INDETERMINATE;
126:            }
127:
128:            /**
129:             * @param description
130:             * @return
131:             */
132:            private boolean isRelevent(IContentDescription description) {
133:                boolean result = false;
134:                if (description == null)
135:                    result = false;
136:                else if (description
137:                        .isRequested(IContentDescription.BYTE_ORDER_MARK))
138:                    result = true;
139:                else if (description.isRequested(IContentDescription.CHARSET))
140:                    result = true;
141:                return result;
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.