1 22 package org.jboss.ejb3.deployers; 23 24 import java.io.IOException ; 25 26 import org.jboss.deployers.plugins.deployers.helpers.ObjectModelFactoryDeployer; 27 import org.jboss.deployers.spi.DeploymentException; 28 import org.jboss.deployers.spi.deployer.DeploymentUnit; 29 import org.jboss.ejb3.metamodel.ApplicationClientDD; 30 import org.jboss.ejb3.metamodel.JBossClientDDObjectFactory; 31 import org.jboss.util.xml.DOMUtils; 32 import org.jboss.virtual.VirtualFile; 33 import org.jboss.xb.binding.ObjectModelFactory; 34 import org.w3c.dom.DocumentType ; 35 import org.w3c.dom.Element ; 36 37 43 public class JBossClientParsingDeployer extends ObjectModelFactoryDeployer<ApplicationClientDD> 44 { 45 private String jbossClientXmlPath = "jboss-client.xml"; 46 47 51 public JBossClientParsingDeployer() 52 { 53 super(ApplicationClientDD.class); 54 setRelativeOrder(PARSER_DEPLOYER + 1); 55 } 56 57 @Override 58 protected boolean allowsReparse() 59 { 60 return true; 61 } 62 63 @Override 64 protected ObjectModelFactory getObjectModelFactory(ApplicationClientDD root) 65 { 66 return new JBossClientDDObjectFactory(root); 67 } 68 69 @Override 70 public void deploy(DeploymentUnit unit) throws DeploymentException 71 { 72 if (accepts(unit)) 73 createMetaData(unit, jbossClientXmlPath, null); 74 } 75 76 80 private boolean accepts(DeploymentUnit unit) throws DeploymentException 81 { 82 boolean accepts = false; 83 84 VirtualFile dd = unit.getMetaDataFile(jbossClientXmlPath); 86 if (dd != null) 87 { 88 log.debug("Found application-client.xml file: " + unit.getName()); 89 try 90 { 91 Element root = DOMUtils.parse(dd.openStream()); 92 DocumentType doctype = root.getOwnerDocument().getDoctype(); 93 String publicId = (doctype != null ? doctype.getPublicId() : null); 94 accepts = "-//JBoss//DTD Application Client 5.0//EN".equals(publicId); 96 if (accepts == false) 97 log.debug("Ignore jboss-client.xml with publicId: " + publicId); 98 } 99 catch (IOException ex) 100 { 101 DeploymentException.rethrowAsDeploymentException("Cannot parse " + jbossClientXmlPath, ex); 102 } 103 } 104 105 return accepts; 106 } 107 } 108 | Popular Tags |