001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.enterprise.deploy.shared;
023:
024: /**
025: * An enumeration of j2ee module types.
026: *
027: * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
028: * @version $Revision: 57196 $
029: */
030: public class ModuleType {
031: // Constants -----------------------------------------------------
032:
033: /** The EAR integer value */
034: private static final int EAR_INT = 0;
035: /** The EJB integer value */
036: private static final int EJB_INT = 1;
037: /** The CAR integer value */
038: private static final int CAR_INT = 2;
039: /** The RAR integer value */
040: private static final int RAR_INT = 3;
041: /** The WAR integer value */
042: private static final int WAR_INT = 4;
043:
044: /** The module type for an EAR */
045: public static final ModuleType EAR = new ModuleType(EAR_INT);
046: /** The module type for an EJB */
047: public static final ModuleType EJB = new ModuleType(EJB_INT);
048: /** The module type for an CAR */
049: public static final ModuleType CAR = new ModuleType(CAR_INT);
050: /** The module type for an RAR */
051: public static final ModuleType RAR = new ModuleType(RAR_INT);
052: /** The module type for an WAR */
053: public static final ModuleType WAR = new ModuleType(WAR_INT);
054:
055: /** The module types */
056: private static final ModuleType[] moduleTypes = new ModuleType[] {
057: EAR, EJB, CAR, RAR, WAR };
058:
059: /** The module type strings */
060: private static final String[] stringTable = { "ear", "ejb", "car",
061: "rar", "war" };
062:
063: /** The module extensions */
064: private static final String[] moduleExtensions = new String[] {
065: ".ear", ".jar", ".jar", ".rar", ".war" };
066:
067: // Attributes ----------------------------------------------------
068:
069: /** The value */
070: private int value;
071:
072: /**
073: * Create a new ModuleType
074: *
075: * @param value the value
076: */
077: protected ModuleType(int value) {
078: this .value = value;
079: }
080:
081: // Public --------------------------------------------------------
082:
083: /**
084: * Get the value
085: *
086: * @return the value
087: */
088: public int getValue() {
089: return value;
090: }
091:
092: /**
093: * Get the string table for class module type. This is:
094: * {"ear", "ejb", "car", "rar", "war"}
095: *
096: * @return the string table
097: */
098: protected String[] getStringTable() {
099: return stringTable;
100: }
101:
102: /**
103: * Get the enumerated values for module type
104: *
105: * @return the string table
106: */
107: protected ModuleType[] getEnumValueTable() {
108: return moduleTypes;
109: }
110:
111: /**
112: * Get the file extension for this module
113: *
114: * @return the file extension
115: */
116: public String getModuleExtension() {
117: if (value >= moduleExtensions.length)
118: return Integer.toString(value);
119: return moduleExtensions[value];
120: }
121:
122: /**
123: * Get the module type for an integer
124: *
125: * @param type the type
126: * @return the module type
127: */
128: public static ModuleType getModuleType(int type) {
129: if (type >= moduleTypes.length)
130: return null;
131: return moduleTypes[type];
132: }
133:
134: /**
135: * @return The stringTable entry for this ModuleType value
136: */
137: public String toString() {
138: if (value >= stringTable.length)
139: return Integer.toString(value);
140: return stringTable[value];
141: }
142:
143: /**
144: * Return the offset of the first element
145: *
146: * @return the offset
147: */
148: protected int getOffset() {
149: return EAR_INT;
150: }
151:
152: // Private -------------------------------------------------------
153:
154: // Inner classes -------------------------------------------------
155: }
|