org.eclipse.wst.common.emfworkbench.integration_1.2.101.v201107140600

16:48:48.311 INFO  jd.cli.Main - Decompiling org.eclipse.wst.common.emfworkbench.integration_1.2.101.v201107140600.jar
package org.eclipse.wst.common.internal.emfworkbench;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
import org.eclipse.jem.util.emf.workbench.WorkbenchURIConverterImpl;
import org.eclipse.wst.common.internal.emf.resource.CompatibilityURIConverter;

public class CompatibilityWorkbenchURIConverterImpl
  extends WorkbenchURIConverterImpl
  implements CompatibilityURIConverter
{
  public CompatibilityWorkbenchURIConverterImpl() {}
  
  public CompatibilityWorkbenchURIConverterImpl(IContainer anInputContainer)
  {
    super(anInputContainer);
  }
  
  public CompatibilityWorkbenchURIConverterImpl(IContainer aContainer, ResourceSetWorkbenchSynchronizer aSynchronizer)
  {
    super(aContainer, aSynchronizer);
  }
  
  public CompatibilityWorkbenchURIConverterImpl(IContainer anInputContainer, IContainer anOutputContainer)
  {
    super(anInputContainer, anOutputContainer);
  }
  
  public CompatibilityWorkbenchURIConverterImpl(IContainer anInputContainer, IContainer anOutputContainer, ResourceSetWorkbenchSynchronizer aSynchronizer)
  {
    super(anInputContainer, anOutputContainer, aSynchronizer);
  }
  
  public URI deNormalize(URI uri)
  {
    if (WorkbenchResourceHelperBase.isPlatformResourceURI(uri))
    {
      IFile aFile = WorkbenchResourceHelper.getPlatformFile(uri);
      if (aFile != null)
      {
        IProject fileProject = aFile.getProject();
        if (resourceSetSynchronizer.getProject() == fileProject) {
          return getContainerRelativeURI(aFile);
        }
      }
    }
    return uri;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.CompatibilityWorkbenchURIConverterImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;

public class DynamicGrowthModel
{
  private static final int MINIMUM_OPTIMAL_SIZE = 10;
  private static final int MEMORY_THRESHHOLD = 100;
  private static final int NOTICEABLE_CHANGE = 5;
  private final List queue = new LinkedList();
  private final Map uniquesMap = new HashMap();
  
  public synchronized boolean injectKey(IPath key)
  {
    int originalSize = getOptimalSize();
    
    int[] count = (int[])null;
    if ((count = (int[])uniquesMap.get(key)) != null) {
      count[0] += 1;
    } else {
      uniquesMap.put(key, count = new int[] { 1 });
    }
    if (queue.size() == 100)
    {
      IPath oldestKey = (IPath)queue.remove(0);
      
      count = (int[])uniquesMap.get(oldestKey);
      Assert.isNotNull(count);
      
      count[0] -= 1;
      
      Assert.isTrue(count[0] >= 0);
      if (count[0] == 0) {
        uniquesMap.remove(oldestKey);
      }
    }
    queue.add(key);
    
    return Math.abs(originalSize - getOptimalSize()) > 5;
  }
  
  public int getOptimalSize()
  {
    return uniquesMap.size() > 10 ? uniquesMap.size() : 10;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.DynamicGrowthModel
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.util.List;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.resource.Resource;

public class EMFWorkbenchContext$ResourceSetListener
  extends AdapterImpl
{
  protected EMFWorkbenchContext$ResourceSetListener(EMFWorkbenchContext paramEMFWorkbenchContext) {}
  
  public void notifyChanged(Notification notification)
  {
    switch (notification.getEventType())
    {
    case 3: 
      this$0.addedResource((Resource)notification.getNewValue());
      break;
    case 4: 
      this$0.removedResource((Resource)notification.getOldValue());
      break;
    case 6: 
      this$0.removedResources((List)notification.getOldValue());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext.ResourceSetListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Factory;
import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jem.util.emf.workbench.EMFWorkbenchContextBase;
import org.eclipse.jem.util.emf.workbench.ISynchronizerExtender;
import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
import org.eclipse.jem.util.emf.workbench.WorkbenchURIConverter;
import org.eclipse.wst.common.internal.emf.resource.CompatibilityXMIResource;
import org.eclipse.wst.common.internal.emf.resource.ReferencedXMIFactoryImpl;
import org.eclipse.wst.common.internal.emf.utilities.DefaultOverridableResourceFactoryRegistry;
import org.eclipse.wst.common.internal.emfworkbench.edit.EditModelRegistry;
import org.eclipse.wst.common.internal.emfworkbench.integration.EMFWorkbenchEditPlugin;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelEvent;
import org.eclipse.wst.common.internal.emfworkbench.integration.ProjectResourceSetEditImpl;

public class EMFWorkbenchContext
  extends EMFWorkbenchContextBase
  implements ISynchronizerExtender
{
  private Map readOnlyModels = new HashMap();
  private Map editableModels = new HashMap();
  protected Adapter resourceSetListener;
  protected boolean defaultToMOF5Compatibility = false;
  
  public EMFWorkbenchContext(IProject aProject)
  {
    super(aProject);
  }
  
  protected void initializeResourceSet(ProjectResourceSet aResourceSet)
  {
    super.initializeResourceSet(aResourceSet);
    Resource.Factory.Registry reg = new DefaultOverridableResourceFactoryRegistry();
    Resource.Factory factory = new ReferencedXMIFactoryImpl();
    reg.getExtensionToFactoryMap().put("*", factory);
    
    reg.getExtensionToFactoryMap().put("xmi", factory);
    aResourceSet.setResourceFactoryRegistry(reg);
    aResourceSet.getSynchronizer().addExtender(this);
    
    startListeningToResourceSet();
  }
  
  public static String getCacheID(String editModelID, Map params)
  {
    return EditModelRegistry.getInstance().getCacheID(editModelID, params);
  }
  
  public final EditModel getEditModelForWrite(String editModelID, Object accessorKey, Map params)
  {
    EditModel editModel = getExistingEditModel(editModelID, params, false);
    if (editModel == null)
    {
      editModel = createEditModelForWrite(editModelID, params);
      synchronized (editModel)
      {
        cacheEditModel(editModel, params);
        editModel.access(accessorKey);
      }
    }
    if ((editModel.isDisposed()) || (editModel.isDisposing()))
    {
      editModel = createEditModelForWrite(editModelID, params);
      cacheEditModel(editModel, params);
    }
    synchronized (editModel)
    {
      editModel.access(accessorKey);
    }
    return editModel;
  }
  
  public final EditModel getEditModelForRead(String editModelID, Object accessorKey, Map params)
  {
    try
    {
      EditModel editModel = getExistingEditModel(editModelID, params, true);
      if (editModel == null)
      {
        editModel = createEditModelForRead(editModelID, params);
        synchronized (editModel)
        {
          cacheEditModel(editModel, params);
          EditModelLeastUsedCache.getInstance().access(editModel);
          editModel.access(accessorKey);
        }
      }
      if ((editModel.isDisposed()) || (editModel.isDisposing()))
      {
        editModel = createEditModelForRead(editModelID, params);
        cacheEditModel(editModel, params);
      }
      synchronized (editModel)
      {
        EditModelLeastUsedCache.getInstance().access(editModel);
        editModel.access(accessorKey);
      }
      return editModel;
    }
    finally
    {
      EditModelLeastUsedCache.getInstance().optimizeLRUSizeIfNecessary();
    }
  }
  
  public final EditModel getEditModelForWrite(String editModelID, Object accessorKey)
  {
    return getEditModelForWrite(editModelID, accessorKey, null);
  }
  
  public final EditModel getEditModelForRead(String editModelID, Object accessorKey)
  {
    return getEditModelForRead(editModelID, accessorKey, null);
  }
  
  public EditModel getExistingEditModel(String editModelID, Map params, boolean isReadOnly)
  {
    EditModel editModel = null;
    synchronized (readOnlyModels)
    {
      if (isReadOnly) {
        editModel = (EditModel)readOnlyModels.get(getCacheID(editModelID, params));
      } else {
        synchronized (editableModels)
        {
          editModel = (EditModel)editableModels.get(getCacheID(editModelID, params));
        }
      }
    }
    return editModel;
  }
  
  protected EditModel createEditModelForRead(String editModelID, Map params)
  {
    return EditModelRegistry.getInstance().createEditModelForRead(editModelID, this, params);
  }
  
  protected EditModel createEditModelForWrite(String editModelID, Map params)
  {
    return EditModelRegistry.getInstance().createEditModelForWrite(editModelID, this, params);
  }
  
  public void cacheEditModel(EditModel editModel, Map params)
  {
    editModel.setParams(params);
    synchronized (readOnlyModels)
    {
      if (editModel.isReadOnly()) {
        readOnlyModels.put(getCacheID(editModel.getEditModelID(), params), editModel);
      } else {
        synchronized (editableModels)
        {
          editableModels.put(getCacheID(editModel.getEditModelID(), params), editModel);
        }
      }
    }
  }
  
  protected void discardAllEditModels()
  {
    synchronized (readOnlyModels)
    {
      synchronized (editableModels)
      {
        Collection readOnly = readOnlyModels.values();
        EditModelLeastUsedCache.getInstance().removeAllCached(readOnly);
        discardModels(readOnly);
        discardModels(editableModels.values());
      }
    }
  }
  
  private void discardModels(Collection editModels)
  {
    if ((editModels != null) && (!editModels.isEmpty()))
    {
      Iterator it = new ArrayList(editModels).iterator();
      while (it.hasNext()) {
        ((EditModel)it.next()).dispose();
      }
    }
  }
  
  public void removeEditModel(EditModel editModel, boolean readOnly)
  {
    synchronized (readOnlyModels)
    {
      if (readOnly) {
        readOnlyModels.values().remove(editModel);
      } else {
        synchronized (editableModels)
        {
          editableModels.values().remove(editModel);
        }
      }
    }
  }
  
  protected void notifyEditModels(EditModelEvent anEvent)
  {
    if (anEvent == null) {
      return;
    }
    List aList = new ArrayList();
    synchronized (readOnlyModels)
    {
      synchronized (editableModels)
      {
        aList.addAll(readOnlyModels.values());
        aList.addAll(editableModels.values());
      }
    }
    for (int i = 0; i < aList.size(); i++)
    {
      EditModel editModel = (EditModel)aList.get(i);
      try
      {
        editModel.resourceChanged(anEvent);
      }
      catch (Exception e)
      {
        EMFWorkbenchEditPlugin.logError(e);
      }
    }
  }
  
  protected boolean shouldNotifyEditModels()
  {
    synchronized (readOnlyModels)
    {
      synchronized (editableModels)
      {
        return (!readOnlyModels.isEmpty()) || (!editableModels.isEmpty());
      }
    }
  }
  
  protected Adapter getResourceSetListener()
  {
    if (resourceSetListener == null) {
      resourceSetListener = new ResourceSetListener();
    }
    return resourceSetListener;
  }
  
  protected class ResourceSetListener
    extends AdapterImpl
  {
    protected ResourceSetListener() {}
    
    public void notifyChanged(Notification notification)
    {
      switch (notification.getEventType())
      {
      case 3: 
        addedResource((Resource)notification.getNewValue());
        break;
      case 4: 
        removedResource((Resource)notification.getOldValue());
        break;
      case 6: 
        removedResources((List)notification.getOldValue());
      }
    }
  }
  
  public void addedResource(Resource addedResource)
  {
    if ((defaultToMOF5Compatibility) && (addedResource != null) && ((addedResource instanceof CompatibilityXMIResource))) {
      ((CompatibilityXMIResource)addedResource).setFormat(1);
    }
    if (shouldNotifyEditModels())
    {
      EditModelEvent event = new EditModelEvent(4, null);
      event.addResource(addedResource);
      notifyEditModels(event);
    }
  }
  
  public void removedResource(Resource removedResource)
  {
    if (shouldNotifyEditModels())
    {
      EditModelEvent event = new EditModelEvent(3, null);
      event.addResource(removedResource);
      notifyEditModels(event);
    }
  }
  
  public void removedResources(List removedResources)
  {
    if (shouldNotifyEditModels())
    {
      EditModelEvent event = new EditModelEvent(3, null);
      event.addResources(removedResources);
      notifyEditModels(event);
    }
  }
  
  protected void startListeningToResourceSet()
  {
    ResourceSet set = getResourceSet();
    if (set != null) {
      set.eAdapters().add(getResourceSetListener());
    }
  }
  
  public void projectChanged(IResourceDelta delta) {}
  
  public void projectClosed()
  {
    discardAllEditModels();
  }
  
  protected WorkbenchURIConverter createURIConverter(ProjectResourceSet aResourceSet)
  {
    return new CompatibilityWorkbenchURIConverterImpl(getProject(), aResourceSet.getSynchronizer());
  }
  
  protected ProjectResourceSet createResourceSet()
  {
    if (project == null) {
      throw new IllegalStateException("Attempt to create resource set with null project");
    }
    return new ProjectResourceSetEditImpl(project);
  }
  
  public void deleteFile(Resource resource)
  {
    try
    {
      WorkbenchResourceHelper.deleteResource(resource);
    }
    catch (CoreException ex)
    {
      EMFWorkbenchEditPlugin.logError(ex);
    }
  }
  
  public boolean isDefaultToMOF5Compatibility()
  {
    return defaultToMOF5Compatibility;
  }
  
  public void setDefaultToMOF5Compatibility(boolean defaultToMOF5Compatibility)
  {
    this.defaultToMOF5Compatibility = defaultToMOF5Compatibility;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import org.eclipse.osgi.util.NLS;

public class EMFWorkbenchEditResourceHandler
  extends NLS
{
  private static final String BUNDLE_NAME = "emfworkbenchedit";
  public static String ClientAccessRegistryException_UI_1;
  public static String ClientAccessRegistryException_UI_0;
  public static String Snapshot_ERROR_0;
  public static String EditModelRegistry_ERROR_2;
  public static String EditModelRegistry_ERROR_1;
  public static String EditModelRegistry_ERROR_0;
  public static String AdapterFactoryDescriptor_ERROR_1;
  public static String AdapterFactoryDescriptor_ERROR_0;
  public static String DynamicAdapterFactory_ERROR_0;
  public static String ClientAccessRegistry_ERROR_1;
  public static String ClientAccessRegistry_ERROR_0;
  
  static
  {
    NLS.initializeMessages("emfworkbenchedit", EMFWorkbenchEditResourceHandler.class);
  }
  
  public static String getString(String key, Object[] args)
  {
    return NLS.bind(key, args);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;

public class EditModelLeastUsedCache
{
  private static EditModelLeastUsedCache INSTANCE = new EditModelLeastUsedCache();
  private static final int threshhold = 10;
  private LinkedHashSet lru = new LinkedHashSet(10);
  
  public static EditModelLeastUsedCache getInstance()
  {
    return INSTANCE;
  }
  
  public void removeAllCached(Collection aCollection)
  {
    if (aCollection != null) {
      lru.removeAll(aCollection);
    }
  }
  
  public void access(EditModel editModel)
  {
    boolean shouldAccess = true;
    synchronized (lru)
    {
      if (lru.contains(editModel))
      {
        moveToEnd(editModel);
        shouldAccess = false;
      }
    }
    if (shouldAccess)
    {
      editModel.access(this);
      synchronized (lru)
      {
        lru.add(editModel);
      }
    }
  }
  
  public void optimizeLRUSizeIfNecessary()
  {
    EditModel model = null;
    synchronized (lru)
    {
      if (lru.size() > 10)
      {
        Iterator iterator = lru.iterator();
        model = (EditModel)iterator.next();
        if (model != null) {
          lru.remove(model);
        }
      }
    }
    if (model != null) {
      model.releaseAccess(this);
    }
  }
  
  private void moveToEnd(EditModel editModel)
  {
    lru.remove(editModel);
    lru.add(editModel);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.EditModelLeastUsedCache
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;

public class EmfPackagePropertyTester
  extends PropertyTester
{
  public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
  {
    if ((receiver == null) || (!(receiver instanceof EObject)) || (expectedValue == null) || (!(expectedValue instanceof String))) {
      return false;
    }
    EObject eObject = (EObject)receiver;
    String emfPackage = (String)expectedValue;
    return emfPackage.equals(eObject.eClass().getEPackage().getNsURI());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.EmfPackagePropertyTester
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.wst.validation.internal.IValidationSelectionHandler;

public class EmfValidationHandler
  implements IValidationSelectionHandler
{
  private String validationType = null;
  
  public IResource getBaseValidationType(Object selection)
  {
    if ((selection instanceof EObject))
    {
      EObject eObject = (EObject)selection;
      Resource resource = eObject.eResource();
      IProject project = ProjectUtilities.getProject(resource);
      return project;
    }
    return null;
  }
  
  public String getValidationTypeString()
  {
    return validationType;
  }
  
  public void setValidationTypeString(String validationType)
  {
    this.validationType = validationType;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.EmfValidationHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.util.Collection;
import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl.SynchronizedResourcesEList;
import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;

public class PassthruResourceSet$PassthruResourcesEList
  extends ProjectResourceSetImpl.SynchronizedResourcesEList
{
  private static final long serialVersionUID = 2504207070244627980L;
  
  public PassthruResourceSet$PassthruResourcesEList(PassthruResourceSet paramPassthruResourceSet)
  {
    super(paramPassthruResourceSet);
  }
  
  public boolean add(Object object)
  {
    if (object == null) {
      return false;
    }
    ResourceSet set = WorkbenchResourceHelperBase.getResourceSet(((Resource)object).getURI());
    if (set != null) {
      return set.getResources().add((Resource)object);
    }
    return super.add(object);
  }
  
  public boolean addAll(Collection collection)
  {
    if (collection.isEmpty()) {
      return false;
    }
    Iterator it = collection.iterator();
    while (it.hasNext())
    {
      Resource res = (Resource)it.next();
      if (!WorkbenchResourceHelperBase.cacheResource(res)) {
        super.add(res);
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.PassthruResourceSet.PassthruResourcesEList
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.util.Collection;
import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl;
import org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl.SynchronizedResourcesEList;
import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;

public class PassthruResourceSet
  extends ProjectResourceSetImpl
{
  protected boolean isIsolated = false;
  
  public class PassthruResourcesEList
    extends ProjectResourceSetImpl.SynchronizedResourcesEList
  {
    private static final long serialVersionUID = 2504207070244627980L;
    
    public PassthruResourcesEList()
    {
      super();
    }
    
    public boolean add(Object object)
    {
      if (object == null) {
        return false;
      }
      ResourceSet set = WorkbenchResourceHelperBase.getResourceSet(((Resource)object).getURI());
      if (set != null) {
        return set.getResources().add((Resource)object);
      }
      return super.add(object);
    }
    
    public boolean addAll(Collection collection)
    {
      if (collection.isEmpty()) {
        return false;
      }
      Iterator it = collection.iterator();
      while (it.hasNext())
      {
        Resource res = (Resource)it.next();
        if (!WorkbenchResourceHelperBase.cacheResource(res)) {
          super.add(res);
        }
      }
      return true;
    }
  }
  
  public PassthruResourceSet()
  {
    isIsolated = false;
  }
  
  public PassthruResourceSet(IProject project)
  {
    setProject(project);
    isIsolated = true;
  }
  
  public boolean isIsolated()
  {
    return isIsolated;
  }
  
  public Resource createResource(URI uri)
  {
    Resource result = WorkbenchResourceHelperBase.getExistingOrCreateResource(uri);
    if (result == null) {
      return super.createResource(uri);
    }
    return result;
  }
  
  protected Resource demandCreateResource(URI uri)
  {
    Resource result = WorkbenchResourceHelperBase.createResource(uri);
    if (result == null) {
      return super.createResource(uri);
    }
    return result;
  }
  
  public EList getResources()
  {
    if (isIsolated) {
      return super.getResources();
    }
    if (resources == null) {
      resources = new PassthruResourcesEList();
    }
    return resources;
  }
  
  protected Resource createResourceFromHandlers(URI uri)
  {
    if (!isIsolated) {
      return super.createResourceFromHandlers(uri);
    }
    return null;
  }
  
  protected Resource getResourceFromHandlers(URI uri)
  {
    if (!isIsolated) {
      return super.getResourceFromHandlers(uri);
    }
    return null;
  }
  
  protected EObject getEObjectFromHandlers(URI uri, boolean loadOnDemand)
  {
    if (!isIsolated) {
      return super.getEObjectFromHandlers(uri, loadOnDemand);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.PassthruResourceSet
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.ILock;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;

class WorkbenchResourceHelper$FileAdapter
  extends AdapterImpl
{
  public static final Object ADAPTER_KEY = FileAdapter.class.getName();
  private static final long delay = 30L;
  private IFile file;
  private long synchronizationStamp;
  protected ResourceSet previousResourceSet;
  private ILock saveLock;
  public static final int FILE_NOT_LOADED = 0;
  public static final int FILE_INACCESSIBLE = -1;
  
  public boolean isAdapterForType(Object type)
  {
    return ADAPTER_KEY.equals(type);
  }
  
  public void notifyChanged(Notification msg)
  {
    switch (msg.getFeatureID(null))
    {
    case 4: 
      if (getResource().isLoaded()) {
        handleLoaded();
      } else {
        handleUnloaded();
      }
      break;
    case 602: 
      handleAboutToSave();
      break;
    case 601: 
      handleSaved();
      break;
    case 603: 
      handleSaveFailed();
      break;
    case 1: 
      handleURIChanged();
    }
  }
  
  private void handleSaveFailed()
  {
    releaseSaveLock();
  }
  
  private void handleAboutToSave()
  {
    aquireSaveLock();
  }
  
  private void aquireSaveLock()
  {
    getSaveLock().acquire();
  }
  
  private boolean aquireSaveLock(long delay)
    throws InterruptedException
  {
    return getSaveLock().acquire(delay);
  }
  
  private void releaseSaveLock()
  {
    getSaveLock().release();
  }
  
  private ILock getSaveLock()
  {
    if (saveLock == null) {
      saveLock = Platform.getJobManager().newLock();
    }
    return saveLock;
  }
  
  private void handleURIChanged()
  {
    file = null;
    synchronizationStamp = 0L;
  }
  
  public IFile getFile()
  {
    if ((file != null) && ((!file.isAccessible()) || (previousResourceSet != getResourceSet())))
    {
      file = null;
      synchronizationStamp = 0L;
    }
    if (file == null)
    {
      if (WorkbenchResourceHelper.isPlatformResourceURI(getURI())) {
        file = WorkbenchResourceHelper.getPlatformFile(getURI());
      } else {
        file = WorkbenchResourceHelper.internalGetFile(getResource());
      }
      if ((file != null) && (!file.isAccessible())) {
        synchronizationStamp = -1L;
      }
      previousResourceSet = getResourceSet();
    }
    return file;
  }
  
  public long getSynchronizationStamp()
  {
    return synchronizationStamp;
  }
  
  public void setSynchronizationStamp(long l)
  {
    synchronizationStamp = l;
  }
  
  /* Error */
  public boolean isConsistent()
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 190	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:getResource	()Lorg/eclipse/wst/common/internal/emf/resource/ReferencedResource;
    //   4: invokeinterface 199 1 0
    //   9: ifne +5 -> 14
    //   12: iconst_1
    //   13: ireturn
    //   14: iconst_0
    //   15: istore_1
    //   16: aload_0
    //   17: ldc2_w 81
    //   20: invokespecial 185	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:aquireSaveLock	(J)Z
    //   23: istore_1
    //   24: goto +8 -> 32
    //   27: astore_2
    //   28: aload_2
    //   29: invokestatic 191	org/eclipse/wst/common/internal/emfworkbench/integration/EMFWorkbenchEditPlugin:logError	(Ljava/lang/Throwable;)V
    //   32: iconst_0
    //   33: istore_2
    //   34: aload_0
    //   35: invokevirtual 186	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:getFile	()Lorg/eclipse/core/resources/IFile;
    //   38: ifnull +15 -> 53
    //   41: aload_0
    //   42: invokevirtual 186	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:getFile	()Lorg/eclipse/core/resources/IFile;
    //   45: invokeinterface 192 1 0
    //   50: ifne +8 -> 58
    //   53: iconst_1
    //   54: istore_2
    //   55: goto +74 -> 129
    //   58: aload_0
    //   59: invokevirtual 186	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:getFile	()Lorg/eclipse/core/resources/IFile;
    //   62: iconst_0
    //   63: invokeinterface 193 2 0
    //   68: ifne +8 -> 76
    //   71: iconst_0
    //   72: istore_2
    //   73: goto +56 -> 129
    //   76: aload_0
    //   77: getfield 160	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:synchronizationStamp	J
    //   80: aload_0
    //   81: invokevirtual 186	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:getFile	()Lorg/eclipse/core/resources/IFile;
    //   84: invokestatic 170	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper:computeModificationStamp	(Lorg/eclipse/core/resources/IFile;)J
    //   87: lcmp
    //   88: ifne +7 -> 95
    //   91: iconst_1
    //   92: goto +4 -> 96
    //   95: iconst_0
    //   96: istore_2
    //   97: goto +32 -> 129
    //   100: astore_3
    //   101: aload_3
    //   102: invokestatic 191	org/eclipse/wst/common/internal/emfworkbench/integration/EMFWorkbenchEditPlugin:logError	(Ljava/lang/Throwable;)V
    //   105: iload_1
    //   106: ifeq +31 -> 137
    //   109: aload_0
    //   110: invokespecial 183	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:releaseSaveLock	()V
    //   113: goto +24 -> 137
    //   116: astore 4
    //   118: iload_1
    //   119: ifeq +7 -> 126
    //   122: aload_0
    //   123: invokespecial 183	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:releaseSaveLock	()V
    //   126: aload 4
    //   128: athrow
    //   129: iload_1
    //   130: ifeq +7 -> 137
    //   133: aload_0
    //   134: invokespecial 183	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:releaseSaveLock	()V
    //   137: iload_2
    //   138: ireturn
    // Line number table:
    //   Java source line #209	-> byte code offset #0
    //   Java source line #210	-> byte code offset #12
    //   Java source line #211	-> byte code offset #14
    //   Java source line #213	-> byte code offset #16
    //   Java source line #214	-> byte code offset #27
    //   Java source line #215	-> byte code offset #28
    //   Java source line #217	-> byte code offset #32
    //   Java source line #220	-> byte code offset #34
    //   Java source line #221	-> byte code offset #53
    //   Java source line #223	-> byte code offset #58
    //   Java source line #224	-> byte code offset #71
    //   Java source line #226	-> byte code offset #76
    //   Java source line #229	-> byte code offset #100
    //   Java source line #230	-> byte code offset #101
    //   Java source line #232	-> byte code offset #105
    //   Java source line #233	-> byte code offset #109
    //   Java source line #231	-> byte code offset #116
    //   Java source line #232	-> byte code offset #118
    //   Java source line #233	-> byte code offset #122
    //   Java source line #234	-> byte code offset #126
    //   Java source line #232	-> byte code offset #129
    //   Java source line #233	-> byte code offset #133
    //   Java source line #235	-> byte code offset #137
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	139	0	this	FileAdapter
    //   15	115	1	hasLocked	boolean
    //   27	2	2	e	InterruptedException
    //   33	105	2	result	boolean
    //   100	2	3	e	Exception
    //   116	11	4	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   16	24	27	java/lang/InterruptedException
    //   34	97	100	java/lang/Exception
    //   34	105	116	finally
  }
  
  public void cacheSynchronizationStamp()
  {
    setSynchronizationStamp(WorkbenchResourceHelper.computeModificationStamp(getFile()));
  }
  
  public ReferencedResource getResource()
  {
    return (ReferencedResource)target;
  }
  
  public URI getURI()
  {
    return target == null ? null : getResource().getURI();
  }
  
  public ResourceSet getResourceSet()
  {
    return target == null ? null : getResource().getResourceSet();
  }
  
  public void handleUnloaded()
  {
    file = null;
    synchronizationStamp = 0L;
  }
  
  public void handleLoaded()
  {
    cacheSynchronizationStamp();
  }
  
  public void handleSaved()
  {
    cacheSynchronizationStamp();
    releaseSaveLock();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper.FileAdapter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;

class WorkbenchResourceHelper$FileAdapterFactory
  extends AdapterFactoryImpl
{
  public Adapter adaptNew(Notifier target, Object type)
  {
    WorkbenchResourceHelper.FileAdapter adapter = new WorkbenchResourceHelper.FileAdapter(null);
    adapter.setTarget(target);
    return adapter;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper.FileAdapterFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.common.internal.emfworkbench;

import java.io.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.ILock;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
import org.eclipse.wst.common.internal.emf.resource.ReferencedXMIFactoryImpl;
import org.eclipse.wst.common.internal.emf.utilities.ExtendedEcoreUtil;
import org.eclipse.wst.common.internal.emf.utilities.ExtendedEcoreUtil.FileNotFoundDetector;

public class WorkbenchResourceHelper
  extends WorkbenchResourceHelperBase
{
  protected static Class REFERENCED_RES_CLASS = ReferencedResource.class;
  private static boolean fileAdapterFactoryInitialized = false;
  
  private static class FileAdapterFactory
    extends AdapterFactoryImpl
  {
    public Adapter adaptNew(Notifier target, Object type)
    {
      WorkbenchResourceHelper.FileAdapter adapter = new WorkbenchResourceHelper.FileAdapter(null);
      adapter.setTarget(target);
      return adapter;
    }
  }
  
  private static class FileAdapter
    extends AdapterImpl
  {
    public static final Object ADAPTER_KEY = FileAdapter.class.getName();
    private static final long delay = 30L;
    private IFile file;
    private long synchronizationStamp;
    protected ResourceSet previousResourceSet;
    private ILock saveLock;
    public static final int FILE_NOT_LOADED = 0;
    public static final int FILE_INACCESSIBLE = -1;
    
    public boolean isAdapterForType(Object type)
    {
      return ADAPTER_KEY.equals(type);
    }
    
    public void notifyChanged(Notification msg)
    {
      switch (msg.getFeatureID(null))
      {
      case 4: 
        if (getResource().isLoaded()) {
          handleLoaded();
        } else {
          handleUnloaded();
        }
        break;
      case 602: 
        handleAboutToSave();
        break;
      case 601: 
        handleSaved();
        break;
      case 603: 
        handleSaveFailed();
        break;
      case 1: 
        handleURIChanged();
      }
    }
    
    private void handleSaveFailed()
    {
      releaseSaveLock();
    }
    
    private void handleAboutToSave()
    {
      aquireSaveLock();
    }
    
    private void aquireSaveLock()
    {
      getSaveLock().acquire();
    }
    
    private boolean aquireSaveLock(long delay)
      throws InterruptedException
    {
      return getSaveLock().acquire(delay);
    }
    
    private void releaseSaveLock()
    {
      getSaveLock().release();
    }
    
    private ILock getSaveLock()
    {
      if (saveLock == null) {
        saveLock = Platform.getJobManager().newLock();
      }
      return saveLock;
    }
    
    private void handleURIChanged()
    {
      file = null;
      synchronizationStamp = 0L;
    }
    
    public IFile getFile()
    {
      if ((file != null) && ((!file.isAccessible()) || (previousResourceSet != getResourceSet())))
      {
        file = null;
        synchronizationStamp = 0L;
      }
      if (file == null)
      {
        if (WorkbenchResourceHelper.isPlatformResourceURI(getURI())) {
          file = WorkbenchResourceHelper.getPlatformFile(getURI());
        } else {
          file = WorkbenchResourceHelper.internalGetFile(getResource());
        }
        if ((file != null) && (!file.isAccessible())) {
          synchronizationStamp = -1L;
        }
        previousResourceSet = getResourceSet();
      }
      return file;
    }
    
    public long getSynchronizationStamp()
    {
      return synchronizationStamp;
    }
    
    public void setSynchronizationStamp(long l)
    {
      synchronizationStamp = l;
    }
    
    /* Error */
    public boolean isConsistent()
    {
      // Byte code:
      //   0: aload_0
      //   1: invokevirtual 190	org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper$FileAdapter:getResource	()Lorg/eclipse/wst/common/internal/emf/resource/ReferencedResource;
      //   4: invokeinterface 199 1 0
      //   9: ifne +5 -> 14
      //   12: iconst_1
      //   13: ireturn
      //   14: iconst_0
      //   15: istore_1
      //   16: aload
1 2 3 4 5 6 7 8

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-2019. Infinite Loop Ltd