package org.jboss.deployment;
import org.jboss.metadata.MetaData;
import org.w3c.dom.Element;
public class J2eeModuleMetaData
extends MetaData
{
public static final int EJB = 0;
public static final int WEB = 1;
public static final int CLIENT = 2;
public static final int CONNECTOR = 3;
public static final int SERVICE = 4;
public static final int HAR = 5;
private static final String[] tags = {"ejb", "web", "java", "connector", "service", "har"};
int type;
String fileName;
String alternativeDD;
String webContext;
public boolean isEjb()
{
return (type == EJB);
}
public boolean isWeb()
{
return (type == WEB);
}
public boolean isJava()
{
return (type == CLIENT);
}
public boolean isConnector()
{
return (type == CONNECTOR);
}
public String getFileName()
{
return fileName;
}
public String getAlternativeDD()
{
return alternativeDD;
}
public String getWebContext()
{
if (type == WEB)
{
return webContext;
}
else
{
return null;
}
}
public void importXml(Element rootElement) throws DeploymentException
{
String rootTag = rootElement.getOwnerDocument().getDocumentElement().getTagName();
if (rootTag.equals("application"))
importXml(rootElement, false);
else if (rootTag.equals("jboss-app"))
importXml(rootElement, true);
else
throw new DeploymentException("Unrecognized root tag: " + rootTag);
}
protected void importXml(Element element, boolean jbossSpecific) throws DeploymentException
{
String name = element.getTagName();
if (name.equals("module"))
{
boolean done = false; for (int i = 0; done == false && i < tags.length; ++i)
{
Element child = getOptionalChild(element, tags[i]);
if (child == null)
{
continue;
}
type = i;
switch (type)
{
case SERVICE:
if (jbossSpecific == false)
{
throw new DeploymentException("Service archives must be in jboss-app.xml");
} case HAR:
if (jbossSpecific == false)
{
throw new DeploymentException("Hibernate archives must be in jboss-app.xml");
}
case EJB:
case CLIENT:
case CONNECTOR:
fileName = getElementContent(child);
alternativeDD = getElementContent(getOptionalChild(element, "alt-dd"));
break;
case WEB:
fileName = getElementContent(getUniqueChild(child, "web-uri"));
webContext = getElementContent(getOptionalChild(child, "context-root"));
alternativeDD = getElementContent(getOptionalChild(element, "alt-dd"));
break;
}
done = true;
}
if (done == false)
{
StringBuffer msg = new StringBuffer("Invalid module content, must be one of: ");
for (int i = 0; i < tags.length; i ++)
{
msg.append(tags[i]);
msg.append(", ");
}
throw new DeploymentException(msg.toString());
}
}
else
{
throw new DeploymentException("non-module tag in application dd: " + name);
}
}
}