]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.export.core/src/org/simantics/export/core/impl/ExportExtensionPointImpl.java b/bundles/org.simantics.export.core/src/org/simantics/export/core/impl/ExportExtensionPointImpl.java
new file mode 100644 (file)
index 0000000..c87bfa7
--- /dev/null
@@ -0,0 +1,751 @@
+package org.simantics.export.core.impl;\r
+\r
+import java.io.File;\r
+import java.lang.ref.WeakReference;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.Arrays;\r
+import java.util.Collection;\r
+import java.util.Comparator;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IConfigurationElement;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.osgi.service.prefs.Preferences;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.type.RecordType;\r
+import org.simantics.export.core.ExportContext;\r
+import org.simantics.export.core.ExportExtensionPoint;\r
+import org.simantics.export.core.error.ExportException;\r
+import org.simantics.export.core.intf.ContentType;\r
+import org.simantics.export.core.intf.ContentTypeAction;\r
+import org.simantics.export.core.intf.DiscoverAction;\r
+import org.simantics.export.core.intf.Discoverer;\r
+import org.simantics.export.core.intf.ExportClass;\r
+import org.simantics.export.core.intf.Exporter;\r
+import org.simantics.export.core.intf.Format;\r
+import org.simantics.export.core.intf.FormatClass;\r
+import org.simantics.export.core.intf.IconResolver;\r
+import org.simantics.export.core.intf.ImportAction;\r
+import org.simantics.export.core.intf.Importer;\r
+import org.simantics.export.core.intf.Publisher;\r
+import org.simantics.export.core.intf.PublisherClass;\r
+import org.simantics.export.core.manager.Content;\r
+import org.simantics.utils.datastructures.ToStringComparator;\r
+\r
+/**\r
+ * Light-weight registry implementation to export extension point.\r
+ *\r
+ * @author toni.kalajainen@semantum.fi\r
+ */\r
+public class ExportExtensionPointImpl implements ExportExtensionPoint {\r
+\r
+       public static final String EP = "org.simantics.export.core.export";\r
+       \r
+       Importer[] importers = createImporters();\r
+       Exporter[] exporters = createExporters();\r
+       Format[] formats = createFormats();\r
+       ContentType[] contentTypes = createContentTypes();\r
+       Discoverer[] discoverers = createDiscoverers();\r
+       Publisher[] publishers = createPublishers();\r
+       \r
+       public ExportExtensionPointImpl() {}\r
+\r
+       public Discoverer[] getDiscoverers(String contentTypeId) {\r
+               int count = 0;\r
+               for ( Discoverer discoverer : discoverers ) {\r
+                       if ( contentTypeId.equals( discoverer.contentTypeId() ) ) count++;\r
+               }\r
+               \r
+               Discoverer[] result = new Discoverer[ count ];\r
+               int i = 0;\r
+               for ( Discoverer discoverer : discoverers ) {\r
+                       if ( contentTypeId.equals( discoverer.contentTypeId() ) ) {                             \r
+                               result[ i++ ] = discoverer;\r
+                       }\r
+               }\r
+               return result;\r
+               \r
+       }\r
+       \r
+       public Format getFormat(String formatId) \r
+       {\r
+               for ( Format format : formats ) {\r
+                       if ( formatId.equals( format.id() ) ) return format;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Format getFormatByExt(String fileExt) {\r
+               for ( Format format : formats ) {\r
+                       if ( fileExt.equals( format.fileext() ) ) return format;\r
+               }\r
+               return null;\r
+       }       \r
+       public ContentType getContentType(String contentTypeId) \r
+                       //throws ExportException \r
+       {\r
+               for ( ContentType contentType : contentTypes ) {\r
+                       if ( contentTypeId.equals( contentType.id() ) ) return contentType;\r
+               }\r
+               //throw new ExportException("ContentType "+contentTypeId+" does not exist");\r
+               return null;\r
+       }\r
+       \r
+       public Importer getImporter(String formatId) \r
+                       //throws ExportException \r
+       {\r
+               for ( Importer importer : importers ) {\r
+                       if ( formatId.equals( importer.formatId() ) ) return importer;\r
+               }\r
+               //throw new ExportException("Importer "+formatId+" does not exist");\r
+               return null;\r
+       }\r
+       \r
+       public Exporter[] getExporters(String formatId, String contentTypeId) \r
+       {\r
+               int count = 0;\r
+               for ( Exporter exporter : exporters ) {\r
+                       if ( exporter.formatId().equals(formatId) &&\r
+                            exporter.contentTypeId().equals(contentTypeId) ) count++;\r
+               }\r
+               Exporter[] result = new Exporter[ count ];\r
+               int index = 0;\r
+               for ( Exporter exporter : exporters ) {\r
+                       if ( formatId.equals( exporter.formatId() ) && contentTypeId.equals( exporter.contentTypeId() ) ) {\r
+                               result[ index++ ] = exporter;\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Exporter[] getExportersForContentType(String contentTypeId) \r
+                       //throws ExportException \r
+       {\r
+               int count = 0;\r
+               for ( Exporter exporter : exporters ) {\r
+                       if ( contentTypeId.equals( exporter.contentTypeId() ) ) count++;\r
+               }\r
+               \r
+               Exporter[] result = new Exporter[ count ];\r
+               int i = 0;\r
+               for ( Exporter exporter : exporters ) {\r
+                       if ( contentTypeId.equals( exporter.contentTypeId() ) ) {\r
+                               result[ i++ ] = exporter;\r
+                       }\r
+               }\r
+               \r
+               Arrays.sort(result, exporterPrioritySorter);\r
+               \r
+               return result;\r
+       }\r
+\r
+       public Exporter[] getExportersForFormat(String formatId) \r
+       {\r
+               int count = 0;\r
+               for ( Exporter exporter : exporters ) {\r
+                       if ( formatId.equals( exporter.formatId() ) ) count++;\r
+               }\r
+               \r
+               Exporter[] result = new Exporter[ count ];\r
+               int i = 0;\r
+               for ( Exporter exporter : exporters ) {\r
+                       if ( formatId.equals( exporter.formatId() ) ) {\r
+                               result[ i++ ] = exporter;\r
+                       }\r
+               }\r
+               \r
+               Arrays.sort(result, exporterPrioritySorter);\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Publisher getPublisher(String publisherId) {\r
+               for ( Publisher publisher : publishers ) {\r
+                       if ( publisherId.equals( publisher.id() ) ) return publisher;\r
+               }\r
+               return null;\r
+       };\r
+       \r
+       public int getPublisherIndex(String publisherId) {\r
+               for (int i=0; i<publishers.length; i++) {\r
+                       if ( publisherId.equals( publishers[i].id() ) ) return i;\r
+               }\r
+               return -1;\r
+       }\r
+       \r
+       public Publisher getPublisherByLabel(String publisherLabel) {\r
+               for ( Publisher publisher : publishers ) {\r
+                       if ( publisher.label().equals(publisherLabel ) ) return publisher;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       ContentType[] createContentTypes() {\r
+               IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
+               int count = 0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "content_type".equals(ce.getName() ) ) count++;                    \r
+               }\r
+               \r
+               ContentType[] result = new ContentType[count];\r
+               int i=0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "content_type".equals(ce.getName() ) ) {\r
+                               result[i++] = new ContentTypeImpl( ce );\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+\r
+       Discoverer[] createDiscoverers() {\r
+               IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
+               int count = 0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "discoverer".equals(ce.getName() ) ) count++;                      \r
+               }\r
+               \r
+               Discoverer[] result = new Discoverer[count];\r
+               int i=0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "discoverer".equals(ce.getName() ) ) {\r
+                               result[i++] = new DiscovererImpl( ce );\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+               \r
+       Format[] createFormats() {\r
+               IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
+               int count = 0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "format".equals(ce.getName() ) ) count++;                  \r
+               }\r
+               \r
+               Format[] result = new Format[count];\r
+               int i=0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "format".equals(ce.getName() ) ) {\r
+                               result[i++] = new FormatImpl( ce );\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       Exporter[] createExporters() {\r
+               IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
+               int count = 0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "exporter".equals(ce.getName() ) ) count++;                        \r
+               }\r
+               \r
+               Exporter[] result = new Exporter[count];\r
+               int i=0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "exporter".equals(ce.getName() ) ) {\r
+                               result[i++] = new ExporterImpl( ce );\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       Importer[] createImporters() {\r
+               IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
+               int count = 0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "importer".equals(ce.getName() ) ) count++;                        \r
+               }\r
+               \r
+               Importer[] result = new Importer[count];\r
+               int i=0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "importer".equals(ce.getName() ) ) {\r
+                               result[i++] = new ImporterImpl( ce );\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       Publisher[] createPublishers() {\r
+               IConfigurationElement ces[] = Platform.getExtensionRegistry().getConfigurationElementsFor( EP ); \r
+               int count = 0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "publisher".equals(ce.getName() ) ) count++;                       \r
+               }\r
+               \r
+               Publisher[] result = new Publisher[count];\r
+               int i=0;\r
+               for (IConfigurationElement ce : ces) {\r
+                       if ( "publisher".equals(ce.getName() ) ) {\r
+                               result[i++] = new PublisherImpl( ce );\r
+                       }\r
+               }\r
+               \r
+               Arrays.sort(result, new ToStringComparator.ByLength());\r
+               \r
+               return result;\r
+       }\r
+       \r
+       static class ContentTypeImpl implements ContentType {\r
+               IConfigurationElement ce;\r
+               ContentTypeAction action;\r
+               WeakReference<IconResolver> resolverCache = null;\r
+               boolean invalidIconResolver = false;\r
+\r
+               public ContentTypeImpl(IConfigurationElement ce) {\r
+                       this.ce = ce;\r
+               }\r
+               \r
+               ContentTypeAction getOrCreate() throws ExportException {\r
+                       if ( action == null ) {\r
+                               try {\r
+                                       String value = ce.getAttribute("contentTypeAction");\r
+                                       if ( value == null ) return new DefaultContentTypeAction();\r
+                                       action = (ContentTypeAction) ce.createExecutableExtension("contentTypeAction");\r
+                               } catch (CoreException e) {\r
+                                       throw new ExportException( e );\r
+                               } \r
+                       }\r
+                       return action;\r
+               }               \r
+\r
+               @Override\r
+               public String id() {                    \r
+                       return ce.getAttribute("id");\r
+               }\r
+\r
+               @Override\r
+               public String label() {\r
+                       return ce.getAttribute("label");\r
+               }\r
+\r
+               @Override\r
+               public String plural() {\r
+                       return ce.getAttribute("plural");\r
+               }\r
+\r
+               public ImageDescriptor icon(String contentUri) {\r
+                       if (!invalidIconResolver && ce.getAttribute("iconResolver") != null) {\r
+                               try {\r
+                                       IconResolver resolver = resolverCache != null ? resolverCache.get() : null;\r
+                                       if (resolver == null) {\r
+                                               resolver = (IconResolver) ce.createExecutableExtension("iconResolver");\r
+                                               resolverCache = new WeakReference<IconResolver>(resolver);\r
+                                       }\r
+                                       return resolver.get(contentUri);\r
+                               } catch (CoreException e) {\r
+                                       // Invalid iconResolver, could not instantiate.\r
+                                       // Don't try to resolve it anymore if it fails once.\r
+                                       invalidIconResolver = true;\r
+                                       return null;\r
+                               }\r
+                       }\r
+                       return icon();\r
+               }\r
+               \r
+               @Override\r
+               public ImageDescriptor icon() {\r
+                       try {\r
+                               String _url = ce.getAttribute("icon");\r
+                               URL url = new URL(_url);\r
+                               return ImageDescriptor.createFromURL(url);\r
+                       } catch (MalformedURLException e) {\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public boolean isModel() {\r
+                       return "true".equalsIgnoreCase(ce.getAttribute("model"));\r
+               }\r
+               \r
+               @Override\r
+               public String toString() {\r
+                       return "ContentType, id="+id()+", label="+label();\r
+               }\r
+\r
+               @Override\r
+               public Map<String, String> getLabels(ExportContext ctx, Collection<String> contents) throws ExportException {\r
+                       ContentTypeAction action = getOrCreate();\r
+                       return action.getLabels(ctx, contents);\r
+               }\r
+               \r
+       }\r
+       \r
+       static class DiscovererImpl implements Discoverer {\r
+               IConfigurationElement ce;\r
+               DiscoverAction action;\r
+\r
+               public DiscovererImpl(IConfigurationElement ce) {\r
+                       this.ce = ce;\r
+               }\r
+\r
+               @Override\r
+               public String contentTypeId() {\r
+                       return ce.getAttribute("content_type_id");\r
+               }\r
+               \r
+               DiscoverAction getOrCreate() throws ExportException {\r
+                       if ( action == null ) {\r
+                               try {\r
+                                       action = (DiscoverAction) ce.createExecutableExtension("discoverAction");\r
+                               } catch (CoreException e) {\r
+                                       throw new ExportException( e );\r
+                               } \r
+                       }\r
+                       return action;\r
+               }\r
+\r
+//             public Read<Collection<String>> discoverRequest(\r
+//                             Collection<String> startLocations) throws ExportException {\r
+//                     return getOrCreate().discoverRequest(startLocations);\r
+//             }\r
+               \r
+               @Override\r
+               public String toString() {\r
+                       try {\r
+                               return "Discoverer, contentTypeId="+contentTypeId()+", class="+getOrCreate().getClass().getCanonicalName();\r
+                       } catch (ExportException e) {\r
+                               return "Discoverer, contentTypeId="+contentTypeId();\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public Collection<String> discoverContent(ExportContext ctx, Collection<String> startLocations) throws ExportException {\r
+                       return getOrCreate().discoverContent(ctx, startLocations);\r
+               }\r
+               \r
+       }\r
+\r
+       static class ExporterImpl implements Exporter {\r
+               IConfigurationElement ce;\r
+               ExportClass action;\r
+               int priority = 0;\r
+\r
+               public ExporterImpl(IConfigurationElement ce) {\r
+                       this.ce = ce;\r
+                       String priorityStr = ce.getAttribute("exportPriority");\r
+                       if ( priorityStr!=null ) priority = Integer.valueOf(priorityStr);\r
+               }\r
+\r
+               ExportClass getOrCreate() throws ExportException {\r
+                       if ( action == null ) {\r
+                               try {\r
+                                       action = (ExportClass) ce.createExecutableExtension("exportAction");\r
+                               } catch (CoreException e) {\r
+                                       throw new ExportException( e );\r
+                               } \r
+                       }\r
+                       return action;\r
+               }\r
+               \r
+               @Override\r
+               public String formatId() {                      \r
+                       return ce.getAttribute("formatId");\r
+               }\r
+               \r
+               @Override\r
+               public String contentTypeId() {\r
+                       return ce.getAttribute("content_type_id");\r
+               }\r
+\r
+               @Override\r
+               public ExportClass exportAction() throws ExportException {\r
+                       return getOrCreate();\r
+               }\r
+               \r
+               @Override\r
+               public String toString() {\r
+                       try {\r
+                               return "Exporter, formatId="+formatId()+", contentTypeId="+contentTypeId()+", class="+getOrCreate().getClass().getCanonicalName();\r
+                       } catch (ExportException e) {\r
+                               return "Exporter, formatId="+formatId()+", contentTypeId="+contentTypeId();\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public int getExportPriority() {\r
+                       return priority;\r
+               }\r
+               \r
+       }\r
+\r
+       static class ImporterImpl implements Importer {\r
+               IConfigurationElement ce;\r
+\r
+               public ImporterImpl(IConfigurationElement ce) {\r
+                       this.ce = ce;\r
+               }\r
+\r
+               @Override\r
+               public String formatId() {                      \r
+                       return ce.getAttribute("formatId");\r
+               }\r
+               \r
+               @Override\r
+               public String contentTypeId() {\r
+                       return ce.getAttribute("content_type_id");\r
+               }\r
+\r
+               @Override\r
+               public ImportAction importAction() throws ExportException {\r
+                       try {\r
+                               return (ImportAction) ce.createExecutableExtension("exportAction");\r
+                       } catch (CoreException e) {\r
+                               throw new ExportException(e);\r
+                       }\r
+               }\r
+               \r
+               @Override\r
+               public String toString() {\r
+                       return "Importer, formatId="+formatId()+", contentTypeId="+contentTypeId();\r
+               }\r
+               \r
+       }\r
+       \r
+       \r
+       static class FormatImpl implements Format {\r
+               IConfigurationElement ce;\r
+               FormatClass formatClass;\r
+\r
+               public FormatImpl(IConfigurationElement ce) {\r
+                       this.ce = ce;\r
+               }\r
+               \r
+               FormatClass getOrCreateFormatClass() throws ExportException {\r
+                       if ( formatClass == null ) {\r
+                               try {\r
+                                       formatClass = (FormatClass) ce.createExecutableExtension("formatClass");\r
+                               } catch (CoreException e) {\r
+                                       e.printStackTrace();                            \r
+                                       throw new ExportException( e );\r
+                               } \r
+                       }\r
+                       return formatClass;\r
+               }\r
+\r
+               @Override\r
+               public String id() {                    \r
+                       return ce.getAttribute("id");\r
+               }\r
+\r
+               @Override\r
+               public String label() {\r
+                       return ce.getAttribute("label");\r
+               }\r
+\r
+               @Override\r
+               public String plural() {\r
+                       return ce.getAttribute("plural");\r
+               }\r
+\r
+               @Override\r
+               public ImageDescriptor icon() {\r
+                       try {\r
+                               String _url = ce.getAttribute("icon");\r
+                               URL url = new URL(_url);\r
+                               return ImageDescriptor.createFromURL(url);\r
+                       } catch (MalformedURLException e) {\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public String fileext() {\r
+                       return ce.getAttribute("fileext");              \r
+               }\r
+\r
+               @Override\r
+               public Class<?> writerClass() throws ClassNotFoundException {\r
+                       String className = ce.getAttribute("writerClass");\r
+                       return Class.forName(className);\r
+               }\r
+\r
+               @Override\r
+               public Class<?> readerClass() throws ClassNotFoundException {\r
+                       String className = ce.getAttribute("readerClass");\r
+                       return Class.forName(className);\r
+               }\r
+\r
+               @Override\r
+               public boolean isGroupFormat() {                        \r
+                       return "true".equals(ce.getAttribute("isGroupFormat"));\r
+               }\r
+               \r
+               @Override\r
+               public boolean isContainerFormat() {\r
+                       return "true".equals(ce.getAttribute("isContainerFormat"));\r
+               }\r
+               \r
+               @Override\r
+               public boolean isAttachable() {\r
+                       return "true".equals(ce.getAttribute("isAttachable"));\r
+               }               \r
+\r
+               @Override\r
+               public boolean mergeGroupFormatDefault() {\r
+                       return "true".equals(ce.getAttribute("mergeGroupDefault"));             \r
+               }\r
+\r
+               @Override\r
+               public boolean isAlwaysPublished() {\r
+                       return "true".equals(ce.getAttribute("isAlwaysPublished"));\r
+               }\r
+\r
+               @Override\r
+               public boolean isLinkContainer() {\r
+                       return "true".equals(ce.getAttribute("isLinkContainer"));\r
+               }       \r
+               @Override\r
+               public RecordType options( ExportContext context ) throws ExportException {\r
+                       return getOrCreateFormatClass().options(context);\r
+               }\r
+\r
+               @Override\r
+               public List<String> validate(ExportContext context, Variant options) throws ExportException {\r
+                       return getOrCreateFormatClass().validate(context, options);\r
+               }\r
+               \r
+               @Override\r
+               public void fillDefaultPrefs( ExportContext ctx, Variant options ) throws ExportException {\r
+                       getOrCreateFormatClass().fillDefaultPrefs( ctx, options );\r
+               }\r
+\r
+\r
+               @Override\r
+               public String toString() {                      \r
+                       try {\r
+                               return "Format, id="+id()+", fileext="+fileext()+", label="+label()+", class="+getOrCreateFormatClass().getClass().getCanonicalName();\r
+                       } catch (ExportException e) {\r
+                               return "Format, id="+id()+", fileext="+fileext()+", label="+label();\r
+                       }                       \r
+               }\r
+\r
+               @Override\r
+               public Object createFile(ExportContext context, File outputFile, Variant options) throws ExportException {\r
+                       return getOrCreateFormatClass().createFile(context, outputFile, options);\r
+               }\r
+\r
+               @Override\r
+               public Object openFile(ExportContext context, File inputFile, Variant options) throws ExportException {\r
+                       return getOrCreateFormatClass().openFile(context, inputFile, options);\r
+               }\r
+               \r
+               @Override\r
+               public void closeFile(ExportContext context, Object handle) throws ExportException {\r
+                       getOrCreateFormatClass().closeFile(context, handle);\r
+               }\r
+\r
+               @Override\r
+               public void addAttachment(ExportContext context, Object handle, List<Content> attachments) throws ExportException {\r
+                       getOrCreateFormatClass().addAttachment(context, handle, attachments);\r
+               }\r
+               \r
+               @Override\r
+               public FormatClass formatActions() throws ExportException {\r
+                       return getOrCreateFormatClass();\r
+               }\r
+\r
+               @Override\r
+               public void savePref(Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode) throws ExportException {\r
+                       getOrCreateFormatClass().savePref(options, contentScopeNode, workbenchScopeNode);\r
+               }\r
+\r
+               @Override\r
+               public void loadPref(Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode) throws ExportException {\r
+                       getOrCreateFormatClass().loadPref(options, contentScopeNode, workbenchScopeNode);                       \r
+               }\r
+\r
+       }\r
+       \r
+       public static class PublisherImpl implements Publisher {\r
+\r
+               IConfigurationElement ce;\r
+               PublisherClass publisherClass;\r
+\r
+               public PublisherImpl(IConfigurationElement ce) {\r
+                       this.ce = ce;\r
+               }\r
+               \r
+               PublisherClass getOrCreatePublisherClass() throws ExportException {\r
+                       if ( publisherClass == null ) {\r
+                               try {\r
+                                       publisherClass = (PublisherClass) ce.createExecutableExtension("publisherClass");\r
+                               } catch (CoreException e) {\r
+                                       e.printStackTrace();                            \r
+                                       throw new ExportException( e );\r
+                               } \r
+                       }\r
+                       return publisherClass;\r
+               }\r
+               \r
+               @Override\r
+               public String id() {\r
+                       return ce.getAttribute("id");\r
+               }\r
+\r
+               @Override\r
+               public String label() {\r
+                       return ce.getAttribute("label");\r
+               }\r
+\r
+               @Override\r
+               public org.simantics.export.core.intf.PublisherClass publisherClass() throws ExportException {\r
+                       return getOrCreatePublisherClass();\r
+               }\r
+               \r
+               @Override\r
+               public String toString() {\r
+                       return label();\r
+               }\r
+               \r
+       }\r
+\r
+       @Override\r
+       public ContentType[] contentTypes() {\r
+               return contentTypes;\r
+       }\r
+\r
+       @Override\r
+       public Discoverer[] discoverers() {\r
+               return discoverers;\r
+       }\r
+\r
+       @Override\r
+       public Format[] formats() {\r
+               return formats;\r
+       }\r
+\r
+       @Override\r
+       public Importer[] importers() {\r
+               return importers;\r
+       }\r
+\r
+       @Override\r
+       public Exporter[] exporters() {\r
+               return exporters;\r
+       }\r
+       \r
+       public Publisher[] publishers() {\r
+               return publishers;\r
+       };\r
+       \r
+       Comparator<Exporter> exporterPrioritySorter = new Comparator<Exporter>() {\r
+               @Override\r
+               public int compare(Exporter o1, Exporter o2) {                  \r
+                       return Integer.signum( o2.getExportPriority() - o1.getExportPriority() );\r
+               }\r
+       };\r
+\r
+       \r
+}\r