1 22 package org.jboss.deployment; 23 24 26 import org.jboss.metadata.MetaData; 27 28 import org.w3c.dom.Element ; 29 30 37 public class J2eeModuleMetaData 38 extends MetaData 39 { 40 public static final int EJB = 0; 42 public static final int WEB = 1; 43 public static final int CLIENT = 2; 44 public static final int CONNECTOR = 3; 45 public static final int SERVICE = 4; 46 public static final int HAR = 5; 47 private static final String [] tags = {"ejb", "web", "java", "connector", "service", "har"}; 48 49 int type; 51 52 String fileName; 53 String alternativeDD; 54 String webContext; 55 56 58 60 63 public J2eeModuleMetaData() 64 { 65 66 } 67 68 73 public J2eeModuleMetaData(int type, String fileName) 74 { 75 this.type = type; 76 this.fileName = fileName; 77 if( type == WEB ) 78 { 79 int dot = fileName.lastIndexOf('.'); 80 if( dot >= 0 ) 81 webContext = fileName.substring(0, dot); 82 } 83 } 84 85 public int getType() 86 { 87 return type; 88 } 89 public void setType(int type) 90 { 91 this.type = type; 92 } 93 94 public boolean isEjb() 95 { 96 return (type == EJB); 97 } 98 99 public boolean isWeb() 100 { 101 return (type == WEB); 102 } 103 104 public boolean isJava() 105 { 106 return (type == CLIENT); 107 } 108 109 public boolean isConnector() 110 { 111 return (type == CONNECTOR); 112 } 113 114 115 public String getFileName() 116 { 117 return fileName; 118 } 119 public void setFileName(String name) 120 { 121 this.fileName = name; 122 if( type == WEB ) 123 { 124 int dot = fileName.lastIndexOf('.'); 125 if( dot >= 0 ) 126 webContext = fileName.substring(0, dot); 127 } 128 } 129 130 public String getAlternativeDD() 131 { 132 return alternativeDD; 133 } 134 public void setAlternativeDD(String dd) 135 { 136 this.alternativeDD = dd; 137 } 138 139 public String getWebContext() 140 { 141 if (type == WEB) 142 { 143 return webContext; 144 } 145 else 146 { 147 return null; 148 } 149 } 150 public void setWebContext(String context) 151 { 152 this.webContext = context; 153 } 154 155 public void importXml(Element rootElement) throws DeploymentException 156 { 157 String rootTag = rootElement.getOwnerDocument().getDocumentElement().getTagName(); 158 if (rootTag.equals("application")) 159 importXml(rootElement, false); 160 else if (rootTag.equals("jboss-app")) 161 importXml(rootElement, true); 162 else 163 throw new DeploymentException("Unrecognized root tag: " + rootTag); 164 } 165 166 protected void importXml(Element element, boolean jbossSpecific) throws DeploymentException 167 { 168 String name = element.getTagName(); 169 if (name.equals("module")) 170 { 171 boolean done = false; for (int i = 0; done == false && i < tags.length; ++i) 173 { 174 Element child = getOptionalChild(element, tags[i]); 175 if (child == null) 176 { 177 continue; 178 } 179 180 type = i; 181 switch (type) 182 { 183 case SERVICE: 184 if (jbossSpecific == false) 185 { 186 throw new DeploymentException("Service archives must be in jboss-app.xml"); 187 } case HAR: 190 if (jbossSpecific == false) 191 { 192 throw new DeploymentException("Hibernate archives must be in jboss-app.xml"); 193 } 194 case EJB: 195 case CLIENT: 196 case CONNECTOR: 197 fileName = getElementContent(child); 198 alternativeDD = getElementContent(getOptionalChild(element, "alt-dd")); 199 break; 200 case WEB: 201 fileName = getElementContent(getUniqueChild(child, "web-uri")); 202 webContext = getElementContent(getOptionalChild(child, "context-root")); 203 alternativeDD = getElementContent(getOptionalChild(element, "alt-dd")); 204 break; 205 } 206 done = true; 207 } 208 209 if (done == false) 211 { 212 StringBuffer msg = new StringBuffer ("Invalid module content, must be one of: "); 213 for (int i = 0; i < tags.length; i ++) 214 { 215 msg.append(tags[i]); 216 msg.append(", "); 217 } 218 throw new DeploymentException(msg.toString()); 219 } 220 } 221 else 222 { 223 throw new DeploymentException("non-module tag in application dd: " + name); 224 } 225 } 226 } 227 | Popular Tags |