KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > application > DefaultEarArchive


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.deployment.application;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25
26 import javax.xml.parsers.ParserConfigurationException JavaDoc;
27
28 import org.apache.cactus.integration.ant.deployment.DefaultJarArchive;
29 import org.apache.cactus.integration.ant.deployment.webapp.DefaultWarArchive;
30 import org.apache.cactus.integration.ant.deployment.webapp.WarArchive;
31 import org.xml.sax.SAXException JavaDoc;
32
33 /**
34  * Encapsulates access to an EAR.
35  *
36  * @since Cactus 1.5
37  * @version $Id: DefaultEarArchive.java,v 1.1 2004/05/31 20:05:24 vmassol Exp $
38  */

39 public class DefaultEarArchive extends DefaultJarArchive implements EarArchive
40 {
41     // Instance Variables ------------------------------------------------------
42

43     /**
44      * The parsed deployment descriptor.
45      */

46     private ApplicationXml applicationXml;
47
48     // Constructors ------------------------------------------------------------
49

50     /**
51      * Constructor.
52      *
53      * @param theFile The enterprise application archive
54      * @throws IOException If there was a problem reading the EAR
55      */

56     public DefaultEarArchive(File JavaDoc theFile)
57         throws IOException JavaDoc
58     {
59         super(theFile);
60     }
61
62     /**
63      * Constructor.
64      *
65      * @param theInputStream The input stream for the enterprise application
66      * archive
67      * @throws IOException If there was a problem reading the EAR
68      */

69     public DefaultEarArchive(InputStream JavaDoc theInputStream)
70         throws IOException JavaDoc
71     {
72         super(theInputStream);
73     }
74
75     // Public Methods ----------------------------------------------------------
76

77     /**
78      * @see EarArchive#getApplicationXml()
79      */

80     public final ApplicationXml getApplicationXml()
81         throws IOException JavaDoc, SAXException JavaDoc, ParserConfigurationException JavaDoc
82     {
83         if (this.applicationXml == null)
84         {
85             InputStream JavaDoc in = null;
86             try
87             {
88                 in = getResource("META-INF/application.xml");
89                 this.applicationXml =
90                     ApplicationXmlIo.parseApplicationXml(in, null);
91             }
92             finally
93             {
94                 if (in != null)
95                 {
96                     in.close();
97                 }
98             }
99         }
100         return this.applicationXml;
101     }
102
103     /**
104      * @see EarArchive#getWebModule(String)
105      */

106     public final WarArchive getWebModule(String JavaDoc theUri)
107         throws IOException JavaDoc
108     {
109         InputStream JavaDoc war = null;
110         try
111         {
112             war = getResource(theUri);
113             if (war != null)
114             {
115                 return new DefaultWarArchive(war);
116             }
117         }
118         finally
119         {
120             if (war != null)
121             {
122                 war.close();
123             }
124         }
125         return null;
126     }
127
128 }
129
Popular Tags