001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * 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, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.deployment.application;
021:
022: import java.io.File;
023: import java.io.IOException;
024: import java.io.InputStream;
025:
026: import javax.xml.parsers.ParserConfigurationException;
027:
028: import org.apache.cactus.integration.ant.deployment.DefaultJarArchive;
029: import org.apache.cactus.integration.ant.deployment.webapp.DefaultWarArchive;
030: import org.apache.cactus.integration.ant.deployment.webapp.WarArchive;
031: import org.xml.sax.SAXException;
032:
033: /**
034: * Encapsulates access to an EAR.
035: *
036: * @since Cactus 1.5
037: * @version $Id: DefaultEarArchive.java 239003 2004-05-31 20:05:27Z vmassol $
038: */
039: public class DefaultEarArchive extends DefaultJarArchive implements
040: EarArchive {
041: // Instance Variables ------------------------------------------------------
042:
043: /**
044: * The parsed deployment descriptor.
045: */
046: private ApplicationXml applicationXml;
047:
048: // Constructors ------------------------------------------------------------
049:
050: /**
051: * Constructor.
052: *
053: * @param theFile The enterprise application archive
054: * @throws IOException If there was a problem reading the EAR
055: */
056: public DefaultEarArchive(File theFile) throws IOException {
057: super (theFile);
058: }
059:
060: /**
061: * Constructor.
062: *
063: * @param theInputStream The input stream for the enterprise application
064: * archive
065: * @throws IOException If there was a problem reading the EAR
066: */
067: public DefaultEarArchive(InputStream theInputStream)
068: throws IOException {
069: super (theInputStream);
070: }
071:
072: // Public Methods ----------------------------------------------------------
073:
074: /**
075: * @see EarArchive#getApplicationXml()
076: */
077: public final ApplicationXml getApplicationXml() throws IOException,
078: SAXException, ParserConfigurationException {
079: if (this .applicationXml == null) {
080: InputStream in = null;
081: try {
082: in = getResource("META-INF/application.xml");
083: this .applicationXml = ApplicationXmlIo
084: .parseApplicationXml(in, null);
085: } finally {
086: if (in != null) {
087: in.close();
088: }
089: }
090: }
091: return this .applicationXml;
092: }
093:
094: /**
095: * @see EarArchive#getWebModule(String)
096: */
097: public final WarArchive getWebModule(String theUri)
098: throws IOException {
099: InputStream war = null;
100: try {
101: war = getResource(theUri);
102: if (war != null) {
103: return new DefaultWarArchive(war);
104: }
105: } finally {
106: if (war != null) {
107: war.close();
108: }
109: }
110: return null;
111: }
112:
113: }
|