]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSourceRequest.java
Fail safe import fixes made by Antti
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / ModelTransferableGraphSourceRequest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.util;
13
14 import java.io.BufferedOutputStream;
15 import java.io.DataOutput;
16 import java.io.DataOutputStream;
17 import java.io.File;
18 import java.io.FileNotFoundException;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.lang.management.ManagementFactory;
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.UUID;
29
30 import org.apache.commons.io.output.DeferredFileOutputStream;
31 import org.eclipse.core.runtime.IProgressMonitor;
32 import org.eclipse.core.runtime.OperationCanceledException;
33 import org.eclipse.core.runtime.SubMonitor;
34 import org.simantics.databoard.Bindings;
35 import org.simantics.databoard.Datatypes;
36 import org.simantics.databoard.accessor.error.AccessorException;
37 import org.simantics.databoard.binding.Binding;
38 import org.simantics.databoard.binding.error.BindingException;
39 import org.simantics.databoard.binding.mutable.Variant;
40 import org.simantics.databoard.parser.repository.DataTypeSyntaxError;
41 import org.simantics.databoard.serialization.RuntimeSerializerConstructionException;
42 import org.simantics.databoard.type.Datatype;
43 import org.simantics.databoard.util.binary.BinaryFile;
44 import org.simantics.databoard.util.binary.BinaryMemory;
45 import org.simantics.databoard.util.binary.DeferredBinaryFile;
46 import org.simantics.databoard.util.binary.NullRandomAccessBinary;
47 import org.simantics.databoard.util.binary.RandomAccessBinary;
48 import org.simantics.db.DirectStatements;
49 import org.simantics.db.ReadGraph;
50 import org.simantics.db.RequestProcessor;
51 import org.simantics.db.Resource;
52 import org.simantics.db.Statement;
53 import org.simantics.db.common.request.UniqueRead;
54 import org.simantics.db.common.utils.NameUtils;
55 import org.simantics.db.exception.CancelTransactionException;
56 import org.simantics.db.exception.DatabaseException;
57 import org.simantics.db.exception.ValidationException;
58 import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
59 import org.simantics.db.layer0.internal.SimanticsInternal;
60 import org.simantics.db.service.ClusterControl;
61 import org.simantics.db.service.ClusterControl.ClusterState;
62 import org.simantics.db.service.ClusteringSupport;
63 import org.simantics.db.service.CollectionSupport;
64 import org.simantics.db.service.DirectQuerySupport;
65 import org.simantics.db.service.SerialisationSupport;
66 import org.simantics.graph.representation.Extensions;
67 import org.simantics.graph.utils.TGResourceUtil;
68 import org.simantics.graph.utils.TGResourceUtil.LongAdapter;
69 import org.simantics.layer0.Layer0;
70 import org.simantics.utils.threads.logger.ITask;
71 import org.simantics.utils.threads.logger.ThreadLogger;
72
73 import gnu.trove.list.array.TIntArrayList;
74 import gnu.trove.map.hash.TIntIntHashMap;
75 import gnu.trove.map.hash.TLongObjectHashMap;
76 import gnu.trove.procedure.TIntProcedure;
77 import gnu.trove.procedure.TLongObjectProcedure;
78 import gnu.trove.set.hash.TIntHashSet;
79
80 public class ModelTransferableGraphSourceRequest extends UniqueRead<ModelTransferableGraphSource> {
81
82         public static String LOG_FILE = "transferableGraph.log";
83         final static boolean LOG = false;
84         final static private boolean DEBUG = false;
85         final static boolean PROFILE = false;
86         
87         private TransferableGraphConfiguration2 configuration;
88         private SubMonitor monitor;
89         
90         static DataOutput log;
91
92         static {
93
94                 if (LOG) {
95                         try {
96                                 FileOutputStream stream = new FileOutputStream(LOG_FILE);
97                                 log = new DataOutputStream(stream);
98                         } catch (FileNotFoundException e) {
99                                 e.printStackTrace();
100                         }
101                 }
102
103         }
104         
105         static void log(String line) {
106                 if (LOG) {
107                         try {
108                                 log.writeUTF(line + "\n");
109                         } catch (IOException e) {
110                                 e.printStackTrace();
111                         }
112                 }
113         }
114
115     public ModelTransferableGraphSourceRequest(TransferableGraphConfiguration2 conf) {
116         this(null, conf);
117     }
118
119     public ModelTransferableGraphSourceRequest(IProgressMonitor monitor, TransferableGraphConfiguration2 conf) {
120         this.monitor = SubMonitor.convert(monitor);
121         this.configuration = conf;
122     }
123
124         Layer0 L0;
125         
126         int statements[];
127         int statementIndex = 0;
128         TIntIntHashMap ids;
129         TIntArrayList externalParents = new TIntArrayList();
130         ArrayList<String> externalNames = new ArrayList<String>();
131         
132         int id = 0;
133         int indent = 0;
134
135         private SerialisationSupport support;
136
137         private Resource getResource(int r) throws DatabaseException {
138                 return support.getResource(r);
139         }
140         
141         public int getInternalId(int r) {
142                 return ids.get(r);
143         }
144         
145         public boolean validateExternal(Resource ext) {
146                 ExtentStatus status = configuration.preStatus.get(ext);
147                 if(status != null) {
148                         if(ExtentStatus.INTERNAL.equals(status)) return false;
149                         else if(ExtentStatus.EXCLUDED.equals(status)) return false;
150                 }
151                 return true;
152         }
153         
154         /*
155          * 
156          * @return -2 if r is not really external and the statement should be excluded
157          * 
158          */
159         public int getId(ReadGraph graph, int r) throws DatabaseException {
160                 if(ids.containsKey(r)) {
161                     int ret = ids.get(r);
162                     if(ret == -1) {
163                         for(int i=0;i<=indent;++i)
164                             System.out.print("  ");
165                         System.out.println("Cycle!!!"); // with " + GraphUtils.getReadableName(g, r));
166                     }
167                         return ret;
168                 }
169                 else {
170             if(!validateExternal(getResource(r))) return -2;
171                         Collection<Resource> parents = graph.getObjects(getResource(r), L0.PartOf);                     
172                         if(parents.size() != 1) {
173                                 throw new ValidationException("Reference to external resource " 
174                                                 + NameUtils.getSafeName(graph, getResource(r), true) + " without unique uri (" + parents.size() + " parents).");
175                         }
176                         for(Resource p : parents) {
177                             ++indent;
178                             int pid = getId(graph, support.getTransientId(p));
179                             if(pid == -2) return -2;
180                                 externalParents.add(pid);
181                                 --indent;
182                         }
183             externalNames.add((String)graph.getRelatedValue(getResource(r), L0.HasName));
184                         ids.put(r, id);
185                         return id++;
186                 }
187         }
188         
189         @Override
190         public ModelTransferableGraphSource perform(ReadGraph graph) throws DatabaseException {
191
192                 support = graph.getService(SerialisationSupport.class);
193
194                 this.L0 = Layer0.getInstance(graph);
195
196                 long total = System.nanoTime();
197         long startupTime = System.nanoTime();
198         long startupTimeEnd = System.nanoTime();
199                 long domainTime = System.nanoTime();
200                 
201                 String otherStatements = "other" + UUID.randomUUID().toString();
202                 String valueFileName = "value" + UUID.randomUUID().toString();
203                 
204                 File base_ = SimanticsInternal.getTemporaryDirectory();
205         File base = new File(base_, "exports");
206         base.mkdirs();
207                 
208         File otherStatementsFile = new File(base, otherStatements);
209         File valueFile = new File(base, valueFileName);
210         
211 //        System.err.println("f: " + otherStatementsFile.getAbsolutePath());
212         
213         try {
214                 DeferredFileOutputStream otherStatementsStream = new DeferredFileOutputStream(1024*1024, otherStatementsFile);
215
216                 DataOutputStream otherStatementsOutput = new DataOutputStream(new BufferedOutputStream(otherStatementsStream, 1024*1024));
217                 DeferredBinaryFile valueOutput = new DeferredBinaryFile(valueFile, 1024*1024, 128*1024);
218
219                 ClusterControl cc = graph.getService(ClusterControl.class);
220                 ClusterState clusterState = cc.getClusterState();
221
222                 TIntHashSet excludedShared = new TIntHashSet();
223
224                 ids = new TIntIntHashMap(1000, 0.75f);
225
226                 DomainProcessorState state = new DomainProcessorState();
227                 state.extensions.putAll(configuration.baseExtensions);
228                 state.ids = ids;
229                 state.statementsOutput = otherStatementsOutput;
230                 state.valueOutput = valueOutput;
231                 state.valueCount = 0;
232                 state.excludedShared = excludedShared;
233             state.monitor = monitor;
234             state.valueModifier = composeTGValueModifier(configuration.valueModifiers);
235
236                 getDomain2(graph, configuration, state, configuration.ignoreVirtualResources);
237
238                 id = ids.size();
239
240                 cc.restoreClusterState(clusterState);
241
242                 otherStatementsOutput.flush();
243                 otherStatementsOutput.close();
244
245                 // Do not close valueOutput, just flush it and reuse it in
246                 // ModelTransferableGraphSource for reading.
247                 valueOutput.flush();
248
249                 long domainDuration = System.nanoTime() - domainTime;
250
251                 state.id = id;
252             state.otherStatementsInput = toRandomAccessBinary(otherStatementsStream, 128*1024);
253             state.valueInput = toRandomAccessBinary(valueOutput);
254             state.statementsOutput = null;
255             state.valueOutput = null;
256
257                 long totalEnd = System.nanoTime();
258
259                 if(PROFILE) {   
260                         System.out.println("startup in " + 1e-9*(startupTimeEnd - startupTime) + "s.");
261                         System.out.println("domain was found in " + 1e-9*(domainDuration) + "s.");
262                         System.out.println("total time for building subgraph was " + 1e-9*(totalEnd-total) + "s.");
263                 }
264                 
265                 return getSource(graph, configuration, state, otherStatementsFile, valueFile);
266                 
267         } catch (DatabaseException e) {
268                 throw e;
269         } catch (IOException e) {
270                 throw new DatabaseException(e.getMessage(), e);
271         } catch (Throwable e) {
272                 dumpHeap("crash.hprof");
273                 throw new DatabaseException(e.getMessage(), e);
274         }
275                 
276         }
277         
278         protected ModelTransferableGraphSource getSource(ReadGraph graph, TransferableGraphConfiguration2 configuration, DomainProcessorState state, File otherStatementsFile, File valueFile) throws DatabaseException {
279         return new ModelTransferableGraphSource(graph, configuration, state, otherStatementsFile, valueFile);
280         }
281
282         private TGValueModifier composeTGValueModifier(Collection<TGValueModifier> configuredModifiers) {
283                 List<TGValueModifier> valueModifiers = configuredModifiers == null ? new ArrayList<>(2) : new ArrayList<>(configuredModifiers.size() + 2);
284                 valueModifiers.add(new ResourceTGValueModifier(support));
285                 valueModifiers.add(RevisionTGValueModifier.INSTANCE);
286                 return new ComposedTGValueModifier(valueModifiers.toArray(new TGValueModifier[valueModifiers.size()]));
287         }
288
289     private static RandomAccessBinary toRandomAccessBinary(DeferredFileOutputStream stream, int bufferSize) throws IOException {
290         if (stream.isInMemory())
291             return new BinaryMemory(stream.getData());
292         return new BinaryFile(stream.getFile(), bufferSize);
293     }
294
295     private static RandomAccessBinary toRandomAccessBinary(DeferredBinaryFile file) throws IOException {
296         RandomAccessBinary b = file.getBackend();
297         long size = b.position();
298         b.position(0);
299         if (b instanceof BinaryMemory) {
300             b.setLength(size);
301         }
302         return b;
303     }
304
305         public static DomainOnlyProcessor getDomainOnly(RequestProcessor processor, IProgressMonitor monitor, final Resource resource) throws DatabaseException {
306                 return getDomainOnly(processor, monitor, Collections.singletonList(resource));
307         }
308
309         public static DomainOnlyProcessor getDomainOnly(RequestProcessor processor, final IProgressMonitor monitor, final Collection<Resource> resources) throws DatabaseException {
310
311                 return processor.syncRequest(new UniqueRead<DomainOnlyProcessor>() {
312
313                         @Override
314                         public DomainOnlyProcessor perform(ReadGraph graph) throws DatabaseException {
315
316                                 try {
317
318                                         TransferableGraphConfiguration2 conf = TransferableGraphConfiguration2.createWithResources(graph, resources, Collections.<Resource>emptyList()); 
319
320                                         DomainProcessorState state = new DomainProcessorState();
321                                         state.extensions.putAll(conf.baseExtensions);
322                                         state.ids = new TIntIntHashMap(1000, 0.75f);
323                                         state.statementsOutput = new DataOutputStream(new NullOutputStream());
324                                         state.valueOutput = new NullRandomAccessBinary();
325                                         state.valueCount = 0;
326                                         state.excludedShared = new TIntHashSet();
327                                         state.monitor = SubMonitor.convert(monitor);
328
329                                         return getDomainOnly(graph, conf, state, conf.ignoreVirtualResources);
330
331                                 } catch (OperationCanceledException e) {
332                                         
333                                         return null;
334
335                                 }
336
337                         }
338
339                 });
340
341         }
342     
343     public static class DomainOnlyProcessor extends DomainProcessor3 {
344
345         final Resource instanceOf;
346         final public List<Resource> internals;
347         final public List<Resource> internalTypes;
348         
349         private int counter = 0;
350         
351                 public DomainOnlyProcessor(ReadGraph graph, TransferableGraphConfiguration2 conf, DomainProcessorState state, boolean ignoreVirtual) throws DatabaseException {
352                         super(graph, conf, state, ignoreVirtual);
353                         CollectionSupport cs = graph.getService(CollectionSupport.class);
354                         internals = cs.createList();
355                         internalTypes = cs.createList();
356                         instanceOf = Layer0.getInstance(graph).InstanceOf;
357                 }
358                 
359                 @Override
360                 final public void addToStream(Resource predicate, Resource object) throws DatabaseException {
361                 }
362                 
363                 @Override
364                 public void flushStatementStream(int sId, DomainProcessorState state) throws IOException {
365                 }
366                 
367                 @Override
368                 public void processValue(ReadGraph graph, Resource subject, int sId, DomainProcessorState state) throws DatabaseException, IOException {
369                 }
370                 
371                 @Override
372                 public void processInternal(ReadGraph graph, Resource subject, DirectStatements stms, DomainProcessorState state) throws DatabaseException, IOException {
373                         
374                         if((counter++ & 1023) == 0)
375                                 if(state.monitor != null)
376                                         if(state.monitor.isCanceled())
377                                                 throw new CancelTransactionException();
378                         
379                         super.processInternal(graph, subject, stms, state);
380                         
381                         internals.add(subject);
382                         
383                         Resource singleType = null;
384                         for(Statement s : stms) {
385                                 if(instanceOf.equals(s.getPredicate())) {
386                                         if(singleType != null) {
387                                                 internalTypes.add(null);
388                                                 return;
389                                         } else {
390                                                 singleType = s.getObject();
391                                         }
392                                 }
393                         }
394                         
395                         internalTypes.add(singleType);
396                         
397                 }
398                 
399         
400     }
401         
402         public static DomainOnlyProcessor getDomainOnly(final ReadGraph graph , final TransferableGraphConfiguration2 conf, DomainProcessorState state, boolean ignoreVirtual) throws DatabaseException {
403
404                 final DomainOnlyProcessor processor = new DomainOnlyProcessor(graph, conf, state, ignoreVirtual);
405                 getDomain2(graph, state, processor);
406                 return processor;
407                 
408         }
409
410     public static DomainProcessor3 getDomain2(final ReadGraph graph , final TransferableGraphConfiguration2 conf, DomainProcessorState state, boolean ignoreVirtual) throws DatabaseException {
411
412                 ITask task = ThreadLogger.getInstance().begin("getDomain2");
413
414                 final DomainProcessor3 processor = new DomainProcessor3(graph, conf, state, ignoreVirtual);
415                 
416                 getDomain2(graph, state, processor);
417                 
418                 final SerialisationSupport support = graph.getService(SerialisationSupport.class);
419                 final ClusteringSupport cls = graph.getService(ClusteringSupport.class);
420                 final Resource indexRoot = processor.conf.indexRoot;
421
422                 if (state.monitor.isCanceled())
423                         throw new CancelTransactionException();
424
425                 TLongObjectHashMap<TIntArrayList> clusterMap = new TLongObjectHashMap<TIntArrayList>();
426                 for(Resource r : processor.status.keySet()) {
427                         ExtentStatus status = processor.status.get(r);
428                         int transientId = support.getTransientId(r);
429                         if(ExtentStatus.INTERNAL == status) {
430                                 long cluster = cls.getCluster(r);
431                                 TIntArrayList list = clusterMap.get(cluster);
432                                 if(list == null) {
433                                         list = new TIntArrayList();
434                                         clusterMap.put(cluster, list);
435                                 }
436                                 list.add(transientId);
437                         } else if(ExtentStatus.EXTERNAL == status) {
438                                 state.externals.add(transientId);
439                         } else if(ExtentStatus.PENDING == status) {
440                                 String uri = graph.getPossibleURI(r);
441                                 if(uri != null)
442                                         state.externals.add(transientId);
443                                 else {
444                                         state.pending.add(transientId);
445                                         System.err.println("Pending status in export: " + NameUtils.getSafeName(graph, r, true) + " (" + graph.getPossibleURI(r) + ")");
446                                 }
447                         }
448                 }
449
450                 if (state.monitor.isCanceled())
451                         throw new CancelTransactionException();
452
453                 final TIntArrayList clustering = new TIntArrayList();
454                 clusterMap.forEachEntry(new TLongObjectProcedure<TIntArrayList>() {
455                         
456                         @Override
457                         public boolean execute(long cluster, TIntArrayList b) {
458                                 clustering.add(b.size());
459                                 b.forEach(new TIntProcedure() {
460                                         
461                                         @Override
462                                         public boolean execute(int rId) {
463                                                 processor.ids.put(rId, processor.id++);
464                                                 return true;
465                                         }
466                                         
467                                 });
468                                 return true;
469                         }
470                         
471                 });
472
473                 if (state.monitor.isCanceled())
474                         throw new CancelTransactionException();
475
476                 final TIntArrayList clusterSets = new TIntArrayList();
477                 clusterMap.forEachEntry(new TLongObjectProcedure<TIntArrayList>() {
478                         
479                         @Override
480                         public boolean execute(long cluster, TIntArrayList b) {
481                                 try {
482                                         Resource clusterSet = cls.getClusterSetOfCluster(cluster);
483                                         if(clusterSet != null) {
484                                                 int transientId = support.getTransientId(clusterSet);
485                                                 if(processor.ids.containsKey(transientId)) {
486                                                         clusterSets.add(processor.ids.get(transientId));
487                                                         return true;
488                                                 } else {
489                                                         if(graph.getRootLibrary().equals(clusterSet)) {
490                                                                 clusterSets.add(Extensions.ROOT_LIBRARY_CLUSTER_SET);
491                                                                 return true;
492                                                         } else if (clusterSet.equals(indexRoot)) {
493                                                                 clusterSets.add(Extensions.INDEX_ROOT_CLUSTER_SET);
494                                                                 return true;
495                                                         }
496                                                 }
497                                         }
498                                 } catch (DatabaseException e) {
499                                 }
500                                 clusterSets.add(Extensions.NO_CLUSTER_SET);
501                                 return true;
502                                 
503                         }
504                         
505                 });
506                 
507                 state.extensions.put(Extensions.CLUSTERING, new Variant(Bindings.INT_ARRAY, clustering.toArray()));
508                 state.extensions.put(Extensions.CLUSTER_SETS, new Variant(Bindings.INT_ARRAY, clusterSets.toArray()));
509                 
510                 long total = processor.startupTime + processor.expandTime
511                                 + processor.classifyPredicateTime
512                                 + processor.processFringeTime + processor.extentSeedTime
513                                 + processor.fullResolveTime + processor.fastResolveTime + 
514                                 + processor.parentResolveTime + processor.otherStatementTime;
515
516                 if (PROFILE) {
517                         System.out.println("startup took " + 1e-9 * processor.startupTime + "s.");
518                         System.out.println("expand took " + 1e-9 * processor.expandTime + "s.");
519                         System.out.println("classifyPredicates took " + 1e-9 * processor.classifyPredicateTime + "s.");
520                         System.out.println("processFringe took " + 1e-9 * processor.processFringeTime + "s.");
521                         System.out.println("extentSeeding took " + 1e-9 * processor.extentSeedTime + "s.");
522                         System.out.println("fullResolve took " + 1e-9 * processor.fullResolveTime + "s.");
523                         System.out.println("fastResolve took " + 1e-9 * processor.fastResolveTime + "s.");
524                         System.out.println("parentResolve took " + 1e-9 * processor.parentResolveTime + "s.");
525                         System.out.println("otherStatements took " + 1e-9 * processor.otherStatementTime + "s.");
526                         System.out.println("value output took " + 1e-9 * processor.valueOutputTime + "s.");
527                         System.out.println("statement output took " + 1e-9 * processor.statementOutputTime + "s.");
528                         System.out.println("total " + 1e-9 * total + "s.");
529                 }
530
531                 task.finish();
532
533                 return processor;
534
535         }
536
537         public static DomainProcessor3 getDomain2(final ReadGraph graph , DomainProcessorState state, final DomainProcessor3 processor) throws DatabaseException {
538                 processor.process(graph, state);
539                 return processor;
540         }
541         
542         static class Expansion3 extends UniqueRead<Collection<DirectStatements>> {
543
544                 final private Collection<Resource> roots;
545                 final boolean ignoreVirtual;
546
547                 public Expansion3(Collection<Resource> roots, boolean ignoreVirtual) {
548                         this.roots = roots;
549                         this.ignoreVirtual = ignoreVirtual;
550                 }
551
552                 @Override
553                 public Collection<DirectStatements> perform(ReadGraph graph) {
554                         
555                         ArrayList<DirectStatements> result = new ArrayList<DirectStatements>();
556
557                         final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
558
559                         final DomainStatementProcedure3 proc = new DomainStatementProcedure3(result);
560
561                         if (ignoreVirtual) {
562                                 for(Resource r : roots) {
563                                         dqs.forEachDirectPersistentStatement(graph, r, proc);
564                                 }
565                         } else {
566                                 for(Resource r : roots) {
567                                         dqs.forEachDirectStatement(graph, r, proc);
568                                 }
569                         }
570                         
571                         return result;
572
573                 }
574
575         }       
576         private static void dumpHeap(String path) {
577                 
578         try {
579             Object bean = getBean();
580             if (bean == null)
581                 return;
582
583             Method m = bean.getClass().getMethod("dumpHeap", String.class, boolean.class);
584             m.invoke(bean, path, true);
585             
586         } catch (IllegalArgumentException e) {
587         } catch (IllegalAccessException e) {
588         } catch (SecurityException e) {
589         } catch (NoSuchMethodException e) {
590         } catch (InvocationTargetException e) {
591                 } finally {
592         }
593                 
594         }
595         
596     private static Object getBean() {
597         Class<?> beanClass = getBeanClass();
598         if (beanClass == null)
599             return null;
600         try {
601             Object bean = ManagementFactory.newPlatformMXBeanProxy(
602                     ManagementFactory.getPlatformMBeanServer(),
603                     "com.sun.management:type=HotSpotDiagnostic",
604                     beanClass);
605             return bean;
606         } catch (IOException e) {
607             return null;
608         }
609     }
610     
611     private static Class<?> getBeanClass() {
612         try {
613             Class<?> clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
614             return clazz;
615         } catch (ClassNotFoundException e) {
616             return null;
617         }
618     }
619
620     public static void main(String[] args) {
621                 
622         try {
623                 
624                         Datatype dt = Datatypes.translate("{ parts : ( | ResourceRVIPart { role : |CHILD|PROPERTY, resource : Long(unit=\"resource\") } | StringRVIPart { role : |CHILD|PROPERTY, string : String } ) [] }");
625                         Binding b = Bindings.getBinding(dt);
626                         Object value = b.createDefault();
627                         Variant variant = new Variant(b, value);
628                         TGResourceUtil util = new TGResourceUtil();
629                         LongAdapter la = new LongAdapter() {
630                                 @Override
631                                 public long adapt(long in) {
632                                         return in;
633                                 }                       
634                         };
635                         util.adaptValue( variant.getBinding(), variant.getValue(), la );
636                         
637                 } catch (DataTypeSyntaxError e) {
638                         e.printStackTrace();
639                 } catch (BindingException e) {
640                         e.printStackTrace();
641                 } catch (RuntimeSerializerConstructionException e) {
642                         e.printStackTrace();
643                 } catch (AccessorException e) {
644                         e.printStackTrace();
645                 }
646         
647         }
648     
649         
650 }