org.eclipse.wst.common.modulecore_1.2.103.v201201190400

16:48:52.634 INFO  jd.cli.Main - Decompiling org.eclipse.wst.common.modulecore_1.2.103.v201201190400.jar
package org.eclipse.wst.common.componentcore;

import java.util.EventObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jem.internal.util.emf.workbench.nls.EMFWorkbenchResourceHandler;
import org.eclipse.jem.util.UIContextDetermination;
import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel;
import org.eclipse.wst.common.componentcore.internal.BinaryComponentHelper;
import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener;
import org.eclipse.wst.common.internal.emfworkbench.validateedit.IValidateEditContext;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;

public class ArtifactEdit
  implements IEditModelHandler, IAdaptable
{
  public static final Class ADAPTER_TYPE = ArtifactEdit.class;
  private final ArtifactEditModel artifactEditModel;
  private boolean isReadOnly;
  private boolean isArtifactEditModelSelfManaged;
  private boolean isBinary;
  private BinaryComponentHelper binaryComponentHelper;
  private final IProject project;
  
  protected ArtifactEdit()
  {
    artifactEditModel = null;
    project = null;
  }
  
  public static ArtifactEdit getArtifactEditForRead(IVirtualComponent aModule)
  {
    if (aModule.isBinary()) {
      return new ArtifactEdit(aModule);
    }
    if (isValidEditableModule(aModule))
    {
      IProject project = aModule.getProject();
      ModuleCoreNature nature = ModuleCoreNature.getModuleCoreNature(project);
      return new ArtifactEdit(nature, aModule, true);
    }
    return null;
  }
  
  public static ArtifactEdit getArtifactEditForWrite(IVirtualComponent aModule)
  {
    if ((!aModule.isBinary()) && (isValidEditableModule(aModule)))
    {
      IProject project = aModule.getProject();
      ModuleCoreNature nature = ModuleCoreNature.getModuleCoreNature(project);
      return new ArtifactEdit(nature, aModule, false);
    }
    return null;
  }
  
  public static ArtifactEdit getArtifactEditForRead(IProject aProject)
  {
    ArtifactEdit artifactEdit = null;
    try
    {
      artifactEdit = new ArtifactEdit(aProject, true);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      artifactEdit = null;
    }
    return artifactEdit;
  }
  
  public static ArtifactEdit getArtifactEditForWrite(IProject aProject)
  {
    ArtifactEdit artifactEdit = null;
    try
    {
      artifactEdit = new ArtifactEdit(aProject, false);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      artifactEdit = null;
    }
    return artifactEdit;
  }
  
  public static boolean isValidEditableModule(IVirtualComponent aModule)
  {
    if (aModule == null) {
      return false;
    }
    if (ModuleURIUtil.fullyQualifyURI(aModule.getProject()) == null) {
      return false;
    }
    IProject project = aModule.getProject();
    if ((project == null) || (!project.isAccessible())) {
      return false;
    }
    return true;
  }
  
  public ArtifactEdit(ArtifactEditModel anArtifactEditModel)
  {
    artifactEditModel = anArtifactEditModel;
    isReadOnly = artifactEditModel.isReadOnly();
    isArtifactEditModelSelfManaged = false;
    
    project = anArtifactEditModel.getProject();
  }
  
  protected ArtifactEdit(IVirtualComponent aBinaryModule)
  {
    if (!aBinaryModule.isBinary()) {
      throw new RuntimeException("This constructor is only for binary components.");
    }
    binaryComponentHelper = initBinaryComponentHelper(aBinaryModule);
    artifactEditModel = null;
    isReadOnly = true;
    isBinary = true;
    isArtifactEditModelSelfManaged = true;
    project = null;
  }
  
  protected BinaryComponentHelper initBinaryComponentHelper(IVirtualComponent binaryModule)
  {
    return null;
  }
  
  protected ArtifactEdit(ModuleCoreNature aNature, IVirtualComponent aModule, boolean toAccessAsReadOnly)
  {
    isReadOnly = toAccessAsReadOnly;
    isArtifactEditModelSelfManaged = true;
    project = aNature.getProject();
    IProject aProject = aModule.getProject();
    URI componentURI = ModuleURIUtil.fullyQualifyURI(aProject);
    Map editModelParams = null;
    if (getContentTypeDescriber() != null)
    {
      editModelParams = new HashMap();
      editModelParams.put("ROOT_URI", getRootURI());
      editModelParams.put("ROOT_CONTENT_TYPE", getContentTypeDescriber());
    }
    if (toAccessAsReadOnly) {
      artifactEditModel = aNature.getArtifactEditModelForRead(componentURI, this, null, editModelParams);
    } else {
      artifactEditModel = aNature.getArtifactEditModelForWrite(componentURI, this, null, editModelParams);
    }
  }
  
  public ArtifactEdit(IProject aProject, boolean toAccessAsReadOnly)
    throws IllegalArgumentException
  {
    this(aProject, toAccessAsReadOnly, false, null);
  }
  
  protected ArtifactEdit(IProject aProject, boolean toAccessAsReadOnly, boolean forCreate, String projectType)
    throws IllegalArgumentException
  {
    this(aProject, toAccessAsReadOnly, forCreate, projectType, null);
  }
  
  protected void verifyOperationSupported()
  {
    if (!validArtifactEdit) {
      throw new RuntimeException("Invalid Artifact Edit access (model version not supported)");
    }
  }
  
  private boolean validArtifactEdit = true;
  
  public boolean isValid()
  {
    return validArtifactEdit;
  }
  
  protected void markInvalid()
  {
    Logger.global.log(Level.WARNING, "Invalid Artifact Edit access (model version not supported)");
    validArtifactEdit = false;
  }
  
  protected ArtifactEdit(IProject aProject, boolean toAccessAsReadOnly, boolean forCreate, String projectType, Map editModelParams)
    throws IllegalArgumentException
  {
    if ((aProject == null) || (!aProject.isAccessible())) {
      throw new IllegalArgumentException("Invalid project: " + aProject);
    }
    ModuleCoreNature nature = ModuleCoreNature.getModuleCoreNature(aProject);
    if (nature == null) {
      throw new IllegalArgumentException("Project does not have ModuleCoreNature: " + aProject);
    }
    if (!validProjectVersion(aProject)) {
      markInvalid();
    }
    IVirtualComponent component = ComponentCore.createComponent(aProject);
    if (component == null) {
      throw new IllegalArgumentException("Invalid component handle: " + aProject);
    }
    if ((!forCreate) && (!isValidEditableModule(component))) {
      throw new IllegalArgumentException("Invalid component handle: " + aProject);
    }
    project = aProject;
    URI componentURI = ModuleURIUtil.fullyQualifyURI(aProject);
    if (getContentTypeDescriber() != null)
    {
      if (editModelParams == null) {
        editModelParams = new HashMap();
      }
      editModelParams.put("ROOT_URI", getRootURI());
      editModelParams.put("ROOT_CONTENT_TYPE", getContentTypeDescriber());
    }
    if (toAccessAsReadOnly) {
      artifactEditModel = nature.getArtifactEditModelForRead(componentURI, this, projectType, editModelParams);
    } else {
      artifactEditModel = nature.getArtifactEditModelForWrite(componentURI, this, projectType, editModelParams);
    }
    isReadOnly = toAccessAsReadOnly;
    isArtifactEditModelSelfManaged = true;
  }
  
  public boolean isProjectOfType(IProject project, String typeID)
  {
    IFacetedProject facetedProject = null;
    try
    {
      facetedProject = ProjectFacetsManager.create(project);
    }
    catch (CoreException localCoreException)
    {
      return false;
    }
    if ((facetedProject != null) && (ProjectFacetsManager.isProjectFacetDefined(typeID)))
    {
      IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID);
      return (projectFacet != null) && (facetedProject.hasProjectFacet(projectFacet));
    }
    return false;
  }
  
  protected String getContentTypeDescriber()
  {
    if (isProjectOfType(project, "jst.ejb")) {
      return "org.eclipse.jst.j2ee.ejbDD";
    }
    if (isProjectOfType(project, "jst.web")) {
      return "org.eclipse.jst.j2ee.webDD";
    }
    if (isProjectOfType(project, "jst.ear")) {
      return "org.eclipse.jst.j2ee.earDD";
    }
    if (isProjectOfType(project, "jst.appclient")) {
      return "org.eclipse.jst.j2ee.appclientDD";
    }
    return null;
  }
  
  protected URI getRootURI()
  {
    if (isProjectOfType(project, "jst.ejb")) {
      return URI.createURI("META-INF/ejb-jar.xml");
    }
    if (isProjectOfType(project, "jst.web")) {
      return URI.createURI("WEB-INF/web.xml");
    }
    if (isProjectOfType(project, "jst.ear")) {
      return URI.createURI("META-INF/application.xml");
    }
    if (isProjectOfType(project, "jst.appclient")) {
      return URI.createURI("META-INF/application-client.xml");
    }
    return null;
  }
  
  protected boolean validProjectVersion(IProject project2)
  {
    return true;
  }
  
  public void save(IProgressMonitor aMonitor)
  {
    if (isReadOnly()) {
      throwAttemptedReadOnlyModification();
    } else if (validateEdit().isOK()) {
      artifactEditModel.save(aMonitor, this);
    }
  }
  
  public void saveIfNecessary(IProgressMonitor aMonitor)
  {
    if (isReadOnly()) {
      throwAttemptedReadOnlyModification();
    } else if ((artifactEditModel.isDirty()) && (validateEdit().isOK())) {
      artifactEditModel.saveIfNecessary(aMonitor, this);
    }
  }
  
  public IStatus validateEdit()
  {
    IValidateEditContext validator = (IValidateEditContext)UIContextDetermination.createInstance("ValidateEditContext");
    return validator.validateState(getArtifactEditModel());
  }
  
  public void saveIfNecessaryWithPrompt(IProgressMonitor monitor, IOperationHandler operationHandler, boolean wasDirty)
  {
    if (shouldSave(operationHandler, wasDirty)) {
      saveIfNecessary(monitor);
    } else {
      handleSaveIfNecessaryDidNotSave(monitor);
    }
  }
  
  private void handleSaveIfNecessaryDidNotSave(IProgressMonitor monitor) {}
  
  private boolean shouldSave(IOperationHandler operationHandler, boolean wasDirty)
  {
    return !wasDirty ? shouldSave() : shouldSave(operationHandler);
  }
  
  private boolean promptToSave(IOperationHandler operationHandler)
  {
    if (operationHandler == null) {
      return false;
    }
    return operationHandler.canContinue(EMFWorkbenchResourceHandler.getString("The_following_resources_ne_UI_"), getArtifactEditModel().getResourceURIs(true));
  }
  
  private boolean shouldSave(IOperationHandler operationHandler)
  {
    return (shouldSave()) || (promptToSave(operationHandler));
  }
  
  private boolean shouldSave()
  {
    return (!isReadOnly()) && (isArtifactEditModelSelfManaged);
  }
  
  public void dispose()
  {
    if (isBinary()) {
      binaryComponentHelper.dispose();
    } else if ((isArtifactEditModelSelfManaged) && (artifactEditModel != null)) {
      artifactEditModel.releaseAccess(this);
    }
  }
  
  public EObject getContentModelRoot()
  {
    if (isBinary()) {
      return binaryComponentHelper.getPrimaryRootObject();
    }
    if (artifactEditModel != null) {
      return artifactEditModel.getPrimaryRootObject();
    }
    return null;
  }
  
  public void addListener(EditModelListener listener)
  {
    if (!isBinary()) {
      if ((artifactEditModel != null) && (listener != null)) {
        artifactEditModel.addListener(listener);
      }
    }
  }
  
  public void removeListener(EditModelListener listener)
  {
    if ((!isBinary()) && 
      (artifactEditModel != null) && (!artifactEditModel.isDisposed())) {
      artifactEditModel.removeListener(listener);
    }
  }
  
  public boolean hasEditModel(EditModel editModel)
  {
    if (isBinary()) {
      return false;
    }
    return artifactEditModel == editModel;
  }
  
  public IProject getProject()
  {
    if (isBinary()) {
      return null;
    }
    return project;
  }
  
  public IVirtualComponent getComponent()
  {
    if (isBinary()) {
      return binaryComponentHelper.getComponent();
    }
    return getArtifactEditModel().getVirtualComponent();
  }
  
  protected ArtifactEditModel getArtifactEditModel()
  {
    if (isBinary()) {
      throwAttemptedBinaryEditModelAccess();
    }
    return artifactEditModel;
  }
  
  protected BinaryComponentHelper getBinaryComponentHelper()
  {
    return binaryComponentHelper;
  }
  
  public CommandStack getCommandStack()
  {
    if (isBinary()) {
      return new BasicCommandStack();
    }
    return artifactEditModel.getCommandStack();
  }
  
  /**
   * @deprecated
   */
  public void deleteResource(Resource aResource)
  {
    if (isBinary()) {
      throwAttemptedBinaryEditModelAccess();
    }
    artifactEditModel.deleteResource(aResource);
  }
  
  public boolean isDirty()
  {
    if (isBinary()) {
      return false;
    }
    return artifactEditModel.isDirty();
  }
  
  private void throwAttemptedReadOnlyModification()
  {
    throw new IllegalStateException("Attempt to modify an ArtifactEdit instance facade that was loaded as read-only.");
  }
  
  protected void throwAttemptedBinaryEditModelAccess()
  {
    throw new IllegalStateException("Attempt to modify an ArtifactEdit instance facade that was loaded as binary.");
  }
  
  public boolean isReadOnly()
  {
    return isReadOnly;
  }
  
  public boolean isBinary()
  {
    return isBinary;
  }
  
  public void forceLoadKnownResources()
  {
    if (!isBinary())
    {
      List uris = getArtifactEditModel().getKnownResourceUris();
      URI uri = null;
      for (int i = 0; i < uris.size(); i++)
      {
        uri = (URI)uris.get(i);
        getArtifactEditModel().getResource(uri);
      }
    }
  }
  
  /**
   * @deprecated
   */
  public Resource getResource(URI aUri)
  {
    if (isBinary()) {
      return binaryComponentHelper.getResource(aUri);
    }
    return getArtifactEditModel().getResource(aUri);
  }
  
  public Object getAdapter(Class adapterType)
  {
    if (adapterType == ArtifactEditModel.class) {
      return getArtifactEditModel();
    }
    return Platform.getAdapterManager().getAdapter(this, adapterType);
  }
  
  public void commandStackChanged(EventObject event)
  {
    getArtifactEditModel().commandStackChanged(event);
  }
}

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

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualFile;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualReference;
import org.eclipse.wst.common.componentcore.internal.resources.VirtualResource;
import org.eclipse.wst.common.componentcore.internal.util.ComponentImplManager;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
import org.eclipse.wst.common.componentcore.resources.IVirtualResource;

public class ComponentCore
{
  private static final IVirtualResource[] NO_RESOURCES = new VirtualResource[0];
  
  public static IVirtualComponent createComponent(IProject aProject)
  {
    if ((aProject == null) || (!aProject.isAccessible())) {
      return null;
    }
    return ComponentImplManager.instance().createComponent(aProject);
  }
  
  public static IVirtualComponent createComponent(IProject aProject, boolean checkForComponentFile)
  {
    if ((aProject == null) || (!aProject.isAccessible())) {
      return null;
    }
    return ComponentImplManager.instance().createComponent(aProject, checkForComponentFile);
  }
  
  /**
   * @deprecated
   */
  public static IVirtualComponent createComponent(IProject aProject, String aName)
  {
    return createComponent(aProject);
  }
  
  public static IVirtualComponent createArchiveComponent(IProject aProject, String aComponentName)
  {
    return ComponentImplManager.instance().createArchiveComponent(aProject, aComponentName);
  }
  
  public static IVirtualComponent createArchiveComponent(IProject aProject, String aComponentName, IPath runtimePath)
  {
    return ComponentImplManager.instance().createArchiveComponent(aProject, aComponentName, runtimePath);
  }
  
  public static IVirtualFolder createFolder(IProject aProject, IPath aRuntimePath)
  {
    return ComponentImplManager.instance().createFolder(aProject, aRuntimePath);
  }
  
  public static IVirtualFile createFile(IProject aProject, IPath aRuntimePath)
  {
    return new VirtualFile(aProject, aRuntimePath);
  }
  
  public static IVirtualReference createReference(IVirtualComponent aComponent, IVirtualComponent aReferencedComponent)
  {
    return new VirtualReference(aComponent, aReferencedComponent);
  }
  
  public static IVirtualReference createReference(IVirtualComponent aComponent, IVirtualComponent aReferencedComponent, IPath runtimePath)
  {
    return new VirtualReference(aComponent, aReferencedComponent, runtimePath);
  }
  
  /* Error */
  public static IVirtualResource[] createResources(org.eclipse.core.resources.IResource aResource)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokeinterface 153 1 0
    //   6: astore_1
    //   7: aconst_null
    //   8: astore_2
    //   9: new 63	java/util/ArrayList
    //   12: dup
    //   13: invokespecial 131	java/util/ArrayList:<init>	()V
    //   16: astore_3
    //   17: aload_1
    //   18: invokestatic 137	org/eclipse/wst/common/componentcore/internal/StructureEdit:getStructureEditForRead	(Lorg/eclipse/core/resources/IProject;)Lorg/eclipse/wst/common/componentcore/internal/StructureEdit;
    //   21: astore_2
    //   22: aload_2
    //   23: ifnull +139 -> 162
    //   26: aload_2
    //   27: aload_0
    //   28: invokeinterface 154 1 0
    //   33: aload_0
    //   34: invokeinterface 152 1 0
    //   39: ifeq +7 -> 46
    //   42: iconst_0
    //   43: goto +4 -> 47
    //   46: iconst_2
    //   47: invokevirtual 136	org/eclipse/wst/common/componentcore/internal/StructureEdit:findResourcesBySourcePath	(Lorg/eclipse/core/runtime/IPath;I)[Lorg/eclipse/wst/common/componentcore/internal/ComponentResource;
    //   50: astore 4
    //   52: iconst_0
    //   53: istore 5
    //   55: goto +65 -> 120
    //   58: aload_0
    //   59: invokeinterface 151 1 0
    //   64: iconst_1
    //   65: if_icmpne +31 -> 96
    //   68: aload_3
    //   69: new 72	org/eclipse/wst/common/componentcore/internal/resources/VirtualFile
    //   72: dup
    //   73: aload_1
    //   74: aload 4
    //   76: iload 5
    //   78: aaload
    //   79: invokeinterface 155 1 0
    //   84: invokespecial 138	org/eclipse/wst/common/componentcore/internal/resources/VirtualFile:<init>	(Lorg/eclipse/core/resources/IProject;Lorg/eclipse/core/runtime/IPath;)V
    //   87: invokeinterface 148 2 0
    //   92: pop
    //   93: goto +24 -> 117
    //   96: aload_3
    //   97: aload_1
    //   98: aload 4
    //   100: iload 5
    //   102: aaload
    //   103: invokeinterface 155 1 0
    //   108: invokestatic 133	org/eclipse/wst/common/componentcore/ComponentCore:createFolder	(Lorg/eclipse/core/resources/IProject;Lorg/eclipse/core/runtime/IPath;)Lorg/eclipse/wst/common/componentcore/resources/IVirtualFolder;
    //   111: invokeinterface 148 2 0
    //   116: pop
    //   117: iinc 5 1
    //   120: iload 5
    //   122: aload 4
    //   124: arraylength
    //   125: if_icmplt -67 -> 58
    //   128: goto +34 -> 162
    //   131: astore 4
    //   133: aload 4
    //   135: invokestatic 134	org/eclipse/wst/common/componentcore/internal/ModulecorePlugin:logError	(Ljava/lang/Throwable;)V
    //   138: aload_2
    //   139: ifnull +31 -> 170
    //   142: aload_2
    //   143: invokevirtual 135	org/eclipse/wst/common/componentcore/internal/StructureEdit:dispose	()V
    //   146: goto +24 -> 170
    //   149: astore 6
    //   151: aload_2
    //   152: ifnull +7 -> 159
    //   155: aload_2
    //   156: invokevirtual 135	org/eclipse/wst/common/componentcore/internal/StructureEdit:dispose	()V
    //   159: aload 6
    //   161: athrow
    //   162: aload_2
    //   163: ifnull +7 -> 170
    //   166: aload_2
    //   167: invokevirtual 135	org/eclipse/wst/common/componentcore/internal/StructureEdit:dispose	()V
    //   170: aload_3
    //   171: invokeinterface 147 1 0
    //   176: ifle +22 -> 198
    //   179: aload_3
    //   180: aload_3
    //   181: invokeinterface 147 1 0
    //   186: anewarray 74	org/eclipse/wst/common/componentcore/internal/resources/VirtualResource
    //   189: invokeinterface 149 2 0
    //   194: checkcast 61	[Lorg/eclipse/wst/common/componentcore/resources/IVirtualResource;
    //   197: areturn
    //   198: getstatic 129	org/eclipse/wst/common/componentcore/ComponentCore:NO_RESOURCES	[Lorg/eclipse/wst/common/componentcore/resources/IVirtualResource;
    //   201: areturn
    // Line number table:
    //   Java source line #205	-> byte code offset #0
    //   Java source line #206	-> byte code offset #7
    //   Java source line #207	-> byte code offset #9
    //   Java source line #209	-> byte code offset #17
    //   Java source line #210	-> byte code offset #22
    //   Java source line #211	-> byte code offset #26
    //   Java source line #212	-> byte code offset #52
    //   Java source line #213	-> byte code offset #58
    //   Java source line #214	-> byte code offset #68
    //   Java source line #216	-> byte code offset #96
    //   Java source line #212	-> byte code offset #117
    //   Java source line #219	-> byte code offset #131
    //   Java source line #220	-> byte code offset #133
    //   Java source line #222	-> byte code offset #138
    //   Java source line #223	-> byte code offset #142
    //   Java source line #221	-> byte code offset #149
    //   Java source line #222	-> byte code offset #151
    //   Java source line #223	-> byte code offset #155
    //   Java source line #225	-> byte code offset #159
    //   Java source line #222	-> byte code offset #162
    //   Java source line #223	-> byte code offset #166
    //   Java source line #226	-> byte code offset #170
    //   Java source line #227	-> byte code offset #179
    //   Java source line #228	-> byte code offset #198
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	202	0	aResource	org.eclipse.core.resources.IResource
    //   6	92	1	proj	IProject
    //   8	159	2	se	org.eclipse.wst.common.componentcore.internal.StructureEdit
    //   16	165	3	foundResources	java.util.List
    //   50	73	4	resources	org.eclipse.wst.common.componentcore.internal.ComponentResource[]
    //   131	3	4	e	UnresolveableURIException
    //   53	68	5	i	int
    //   149	11	6	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   17	128	131	org/eclipse/wst/common/componentcore/UnresolveableURIException
    //   17	138	149	finally
  }
}

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

import org.eclipse.core.runtime.IProgressMonitor;

public abstract interface IEditModelHandler
{
  public abstract void save(IProgressMonitor paramIProgressMonitor);
  
  public abstract void saveIfNecessary(IProgressMonitor paramIProgressMonitor);
  
  public abstract void dispose();
}

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

import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
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.ProjectUtilities;
import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel;
import org.eclipse.wst.common.componentcore.internal.ModuleStructuralModel;
import org.eclipse.wst.common.componentcore.internal.ModulecorePlugin;
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
import org.eclipse.wst.common.componentcore.internal.impl.ComponentCoreURIConverter;
import org.eclipse.wst.common.componentcore.internal.impl.WTPResourceFactoryRegistry;
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.componentcore.internal.util.ModuleCoreMessages;
import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
import org.eclipse.wst.common.internal.emfworkbench.edit.EditModelRegistry;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelNature;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;

public class ModuleCoreNature
  extends EditModelNature
  implements IProjectNature, IModuleConstants, ISynchronizerExtender
{
  public static final String VALIDATION_BUILDER_ID = "org.eclipse.wst.validation.validationbuilder";
  private ModuleStructuralModel cachedWriteHandle;
  private ModuleStructuralModel cachedReadHandle;
  
  public static ModuleCoreNature getModuleCoreNature(IProject aProject)
  {
    try
    {
      if ((aProject != null) && (aProject.isAccessible())) {
        return (ModuleCoreNature)aProject.getNature("org.eclipse.wst.common.modulecore.ModuleCoreNature");
      }
    }
    catch (CoreException localCoreException) {}
    return null;
  }
  
  public static boolean isFlexibleProject(IProject project)
  {
    boolean foundNature = getModuleCoreNature(project) != null;
    if (foundNature) {
      return componentResourceExists(project);
    }
    return false;
  }
  
  public static boolean componentResourceExists(IProject project)
  {
    IFile compFile = project.getFile(StructureEdit.MODULE_META_FILE_NAME);
    if (compFile.isAccessible()) {
      return true;
    }
    compFile = project.getFile(".settings/.component");
    if (compFile.isAccessible()) {
      return true;
    }
    compFile = project.getFile(".component");
    if (compFile.isAccessible()) {
      return true;
    }
    compFile = project.getFile(".wtpmodules");
    return compFile.isAccessible();
  }
  
  /* Error */
  public static ModuleCoreNature addModuleCoreNatureIfNecessary(IProject aProject, org.eclipse.core.runtime.IProgressMonitor aMonitor)
  {
    // Byte code:
    //   0: aload_0
    //   1: ldc 6
    //   3: invokeinterface 401 2 0
    //   8: ifeq +8 -> 16
    //   11: aload_0
    //   12: invokestatic 367	org/eclipse/wst/common/componentcore/ModuleCoreNature:getModuleCoreNature	(Lorg/eclipse/core/resources/IProject;)Lorg/eclipse/wst/common/componentcore/ModuleCoreNature;
    //   15: areturn
    //   16: invokestatic 358	org/eclipse/core/runtime/Platform:getJobManager	()Lorg/eclipse/core/runtime/jobs/IJobManager;
    //   19: astore_2
    //   20: invokestatic 357	org/eclipse/core/resources/ResourcesPlugin:getWorkspace	()Lorg/eclipse/core/resources/IWorkspace;
    //   23: invokeinterface 409 1 0
    //   28: astore_3
    //   29: aload_1
    //   30: ifnull +12 -> 42
    //   33: aload_1
    //   34: ldc 4
    //   36: iconst_5
    //   37: invokeinterface 411 3 0
    //   42: aload_2
    //   43: aload_3
    //   44: aload_1
    //   45: invokeinterface 413 3 0
    //   50: aload_0
    //   51: invokeinterface 402 1 0
    //   56: astore 4
    //   58: aload 4
    //   60: invokeinterface 406 1 0
    //   65: astore 5
    //   67: aload 5
    //   69: arraylength
    //   70: iconst_1
    //   71: iadd
    //   72: anewarray 168	java/lang/String
    //   75: astore 6
    //   77: aload 5
    //   79: iconst_0
    //   80: aload 6
    //   82: iconst_0
    //   83: aload 5
    //   85: arraylength
    //   86: invokestatic 355	java/lang/System:arraycopy	(Ljava/lang/Object;ILjava/lang/Object;II)V
    //   89: aload 6
    //   91: aload 5
    //   93: arraylength
    //   94: ldc 6
    //   96: aastore
    //   97: aload 4
    //   99: aload 6
    //   101: invokeinterface 407 2 0
    //   106: aload_0
    //   107: aload 4
    //   109: aload_1
    //   110: invokeinterface 405 3 0
    //   115: goto +32 -> 147
    //   118: astore 4
    //   120: aload 4
    //   122: invokestatic 380	org/eclipse/wst/common/componentcore/internal/ModulecorePlugin:logError	(Lorg/eclipse/core/runtime/CoreException;)V
    //   125: aload_2
    //   126: aload_3
    //   127: invokeinterface 412 2 0
    //   132: goto +22 -> 154
    //   135: astore 7
    //   137: aload_2
    //   138: aload_3
    //   139: invokeinterface 412 2 0
    //   144: aload 7
    //   146: athrow
    //   147: aload_2
    //   148: aload_3
    //   149: invokeinterface 412 2 0
    //   154: aload_1
    //   155: ifnull +17 -> 172
    //   158: aload_1
    //   159: invokeinterface 410 1 0
    //   164: goto +8 -> 172
    //   167: astore_2
    //   168: aload_2
    //   169: invokestatic 380	org/eclipse/wst/common/componentcore/internal/ModulecorePlugin:logError	(Lorg/eclipse/core/runtime/CoreException;)V
    //   172: aload_0
    //   173: invokestatic 367	org/eclipse/wst/common/componentcore/ModuleCoreNature:getModuleCoreNature	(Lorg/eclipse/core/resources/IProject;)Lorg/eclipse/wst/common/componentcore/ModuleCoreNature;
    //   176: areturn
    // Line number table:
    //   Java source line #215	-> byte code offset #0
    //   Java source line #216	-> byte code offset #11
    //   Java source line #218	-> byte code offset #16
    //   Java source line #219	-> byte code offset #20
    //   Java source line #220	-> byte code offset #29
    //   Java source line #221	-> byte code offset #33
    //   Java source line #222	-> byte code offset #42
    //   Java source line #224	-> byte code offset #50
    //   Java source line #225	-> byte code offset #58
    //   Java source line #226	-> byte code offset #67
    //   Java source line #227	-> byte code offset #77
    //   Java source line #228	-> byte code offset #89
    //   Java source line #229	-> byte code offset #97
    //   Java source line #230	-> byte code offset #106
    //   Java source line #231	-> byte code offset #118
    //   Java source line #232	-> byte code offset #120
    //   Java source line #234	-> byte code offset #125
    //   Java source line #233	-> byte code offset #135
    //   Java source line #234	-> byte code offset #137
    //   Java source line #235	-> byte code offset #144
    //   Java source line #234	-> byte code offset #147
    //   Java source line #236	-> byte code offset #154
    //   Java source line #237	-> byte code offset #158
    //   Java source line #238	-> byte code offset #167
    //   Java source line #239	-> byte code offset #168
    //   Java source line #242	-> byte code offset #172
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	177	0	aProject	IProject
    //   0	177	1	aMonitor	org.eclipse.core.runtime.IProgressMonitor
    //   19	129	2	manager	org.eclipse.core.runtime.jobs.IJobManager
    //   167	2	2	e	CoreException
    //   28	121	3	root	org.eclipse.core.resources.IWorkspaceRoot
    //   56	52	4	description	org.eclipse.core.resources.IProjectDescription
    //   118	3	4	e	CoreException
    //   65	27	5	currentNatureIds	String[]
    //   75	25	6	newNatureIds	String[]
    //   135	10	7	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   50	115	118	org/eclipse/core/runtime/CoreException
    //   50	125	135	finally
    //   0	15	167	org/eclipse/core/runtime/CoreException
    //   16	164	167	org/eclipse/core/runtime/CoreException
  }
  
  public ModuleStructuralModel getModuleStructuralModelForRead(Object anAccessorKey)
  {
    ModuleStructuralModel editModel = (ModuleStructuralModel)getEmfContext().getExistingEditModel("org.eclipse.wst.modulecore.structuralModel", null, true);
    if (editModel == null)
    {
      editModel = (ModuleStructuralModel)EditModelRegistry.getInstance().createEditModelForRead("org.eclipse.wst.modulecore.structuralModel", getEmfContext(), null);
      getEmfContext().cacheEditModel(editModel, null);
      editModel.access(anAccessorKey);
    }
    else
    {
      editModel.access(anAccessorKey);
    }
    return editModel;
  }
  
  public ModuleStructuralModel getModuleStructuralModelForWrite(Object anAccessorKey)
  {
    ModuleStructuralModel editModel = (ModuleStructuralModel)getEmfContext().getExistingEditModel("org.eclipse.wst.modulecore.structuralModel", null, false);
    if (editModel == null)
    {
      editModel = (ModuleStructuralModel)EditModelRegistry.getInstance().createEditModelForWrite("org.eclipse.wst.modulecore.structuralModel", getEmfContext(), null);
      getEmfContext().cacheEditModel(editModel, null);
      editModel.access(anAccessorKey);
    }
    else
    {
      editModel.access(anAccessorKey);
    }
    return editModel;
  }
  
  public ArtifactEditModel getArtifactEditModelForRead(URI aModuleURI, Object anAccessorKey)
  {
    return getArtifactEditModelForRead(aModuleURI, anAccessorKey, null);
  }
  
  public ArtifactEditModel getArtifactEditModelForRead(URI aModuleURI, Object anAccessorKey, String projectType, Map params)
  {
    if (params == null) {
      params = new HashMap();
    }
    params.put("MODULE_URI", aModuleURI);
    if (projectType != null) {
      return (ArtifactEditModel)getEditModelForRead(projectType, anAccessorKey, params);
    }
    try
    {
      IProject aProject = StructureEdit.getContainingProject(aModuleURI);
      IFacetedProject facetedProject = ProjectFacetsManager.create(aProject);
      if (facetedProject != null)
      {
        String[] editModelIDs = EditModelRegistry.getInstance().getRegisteredEditModelIDs();
        for (int i = 0; i < editModelIDs.length; i++) {
          try
          {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(editModelIDs[i]);
            if ((facet != null) && (facetedProject.hasProjectFacet(facet)))
            {
              ArtifactEditModel editModel = (ArtifactEditModel)getEditModelForRead(editModelIDs[i], anAccessorKey, params);
              if (editModel != null) {
                return editModel;
              }
            }
          }
          catch (IllegalArgumentException localIllegalArgumentException) {}catch (Exception e)
          {
            ModulecorePlugin.logError(4, ModuleCoreMessages.Acquiring_ArtifactEdit_For_Read_Exception, e);
          }
        }
      }
    }
    catch (Exception e)
    {
      ModulecorePlugin.logError(4, ModuleCoreMessages.Acquiring_ArtifactEdit_For_Read_Exception, e);
    }
    return null;
  }
  
  public ArtifactEditModel getArtifactEditModelForRead(URI aModuleURI, Object anAccessorKey, String projectType)
  {
    Map params = new HashMap();
    return getArtifactEditModelForRead(aModuleURI, anAccessorKey, projectType, params);
  }
  
  public ArtifactEditModel getArtifactEditModelForWrite(URI aModuleURI, Object anAccessorKey)
  {
    return getArtifactEditModelForWrite(aModuleURI, anAccessorKey, null);
  }
  
  public ArtifactEditModel getArtifactEditModelForWrite(URI aModuleURI, Object anAccessorKey, String projectType, Map params)
  {
    if (params == null) {
      params = new HashMap();
    }
    params.put("MODULE_URI", aModuleURI);
    if (projectType != null) {
      return (ArtifactEditModel)getEditModelForWrite(projectType, anAccessorKey, params);
    }
    try
    {
      IProject aProject = StructureEdit.getContainingProject(aModuleURI);
      IFacetedProject facetedProject = ProjectFacetsManager.create(aProject);
      if (facetedProject != null)
      {
        String[] editModelIDs = EditModelRegistry.getInstance().getRegisteredEditModelIDs();
        for (int i = 0; i < editModelIDs.length; i++) {
          try
          {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(editModelIDs[i]);
            if ((facet != null) && (facetedProject.hasProjectFacet(facet)))
            {
              ArtifactEditModel editModel = (ArtifactEditModel)getEditModelForWrite(editModelIDs[i], anAccessorKey, params);
              if (editModel != null) {
                return editModel;
              }
            }
          }
          catch (IllegalArgumentException localIllegalArgumentException) {}catch (Exception e)
          {
            ModulecorePlugin.logError(4, ModuleCoreMessages.Acquiring_ArtifactEdit_For_Write_Exception, e);
          }
        }
      }
    }
    catch (Exception e)
    {
      ModulecorePlugin.logError(4, ModuleCoreMessages.Acquiring_ArtifactEdit_For_Write_Exception, e);
    }
    return null;
  }
  
  public ArtifactEditModel getArtifactEditModelForWrite(URI aModuleURI, Object anAccessorKey, String projectType)
  {
    Map params = new HashMap();
    return getArtifactEditModelForWrite(aModuleURI, anAccessorKey, projectType, params);
  }
  
  public String getNatureID()
  {
    return "org.eclipse.wst.common.modulecore.ModuleCoreNature";
  }
  
  public void primaryContributeToContext(EMFWorkbenchContextBase aNature)
  {
    if (emfContext == aNature) {
      return;
    }
    emfContext = aNature;
    getEmfContext().setDefaultToMOF5Compatibility(true);
    
    ProjectResourceSet projectResourceSet = aNature.getResourceSet();
    projectResourceSet.setResourceFactoryRegistry(WTPResourceFactoryRegistry.INSTANCE);
    projectResourceSet.setURIConverter(createURIConverter(getProject(), projectResourceSet));
    if (projectResourceSet.getSynchronizer() != null) {
      projectResourceSet.getSynchronizer().addExtender(this);
    }
    cacheModuleStructuralModels();
  }
  
  protected void primConfigure()
    throws CoreException
  {
    super.primConfigure();
    
    ProjectUtilities.addToBuildSpec("org.eclipse.wst.validation.validationbuilder", project);
  }
  
  private URIConverter createURIConverter(IProject aProject, ProjectResourceSet aResourceSet)
  {
    ComponentCoreURIConverter uriConverter = new ComponentCoreURIConverter(aProject, aResourceSet.getSynchronizer());
    uriConverter.addInputContainer(getProject());
    return uriConverter;
  }
  
  public ResourceSet getResourceSet()
  {
    return getEmfContextBase().getResourceSet();
  }
  
  public void secondar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

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