001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.deployment;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.util.Loader;
023: import org.apache.axis2.description.Parameter;
024: import org.apache.axis2.engine.AxisConfiguration;
025: import org.apache.axis2.engine.AxisConfigurator;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: import java.io.IOException;
030: import java.io.InputStream;
031: import java.net.MalformedURLException;
032: import java.net.URL;
033:
034: public class URLBasedAxisConfigurator extends DeploymentEngine
035: implements AxisConfigurator {
036:
037: private static final Log log = LogFactory
038: .getLog(URLBasedAxisConfigurator.class);
039: private URL axis2xml;
040: private URL repository;
041:
042: public URLBasedAxisConfigurator(URL axis2xml, URL repository)
043: throws AxisFault {
044: this .axis2xml = axis2xml;
045: this .repository = repository;
046: }
047:
048: public AxisConfiguration getAxisConfiguration() throws AxisFault {
049: InputStream axis2xmlStream;
050: try {
051: if (axis2xml == null) {
052: axis2xmlStream = Loader
053: .getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
054: } else {
055: axis2xmlStream = axis2xml.openStream();
056: }
057: axisConfig = populateAxisConfiguration(axis2xmlStream);
058: if (repository == null) {
059: Parameter axis2repoPara = axisConfig
060: .getParameter(DeploymentConstants.AXIS2_REPO);
061: if (axis2repoPara != null) {
062: String repoValue = (String) axis2repoPara
063: .getValue();
064: if (repoValue != null
065: && !"".equals(repoValue.trim())) {
066: if (repoValue.startsWith("file:/")) {
067: // we treat this case specially , by assuming file is
068: // located in the local machine
069: loadRepository(repoValue);
070: } else {
071: loadRepositoryFromURL(new URL(repoValue));
072: }
073: }
074: } else {
075: log
076: .info("No repository found , module will be loaded from classpath");
077: loadFromClassPath();
078: }
079: } else {
080: loadRepositoryFromURL(repository);
081: }
082:
083: } catch (IOException e) {
084: throw new AxisFault(e.getMessage());
085: }
086: axisConfig.setConfigurator(this );
087: return axisConfig;
088: }
089:
090: //to load services
091: public void loadServices() {
092: try {
093: if (repository == null) {
094: Parameter axis2repoPara = axisConfig
095: .getParameter(DeploymentConstants.AXIS2_REPO);
096: if (axis2repoPara != null) {
097: String repoValue = (String) axis2repoPara
098: .getValue();
099: if (repoValue != null
100: && !"".equals(repoValue.trim())) {
101: if (repoValue.startsWith("file://")) {
102: // we treat this case specially , by assuming file is
103: // locate in the local machine
104: super .loadServices();
105: } else {
106: loadServicesFromUrl(new URL(repoValue));
107: }
108: }
109: }
110: } else {
111: loadServicesFromUrl(repository);
112: }
113: } catch (MalformedURLException e) {
114: log.info(e);
115: }
116: }
117:
118: //To engage globally listed modules
119: public void engageGlobalModules() throws AxisFault {
120: engageModules();
121: }
122: }
|