Mercurial > repos > ganjoo > webservice_toolsuite
comparison WebServiceToolWorkflow/lib/SAWADLParser/src/javax/wadls/factory/WADLFactory.java @ 0:d5cd409b8a18 default tip
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author | ganjoo |
---|---|
date | Tue, 07 Jun 2011 18:00:50 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d5cd409b8a18 |
---|---|
1 /* | |
2 * (c) Copyright IBM Corp 2001, 2005 | |
3 */ | |
4 | |
5 package javax.wadls.factory; | |
6 | |
7 import java.io.*; | |
8 import java.util.*; | |
9 | |
10 import javax.wadls.*; | |
11 import javax.wadls.xml.*; | |
12 | |
13 /** | |
14 * This abstract class defines a factory API that enables applications | |
15 * to obtain a WSDLFactory capable of producing new Definitions, new | |
16 * WSDLReaders, and new WSDLWriters. | |
17 * | |
18 * Some ideas used here have been shamelessly copied from the | |
19 * wonderful JAXP and Xerces work. | |
20 * | |
21 * @author Matthew J. Duftler (duftler@us.ibm.com) | |
22 */ | |
23 public abstract class WADLFactory | |
24 { | |
25 private static final String PROPERTY_NAME = | |
26 "javax.wadls.factory.WADLFactory"; | |
27 private static final String PROPERTY_FILE_NAME = | |
28 "wadl.properties"; | |
29 private static final String DEFAULT_FACTORY_IMPL_NAME = | |
30 "edu.uga.cs.lsdis.meteors.wadls.factory.WADLFactoryImpl"; | |
31 | |
32 private static String fullPropertyFileName = null; | |
33 | |
34 /** | |
35 * Get a new instance of a WSDLFactory. This method | |
36 * follows (almost) the same basic sequence of steps that JAXP | |
37 * follows to determine the fully-qualified class name of the | |
38 * class which implements WSDLFactory. The steps (in order) | |
39 * are: | |
40 *<pre> | |
41 * Check the javax.wsdls.factory.WSDLFactory system property. | |
42 * Check the lib/wsdl.properties file in the JRE directory. The key | |
43 * will have the same name as the above system property. | |
44 * Use the default value. | |
45 *</pre> | |
46 * Once an instance of a WSDLFactory is obtained, invoke | |
47 * newDefinition(), newWSDLReader(), or newWSDLWriter(), to create | |
48 * the desired instances. | |
49 */ | |
50 public static WADLFactory newInstance() throws WADLSException | |
51 { | |
52 String factoryImplName = findFactoryImplName(); | |
53 | |
54 return newInstance(factoryImplName); | |
55 } | |
56 | |
57 /** | |
58 * Get a new instance of a WSDLFactory. This method | |
59 * returns an instance of the class factoryImplName. | |
60 * Once an instance of a WSDLFactory is obtained, invoke | |
61 * newDefinition(), newWSDLReader(), or newWSDLWriter(), to create | |
62 * the desired instances. | |
63 * | |
64 * @param factoryImplName the fully-qualified class name of the | |
65 * class which provides a concrete implementation of the abstract | |
66 * class WSDLFactory. | |
67 */ | |
68 public static WADLFactory newInstance(String factoryImplName) | |
69 throws WADLSException | |
70 { | |
71 if (factoryImplName != null) | |
72 { | |
73 try | |
74 { | |
75 Class cl = Class.forName(factoryImplName); | |
76 | |
77 return (WADLFactory)cl.newInstance(); | |
78 } | |
79 catch (Exception e) | |
80 { | |
81 /* | |
82 Catches: | |
83 ClassNotFoundException | |
84 InstantiationException | |
85 IllegalAccessException | |
86 */ | |
87 throw new WADLSException(WADLSException.CONFIGURATION_ERROR, | |
88 "Problem instantiating factory " + | |
89 "implementation.", | |
90 e); | |
91 } | |
92 } | |
93 else | |
94 { | |
95 throw new WADLSException(WADLSException.CONFIGURATION_ERROR, | |
96 "Unable to find name of factory " + | |
97 "implementation."); | |
98 } | |
99 } | |
100 | |
101 /** | |
102 * Create a new instance of a Definition. | |
103 */ | |
104 public abstract Application newApplication(); | |
105 | |
106 /** | |
107 * Create a new instance of a WSDLReader. | |
108 */ | |
109 public abstract WADLReader newWADLReader(); | |
110 | |
111 /** | |
112 * Create a new instance of a WSDLWriter. | |
113 */ | |
114 public abstract WADLWriter newWADLWriter(); | |
115 | |
116 | |
117 private static String findFactoryImplName() | |
118 { | |
119 String factoryImplName = null; | |
120 | |
121 // First, check the system property. | |
122 try | |
123 { | |
124 factoryImplName = System.getProperty(PROPERTY_NAME); | |
125 | |
126 if (factoryImplName != null) | |
127 { | |
128 return factoryImplName; | |
129 } | |
130 } | |
131 catch (SecurityException e) | |
132 { | |
133 } | |
134 | |
135 // Second, check the properties file. | |
136 String propFileName = getFullPropertyFileName(); | |
137 | |
138 if (propFileName != null) | |
139 { | |
140 try | |
141 { | |
142 Properties properties = new Properties(); | |
143 File propFile = new File(propFileName); | |
144 FileInputStream fis = new FileInputStream(propFile); | |
145 | |
146 properties.load(fis); | |
147 fis.close(); | |
148 | |
149 factoryImplName = properties.getProperty(PROPERTY_NAME); | |
150 | |
151 if (factoryImplName != null) | |
152 { | |
153 return factoryImplName; | |
154 } | |
155 } | |
156 catch (IOException e) | |
157 { | |
158 } | |
159 } | |
160 | |
161 // Third, return the default. | |
162 return DEFAULT_FACTORY_IMPL_NAME; | |
163 } | |
164 | |
165 private static String getFullPropertyFileName() | |
166 { | |
167 if (fullPropertyFileName == null) | |
168 { | |
169 try | |
170 { | |
171 String javaHome = System.getProperty("java.home"); | |
172 | |
173 fullPropertyFileName = javaHome + File.separator + "lib" + | |
174 File.separator + PROPERTY_FILE_NAME; | |
175 } | |
176 catch (SecurityException e) | |
177 { | |
178 } | |
179 } | |
180 | |
181 return fullPropertyFileName; | |
182 } | |
183 } |