001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.axis2.client;
017:
018: import java.util.Hashtable;
019: import java.util.Map;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.context.ConfigurationContext;
023: import org.apache.axis2.context.ConfigurationContextFactory;
024: import org.apache.axis2.jaxws.ClientConfigurationFactory;
025: import org.apache.axis2.jaxws.util.ClassLoaderUtils;
026: import org.apache.axis2.jaxws.util.Constants;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: public class Axis2ClientConfigurationFactory extends
031: ClientConfigurationFactory {
032:
033: private static final Log LOG = LogFactory
034: .getLog(Axis2ClientConfigurationFactory.class);
035:
036: private Map<ClassLoader, ConfigurationContext> contextCache = new Hashtable<ClassLoader, ConfigurationContext>();
037:
038: private boolean reuseConfigurationContext;
039:
040: public Axis2ClientConfigurationFactory(boolean reuse) {
041: this .reuseConfigurationContext = reuse;
042: }
043:
044: public ConfigurationContext getClientConfigurationContext() {
045: ClassLoader cl = ClassLoaderUtils.getContextClassLoader();
046: if (cl == null) {
047: if (this .reuseConfigurationContext) {
048: cl = ClientConfigurationFactory.class.getClassLoader();
049: } else {
050: return createConfigurationContext();
051: }
052: }
053:
054: synchronized (cl) {
055: return getConfigurationContext(cl);
056: }
057: }
058:
059: private ConfigurationContext getConfigurationContext(ClassLoader cl) {
060: ConfigurationContext context = this .contextCache.get(cl);
061: if (context == null) {
062: context = createConfigurationContext();
063: this .contextCache.put(cl, context);
064: if (LOG.isDebugEnabled()) {
065: LOG.debug("Created new configuration context "
066: + context + " for " + cl);
067: }
068: } else {
069: if (LOG.isDebugEnabled()) {
070: LOG.debug("Configuration context " + context
071: + " reused for " + cl);
072: }
073: }
074: return context;
075: }
076:
077: private ConfigurationContext removeConfigurationContext(
078: ClassLoader cl) {
079: return this .contextCache.remove(cl);
080: }
081:
082: public void clearCache() {
083: this .contextCache.clear();
084: }
085:
086: public ConfigurationContext clearCache(ClassLoader cl) {
087: ConfigurationContext context = null;
088: if (cl != null) {
089: synchronized (cl) {
090: context = removeConfigurationContext(cl);
091: }
092:
093: if (LOG.isDebugEnabled()) {
094: LOG.debug("Removed configuration context " + context
095: + " for " + cl);
096: }
097: }
098:
099: return context;
100: }
101:
102: private ConfigurationContext createConfigurationContext() {
103: String repoPath = System.getProperty(Constants.AXIS2_REPO_PATH);
104: String axisConfigPath = System
105: .getProperty(Constants.AXIS2_CONFIG_PATH);
106: try {
107: return ConfigurationContextFactory
108: .createConfigurationContextFromFileSystem(repoPath,
109: axisConfigPath);
110: } catch (AxisFault e) {
111: throw new RuntimeException(e.getMessage(), e);
112: }
113: }
114:
115: }
|