1 22 package org.jboss.deployers.plugins.deployers.helpers; 23 24 import java.io.InputStream ; 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.Unmarshaller; 30 import org.jboss.xb.binding.UnmarshallerFactory; 31 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver; 32 import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory; 33 34 41 public abstract class SchemaResolverDeployer<T> extends AbstractParsingDeployer<T> 42 { 43 44 private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); 45 46 47 private static final SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver(); 48 49 55 public SchemaResolverDeployer(Class <T> deploymentType) 56 { 57 super(deploymentType); 58 } 59 60 69 protected T parse(DeploymentUnit unit, VirtualFile file, T root) throws Exception 70 { 71 if (file == null) 72 throw new IllegalArgumentException ("Null file"); 73 74 log.debug("Parsing file: "+file+" for deploymentType: "+getDeploymentType()); 75 Unmarshaller unmarshaller = factory.newUnmarshaller(); 76 InputStream is = file.openStream(); 77 Object parsed = null; 78 try 79 { 80 parsed = unmarshaller.unmarshal(is, resolver); 81 log.debug("Parsed file: "+file+" to: "+parsed); 82 } 83 finally 84 { 85 try 86 { 87 is.close(); 88 } 89 catch (Exception ignored) 90 { 91 } 92 } 93 if (parsed == null) 94 throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!"); 95 96 return getDeploymentType().cast(parsed); 97 } 98 } 99 | Popular Tags |