View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  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  package org.apache.geronimo.j2ee.deployment;
19  
20  import java.util.jar.JarFile;
21  import java.net.URI;
22  
23  import org.apache.xmlbeans.XmlObject;
24  import org.apache.geronimo.kernel.config.ConfigurationModuleType;
25  import org.apache.geronimo.kernel.repository.Environment;
26  import org.apache.geronimo.deployment.util.DeploymentUtil;
27  import org.apache.geronimo.gbean.AbstractName;
28  
29  /**
30   * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
31   */
32  public abstract class Module {
33      private final boolean standAlone;
34  
35      private final AbstractName moduleName;
36      private final String name;
37      private final Environment environment;
38      private final URI moduleURI;
39      private final JarFile moduleFile;
40      private final String targetPath;
41      private final URI targetPathURI;
42      private final XmlObject specDD;
43      private final XmlObject vendorDD;
44      private final String originalSpecDD;
45      private final String namespace;
46  
47      private EARContext earContext;
48      private EARContext rootEarContext;
49  
50      protected Module(boolean standAlone, AbstractName moduleName, Environment environment, JarFile moduleFile, String targetPath, XmlObject specDD, XmlObject vendorDD, String originalSpecDD, String namespace) {
51          assert targetPath != null: "targetPath is null";
52          assert moduleName != null: "moduleName is null";
53  
54          this.standAlone = standAlone;
55          this.moduleName = moduleName;
56          this.environment = environment;
57          this.moduleFile = moduleFile;
58          this.targetPath = targetPath;
59          this.specDD = specDD;
60          this.vendorDD = vendorDD;
61          this.originalSpecDD = originalSpecDD;
62          this.namespace = namespace;
63  
64          if (standAlone) {
65              name = environment.getConfigId().toString();
66              moduleURI = URI.create("");
67          } else {
68              name = targetPath;
69              moduleURI = URI.create(targetPath);
70          }
71  
72          targetPathURI = URI.create(targetPath + "/");
73      }
74  
75      public abstract ConfigurationModuleType getType();
76  
77      public String getName() {
78          return name;
79      }
80  
81      public boolean isStandAlone() {
82          return standAlone;
83      }
84  
85      public AbstractName getModuleName() {
86          return moduleName;
87      }
88  
89      public Environment getEnvironment() {
90          return environment;
91      }
92  
93      public URI getModuleURI() {
94          return moduleURI;
95      }
96  
97      public JarFile getModuleFile() {
98          return moduleFile;
99      }
100 
101     public String getTargetPath() {
102         return targetPath;
103     }
104 
105     public URI getTargetPathURI() {
106         return targetPathURI;
107     }
108 
109     public XmlObject getSpecDD() {
110         return specDD;
111     }
112 
113     public XmlObject getVendorDD() {
114         return vendorDD;
115     }
116 
117     public String getOriginalSpecDD() {
118         return originalSpecDD;
119     }
120 
121     public String getNamespace() {
122         return namespace;
123     }
124 
125     public int hashCode() {
126         return name.hashCode();
127     }
128 
129     public boolean equals(Object obj) {
130         if (obj == this) {
131             return true;
132         }
133         if (obj instanceof Module) {
134             Module module = (Module) obj;
135             return name.equals(module.name);
136         }
137         return false;
138     }
139 
140     public void close() {
141         DeploymentUtil.close(moduleFile);
142     }
143 
144 
145     public EARContext getEarContext() {
146         return earContext;
147     }
148 
149     public void setEarContext(EARContext earContext) {
150         this.earContext = earContext;
151     }
152 
153     public EARContext getRootEarContext() {
154         return rootEarContext;
155     }
156 
157     public void setRootEarContext(EARContext rootEarContext) {
158         this.rootEarContext = rootEarContext;
159     }
160 }