Source Code Cross Referenced for WSDLHandlerFactory.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » ws » handler » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.ws.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial Developer : Sauthier Guillaume
022:         * --------------------------------------------------------------------------
023:         * $Id: WSDLHandlerFactory.java 5188 2004-07-27 14:21:30Z sauthieg $
024:         * --------------------------------------------------------------------------
025:         */package org.objectweb.jonas.ws.handler;
026:
027:        import java.util.Properties;
028:
029:        import java.lang.reflect.Constructor;
030:
031:        import java.io.InputStream;
032:        import java.io.IOException;
033:        import java.io.File;
034:        import java.io.FileInputStream;
035:
036:        import org.objectweb.jonas.ws.WSServiceException;
037:
038:        import org.objectweb.util.monolog.api.BasicLevel;
039:        import org.objectweb.util.monolog.api.Logger;
040:
041:        import org.objectweb.jonas.common.JProp;
042:        import org.objectweb.jonas.common.Log;
043:        import org.objectweb.jonas_lib.I18n;
044:
045:        /**
046:         * WSDLHandlerFactory is used to dynamically instantiate a WSDLHandler
047:         * from a Property file.<br/>
048:         * Minimum properties in file : <br/>
049:         * - <code>jonas.service.wsdl.class</code> : Fully qualified classname to be instanciated
050:         *
051:         * @author Guillaume Sauthier
052:         */
053:        public class WSDLHandlerFactory {
054:
055:            /** Classname property */
056:            public static final String CLASSNAME = "jonas.service.wsdl.class";
057:
058:            /**
059:             * Logger
060:             */
061:            private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX);
062:
063:            /**
064:             * I18n
065:             */
066:            private static I18n i18n = I18n
067:                    .getInstance(WSDLHandlerFactory.class);
068:
069:            /**
070:             * Construct a new WSDLHandlerFactory
071:             */
072:            private WSDLHandlerFactory() {
073:            }
074:
075:            /**
076:             * @return Returns a new WSDLHandlerFactory instance.
077:             */
078:            public static WSDLHandlerFactory newInstance() {
079:                return new WSDLHandlerFactory();
080:            }
081:
082:            /**
083:             * Create a new WSDLHandler.
084:             *
085:             * @param filename properties filename to be loaded
086:             *
087:             * @return a WSDLHandler init from properties
088:             *
089:             * @throws WSServiceException when filename is null or cannot be
090:             *         loaded (as ClassLoader Resource or as System file)
091:             */
092:            public WSDLHandler newHandler(String filename)
093:                    throws WSServiceException {
094:
095:                Properties props = loadProperties(filename + ".properties");
096:
097:                String classname = props.getProperty(CLASSNAME);
098:
099:                if (classname == null) {
100:                    // i18n WSDLHandlerFactory.newHandler.noClassname
101:                    String err = i18n.getMessage(
102:                            "WSDLHandlerFactory.newHandler.noClassname",
103:                            filename + ".properties");
104:                    logger.log(BasicLevel.ERROR, err);
105:                    throw new WSServiceException(err);
106:                }
107:
108:                Object[] pvalues = new Object[] { props };
109:                Class[] types = new Class[] { Properties.class };
110:
111:                // Instanciation
112:                WSDLHandler handler = null;
113:                try {
114:                    Class handlerClazz = Class.forName(classname);
115:                    Constructor handlerConstr = handlerClazz
116:                            .getConstructor(types);
117:                    handler = (WSDLHandler) handlerConstr.newInstance(pvalues);
118:                } catch (Exception e) {
119:                    // i18n WSDLHandlerFactory.newHandler.instantiationFailure
120:                    String err = i18n
121:                            .getMessage(
122:                                    "WSDLHandlerFactory.newHandler.instantiationFailure",
123:                                    filename, classname);
124:                    logger.log(BasicLevel.ERROR, err);
125:                    throw new WSServiceException(err, e);
126:                }
127:
128:                return handler;
129:            }
130:
131:            /**
132:             * Load Properties from a properties file.
133:             * Try to load the file first as a ClassLoader resource and
134:             * as a File if not found in ClassLoader.
135:             *
136:             * @param filename filename to be loaded
137:             *
138:             * @return the Properties object loaded from filename
139:             *
140:             * @throws WSServiceException if properties cannot be loaded.
141:             */
142:            private Properties loadProperties(String filename)
143:                    throws WSServiceException {
144:
145:                Properties props = new Properties();
146:
147:                InputStream is = getFromClassLoader(filename);
148:
149:                if (is == null) {
150:                    // load from ${jonas.base}/conf
151:                    is = getFromFile(JProp.getJonasBase() + File.separator
152:                            + "conf" + File.separator + filename);
153:                }
154:
155:                if (is != null) {
156:                    try {
157:                        props.load(is);
158:                    } catch (IOException ioe) {
159:                        // !!! i18n WSDLHandlerFactory.loadProperties.ioe
160:                        String err = i18n.getMessage(
161:                                "WSDLHandlerFactory.loadProperties.ioe",
162:                                filename);
163:                        logger.log(BasicLevel.ERROR, err);
164:                        throw new WSServiceException(err);
165:                    }
166:                } else {
167:                    // !!! i18n WSDLHandlerFactory.loadProperties.notFound
168:                    String err = i18n.getMessage(
169:                            "WSDLHandlerFactory.loadProperties.notFound",
170:                            filename);
171:                    logger.log(BasicLevel.ERROR, err);
172:                    throw new WSServiceException(err);
173:                }
174:
175:                return props;
176:            }
177:
178:            /**
179:             * Get the file as ClassLoader Resource (can be null if not found).
180:             *
181:             * @param filename the filename searched in the ClassLoader
182:             *
183:             * @return an InputStream from the ClassLoader
184:             */
185:            private InputStream getFromClassLoader(String filename) {
186:
187:                String clProps = filename;
188:
189:                // if filename do not start with a "/" prepend it.
190:                // otherwise, getResourceAsStream will attemps to load it
191:                // from directory of the current package.
192:                if (!clProps.startsWith("/")) {
193:                    clProps = "/" + clProps;
194:                }
195:
196:                return getClass().getResourceAsStream(clProps);
197:            }
198:
199:            /**
200:             * Get the file as File (can be null if not found).
201:             *
202:             * @param filename the filename searched in the System files.
203:             *
204:             * @return an InputStream from the File
205:             */
206:            private InputStream getFromFile(String filename) {
207:
208:                InputStream is = null;
209:
210:                // Create a file
211:                File file = new File(filename);
212:                try {
213:                    is = new FileInputStream(file);
214:                } catch (IOException ioe) {
215:                    logger.log(BasicLevel.WARN, "Cannot load " + filename
216:                            + " from file system.");
217:                    is = null;
218:                }
219:
220:                return is;
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.