1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.composite.composites;
17
18 import net.sf.composite.SimpleComposite;
19 import net.sf.composite.SpecializableComposite;
20 import net.sf.composite.specialize.SpecializationException;
21
22 /***
23 * Wraps a SimpleComposite so that it implements the ListableComposite and
24 * SpecializableComposite interfaces.
25 *
26 * @author Matt Sgarlata
27 * @since Dec 27, 2004
28 */
29 public class CompositeDecorator extends BaseComposite implements
30 SpecializableComposite {
31
32
33
34
35
36
37
38
39 private SimpleComposite composite;
40
41 /***
42 * Creates a new composite decorator. To complete initialization of the
43 * decorator, the {@link CompositeDecorator#setComposite(SimpleComposite)}method
44 * must be called
45 */
46 public CompositeDecorator() {
47 super();
48 }
49
50 /***
51 * Creates a new composite that decorates the given composite.
52 *
53 * @param composite
54 * the composite to be decorated.
55 */
56 public CompositeDecorator(SimpleComposite composite) {
57 this();
58 setComposite(composite);
59 }
60
61
62 public boolean isSpecializable(Class type) throws SpecializationException {
63 return getSpecializer().isSpecializable(getComposite(), type);
64 }
65 public Object specialize(Class type) throws SpecializationException {
66 return getSpecializer().specialize(getComposite(), type);
67 }
68
69 public SimpleComposite getComposite() {
70 return composite;
71 }
72 public void setComposite(SimpleComposite composite) {
73 this.composite = composite;
74 }
75
76 /***
77 * Retrieves the components of the underlying composite.
78 *
79 * @return the components of the underlying composite
80 */
81 public Object[] getComponents() {
82 return getComposite().getComponents();
83 }
84
85 /***
86 * Sets the components of the underlying compmosite
87 *
88 * @param components
89 * the new components that will make up the underlying composite
90 */
91 public void setComponents(Object[] components) {
92 getComposite().setComponents(components);
93 }
94
95 }