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:
020: package org.apache.axis2.deployment.repository.util;
021:
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.deployment.DeploymentErrorMsgs;
024: import org.apache.axis2.deployment.Deployer;
025: import org.apache.axis2.deployment.DeploymentException;
026: import org.apache.axis2.deployment.util.Utils;
027: import org.apache.axis2.i18n.Messages;
028:
029: import java.io.File;
030: import java.net.URL;
031:
032: /**
033: * DeploymentFileData represents a "thing to deploy" in Axis2. It consists of a file,
034: * a deployment ClassLoader, and a Deployer.
035: */
036: public class DeploymentFileData {
037: private File file;
038: private ClassLoader classLoader;
039: private Deployer deployer;
040:
041: public DeploymentFileData(File file) {
042: if (file == null)
043: throw new IllegalArgumentException(
044: "Filename must not be null");
045: this .file = file;
046: }
047:
048: public DeploymentFileData(File file, Deployer deployer) {
049: this (file);
050: this .deployer = deployer;
051: }
052:
053: public String getAbsolutePath() {
054: return file.getAbsolutePath();
055: }
056:
057: public ClassLoader getClassLoader() {
058: return classLoader;
059: }
060:
061: public File getFile() {
062: return file;
063: }
064:
065: /**
066: * Get the name of the file.
067: *
068: * @return the name of the referenced file
069: */
070: public String getName() {
071: return file.getName(); // No need to check for null due to constructor check
072: }
073:
074: /**
075: * Get the name of the file.
076: *
077: * @return the name of the referenced file
078: * @deprecated please use getName() instead - this will disappear after 1.3.
079: */
080: public String getServiceName() {
081: return getName();
082: }
083:
084: public static boolean isModuleArchiveFile(String filename) {
085: return (filename.endsWith(".mar"));
086: }
087:
088: /**
089: * Checks whether a given file is a jar or an aar file.
090: *
091: * @param filename file to check
092: * @return Returns boolean.
093: */
094: public static boolean isServiceArchiveFile(String filename) {
095: return ((filename.endsWith(".jar")) | (filename
096: .endsWith(".aar")));
097: }
098:
099: public static String getFileExtension(String fileName) {
100: int index = fileName.lastIndexOf('.');
101: return fileName.substring(index + 1);
102: }
103:
104: public void setClassLoader(ClassLoader classLoader) {
105: this .classLoader = classLoader;
106: }
107:
108: public void setClassLoader(boolean isDirectory, ClassLoader parent,
109: File file) throws AxisFault {
110: if (!isDirectory) {
111: if (this .file != null) {
112: URL[] urlsToLoadFrom;
113: try {
114: if (!this .file.exists()) {
115: throw new AxisFault(Messages.getMessage(
116: DeploymentErrorMsgs.FILE_NOT_FOUND,
117: this .file.getAbsolutePath()));
118: }
119: urlsToLoadFrom = new URL[] { this .file.toURL() };
120: classLoader = Utils.createClassLoader(
121: urlsToLoadFrom, parent, true, file);
122: } catch (Exception e) {
123: throw AxisFault.makeFault(e);
124: }
125: }
126: } else {
127: if (this .file != null) {
128: classLoader = Utils.getClassLoader(parent, this .file);
129: }
130: }
131: }
132:
133: public Deployer getDeployer() {
134: return deployer;
135: }
136:
137: public void setDeployer(Deployer deployer) {
138: this .deployer = deployer;
139: }
140:
141: public void deploy() throws DeploymentException {
142: deployer.deploy(this);
143: }
144: }
|