KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > spi > TargetModuleIDImpl


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.deployment.spi;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
28 import javax.enterprise.deploy.spi.Target JavaDoc;
29 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
30
31 /**
32  * A TargetModuleID interface represents a unique identifier for a deployed
33  * application module. A deployable application module can be an EAR, JAR, WAR
34  * or RAR file. A TargetModuleID can represent a root module or a child module.
35  * A root module TargetModuleID has no parent. It represents a deployed EAR file
36  * or stand alone module. A child module TargetModuleID represents a deployed
37  * sub module of a J2EE application. A child TargetModuleID has only one parent,
38  * the super module it was bundled and deployed with. The identifier consists of
39  * the target name and the unique identifier for the deployed application
40  * module.
41  *
42  * @author thomas.diesler@jboss.org
43  * @version $Revision: 38481 $
44  */

45 public class TargetModuleIDImpl implements TargetModuleID JavaDoc
46 {
47
48    private TargetModuleIDImpl parentModuleID;
49    private List JavaDoc childModuleIDs = new ArrayList JavaDoc();
50    private JBossTarget target;
51    private String JavaDoc moduleID;
52    private ModuleType JavaDoc moduleType;
53    private boolean isRunning;
54
55    /**
56     * Construct a new target module
57     */

58    public TargetModuleIDImpl(Target JavaDoc target, String JavaDoc moduleID, TargetModuleID JavaDoc parentModuleID, boolean isRunning, ModuleType JavaDoc moduleType)
59    {
60       this.target = (JBossTarget)target;
61       this.moduleID = moduleID;
62       this.parentModuleID = (TargetModuleIDImpl)parentModuleID;
63       this.isRunning = isRunning;
64       this.moduleType = moduleType;
65    }
66
67    /**
68     * True if the module is running.
69     */

70    public boolean isRunning()
71    {
72       return isRunning;
73    }
74
75    /**
76     * Get this modules type.
77     */

78    public ModuleType JavaDoc getModuleType()
79    {
80       return moduleType;
81    }
82
83    // TargetModuleID interface ************************************************
84

85    /**
86     * Get the target
87     * @return the target
88     */

89    public Target JavaDoc getTarget()
90    {
91       return target;
92    }
93
94    /**
95     * Get the module id
96     * @return the id
97     */

98    public String JavaDoc getModuleID()
99    {
100       return moduleID;
101    }
102
103    /**
104     * The URL for a web module
105     * @return the url
106     */

107    public String JavaDoc getWebURL()
108    {
109       return null; //[todo] implement method
110
}
111
112    /**
113     * The parent of this module
114     * @return the parent or null if there is no parent
115     */

116    public TargetModuleID JavaDoc getParentTargetModuleID()
117    {
118       return parentModuleID;
119    }
120
121    /**
122     * Get the child modules
123     * @return an array of child modules or null if there are no children
124     */

125    public TargetModuleID JavaDoc[] getChildTargetModuleID()
126    {
127       TargetModuleID JavaDoc[] idarr = new TargetModuleID JavaDoc[childModuleIDs.size()];
128       childModuleIDs.toArray(idarr);
129       return idarr;
130    }
131
132    public void addChildTargetModuleID(TargetModuleID JavaDoc childModuleID)
133    {
134       childModuleIDs.add(childModuleID);
135    }
136
137    public int hashCode()
138    {
139       String JavaDoc hashStr = moduleType + moduleID;
140       if (parentModuleID != null)
141       {
142          hashStr += parentModuleID.moduleID;
143       }
144       return hashStr.hashCode();
145    }
146
147    /**
148     * Equality is defined by moduleType, moduleID, and parentModuleID
149     */

150    public boolean equals(Object JavaDoc obj)
151    {
152       boolean equals = false;
153       if (obj instanceof TargetModuleIDImpl)
154       {
155          TargetModuleIDImpl other = (TargetModuleIDImpl)obj;
156          equals = moduleType.equals(other.moduleType) && moduleID.equals(other.moduleID);
157          if (equals && parentModuleID != null)
158             equals = equals && parentModuleID.equals(other.parentModuleID);
159       }
160       return equals;
161    }
162
163    public String JavaDoc toString()
164    {
165       String JavaDoc parentID = (parentModuleID != null ? parentModuleID.moduleID : null);
166       return "[host=" + target.getHostName() + ",parent=" + parentID + ",id=" + moduleID + "]";
167    }
168 }
169
Popular Tags