1 22 package org.jboss.deployers.plugins.deployers.helpers; 23 24 import java.util.List ; 25 26 import org.jboss.deployers.spi.DeploymentException; 27 import org.jboss.deployers.spi.deployer.DeploymentUnit; 28 import org.jboss.virtual.VirtualFile; 29 30 39 public abstract class AbstractParsingDeployer<T> extends AbstractTypedDeployer<T> 40 { 41 48 protected AbstractParsingDeployer(Class <T> deploymentType) 49 { 50 super(deploymentType); 51 setRelativeOrder(PARSER_DEPLOYER); 53 } 54 55 61 protected boolean allowsReparse() 62 { 63 return false; 64 } 65 66 73 protected T getMetaData(DeploymentUnit unit, String key) 74 { 75 return unit.getAttachment(key, getDeploymentType()); 76 } 77 78 86 protected void createMetaData(DeploymentUnit unit, String name, String suffix) throws DeploymentException 87 { 88 createMetaData(unit, name, suffix, getDeploymentType().getName()); 89 } 90 91 101 protected void createMetaData(DeploymentUnit unit, String name, String suffix, String key) throws DeploymentException 102 { 103 T result = getMetaData(unit, key); 105 if (result != null && allowsReparse() == false) 106 return; 107 108 try 110 { 111 if (suffix == null) 112 result = parse(unit, name, result); 113 else 114 result = parse(unit, name, suffix, result); 115 } 116 catch (Exception e) 117 { 118 throw DeploymentException.rethrowAsDeploymentException("Error creating managed object for " + unit.getName(), e); 119 } 120 121 if (result == null) 123 return; 124 125 unit.getTransientManagedObjects().addAttachment(key, result, getDeploymentType()); 127 } 128 129 138 protected T parse(DeploymentUnit unit, String name, T root) throws Exception 139 { 140 VirtualFile file = unit.getMetaDataFile(name); 142 if (file == null) 143 return null; 144 145 T result = parse(unit, file, root); 146 init(unit, result, file); 147 return result; 148 } 149 150 160 protected T parse(DeploymentUnit unit, String name, String suffix, T root) throws Exception 161 { 162 List <VirtualFile> files = unit.getMetaDataFiles(name, suffix); 164 if (files.size() == 0) 165 return null; 166 167 if (files.size() > 1) 169 throw new DeploymentException("Only one file is allowed, found=" + files); 170 171 VirtualFile file = files.get(0); 172 173 T result = parse(unit, file, root); 174 init(unit, result, file); 175 return result; 176 } 177 178 187 protected abstract T parse(DeploymentUnit unit, VirtualFile file, T root) throws Exception ; 188 189 197 protected void init(DeploymentUnit unit, T metaData, VirtualFile file) throws Exception 198 { 199 } 200 } | Popular Tags |