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.morph.reflect.reflectors;
17  
18  import net.sf.composite.Defaults;
19  import net.sf.composite.specialize.SpecializationException;
20  import net.sf.composite.specialize.Specializer;
21  import net.sf.composite.specialize.specializers.CachingSpecializerProxy;
22  import net.sf.composite.specialize.specializers.CloningSpecializer;
23  import net.sf.composite.util.CompositeUtils;
24  import net.sf.composite.validate.ComponentValidator;
25  import net.sf.morph.reflect.Reflector;
26  
27  /**
28   * 
29   * @author Matt Sgarlata
30   * @since Oct 25, 2007
31   */
32  public abstract class BaseCompositeReflector extends BaseReflector {
33  
34  	private Object[] components;
35  	private Specializer specializer;
36  	private ComponentValidator componentValidator;
37  
38  
39  	public boolean isSpecializable(Class type) throws SpecializationException {
40  		initialize();
41  		return getSpecializer().isSpecializable(this, type);
42  	}
43  
44  	public Object specialize(Class type) {
45  		initialize();
46  		return getSpecializer().specialize(this, type);
47  	}
48  	
49  	public Class getComponentType() {
50  		return Reflector.class;
51  	}
52  
53  	protected boolean isPerformingLogging() {
54  		// let the delegate do the logging
55  		return false;
56  	}
57  
58  	public Object clone() throws CloneNotSupportedException {
59  		return super.clone();
60  	}
61  
62  	public String toString() {
63  		return CompositeUtils.toString(this);
64  	}
65  
66  	public Object[] getComponents() {
67  		return components;
68  	}
69  
70  	public void setComponents(Object[] components) {
71  		setInitialized(false);
72  		this.components = components;
73  	}
74  
75  	public Specializer getSpecializer() {
76  		if (specializer == null) {
77  			specializer = new CachingSpecializerProxy(new CloningSpecializer());
78  		}
79  		return specializer;
80  	}
81  
82  	public void setSpecializer(Specializer specializer) {
83  		this.specializer = specializer;
84  	}
85  
86  	public ComponentValidator getComponentValidator() {
87  		if (componentValidator == null) {
88  			componentValidator = Defaults.createComponentValidator();
89  		}
90  		return componentValidator;
91  	}
92  
93  	public void setComponentValidator(ComponentValidator validator) {
94  		this.componentValidator = validator;
95  	}
96  
97  }