]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.export.core/src/org/simantics/export/core/impl/ExportExtensionPointImpl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.export.core / src / org / simantics / export / core / impl / ExportExtensionPointImpl.java
1 package org.simantics.export.core.impl;\r
2 \r
3 import java.io.File;\r
4 import java.lang.ref.WeakReference;\r
5 import java.net.MalformedURLException;\r
6 import java.net.URL;\r
7 import java.util.Arrays;\r
8 import java.util.Collection;\r
9 import java.util.Comparator;\r
10 import java.util.List;\r
11 import java.util.Map;\r
12 \r
13 import org.eclipse.core.runtime.CoreException;\r
14 import org.eclipse.core.runtime.IConfigurationElement;\r
15 import org.eclipse.core.runtime.Platform;\r
16 import org.eclipse.jface.resource.ImageDescriptor;\r
17 import org.osgi.service.prefs.Preferences;\r
18 import org.simantics.databoard.binding.mutable.Variant;\r
19 import org.simantics.databoard.type.RecordType;\r
20 import org.simantics.export.core.ExportContext;\r
21 import org.simantics.export.core.ExportExtensionPoint;\r
22 import org.simantics.export.core.error.ExportException;\r
23 import org.simantics.export.core.intf.ContentType;\r
24 import org.simantics.export.core.intf.ContentTypeAction;\r
25 import org.simantics.export.core.intf.DiscoverAction;\r
26 import org.simantics.export.core.intf.Discoverer;\r
27 import org.simantics.export.core.intf.ExportClass;\r
28 import org.simantics.export.core.intf.Exporter;\r
29 import org.simantics.export.core.intf.Format;\r
30 import org.simantics.export.core.intf.FormatClass;\r
31 import org.simantics.export.core.intf.IconResolver;\r
32 import org.simantics.export.core.intf.ImportAction;\r
33 import org.simantics.export.core.intf.Importer;\r
34 import org.simantics.export.core.intf.Publisher;\r
35 import org.simantics.export.core.intf.PublisherClass;\r
36 import org.simantics.export.core.manager.Content;\r
37 import org.simantics.utils.datastructures.ToStringComparator;\r
38 \r
39 /**\r
40  * Light-weight registry implementation to export extension point.\r
41  *\r
42  * @author toni.kalajainen@semantum.fi\r
43  */\r
44 public class ExportExtensionPointImpl implements ExportExtensionPoint {\r
45 \r
46         public static final String EP = "org.simantics.export.core.export";\r
47         \r
48         Importer[] importers = createImporters();\r
49         Exporter[] exporters = createExporters();\r
50         Format[] formats = createFormats();\r
51         ContentType[] contentTypes = createContentTypes();\r
52         Discoverer[] discoverers = createDiscoverers();\r
53         Publisher[] publishers = createPublishers();\r
54         \r
55         public ExportExtensionPointImpl() {}\r
56 \r
57         public Discoverer[] getDiscoverers(String contentTypeId) {\r
58                 int count = 0;\r
59                 for ( Discoverer discoverer : discoverers ) {\r
60                         if ( contentTypeId.equals( discoverer.contentTypeId() ) ) count++;\r
61                 }\r
62                 \r
63                 Discoverer[] result = new Discoverer[ count ];\r
64                 int i = 0;\r
65                 for ( Discoverer discoverer : discoverers ) {\r
66                         if ( contentTypeId.equals( discoverer.contentTypeId() ) ) {                             \r
67                                 result[ i++ ] = discoverer;\r
68                         }\r
69                 }\r
70                 return result;\r
71                 \r
72         }\r
73         \r
74         public Format getFormat(String formatId) \r
75         {\r
76                 for ( Format format : formats ) {\r
77                         if ( formatId.equals( format.id() ) ) return format;\r
78                 }\r
79                 return null;\r
80         }\r
81 \r
82         @Override\r
83         public Format getFormatByExt(String fileExt) {\r
84                 for ( Format format : formats ) {\r
85                         if ( fileExt.equals( format.fileext() ) ) return format;\r
86                 }\r
87                 return null;\r
88         }       \r
89         public ContentType getContentType(String contentTypeId) \r
90                         //throws ExportException \r
91         {\r
92                 for ( ContentType contentType : contentTypes ) {\r
93                         if ( contentTypeId.equals( contentType.id() ) ) return contentType;\r
94                 }\r
95                 //throw new ExportException("ContentType "+contentTypeId+" does not exist");\r
96                 return null;\r
97         }\r
98         \r
99         public Importer getImporter(String formatId) \r
100                         //throws ExportException \r
101         {\r
102                 for ( Importer importer : importers ) {\r
103                         if ( formatId.equals( importer.formatId() ) ) return importer;\r
104                 }\r
105                 //throw new ExportException("Importer "+formatId+" does not exist");\r
106                 return null;\r
107         }\r
108         \r
109         public Exporter[] getExporters(String formatId, String contentTypeId) \r
110         {\r
111                 int count = 0;\r
112                 for ( Exporter exporter : exporters ) {\r
113                         if ( exporter.formatId().equals(formatId) &&\r
114                              exporter.contentTypeId().equals(contentTypeId) ) count++;\r
115                 }\r
116                 Exporter[] result = new Exporter[ count ];\r
117                 int index = 0;\r
118                 for ( Exporter exporter : exporters ) {\r
119                         if ( formatId.equals( exporter.formatId() ) && contentTypeId.equals( exporter.contentTypeId() ) ) {\r
120                                 result[ index++ ] = exporter;\r
121                         }\r
122                 }\r
123                 \r
124                 return result;\r
125         }\r
126         \r
127         public Exporter[] getExportersForContentType(String contentTypeId) \r
128                         //throws ExportException \r
129         {\r
130                 int count = 0;\r
131                 for ( Exporter exporter : exporters ) {\r
132                         if ( contentTypeId.equals( exporter.contentTypeId() ) ) count++;\r
133                 }\r
134                 \r
135                 Exporter[] result = new Exporter[ count ];\r
136                 int i = 0;\r
137                 for ( Exporter exporter : exporters ) {\r
138                         if ( contentTypeId.equals( exporter.contentTypeId() ) ) {\r
139                                 result[ i++ ] = exporter;\r
140                         }\r
141                 }\r
142                 \r
143                 Arrays.sort(result, exporterPrioritySorter);\r
144                 \r
145                 return result;\r
146         }\r
147 \r
148         public Exporter[] getExportersForFormat(String formatId) \r
149         {\r
150                 int count = 0;\r
151                 for ( Exporter exporter : exporters ) {\r
152                         if ( formatId.equals( exporter.formatId() ) ) count++;\r
153                 }\r
154                 \r
155                 Exporter[] result = new Exporter[ count ];\r
156                 int i = 0;\r
157                 for ( Exporter exporter : exporters ) {\r
158                         if ( formatId.equals( exporter.formatId() ) ) {\r
159                                 result[ i++ ] = exporter;\r
160                         }\r
161                 }\r
162                 \r
163                 Arrays.sort(result, exporterPrioritySorter);\r
164                 \r
165                 return result;\r
166         }\r
167         \r
168         public Publisher getPublisher(String publisherId) {\r
169                 for ( Publisher publisher : publishers ) {\r
170                         if ( publisherId.equals( publisher.id() ) ) return publisher;\r
171                 }\r
172                 return null;\r
173         };\r
174         \r
175         public int getPublisherIndex(String publisherId) {\r
176                 for (int i=0; i<publishers.length; i++) {\r
177                         if ( publisherId.equals( publishers[i].id() ) ) return i;\r
178                 }\r
179                 return -1;\r
180         }\r
181         \r
182         public Publisher getPublisherByLabel(String publisherLabel) {\r
183                 for ( Publisher publisher : publishers ) {\r
184                         if ( publisher.label().equals(publisherLabel ) ) return publisher;\r
185                 }\r
186                 return null;\r
187         }\r
188         \r
189         ContentType[] createContentTypes() {\r
190                 IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
191                 int count = 0;\r
192                 for (IConfigurationElement ce : ces) {\r
193                         if ( "content_type".equals(ce.getName() ) ) count++;                    \r
194                 }\r
195                 \r
196                 ContentType[] result = new ContentType[count];\r
197                 int i=0;\r
198                 for (IConfigurationElement ce : ces) {\r
199                         if ( "content_type".equals(ce.getName() ) ) {\r
200                                 result[i++] = new ContentTypeImpl( ce );\r
201                         }\r
202                 }\r
203                 \r
204                 return result;\r
205         }\r
206 \r
207         Discoverer[] createDiscoverers() {\r
208                 IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
209                 int count = 0;\r
210                 for (IConfigurationElement ce : ces) {\r
211                         if ( "discoverer".equals(ce.getName() ) ) count++;                      \r
212                 }\r
213                 \r
214                 Discoverer[] result = new Discoverer[count];\r
215                 int i=0;\r
216                 for (IConfigurationElement ce : ces) {\r
217                         if ( "discoverer".equals(ce.getName() ) ) {\r
218                                 result[i++] = new DiscovererImpl( ce );\r
219                         }\r
220                 }\r
221                 \r
222                 return result;\r
223         }\r
224                 \r
225         Format[] createFormats() {\r
226                 IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
227                 int count = 0;\r
228                 for (IConfigurationElement ce : ces) {\r
229                         if ( "format".equals(ce.getName() ) ) count++;                  \r
230                 }\r
231                 \r
232                 Format[] result = new Format[count];\r
233                 int i=0;\r
234                 for (IConfigurationElement ce : ces) {\r
235                         if ( "format".equals(ce.getName() ) ) {\r
236                                 result[i++] = new FormatImpl( ce );\r
237                         }\r
238                 }\r
239                 \r
240                 return result;\r
241         }\r
242         \r
243         Exporter[] createExporters() {\r
244                 IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
245                 int count = 0;\r
246                 for (IConfigurationElement ce : ces) {\r
247                         if ( "exporter".equals(ce.getName() ) ) count++;                        \r
248                 }\r
249                 \r
250                 Exporter[] result = new Exporter[count];\r
251                 int i=0;\r
252                 for (IConfigurationElement ce : ces) {\r
253                         if ( "exporter".equals(ce.getName() ) ) {\r
254                                 result[i++] = new ExporterImpl( ce );\r
255                         }\r
256                 }\r
257                 \r
258                 return result;\r
259         }\r
260         \r
261         Importer[] createImporters() {\r
262                 IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
263                 int count = 0;\r
264                 for (IConfigurationElement ce : ces) {\r
265                         if ( "importer".equals(ce.getName() ) ) count++;                        \r
266                 }\r
267                 \r
268                 Importer[] result = new Importer[count];\r
269                 int i=0;\r
270                 for (IConfigurationElement ce : ces) {\r
271                         if ( "importer".equals(ce.getName() ) ) {\r
272                                 result[i++] = new ImporterImpl( ce );\r
273                         }\r
274                 }\r
275                 \r
276                 return result;\r
277         }\r
278         \r
279         Publisher[] createPublishers() {\r
280                 IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
281                 int count = 0;\r
282                 for (IConfigurationElement ce : ces) {\r
283                         if ( "publisher".equals(ce.getName() ) ) count++;                       \r
284                 }\r
285                 \r
286                 Publisher[] result = new Publisher[count];\r
287                 int i=0;\r
288                 for (IConfigurationElement ce : ces) {\r
289                         if ( "publisher".equals(ce.getName() ) ) {\r
290                                 result[i++] = new PublisherImpl( ce );\r
291                         }\r
292                 }\r
293                 \r
294                 Arrays.sort(result, new ToStringComparator.ByLength());\r
295                 \r
296                 return result;\r
297         }\r
298         \r
299         static class ContentTypeImpl implements ContentType {\r
300                 IConfigurationElement ce;\r
301                 ContentTypeAction action;\r
302                 WeakReference<IconResolver> resolverCache = null;\r
303                 boolean invalidIconResolver = false;\r
304 \r
305                 public ContentTypeImpl(IConfigurationElement ce) {\r
306                         this.ce = ce;\r
307                 }\r
308                 \r
309                 ContentTypeAction getOrCreate() throws ExportException {\r
310                         if ( action == null ) {\r
311                                 try {\r
312                                         String value = ce.getAttribute("contentTypeAction");\r
313                                         if ( value == null ) return new DefaultContentTypeAction();\r
314                                         action = (ContentTypeAction) ce.createExecutableExtension("contentTypeAction");\r
315                                 } catch (CoreException e) {\r
316                                         throw new ExportException( e );\r
317                                 } \r
318                         }\r
319                         return action;\r
320                 }               \r
321 \r
322                 @Override\r
323                 public String id() {                    \r
324                         return ce.getAttribute("id");\r
325                 }\r
326 \r
327                 @Override\r
328                 public String label() {\r
329                         return ce.getAttribute("label");\r
330                 }\r
331 \r
332                 @Override\r
333                 public String plural() {\r
334                         return ce.getAttribute("plural");\r
335                 }\r
336 \r
337                 public ImageDescriptor icon(String contentUri) {\r
338                         if (!invalidIconResolver && ce.getAttribute("iconResolver") != null) {\r
339                                 try {\r
340                                         IconResolver resolver = resolverCache != null ? resolverCache.get() : null;\r
341                                         if (resolver == null) {\r
342                                                 resolver = (IconResolver) ce.createExecutableExtension("iconResolver");\r
343                                                 resolverCache = new WeakReference<IconResolver>(resolver);\r
344                                         }\r
345                                         return resolver.get(contentUri);\r
346                                 } catch (CoreException e) {\r
347                                         // Invalid iconResolver, could not instantiate.\r
348                                         // Don't try to resolve it anymore if it fails once.\r
349                                         invalidIconResolver = true;\r
350                                         return null;\r
351                                 }\r
352                         }\r
353                         return icon();\r
354                 }\r
355                 \r
356                 @Override\r
357                 public ImageDescriptor icon() {\r
358                         try {\r
359                                 String _url = ce.getAttribute("icon");\r
360                                 URL url = new URL(_url);\r
361                                 return ImageDescriptor.createFromURL(url);\r
362                         } catch (MalformedURLException e) {\r
363                                 return null;\r
364                         }\r
365                 }\r
366 \r
367                 @Override\r
368                 public boolean isModel() {\r
369                         return "true".equalsIgnoreCase(ce.getAttribute("model"));\r
370                 }\r
371                 \r
372                 @Override\r
373                 public String toString() {\r
374                         return "ContentType, id="+id()+", label="+label();\r
375                 }\r
376 \r
377                 @Override\r
378                 public Map<String, String> getLabels(ExportContext ctx, Collection<String> contents) throws ExportException {\r
379                         ContentTypeAction action = getOrCreate();\r
380                         return action.getLabels(ctx, contents);\r
381                 }\r
382                 \r
383         }\r
384         \r
385         static class DiscovererImpl implements Discoverer {\r
386                 IConfigurationElement ce;\r
387                 DiscoverAction action;\r
388 \r
389                 public DiscovererImpl(IConfigurationElement ce) {\r
390                         this.ce = ce;\r
391                 }\r
392 \r
393                 @Override\r
394                 public String contentTypeId() {\r
395                         return ce.getAttribute("content_type_id");\r
396                 }\r
397                 \r
398                 DiscoverAction getOrCreate() throws ExportException {\r
399                         if ( action == null ) {\r
400                                 try {\r
401                                         action = (DiscoverAction) ce.createExecutableExtension("discoverAction");\r
402                                 } catch (CoreException e) {\r
403                                         throw new ExportException( e );\r
404                                 } \r
405                         }\r
406                         return action;\r
407                 }\r
408 \r
409 //              public Read<Collection<String>> discoverRequest(\r
410 //                              Collection<String> startLocations) throws ExportException {\r
411 //                      return getOrCreate().discoverRequest(startLocations);\r
412 //              }\r
413                 \r
414                 @Override\r
415                 public String toString() {\r
416                         try {\r
417                                 return "Discoverer, contentTypeId="+contentTypeId()+", class="+getOrCreate().getClass().getCanonicalName();\r
418                         } catch (ExportException e) {\r
419                                 return "Discoverer, contentTypeId="+contentTypeId();\r
420                         }\r
421                 }\r
422 \r
423                 @Override\r
424                 public Collection<String> discoverContent(ExportContext ctx, Collection<String> startLocations) throws ExportException {\r
425                         return getOrCreate().discoverContent(ctx, startLocations);\r
426                 }\r
427                 \r
428         }\r
429 \r
430         static class ExporterImpl implements Exporter {\r
431                 IConfigurationElement ce;\r
432                 ExportClass action;\r
433                 int priority = 0;\r
434 \r
435                 public ExporterImpl(IConfigurationElement ce) {\r
436                         this.ce = ce;\r
437                         String priorityStr = ce.getAttribute("exportPriority");\r
438                         if ( priorityStr!=null ) priority = Integer.valueOf(priorityStr);\r
439                 }\r
440 \r
441                 ExportClass getOrCreate() throws ExportException {\r
442                         if ( action == null ) {\r
443                                 try {\r
444                                         action = (ExportClass) ce.createExecutableExtension("exportAction");\r
445                                 } catch (CoreException e) {\r
446                                         throw new ExportException( e );\r
447                                 } \r
448                         }\r
449                         return action;\r
450                 }\r
451                 \r
452                 @Override\r
453                 public String formatId() {                      \r
454                         return ce.getAttribute("formatId");\r
455                 }\r
456                 \r
457                 @Override\r
458                 public String contentTypeId() {\r
459                         return ce.getAttribute("content_type_id");\r
460                 }\r
461 \r
462                 @Override\r
463                 public ExportClass exportAction() throws ExportException {\r
464                         return getOrCreate();\r
465                 }\r
466                 \r
467                 @Override\r
468                 public String toString() {\r
469                         try {\r
470                                 return "Exporter, formatId="+formatId()+", contentTypeId="+contentTypeId()+", class="+getOrCreate().getClass().getCanonicalName();\r
471                         } catch (ExportException e) {\r
472                                 return "Exporter, formatId="+formatId()+", contentTypeId="+contentTypeId();\r
473                         }\r
474                 }\r
475 \r
476                 @Override\r
477                 public int getExportPriority() {\r
478                         return priority;\r
479                 }\r
480                 \r
481         }\r
482 \r
483         static class ImporterImpl implements Importer {\r
484                 IConfigurationElement ce;\r
485 \r
486                 public ImporterImpl(IConfigurationElement ce) {\r
487                         this.ce = ce;\r
488                 }\r
489 \r
490                 @Override\r
491                 public String formatId() {                      \r
492                         return ce.getAttribute("formatId");\r
493                 }\r
494                 \r
495                 @Override\r
496                 public String contentTypeId() {\r
497                         return ce.getAttribute("content_type_id");\r
498                 }\r
499 \r
500                 @Override\r
501                 public ImportAction importAction() throws ExportException {\r
502                         try {\r
503                                 return (ImportAction) ce.createExecutableExtension("exportAction");\r
504                         } catch (CoreException e) {\r
505                                 throw new ExportException(e);\r
506                         }\r
507                 }\r
508                 \r
509                 @Override\r
510                 public String toString() {\r
511                         return "Importer, formatId="+formatId()+", contentTypeId="+contentTypeId();\r
512                 }\r
513                 \r
514         }\r
515         \r
516         \r
517         static class FormatImpl implements Format {\r
518                 IConfigurationElement ce;\r
519                 FormatClass formatClass;\r
520 \r
521                 public FormatImpl(IConfigurationElement ce) {\r
522                         this.ce = ce;\r
523                 }\r
524                 \r
525                 FormatClass getOrCreateFormatClass() throws ExportException {\r
526                         if ( formatClass == null ) {\r
527                                 try {\r
528                                         formatClass = (FormatClass) ce.createExecutableExtension("formatClass");\r
529                                 } catch (CoreException e) {\r
530                                         e.printStackTrace();                            \r
531                                         throw new ExportException( e );\r
532                                 } \r
533                         }\r
534                         return formatClass;\r
535                 }\r
536 \r
537                 @Override\r
538                 public String id() {                    \r
539                         return ce.getAttribute("id");\r
540                 }\r
541 \r
542                 @Override\r
543                 public String label() {\r
544                         return ce.getAttribute("label");\r
545                 }\r
546 \r
547                 @Override\r
548                 public String plural() {\r
549                         return ce.getAttribute("plural");\r
550                 }\r
551 \r
552                 @Override\r
553                 public ImageDescriptor icon() {\r
554                         try {\r
555                                 String _url = ce.getAttribute("icon");\r
556                                 URL url = new URL(_url);\r
557                                 return ImageDescriptor.createFromURL(url);\r
558                         } catch (MalformedURLException e) {\r
559                                 return null;\r
560                         }\r
561                 }\r
562 \r
563                 @Override\r
564                 public String fileext() {\r
565                         return ce.getAttribute("fileext");              \r
566                 }\r
567 \r
568                 @Override\r
569                 public Class<?> writerClass() throws ClassNotFoundException {\r
570                         String className = ce.getAttribute("writerClass");\r
571                         return Class.forName(className);\r
572                 }\r
573 \r
574                 @Override\r
575                 public Class<?> readerClass() throws ClassNotFoundException {\r
576                         String className = ce.getAttribute("readerClass");\r
577                         return Class.forName(className);\r
578                 }\r
579 \r
580                 @Override\r
581                 public boolean isGroupFormat() {                        \r
582                         return "true".equals(ce.getAttribute("isGroupFormat"));\r
583                 }\r
584                 \r
585                 @Override\r
586                 public boolean isContainerFormat() {\r
587                         return "true".equals(ce.getAttribute("isContainerFormat"));\r
588                 }\r
589                 \r
590                 @Override\r
591                 public boolean isAttachable() {\r
592                         return "true".equals(ce.getAttribute("isAttachable"));\r
593                 }               \r
594 \r
595                 @Override\r
596                 public boolean mergeGroupFormatDefault() {\r
597                         return "true".equals(ce.getAttribute("mergeGroupDefault"));             \r
598                 }\r
599 \r
600                 @Override\r
601                 public boolean isAlwaysPublished() {\r
602                         return "true".equals(ce.getAttribute("isAlwaysPublished"));\r
603                 }\r
604 \r
605                 @Override\r
606                 public boolean isLinkContainer() {\r
607                         return "true".equals(ce.getAttribute("isLinkContainer"));\r
608                 }       \r
609                 @Override\r
610                 public RecordType options( ExportContext context ) throws ExportException {\r
611                         return getOrCreateFormatClass().options(context);\r
612                 }\r
613 \r
614                 @Override\r
615                 public List<String> validate(ExportContext context, Variant options) throws ExportException {\r
616                         return getOrCreateFormatClass().validate(context, options);\r
617                 }\r
618                 \r
619                 @Override\r
620                 public void fillDefaultPrefs( ExportContext ctx, Variant options ) throws ExportException {\r
621                         getOrCreateFormatClass().fillDefaultPrefs( ctx, options );\r
622                 }\r
623 \r
624 \r
625                 @Override\r
626                 public String toString() {                      \r
627                         try {\r
628                                 return "Format, id="+id()+", fileext="+fileext()+", label="+label()+", class="+getOrCreateFormatClass().getClass().getCanonicalName();\r
629                         } catch (ExportException e) {\r
630                                 return "Format, id="+id()+", fileext="+fileext()+", label="+label();\r
631                         }                       \r
632                 }\r
633 \r
634                 @Override\r
635                 public Object createFile(ExportContext context, File outputFile, Variant options) throws ExportException {\r
636                         return getOrCreateFormatClass().createFile(context, outputFile, options);\r
637                 }\r
638 \r
639                 @Override\r
640                 public Object openFile(ExportContext context, File inputFile, Variant options) throws ExportException {\r
641                         return getOrCreateFormatClass().openFile(context, inputFile, options);\r
642                 }\r
643                 \r
644                 @Override\r
645                 public void closeFile(ExportContext context, Object handle) throws ExportException {\r
646                         getOrCreateFormatClass().closeFile(context, handle);\r
647                 }\r
648 \r
649                 @Override\r
650                 public void addAttachment(ExportContext context, Object handle, List<Content> attachments) throws ExportException {\r
651                         getOrCreateFormatClass().addAttachment(context, handle, attachments);\r
652                 }\r
653                 \r
654                 @Override\r
655                 public FormatClass formatActions() throws ExportException {\r
656                         return getOrCreateFormatClass();\r
657                 }\r
658 \r
659                 @Override\r
660                 public void savePref(Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode) throws ExportException {\r
661                         getOrCreateFormatClass().savePref(options, contentScopeNode, workbenchScopeNode);\r
662                 }\r
663 \r
664                 @Override\r
665                 public void loadPref(Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode) throws ExportException {\r
666                         getOrCreateFormatClass().loadPref(options, contentScopeNode, workbenchScopeNode);                       \r
667                 }\r
668 \r
669         }\r
670         \r
671         public static class PublisherImpl implements Publisher {\r
672 \r
673                 IConfigurationElement ce;\r
674                 PublisherClass publisherClass;\r
675 \r
676                 public PublisherImpl(IConfigurationElement ce) {\r
677                         this.ce = ce;\r
678                 }\r
679                 \r
680                 PublisherClass getOrCreatePublisherClass() throws ExportException {\r
681                         if ( publisherClass == null ) {\r
682                                 try {\r
683                                         publisherClass = (PublisherClass) ce.createExecutableExtension("publisherClass");\r
684                                 } catch (CoreException e) {\r
685                                         e.printStackTrace();                            \r
686                                         throw new ExportException( e );\r
687                                 } \r
688                         }\r
689                         return publisherClass;\r
690                 }\r
691                 \r
692                 @Override\r
693                 public String id() {\r
694                         return ce.getAttribute("id");\r
695                 }\r
696 \r
697                 @Override\r
698                 public String label() {\r
699                         return ce.getAttribute("label");\r
700                 }\r
701 \r
702                 @Override\r
703                 public org.simantics.export.core.intf.PublisherClass publisherClass() throws ExportException {\r
704                         return getOrCreatePublisherClass();\r
705                 }\r
706                 \r
707                 @Override\r
708                 public String toString() {\r
709                         return label();\r
710                 }\r
711                 \r
712         }\r
713 \r
714         @Override\r
715         public ContentType[] contentTypes() {\r
716                 return contentTypes;\r
717         }\r
718 \r
719         @Override\r
720         public Discoverer[] discoverers() {\r
721                 return discoverers;\r
722         }\r
723 \r
724         @Override\r
725         public Format[] formats() {\r
726                 return formats;\r
727         }\r
728 \r
729         @Override\r
730         public Importer[] importers() {\r
731                 return importers;\r
732         }\r
733 \r
734         @Override\r
735         public Exporter[] exporters() {\r
736                 return exporters;\r
737         }\r
738         \r
739         public Publisher[] publishers() {\r
740                 return publishers;\r
741         };\r
742         \r
743         Comparator<Exporter> exporterPrioritySorter = new Comparator<Exporter>() {\r
744                 @Override\r
745                 public int compare(Exporter o1, Exporter o2) {                  \r
746                         return Integer.signum( o2.getExportPriority() - o1.getExportPriority() );\r
747                 }\r
748         };\r
749 \r
750         \r
751 }\r