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;
17  
18  import net.sf.composite.specialize.SpecializationException;
19  
20  /***
21   * A composite that may be exposable as types in addition to those explicitly
22   * specified in the class declaration. For example, if some subset of the
23   * components of a composite all implement some interface that is not
24   * implemented by the composite itself, a new composite can be created that
25   * implements this interface that all the components implement. All that is
26   * needed is a method of choosing which component should perform the requested
27   * operation. This method of choosing is not specified by this interface;
28   * rather, this interface simply indicates that this composite may expose
29   * additional interfaces if those interfaces are implemented by some subset of
30   * the components of this composite.
31   * 
32   * @author Matt Sgarlata
33   * @since Dec 27, 2004
34   */
35  public interface SpecializableComposite extends Composite {
36  
37  	/***
38  	 * Uses the components in this composite to dynamically create a composite
39  	 * that implements <code>type</code>.
40  	 * 
41  	 * @param type
42  	 *            the interface to be exposed
43  	 * @return the new composite that implements the requested interface
44  	 * @throws SpecializationException
45  	 *             if an error occurs while creating the new, specialized,
46  	 *             composite that implements the requested interface
47  	 */
48  	public Object specialize(Class type) throws SpecializationException;
49  
50  	/***
51  	 * Indicates whether this composite can expose the given interface by
52  	 * dynamically creating a new composite.
53  	 * 
54  	 * @param type
55  	 *            the interface to be exposed
56  	 * @return whether this composite can expose the given interface by
57  	 *         dynamically creating a new composite
58  	 * @throws SpecializationException
59  	 *             if an error occurrs
60  	 */
61  	public boolean isSpecializable(Class type) throws SpecializationException;
62  
63  }