Source Code Cross Referenced for ServiceProxy.java in  » 6.0-JDK-Modules-sun » javac-compiler » com » sun » tools » javac » processing » 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 » 6.0 JDK Modules sun » javac compiler » com.sun.tools.javac.processing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.tools.javac.processing;
027:
028:        import java.io.BufferedReader;
029:        import java.io.FileNotFoundException;
030:        import java.io.IOException;
031:        import java.io.InputStream;
032:        import java.io.InputStreamReader;
033:        import java.net.MalformedURLException;
034:        import java.net.URL;
035:        import java.util.ArrayList;
036:        import java.util.Iterator;
037:        import java.util.List;
038:        import java.util.Set;
039:
040:        /**
041:         * Utility class to determine if a service can be found on the
042:         * path that might be used to create a class loader.
043:         *
044:         * <p><b>This is NOT part of any API supported by Sun Microsystems.
045:         * If you write code that depends on this, you do so at your own risk.
046:         * This code and its internal interfaces are subject to change or
047:         * deletion without notice.</b>
048:         *
049:         */
050:        // based on sun.misc.Service
051:        class ServiceProxy {
052:            static class ServiceConfigurationError extends Error {
053:                static final long serialVersionUID = 7732091036771098303L;
054:
055:                ServiceConfigurationError(String msg) {
056:                    super (msg);
057:                }
058:            }
059:
060:            private static final String prefix = "META-INF/services/";
061:
062:            private static void fail(Class service, String msg)
063:                    throws ServiceConfigurationError {
064:                throw new ServiceConfigurationError(service.getName() + ": "
065:                        + msg);
066:            }
067:
068:            private static void fail(Class service, URL u, int line, String msg)
069:                    throws ServiceConfigurationError {
070:                fail(service, u + ":" + line + ": " + msg);
071:            }
072:
073:            /**
074:             * Parse the content of the given URL as a provider-configuration file.
075:             *
076:             * @param  service
077:             *         The service class for which providers are being sought;
078:             *         used to construct error detail strings
079:             *
080:             * @param  url
081:             *         The URL naming the configuration file to be parsed
082:             *
083:             * @return true if the name of a service is found
084:             *
085:             * @throws ServiceConfigurationError
086:             *         If an I/O error occurs while reading from the given URL, or
087:             *         if a configuration-file format error is detected
088:             */
089:            private static boolean parse(Class service, URL u)
090:                    throws ServiceConfigurationError {
091:                InputStream in = null;
092:                BufferedReader r = null;
093:                try {
094:                    in = u.openStream();
095:                    r = new BufferedReader(new InputStreamReader(in, "utf-8"));
096:                    int lc = 1;
097:                    String ln;
098:                    while ((ln = r.readLine()) != null) {
099:                        int ci = ln.indexOf('#');
100:                        if (ci >= 0)
101:                            ln = ln.substring(0, ci);
102:                        ln = ln.trim();
103:                        int n = ln.length();
104:                        if (n != 0) {
105:                            if ((ln.indexOf(' ') >= 0)
106:                                    || (ln.indexOf('\t') >= 0))
107:                                fail(service, u, lc,
108:                                        "Illegal configuration-file syntax");
109:                            int cp = ln.codePointAt(0);
110:                            if (!Character.isJavaIdentifierStart(cp))
111:                                fail(service, u, lc,
112:                                        "Illegal provider-class name: " + ln);
113:                            for (int i = Character.charCount(cp); i < n; i += Character
114:                                    .charCount(cp)) {
115:                                cp = ln.codePointAt(i);
116:                                if (!Character.isJavaIdentifierPart(cp)
117:                                        && (cp != '.'))
118:                                    fail(service, u, lc,
119:                                            "Illegal provider-class name: "
120:                                                    + ln);
121:                            }
122:                            return true;
123:                        }
124:                    }
125:                } catch (FileNotFoundException x) {
126:                    return false;
127:                } catch (IOException x) {
128:                    fail(service, ": " + x);
129:                } finally {
130:                    try {
131:                        if (r != null)
132:                            r.close();
133:                    } catch (IOException y) {
134:                        fail(service, ": " + y);
135:                    }
136:                    try {
137:                        if (in != null)
138:                            in.close();
139:                    } catch (IOException y) {
140:                        fail(service, ": " + y);
141:                    }
142:                }
143:                return false;
144:            }
145:
146:            /**
147:             * Return true if a description for at least one service is found in the
148:             * service configuration files in the given URLs.
149:             */
150:            public static boolean hasService(Class<?> service, URL[] urls)
151:                    throws ServiceConfigurationError {
152:                for (URL url : urls) {
153:                    try {
154:                        String fullName = prefix + service.getName();
155:                        URL u = new URL(url, fullName);
156:                        boolean found = parse(service, u);
157:                        if (found)
158:                            return true;
159:                    } catch (MalformedURLException e) {
160:                        // should not happen; ignore it if it does
161:                    }
162:                }
163:                return false;
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.