1 package org.ozoneDB.tools.OPP.srcgen.resolve; 9 10 import org.ozoneDB.tools.OPP.message.MessageWriter; 11 import org.ozoneDB.tools.OPP.OPPHelper; 12 import org.ozoneDB.tools.OPP.OPP; 13 import org.ozoneDB.tools.OPP.srcgen.MethodResolver; 14 import org.ozoneDB.tools.OPP.srcgen.ResolverException; 15 import org.ozoneDB.tools.OPP.srcgen.ClassQuery; 16 import org.ozoneDB.tools.OPP.srcgen.streamfactory.InputStreamFactory; 17 import org.ozoneDB.OzoneRemote; 18 import org.ozoneDB.core.Lock; 19 20 import java.io.*; 21 import java.util.regex.Pattern ; 22 23 31 public class SourceUpdateMethodResolver implements MethodResolver { 32 private MessageWriter genListener; 33 private InputStreamFactory streamFactory; 34 private ClassQuery classQuery; 35 36 public SourceUpdateMethodResolver(InputStreamFactory _streamFactory, MessageWriter _genListener, ClassQuery _classQuery) { 37 streamFactory = _streamFactory; 38 genListener = _genListener; 39 classQuery = _classQuery; 40 } 41 42 46 private void searchUpdateMethods(String cl, MethodResolver.UpdateMethodBag updateMethodsIf) throws IOException, ClassNotFoundException { 47 String dbRemote = OzoneRemote.class.getName(); 48 java.util.Vector stack = new java.util.Vector (); 49 stack.addElement(cl); 50 51 while (!stack.isEmpty()) { 52 String dbInterface = (String ) stack.lastElement(); 53 stack.removeElementAt(stack.size() - 1); 54 genListener.debug("checking: " + dbInterface); 55 56 if (!dbRemote.equals(dbInterface) && classQuery.isAssignable(dbRemote, dbInterface)) { 57 String [] ifs = classQuery.getInterfaces(dbInterface); 58 for (int i = 0; i < ifs.length; i++) { 59 stack.addElement(ifs[i]); 60 } 61 searchUpdateMethods2(dbInterface, updateMethodsIf); 63 } 64 } 66 } 67 68 72 private void searchUpdateMethods2(String dbInterface, MethodResolver.UpdateMethodBag updateMethodsIf) throws IOException { 73 Pattern re = OPPHelper.newRE(OPP.UPDATE_SIGN, true); 75 Pattern mre = OPPHelper.newRE(OPP.METHOD_PATTERN, false); 77 Pattern jre = OPPHelper.newRE(OPP.JAVADOC_PATTERN, false); 79 Pattern docstart = OPPHelper.newRE("/\\*\\*", false); 81 82 83 genListener.debug("reading: " + dbInterface); 84 LineNumberReader reader = new LineNumberReader(new InputStreamReader(streamFactory.newInstance(dbInterface))); 85 86 try { 87 String line = reader.readLine(); 88 89 93 boolean isJavadocUpdate = false; 94 String lastMatchedMethod = null; 95 while (line != null) { 96 boolean isUpdate = OPPHelper.reSearch(re, line, 0, 0) != null; 98 String match = OPPHelper.reSearch(docstart, line, 0, 0); 100 if (match != null) { 101 lastMatchedMethod = null; 102 isJavadocUpdate = false; 103 } 104 match = OPPHelper.reSearch(mre, line, 0, 1); 105 if (match != null) { 106 lastMatchedMethod = match; 107 } 108 match = OPPHelper.reSearch(jre, line, 0, 0); 109 if (match != null) { 110 isJavadocUpdate = true; 111 } 112 if (lastMatchedMethod != null && (isUpdate || isJavadocUpdate)) { 113 String methodName = lastMatchedMethod; 114 genListener.debug("method: " + methodName + " matched per update regexp in interface "); 115 updateMethodsIf.addMethod(methodName, Lock.LEVEL_WRITE); 116 lastMatchedMethod = null; 117 isJavadocUpdate = false; 118 } else if (lastMatchedMethod == null && isUpdate) { 119 genListener.warning(OPPHelper.classFileBasename(dbInterface) + ".java", reader.getLineNumber(), 120 "Unable to determine the method name for the " 121 + " found update definition in line " + reader.getLineNumber() + "."); 122 } else { 123 130 } 131 line = reader.readLine(); 132 } 133 } finally { 134 reader.close(); 135 } 136 } 137 138 public void resolveMethods(String className, MethodResolver.UpdateMethodBag result) throws ResolverException { 139 140 try { 141 searchUpdateMethods(className, result); 142 } catch (IOException e) { 143 throw new ResolverException("Could not resolve update methods (" + className + "). " + e.getMessage(), e); 144 } catch (ClassNotFoundException e) { 145 throw new ResolverException("Could not resolve update methods (" + className + "). " + e.getMessage(), e); 146 } 147 148 } 149 } | Popular Tags |