KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > JtDecorator


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 Decorator pattern.
11  */

12
13 public class JtDecorator extends JtObject {
14
15   private Object JavaDoc component = null;
16  
17
18 /**
19   * Specifies the object that is being decorated (extra functionality added).
20   * @param component component
21   */

22
23   public void setComponent (Object JavaDoc component) {
24      this.component = component;
25   }
26
27
28 /**
29   * Returns the object that is being decorated.
30   */

31
32   public Object JavaDoc getComponent () {
33      return (component);
34   }
35
36   public JtDecorator () {
37   }
38
39
40
41
42   /**
43     * Process object messages.
44     * <ul>
45     * <li>JtREMOVE - Performs any housekeeping that may be needed before the object is removed.
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 (super.processMessage (null));
71      }
72
73
74      handleError ("JtDecortator.processMessage: invalid message id:" + msgid);
75      return (null);
76
77   }
78
79  
80   /**
81    * Unit tests the messages processed by JtDecorator.
82    */

83
84   public static void main(String JavaDoc[] args) {
85
86     JtFactory factory = new JtFactory ();
87
88     JtDecorator decorator;
89  
90     //main.setObjTrace (1);
91
//main.setLogFile ("log.txt");
92

93
94     // Create JtDecorator
95

96     decorator = (JtDecorator) factory.createObject ("Jt.JtDecorator", "decorator");
97
98     System.out.println (decorator);
99
100     factory.removeObject ("decorator");
101
102
103   }
104
105 }
106
107
108
Popular Tags