| /******************************************************************************* |
| * Copyright (c) 2008, 2009 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.internal.resource.orm; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.jpt.core.JptCorePlugin; |
| import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; |
| import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; |
| import org.eclipse.jpt.core.resource.orm.AccessType; |
| import org.eclipse.jpt.core.resource.orm.OrmFactory; |
| import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults; |
| import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; |
| import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; |
| import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; |
| import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings; |
| import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
| |
| public class EclipseLinkOrmXmlResourceProvider |
| extends AbstractXmlResourceProvider |
| implements OrmFileCreationDataModelProperties |
| { |
| /** |
| * (Convenience method) Returns an EclipseLink ORM resource model provider for |
| * the given file. |
| */ |
| public static EclipseLinkOrmXmlResourceProvider getXmlResourceProvider(IFile file) { |
| return getXmlResourceProvider_(file.getProject(), file.getFullPath().toString()); |
| } |
| |
| /** |
| * (Convenience method) Returns an EclipseLink ORM resource model provider for |
| * the given project in the specified deploy location |
| */ |
| public static EclipseLinkOrmXmlResourceProvider getXmlResourceProvider(IProject project, String deployLocation) { |
| return getXmlResourceProvider_(project, JptCorePlugin.getDeploymentURI(project, deployLocation)); |
| |
| } |
| |
| /** |
| * (Convenience method) Returns an EclipseLink ORM resource model provider for |
| * the given project in the default deploy location |
| */ |
| public static EclipseLinkOrmXmlResourceProvider getDefaultXmlResourceProvider(IProject project) { |
| return getXmlResourceProvider(project, JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH); |
| } |
| |
| private static EclipseLinkOrmXmlResourceProvider getXmlResourceProvider_(IProject project, String location) { |
| return new EclipseLinkOrmXmlResourceProvider(project, new Path(location)); |
| } |
| |
| |
| public EclipseLinkOrmXmlResourceProvider(IProject project) { |
| this(project, new Path(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH)); |
| } |
| |
| public EclipseLinkOrmXmlResourceProvider(IProject project, IPath filePath) { |
| super(project, filePath, JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE); |
| } |
| |
| |
| @Override |
| protected void populateRoot(Object config) { |
| IDataModel dataModel = (IDataModel) config; |
| XmlEntityMappings entityMappings = EclipseLinkOrmFactory.eINSTANCE.createXmlEntityMappings(); |
| entityMappings.setVersion(dataModel.getStringProperty(VERSION)); |
| getResourceContents().add(entityMappings); |
| |
| AccessType defaultAccess = (AccessType) dataModel.getProperty(DEFAULT_ACCESS); |
| if (defaultAccess != null) { |
| XmlPersistenceUnitMetadata puMetadata = EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); |
| entityMappings.setPersistenceUnitMetadata(puMetadata); |
| XmlPersistenceUnitDefaults puDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); |
| puMetadata.setPersistenceUnitDefaults(puDefaults); |
| puDefaults.setAccess(defaultAccess); |
| } |
| } |
| } |