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 org.jboss.deployment;
023:
024: // $Id: J2eeModuleMetaData.java 57209 2006-09-26 12:21:57Z dimitris@jboss.org $
025:
026: import org.jboss.metadata.MetaData;
027:
028: import org.w3c.dom.Element;
029:
030: /**
031: * The metadata for an application/module element
032: *
033: * @author <a href="mailto:daniel.schulze@telkel.com">Daniel Schulze</a>
034: * @author Thomas.Diesler@jboss.org
035: * @version $Revision: 57209 $
036: */
037: public class J2eeModuleMetaData extends MetaData {
038: // Constants -----------------------------------------------------
039: public static final int EJB = 0;
040: public static final int WEB = 1;
041: public static final int CLIENT = 2;
042: public static final int CONNECTOR = 3;
043: public static final int SERVICE = 4;
044: public static final int HAR = 5;
045: private static final String[] tags = { "ejb", "web", "java",
046: "connector", "service", "har" };
047:
048: // Attributes ----------------------------------------------------
049: int type;
050:
051: String fileName;
052: String alternativeDD;
053: String webContext;
054:
055: // Static --------------------------------------------------------
056:
057: // Public --------------------------------------------------------
058:
059: public boolean isEjb() {
060: return (type == EJB);
061: }
062:
063: public boolean isWeb() {
064: return (type == WEB);
065: }
066:
067: public boolean isJava() {
068: return (type == CLIENT);
069: }
070:
071: public boolean isConnector() {
072: return (type == CONNECTOR);
073: }
074:
075: public String getFileName() {
076: return fileName;
077: }
078:
079: public String getAlternativeDD() {
080: return alternativeDD;
081: }
082:
083: public String getWebContext() {
084: if (type == WEB) {
085: return webContext;
086: } else {
087: return null;
088: }
089: }
090:
091: public void importXml(Element rootElement)
092: throws DeploymentException {
093: String rootTag = rootElement.getOwnerDocument()
094: .getDocumentElement().getTagName();
095: if (rootTag.equals("application"))
096: importXml(rootElement, false);
097: else if (rootTag.equals("jboss-app"))
098: importXml(rootElement, true);
099: else
100: throw new DeploymentException("Unrecognized root tag: "
101: + rootTag);
102: }
103:
104: protected void importXml(Element element, boolean jbossSpecific)
105: throws DeploymentException {
106: String name = element.getTagName();
107: if (name.equals("module")) {
108: boolean done = false; // only one of the tags can hit!
109: for (int i = 0; done == false && i < tags.length; ++i) {
110: Element child = getOptionalChild(element, tags[i]);
111: if (child == null) {
112: continue;
113: }
114:
115: type = i;
116: switch (type) {
117: case SERVICE:
118: if (jbossSpecific == false) {
119: throw new DeploymentException(
120: "Service archives must be in jboss-app.xml");
121: } // end of if ()
122: //fall through.
123: case HAR:
124: if (jbossSpecific == false) {
125: throw new DeploymentException(
126: "Hibernate archives must be in jboss-app.xml");
127: }
128: case EJB:
129: case CLIENT:
130: case CONNECTOR:
131: fileName = getElementContent(child);
132: alternativeDD = getElementContent(getOptionalChild(
133: element, "alt-dd"));
134: break;
135: case WEB:
136: fileName = getElementContent(getUniqueChild(child,
137: "web-uri"));
138: webContext = getElementContent(getOptionalChild(
139: child, "context-root"));
140: alternativeDD = getElementContent(getOptionalChild(
141: element, "alt-dd"));
142: break;
143: }
144: done = true;
145: }
146:
147: // If the module content is not recognized throw an exception
148: if (done == false) {
149: StringBuffer msg = new StringBuffer(
150: "Invalid module content, must be one of: ");
151: for (int i = 0; i < tags.length; i++) {
152: msg.append(tags[i]);
153: msg.append(", ");
154: }
155: throw new DeploymentException(msg.toString());
156: }
157: } else {
158: throw new DeploymentException(
159: "non-module tag in application dd: " + name);
160: }
161: }
162: }
|