]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/wire/WireClient.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / wire / WireClient.java
1 /*******************************************************************************\r
2  * Copyright (c) 2010- Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  * \r
9  * Contributors:\r
10  *    VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.databoard.accessor.wire;\r
13 \r
14 import java.lang.ref.ReferenceQueue;\r
15 import java.lang.ref.WeakReference;\r
16 import java.util.ArrayList;\r
17 import java.util.Collection;\r
18 import java.util.HashMap;\r
19 import java.util.LinkedList;\r
20 import java.util.List;\r
21 import java.util.Map;\r
22 import java.util.Map.Entry;\r
23 import java.util.TreeMap;\r
24 import java.util.concurrent.CopyOnWriteArrayList;\r
25 import java.util.concurrent.Executor;\r
26 \r
27 import org.simantics.databoard.Bindings;\r
28 import org.simantics.databoard.Datatypes;\r
29 import org.simantics.databoard.Methods;\r
30 import org.simantics.databoard.accessor.Accessor;\r
31 import org.simantics.databoard.accessor.ArrayAccessor;\r
32 import org.simantics.databoard.accessor.BooleanAccessor;\r
33 import org.simantics.databoard.accessor.ByteAccessor;\r
34 import org.simantics.databoard.accessor.CloseableAccessor;\r
35 import org.simantics.databoard.accessor.DoubleAccessor;\r
36 import org.simantics.databoard.accessor.FloatAccessor;\r
37 import org.simantics.databoard.accessor.IntegerAccessor;\r
38 import org.simantics.databoard.accessor.LongAccessor;\r
39 import org.simantics.databoard.accessor.MapAccessor;\r
40 import org.simantics.databoard.accessor.OptionalAccessor;\r
41 import org.simantics.databoard.accessor.RecordAccessor;\r
42 import org.simantics.databoard.accessor.StringAccessor;\r
43 import org.simantics.databoard.accessor.UnionAccessor;\r
44 import org.simantics.databoard.accessor.VariantAccessor;\r
45 import org.simantics.databoard.accessor.error.AccessorConstructionException;\r
46 import org.simantics.databoard.accessor.error.AccessorException;\r
47 import org.simantics.databoard.accessor.error.ReferenceException;\r
48 import org.simantics.databoard.accessor.event.ArrayElementRemoved;\r
49 import org.simantics.databoard.accessor.event.Event;\r
50 import org.simantics.databoard.accessor.event.MapEntryAdded;\r
51 import org.simantics.databoard.accessor.event.MapEntryRemoved;\r
52 import org.simantics.databoard.accessor.event.OptionalValueAssigned;\r
53 import org.simantics.databoard.accessor.event.OptionalValueRemoved;\r
54 import org.simantics.databoard.accessor.event.ValueAssigned;\r
55 import org.simantics.databoard.accessor.impl.ListenerEntry;\r
56 import org.simantics.databoard.accessor.interestset.InterestSet;\r
57 import org.simantics.databoard.accessor.reference.ChildReference;\r
58 import org.simantics.databoard.accessor.reference.ComponentReference;\r
59 import org.simantics.databoard.accessor.reference.IndexReference;\r
60 import org.simantics.databoard.accessor.reference.KeyReference;\r
61 import org.simantics.databoard.accessor.reference.NameReference;\r
62 import org.simantics.databoard.accessor.wire.IWireServer.AccessorInfo;\r
63 import org.simantics.databoard.accessor.wire.IWireServer.ApplyResult;\r
64 import org.simantics.databoard.adapter.AdaptException;\r
65 import org.simantics.databoard.binding.ArrayBinding;\r
66 import org.simantics.databoard.binding.Binding;\r
67 import org.simantics.databoard.binding.MapBinding;\r
68 import org.simantics.databoard.binding.error.BindingConstructionException;\r
69 import org.simantics.databoard.binding.error.BindingException;\r
70 import org.simantics.databoard.binding.impl.ArrayListBinding;\r
71 import org.simantics.databoard.binding.impl.ObjectArrayBinding;\r
72 import org.simantics.databoard.binding.impl.TreeMapBinding;\r
73 import org.simantics.databoard.binding.mutable.MutableVariant;\r
74 import org.simantics.databoard.method.MethodInterface;\r
75 import org.simantics.databoard.type.ArrayType;\r
76 import org.simantics.databoard.type.BooleanType;\r
77 import org.simantics.databoard.type.ByteType;\r
78 import org.simantics.databoard.type.Datatype;\r
79 import org.simantics.databoard.type.DoubleType;\r
80 import org.simantics.databoard.type.FloatType;\r
81 import org.simantics.databoard.type.IntegerType;\r
82 import org.simantics.databoard.type.LongType;\r
83 import org.simantics.databoard.type.MapType;\r
84 import org.simantics.databoard.type.OptionalType;\r
85 import org.simantics.databoard.type.RecordType;\r
86 import org.simantics.databoard.type.StringType;\r
87 import org.simantics.databoard.type.UnionType;\r
88 import org.simantics.databoard.type.VariantType;\r
89 import org.simantics.databoard.util.BijectionMap;\r
90 \r
91 /**\r
92  * WireAccessor provides an accessor over TCP/IP connection.\r
93  * \r
94  * All method invocation is blocking. WireAccessor may be accessed from \r
95  * simultanous threads.\r
96  * \r
97  *\r
98  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
99  */\r
100 public class WireClient implements IWireClient {\r
101 \r
102         /** A queue of released accessors */\r
103         ReferenceQueue<WireAccessor> releaseQueue = new ReferenceQueue<WireAccessor>();\r
104         Map<ChildReference, WireAccessorReference> subAccessorMap = new HashMap<ChildReference, WireAccessorReference>();\r
105         \r
106 //      Map<Integer, Accessor> accessorMap = new HashMap<Integer, Accessor>();\r
107         BijectionMap<Integer, ListenerEntry> listenerMap = new BijectionMap<Integer, ListenerEntry>();\r
108         \r
109         MethodInterface serverMi;\r
110         MethodInterface clientMi;\r
111         IWireServer server;\r
112         WireAccessor root;\r
113         \r
114         public WireClient() {\r
115                 try {\r
116                         this.clientMi = Methods.bindInterface(IWireClient.class, this);\r
117                 } catch (BindingConstructionException e) {\r
118                         throw new RuntimeException(e);\r
119                 }\r
120         }\r
121         \r
122         public void setServerMethodInterface(MethodInterface serverMi) {\r
123                 try {\r
124                         this.serverMi = serverMi;\r
125                         this.server = Methods.createProxy(IWireServer.class, serverMi);\r
126                 } catch (BindingConstructionException e) {\r
127                         throw new RuntimeException(e);\r
128                 }\r
129         }\r
130         \r
131         public MethodInterface getServerMethodInterface() {\r
132                 return serverMi;\r
133         }\r
134         \r
135         public MethodInterface getClientMethodInterface() {\r
136                 return clientMi;\r
137         }\r
138         \r
139         public void close() {\r
140                 try {\r
141                         closeReleasedAccessors();                       \r
142                 } catch (WireException e) {\r
143                         e.printStackTrace();\r
144                 }\r
145                 \r
146         }\r
147         \r
148         /**\r
149          * Create an accessor. Does not dispose or add to cache, use getAccessor instead\r
150          * @param ref\r
151          * @return\r
152          * @throws WireException\r
153          */\r
154         WireAccessor createAccessor(ChildReference ref) throws WireException {\r
155                 AccessorInfo ai = server.openAccessor(ref);\r
156                 if (ai.type instanceof BooleanType) {\r
157                         return new WireBoolean(ai.accessorId, ai.type, ref);\r
158                 } else\r
159                 if (ai.type instanceof ByteType) {\r
160                         return new WireByte(ai.accessorId, ai.type, ref);\r
161                 } else \r
162                 if (ai.type instanceof IntegerType) {\r
163                         return new WireInteger(ai.accessorId, ai.type, ref);\r
164                 } else \r
165                 if (ai.type instanceof LongType) {\r
166                         return new WireLong(ai.accessorId, ai.type, ref);\r
167                 } else \r
168                 if (ai.type instanceof FloatType) {\r
169                         return new WireFloat(ai.accessorId, ai.type, ref);\r
170                 } else \r
171                 if (ai.type instanceof DoubleType) {\r
172                         return new WireDouble(ai.accessorId, ai.type, ref);\r
173                 } else  \r
174                 if (ai.type instanceof StringType) {\r
175                         return new WireByte(ai.accessorId, ai.type, ref);\r
176                 } else \r
177                 if (ai.type instanceof MapType) {\r
178                         return new WireMap(ai.accessorId, ai.type, ref);\r
179                 } else \r
180                 if (ai.type instanceof OptionalType) {\r
181                         return new WireOptional(ai.accessorId, ai.type, ref);\r
182                 } else \r
183                 if (ai.type instanceof RecordType) {\r
184                         return new WireRecord(ai.accessorId, ai.type, ref);\r
185                 } else \r
186                 if (ai.type instanceof UnionType) {\r
187                         return new WireUnion(ai.accessorId, ai.type, ref);\r
188                 } else \r
189                 if (ai.type instanceof VariantType) {\r
190                         return new WireVariant(ai.accessorId, ai.type, ref);\r
191                 } \r
192                 throw new WireException("error, unknown data type "+ai.type);\r
193         }\r
194         \r
195         /**\r
196          * Create or get wire accessor\r
197          * @param ref path from root\r
198          * @return wire accessor\r
199          * @throws WireException\r
200          */\r
201         public WireAccessor getAccessor(ChildReference ref) throws WireException {\r
202                 synchronized(subAccessorMap) {\r
203                         // Rseult Check cache\r
204                         closeReleasedAccessors();\r
205                         WireAccessorReference war = subAccessorMap.get(ref);\r
206                         WireAccessor result = war == null ? null : war.get();\r
207                         if (result != null) return result;\r
208                         \r
209                         result = createAccessor(ref);\r
210                         war = new WireAccessorReference(result);\r
211                         subAccessorMap.put(ref, war);\r
212                         \r
213                         return result;\r
214                 }\r
215         }\r
216         \r
217         /**\r
218          * Close garbage collected accessors\r
219          * @throws WireException \r
220          */\r
221         void closeReleasedAccessors() throws WireException {\r
222                 if (releaseQueue.poll()==null) return;\r
223                 ArrayList<Integer> ids = new ArrayList<Integer>();\r
224                 while (releaseQueue.poll() != null) {\r
225                         try {\r
226                                 WireAccessorReference ref = (WireAccessorReference) releaseQueue.remove();\r
227                                 ids.add( ref.accId );\r
228                         } catch (InterruptedException e) {\r
229                         }\r
230                 }\r
231                 // Close accessors\r
232                 server.closeAccessors( ids.toArray(new Integer[ids.size()]) );\r
233         }\r
234         \r
235         @Override\r
236         public int onEvents(int lisId, Event[] events) {\r
237                 ListenerEntry listener = null;\r
238                 synchronized(listenerMap) {\r
239                         listener = listenerMap.getRight(lisId);\r
240                 }\r
241                 if (listener==null) return 0;\r
242 \r
243                 List<Event> list = new CopyOnWriteArrayList<Event>(events);\r
244                 listener.emitEvents(list);\r
245                 \r
246                 return 0;\r
247         }\r
248         \r
249         class WireAccessorReference extends WeakReference<WireAccessor> {\r
250 \r
251                 int accId;\r
252                 \r
253                 public WireAccessorReference(WireAccessor referent) {\r
254                         super(referent, releaseQueue);\r
255                         this.accId = referent.accId;\r
256                 }\r
257                 \r
258         }\r
259         \r
260         abstract class WireAccessor implements Accessor, CloseableAccessor {\r
261                 int accId;\r
262                 ChildReference ref;\r
263                 Datatype type;          \r
264                 \r
265                 WireAccessor(int accId, Datatype type, ChildReference ref) {\r
266                         this.accId = accId;\r
267                         this.type = type;\r
268                         this.ref = ref;                 \r
269                 }\r
270 \r
271                 @Override\r
272                 public Object getValue(Binding binding) throws AccessorException {\r
273                         try {\r
274                                 MutableVariant value = server.getValue(accId);\r
275                                 return value.getValue(binding);\r
276                         } catch (WireException e) {\r
277                                 throw new AccessorException(e);\r
278                         } catch (AdaptException e) {\r
279                                 throw new AccessorException(e);\r
280                         }\r
281                 }\r
282                 \r
283                 @Override\r
284                 public void getValue(Binding binding, Object obj)\r
285                                 throws AccessorException {\r
286             try {\r
287                 MutableVariant value= server.getValue(accId);\r
288                 binding.readFrom(value.getBinding(), value.getValue(), obj);\r
289             } catch ( WireException e ) {\r
290                 throw new AccessorException(e);\r
291             } catch ( BindingException e ) {\r
292                 throw new AccessorException(e);\r
293             }\r
294                 }\r
295                 \r
296                 @Override\r
297                 public boolean getValue(ChildReference path, Binding binding, Object obj) throws AccessorException {\r
298                         try {\r
299                                 Accessor a = getComponent(path);\r
300                                 a.getValue(binding, obj);\r
301                                 return true;\r
302                         } catch (ReferenceException re) {\r
303                                 return false;\r
304                         } catch (AccessorConstructionException e) {\r
305                                 throw new AccessorException(e);\r
306                         }\r
307                 }       \r
308                 \r
309                 public Object getValue(ChildReference path, Binding binding) throws AccessorException {\r
310                         try {\r
311                                 Accessor a = getComponent(path);\r
312                                 return a.getValue(binding);\r
313                         } catch (ReferenceException re) {\r
314                                 return null;\r
315                         } catch (AccessorConstructionException e) {\r
316                                 throw new AccessorException(e);\r
317                         }\r
318                 }\r
319                 \r
320                 \r
321                 void applyEvent(Event...events) throws AccessorException {\r
322                         ApplyResult result = server.apply(accId, events, false);\r
323                         if (result.error != null) throw new AccessorException( result.error );\r
324                 }\r
325                 \r
326                 @Override\r
327                 public void setValue(Binding binding, Object newValue) throws AccessorException {\r
328                         applyEvent( new ValueAssigned(binding, newValue) ); \r
329                 }\r
330                 \r
331                 public boolean setValue(ChildReference path, Binding binding, Object obj) throws AccessorException {\r
332                         try {\r
333                                 Accessor a = getComponent(path);\r
334                                 a.setValue(binding, obj);\r
335                                 return true;\r
336                         } catch (ReferenceException re) {\r
337                                 return false;\r
338                         } catch (AccessorConstructionException e) {\r
339                                 throw new AccessorException(e);\r
340                         }\r
341                 }\r
342                 \r
343                 @SuppressWarnings("unchecked")\r
344                 @Override\r
345                 public <T extends Accessor> T getComponent(ChildReference reference)\r
346                 throws AccessorConstructionException {\r
347                         try {\r
348                                 // Create a reference from the root\r
349                                 ChildReference r = ChildReference.concatenate(ref, reference);\r
350                                 return (T) WireClient.this.getAccessor( r );\r
351                         } catch (WireException e) {\r
352                                 throw new AccessorConstructionException( e ); \r
353                         }\r
354                 }\r
355 \r
356                 @Override\r
357                 public void apply(List<Event> changeSet, LinkedList<Event> rollback)\r
358                                 throws AccessorException {\r
359                         \r
360                         ApplyResult result = server.apply(accId, changeSet.toArray(new Event[changeSet.size()]), rollback!=null);\r
361                         if (rollback!=null && result.rollbackLog!=null)\r
362                                 rollback.addAll( result.rollbackLog );\r
363                         if (result.error != null) throw new AccessorException( result.error );\r
364                         \r
365                 }\r
366 \r
367                 @Override\r
368                 public Datatype type() { \r
369                         return type;\r
370                 }\r
371 \r
372                 @Override\r
373                 public void addListener(Listener listener, InterestSet interestSet,\r
374                                 ChildReference pathPrefix, Executor executor) throws AccessorException {\r
375                         try {\r
376                                 ListenerEntry le = new ListenerEntry(listener, interestSet, pathPrefix, executor);\r
377                                 int lisId = server.addListener(accId, interestSet, pathPrefix);\r
378                                 synchronized(listenerMap) {\r
379                                         listenerMap.map(lisId, le);\r
380                                 }\r
381                         } catch (WireException e) {\r
382                                 throw new AccessorException(e);\r
383                         }\r
384                 }\r
385 \r
386                 @Override\r
387                 public void removeListener(Listener listener) throws AccessorException {\r
388                         Integer lisId = null;\r
389                         synchronized(listenerMap) {\r
390                                 for (Entry<Integer, ListenerEntry> e : listenerMap.getEntries()) {\r
391                                         if (e.getValue().listener == listener) {\r
392                                                 lisId = e.getKey();\r
393                                                 break;\r
394                                         }\r
395                                 }\r
396                                 if (lisId==null) return;\r
397                                 listenerMap.removeWithLeft(lisId);\r
398                         }\r
399                         try {\r
400                                 server.removeListener(lisId);\r
401                         } catch (WireException e) {\r
402                                 throw new AccessorException( e );\r
403                         }                       \r
404                 }\r
405                 \r
406                 public void close() throws AccessorException {\r
407                         try {\r
408                                 server.closeAccessors( new Integer[] {accId} );\r
409                         } catch (WireException e) {\r
410                                 throw new AccessorException( e );\r
411                         }\r
412                 }\r
413 \r
414         }\r
415         \r
416         class WireBoolean extends WireAccessor implements BooleanAccessor {\r
417 \r
418                 WireBoolean(int accId, Datatype type, ChildReference ref) {\r
419                         super(accId, type, ref);\r
420                 }\r
421                 \r
422                 @Override\r
423                 public BooleanType type() { \r
424                         return (BooleanType) type;\r
425                 }\r
426                 \r
427                 @Override\r
428                 public boolean getValue() throws AccessorException {\r
429                         try {\r
430                                 MutableVariant value = server.getValue(accId);\r
431                                 return (Boolean) value.getValue( Bindings.BOOLEAN );\r
432                         } catch (WireException e) {\r
433                                 throw new AccessorException( e );\r
434                         } catch (AdaptException e) {\r
435                                 throw new AccessorException( e );\r
436                         }\r
437                 }\r
438 \r
439                 @Override\r
440                 public void setValue(boolean value) throws AccessorException {\r
441                         Event e = new ValueAssigned(null, Bindings.BOOLEAN, value); \r
442                         Event[] list = new Event[] {e};\r
443                         ApplyResult result = server.apply(accId, list, false);\r
444                         if (result.error != null) throw new AccessorException( result.error );\r
445                 }\r
446         }       \r
447         \r
448         class WireByte extends WireAccessor implements ByteAccessor {\r
449 \r
450                 WireByte(int accId, Datatype type, ChildReference ref) {\r
451                         super(accId, type, ref);\r
452                 }\r
453                 \r
454                 @Override\r
455                 public ByteType type() { \r
456                         return (ByteType) type;\r
457                 }\r
458                 \r
459                 @Override\r
460                 public byte getValue() throws AccessorException {\r
461                         try {\r
462                                 MutableVariant value = server.getValue(accId);\r
463                                 return (Byte) value.getValue( Bindings.BYTE );\r
464                         } catch (WireException e) {\r
465                                 throw new AccessorException( e );\r
466                         } catch (AdaptException e) {\r
467                                 throw new AccessorException( e );\r
468                         }\r
469                 }\r
470                 \r
471                 @Override\r
472                 public void setValue(byte value) throws AccessorException {\r
473                         Event e = new ValueAssigned(null, Bindings.BYTE, value); \r
474                         Event[] list = new Event[] {e};\r
475                         ApplyResult result = server.apply(accId, list, false);\r
476                         if (result.error != null) throw new AccessorException( result.error );\r
477                 }\r
478         }\r
479 \r
480         class WireInteger extends WireAccessor implements IntegerAccessor {\r
481 \r
482                 WireInteger(int accId, Datatype type, ChildReference ref) {\r
483                         super(accId, type, ref);\r
484                 }\r
485                 \r
486                 @Override\r
487                 public IntegerType type() { \r
488                         return (IntegerType) type;\r
489                 }\r
490                 \r
491                 @Override\r
492                 public int getValue() throws AccessorException {\r
493                         try {\r
494                                 MutableVariant value = server.getValue(accId);\r
495                                 return (Integer) value.getValue( Bindings.INTEGER );\r
496                         } catch (WireException e) {\r
497                                 throw new AccessorException( e );\r
498                         } catch (AdaptException e) {\r
499                                 throw new AccessorException( e );\r
500                         }\r
501                 }\r
502 \r
503                 @Override\r
504                 public void setValue(int value) throws AccessorException {\r
505                         Event e = new ValueAssigned(Bindings.INTEGER, value); \r
506                         Event[] list = new Event[] {e};\r
507                         ApplyResult result = server.apply(accId, list, false);\r
508                         if (result.error != null) throw new AccessorException( result.error );\r
509                 }\r
510 \r
511         }\r
512 \r
513         class WireLong extends WireAccessor implements LongAccessor {\r
514 \r
515                 WireLong(int accId, Datatype type, ChildReference ref) {\r
516                         super(accId, type, ref);\r
517                 }\r
518                 \r
519                 @Override\r
520                 public LongType type() { \r
521                         return (LongType) type;\r
522                 }\r
523                 \r
524                 @Override\r
525                 public long getValue() throws AccessorException {\r
526                         try {\r
527                                 MutableVariant value = server.getValue(accId);\r
528                                 return (Long) value.getValue( Bindings.LONG );\r
529                         } catch (WireException e) {\r
530                                 throw new AccessorException( e );\r
531                         } catch (AdaptException e) {\r
532                                 throw new AccessorException( e );\r
533                         }\r
534                 }\r
535 \r
536                 @Override\r
537                 public void setValue(long value) throws AccessorException {\r
538                         Event e = new ValueAssigned(Bindings.LONG, value); \r
539                         Event[] list = new Event[] {e};\r
540                         ApplyResult result = server.apply(accId, list, false);\r
541                         if (result.error != null) throw new AccessorException( result.error );\r
542                 }\r
543 \r
544         }\r
545 \r
546         class WireFloat extends WireAccessor implements FloatAccessor {\r
547 \r
548                 WireFloat(int accId, Datatype type, ChildReference ref) {\r
549                         super(accId, type, ref);\r
550                 }\r
551                 \r
552                 @Override\r
553                 public FloatType type() { \r
554                         return (FloatType) type;\r
555                 }\r
556                 \r
557                 @Override\r
558                 public float getValue() throws AccessorException {\r
559                         try {\r
560                                 MutableVariant value = server.getValue(accId);\r
561                                 return (Float) value.getValue( Bindings.FLOAT );\r
562                         } catch (WireException e) {\r
563                                 throw new AccessorException( e );\r
564                         } catch (AdaptException e) {\r
565                                 throw new AccessorException( e );\r
566                         }\r
567                 }\r
568 \r
569                 @Override\r
570                 public void setValue(float value) throws AccessorException {\r
571                         Event e = new ValueAssigned(Bindings.FLOAT, value); \r
572                         Event[] list = new Event[] {e};\r
573                         ApplyResult result = server.apply(accId, list, false);\r
574                         if (result.error != null) throw new AccessorException( result.error );\r
575                 }\r
576 \r
577         }\r
578 \r
579         class WireDouble extends WireAccessor implements DoubleAccessor {\r
580 \r
581                 WireDouble(int accId, Datatype type, ChildReference ref) {\r
582                         super(accId, type, ref);\r
583                 }\r
584                 \r
585                 @Override\r
586                 public DoubleType type() { \r
587                         return (DoubleType) type;\r
588                 }\r
589                 \r
590                 @Override\r
591                 public double getValue() throws AccessorException {\r
592                         try {\r
593                                 MutableVariant value = server.getValue(accId);\r
594                                 return (Double) value.getValue( Bindings.DOUBLE );\r
595                         } catch (WireException e) {\r
596                                 throw new AccessorException( e );\r
597                         } catch (AdaptException e) {\r
598                                 throw new AccessorException( e );\r
599                         }\r
600                 }\r
601 \r
602                 @Override\r
603                 public void setValue(double value) throws AccessorException {\r
604                         Event e = new ValueAssigned(Bindings.DOUBLE, value); \r
605                         Event[] list = new Event[] {e};\r
606                         ApplyResult result = server.apply(accId, list, false);\r
607                         if (result.error != null) throw new AccessorException( result.error );\r
608                 }\r
609 \r
610         }\r
611 \r
612         class WireArray extends WireAccessor implements ArrayAccessor {\r
613 \r
614                 WireArray(int accId, Datatype type, ChildReference ref) {\r
615                         super(accId, type, ref);\r
616                 }\r
617                 \r
618                 @Override\r
619                 public ArrayType type() { \r
620                         return (ArrayType) type;\r
621                 }\r
622 \r
623                 @Override\r
624                 public void add(Binding binding, Object value) throws AccessorException {\r
625                         try {\r
626                                 server.addAll(accId, -1, new MutableVariant(binding, value));\r
627                         } catch (WireException e) {\r
628                                 throw new AccessorException(e);\r
629                         }\r
630                 }\r
631 \r
632                 @Override\r
633                 public void addAll(Binding binding, Object[] values) throws AccessorException {\r
634                         try {\r
635                                 ArrayBinding ab = new ObjectArrayBinding(new ArrayType(binding.type()), binding);\r
636                                 MutableVariant array = new MutableVariant(ab, values);\r
637                                 server.addAll(accId, -1, array);\r
638                         } catch (WireException e) {\r
639                                 throw new AccessorException(e);\r
640                         }\r
641                 }\r
642 \r
643                 @Override\r
644                 public void addAll(int index, Binding binding, Object[] values)\r
645                                 throws AccessorException {\r
646                         try {\r
647                                 ArrayBinding ab = new ObjectArrayBinding(new ArrayType(binding.type()), binding);\r
648                                 MutableVariant array = new MutableVariant(ab, values);\r
649                                 server.addAll(accId, index, array);\r
650                         } catch (WireException e) {\r
651                                 throw new AccessorException(e);\r
652                         }\r
653                 }\r
654 \r
655                 @Override\r
656                 public void add(int index, Binding binding, Object value) throws AccessorException {\r
657                         try {\r
658                                 server.addAll(accId, index, new MutableVariant(binding, value));\r
659                         } catch (WireException e) {\r
660                                 throw new AccessorException(e);\r
661                         }\r
662                 }\r
663 \r
664                 @Override\r
665                 public void set(int index, Binding binding, Object value)\r
666                                 throws AccessorException {\r
667                         applyEvent(new ValueAssigned(new IndexReference(index), binding, value));\r
668                 }\r
669 \r
670                 @Override\r
671                 public void remove(int index, int count) throws AccessorException {\r
672                         applyEvent(new ArrayElementRemoved(index));                     \r
673                 }\r
674 \r
675                 @SuppressWarnings("unchecked")\r
676                 @Override\r
677                 public <T extends Accessor> T getAccessor(int index)\r
678                                 throws AccessorConstructionException {\r
679                         return (T) getComponent(new IndexReference(index));\r
680                 }\r
681 \r
682                 @Override\r
683                 public Object get(int index, Binding valueBinding)\r
684                                 throws AccessorException {\r
685                         try {\r
686                                 MutableVariant v = server.getArrayElement(accId, index);\r
687                                 return v.getValue(valueBinding);\r
688                         } catch (WireException e) {\r
689                                 throw new AccessorException(e);\r
690                         } catch (AdaptException e) {\r
691                                 throw new AccessorException(e);\r
692                         }\r
693                 }\r
694                 \r
695                 @Override\r
696                 public void get(int index, Binding valueBinding, Object dst)\r
697                                 throws AccessorException {\r
698                         try {\r
699                                 MutableVariant v = server.getArrayElement(accId, index);\r
700                                 valueBinding.readFrom(v.getBinding(), v.getValue(), v);\r
701                         } catch (WireException e) {\r
702                                 throw new AccessorException(e);\r
703                         } catch (BindingException e) {\r
704                                 throw new AccessorException(e);\r
705                         }\r
706                 }               \r
707 \r
708                 @Override\r
709                 public void getAll(Binding valueBinding, Object[] array)\r
710                                 throws AccessorException {\r
711                         ObjectArrayBinding arrayBinding = new ObjectArrayBinding(type(), valueBinding);\r
712                         Object[] a2 = (Object[]) getValue(arrayBinding);\r
713                         System.arraycopy(a2, 0, array, 0, a2.length);                   \r
714                 }\r
715 \r
716                 @Override\r
717                 public void getAll(Binding valueBinding, Collection<Object> values)\r
718                                 throws AccessorException {\r
719                         ArrayListBinding arrayBinding = new ArrayListBinding(type(), valueBinding);\r
720                         ArrayList<?> a2 = (ArrayList<?>) getValue(arrayBinding);\r
721                         values.addAll(a2);                      \r
722                 }\r
723                 \r
724                 @Override\r
725                 public void setSize(int newSize) throws AccessorException {\r
726                         throw new AccessorException("Not implemented");\r
727                 }\r
728 \r
729                 @Override\r
730                 public int size() throws AccessorException {\r
731                         try {\r
732                                 return server.size(accId);\r
733                         } catch (WireException e) {\r
734                                 throw new AccessorException( e );\r
735                         }\r
736                 }\r
737         }\r
738         \r
739         class WireMap extends WireAccessor implements MapAccessor {\r
740 \r
741                 WireMap(int accId, Datatype type, ChildReference ref) {\r
742                         super(accId, type, ref);\r
743                 }\r
744                 \r
745                 @Override\r
746                 public MapType type() { \r
747                         return (MapType) type;\r
748                 }               \r
749 \r
750                 @Override\r
751                 public int size() throws AccessorException {\r
752                         try {\r
753                                 return server.size(accId);\r
754                         } catch (WireException e) {\r
755                                 throw new AccessorException( e );\r
756                         }\r
757                 }\r
758 \r
759                 @Override\r
760                 public Object get(Binding keyBinding, Object key, Binding valueBinding)\r
761                                 throws AccessorException {\r
762                         try {\r
763                                 MutableVariant value = server.getMapValue(accId, new MutableVariant(keyBinding, key));\r
764                 if (value.type().equals(Datatypes.VOID)) return null;\r
765                                 return value.getValue(valueBinding);\r
766                         } catch (WireException e) {\r
767                                 throw new AccessorException( e );\r
768                         } catch (AdaptException e) {\r
769                                 throw new AccessorException( e );\r
770                         }\r
771                 }\r
772 \r
773                 @Override\r
774                 public boolean containsKey(Binding keyBinding, Object key)\r
775                                 throws AccessorException {\r
776                         try {\r
777                                 return server.containsKey(accId, new MutableVariant(keyBinding, key));\r
778                         } catch (WireException e) {\r
779                                 throw new AccessorException( e );\r
780                         }\r
781                 }\r
782 \r
783                 @Override\r
784                 public boolean containsValue(Binding valueBinding, Object value)\r
785                                 throws AccessorException {\r
786                         try {\r
787                                 return server.containsValue(accId, new MutableVariant(valueBinding, value));\r
788                         } catch (WireException e) {\r
789                                 throw new AccessorException( e );\r
790                         }\r
791                 }\r
792 \r
793                 @Override\r
794                 public void put(Binding keyBinding, Object key, Binding valueBinding,\r
795                                 Object value) throws AccessorException {\r
796                         applyEvent( new MapEntryAdded(new MutableVariant(keyBinding, key), new MutableVariant(valueBinding, value)) );\r
797                 }\r
798 \r
799                 @Override\r
800                 public void remove(Binding keyBinding, Object key)\r
801                                 throws AccessorException {\r
802                         applyEvent( new MapEntryRemoved(new MutableVariant(keyBinding, key)) );\r
803                 }\r
804 \r
805                 @Override\r
806                 public void clear() throws AccessorException {\r
807                         try {\r
808                                 server.clear(accId);\r
809                         } catch (WireException e) {\r
810                                 throw new AccessorException(e);\r
811                         }                       \r
812                 }\r
813 \r
814                 @Override\r
815                 public void putAll(Binding keyBinding, Binding valueBinding,\r
816                                 Map<Object, Object> from) throws AccessorException {\r
817                         \r
818                         int count = from.size();\r
819                         Event events[] = new Event[ count ];\r
820                         int i = 0;\r
821                         for (Entry<Object, Object> e : from.entrySet()) {\r
822                                 MutableVariant key = new MutableVariant( keyBinding, e.getKey() );\r
823                                 MutableVariant value = new MutableVariant( valueBinding, e.getValue() );\r
824                                 events[i] = new MapEntryAdded( key, value );\r
825                                 ++i;\r
826                         }\r
827                         applyEvent( events );                                           \r
828                 }\r
829 \r
830                 @Override\r
831                 public void putAll(Binding keyBinding, Binding valueBinding,\r
832                                 Object[] keys, Object[] values) throws AccessorException {\r
833                         if (keys.length != values.length) throw new AccessorException("bad args");\r
834                         int count = keys.length;\r
835                         Event events[] = new Event[ count ];\r
836                         for (int i=0; i<count; i++) {\r
837                                 events[i] = new MapEntryAdded( new MutableVariant(keyBinding, keys[i]), new MutableVariant(valueBinding, values[i]) );\r
838                         }\r
839                         applyEvent( events );                   \r
840                 }\r
841 \r
842                 @SuppressWarnings("unchecked")\r
843         @Override\r
844                 public void getAll(Binding keyBinding, Binding valueBinding,\r
845                                 Map<Object, Object> to) throws AccessorException {\r
846                         MapBinding binding = new TreeMapBinding(keyBinding, valueBinding);\r
847                         TreeMap<Object, Object> v = (TreeMap<Object, Object>) getValue(binding);\r
848                         to.putAll(v);\r
849                 }\r
850 \r
851                 @SuppressWarnings("unchecked")\r
852         @Override\r
853                 public void getAll(Binding keyBinding, Binding valueBinding,\r
854                                 Object[] keys, Object[] values) throws AccessorException {\r
855                         MapBinding binding = new TreeMapBinding(keyBinding, valueBinding);\r
856                         TreeMap<Object, Object> v = (TreeMap<Object, Object>) getValue(binding);\r
857                         int i=0;\r
858                         for (Entry<Object, Object> e : v.entrySet()) {\r
859                                 keys[i] = e.getKey();\r
860                                 values[i] = e.getValue();\r
861                                 ++i;\r
862                         }\r
863                 }\r
864 \r
865                 @Override\r
866                 public Object[] getKeys(Binding keyBinding) throws AccessorException {\r
867                         try {\r
868                                 MutableVariant array = server.getMapKeys(accId);\r
869                                 ArrayBinding binding = new ObjectArrayBinding( keyBinding );\r
870                                 return (Object[]) array.getValue(binding);\r
871                         } catch (WireException e) {\r
872                                 throw new AccessorException( e );\r
873                         } catch (AdaptException e) {\r
874                                 throw new AccessorException( e );\r
875                         }\r
876                 }\r
877 \r
878                 @Override\r
879                 public int count(Binding keyBinding, Object from,\r
880                                 boolean fromInclusive, Object end, boolean endInclusive)\r
881                                 throws AccessorException {\r
882                         throw new AccessorException("Not implemented");\r
883                 }\r
884 \r
885                 @Override\r
886                 public int getEntries(Binding keyBinding, Object from,\r
887                                 boolean fromInclusive, Object end, boolean endInclusive,\r
888                                 ArrayBinding keyArrayBinding, Object dstKeys,\r
889                                 ArrayBinding valueArrayBinding, Object dstValues, int limit)\r
890                                 throws AccessorException {\r
891                         throw new AccessorException("Not implemented");\r
892                 }\r
893                 \r
894 \r
895                 @Override\r
896                 public Object[] getValues(Binding valueBinding)\r
897                                 throws AccessorException {\r
898                         try {\r
899                                 MutableVariant array = server.getMapValues(accId);\r
900                                 ArrayBinding binding = new ObjectArrayBinding( valueBinding );\r
901                                 return (Object[]) array.getValue(binding);\r
902                         } catch (WireException e) {\r
903                                 throw new AccessorException( e );\r
904                         } catch (AdaptException e) {\r
905                                 throw new AccessorException( e );\r
906                         }\r
907                 }\r
908 \r
909                 @SuppressWarnings("unchecked")\r
910                 @Override\r
911                 public <T extends Accessor> T getValueAccessor(Binding keyBinding, Object key) throws AccessorConstructionException {\r
912                         return (T) getComponent( new KeyReference(keyBinding, key) );\r
913                 }\r
914 \r
915                 @Override\r
916                 public Object getFirstKey(Binding keyBinding) throws AccessorException {\r
917                         try {\r
918                                 MutableVariant result = server.getFirstKey(accId);\r
919                 if (result.type().equals(Datatypes.VOID)) return null;\r
920                                 return result.getValue(keyBinding);\r
921                         } catch (WireException e) {\r
922                                 throw new AccessorException(e);\r
923                         } catch (AdaptException e) {\r
924                                 throw new AccessorException(e);\r
925                         }\r
926                 }\r
927 \r
928                 @Override\r
929                 public Object getLastKey(Binding keyBinding) throws AccessorException {\r
930                         try {\r
931                                 MutableVariant result = server.getLastKey(accId);\r
932                 if (result.type().equals(Datatypes.VOID)) return null;\r
933                                 return result.getValue(keyBinding);\r
934                         } catch (WireException e) {\r
935                                 throw new AccessorException(e);\r
936                         } catch (AdaptException e) {\r
937                                 throw new AccessorException(e);\r
938                         }\r
939                 }\r
940 \r
941                 @Override\r
942                 public Object getLowerKey(Binding keyBinding, Object key)\r
943                                 throws AccessorException {\r
944                         try {\r
945                                 MutableVariant result = server.getLowerKey(accId, new MutableVariant(keyBinding, key));\r
946                                 if (result.type().equals(Datatypes.VOID)) return null;\r
947                                 return result.getValue(keyBinding);\r
948                         } catch (WireException e) {\r
949                                 throw new AccessorException(e);\r
950                         } catch (AdaptException e) {\r
951                                 throw new AccessorException(e);\r
952                         }\r
953                 }\r
954 \r
955                 @Override\r
956                 public Object getFloorKey(Binding keyBinding, Object key)\r
957                                 throws AccessorException {\r
958                         try {\r
959                                 MutableVariant result = server.getFloorKey(accId, new MutableVariant(keyBinding, key));\r
960                 if (result.type() == Datatypes.VOID) return null;\r
961                                 return result.getValue(keyBinding);\r
962                         } catch (WireException e) {\r
963                                 throw new AccessorException(e);\r
964                         } catch (AdaptException e) {\r
965                                 throw new AccessorException(e);\r
966                         }\r
967                 }\r
968 \r
969                 @Override\r
970                 public Object getCeilingKey(Binding keyBinding, Object key)\r
971                                 throws AccessorException {\r
972                         try {\r
973                                 MutableVariant result = server.getCeilingKey(accId, new MutableVariant(keyBinding, key));\r
974                 if (result.type().equals(Datatypes.VOID)) return null;\r
975                                 return result.getValue(keyBinding);\r
976                         } catch (WireException e) {\r
977                                 throw new AccessorException(e);\r
978                         } catch (AdaptException e) {\r
979                                 throw new AccessorException(e);\r
980                         }\r
981                 }\r
982 \r
983                 @Override\r
984                 public Object getHigherKey(Binding keyBinding, Object key)\r
985                                 throws AccessorException {\r
986                         try {\r
987                                 MutableVariant result = server.getHigherKey(accId, new MutableVariant(keyBinding, key));\r
988                 if (result.type().equals(Datatypes.VOID)) return null;\r
989                                 return result.getValue(keyBinding);\r
990                         } catch (WireException e) {\r
991                                 throw new AccessorException(e);\r
992                         } catch (AdaptException e) {\r
993                                 throw new AccessorException(e);\r
994                         }\r
995                 }\r
996                 \r
997         }\r
998         \r
999         class WireOptional extends WireAccessor implements OptionalAccessor {\r
1000 \r
1001                 WireOptional(int accId, Datatype type, ChildReference ref) {\r
1002                         super(accId, type, ref);\r
1003                 }\r
1004                 \r
1005                 @Override\r
1006                 public OptionalType type() { \r
1007                         return (OptionalType) type;\r
1008                 }                               \r
1009 \r
1010                 @Override\r
1011                 public void setNoValue() throws AccessorException {\r
1012                         applyEvent( new OptionalValueRemoved() );\r
1013                 }\r
1014 \r
1015                 @Override\r
1016                 public boolean hasValue() throws AccessorException {\r
1017                         try {\r
1018                                 return server.hasValue(accId);\r
1019                         } catch (WireException e) {\r
1020                                 throw new AccessorException( e );                               \r
1021                         }\r
1022                 }\r
1023 \r
1024                 @Override\r
1025                 public Object getComponentValue(Binding componentBinding)\r
1026                                 throws AccessorException {\r
1027                         try {\r
1028                                 WireAccessor sa = createAccessor( new ComponentReference() );\r
1029                                 try {\r
1030                                         return sa.getValue(componentBinding);\r
1031                                 } finally {\r
1032                                         sa.close();\r
1033                                 }\r
1034                         } catch (WireException e) {\r
1035                                 throw new AccessorException( e );                               \r
1036                         }\r
1037                 }\r
1038 \r
1039                 @Override\r
1040                 public void setComponentValue(Binding binding, Object value)\r
1041                                 throws AccessorException {                      \r
1042                         applyEvent(new OptionalValueAssigned(binding, value));\r
1043                 }\r
1044 \r
1045                 @SuppressWarnings("unchecked")\r
1046                 @Override\r
1047                 public <T extends Accessor> T getComponentAccessor()\r
1048                                 throws AccessorConstructionException {\r
1049                         return (T) getComponent( new ComponentReference() );\r
1050                 }\r
1051                 \r
1052         }\r
1053         \r
1054         class WireRecord extends WireAccessor implements RecordAccessor {\r
1055 \r
1056                 WireRecord(int accId, Datatype type, ChildReference ref) {\r
1057                         super(accId, type, ref);\r
1058                 }\r
1059                 \r
1060                 @Override\r
1061                 public RecordType type() { \r
1062                         return (RecordType) type;\r
1063                 }               \r
1064 \r
1065                 @Override\r
1066                 public int count() throws AccessorException {                   \r
1067                         try {\r
1068                                 return server.size(accId);\r
1069                         } catch (WireException e) {\r
1070                                 throw new AccessorException(e);\r
1071                         }\r
1072                 }\r
1073 \r
1074                 @SuppressWarnings("unchecked")\r
1075                 @Override\r
1076                 public <T extends Accessor> T getFieldAccessor(int index)\r
1077                                 throws AccessorConstructionException {\r
1078                         return (T) getComponent( new IndexReference(index) );\r
1079                 }\r
1080 \r
1081                 @SuppressWarnings("unchecked")\r
1082                 @Override\r
1083                 public <T extends Accessor> T getFieldAccessor(String fieldName)\r
1084                                 throws AccessorConstructionException {\r
1085                         return (T) getComponent( new NameReference( fieldName ) );\r
1086                 }\r
1087 \r
1088                 @Override\r
1089                 public Object getFieldValue(String fieldName, Binding fieldBinding)\r
1090                                 throws AccessorException {\r
1091                         int fieldIndex = type().getComponentIndex(fieldName);\r
1092                         if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");\r
1093                         return getFieldValue(fieldIndex, fieldBinding);\r
1094                 }\r
1095                 \r
1096                 @Override\r
1097                 public Object getFieldValue(int index, Binding fieldBinding)\r
1098                                 throws AccessorException {\r
1099                         try {\r
1100                                 WireAccessor sa = createAccessor( new IndexReference(index) );\r
1101                                 try {\r
1102                                         return sa.getValue(fieldBinding);\r
1103                                 } finally {\r
1104                                         sa.close();\r
1105                                 }\r
1106                         } catch (WireException e) {\r
1107                                 throw new AccessorException( e );                               \r
1108                         }\r
1109                 }\r
1110                 \r
1111                 public void setFieldValue(String fieldName, Binding fieldBinding, Object value) throws AccessorException {\r
1112                         int fieldIndex = type().getComponentIndex(fieldName);\r
1113                         if (fieldIndex<0) throw new AccessorException("Field "+fieldName+" does not exist");\r
1114                         setFieldValue(fieldIndex, fieldBinding, value);\r
1115                 };\r
1116 \r
1117                 @Override\r
1118                 public void setFieldValue(int index, Binding fieldBinding, Object value)\r
1119                                 throws AccessorException {\r
1120                         try {\r
1121                                 WireAccessor sa = createAccessor( new IndexReference(index) );\r
1122                                 try {\r
1123                                         sa.setValue(fieldBinding, value);\r
1124                                 } finally {\r
1125                                         sa.close();\r
1126                                 }\r
1127                         } catch (WireException e) {\r
1128                                 throw new AccessorException( e );                               \r
1129                         }\r
1130                 }\r
1131                 \r
1132         }\r
1133         \r
1134         class WireString extends WireAccessor implements StringAccessor {\r
1135 \r
1136                 WireString(int accId, Datatype type, ChildReference ref) {\r
1137                         super(accId, type, ref);\r
1138                 }\r
1139 \r
1140                 @Override\r
1141                 public StringType type() { \r
1142                         return (StringType) type;\r
1143                 }               \r
1144 \r
1145                 @Override\r
1146                 public String getValue() throws AccessorException {\r
1147                         try {\r
1148                                 MutableVariant value = server.getValue(accId);\r
1149                                 return (String) value.getValue( Bindings.STRING );\r
1150                         } catch (WireException e) {\r
1151                                 throw new AccessorException( e );\r
1152                         } catch (AdaptException e) {\r
1153                                 throw new AccessorException( e );\r
1154                         }\r
1155                 }\r
1156 \r
1157                 @Override\r
1158                 public void setValue(String newValue) throws AccessorException {\r
1159                         Event e = new ValueAssigned( Bindings.STRING, newValue); \r
1160                         Event[] list = new Event[] {e};\r
1161                         ApplyResult result = server.apply(accId, list, false);\r
1162                         if (result.error != null) throw new AccessorException( result.error );\r
1163                 }\r
1164                 \r
1165         }\r
1166         \r
1167         class WireUnion extends WireAccessor implements UnionAccessor {\r
1168 \r
1169                 WireUnion(int accId, Datatype type, ChildReference ref) {\r
1170                         super(accId, type, ref);\r
1171                 }\r
1172                 \r
1173                 @Override\r
1174                 public UnionType type() { \r
1175                         return (UnionType) type;\r
1176                 }                               \r
1177 \r
1178                 @Override\r
1179                 public int count() throws AccessorException {\r
1180                         try {\r
1181                                 return server.size(accId);\r
1182                         } catch (WireException e) {\r
1183                                 throw new AccessorException(e);\r
1184                         }\r
1185                 }\r
1186 \r
1187                 @Override\r
1188                 public int getTag() throws AccessorException {\r
1189                         try {\r
1190                                 return server.getTag(accId);\r
1191                         } catch (WireException e) {\r
1192                                 throw new AccessorException(e);\r
1193                         }\r
1194                 }\r
1195 \r
1196                 @SuppressWarnings("unchecked")\r
1197                 @Override\r
1198                 public <T extends Accessor> T getComponentAccessor()\r
1199                                 throws AccessorConstructionException {\r
1200                         return (T) getComponent(new ComponentReference());\r
1201                 }\r
1202 \r
1203                 @Override\r
1204                 public Object getComponentValue(Binding componentBinding)\r
1205                                 throws AccessorException {\r
1206                         try {\r
1207                                 WireAccessor sa = createAccessor( new ComponentReference() );\r
1208                                 try {\r
1209                                         return sa.getValue(componentBinding);\r
1210                                 } finally {\r
1211                                         sa.close();\r
1212                                 }\r
1213                         } catch (WireException e) {\r
1214                                 throw new AccessorException( e );                               \r
1215                         }\r
1216                 }\r
1217 \r
1218                 @Override\r
1219                 public void setComponentValue(int tag, Binding componentBinding,\r
1220                                 Object componentValue) throws AccessorException {\r
1221                         try {\r
1222                                 WireAccessor sa = createAccessor( new ComponentReference() );\r
1223                                 try {\r
1224                                         sa.setValue(componentBinding, componentValue);\r
1225                                 } finally {\r
1226                                         sa.close();\r
1227                                 }\r
1228                         } catch (WireException e) {\r
1229                                 throw new AccessorException( e );                               \r
1230                         }                       \r
1231                         \r
1232                 }\r
1233                 \r
1234         }\r
1235         \r
1236         class WireVariant extends WireAccessor implements VariantAccessor {\r
1237 \r
1238                 WireVariant(int accId, Datatype type, ChildReference ref) {\r
1239                         super(accId, type, ref);\r
1240                 }\r
1241 \r
1242                 @Override\r
1243                 public VariantType type() { \r
1244                         return (VariantType) type;\r
1245                 }               \r
1246                 \r
1247                 @SuppressWarnings("unchecked")\r
1248                 @Override\r
1249                 public <T extends Accessor> T getContentAccessor()\r
1250                                 throws AccessorConstructionException {\r
1251                         return (T) getComponent(new ComponentReference());\r
1252                 }\r
1253 \r
1254                 @Override\r
1255                 public void setContentValue(Binding valueBinding, Object value)\r
1256                                 throws AccessorException {\r
1257                         try {\r
1258                                 WireAccessor sa = createAccessor( new ComponentReference() );\r
1259                                 try {\r
1260                                         sa.setValue(valueBinding, value);\r
1261                                 } finally {\r
1262                                         sa.close();\r
1263                                 }\r
1264                         } catch (WireException e) {\r
1265                                 throw new AccessorException( e );                               \r
1266                         }\r
1267                 }\r
1268 \r
1269                 @Override\r
1270                 public Object getContentValue(Binding contentBinding)\r
1271                                 throws AccessorException {\r
1272                         try {\r
1273                                 WireAccessor sa = createAccessor( new ComponentReference() );\r
1274                                 try {\r
1275                                         return sa.getValue(contentBinding);\r
1276                                 } finally {\r
1277                                         sa.close();\r
1278                                 }\r
1279                         } catch (WireException e) {\r
1280                                 throw new AccessorException( e );                               \r
1281                         }\r
1282                 }\r
1283 \r
1284                 @Override\r
1285                 public Datatype getContentType() throws AccessorException {\r
1286                         try {\r
1287                                 WireAccessor sa = createAccessor( new ComponentReference() );\r
1288                                 try {\r
1289                                         return sa.type();\r
1290                                 } finally {\r
1291                                         sa.close();\r
1292                                 }\r
1293                         } catch (WireException e) {\r
1294                                 throw new AccessorException( e );                               \r
1295                         }\r
1296                 }\r
1297                 \r
1298         }\r
1299 \r
1300         \r
1301 }\r
1302 \r