KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtBuilder


1
2
3 package Jt;
4 import java.util.*;
5 import java.lang.reflect.*;
6 import java.beans.*;
7 import java.io.*;
8
9 /**
10  * Jt Implementation of the Builder pattern.
11  */

12
13 public class JtBuilder extends JtObject {
14
15   private Object JavaDoc builder;
16
17   public JtBuilder () {
18   }
19
20 /**
21   * Specifies the builder.
22   *
23   * @param builder builder
24   */

25
26   public void setBuilder (Object JavaDoc builder) {
27      this.builder = builder;
28
29   }
30
31 /**
32   * Returns the builder.
33   */

34
35   public Object JavaDoc getBuilder () {
36      return (builder);
37   }
38
39
40
41   /**
42     * Process object messages by forwarding them to an object (builder) that
43     * takes care of the building functionality. Different representations
44     * can be created.
45     * <ul>
46     * </ul>
47     */

48
49   public Object JavaDoc processMessage (Object JavaDoc event) {
50
51    String JavaDoc msgid = null;
52    JtMessage e = (JtMessage) event;
53    Object JavaDoc content;
54    Object JavaDoc data;
55
56
57      if (e == null)
58     return null;
59
60      msgid = (String JavaDoc) e.getMsgId ();
61
62      if (msgid == null)
63     return null;
64
65      content = e.getMsgContent();
66      //data = e.getMsgData ();
67

68
69      if (msgid.equals ("JtREMOVE")) {
70        return (this);
71      }
72
73      if (builder == null) {
74        handleError ("JtBuilder.process: the builder attribute needs to be set");
75        return (null);
76      }
77
78      // Let the builder process the request
79

80      return (sendMessage (builder, event));
81
82
83   }
84
85  
86   /**
87    * Unit tests the messages processed by JtBuilder.
88    */

89
90
91   public static void main(String JavaDoc[] args) {
92
93     JtFactory factory = new JtFactory ();
94     JtBuilder builder;
95
96
97     // Create an instance of JtBuilder
98

99     builder = (JtBuilder) factory.createObject ("Jt.JtBuilder", "builder");
100
101     // Remove the object
102

103     factory.removeObject ("builder");
104
105
106   }
107
108
109 }
110
111
112
Popular Tags