org.eclipse.emf.exporter_2.6.0.v20120130-0943

16:43:38.454 INFO  jd.cli.Main - Decompiling org.eclipse.emf.exporter_2.6.0.v20120130-0943.jar
package org.eclipse.emf.exporter;

import org.eclipse.emf.common.EMFPlugin.EclipsePlugin;

public class ExporterPlugin$Implementation
  extends EMFPlugin.EclipsePlugin
{
  public ExporterPlugin$Implementation()
  {
    ExporterPlugin.access$0(this);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ExporterPlugin.Implementation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.EMFPlugin.EclipsePlugin;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.converter.ConverterPlugin;

public final class ExporterPlugin
  extends EMFPlugin
{
  public static final ExporterPlugin INSTANCE = new ExporterPlugin();
  private static Implementation plugin;
  public static final String ID = "org.eclipse.emf.exporter";
  
  private ExporterPlugin()
  {
    super(new ResourceLocator[] {ConverterPlugin.INSTANCE });
  }
  
  public ResourceLocator getPluginResourceLocator()
  {
    return plugin;
  }
  
  public static Implementation getPlugin()
  {
    return plugin;
  }
  
  public static class Implementation
    extends EMFPlugin.EclipsePlugin
  {
    public Implementation()
    {
      ExporterPlugin.plugin = this;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ExporterPlugin
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.converter.util.ConverterUtil.EPackageList;
import org.eclipse.emf.ecore.EPackage;

class ModelExporter$1
  extends ConverterUtil.EPackageList
{
  private static final long serialVersionUID = 1L;
  
  ModelExporter$1(ModelExporter paramModelExporter) {}
  
  protected void didAdd(int index, EPackage newObject)
  {
    ModelExporter.EPackageExportInfo packageInfo = this$0.getEPackageExportInfo(newObject);
    if (packageInfo.getArtifactLocation() == null)
    {
      String location = (String)this$0.getExporterNestedGenAnnotationDetails(this$0.getGenModel(), "selectedPackages").get(newObject.getNsURI());
      if (location != null)
      {
        packageInfo.setConvert(true);
        packageInfo.setArtifactLocation(location);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.emf.codegen.ecore.genmodel.GenAnnotation;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.converter.util.ConverterUtil.GenPackageList;
import org.eclipse.emf.ecore.resource.Resource;

class ModelExporter$2
  extends ConverterUtil.GenPackageList
{
  private static final long serialVersionUID = 1L;
  
  ModelExporter$2(ModelExporter paramModelExporter) {}
  
  protected void didAdd(int index, GenPackage newObject)
  {
    URI genModelURI = newObject.getGenModel().eResource() != null ? 
      newObject.getGenModel().eResource().getURI() : 
      null;
    
    String stringURI = (String)this$0.getExporterNestedGenAnnotationDetails(this$0.getGenModel(), "selectedReferencedPackages").get(newObject.getNSURI());
    if (stringURI != null)
    {
      ModelExporter.ReferencedGenPackageExportInfo genPackageInfo = this$0.getReferencedGenPackageExportInfo(newObject);
      if (genPackageInfo.getArtifactURI() == null)
      {
        genPackageInfo.setModelExporterID(this$0.getID());
        URI uri = URI.createURI(stringURI);
        if (genModelURI != null) {
          uri = uri.resolve(genModelURI);
        }
        genPackageInfo.setArtifactURI(uri);
      }
    }
    List<GenAnnotation> uriAnnotations = this$0.getExporterNestedGenAnnotations(newObject);
    if (!uriAnnotations.isEmpty())
    {
      ModelExporter.ReferencedGenPackageExportInfo genPackageInfo = null;
      for (GenAnnotation uriAnnotation : uriAnnotations) {
        if (!uriAnnotation.getDetails().isEmpty())
        {
          if (genPackageInfo == null) {
            genPackageInfo = this$0.getReferencedGenPackageExportInfo(newObject);
          }
          for (Map.Entry<String, String> entry : uriAnnotation.getDetails())
          {
            String packageNSURI = (String)entry.getKey();
            String stringArtifactURIs = (String)entry.getValue();
            if (stringArtifactURIs != null)
            {
              String[] stringURIs = stringArtifactURIs.split(" ");
              
              List<URI> uris = (List)genPackageInfo.getNSURIToLocalArtifactURIs().get(packageNSURI);
              if (uris == null)
              {
                uris = new ArrayList(stringURIs.length);
                genPackageInfo.getNSURIToLocalArtifactURIs().put(packageNSURI, uris);
              }
              for (int k = 0; k < stringURIs.length; k++)
              {
                URI uri = URI.createURI(stringURIs[k]);
                if (genModelURI != null) {
                  uri = uri.resolve(genModelURI);
                }
                uris.add(uri);
              }
            }
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.converter.ModelConverter;
import org.eclipse.emf.converter.ModelConverter.ReferencedEPackageFilter;

class ModelExporter$3
  extends ModelConverter.ReferencedEPackageFilter
{
  ModelExporter$3(ModelExporter paramModelExporter, ModelConverter paramModelConverter)
  {
    super(paramModelConverter);
  }
  
  protected boolean isValidReference(GenPackage genPackage)
  {
    return (super.isValidReference(genPackage)) && (this$0.getReferencedGenPackageExportInfo(genPackage).getArtifactURI() != null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import org.eclipse.emf.converter.ModelConverter.EPackageConvertInfo;

public class ModelExporter$EPackageExportInfo
  extends ModelConverter.EPackageConvertInfo
{
  public String getArtifactLocation()
  {
    return getConvertData();
  }
  
  public void setArtifactLocation(String artifactLocation)
  {
    setConvertData(artifactLocation);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.EPackageExportInfo
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import java.util.List;
import java.util.Map;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.URI;

public class ModelExporter$ExportData
{
  public Map<GenPackage, URI> genPackageToArtifactURI;
  public Map<GenPackage, List<GenPackage>> genPackageToReferencedGenPackages;
  public Map<GenPackage, URI> referencedGenPackagesToArtifactURI;
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.ExportData
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import java.util.Collection;
import java.util.Iterator;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.AbstractTreeIterator;
import org.eclipse.emf.common.util.EList;

public class ModelExporter$GenPackagesTreeIterator
  extends AbstractTreeIterator<GenPackage>
{
  private static final long serialVersionUID = 1L;
  
  public ModelExporter$GenPackagesTreeIterator(GenModel genModel)
  {
    this(genModel.getGenPackages());
  }
  
  public ModelExporter$GenPackagesTreeIterator(Collection<GenPackage> genPackages)
  {
    super(genPackages, false);
  }
  
  protected Iterator<GenPackage> getChildren(Object object)
  {
    return (object instanceof Collection) ? 
      ((Collection)object).iterator() : 
      ((GenPackage)object).getNestedGenPackages().iterator();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.GenPackagesTreeIterator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.converter.ModelConverter.ReferencedGenPackageConvertInfo;

public class ModelExporter$ReferencedGenPackageExportInfo
  extends ModelConverter.ReferencedGenPackageConvertInfo
{
  protected String modelExporterID;
  protected URI artifactURI;
  protected Map<String, List<URI>> nsURIToLocalArtifactURIs;
  
  public String getModelExporterID()
  {
    return modelExporterID;
  }
  
  public void setModelExporterID(String modelExporterID)
  {
    this.modelExporterID = modelExporterID;
  }
  
  public URI getArtifactURI()
  {
    return artifactURI;
  }
  
  public void setArtifactURI(URI artifactURI)
  {
    this.artifactURI = artifactURI;
  }
  
  public Map<String, List<URI>> getNSURIToLocalArtifactURIs()
  {
    if (nsURIToLocalArtifactURIs == null) {
      nsURIToLocalArtifactURIs = new HashMap();
    }
    return nsURIToLocalArtifactURIs;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.exporter.ModelExporter.ReferencedGenPackageExportInfo
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.exporter;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.emf.codegen.ecore.genmodel.GenAnnotation;
import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.util.AbstractTreeIterator;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticException;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.UniqueEList;
import org.eclipse.emf.converter.ModelConverter;
import org.eclipse.emf.converter.ModelConverter.EPackageConvertInfo;
import org.eclipse.emf.converter.ModelConverter.ReferencedEPackageFilter;
import org.eclipse.emf.converter.ModelConverter.ReferencedGenPackageConvertInfo;
import org.eclipse.emf.converter.util.ConverterUtil;
import org.eclipse.emf.converter.util.ConverterUtil.EPackageList;
import org.eclipse.emf.converter.util.ConverterUtil.GenPackageList;
import org.eclipse.emf.converter.util.ConverterUtil.WorkspaceResourceValidator;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.exporter.util.ExporterUtil;

public abstract class ModelExporter
  extends ModelConverter
{
  public static final String GENANNOTATION_SOURCE_PREFIX = "http://www.eclipse.org/emf/2002/GenModel/exporter/";
  public static final String GENANNOTATION_KEY_DIRECTORY_URI = "directoryURI";
  public static final String GENANNOTATION_SOURCE_SELECTED_EPACKAGES = "selectedPackages";
  public static final String GENANNOTATION_SOURCE_SELECTED_REFERENCES = "selectedReferencedPackages";
  protected Map<EPackage, GenPackage> ePackageToGenPackageMap;
  protected URI directoryURI;
  protected Map<GenBase, EMap<String, String>> genBaseToDetailsMap;
  
  public static class EPackageExportInfo
    extends ModelConverter.EPackageConvertInfo
  {
    public String getArtifactLocation()
    {
      return getConvertData();
    }
    
    public void setArtifactLocation(String artifactLocation)
    {
      setConvertData(artifactLocation);
    }
  }
  
  public static class ReferencedGenPackageExportInfo
    extends ModelConverter.ReferencedGenPackageConvertInfo
  {
    protected String modelExporterID;
    protected URI artifactURI;
    protected Map<String, List<URI>> nsURIToLocalArtifactURIs;
    
    public String getModelExporterID()
    {
      return modelExporterID;
    }
    
    public void setModelExporterID(String modelExporterID)
    {
      this.modelExporterID = modelExporterID;
    }
    
    public URI getArtifactURI()
    {
      return artifactURI;
    }
    
    public void setArtifactURI(URI artifactURI)
    {
      this.artifactURI = artifactURI;
    }
    
    public Map<String, List<URI>> getNSURIToLocalArtifactURIs()
    {
      if (nsURIToLocalArtifactURIs == null) {
        nsURIToLocalArtifactURIs = new HashMap();
      }
      return nsURIToLocalArtifactURIs;
    }
  }
  
  protected static class GenPackagesTreeIterator
    extends AbstractTreeIterator<GenPackage>
  {
    private static final long serialVersionUID = 1L;
    
    public GenPackagesTreeIterator(GenModel genModel)
    {
      this(genModel.getGenPackages());
    }
    
    public GenPackagesTreeIterator(Collection<GenPackage> genPackages)
    {
      super(false);
    }
    
    protected Iterator<GenPackage> getChildren(Object object)
    {
      return (object instanceof Collection) ? 
        ((Collection)object).iterator() : 
        ((GenPackage)object).getNestedGenPackages().iterator();
    }
  }
  
  protected boolean saveExporter = false;
  protected boolean saveEPackageArtifactURI = false;
  
  public void dispose()
  {
    if (genBaseToDetailsMap != null)
    {
      genBaseToDetailsMap.clear();
      genBaseToDetailsMap = null;
    }
    if (ePackageToGenPackageMap != null)
    {
      ePackageToGenPackageMap.clear();
      ePackageToGenPackageMap = null;
    }
    super.dispose();
  }
  
  protected String getConverterGenAnnotationSource()
  {
    return "http://www.eclipse.org/emf/2002/GenModel/exporter/" + getID();
  }
  
  protected Map<EPackage, GenPackage> getEPackageToGenPackageMap()
  {
    if (ePackageToGenPackageMap == null) {
      ePackageToGenPackageMap = new HashMap();
    }
    return ePackageToGenPackageMap;
  }
  
  protected Map<GenBase, EMap<String, String>> getGenBaseToGenAnnotationDetailsMap()
  {
    if (genBaseToDetailsMap == null) {
      genBaseToDetailsMap = new HashMap();
    }
    return genBaseToDetailsMap;
  }
  
  protected EMap<String, String> getExporterGenAnnotationDetails(GenBase genBase)
  {
    EMap<String, String> eMap = (EMap)getGenBaseToGenAnnotationDetailsMap().get(genBase);
    if (eMap == null)
    {
      GenAnnotation genAnnotation = genBase.getGenAnnotation(getConverterGenAnnotationSource());
      if (genAnnotation != null)
      {
        eMap = genAnnotation.getDetails();
        getGenBaseToGenAnnotationDetailsMap().put(genBase, eMap);
      }
      else
      {
        eMap = ECollections.emptyEMap();
      }
    }
    return eMap;
  }
  
  protected List<GenAnnotation> getExporterNestedGenAnnotations(GenBase genBase)
  {
    if (genBase != null)
    {
      GenAnnotation exportAnnotation = genBase.getGenAnnotation(getConverterGenAnnotationSource());
      if ((exportAnnotation != null) && (!exportAnnotation.getGenAnnotations().isEmpty()))
      {
        List<GenAnnotation> nestedAnnotations = exportAnnotation.getGenAnnotations();
        if (nestedAnnotations != null) {
          return nestedAnnotations;
        }
      }
    }
    return Collections.emptyList();
  }
  
  protected EMap<String, String> getExporterNestedGenAnnotationDetails(GenBase genBase, String nestedGenAnnotationSource)
  {
    GenAnnotation genAnnotation = genBase.getGenAnnotation(getConverterGenAnnotationSource());
    if (genAnnotation != null)
    {
      GenAnnotation nestedGenAnnotation = genAnnotation.getGenAnnotation(nestedGenAnnotationSource);
      if (nestedGenAnnotation != null) {
        return nestedGenAnnotation.getDetails();
      }
    }
    return ECollections.emptyEMap();
  }
  
  public List<URI> getArtifactURIs(GenPackage genPackage)
  {
    List<GenAnnotation> nestedAnnotations = getExporterNestedGenAnnotations(genPackage);
    if (!nestedAnnotations.isEmpty())
    {
      List<URI> uris = new UniqueEList(nestedAnnotations.size());
      URI genModelURI = genPackage.getGenModel().eResource() != null ? 
        genPackage.getGenModel().eResource().getURI() : 
        null;
      for (GenAnnotation uriAnnotation : nestedAnnotations)
      {
        URI uri = URI.createURI(uriAnnotation.getSource());
        if (genModelURI != null) {
          uri = uri.resolve(genModelURI);
        }
        uris.add(uri);
      }
      for (GenPackage referencedGenPackage : getReferencedGenPackages())
      {
        ReferencedGenPackageExportInfo genPackageInfo = getReferencedGenPackageExportInfo(referencedGenPackage);
        if (genPackageInfo.getArtifactURI() != null)
        {
          List<URI> localURIs = (List)genPackageInfo.getNSURIToLocalArtifactURIs().get(genPackage.getNSURI());
          if (localURIs != null) {
            uris.addAll(localURIs);
          }
        }
      }
      return uris;
    }
    return Collections.emptyList();
  }
  
  public void setGenModel(GenModel genModel)
    throws DiagnosticException
  {
    dispose();
    this.genModel = genModel;
    genModel = getGenModel();
    
    Diagnostic diagnostic = null;
    if (genModel != null)
    {
      genModel.reconcile();
      genModel.setValidateModel(true);
      diagnostic = genModel.diagnose();
      if (getDirectoryURI() == null)
      {
        String location = (String)getExporterGenAnnotationDetails(genModel).get("directoryURI");
        setDirectoryURI(location);
      }
      if ((genModel.eResource() != null) && (getDirectoryURI() != null)) {
        setDirectoryURI(getDirectoryURI().resolve(genModel.eResource().getURI()));
      }
      for (Iterator<GenPackage> i = new GenPackagesTreeIterator(genModel); i.hasNext();)
      {
        GenPackage genPackage = (GenPackage)i.next();
        if (isValidEPackage(genPackage))
        {
          EPackage ePackage = genPackage.getEcorePackage();
          
          getEPackageToGenPackageMap().put(ePackage, genPackage);
          getEPackages().add(genPackage.getEcorePackage());
        }
      }
      List<GenPackage> exporterUsedGenPackages = new ConverterUtil.GenPackageList(genModel.getUsedGenPackages());
      GenAnnotation genModelAnnotation = genModel.getGenAnnotation(getConverterGenAnnotationSource());
      if (genModelAnnotation != null)
      {
        GenAnnotation referencedPackagesAnnotation = genModelAnnotation.getGenAnnotation("selectedReferencedPackages");
        if (referencedPackagesAnnotation != null) {
          for (Object o : referencedPackagesAnnotation.getReferences()) {
            if ((o instanceof GenPackage)) {
              exporterUsedGenPackages.add((GenPackage)o);
            }
          }
        }
      }
      for (Iterator<GenPackage> i = new GenPackagesTreeIterator(exporterUsedGenPackages); i.hasNext();)
      {
        GenPackage genPackage = (GenPackage)i.next();
        if (isValidEPackage(genPackage))
        {
          EPackage ePackage = genPackage.getEcorePackage();
          getEPackageToGenPackageMap().put(ePackage, genPackage);
          if (isValidReferencedGenPackage(genPackage)) {
            getReferencedGenPackages().add(genPackage);
          }
          getEPackages().add(ePackage);
        }
      }
    }
    adjustGenModel();
    if ((diagnostic != null) && (diagnostic.getSeverity() != 0)) {
      throw new DiagnosticException(diagnostic);
    }
  }
  
  protected void adjustGenModel()
  {
    boolean defaultLocationSet = false;
    for (Map.Entry<EPackage, ModelConverter.EPackageConvertInfo> entry : getEPackageToInfoMap().entrySet())
    {
      EPackage ePackage = (EPackage)entry.getKey();
      EPackageExportInfo packageInfo = (EPackageExportInfo)entry.getValue();
      if (packageInfo.getArtifactLocation() == null)
      {
        packageInfo.setArtifactLocation(getDefaultArtifactLocation(ePackage));
        defaultLocationSet |= packageInfo.getArtifactLocation() == null;
      }
    }
    if (defaultLocationSet) {
      makeEPackageConvertDataUnique();
    }
  }
  
  protected String getDefaultArtifactLocation(EPackage ePackage)
  {
    return null;
  }
  
  protected boolean isValidEPackage(GenPackage genPackage)
  {
    return (genPackage.getEcorePackage() != null) && (genPackage.hasClassifiers());
  }
  
  protected boolean isValidReferencedGenPackage(GenPackage genPackage)
  {
    return (genPackage.getEcorePackage() != null) && (genPackage.hasClassifiers());
  }
  
  protected List<EPackage> createEPackagesList()
  {
    
      new ConverterUtil.EPackageList()
      {
        private static final long serialVersionUID = 1L;
        
        protected void didAdd(int index, EPackage newObject)
        {
          ModelExporter.EPackageExportInfo packageInfo = getEPackageExportInfo(newObject);
          if (packageInfo.getArtifactLocation() == null)
          {
            String location = (String)getExporterNestedGenAnnotationDetails(getGenModel(), "selectedPackages").get(newObject.getNsURI());
            if (location != null)
            {
              packageInfo.setConvert(true);
              packageInfo.setArtifactLocation(location);
            }
          }
        }
      };
    }
    
    protected List<GenPackage> createReferencedGenPackagesList()
    {
      
        new ConverterUtil.GenPackageList()
        {
          private static final long serialVersionUID = 1L;
          
          protected void didAdd(int index, GenPackage newObject)
          {
            URI genModelURI = newObject.getGenModel().eResource() != null ? 
              newObject.getGenModel().eResource().getURI() : 
              null;
            
            String stringURI = (String)getExporterNestedGenAnnotationDetails(getGenModel(), "selectedReferencedPackages").get(newObject.getNSURI());
            if (stringURI != null)
            {
              ModelExporter.ReferencedGenPackageExportInfo genPackageInfo = getReferencedGenPackageExportInfo(newObject);
              if (genPackageInfo.getArtifactURI() == null)
              {
                genPackageInfo.setModelExporterID(getID());
                URI uri = URI.createURI(stringURI);
                if (genModelURI != null) {
                  uri = uri.resolve(genModelURI);
                }
                genPackageInfo.setArtifactURI(uri);
              }
            }
            List<GenAnnotation> uriAnnotations = getExporterNestedGenAnnotations(newObject);
            if (!uriAnnotations.isEmpty())
            {
              ModelExporter.ReferencedGenPackageExportInfo genPackageInfo = null;
              for (GenAnnotation uriAnnotation : uriAnnotations) {
                if (!uriAnnotation.getDetails().isEmpty())
                {
                  if (genPackageInfo == null) {
                    genPackageInfo = getReferencedGenPackageExportInfo(newObject);
                  }
                  for (Map.Entry<String, String> entry : uriAnnotation.getDetails())
                  {
                    String packageNSURI = (String)entry.getKey();
                    String stringArtifactURIs = (String)entry.getValue();
                    if (stringArtifactURIs != null)
                    {
                      String[] stringURIs = stringArtifactURIs.split(" ");
                      
                      List<URI> uris = (List)genPackageInfo.getNSURIToLocalArtifactURIs().get(packageNSURI);
                      if (uris == null)
                      {
                        uris = new ArrayList(stringURIs.length);
                        genPackageInfo.getNSURIToLocalArtifactURIs().put(packageNSURI, uris);
                      }
                      for (int k = 0; k < stringURIs.length; k++)
                      {
                        URI uri = URI.createURI(stringURIs[k]);
                        if (genModelURI != null) {
                          uri = uri.resolve(genModelURI);
                        }
                        uris.add(uri);
                      }
                    }
                  }
                }
              }
            }
          }
        };
      }
      
      public void loadGenModel(URI uri)
        throws DiagnosticException
      {
        setGenModel(uri == null ? null : 
          (GenModel)createResourceSet().getResource(uri, true).getContents().get(0));
      }
      
      public EPackageExportInfo getEPackageExportInfo(EPackage ePackage)
      {
        return (EPackageExportInfo)getEPackageConvertInfo(ePackage);
      }
      
      protected ModelConverter.EPackageConvertInfo createEPackageInfo(EPackage ePackage)
      {
        return new EPackageExportInfo();
      }
      
      public ReferencedGenPackageExportInfo getReferencedGenPackageExportInfo(GenPackage genPackage)
      {
        return (ReferencedGenPackageExportInfo)getReferenceGenPackageConvertInfo(genPackage);
      }
      
      protected ModelConverter.ReferencedGenPackageConvertInfo createGenPackageConvertInfo(GenPackage genPackage)
      {
        ReferencedGenPackageExportInfo genPackageInfo = new ReferencedGenPackageExportInfo();
        genPackageInfo.setValidReference(!getExporterNestedGenAnnotations(genPackage).isEmpty());
        return genPackageInfo;
      }
      
      protected ModelConverter.ReferencedEPackageFilter createReferencedEPackageFilterToConvert()
      {
        new ModelConverter.ReferencedEPackageFilter(this)
        {
          protected boolean isValidReference(GenPackage genPackage)
          {
            return (super.isValidReference(genPackage)) && (getReferencedGenPackageExportInfo(genPackage).getArtifactURI() != null);
          }
        };
      }
      
      protected boolean canConvert(EPackage ePackage)
      {
        return (super.canConvert(ePackage)) && (getEPackageExportInfo(ePackage).getArtifactLocation() != null);
      }
      
      public Diagnostic export(Monitor monitor)
        throws Exception
      {
        Map<String, GenPackage> nsURIToReferencedGenPackage = null;
        Map<GenPackage, URI> referencedGenPackageToArtifactURI = null;
        if (referencedGenPackageToInfoMap != null)
        {
          referencedGenPackageToArtifactURI = new HashMap(referencedGenPackageToInfoMap.size());
          nsURIToReferencedGenPackage = new HashMap(referencedGenPackageToInfoMap.size());
          List<GenPackage> referencedGenPackages = computeValidReferencedGenPackages();
          for (GenPackage genPackage : referencedGenPackages)
          {
            URI artifactURI = getReferencedGenPackageExportInfo(genPackage).getArtifactURI();
            referencedGenPackageToArtifactURI.put(genPackage, artifactURI);
            nsURIToReferencedGenPackage.put(genPackage.getNSURI(), genPackage);
          }
        }
        Map<GenPackage, URI> genPackageToArtifactURI = null;
        Map<GenPackage, List<GenPackage>> genPackageToReferencedGenPackages = null;
        if ((ePackageToInfoMap != null) && (ePackageToGenPackageMap != null))
        {
          genPackageToArtifactURI = new HashMap(ePackageToInfoMap.size());
          genPackageToReferencedGenPackages = new HashMap(ePackageToInfoMap.size());
          
          Object ePackages = computeEPackagesToConvert();
          for (EPackage ePackage : (List)ePackages)
          {
            GenPackage genPackage = (GenPackage)ePackageToGenPackageMap.get(ePackage);
            if (genPackage != null)
            {
              if (nsURIToReferencedGenPackage != null)
              {
                List<EPackage> requiredEPackages = ConverterUtil.computeRequiredPackages(ePackage);
                List<GenPackage> requiredGenPackages = new ConverterUtil.GenPackageList(requiredEPackages.size());
                for (EPackage requiredEPackage : requiredEPackages)
                {
                  GenPackage referencedGenPackage = (GenPackage)nsURIToReferencedGenPackage.get(requiredEPackage.getNsURI());
                  if (referencedGenPackage != null) {
                    requiredGenPackages.add(referencedGenPackage);
                  }
                }
                if (!requiredGenPackages.isEmpty()) {
                  genPackageToReferencedGenPackages.put(genPackage, requiredGenPackages);
                }
              }
              EPackageExportInfo exportInfo = getEPackageExportInfo(ePackage);
              String artifactLocation = exportInfo.getArtifactLocation();
              if (artifactLocation != null) {
                genPackageToArtifactURI.put(genPackage, computeArtifactURI(artifactLocation));
              }
            }
          }
        }
        if ((genPackageToArtifactURI == null) || (genPackageToArtifactURI.isEmpty())) {
          throw new DiagnosticException(new BasicDiagnostic(4, "org.eclipse.emf.exporter", 0, ExporterPlugin.INSTANCE.getString("_UI_NoPackagesToExport_error"), null));
        }
        ExportData exportData = new ExportData();
        genPackageToArtifactURI = genPackageToArtifactURI;
        referencedGenPackagesToArtifactURI = ((referencedGenPackageToArtifactURI != null) && (!referencedGenPackageToArtifactURI.isEmpty()) ? 
          referencedGenPackageToArtifactURI : 
          Collections.emptyMap());
        genPackageToReferencedGenPackages = ((genPackageToReferencedGenPackages != null) && (!genPackageToReferencedGenPackages.isEmpty()) ? 
          genPackageToReferencedGenPackages : 
          Collections.emptyMap());
        
        return doExport(monitor, exportData);
      }
      
      protected Diagnostic doExport(Monitor monitor, ExportData exportData)
        throws Exception
      {
        return Diagnostic.OK_INSTANCE;
      }
      
      public Diagnostic checkEPackageArtifactLocation(String location, String packageName)
      {
        String message = null;
        if ((location == null) || (location.equals(""))) {
          message = packageName == null ? 
            ExporterPlugin.INSTANCE.getString("_UI_ArtifactFileNameCannotBeEmpty_message") : 
            ExporterPlugin.INSTANCE.getString("_UI_ArtifactFileNameForPackageCannotBeEmpty_message", new Object[] { packageName });
        } else {
          message = doCheckEPackageArtifactLocation(location, packageName);
        }
        if (message == null) {
          return Diagnostic.OK_INSTANCE;
        }
        return new BasicDiagnostic(4, "org.eclipse.emf.converter", 0, message, null);
      }
      
      protected String doCheckEPackageArtifactLocation(String location, String packageName)
      {
        return null;
      }
      
      public URI getDirectoryURI()
      {
        return directoryURI;
      }
      
      public void setDirectoryURI(URI directoryURI)
      {
        this.directoryURI = directoryURI;
      }
      
      public void setDirectoryURI(String location)
      {
        directoryURI = createEncodedURI(location);
      }
      
      protected URI computeArtifactURI(String location)
      {
        URI artifactURI = createEncodedURI(location);
        URI directoryURI = getDirectoryURI();
        if (directoryURI != null) {
          artifactURI = artifactURI.resolve(directoryURI);
        }
        return artifactURI;
      }
      
      protected URI createEncodedURI(String location)
      {
        return location != null ? 
          URI.createURI(location, true, 0) : 
          null;
      }
      
      public Diagnostic validateDirectoryURI(String uri)
      {
        if ((uri != null) && (uri.length() > 0) && (!uri.endsWith("/"))) {
          return new BasicDiagnostic(4, 
            "org.eclipse.emf.converter", 8, 
            ExporterPlugin.INSTANCE.getString("_UI_DirectoryURI_error"), null);
        }
        return Diagnostic.OK_INSTANCE;
      }
      
      public boolean isSaveEPackageArtifactURI()
      {
        return saveEPackageArtifactURI;
      }
      
      public void setSaveEPackageArtifactURI(boolean saveEPackageArtifactURI)
      {
        this.saveEPackageArtifactURI = saveEPackageArtifactURI;
      }
      
      public boolean isSaveExporter()
      {
        return saveExporter;
      }
      
      public void setSaveExporter(boolean saveExporter)
      {
        this.saveExporter = saveExporter;
      }
      
      public void save()
        throws Exception
      {
        Resource genModelResource = getGenModel().eResource();
        
        boolean changed = false;
        if (isSaveExporter()) {
          changed |= saveExporter();
        }
        if (isSaveEPackageArtifactURI()) {
          changed |= saveEPackageArtifactURI();
        }
        changed |= genModelResource.isModified();
        if (changed)
        {
          if (EMFPlugin.IS_ECLIPSE_RUNNING)
          {
            String readOnlyFiles = ConverterUtil.WorkspaceResourceValidator.validate(Collections.singletonList(genModelResource));
            if (readOnlyFiles != null) {
              throw new Exception(ExporterPlugin.INSTANCE.getString("_UI_ReadOnlyFiles_error", new String[] { readOnlyFiles }));
            }
          }
          genModelResource.save(getGenModelSaveOptions());
        }
      }
      
      protected boolean saveExporter()
      {
        boolean changed = false;
        GenAnnotation genModelAnnotation = getGenModel().getGenAnnotation(getConverterGenAnnotationSource());
        URI directoryURI = getDirectoryURI();
        if (directoryURI == null)
        {
          if (genModelAnnotation != null) {
            changed |= genModelAnnotation.getDetails().remove("directoryURI");
          }
        }
        else
        {
          if (getGenModel().eResource() != null) {
            directoryURI = directoryURI.deresolve(getGenModel().eResource().getURI());
          }
          if (genModelAnnotation == null)
          {
            genModelAnnotation = ExporterUtil.findOrCreateGenAnnotation(getGenModel(), getConverterGenAnnotationSource());
            changed = true;
          }
          String stringURI = directoryURI.toString();
          Object oldValue = genModelAnnotation.getDetails().put("directoryURI", stringURI);
          changed |= !stringURI.equals(oldValue);
        }
        List<EPackage> ePackages = computeEPackagesToConvert();
        String location;
        if (ePackages.isEmpty())
        {
          if (genModelAnnotation != null)
          {
            GenAnnotation nestedGenAnnotation = genModelAnnotation.getGenAnnotation("selectedPackages");
            if (nestedGenAnnotation != null)
            {
              genModelAnnotation.getGenAnnotations().remove(nestedGenAnnotation);
              changed = true;
            }
          }
        }
        else
        {
          if (genModelAnnotation == null)
          {
            genModelAnnotation = ExporterUtil.findOrCreateGenAnnotation(getGenModel(), getConverterGenAnnotationSource());
            changed = true;
          }
          GenAnnotation nestedGenAnnotation = ExporterUtil.findOrCreateGenAnnotation(genModelAnnotation, "selectedPackages");
          Set<String> nsURIs = new HashSet();
          for (EPackage ePackage : ePackages)
          {
            location = getEPackageExportInfo(ePackage).getArtifactLocation();
            if (location != null)
            {
              nsURIs.add(ePackage.getNsURI());
              Object oldValue = nestedGenAnnotation.getDetails().put(ePackage.getNsURI(), location);
              changed |= !location.equals(oldValue);
            }
          }
          changed |= nestedGenAnnotation.getDetails().keySet().retainAll(nsURIs);
        }
        List<GenPackage> referencedGenPackages = computeValidReferencedGenPackages();
        if (referencedGenPackages.isEmpty())
        {
          if (genModelAnnotation != null)
          {
            GenAnnotation nestedGenAnnotation = genModelAnnotation.getGenAnnotation("selectedReferencedPackages");
            if (nestedGenAnnotation != null) {
              changed |= genModelAnnotation.getGenAnnotations().remove(nestedGenAnnotation);
            }
          }
        }
        else
        {
          if (genModelAnnotation == null)
          {
            genModelAnnotation = ExporterUtil.findOrCreateGenAnnotation(getGenModel(), getConverterGenAnnotationSource());
            changed = true;
          }
          GenAnnotation nestedGenAnnotation = ExporterUtil.findOrCreateGenAnnotation(genModelAnnotation, "selectedReferencedPackages");
          Set<String> nsURIs = new HashSet();
          for (GenPackage genPackage : referencedGenPackages)
          {
            nsURIs.add(genPackage.getNSURI());
            URI uri = getReferencedGenPackageExportInfo(genPackage).getArtifactURI();
            if (genPackage.getGenModel().eResource() != null) {
              uri = uri.deresolve(genPackage.getGenModel().eResource().getURI());
            }
            String stringURI = uri.toString();
            Object oldValue = nestedGenAnnotation.getDetails().put(genPackage.getNSURI(), stringURI);
            changed |= !stringURI.equals(oldValue);
            if (getGenModel().getUsedGenPackages().contains(genPackage)) {
              changed |= nestedGenAnnotation.getReferences().remove(genPackage);
            } else {
              changed |= nestedGenAnnotation.getReferences().add(genPackage);
            }
          }
          changed |= nestedGenAnnotation.getDetails().keySet().retainAll(nsURIs);
        }
        return changed;
      }
      
      protected boolean saveEPackageArtifactURI()
      {
        List<GenPackage> localGenPackages = new ConverterUtil.GenPackageList();
        List<EPackage> externalEPackages = new ConverterUtil.EPackageList();
        
        boolean isLocalGePackage = false;
        List<EPackage> ePackages = computeEPackagesToConvert();
        for (EPackage ePackage : ePackages)
        {
          for (Iterator<GenPackage> j = new GenPackagesTreeIterator(getGenModel()); j.hasNext();)
          {
            GenPackage genPackage = (GenPackage)j.next();
            if (genPackage.getEcorePackage() == ePackage)
            {
              isLocalGePackage = localGenPackages.add(genPackage);
              break;
            }
          }
          if (!isLocalGePackage) {
            externalEPackages.add(ePackage);
          } else {
            isLocalGePackage = false;
          }
        }
        boolean changed = false;
        if (!localGenPackages.isEmpty())
        {
          URI genModelURI = getGenModel().eResource() != null ? 
            getGenModel().eResource().getURI() : 
            null;
          
          Map<String, String> externalPackageToLocalURIMap = new HashMap(externalEPackages.size());
          for (EPackage ePackage : externalEPackages)
          {
            String location = getEPackageExportInfo(ePackage).getArtifactLocation();
            if (location != null)
            {
              URI uri = computeArtifactURI(location);
              if (genModelURI != null) {
                uri = uri.deresolve(genModelURI);
              }
              String stringURI = uri.toString();
              externalPackageToLocalURIMap.put(ePackage.getNsURI(), stringURI);
            }
          }
          for (GenPackage genPackage : lo
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd