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.deployers;
020:
021: import org.apache.axis2.deployment.Deployer;
022: import org.apache.axis2.deployment.DeploymentException;
023: import org.apache.axis2.deployment.repository.util.DeploymentFileData;
024: import org.apache.axis2.context.ConfigurationContext;
025: import org.apache.axis2.AxisFault;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.commons.logging.Log;
028:
029: import java.io.FileReader;
030: import java.io.FileNotFoundException;
031: import java.io.FileInputStream;
032:
033: /**
034: * A custom Deployer instance for testing. This coordinates with the CustomDeployerTest and
035: * the CustomDeployerRepo/ repository in test-resources/. It's going to be set up to deploy
036: * "svc" files, both in the services/ directory and in the widgets/ directory. After the
037: * config is complete, we should have 2 deployed items, and should have found both "Mary" and
038: * "George" (see the repo for test data). We use static fields to keep all this information
039: * in a way that the test can access it.
040: */
041: public class CustomDeployer implements Deployer {
042: protected static final Log log = LogFactory
043: .getLog(CustomDeployer.class);
044:
045: /** Has init() been called? */
046: public static boolean initCalled;
047: /** This is set to the last argument to setDirectory() */
048: public static String directory;
049: /** This is set to the last argument to setExtension() */
050: public static String extension;
051: /** The count of deployed items */
052: public static int deployedItems;
053: /** Set to true if "George" has been deployed */
054: public static boolean georgeDeployed;
055: /** Set to true if "Mary" has been deployed */
056: public static boolean maryDeployed;
057:
058: public static final String PARAM_NAME = "customDeployerParam";
059: public static final String PARAM_VAL = "customDeployer parameter value";
060:
061: /**
062: * Initialize the Deployer
063: *
064: * @param configCtx our ConfigurationContext
065: */
066: public void init(ConfigurationContext configCtx) {
067: initCalled = true;
068:
069: // Set a property on the AxisConfig just to make sure we end up with the right one
070: try {
071: configCtx.getAxisConfiguration().addParameter(PARAM_NAME,
072: PARAM_VAL);
073: } catch (AxisFault axisFault) {
074: // Two comments - 1) why the heck does addParameter throw AxisFault?
075: // 2) why doesn't init() throw AxisFault?
076: }
077: }
078:
079: /**
080: * Process a file and add it to the configuration
081: *
082: * @param deploymentFileData the DeploymentFileData object to deploy
083: * @throws org.apache.axis2.deployment.DeploymentException
084: * if there is a problem
085: */
086: public void deploy(DeploymentFileData deploymentFileData)
087: throws DeploymentException {
088: log.info("Deploying - " + deploymentFileData.getName());
089: try {
090: FileInputStream fis = new FileInputStream(
091: deploymentFileData.getFile());
092: int x = fis.available();
093: byte b[] = new byte[x];
094: fis.read(b);
095: String content = new String(b);
096: if (content.indexOf("George") > -1)
097: georgeDeployed = true;
098: if (content.indexOf("Mary") > -1)
099: maryDeployed = true;
100: deployedItems++;
101: } catch (Exception e) {
102: throw new DeploymentException(e);
103: }
104: }
105:
106: /**
107: * Set the directory
108: *
109: * @param directory directory name
110: */
111: public void setDirectory(String directory) {
112: CustomDeployer.directory = directory;
113: }
114:
115: /**
116: * Set the extension to look for TODO: Support multiple extensions?
117: *
118: * @param extension the file extension associated with this Deployer
119: */
120: public void setExtension(String extension) {
121: CustomDeployer.extension = extension;
122: }
123:
124: /**
125: * Remove a given file from the configuration
126: *
127: * @param fileName name of item to remove
128: * @throws org.apache.axis2.deployment.DeploymentException
129: * if there is a problem
130: */
131: public void unDeploy(String fileName) throws DeploymentException {
132: // Undeploy
133: }
134: }
|