diff options
author | kmoore | 2011-01-28 19:12:19 +0000 |
---|---|---|
committer | kmoore | 2011-01-28 19:12:19 +0000 |
commit | 3f1ffe0866fc4e9412534ddae8f1aa4848108ae6 (patch) | |
tree | 9adb2995e4cd4eab26db30a459c5c0ce73869002 /jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal | |
parent | a4de708adbb4de31294b9b209bef723de6bf2bad (diff) | |
download | webtools.dali-3f1ffe0866fc4e9412534ddae8f1aa4848108ae6.tar.gz webtools.dali-3f1ffe0866fc4e9412534ddae8f1aa4848108ae6.tar.xz webtools.dali-3f1ffe0866fc4e9412534ddae8f1aa4848108ae6.zip |
refactor the JAXB SchemaFileCreationDataModelProvider so that it is not extending anything related to JPA. In preparation for creating the common plug-in
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal')
7 files changed, 192 insertions, 113 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java index 84253fe8ab..61abb8e733 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Oracle. All rights reserved. + * Copyright (c) 2006, 2011 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. @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.facet; -import static org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties.CONTAINER_PATH; +import static org.eclipse.jpt.core.internal.operations.JptFileCreationDataModelProperties.CONTAINER_PATH; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java index d487ee85bc..7134dc1c2b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -13,23 +13,18 @@ import java.util.Set; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jpt.core.JpaFacet; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.internal.JptCoreMessages; -import org.eclipse.jpt.core.internal.utility.PlatformTools; import org.eclipse.jpt.core.resource.ResourceLocator; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; import org.eclipse.wst.common.project.facet.core.IFacetedProject; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; public abstract class AbstractJpaFileCreationDataModelProvider - extends AbstractDataModelProvider + extends AbstractJptFileCreationDataModelProvider implements JpaFileCreationDataModelProperties { protected AbstractJpaFileCreationDataModelProvider() { @@ -39,34 +34,19 @@ public abstract class AbstractJpaFileCreationDataModelProvider @Override public Set<String> getPropertyNames() { - @SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames(); - propertyNames.add(PROJECT); - propertyNames.add(CONTAINER_PATH); - propertyNames.add(FILE_NAME); propertyNames.add(VERSION); return propertyNames; } @Override public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(CONTAINER_PATH)) { - IContainer sourceLocation = getDefaultContainer(); - if (sourceLocation != null && sourceLocation.exists()) { - return sourceLocation.getFullPath(); - } - } - else if (propertyName.equals(FILE_NAME)) { - return getDefaultFileName(); - } - else if (propertyName.equals(VERSION)) { + if (propertyName.equals(VERSION)) { return getDefaultVersion(); } return super.getDefaultProperty(propertyName); } - protected abstract String getDefaultFileName(); - protected abstract String getDefaultVersion(); @@ -74,15 +54,10 @@ public abstract class AbstractJpaFileCreationDataModelProvider @Override public IStatus validate(String propertyName) { - IStatus status = Status.OK_STATUS; - if (propertyName.equals(CONTAINER_PATH) - || propertyName.equals(FILE_NAME)) { - status = validateContainerPathAndFileName(); - } + IStatus status = super.validate(propertyName); if (! status.isOK()) { return status; } - if (propertyName.equals(CONTAINER_PATH) || propertyName.equals(VERSION)) { status = validateVersion(); @@ -94,15 +69,13 @@ public abstract class AbstractJpaFileCreationDataModelProvider return status; } + @Override protected IStatus validateContainerPathAndFileName() { - IContainer container = getContainer(); - if (container == null) { - // verifies container has been specified, but should be unnecessary in most cases. - // there is almost always a default, and the new file wizard does this validation as well. - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_CONTAINER_NOT_SPECIFIED); + IStatus status = super.validateContainerPathAndFileName(); + if (! status.isOK()) { + return status; } + IContainer container = getContainer(); IProject project = getProject(container); if (! JpaFacet.isInstalled(project)) { // verifies project has jpa facet @@ -123,21 +96,6 @@ public abstract class AbstractJpaFileCreationDataModelProvider IStatus.WARNING, JptCorePlugin.PLUGIN_ID, JptCoreMessages.VALIDATE_CONTAINER_QUESTIONABLE); } - String fileName = getStringProperty(FILE_NAME); - if (StringTools.stringIsEmpty(fileName)) { - // verifies file name has been specified, but should be unnecessary in most cases. - // there is almost always a default, and the new file wizard does this validation as well. - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_FILE_NAME_NOT_SPECIFIED); - } - if (container.getFile(new Path(fileName)).exists()) { - // verifies file does not exist, but should be unnecessary in most cases. - // the new file wizard does this validation as well. - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_FILE_ALREADY_EXISTS); - } return Status.OK_STATUS; } @@ -173,26 +131,6 @@ public abstract class AbstractJpaFileCreationDataModelProvider // **************** helper methods ***************************************** - protected IPath getContainerPath() { - return (IPath) this.model.getProperty(CONTAINER_PATH); - } - - protected IContainer getContainer() { - IPath containerPath = getContainerPath(); - if (containerPath == null) { - return null; - } - return PlatformTools.getContainer(containerPath); - } - - protected IProject getProject() { - return getProject(getContainer()); - } - - protected IProject getProject(IContainer container) { - return (container == null) ? null : container.getProject(); - } - protected JpaProject getJpaProject() { return getJpaProject(getProject()); } @@ -201,17 +139,6 @@ public abstract class AbstractJpaFileCreationDataModelProvider return (project == null) ? null : JptCorePlugin.getJpaProject(project); } - /** - * Return a best guess source location for the for the specified project - */ - protected IContainer getDefaultContainer() { - IProject project = (IProject) this.model.getProperty(PROJECT); - if (project != null) { - return JptCorePlugin.getResourceLocator(project).getDefaultResourceLocation(project); - } - return null; - } - protected String getJpaFacetVersion(IProject project) throws CoreException { IFacetedProject fproj = ProjectFacetsManager.create(project); return fproj.getProjectFacetVersion(JpaFacet.FACET).getVersionString(); @@ -222,7 +149,7 @@ public abstract class AbstractJpaFileCreationDataModelProvider return (jpaProject != null) && isSupportedPlatformId(jpaProject.getJpaPlatform().getId()); } - protected boolean isSupportedPlatformId(String id) { + protected boolean isSupportedPlatformId(@SuppressWarnings("unused") String id) { return true; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java index c1b526e43c..ca612ee1b2 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -10,7 +10,7 @@ package org.eclipse.jpt.core.internal.operations; -import static org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties.*; +import static org.eclipse.jpt.core.internal.operations.JptFileCreationDataModelProperties.*; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJptFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJptFileCreationDataModelProvider.java new file mode 100644 index 0000000000..28261d10b8 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJptFileCreationDataModelProvider.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.operations; + +import java.util.Set; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.internal.JptCoreMessages; +import org.eclipse.jpt.core.internal.utility.PlatformTools; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; + +public abstract class AbstractJptFileCreationDataModelProvider + extends AbstractDataModelProvider + implements JptFileCreationDataModelProperties +{ + protected AbstractJptFileCreationDataModelProvider() { + super(); + } + + + @Override + public Set<String> getPropertyNames() { + @SuppressWarnings("unchecked") + Set<String> propertyNames = super.getPropertyNames(); + propertyNames.add(PROJECT); + propertyNames.add(CONTAINER_PATH); + propertyNames.add(FILE_NAME); + return propertyNames; + } + + @Override + public Object getDefaultProperty(String propertyName) { + if (propertyName.equals(CONTAINER_PATH)) { + IContainer sourceLocation = getDefaultContainer(); + if (sourceLocation != null && sourceLocation.exists()) { + return sourceLocation.getFullPath(); + } + } + else if (propertyName.equals(FILE_NAME)) { + return getDefaultFileName(); + } + return super.getDefaultProperty(propertyName); + } + + protected abstract String getDefaultFileName(); + + + // **************** validation ********************************************* + + @Override + public IStatus validate(String propertyName) { + IStatus status = Status.OK_STATUS; + if (propertyName.equals(CONTAINER_PATH) + || propertyName.equals(FILE_NAME)) { + status = validateContainerPathAndFileName(); + } + if (! status.isOK()) { + return status; + } + + return status; + } + + protected IStatus validateContainerPathAndFileName() { + IContainer container = getContainer(); + if (container == null) { + // verifies container has been specified, but should be unnecessary in most cases. + // there is almost always a default, and the new file wizard does this validation as well. + return new Status( + IStatus.ERROR, JptCorePlugin.PLUGIN_ID, + JptCoreMessages.VALIDATE_CONTAINER_NOT_SPECIFIED); + } + String fileName = getStringProperty(FILE_NAME); + if (StringTools.stringIsEmpty(fileName)) { + // verifies file name has been specified, but should be unnecessary in most cases. + // there is almost always a default, and the new file wizard does this validation as well. + return new Status( + IStatus.ERROR, JptCorePlugin.PLUGIN_ID, + JptCoreMessages.VALIDATE_FILE_NAME_NOT_SPECIFIED); + } + if (container.getFile(new Path(fileName)).exists()) { + // verifies file does not exist, but should be unnecessary in most cases. + // the new file wizard does this validation as well. + return new Status( + IStatus.ERROR, JptCorePlugin.PLUGIN_ID, + JptCoreMessages.VALIDATE_FILE_ALREADY_EXISTS); + } + return Status.OK_STATUS; + } + + + // **************** helper methods ***************************************** + + protected IPath getContainerPath() { + return (IPath) this.model.getProperty(CONTAINER_PATH); + } + + protected IContainer getContainer() { + IPath containerPath = getContainerPath(); + if (containerPath == null) { + return null; + } + return PlatformTools.getContainer(containerPath); + } + + protected IProject getProject() { + return getProject(getContainer()); + } + + protected IProject getProject(IContainer container) { + return (container == null) ? null : container.getProject(); + } + + /** + * Return a best guess source location for the for the specified project + */ + protected IContainer getDefaultContainer() { + IProject project = (IProject) this.model.getProperty(PROJECT); + if (project != null) { + return JptCorePlugin.getResourceLocator(project).getDefaultResourceLocation(project); + } + return null; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JpaFileCreationDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JpaFileCreationDataModelProperties.java index 21fc45432f..8e15e06ec3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JpaFileCreationDataModelProperties.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JpaFileCreationDataModelProperties.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. + * Copyright (c) 2009, 2011 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 @@ -10,29 +10,11 @@ *******************************************************************************/ package org.eclipse.jpt.core.internal.operations; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; - -public interface JpaFileCreationDataModelProperties +public interface JpaFileCreationDataModelProperties extends JptFileCreationDataModelProperties { - /** - * Optional, type {@link IProject}, gives a clue as to the default container path - */ - public static final String PROJECT = "JpaFileCreationDataModelProperties.PROJECT"; - - /** - * Required, type {@link IPath}, identifies the full path to the container in which - * the file should be created - */ - public static final String CONTAINER_PATH = "JpaFileCreationDataModelProperties.CONTAINER_PATH"; - - /** - * Required, type {@link String}, identifies the file name - */ - public static final String FILE_NAME = "JpaFileCreationDataModelProperties.FILE_NAME"; - + /** * Required, type {@link String}, identifies the version of the file to create */ - public static final String VERSION = "JpaFileCreationDataModelProperties.VERSION"; + String VERSION = "JpaFileCreationDataModelProperties.VERSION"; //$NON-NLS-1$ } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JptFileCreationDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JptFileCreationDataModelProperties.java new file mode 100644 index 0000000000..cbfadb712f --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/JptFileCreationDataModelProperties.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 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.operations; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; + +public interface JptFileCreationDataModelProperties +{ + /** + * Optional, type {@link IProject}, gives a clue as to the default container path + */ + String PROJECT = "JptFileCreationDataModelProperties.PROJECT"; //$NON-NLS-1$ + + /** + * Required, type {@link IPath}, identifies the full path to the container in which + * the file should be created + */ + String CONTAINER_PATH = "JptFileCreationDataModelProperties.CONTAINER_PATH"; //$NON-NLS-1$ + + /** + * Required, type {@link String}, identifies the file name + */ + String FILE_NAME = "JptFileCreationDataModelProperties.FILE_NAME"; //$NON-NLS-1$ +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java index 75e2083b37..4db67ed303 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. + * Copyright (c) 2008, 2011 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 @@ -16,17 +16,17 @@ public interface OrmFileCreationDataModelProperties /** * Optional, type AccessType, specifies the default access type (or null) */ - public static final String DEFAULT_ACCESS = "OrmFileCreationDataModelProperties.DEFAULT_ACCESS"; + String DEFAULT_ACCESS = "OrmFileCreationDataModelProperties.DEFAULT_ACCESS"; //$NON-NLS-1$ /** * Required, type Boolean, specifies whether to add a reference to the file * in the persistence unit */ - public static final String ADD_TO_PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT"; + String ADD_TO_PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT"; //$NON-NLS-1$ /** * Optional (unless ADD_TO_PERSISTENCE_UNIT property is true), type String, * identifies the persistence unit to which to add a reference to the file */ - public static final String PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.PERSISTENCE_UNIT"; + String PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.PERSISTENCE_UNIT"; //$NON-NLS-1$ } |