1 18 19 package org.objectweb.jac.core; 20 21 import java.io.BufferedInputStream ; 22 import java.io.FileInputStream ; 23 import java.io.FileNotFoundException ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 import java.util.List ; 29 import java.util.Set ; 30 import java.util.Vector ; 31 import org.apache.log4j.Logger; 32 33 38 39 public class ParserImpl implements Parser 40 { 41 static Logger logger = Logger.getLogger("parser"); 42 43 public List parse(String filePath, String targetClass, 44 Set blockKeywords) throws IOException 45 { 46 InputStream inputStream = null; 47 try { 48 logger.debug("FileInputStream("+filePath+")"); 49 inputStream = new FileInputStream (filePath); 50 } catch (FileNotFoundException e) { 51 try { 52 logger.debug("getResourceAsStream("+filePath+")"); 53 inputStream = 54 getClass().getClassLoader().getResourceAsStream(filePath); 55 if (inputStream==null) { 56 logger.warn("Resource "+filePath+" not found"); 57 } 58 } catch (Exception e2) { 59 logger.debug("caught exception "+e2); 60 logger.debug("new URL("+filePath+")"); 62 try { 63 URL url = new URL (filePath); 64 inputStream = url.openStream(); 65 } catch (MalformedURLException e3) { 66 e3.printStackTrace(); 67 return null; 68 } 69 } 70 } 71 if (inputStream!=null) { 72 return parse(new BufferedInputStream (inputStream), 73 filePath,targetClass,blockKeywords); 74 } else { 75 return new Vector (); 76 } 77 } 78 79 public List parse(InputStream inputStream, String filePath, 80 String targetClass, Set blockKeywords) { 81 List methods = null; 82 if (filePath.endsWith(".xml")) { 83 try { 84 InputStreamParser parser = 85 (InputStreamParser)(Class.forName( 86 "org.objectweb.jac.core.parsers.xml.JacXmlParser").newInstance()); 87 methods = parser.parse(inputStream, filePath, 88 targetClass, blockKeywords); 89 } catch (Exception e) { 90 logger.error("Exception during xml parsing",e); 91 } 92 } else if (filePath.endsWith(".acc")) { 93 try { 94 InputStreamParser parser = 95 (InputStreamParser)(Class.forName( 96 "org.objectweb.jac.core.parsers.acc.AccParserWrapper").newInstance()); 97 methods = parser.parse(inputStream, filePath, 98 targetClass, blockKeywords); 99 } catch (Exception e) { 100 logger.error("Exception during acc parsing",e); 101 } 102 } else { 103 logger.warn("No parser found for "+filePath); 104 methods = new Vector (); 105 } 106 return methods; 107 } 108 } 109 | Popular Tags |