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.Constants;
023: import org.apache.axis2.util.Loader;
024: import org.apache.axis2.description.Parameter;
025: import org.apache.axis2.engine.AxisConfiguration;
026: import org.apache.axis2.engine.AxisConfigurator;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: import java.io.File;
031: import java.io.FileInputStream;
032: import java.io.FileNotFoundException;
033: import java.io.InputStream;
034: import java.io.IOException;
035:
036: public class FileSystemConfigurator extends DeploymentEngine implements
037: AxisConfigurator {
038:
039: private static final Log log = LogFactory
040: .getLog(FileSystemConfigurator.class);
041: /**
042: * To check whether need to create a service side or client side
043: */
044: private String axis2xml = null;
045: private String repoLocation = null;
046:
047: /**
048: * Load an AxisConfiguration from the repository directory specified
049: *
050: * @param repoLocation
051: * @param axis2xml
052: */
053: public FileSystemConfigurator(String repoLocation, String axis2xml)
054: throws AxisFault {
055: if (repoLocation == null) {
056: //checking wether user has set the system property
057: repoLocation = System.getProperty(Constants.AXIS2_REPO);
058: }
059:
060: // OK, we've got a repository location in mind. Let's make
061: // sure it exists.
062: if (repoLocation != null) {
063: File repo = new File(repoLocation);
064: if (repo.exists()) {
065: // ok, save it if so
066: this .repoLocation = repo.getAbsolutePath();
067: } else {
068: log.info("Couldn't find repository location '"
069: + repoLocation + "'");
070: throw new AxisFault(
071: "Couldn't find repository location '"
072: + repoLocation + "'");
073: }
074: }
075:
076: // Deal with the config file. If a filename was specified as an
077: // arg to this constructor, just respect it.
078: if (axis2xml == null) {
079: // If not, check for a system property setting
080: axis2xml = System.getProperty(Constants.AXIS2_CONF);
081:
082: // And if not that, try at the root of the repository if we have one.
083: // It might be nice to default the repository to the current directory, but we don't yet
084: if (axis2xml == null) {
085: if (repoLocation != null) {
086: axis2xml = repoLocation + File.separator
087: + Constants.AXIS2_CONF;
088: }
089: }
090:
091: // In either case, check that the file exists... if not
092: // we'll use the default axis2.xml on the classpath.
093: if (axis2xml != null) {
094: File configFile = new File(axis2xml);
095: if (!configFile.exists()) {
096: log.debug("Config file '" + axis2xml
097: + "' doesn't exist, ignoring.");
098: axis2xml = null;
099: }
100: }
101: }
102:
103: this .axis2xml = axis2xml;
104: }
105:
106: /**
107: * First create a Deployment engine, use that to create an AxisConfiguration
108: *
109: * @return Axis Configuration
110: * @throws AxisFault
111: */
112: public synchronized AxisConfiguration getAxisConfiguration()
113: throws AxisFault {
114: InputStream configStream = null;
115: try {
116: if (axis2xml != null && !"".equals(axis2xml)) {
117: configStream = new FileInputStream(axis2xml);
118: } else {
119: configStream = Loader
120: .getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
121: }
122: axisConfig = populateAxisConfiguration(configStream);
123: } catch (FileNotFoundException e) {
124: throw new AxisFault(
125: "System can not find the given axis2.xml "
126: + axis2xml);
127: } finally {
128: if (configStream != null) {
129: try {
130: configStream.close();
131: } catch (IOException e) {
132: throw AxisFault.makeFault(e);
133: }
134: }
135: }
136: Parameter axis2repoPara = axisConfig
137: .getParameter(DeploymentConstants.AXIS2_REPO);
138: if (axis2repoPara != null) {
139: repoLocation = (String) axis2repoPara.getValue();
140: }
141: if (!(repoLocation == null || "".equals(repoLocation))) {
142: loadRepository(repoLocation);
143: } else {
144: loadFromClassPath();
145: }
146: axisConfig.setConfigurator(this );
147: return axisConfig;
148: }
149:
150: public void engageGlobalModules() throws AxisFault {
151: engageModules();
152: }
153:
154: public void loadServices() {
155: if (!(repoLocation == null || "".equals(repoLocation))) {
156: super.loadServices();
157: }
158: }
159: }
|