KickJava   Java API By Example, From Geeks To Geeks.

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


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.tools.OPP.message.ForkMessageWriter;
14
15 import java.util.Set JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 /**
20  * The composite builder allows building multiple structures in parallel from a single
21  * source of direction.
22  * @author Joakim Ohlrogge
23  */

24 public class CompositeBuilder implements ClassBuilder {
25     private Set JavaDoc builders;
26
27     public void init(MessageWriter msgWriter) {
28         // initialized all sub builders with a fork msg writer.
29
// The Fork writer makes sure all messages are grouped by sub builder.
30
for (Iterator JavaDoc iter = builders.iterator(); iter.hasNext();) {
31             ((ClassBuilder) iter.next()).init(new ForkMessageWriter(msgWriter));
32         }
33     }
34
35     public void beginClass(int modifier, String JavaDoc fullName, String JavaDoc superClass, String JavaDoc interfaces[]) throws BuilderException {
36         for (Iterator JavaDoc iter = builders.iterator(); iter.hasNext();) {
37             ((ClassBuilder) iter.next()).beginClass(modifier, fullName, superClass, interfaces);
38         }
39     }
40
41     public void makeConstructor(int modifier, ClassBuilder.Parameter parameters[], String JavaDoc exceptions[]) throws BuilderException {
42         for (Iterator JavaDoc iter = builders.iterator(); iter.hasNext();) {
43             ((ClassBuilder) iter.next()).makeConstructor(modifier, parameters, exceptions);
44         }
45     }
46
47     public void makeMethod(int modifier, String JavaDoc name, ClassBuilder.Parameter parameters[], String JavaDoc returnType, String JavaDoc exceptions[], int lockLevel) throws BuilderException {
48         for (Iterator JavaDoc iter = builders.iterator(); iter.hasNext();) {
49             ((ClassBuilder) iter.next()).makeMethod(modifier, name, parameters, returnType, exceptions, lockLevel);
50         }
51     }
52
53     public void endClass() throws BuilderException {
54         for (Iterator JavaDoc iter = builders.iterator(); iter.hasNext();) {
55             ((ClassBuilder) iter.next()).endClass();
56         }
57     }
58
59     public CompositeBuilder() {
60         this.builders = new HashSet JavaDoc();
61     }
62
63     /**
64      * Adds a builder to the composition
65      * @param builder The builder to add
66      */

67     public void addBuilder(ClassBuilder builder) {
68         builders.add(builder);
69     }
70
71     /**
72      * Removes a builder from the composition
73      * @param builder
74      */

75     public void removeBuilder(ClassBuilder builder) {
76         builders.remove(builder);
77     }
78 }
79
Popular Tags