1 package org.ozoneDB.tools.OPP.srcgen.builder; 9 10 import org.ozoneDB.tools.OPP.srcgen.ClassBuilder; 11 import org.ozoneDB.tools.OPP.srcgen.BuilderException; 12 import org.ozoneDB.tools.OPP.message.MessageWriter; 13 import org.ozoneDB.core.Lock; 14 15 import java.util.regex.Pattern ; 16 import java.util.regex.Matcher ; 17 18 23 public class MethodNameUpgradingClassBuilderDecorator implements ClassBuilder { 24 private ClassBuilder classBuilder; 25 private MessageWriter msgWriter; 26 private Pattern updateMethodPattern; 27 28 public MethodNameUpgradingClassBuilderDecorator(ClassBuilder classBuilder, String updateMethodExpression) { 29 this.classBuilder = classBuilder; 30 this.updateMethodPattern = Pattern.compile(updateMethodExpression); 31 } 32 33 public void init(MessageWriter msgWriter) { 34 this.msgWriter = msgWriter; 35 classBuilder.init(msgWriter); 36 } 37 38 public void beginClass(int modifier, String fullName, String superClass, String interfaces[]) throws BuilderException { 39 classBuilder.beginClass(modifier, fullName, superClass, interfaces); 40 } 41 42 public void makeConstructor(int modifier, ClassBuilder.Parameter parameters[], String exceptions[]) throws BuilderException { 43 classBuilder.makeConstructor(modifier, parameters, exceptions); 44 } 45 46 public void makeMethod(int modifier, String name, ClassBuilder.Parameter parameters[], String returnType, String exceptions[], int lockLevel) throws BuilderException { 47 Matcher matcher = updateMethodPattern.matcher(name); 48 if (matcher.matches()) { 49 msgWriter.debug("method: " + name + " matches expression \"" + updateMethodPattern.pattern() + "\""); 50 if (lockLevel < Lock.LEVEL_WRITE) { 51 msgWriter.info("Upgrading method: " + name + " to lock level WRITE"); 52 lockLevel = Lock.LEVEL_WRITE; 53 } else { 54 msgWriter.info("method: " + name + " is already defined as an update method, doing nothing!"); 55 } 56 } 57 classBuilder.makeMethod(modifier, name, parameters, returnType, exceptions, lockLevel); 58 } 59 60 public void endClass() throws BuilderException { 61 classBuilder.endClass(); 62 } 63 } 64 | Popular Tags |