1 26 27 package org.objectweb.jonas_ws.deployment.lib; 28 29 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.io.InputStreamReader ; 34 import java.io.Reader ; 35 import java.util.jar.JarFile ; 36 37 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 38 import org.objectweb.jonas_lib.deployment.digester.JDigester; 39 40 import org.objectweb.jonas_ws.deployment.api.MappingFile; 41 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException; 42 import org.objectweb.jonas_ws.deployment.rules.JavaWsdlMappingRuleSet; 43 import org.objectweb.jonas_ws.deployment.xml.JavaWsdlMapping; 44 45 import org.objectweb.jonas.common.Log; 46 47 import org.objectweb.util.monolog.api.BasicLevel; 48 import org.objectweb.util.monolog.api.Logger; 49 50 51 62 public class MappingFileManager { 63 64 67 private static JDigester mfDigester = null; 68 69 72 private static JavaWsdlMappingRuleSet mfRuleSet = new JavaWsdlMappingRuleSet(); 73 74 77 private static boolean parsingWithValidation = true; 78 79 82 private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX); 83 84 87 private MappingFileManager() { } 88 89 99 public static MappingFile getInstance(File module, String filename) 100 throws WSDeploymentDescException { 101 InputStream is = openStream(module, filename); 102 return new MappingFile(loadMappingFile(new InputStreamReader (is), filename)); 103 } 104 105 116 public static MappingFile getInstance(Reader r, String filename, boolean validate) 117 throws WSDeploymentDescException { 118 parsingWithValidation = validate; 119 return new MappingFile(loadMappingFile(r, filename)); 120 } 121 131 public static MappingFile getInstance(InputStream is, String filename) 132 throws WSDeploymentDescException { 133 return new MappingFile(loadMappingFile(new InputStreamReader (is), filename)); 134 } 135 136 137 147 private static InputStream openStream(File module, String filename) 148 throws WSDeploymentDescException { 149 150 InputStream isMapping = null; 151 152 if (module.exists()) { 154 if (module.isFile()) { 156 JarFile jf = null; 157 158 try { 160 jf = new JarFile (module.getAbsolutePath()); 161 isMapping = jf.getInputStream(jf.getEntry(filename)); 162 } catch (Exception e) { 163 if (jf != null) { 164 try { 165 jf.close(); 166 } catch (IOException i) { 167 logger.log(BasicLevel.WARN, "Can't close '" + module + "'"); 168 } 169 } 170 171 throw new WSDeploymentDescException("Cannot read the jaxrpc-mapping-file " 172 + filename + " in " + module.getAbsolutePath(), 173 e); 174 } 175 } else { 176 try { 178 isMapping = 179 new FileInputStream (new File (module, filename)); 180 } catch (IOException ioe) { 181 throw new WSDeploymentDescException("Cannot read the jaxrpc-mapping-file " 182 + filename + " in " + module.getAbsolutePath(), 183 ioe); 184 } 185 } 186 187 } else { 188 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 190 isMapping = loader.getResourceAsStream(filename); 191 } 192 193 return isMapping; 194 } 195 196 206 private static JavaWsdlMapping loadMappingFile(Reader reader, String fileName) 207 throws WSDeploymentDescException { 208 209 JavaWsdlMapping jwm = new JavaWsdlMapping(); 210 211 if (mfDigester == null) { 213 try { 214 mfDigester = new JDigester(mfRuleSet, 216 parsingWithValidation, 217 true, 218 null, 219 new JaxrpcMappingSchemas()); 220 } catch (DeploymentDescException e) { 221 throw new WSDeploymentDescException(e); 222 } 223 } 224 225 try { 226 mfDigester.parse(reader, fileName, jwm); 227 } catch (DeploymentDescException e) { 228 throw new WSDeploymentDescException(e); 229 } finally { 230 mfDigester.push(null); 231 } 232 233 return jwm; 234 } 235 236 239 public static boolean isParsingWithValidation() { 240 return parsingWithValidation; 241 } 242 243 246 public static void setParsingWithValidation(boolean parsingWithValidation) { 247 MappingFileManager.parsingWithValidation = parsingWithValidation; 248 } 249 } 250 | Popular Tags |