You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ow...@apache.org on 2002/11/19 18:49:58 UTC
cvs commit: xml-axis-wsif/java/src/org/apache/wsif/util WSIFPluggableProviders.java
owenb 2002/11/19 09:49:58
Modified: java/src/org/apache/wsif/util Tag: pre1_2_0-patches
WSIFPluggableProviders.java
Log:
Fix - if the same provider class name is found multiple times, only add the provider once.
Trace - added extra event, entry, exit tracing and corrected the tracing of an ignored exception
Revision Changes Path
No revision
No revision
1.5.2.1 +156 -139 xml-axis-wsif/java/src/org/apache/wsif/util/WSIFPluggableProviders.java
Index: WSIFPluggableProviders.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/WSIFPluggableProviders.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- WSIFPluggableProviders.java 18 Sep 2002 15:38:19 -0000 1.5
+++ WSIFPluggableProviders.java 19 Nov 2002 17:49:58 -0000 1.5.2.1
@@ -107,23 +107,23 @@
* @author Ant Elder <an...@apache.org>
*/
public class WSIFPluggableProviders {
-
- // defines if providers will be loaded automatically
- private static boolean autoLoadProviders = true;
+
+ // defines if providers will be loaded automatically
+ private static boolean autoLoadProviders = true;
// all the providers found in all the SPI files from
// all the jar files in the classpath, in the order
// they were found with the 1st in the ArrayList
// being higher in the classpath.
private static ArrayList providersFromSPIFiles;
-
+
// a mapping of providers chosen to be supporting
// a binding namespace. The mapping key is the
// namespace URI, the value is the provider
private static HashMap defaultNSProviders;
- private static final String PLUGABLE_PROVIDER_FILENAME =
- "META-INF/services/org.apache.wsif.spi.WSIFProvider";
+ private static final String PLUGABLE_PROVIDER_FILENAME =
+ "META-INF/services/org.apache.wsif.spi.WSIFProvider";
/**
* Gets a WSIFProvider for a particular bindng namespace URI.
@@ -154,7 +154,7 @@
return null;
}
if (providers.size() == 1) {
- provider = (WSIFProvider)providers.get(0);
+ provider = (WSIFProvider) providers.get(0);
} else {
provider = chooseProvider(providers, namespaceURI);
}
@@ -187,9 +187,10 @@
}
if (provider == null) {
- WSIFProvider p = (WSIFProvider) defaultNSProviders.get(providerNamespaceURI);
- if ( defaultNSProviders != null ) {
- defaultNSProviders.remove(providerNamespaceURI);
+ WSIFProvider p =
+ (WSIFProvider) defaultNSProviders.get(providerNamespaceURI);
+ if (defaultNSProviders != null) {
+ defaultNSProviders.remove(providerNamespaceURI);
}
} else {
defaultNSProviders.put(providerNamespaceURI, provider);
@@ -206,9 +207,9 @@
* binding namespace, otherwise false.
*/
public static boolean isProviderAvailable(String ns1) {
- return isProviderAvailable( ns1, ns1 );
+ return isProviderAvailable(ns1, ns1);
}
-
+
/**
* Tests if a provider is available for the given namespaces.
* @param ns1 the WSDL binding namespace URI
@@ -217,22 +218,22 @@
* namespaces, otherwise false.
*/
public static boolean isProviderAvailable(String ns1, String ns2) {
- boolean supported = false;
- ArrayList ps = getSupportingProviders( ns1, false );
- if ( ps.size() > 0 ) {
- if ( ns2 == null || ns2.length() < 1 || ns2.equals( ns1 ) ) {
- supported = true;
- } else {
- String[] supportedNS;
- for (int i=0; i<ps.size() && !supported; i++) {
+ boolean supported = false;
+ ArrayList ps = getSupportingProviders(ns1, false);
+ if (ps.size() > 0) {
+ if (ns2 == null || ns2.length() < 1 || ns2.equals(ns1)) {
+ supported = true;
+ } else {
+ String[] supportedNS;
+ for (int i = 0; i < ps.size() && !supported; i++) {
supportedNS = ((WSIFProvider)ps.get(i)).getAddressNamespaceURIs();
for (int j=0; j<supportedNS.length && !supported; j++) {
- if ( ns2.equals( supportedNS[j] )) {
- supported = true;
+ if (ns2.equals(supportedNS[j])) {
+ supported = true;
+ }
}
- }
- }
- }
+ }
+ }
}
return supported;
}
@@ -249,10 +250,10 @@
*/
public static void setAutoLoadProviders(boolean b) {
Trc.entry(null, b);
- if ( autoLoadProviders != b ) {
- providersFromSPIFiles = null;
- defaultNSProviders = null;
- autoLoadProviders = b;
+ if (autoLoadProviders != b) {
+ providersFromSPIFiles = null;
+ defaultNSProviders = null;
+ autoLoadProviders = b;
}
Trc.exit();
}
@@ -280,31 +281,43 @@
private static ArrayList getSupportingProviders(
String namespaceURI,
boolean issueMessage) {
+
+ Trc.entry(null, namespaceURI, new Boolean(issueMessage));
if (providersFromSPIFiles == null) {
providersFromSPIFiles = getAllDynamicWSIFProviders();
}
ArrayList supportingProviders = new ArrayList();
String[] uris;
WSIFProvider p;
- for (Iterator i = providersFromSPIFiles.iterator(); i.hasNext(); ) {
- p = (WSIFProvider) i.next();
+ for (Iterator i = providersFromSPIFiles.iterator(); i.hasNext();) {
+ p = (WSIFProvider) i.next();
uris = p.getBindingNamespaceURIs();
for (int j = 0; j < uris.length; j++) {
- if (namespaceURI != null && namespaceURI.equals(uris[j])) {
- supportingProviders.add( p );
+ if (namespaceURI != null && namespaceURI.equals(uris[j])) {
+ Trc.event(
+ null,
+ "Adding provider " + p + " for namespace " + uris[j]);
+ supportingProviders.add(p);
}
}
}
if (defaultNSProviders != null) {
if (defaultNSProviders.get(namespaceURI) != null) {
+ Trc.event(
+ null,
+ "Adding default provider "
+ + defaultNSProviders.get(namespaceURI)
+ + " for namespace "
+ + namespaceURI);
supportingProviders.add(defaultNSProviders.get(namespaceURI));
}
- }
+ }
if (supportingProviders.size() > 1 && issueMessage) {
issueMultipleProvidersMsg(namespaceURI, supportingProviders);
}
-
+
+ Trc.exit(supportingProviders);
return supportingProviders;
}
@@ -315,111 +328,111 @@
* @return an array of WSIFProvider.
*/
private static ArrayList getAllDynamicWSIFProviders() {
- if (!autoLoadProviders) {
- return new ArrayList();
- }
-
- ArrayList al = (ArrayList) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ Trc.entry(null);
+ if (!autoLoadProviders) {
+ return new ArrayList();
+ }
+
+ ArrayList al =
+ (ArrayList) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
return findPlugableProviders();
- }
- } );
-
- return al;
+ }
+ });
+ Trc.exit(al);
+ return al;
}
private static ArrayList findPlugableProviders() {
- Object o;
- ArrayList classNames = new ArrayList();
- ArrayList providers = new ArrayList();
-
- // find all the class names mentioned in all the META-INF files
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try {
- for(Enumeration e = loader.getResources( PLUGABLE_PROVIDER_FILENAME ); e.hasMoreElements(); ) {
- classNames.addAll( readMETAINFClassNames( (URL) e.nextElement() ) );
- }
- } catch (Exception ex) {
- Trc.exception( ex );
- MessageLogger.log(
- "WSIF.0003W",
- ex.getMessage() );
- return providers;
- }
-
- // instantiate a provider for each of the named classes
- for (Iterator i=classNames.iterator(); i.hasNext(); ) {
- try {
- o = Class.forName( (String) i.next(), true, loader ).newInstance();
- if (o instanceof org.apache.wsif.spi.WSIFProvider) {
- WSIFProvider p = (org.apache.wsif.spi.WSIFProvider) o;
- if ( p.getBindingNamespaceURIs().length > 0 ) {
- providers.add( p );
- } else {
- WSIFException ex = new WSIFException(
- "ignoring disabled WSIFProvider:" +
- p.getClass().getName() );
- Trc.exception( ex );
- }
- } else {
- MessageLogger.log(
- "WSIF.0003W",
- "The provider class specified," +
- ( (o == null) ? null : o.getClass().getName() ) +
- ", does not implement org.apache.wsif.spi.WSIFProvider" );
- }
- } catch (ClassNotFoundException ex) {
- Trc.exception( ex );
- MessageLogger.log(
- "WSIF.0003W",
- ex.getMessage() );
- } catch (Exception ex) {
- Trc.exception( ex );
- MessageLogger.log(
- "WSIF.0003W",
- ex.getMessage() );
- }
- }
+ Object o;
+ ArrayList classNames = new ArrayList();
+ ArrayList providers = new ArrayList();
+
+ // find all the class names mentioned in all the META-INF files
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
- return providers;
+ try {
+ for (Enumeration e = loader.getResources(PLUGABLE_PROVIDER_FILENAME); e.hasMoreElements();) {
+ readMETAINFClassNames((URL) e.nextElement(), classNames);
+ }
+ } catch (Exception ex) {
+ Trc.exception(ex);
+ MessageLogger.log("WSIF.0003W", ex.getMessage());
+ return providers;
+ }
+
+ // instantiate a provider for each of the named classes
+ for (Iterator i = classNames.iterator(); i.hasNext();) {
+ try {
+ o = Class.forName((String) i.next(), true, loader).newInstance();
+ if (o instanceof org.apache.wsif.spi.WSIFProvider) {
+ WSIFProvider p = (org.apache.wsif.spi.WSIFProvider) o;
+ if (p.getBindingNamespaceURIs().length > 0) {
+ Trc.event(null, "Registering provider: " + p);
+ providers.add(p);
+ } else {
+ WSIFException ex =
+ new WSIFException(
+ "Disabled WSIFProvider found:"
+ + p.getClass().getName());
+ Trc.ignoredException(ex);
+ }
+ } else {
+ MessageLogger.log(
+ "WSIF.0003W",
+ "The provider class specified,"
+ + ((o == null) ? null : o.getClass().getName())
+ + ", does not implement org.apache.wsif.spi.WSIFProvider");
+ }
+ } catch (ClassNotFoundException ex) {
+ Trc.exception(ex);
+ MessageLogger.log("WSIF.0003W", ex.getMessage());
+ } catch (Exception ex) {
+ Trc.exception(ex);
+ MessageLogger.log("WSIF.0003W", ex.getMessage());
+ }
+ }
+
+ return providers;
}
- private static ArrayList readMETAINFClassNames(URL u) {
- ArrayList classNames = new ArrayList();
- BufferedReader in = null;
+ private static void readMETAINFClassNames(URL u, ArrayList classNames) {
+ Trc.entry(null, u);
+ Trc.event(
+ null,
+ "Reading provider class names from URL: " + u.toString());
+ BufferedReader in = null;
String inputLine;
int i;
- try {
- in = new BufferedReader( new InputStreamReader( u.openStream() ) );
- while ((inputLine = in.readLine()) != null) {
- i = inputLine.indexOf('#');
- if(i >= 0) {
- inputLine = inputLine.substring(0, i);
- }
- inputLine = inputLine.trim();
- if (inputLine.length() > 0 ) {
- classNames.add( inputLine );
- }
- }
- } catch (IOException ex) {
- Trc.exception( ex );
- MessageLogger.log(
- "WSIF.0003W",
- ex.getMessage() );
- } finally {
- if ( in != null ) {
- try {
- in.close();
- } catch (IOException ex) {
- Trc.exception( ex );
- MessageLogger.log(
- "WSIF.0003W",
- ex.getMessage() );
- }
- }
- }
- return classNames;
+ try {
+ in = new BufferedReader(new InputStreamReader(u.openStream()));
+ while ((inputLine = in.readLine()) != null) {
+ i = inputLine.indexOf('#');
+ if (i >= 0) {
+ inputLine = inputLine.substring(0, i);
+ }
+ inputLine = inputLine.trim();
+ if (inputLine.length() > 0) {
+ Trc.event(null, "Found provider class name: " + inputLine);
+ if (!classNames.contains(inputLine)) {
+ classNames.add(inputLine);
+ }
+ }
+ }
+ } catch (IOException ex) {
+ Trc.exception(ex);
+ MessageLogger.log("WSIF.0003W", ex.getMessage());
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException ex) {
+ Trc.exception(ex);
+ MessageLogger.log("WSIF.0003W", ex.getMessage());
+ }
+ }
+ }
+ Trc.exit();
}
/**
@@ -437,15 +450,16 @@
if (providers == null || providers.size() < 1) {
return null;
} else if (providers.size() == 1) {
- return (WSIFProvider)providers.get(0);
+ return (WSIFProvider) providers.get(0);
}
int i = providers.size() - 1;
- while (i > 0 && !isDefaultProvider((WSIFProvider)providers.get(i), uri)) {
+ while (i > 0
+ && !isDefaultProvider((WSIFProvider) providers.get(i), uri)) {
i--;
}
WSIFProvider p = (WSIFProvider) providers.get(i);
- issueChosenProviderMsg( uri, p );
+ issueChosenProviderMsg(uri, p);
return p;
}
@@ -458,21 +472,24 @@
* @return true if className is defined as the default WSIFprovider,
* otherwise false.
*/
- private static boolean isDefaultProvider(WSIFProvider provider, String uri) {
+ private static boolean isDefaultProvider(
+ WSIFProvider provider,
+ String uri) {
String className = provider.getClass().getName();
String defaultURI;
try {
String key = WSIFConstants.WSIF_PROP_PROVIDER_PFX1 + className;
int n = Integer.parseInt(WSIFProperties.getProperty(key));
for (int i = 1; i <= n; i++) {
- key = WSIFConstants.WSIF_PROP_PROVIDER_PFX2 + i + "." + className;
+ key =
+ WSIFConstants.WSIF_PROP_PROVIDER_PFX2 + i + "." + className;
defaultURI = WSIFProperties.getProperty(key);
- if (uri != null && uri.equals(defaultURI)) {
+ if (uri != null && uri.equals(defaultURI)) {
return true;
}
}
} catch (NumberFormatException e) { // ignore any error
- Trc.ignoredException(e);
+ Trc.ignoredException(e);
} // ignore any error
return false;
}
@@ -490,7 +507,7 @@
for (int i = 1; i < providers.size(); i++) {
providerNames += ", " + providers.get(i).getClass().getName();
}
- MessageLogger.log("WSIF.0006W",uri, providerNames);
+ MessageLogger.log("WSIF.0006W", uri, providerNames);
}
/**