1 22 package org.jboss.metadata.web; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.net.URL ; 27 28 import org.jboss.logging.Logger; 29 import org.jboss.metadata.DDObjectFactory; 30 import org.jboss.metadata.EjbLocalRefMetaData; 31 import org.jboss.metadata.EjbRefMetaData; 32 import org.jboss.metadata.EnvEntryMetaData; 33 import org.jboss.metadata.MessageDestinationMetaData; 34 import org.jboss.metadata.MessageDestinationRefMetaData; 35 import org.jboss.metadata.ResourceEnvRefMetaData; 36 import org.jboss.metadata.ResourceRefMetaData; 37 import org.jboss.metadata.SecurityRoleMetaData; 38 import org.jboss.metadata.WebMetaData; 39 import org.jboss.util.xml.JBossEntityResolver; 40 import org.jboss.xb.binding.JBossXBException; 41 import org.jboss.xb.binding.ObjectModelFactory; 42 import org.jboss.xb.binding.Unmarshaller; 43 import org.jboss.xb.binding.UnmarshallerFactory; 44 import org.jboss.xb.binding.UnmarshallingContext; 45 import org.xml.sax.Attributes ; 46 47 public class JBossWebMetaDataObjectFactory extends DDObjectFactory 48 { 49 private static Logger log = Logger.getLogger(JBossWebMetaDataObjectFactory.class); 50 51 private static final ThreadLocal <WebMetaData> activeMetaData = new ThreadLocal <WebMetaData>(); 52 private WebMetaData metaData; 53 54 public static WebMetaData parse(URL ddResource, WebMetaData dd) 55 throws JBossXBException, IOException 56 { 57 if (ddResource == null) return null; 58 log.debug("found jboss-web.xml " + ddResource); 59 60 InputStream is = ddResource.openStream(); 61 62 return parse(dd, is); 63 } 64 65 public static WebMetaData parse(WebMetaData metaData, InputStream is) 66 throws JBossXBException 67 { 68 ObjectModelFactory factory = null; 69 Unmarshaller unmarshaller = null; 70 71 if (metaData == null) 72 metaData = new WebMetaData(); 73 74 activeMetaData.set(metaData); 75 factory = new JBossWebMetaDataObjectFactory(metaData); 76 UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance(); 77 unmarshaller = unmarshallerFactory.newUnmarshaller(); 79 JBossEntityResolver entityResolver = new JBossEntityResolver(); 80 unmarshaller.setEntityResolver(entityResolver); 81 82 metaData = (WebMetaData) unmarshaller.unmarshal(is, factory, null); 83 return metaData; 84 } 85 86 public JBossWebMetaDataObjectFactory(WebMetaData dd) 87 { 88 super(); 89 this.metaData = dd; 90 } 91 92 95 public Object newRoot(Object root, UnmarshallingContext navigator, 96 String namespaceURI, String localName, Attributes attrs) 97 { 98 if( root == null && metaData == null ) 100 throw new IllegalStateException ("No existing WebMetaData, check the JBossWebAppParsingDeployer order"); 101 102 return root == null ? metaData : root; 103 } 104 105 public Object completeRoot(Object root, UnmarshallingContext ctx, 106 String uri, String name) 107 { 108 return root; 109 } 110 111 113 116 public Object newChild(WebMetaData dd, UnmarshallingContext navigator, 117 String namespaceURI, String localName, Attributes attrs) 118 { 119 Object child = null; 120 log.debug("newChild, "+localName); 121 if ((child = newEnvRefGroupChild(localName)) != null) 122 return child; 123 else if (localName.equals("security-role")) 124 child = new SecurityRoleMetaData(); 125 else if (localName.equals("servlet")) 126 child = new Servlet(); 127 else if (localName.equals("replication-config")) 128 child = new ReplicationConfig(); 129 else if (localName.equals("passivation-config")) 130 child = new PassivationConfig(); 131 else if (localName.equals("message-destination")) 132 { 133 child = new MessageDestinationMetaData(); 134 } 135 return child; 136 } 137 138 public void addChild(WebMetaData parent, ReplicationConfig config, 139 UnmarshallingContext navigator, String namespaceURI, String localName) 140 { 141 parent.setReplicationConfig(config); 142 } 143 144 public void addChild(WebMetaData parent, PassivationConfig config, 145 UnmarshallingContext navigator, String namespaceURI, String localName) 146 { 147 parent.setPassivationConfig(config); 148 } 149 150 public void addChild(WebMetaData parent, EjbLocalRefMetaData ref, 151 UnmarshallingContext navigator, String namespaceURI, String localName) 152 { 153 parent.addEjbLocalRef(ref); 154 } 155 156 public void addChild(WebMetaData parent, EjbRefMetaData ref, 157 UnmarshallingContext navigator, String namespaceURI, String localName) 158 { 159 parent.addEjbRef(ref); 160 } 161 162 public void addChild(WebMetaData parent, EnvEntryMetaData ref, 163 UnmarshallingContext navigator, String namespaceURI, String localName) 164 { 165 parent.addEnvEntry(ref); 166 } 167 168 public void addChild(WebMetaData parent, MessageDestinationMetaData destination, 169 UnmarshallingContext navigator, String namespaceURI, String localName) 170 { 171 log.debug("addMessageDestinationMetaData, "+destination); 172 parent.addMessageDestination(destination); 173 String link = destination.getJNDIName(); 175 if( link != null ) 176 { 177 MessageDestinationMetaData ref = parent.getMessageDestination(link); 178 if( ref != null ) 179 { 180 log.debug("ressolved "+ref+" to link JndiName: "+destination.getJNDIName()); 181 ref.setJNDIName(destination.getJNDIName()); 182 } 183 } 184 } 185 public void addChild(WebMetaData parent, MessageDestinationRefMetaData ref, 186 UnmarshallingContext navigator, String namespaceURI, String localName) 187 { 188 log.debug("addMessageDestinationMetaDataRef, "+ref); 189 parent.addMessageDestinationRef(ref); 190 } 191 192 public void addChild(WebMetaData parent, ResourceEnvRefMetaData ref, 193 UnmarshallingContext navigator, String namespaceURI, String localName) 194 { 195 parent.updateResourceEnvRef(ref); 197 } 198 199 public void addChild(WebMetaData parent, ResourceRefMetaData ref, 200 UnmarshallingContext navigator, String namespaceURI, String localName) 201 { 202 parent.updateResourceRef(ref); 204 } 205 206 public void addChild(WebMetaData parent, SecurityRoleMetaData role, 207 UnmarshallingContext navigator, String namespaceURI, String localName) 208 { 209 parent.addSecurityRole(role); 210 } 211 212 public void addChild(WebMetaData parent, Servlet servlet, 213 UnmarshallingContext navigator, String namespaceURI, String localName) 214 { 215 parent.updateServlet(servlet); 216 } 217 218 public void setValue(WebMetaData dd, 219 UnmarshallingContext navigator, String namespaceURI, String localName, 220 String value) 221 { 222 if (localName.equals("depends")) 223 { 224 dd.addDependency(value); 225 } 226 else if (localName.equals("context-root")) 227 { 228 dd.setContextRoot(value); 229 } 230 else if (localName.equals("security-domain")) 231 { 232 dd.setSecurityDomain(value); 233 } 234 } 235 236 public void setValue(ReplicationConfig config, 237 UnmarshallingContext navigator, String namespaceURI, String localName, 238 String value) 239 { 240 if (localName.equals("replication-trigger")) 241 { 242 config.setTrigger(value); 243 } 244 else if (localName.equals("replication-granularity")) 245 { 246 config.setGranularity(value); 247 } 248 else if (localName.equals("replication-field-batch-mode")) 249 { 250 config.setFieldBatchMode(value); 251 } 252 } 253 254 public void setValue(PassivationConfig config, 255 UnmarshallingContext navigator, String namespaceURI, String localName, 256 String value) 257 { 258 if (localName.equals("use-session-passivation")) 259 { 260 config.setUseSessionPassivation(value); 261 } 262 else if (localName.equals("passivation-min-idle-time")) 263 { 264 config.setPassivationMinIdleTime(value); 265 } 266 else if (localName.equals("passivation-max-idle-time")) 267 { 268 config.setPassivationMaxIdleTime(value); 269 } 270 } 271 272 public void setValue(Servlet servlet, 273 UnmarshallingContext navigator, String namespaceURI, String localName, 274 String value) 275 { 276 if (localName.equals("servlet-name")) 277 { 278 servlet.setName(value); 279 } 280 else if (localName.equals("run-as-principal")) 281 { 282 servlet.addRunAsPrincipal(value); 283 } 284 } 285 286 public void setValue(ServletMapping mapping, 287 UnmarshallingContext navigator, String namespaceURI, String localName, 288 String value) 289 { 290 if (localName.equals("servlet-name")) 291 { 292 mapping.setName(value); 293 } 294 else if (localName.equals("url-pattern")) 295 { 296 mapping.setUrlPattern(value); 297 } 298 } 299 300 public void setValue(SecurityRoleMetaData role, 301 UnmarshallingContext navigator, String namespaceURI, String localName, 302 String value) 303 { 304 if (localName.equals("principal-name")) 305 { 306 role.setRoleName(value); 307 } 308 else 309 super.setValue(role, navigator, namespaceURI, localName, value); 310 } 311 312 } 313 | Popular Tags |