Author: alessio.soldano(a)jboss.com
Date: 2012-06-08 09:33:49 -0400 (Fri, 08 Jun 2012)
New Revision: 16402
Added:
api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigUtil.java
Modified:
api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigurer.java
Log:
[JBWS-3335] Refactoring ClientConfigurer interface now that there's way for changing a
previously set client configuration + providing a utility class to further simplify
configuration setup
Added: api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigUtil.java
===================================================================
--- api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigUtil.java
(rev 0)
+++
api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigUtil.java 2012-06-08
13:33:49 UTC (rev 16402)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.api.configuration;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import javax.xml.ws.BindingProvider;
+
+/**
+ * A facility for setting a JBossWS Client Configuration
+ *
+ * @author <a href="mailto:alessio.soldano@jboss.com">Alessio
Soldano</a>
+ */
+public abstract class ClientConfigUtil
+{
+ /**
+ * Reads a client configuration and setups the handlers in the provided
BindingProvider accordingly.
+ * This leverages the resolveClientConfigurer() method for getting the ClientConfigure
to use.
+ *
+ * @param bp The BindingProvider instance to setup
+ * @param configFile The configuration file
+ * @param configName The configuration name
+ */
+ public static void setConfigHandlers(BindingProvider bp, String configFile, String
configName) {
+ ClientConfigurer configurer = resolveClientConfigurer();
+ configurer.setConfigHandlers(bp, configFile, configName);
+ }
+
+ /**
+ * Resolves a ClientConfigurer instance by first using the defining classloader and
+ * failing that by using the current thread context classloader.
+ *
+ * @return A ClientConfigurer instance
+ */
+ public static ClientConfigurer resolveClientConfigurer() {
+ Iterator<ClientConfigurer> it = ServiceLoader.load(ClientConfigurer.class,
ClientConfigUtil.class.getClassLoader()).iterator();
+ if (!it.hasNext()) {
+ it = ServiceLoader.load(ClientConfigurer.class,
getContextClassLoader()).iterator();
+ }
+ return it.next();
+ }
+
+ private static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+}
Modified: api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigurer.java
===================================================================
---
api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigurer.java 2012-06-08
13:30:59 UTC (rev 16401)
+++
api/trunk/src/main/java/org/jboss/ws/api/configuration/ClientConfigurer.java 2012-06-08
13:33:49 UTC (rev 16402)
@@ -24,19 +24,19 @@
import javax.xml.ws.BindingProvider;
/**
- * A facility for setting a JBossWS Client Configuration
+ * JBossWS Client Configuration interface
*
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio
Soldano</a>
*/
public interface ClientConfigurer
{
/**
- * Reads a client configuration and setups the specified BindingProvider accordingly
+ * Reads a client configuration and setups the handlers in the provided
BindingProvider accordingly.
*
* @param bp The BindingProvider instance to setup
* @param configFile The configuration file
* @param configName The configuration name
*/
- public void addConfigHandlers(BindingProvider bp, String configFile, String
configName);
+ public void setConfigHandlers(BindingProvider bp, String configFile, String
configName);
}