View Javadoc

1   /*
2    * Created on Jul 24, 2005. Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the "License"); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.editor;
13  import java.util.EnumSet;
14  
15  import sk.baka.ikslibs.SourceEnum;
16  /***
17   * <p>
18   * Contains information about single renderer. Returned by the renderer factory.
19   * If the factory instance wants to store additional properties into this object
20   * (for example editor class instance, etc) it may derive from this class.
21   * Derived class should preserve immutability.
22   * </p>
23   * <p>
24   * Object is equal to other editor info object if and only if a) their factories
25   * are equal, b) their ids are equal.
26   * </p>
27   * @author Martin Vysny
28   */
29  public class RendererInfo {
30  	/***
31  	 * Constructor.
32  	 * @param id Unique identifier of this renderer. Unique in context of a
33  	 * factory instance.
34  	 * @param factory The factory that is able to produce this renderer.
35  	 * @param sourceTypes type of Source object that this exporter processes.
36  	 * @param sourceNamespace the namespace of the source document.
37  	 */
38  	public RendererInfo(final String id, final IRendererFactory factory,
39  			final EnumSet<SourceEnum> sourceTypes, final String sourceNamespace) {
40  		super();
41  		if (sourceTypes.contains(SourceEnum.SAX)
42  				|| sourceTypes.contains(SourceEnum.STREAM))
43  			throw new IllegalArgumentException(
44  					"sourceTypes must not contain SAX nor STREAM source kind."); //$NON-NLS-1$
45  		this.id = id;
46  		this.factory = factory;
47  		this.sourceNamespace = sourceNamespace;
48  		this.sourceTypes = sourceTypes;
49  	}
50  	/***
51  	 * Unique identifier of this renderer. Unique in context of a factory
52  	 * instance.
53  	 */
54  	private final String id;
55  	/***
56  	 * The factory that is able to produce this renderer.
57  	 */
58  	private final IRendererFactory factory;
59  	/***
60  	 * Set of all types of sources that are supported by this editor. Editor is
61  	 * not required to support all kinds of results - export engine can
62  	 * automatically convert between some result kinds. However, the editor
63  	 * should support all kinds of results for which it is optimized.
64  	 */
65  	public final EnumSet<SourceEnum> sourceTypes;
66  	/***
67  	 * The namespace this editor can process.
68  	 */
69  	public final String sourceNamespace;
70  	/*
71  	 * (non-Javadoc)
72  	 * @see java.lang.Object#toString()
73  	 */
74  	@Override
75  	public String toString() {
76  		return "Renderer " + getId(); //$NON-NLS-1$
77  	}
78  	/*
79  	 * (non-Javadoc)
80  	 * @see java.lang.Object#equals(java.lang.Object)
81  	 */
82  	@Override
83  	public final boolean equals(Object obj) {
84  		if (obj == this)
85  			return true;
86  		if (!(obj instanceof RendererInfo))
87  			return false;
88  		final RendererInfo other = (RendererInfo) obj;
89  		return other.getId().equals(getId()) && other.getFactory().equals(getFactory());
90  	}
91  	/*
92  	 * (non-Javadoc)
93  	 * @see java.lang.Object#hashCode()
94  	 */
95  	@Override
96  	public final int hashCode() {
97  		return getFactory().hashCode() * 4801 + getId().hashCode();
98  	}
99  	/***
100 	 * Produces new instance of this renderer.
101 	 * @return new instance of this renderer.
102 	 * @throws EditorException if renderer construction fails.
103 	 */
104 	public final IRenderer newRenderer() throws EditorException {
105 		return getFactory().produce(getId());
106 	}
107     /***
108      * @return Returns the id.
109      */
110     public String getId() {
111         return this.id;
112     }
113     /***
114      * @return Returns the factory.
115      */
116     public IRendererFactory getFactory() {
117         return this.factory;
118     }
119 }