KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > OPP > srcgen > builder > MethodNameUpgradingClassBuilderDecorator


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8
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 JavaDoc;
16 import java.util.regex.Matcher JavaDoc;
17
18 /**
19  * User: Jocke
20  * Date: 2004-jan-04
21  * Time: 14:21:57
22  */

23 public class MethodNameUpgradingClassBuilderDecorator implements ClassBuilder {
24     private ClassBuilder classBuilder;
25     private MessageWriter msgWriter;
26     private Pattern JavaDoc updateMethodPattern;
27
28     public MethodNameUpgradingClassBuilderDecorator(ClassBuilder classBuilder, String JavaDoc 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 JavaDoc fullName, String JavaDoc superClass, String JavaDoc interfaces[]) throws BuilderException {
39         classBuilder.beginClass(modifier, fullName, superClass, interfaces);
40     }
41
42     public void makeConstructor(int modifier, ClassBuilder.Parameter parameters[], String JavaDoc exceptions[]) throws BuilderException {
43         classBuilder.makeConstructor(modifier, parameters, exceptions);
44     }
45
46     public void makeMethod(int modifier, String JavaDoc name, ClassBuilder.Parameter parameters[], String JavaDoc returnType, String JavaDoc exceptions[], int lockLevel) throws BuilderException {
47         Matcher JavaDoc 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