View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans.
5    *
6    * CosyBeans is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.displayers;
21  
22  import java.util.BitSet;
23  import java.util.Map;
24  
25  import com.cosylab.util.CommonException;
26  
27  
28  /**
29   * <code>ObjectConsumerMulticaster</code> delegates all defined data sources to
30   * <code>ObjectConsumer</code> delegate.
31   *
32   * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
33   * @version $Id: ObjectConsumerMulticaster.java,v 1.5 2008-04-22 12:31:02 jbobnar Exp $
34   *
35   * @since Feb 5, 2004.
36   */
37  public class ObjectConsumerMulticaster implements DoubleConsumer,
38  	DoubleSeqConsumer, LongConsumer, LongSeqConsumer, NumberConsumer,
39  	ObjectConsumer, ObjectSeqConsumer, PatternConsumer, StringConsumer,
40  	StringSeqConsumer
41  {
42  	/** Types of data consumers, that are supported by this multicaster. */
43  	public static final Class[] SUPPORTED_CONSUMER_TYPES = {
44  		DoubleConsumer.class, DoubleSeqConsumer.class, LongConsumer.class,
45  		LongSeqConsumer.class, NumberConsumer.class, ObjectConsumer.class,
46  		ObjectSeqConsumer.class, PatternConsumer.class, StringConsumer.class,
47  		StringSeqConsumer.class
48  	};
49  
50  	/**
51  	 * If multicaster supports type, new multicaster is created, otherwise
52  	 * <code>null</code>is returned.
53  	 *
54  	 * @param type the requested consumer type
55  	 * @param delegate the consumer to which all call sare delegated
56  	 *
57  	 * @return new multicaster if type is supported, otherwise
58  	 *         <code>null</code>
59  	 */
60  	public static final ObjectConsumer createDataConsumer(Class type,
61  	    ObjectConsumer delegate)
62  	{
63  		if (type == ObjectConsumer.class) {
64  			return delegate;
65  		}
66  
67  		return new ObjectConsumerMulticaster(delegate);
68  	}
69  
70  	private ObjectConsumer delegate;
71  
72  	/**
73  	 * Creates multicaster without delegate. Set delegate before usage.
74  	 */
75  	public ObjectConsumerMulticaster()
76  	{
77  		super();
78  	}
79  
80  	/**
81  	 * Creates a new ObjectConsumerMulticaster object.
82  	 *
83  	 * @param delegate DOCUMENT ME!
84  	 */
85  	public ObjectConsumerMulticaster(ObjectConsumer delegate)
86  	{
87  		super();
88  		this.delegate = delegate;
89  	}
90  
91  	/**
92  	 * Returns delegated consumer.
93  	 *
94  	 * @return delegated consumer
95  	 */
96  	public ObjectConsumer getDelegate()
97  	{
98  		return delegate;
99  	}
100 
101 	/**
102 	 * Sets delegated consumer.
103 	 *
104 	 * @param consumer delegated
105 	 */
106 	public void setDelegate(ObjectConsumer consumer)
107 	{
108 		delegate = consumer;
109 	}
110 
111 	/* (non-Javadoc)
112 	 * @see com.cosylab.gui.displayers.DoubleConsumer#updateValue(long, double)
113 	 */
114 	public void updateValue(long timestamp, double value)
115 		throws CommonException
116 	{
117 		delegate.updateValue(timestamp, new Double(value));
118 	}
119 
120 	/* (non-Javadoc)
121 	 * @see com.cosylab.gui.displayers.DoubleSeqConsumer#updateValue(long, double[])
122 	 */
123 	public void updateValue(long timestamp, double[] value)
124 		throws CommonException
125 	{
126 		delegate.updateValue(timestamp, value);
127 	}
128 
129 	/* (non-Javadoc)
130 	 * @see com.cosylab.gui.displayers.LongConsumer#updateValue(long, long)
131 	 */
132 	public void updateValue(long timestamp, long value)
133 		throws CommonException
134 	{
135 		delegate.updateValue(timestamp, new Long(value));
136 	}
137 
138 	/* (non-Javadoc)
139 	 * @see com.cosylab.gui.displayers.LongSeqConsumer#updateValue(long, long[])
140 	 */
141 	public void updateValue(long timestamp, long[] value)
142 		throws CommonException
143 	{
144 		delegate.updateValue(timestamp, value);
145 	}
146 
147 	/* (non-Javadoc)
148 	 * @see com.cosylab.gui.displayers.NumberConsumer#updateValue(long, java.lang.Number)
149 	 */
150 	public void updateValue(long timestamp, Number value)
151 		throws CommonException
152 	{
153 		delegate.updateValue(timestamp, value);
154 	}
155 
156 	/* (non-Javadoc)
157 	 * @see com.cosylab.gui.displayers.ObjectConsumer#updateValue(long, java.lang.Object)
158 	 */
159 	public void updateValue(long timestamp, Object value)
160 		throws CommonException
161 	{
162 		delegate.updateValue(timestamp, value);
163 	}
164 
165 	/* (non-Javadoc)
166 	 * @see com.cosylab.gui.displayers.ObjectSeqConsumer#updateValue(long, java.lang.Object[])
167 	 */
168 	public void updateValue(long timestamp, Object[] value)
169 		throws CommonException
170 	{
171 		delegate.updateValue(timestamp, value);
172 	}
173 
174 	/* (non-Javadoc)
175 	 * @see com.cosylab.gui.displayers.PatternConsumer#updateValue(long, java.util.BitSet)
176 	 */
177 	public void updateValue(long timestamp, BitSet value)
178 		throws CommonException
179 	{
180 		delegate.updateValue(timestamp, value);
181 	}
182 
183 	/* (non-Javadoc)
184 	 * @see com.cosylab.gui.displayers.StringConsumer#updateValue(long, java.lang.String)
185 	 */
186 	public void updateValue(long timestamp, String value)
187 		throws CommonException
188 	{
189 		delegate.updateValue(timestamp, value);
190 	}
191 
192 	/* (non-Javadoc)
193 	 * @see com.cosylab.gui.displayers.StringSeqConsumer#updateValue(long, java.lang.String[])
194 	 */
195 	public void updateValue(long timestamp, String[] value)
196 		throws CommonException
197 	{
198 		delegate.updateValue(timestamp, value);
199 	}
200 
201 	/* (non-Javadoc)
202 	 * @see com.cosylab.gui.displayers.DataConsumer#getDefaultDataConsumer()
203 	 */
204 	public DataConsumer getDefaultDataConsumer()
205 	{
206 		return delegate.getDefaultDataConsumer();
207 	}
208 
209 	/* (non-Javadoc)
210 	 * @see com.cosylab.gui.displayers.DataConsumer#getName()
211 	 */
212 	public String getName()
213 	{
214 		return delegate.getName();
215 	}
216 
217 	/* (non-Javadoc)
218 	 * @see com.cosylab.gui.displayers.DataConsumer#getSupportedCharacteristics()
219 	 */
220 	public String[] getSupportedCharacteristics()
221 	{
222 		return delegate.getSupportedCharacteristics();
223 	}
224 
225 	/* (non-Javadoc)
226 	 * @see com.cosylab.gui.displayers.DataConsumer#getSupportedConsumerTypes()
227 	 */
228 	@SuppressWarnings("unchecked")
229 	public Class[] getSupportedConsumerTypes()
230 	{
231 		return SUPPORTED_CONSUMER_TYPES;
232 	}
233 
234 	/* (non-Javadoc)
235 	 * @see com.cosylab.gui.displayers.DataConsumer#setCharacteristics(java.util.Map)
236 	 */
237 	public void setCharacteristics(Map characteristics)
238 	{
239 		delegate.setCharacteristics(characteristics);
240 	}
241 
242 	/* (non-Javadoc)
243 	 * @see com.cosylab.gui.displayers.DataConsumer#updateDataState(com.cosylab.gui.displayers.DataState)
244 	 */
245 	public void updateDataState(DataState state)
246 	{
247 		delegate.updateDataState(state);
248 	}
249 
250 	/*
251 	 * (non-Javadoc)
252 	 * @see com.cosylab.gui.displayers.DataConsumer#getDataConsumer(java.lang.Class)
253 	 */
254 	public <D extends DataConsumer> D getDataConsumer(Class<D> type) {
255 		return delegate.getDataConsumer(type);
256 	}
257 }
258 
259 /* __oOo__ */