| /******************************************************************************* |
| * Copyright (c) 2008 Oracle. |
| * All rights reserved. This program and the accompanying materials are |
| * made available under the terms of the Eclipse Public License v1.0 which |
| * accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jpt.eclipselink.core.resource.elorm; |
| |
| import java.io.IOException; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.emf.common.util.URI; |
| import org.eclipse.jpt.core.resource.common.JpaArtifactEdit; |
| import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; |
| |
| /** |
| * Provisional API: This interface is part of an interim API that is still |
| * under development and expected to change significantly before reaching |
| * stability. It is available at this early stage to solicit feedback from |
| * pioneering adopters on the understanding that any code that uses this API |
| * will almost certainly be broken (repeatedly) as the API evolves. |
| */ |
| public class EclipseLinkOrmArtifactEdit extends JpaArtifactEdit |
| { |
| /** |
| * @param aProject |
| * @return an eclipselink orm artifact for the project aProject. |
| * Opened only for read access (no write) |
| */ |
| public static EclipseLinkOrmArtifactEdit getArtifactEditForRead(IProject aProject) { |
| EclipseLinkOrmArtifactEdit artifactEdit = null; |
| try { |
| artifactEdit = new EclipseLinkOrmArtifactEdit(aProject, true); |
| } |
| catch (IllegalArgumentException iae) { |
| // suppress illegal argument exception |
| JptEclipseLinkCorePlugin.log(iae); |
| } |
| return artifactEdit; |
| } |
| |
| /** |
| * @param aProject |
| * @return an eclipselink orm artifact for the project aProject. |
| * Opened for both write and read access |
| */ |
| public static EclipseLinkOrmArtifactEdit getArtifactEditForWrite(IProject aProject) { |
| EclipseLinkOrmArtifactEdit artifactEdit = null; |
| try { |
| artifactEdit = new EclipseLinkOrmArtifactEdit(aProject, false); |
| } |
| catch (IllegalArgumentException iae) { |
| // suppress illegal argument exception |
| JptEclipseLinkCorePlugin.log(iae); |
| } |
| return artifactEdit; |
| } |
| |
| |
| public EclipseLinkOrmArtifactEdit(IProject aProject, boolean toAccessAsReadOnly) |
| throws IllegalArgumentException { |
| super(aProject, toAccessAsReadOnly); |
| } |
| |
| |
| @Override |
| public EclipseLinkOrmResource getResource(IFile file) { |
| // This *seems* to do the same basic thing as below, but circumvents the |
| // URI munging that ArtifactEditModel does (see bug 209093) |
| try { |
| EclipseLinkOrmResource resource = |
| (EclipseLinkOrmResource) getArtifactEditModel().createResource(URI.createPlatformResourceURI(file.getFullPath().toString())); |
| if (! resource.isLoaded()) { |
| resource.load(getArtifactEditModel().getResourceSet().getLoadOptions()); |
| } |
| return resource; |
| } |
| catch (ClassCastException cce) { |
| return null; |
| } |
| catch (IOException ioe) { |
| JptEclipseLinkCorePlugin.log(ioe); |
| return null; |
| } |
| } |
| |
| @Override |
| public EclipseLinkOrmResource getResource(String fileURI) { |
| try { |
| return (EclipseLinkOrmResource) getArtifactEditModel().getResource(URI.createURI(fileURI)); |
| } |
| catch (ClassCastException cce) { |
| return null; |
| } |
| } |
| } |