View Javadoc

1   /*
2    * Copyright 2004-2005 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
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  //	protected InvocationHandler createInvocationHandler()
33  //		throws Exception {
34  //		// FIXME exception handling, documentation of newInstance call and
35  //		// needed no-arg constructor
36  //		return new DelegatingInvocationHandler(getComposite().getClass().newInstance());
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  }