| /******************************************************************************* |
| * Copyright (c) 2006, 2007 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.core.internal.content.orm.resource; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.emf.common.util.URI; |
| import org.eclipse.emf.ecore.resource.URIConverter; |
| import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase; |
| import org.eclipse.jem.util.plugin.JEMUtilPlugin; |
| import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; |
| import org.eclipse.jpt.core.internal.content.orm.OrmResource; |
| import org.eclipse.wst.common.internal.emf.resource.Renderer; |
| import org.eclipse.wst.common.internal.emf.resource.Translator; |
| import org.eclipse.wst.common.internal.emf.resource.TranslatorResource; |
| import org.eclipse.wst.common.internal.emf.resource.TranslatorResourceImpl; |
| |
| public class OrmResourceImpl extends TranslatorResourceImpl |
| implements OrmResource |
| { |
| private Translator rootTranslator; |
| |
| public OrmResourceImpl(Renderer aRenderer) { |
| super(aRenderer); |
| } |
| |
| public OrmResourceImpl(URI uri, Renderer aRenderer) { |
| super(uri, aRenderer); |
| } |
| |
| /** |
| * @see TranslatorResourceImpl#getDefaultPublicId() |
| */ |
| protected String getDefaultPublicId() { |
| return null; |
| // only applicable for DTD-based files |
| } |
| |
| /** |
| * @see TranslatorResourceImpl#getDefaultSystemId() |
| */ |
| protected String getDefaultSystemId() { |
| return null; |
| // only applicable for DTD-based files |
| } |
| |
| /** |
| * @see TranslatorResourceImpl#getDefaultVersionId() |
| */ |
| protected int getDefaultVersionID() { |
| return 10; |
| // this seems to be the default version of the spec for this doc |
| // and the id 10 maps to the version 1.0 |
| } |
| |
| /** |
| * @see TranslatorResource#getDoctype() |
| */ |
| public String getDoctype() { |
| return null; |
| // only applicable for DTD-based files |
| } |
| |
| /** |
| * @see TranslatorResource#getRootTranslator() |
| */ |
| public Translator getRootTranslator() { |
| if (this.rootTranslator == null) { |
| this.rootTranslator = buildRootTranslator(); |
| } |
| return this.rootTranslator; |
| } |
| |
| protected Translator buildRootTranslator() { |
| return new EntityMappingsTranslator(); |
| } |
| |
| /** |
| * @see OrmResource#getEntityMappings() |
| */ |
| public EntityMappingsInternal getEntityMappings() { |
| return (EntityMappingsInternal) getRootObject(); |
| } |
| |
| public IFile getFile() { |
| IFile file = null; |
| file = getFile(getURI()); |
| if (file == null) { |
| if (getResourceSet() != null) { |
| URIConverter converter = getResourceSet().getURIConverter(); |
| URI convertedUri = converter.normalize(getURI()); |
| if (! getURI().equals(convertedUri)) { |
| file = getFile(convertedUri); |
| } |
| } |
| } |
| return file; |
| } |
| |
| /** |
| * Return the IFile for the <code>uri</code> within the Workspace. This URI is assumed to be |
| * absolute in the following format: platform:/resource/.... |
| */ |
| private IFile getFile(URI uri) { |
| if (WorkbenchResourceHelperBase.isPlatformResourceURI(uri)) { |
| String fileString = URI.decode(uri.path()); |
| fileString = fileString.substring(JEMUtilPlugin.PLATFORM_RESOURCE.length() + 1); |
| return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileString)); |
| } |
| return null; |
| } |
| } |