1 22 package org.jboss.system.metadata; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.jboss.deployment.DeploymentException; 28 import org.jboss.logging.Logger; 29 import org.jboss.mx.loading.LoaderRepositoryFactory; 30 import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig; 31 import org.jboss.util.StringPropertyReplacer; 32 import org.w3c.dom.Document ; 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.Node ; 35 import org.w3c.dom.NodeList ; 36 37 42 public class ServiceDeploymentParser 43 { 44 45 private static final Logger log = Logger.getLogger(ServiceDeploymentParser.class); 46 47 48 private Document document; 49 50 55 public ServiceDeploymentParser(Document document) 56 { 57 if (document == null) 58 throw new IllegalArgumentException ("Null document"); 59 60 this.document = document; 61 } 62 63 69 public ServiceDeployment parse() throws DeploymentException 70 { 71 ServiceDeployment parsed = new ServiceDeployment(); 72 73 List <ServiceDeploymentClassPath> classPaths = parseXMLClasspath(document); 74 parsed.setClassPaths(classPaths); 75 76 LoaderRepositoryConfig repository = parseLoaderRepositoryConfig(document); 77 if (repository != null) 78 parsed.setLoaderRepositoryConfig(repository); 79 80 parsed.setConfig(document.getDocumentElement()); 82 return parsed; 83 } 84 85 92 private List <ServiceDeploymentClassPath> parseXMLClasspath(Document document) throws DeploymentException 93 { 94 ArrayList <ServiceDeploymentClassPath> classPaths = null; 95 96 NodeList children = document.getDocumentElement().getChildNodes(); 97 for (int i = 0; i < children.getLength(); ++i) 98 { 99 if (children.item(i).getNodeType() == Node.ELEMENT_NODE) 100 { 101 Element classpathElement = (Element )children.item(i); 102 if (classpathElement.getTagName().equals("classpath")) 103 { 104 log.debug("Found classpath element: " + classpathElement); 105 if (classpathElement.hasAttribute("codebase") == false) 106 throw new DeploymentException("Invalid classpath element missing codebase: " + classpathElement); 107 108 String codebase = classpathElement.getAttribute("codebase").trim(); 109 codebase = StringPropertyReplacer.replaceProperties(codebase); 110 111 String archives = null; 112 if (classpathElement.hasAttribute("archives")) 113 { 114 archives = classpathElement.getAttribute("archives").trim(); 115 archives = StringPropertyReplacer.replaceProperties(archives); 116 if ("".equals(archives)) 117 archives = null; 118 } 119 120 if (classPaths == null) 121 classPaths = new ArrayList <ServiceDeploymentClassPath>(); 122 123 ServiceDeploymentClassPath classPath = new ServiceDeploymentClassPath(codebase, archives); 124 classPaths.add(classPath); 125 } 126 } 127 } 128 return classPaths; 129 } 130 131 138 private LoaderRepositoryConfig parseLoaderRepositoryConfig(Document document) throws DeploymentException 139 { 140 NodeList loaders = document.getElementsByTagName("loader-repository"); 142 if( loaders.getLength() > 0 ) 143 { 144 Element loader = (Element ) loaders.item(0); 145 try 146 { 147 return LoaderRepositoryFactory.parseRepositoryConfig(loader); 148 } 149 catch (Exception e) 150 { 151 throw DeploymentException.rethrowAsDeploymentException("Unable to parse loader repository config", e); 152 } 153 } 154 return null; 155 } 156 } 157 | Popular Tags |