1
2
3
4
5
6
7
8
9
10
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.");
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
72
73
74 @Override
75 public String toString() {
76 return "Renderer " + getId();
77 }
78
79
80
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
93
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 }