1 22 package org.jboss.deployers.plugins.deployers.helpers; 23 24 import java.net.URL ; 25 26 import org.jboss.deployers.spi.DeploymentException; 27 import org.jboss.deployers.spi.deployer.DeploymentUnit; 28 import org.jboss.virtual.VirtualFile; 29 import org.jboss.xb.binding.ObjectModelFactory; 30 import org.jboss.xb.binding.Unmarshaller; 31 import org.jboss.xb.binding.UnmarshallerFactory; 32 33 44 public abstract class ObjectModelFactoryDeployer<T> extends AbstractParsingDeployer<T> 45 { 46 47 private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); 48 49 55 public ObjectModelFactoryDeployer(Class <T> deploymentType) 56 { 57 super(deploymentType); 58 } 59 60 72 protected T parse(DeploymentUnit unit, VirtualFile file, T root) throws Exception 73 { 74 if (file == null) 75 throw new IllegalArgumentException ("Null file"); 76 77 Unmarshaller unmarshaller = factory.newUnmarshaller(); 78 Object parsed = null; 79 try 80 { 81 ObjectModelFactory factory = getObjectModelFactory(root); 82 URL url = file.toURL(); 83 parsed = unmarshaller.unmarshal(url.toString(), factory, root); 84 } 85 catch (Throwable t) 86 { 87 DeploymentException.rethrowAsDeploymentException("Error parsing meta data " + file.getPathName(), t); 88 } 89 if (parsed == null) 90 throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!"); 91 92 return getDeploymentType().cast(parsed); 93 } 94 95 101 protected abstract ObjectModelFactory getObjectModelFactory(T root); 102 } 103 | Popular Tags |