diff options
author | pfullbright | 2011-04-11 22:49:23 +0000 |
---|---|---|
committer | pfullbright | 2011-04-11 22:49:23 +0000 |
commit | 771f7c6a93a04e4e2f6c05ec5cf0f8c86735e3fd (patch) | |
tree | 834593051497d79a41f7e9b4650f3bf29fcbcd4e /jaxb/plugins | |
parent | 8466793321e0d433426c5ac35921f210c4858b7a (diff) | |
download | webtools.dali-771f7c6a93a04e4e2f6c05ec5cf0f8c86735e3fd.tar.gz webtools.dali-771f7c6a93a04e4e2f6c05ec5cf0f8c86735e3fd.tar.xz webtools.dali-771f7c6a93a04e4e2f6c05ec5cf0f8c86735e3fd.zip |
added general support for eclipselink jaxb validation/ specific support for jaxb.properties validation
Diffstat (limited to 'jaxb/plugins')
11 files changed, 241 insertions, 10 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/.classpath b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/.classpath index 4ac7ebdea3..0232fe5ec9 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/.classpath +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/.classpath @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="property_files"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> <accessrules> diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF index 821cb8ba2e..3f964bf63b 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF @@ -9,16 +9,20 @@ Bundle-ActivationPolicy: lazy Bundle-ClassPath: . Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)", +Require-Bundle: org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)", + org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)", org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)", org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)", org.eclipse.jpt.common.eclipselink.core;bundle-version="[1.0.0,2.0.0)", org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)", org.eclipse.jpt.jaxb.core;bundle-version="[1.0.0,2.0.0)", org.eclipse.jst.common.project.facet.core;bundle-version="[1.4.200,2.0.0)", - org.eclipse.jst.j2ee;bundle-version="[1.1.500,2.0.0)" + org.eclipse.jst.j2ee;bundle-version="[1.1.500,2.0.0)", + org.eclipse.wst.validation;bundle-version="[1.2.300,2.0.0)" Export-Package: org.eclipse.jpt.jaxb.eclipselink.core, + org.eclipse.jpt.jaxb.eclipselink.core.internal.context, org.eclipse.jpt.jaxb.eclipselink.core.internal.libval;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_2;x-internal:=true, - org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_3;x-internal:=true + org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_3;x-internal:=true, + org.eclipse.jpt.jaxb.eclipselink.core.internal.validation diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/build.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/build.properties index f0dca02368..b7fe1216e1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/build.properties +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/build.properties @@ -7,7 +7,8 @@ # Contributors: # Oracle - initial API and implementation ################################################################################ -source.. = src/ +source.. = src/,\ + property_files/ output.. = bin/ bin.includes = .,\ META-INF/,\ diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties new file mode 100644 index 0000000000..cd71550835 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties @@ -0,0 +1,11 @@ +############################################################################### +# Copyright (c) 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 +############################################################################### + +PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY = Project is missing a jaxb.properties file specifying the EclipseLink JAXB context factory
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java new file mode 100644 index 0000000000..b162386a60 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 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.jaxb.eclipselink.core.internal.context; + +import java.util.List; +import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.jaxb.core.JaxbProject; +import org.eclipse.jpt.jaxb.core.context.JaxbPackage; +import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextRoot; +import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessageBuilder; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessages; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + + +public class ELJaxbContextRoot + extends AbstractJaxbContextRoot { + + + public ELJaxbContextRoot(JaxbProject jaxbProject) { + super(jaxbProject); + } + + + // **************** validation ******************************************** + + @Override + public void validate(List<IMessage> messages, IReporter reporter) { + super.validate(messages, reporter); + + validateJaxbProperties(messages, reporter); + } + + protected void validateJaxbProperties(List<IMessage> messages, IReporter reporter) { + String factoryProp = "javax.xml.bind.context.factory"; + String factoryPropValue = "org.eclipse.persistence.jaxb.JAXBContextFactory"; + + for (JaxbPackage jp : getPackages()) { + String pn = jp.getName(); + JaxbPropertiesResource jpr = getJaxbProject().getJaxbPropertiesResource(pn); + if (jpr != null && StringTools.stringsAreEqual(jpr.getProperty(factoryProp), factoryPropValue)) { + return; + } + } + + messages.add( + ELJaxbValidationMessageBuilder.buildMessage( + IMessage.HIGH_SEVERITY, + ELJaxbValidationMessages.PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY, + getJaxbProject())); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java new file mode 100644 index 0000000000..ec3de10173 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 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.jaxb.eclipselink.core.internal.v2_1; + +import org.eclipse.jpt.jaxb.core.JaxbFactory; +import org.eclipse.jpt.jaxb.core.JaxbProject; +import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; +import org.eclipse.jpt.jaxb.core.internal.AbstractJaxbFactory; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.ELJaxbContextRoot; + + +public class ELJaxb_2_1_Factory + extends AbstractJaxbFactory { + + // singleton + private static final JaxbFactory INSTANCE = new ELJaxb_2_1_Factory(); + + + /** + * Return the singleton. + */ + public static JaxbFactory instance() { + return INSTANCE; + } + + + /** + * Ensure single instance. + */ + private ELJaxb_2_1_Factory() { + super(); + } + + + @Override + public JaxbContextRoot buildContextRoot(JaxbProject parent) { + return new ELJaxbContextRoot(parent); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java index 622eb210a4..ebdf91bfd0 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1; import org.eclipse.jpt.jaxb.core.JaxbFactory; import org.eclipse.jpt.jaxb.core.internal.jaxb21.AbstractJaxb_2_1_PlatformDefinition; -import org.eclipse.jpt.jaxb.core.internal.jaxb21.GenericJaxb_2_1_Factory; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDefinition; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbPlatform; @@ -41,6 +40,6 @@ public class ELJaxb_2_1_PlatformDefinition } public JaxbFactory getFactory() { - return GenericJaxb_2_1_Factory.instance(); + return ELJaxb_2_1_Factory.instance(); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_2/ELJaxb_2_2_PlatformDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_2/ELJaxb_2_2_PlatformDefinition.java index 5ef9ca3d56..557a8a9060 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_2/ELJaxb_2_2_PlatformDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_2/ELJaxb_2_2_PlatformDefinition.java @@ -10,11 +10,11 @@ package org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_2; import org.eclipse.jpt.jaxb.core.JaxbFactory; -import org.eclipse.jpt.jaxb.core.internal.jaxb21.GenericJaxb_2_1_Factory; import org.eclipse.jpt.jaxb.core.internal.jaxb22.AbstractJaxb_2_2_PlatformDefinition; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDefinition; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbPlatform; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1.ELJaxb_2_1_Factory; public class ELJaxb_2_2_PlatformDefinition @@ -41,6 +41,6 @@ public class ELJaxb_2_2_PlatformDefinition } public JaxbFactory getFactory() { - return GenericJaxb_2_1_Factory.instance(); + return ELJaxb_2_1_Factory.instance(); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_3/ELJaxb_2_3_PlatformDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_3/ELJaxb_2_3_PlatformDefinition.java index e71928d539..9b24d0847f 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_3/ELJaxb_2_3_PlatformDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_3/ELJaxb_2_3_PlatformDefinition.java @@ -10,11 +10,11 @@ package org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_3; import org.eclipse.jpt.jaxb.core.JaxbFactory; -import org.eclipse.jpt.jaxb.core.internal.jaxb21.GenericJaxb_2_1_Factory; import org.eclipse.jpt.jaxb.core.internal.jaxb22.AbstractJaxb_2_2_PlatformDefinition; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDefinition; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbPlatform; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1.ELJaxb_2_1_Factory; public class ELJaxb_2_3_PlatformDefinition @@ -41,6 +41,6 @@ public class ELJaxb_2_3_PlatformDefinition } public JaxbFactory getFactory() { - return GenericJaxb_2_1_Factory.instance(); + return ELJaxb_2_1_Factory.instance(); } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessageBuilder.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessageBuilder.java new file mode 100644 index 0000000000..839c0fb38b --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessageBuilder.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 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.jaxb.eclipselink.core.internal.validation; + +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; +import org.eclipse.jpt.jaxb.eclipselink.core.JptJaxbEclipseLinkCorePlugin; +import org.eclipse.wst.validation.internal.core.Message; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; + +public class ELJaxbValidationMessageBuilder { + + private static String[] DEFAULT_PARMS = new String[0]; + private static TextRange DEFAULT_TEXT_RANGE = TextRange.Empty.instance(); + + public static IMessage buildMessage( + int severity, String messageId, Object targetObject) { + return buildMessage(severity, messageId, DEFAULT_PARMS, targetObject); + } + + public static IMessage buildMessage( + int severity, String messageId, String[] parms, Object targetObject) { + return buildMessage(severity, messageId, parms, targetObject, DEFAULT_TEXT_RANGE); + } + + public static IMessage buildMessage( + int severity, String messageId, Object targetObject, TextRange textRange) { + return buildMessage(severity, messageId, DEFAULT_PARMS, targetObject, textRange); + } + + public static IMessage buildMessage( + int severity, String messageId, String[] parms, Object targetObject, TextRange textRange) { + IMessage message = new ELJaxbValidationMessage(ELJaxbValidationMessages.BUNDLE_NAME, severity, messageId, parms, targetObject); + message.setMarkerId(JptJaxbCorePlugin.VALIDATION_MARKER_ID); //TODO do we need an 'EclipseLink' problem marker? + if (textRange == null) { + //log an exception and then continue without setting location information + //At least the user will still get the validation message and will + //be able to see other validation messages with valid textRanges + JptJaxbEclipseLinkCorePlugin.log(new IllegalArgumentException("Null text range for message ID: " + messageId)); //$NON-NLS-1$ + } + else { + message.setLineNo(textRange.getLineNumber()); + message.setOffset(textRange.getOffset()); + message.setLength(textRange.getLength()); + } + return message; + } + + + private ELJaxbValidationMessageBuilder() { + super(); + throw new UnsupportedOperationException(); + } + + /** + * Used so that we can find the resource bundle using this classLoader. + * Otherwise the wst validation message attempts to use the ClassLoader + * of the generic jaxb validator which is in the org.eclipse.jpt.jaxb.core plugin. + */ + private static class ELJaxbValidationMessage + extends Message { + + public ELJaxbValidationMessage(String aBundleName, int aSeverity, String anId, String[] aParams, Object aTargetObject) { + super(aBundleName, aSeverity, anId, aParams, aTargetObject); + } + + @Override + public ResourceBundle getBundle(Locale locale, ClassLoader classLoader) { + ResourceBundle bundle = null; + try { + bundle = ResourceBundle.getBundle(getBundleName(), locale, getClass().getClassLoader()); + } catch (MissingResourceException e) { + return super.getBundle(locale, classLoader); + } + return bundle; + } + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java new file mode 100644 index 0000000000..51a0d4addc --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 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.jaxb.eclipselink.core.internal.validation; + +@SuppressWarnings("nls") +public interface ELJaxbValidationMessages { + + // bundle name + String BUNDLE_NAME = "el_jaxb_validation"; + + + // validation on project + String PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY = "PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY"; +} |