diff options
author | pfullbright | 2010-09-29 14:32:00 +0000 |
---|---|---|
committer | pfullbright | 2010-09-29 14:32:00 +0000 |
commit | 96446f6c7e8c9fce0575a68145e5023e94e9fcdd (patch) | |
tree | 16ef5c2e9427c09a5e90f38e67d95f66561ad00e /jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen | |
parent | 8a6f1177a42c0a4bbace747cc10d4da743df42b2 (diff) | |
download | webtools.dali-96446f6c7e8c9fce0575a68145e5023e94e9fcdd.tar.gz webtools.dali-96446f6c7e8c9fce0575a68145e5023e94e9fcdd.tar.xz webtools.dali-96446f6c7e8c9fce0575a68145e5023e94e9fcdd.zip |
renamed and moved to jaxb component
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen')
13 files changed, 462 insertions, 0 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.classpath b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.classpath new file mode 100644 index 0000000000..bbf9ced68e --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <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"/> + <classpathentry exported="true" kind="lib" path="lib/eclipselink.jar" sourcepath="lib/eclipselink-src.zip"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.cvsignore b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.cvsignore new file mode 100644 index 0000000000..c5e82d7458 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.cvsignore @@ -0,0 +1 @@ +bin
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.project b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.project new file mode 100644 index 0000000000..a482c34f48 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.jpt.jaxb.eclipselink.core.schemagen</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.settings/org.eclipse.jdt.core.prefs b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..8fb4ff705c --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Tue Apr 13 12:12:27 EDT 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/META-INF/MANIFEST.MF b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d196476a1e --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-Vendor: %providerName +Bundle-SymbolicName: org.eclipse.jpt.jaxb.eclipselink.core.schemagen;singleton:=true +Bundle-Version: 1.1.0.qualifier +Bundle-ClassPath: lib/eclipselink.jar +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: javax.xml.bind +Export-Package: org.eclipse.jpt.jaxb.eclipselink.core.schemagen, + org.eclipse.jpt.jaxb.eclipselink.core.schemagen.internal diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/about.html b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/about.html new file mode 100644 index 0000000000..071f586b21 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/about.html @@ -0,0 +1,47 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<HTML> + +<head> +<title>About</title> +<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> +</head> + +<BODY lang="EN-US"> + +<H2>About This Content</H2> + +<P>May 02, 2008</P> + +<H3>License</H3> + +<P>The Eclipse Foundation makes available all content in this plug-in +("Content"). Unless otherwise indicated below, the Content is provided to you +under the terms and conditions of the Eclipse Public License Version 1.0 +("EPL"). A copy of the EPL is available at +<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>. +For purposes of the EPL, "Program" will mean the Content.</P> + +<P>If you did not receive this Content directly from the Eclipse Foundation, the +Content is being redistributed by another party ("Redistributor") and different +terms and conditions may apply to your use of any object code in the Content. +Check the Redistributor's license that was provided with the Content. If no such +license exists, contact the Redistributor. Unless otherwise indicated below, the +terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at +<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P> + +<h3>Third Party Content</h3> +<p>The Content includes items that have been sourced from third parties as set + out below. If you did not receive this Content directly from the Eclipse Foundation, + the following is provided for informational purposes only, and you should look + to the Redistributor’s license for terms and conditions of use.</p> + +<h4><a name="JPA" id="JPA"></a>Java Persistence API (JPA) v1.0</h4> + +<blockquote> + <p>The Java Persistence API (JPA) which is distributed under <a href="https://glassfish.dev.java.net/public/CDDLv1.0.html">CDDL + v1.0</a> is required by the Dali Java Persistence Tools Project in order + to support this standard.</p> +</blockquote> +</BODY> +</HTML> diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/build.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/build.properties new file mode 100644 index 0000000000..a3ffe71f6c --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/build.properties @@ -0,0 +1,20 @@ +############################################################################### +# Copyright (c) 2010 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 +############################################################################### +javacSource=1.5 +javacTarget=1.5 +source.. = src/ +output.. = bin/ +bin.includes = .,\ + META-INF/,\ + lib/eclipselink.jar,\ + about.html,\ + plugin.properties +jars.compile.order = . diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/lib/eclipselink-src.zip b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/lib/eclipselink-src.zip Binary files differnew file mode 100644 index 0000000000..68a5393d4f --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/lib/eclipselink-src.zip diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/lib/eclipselink.jar b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/lib/eclipselink.jar Binary files differnew file mode 100644 index 0000000000..855e644c5e --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/lib/eclipselink.jar diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/plugin.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/plugin.properties new file mode 100644 index 0000000000..c05741163a --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/plugin.properties @@ -0,0 +1,24 @@ +############################################################################### +# Copyright (c) 2006, 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 +############################################################################### +# ==================================================================== +# To code developer: +# Do NOT change the properties between this line and the +# "%%% END OF TRANSLATED PROPERTIES %%%" line. +# Make a new property name, append to the end of the file and change +# the code to use the new property. +# ==================================================================== + +# ==================================================================== +# %%% END OF TRANSLATED PROPERTIES %%% +# ==================================================================== + +pluginName = Dali Java Persistence Tools - EclipseLink JAXB Support - Schema Generation +providerName = Eclipse Web Tools Platform diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/Main.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/Main.java new file mode 100644 index 0000000000..3bcf4eac26 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/Main.java @@ -0,0 +1,250 @@ +/******************************************************************************* +* Copyright (c) 2010 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.schemagen; + +import java.io.File; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.xml.bind.JAXBException; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.jpt.jaxb.eclipselink.core.schemagen.internal.JptEclipseLinkJaxbCoreMessages; +import org.eclipse.persistence.jaxb.JAXBContext; +import org.eclipse.persistence.jaxb.JAXBContextFactory; + +/** + * Generate a EclipseLink JAXB Schema + * + * Current command-line arguments: + * [-s schema.xsd] - specifies the target schema + * [-c className] - specifies the fully qualified class name + */ +public class Main +{ + private String[] sourceClassNames; + private String targetSchemaName; + @SuppressWarnings("unused") + private boolean isDebugMode; + + static public String NO_FACTORY_CLASS = "doesnt contain ObjectFactory.class"; //$NON-NLS-1$ + static public String CANNOT_BE_CAST_TO_JAXBCONTEXT = "cannot be cast to org.eclipse.persistence.jaxb.JAXBContext"; //$NON-NLS-1$ + + // ********** static methods ********** + + public static void main(String[] args) { + new Main().execute(args); + } + + // ********** constructors ********** + + private Main() { + super(); + } + + // ********** behavior ********** + + protected void execute(String[] args) { + + this.initializeWith(args); + + this.generate(); + } + + // ********** internal methods ********** + + private void initializeWith(String[] args) { + this.sourceClassNames = this.getSourceClassNames(args); + this.targetSchemaName = this.getTargetSchemaName(args); + + this.isDebugMode = this.getDebugMode(args); + } + + private void generate() { + // Create the JAXBContext + JAXBContext jaxbContext = this.buildJaxbContext(); + + // Generate an XML Schema + if(jaxbContext != null) { + this.generateSchema(jaxbContext); + } + String result = (jaxbContext != null) ? + this.bind(JptEclipseLinkJaxbCoreMessages.SCHEMA_GENERATED, this.targetSchemaName) : + this.bind(JptEclipseLinkJaxbCoreMessages.SCHEMA_NOT_CREATED, this.targetSchemaName); + System.out.println(result); + } + + private JAXBContext buildJaxbContext() { + System.out.println(this.getString(JptEclipseLinkJaxbCoreMessages.LOADING_CLASSES)); + JAXBContext jaxbContext = null; + try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + + Class[] sourceClasses = this.buildSourceClasses(this.sourceClassNames, loader); + + //call MOXy JAXBContextFactory directly. This eliminates the need to have the JAXB properties file in place + //in time for the generation. + jaxbContext = (JAXBContext)JAXBContextFactory.createContext(sourceClasses, Collections.<String,Object>emptyMap()); + } + catch (JAXBException ex) { + this.handleJaxbException(ex); + } + catch (ClassCastException ex) { + this.handleClassCastException(ex); + } + return jaxbContext; + } + + private void generateSchema(JAXBContext jaxbContext) { + System.out.println(this.getString(JptEclipseLinkJaxbCoreMessages.GENERATING_SCHEMA)); + System.out.flush(); + + SchemaOutputResolver schemaOutputResolver = + new JptSchemaOutputResolver(this.targetSchemaName); + + try { + jaxbContext.generateSchema(schemaOutputResolver); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + private Class[] buildSourceClasses(String[] classNames, ClassLoader loader) { + + ArrayList<Class> sourceClasses = new ArrayList<Class>(classNames.length); + for(String className: classNames) { + try { + sourceClasses.add(loader.loadClass(className)); + System.out.println(className); + } + catch (ClassNotFoundException e) { + System.err.println(this.bind(JptEclipseLinkJaxbCoreMessages.NOT_FOUND, className)); + } + } + System.out.flush(); + return sourceClasses.toArray(new Class[0]); + } + + private void handleJaxbException(JAXBException ex) { + String message = ex.getMessage(); + Throwable linkedEx = ex.getLinkedException(); + if(message != null && message.indexOf(NO_FACTORY_CLASS) > -1) { + System.err.println(message); + } + else if(linkedEx != null && linkedEx instanceof ClassNotFoundException) { + String errorMessage = this.bind( + JptEclipseLinkJaxbCoreMessages.CONTEXT_FACTORY_NOT_FOUND, linkedEx.getMessage()); + System.err.println(errorMessage); + } + else { + ex.printStackTrace(); + } + } + + private void handleClassCastException(ClassCastException ex) { + String message = ex.getMessage(); + if(message != null && message.indexOf(CANNOT_BE_CAST_TO_JAXBCONTEXT) > -1) { + System.err.println(this.getString(JptEclipseLinkJaxbCoreMessages.PROPERTIES_FILE_NOT_FOUND)); + } + else { + ex.printStackTrace(); + } + } + + private String getString(String key) { + return JptEclipseLinkJaxbCoreMessages.getString(key); + } + + private String bind(String key, Object argument) { + return MessageFormat.format(this.getString(key), argument); + } + + // ********** argument queries ********** + + private String[] getSourceClassNames(String[] args) { + + return this.getAllArgumentValues("-c", args); //$NON-NLS-1$ + } + + private String getTargetSchemaName(String[] args) { + + return this.getArgumentValue("-s", args); //$NON-NLS-1$ + } + + private boolean getDebugMode(String[] args) { + + return this.argumentExists("-debug", args); //$NON-NLS-1$ + } + + private String getArgumentValue(String argName, String[] args) { + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (arg.toLowerCase().equals(argName)) { + int j = i + 1; + if (j < args.length) { + return args[j]; + } + } + } + return null; + } + + private String[] getAllArgumentValues(String argName, String[] args) { + List<String> argValues = new ArrayList<String>(); + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (arg.toLowerCase().equals(argName)) { + int j = i + 1; + if (j < args.length) { + argValues.add(args[j]); + i++; + } + } + } + return argValues.toArray(new String[0]); + } + + private boolean argumentExists(String argName, String[] args) { + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (arg.toLowerCase().equals(argName)) { + return true; + } + } + return false; + } + +} + +// ********** inner class ********** + +class JptSchemaOutputResolver extends SchemaOutputResolver { + + private final String targetSchemaName; + + protected JptSchemaOutputResolver(String targetSchemaName) { + this.targetSchemaName = targetSchemaName; + } + + @Override + public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { + + File file = new File(this.targetSchemaName ); + StreamResult result = new StreamResult(file); + result.setSystemId(file.toURI().toURL().toString()); + return result; + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/internal/JptEclipseLinkJaxbCoreMessages.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/internal/JptEclipseLinkJaxbCoreMessages.java new file mode 100644 index 0000000000..65a9e2eee8 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/internal/JptEclipseLinkJaxbCoreMessages.java @@ -0,0 +1,43 @@ +/******************************************************************************* +* Copyright (c) 2010 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.schemagen.internal; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Localized messages used by Dali EclipseLink JAXB core. + */ +public class JptEclipseLinkJaxbCoreMessages +{ + public static final String LOADING_CLASSES = "LOADING_CLASSES"; + public static final String GENERATING_SCHEMA = "GENERATING_SCHEMA"; + public static final String SCHEMA_GENERATED = "SCHEMA_GENERATED"; + public static final String SCHEMA_NOT_CREATED = "SCHEMA_NOT_CREATED"; + public static final String NOT_FOUND = "NOT_FOUND"; + public static final String CONTEXT_FACTORY_NOT_FOUND = "CONTEXT_FACTORY_NOT_FOUND"; + public static final String PROPERTIES_FILE_NOT_FOUND = "PROPERTIES_FILE_NOT_FOUND"; + + + private static final String BUNDLE_NAME = "org.eclipse.jpt.jaxb.eclipselink.core.schemagen.internal.jpt_eclipselink_jaxb_core"; //$NON-NLS-1$ + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private JptEclipseLinkJaxbCoreMessages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +}
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/internal/jpt_eclipselink_jaxb_core.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/internal/jpt_eclipselink_jaxb_core.properties new file mode 100644 index 0000000000..f7914dbf32 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core.schemagen/src/org/eclipse/jpt/jaxb/eclipselink/core/schemagen/internal/jpt_eclipselink_jaxb_core.properties @@ -0,0 +1,21 @@ +################################################################################ +# Copyright (c) 2010 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 +################################################################################ + +LOADING_CLASSES = loading... +GENERATING_SCHEMA = \nMOXy generating schema... +SCHEMA_GENERATED = \nSchema {0} generated +SCHEMA_NOT_CREATED = \nSchema {0} not created +NOT_FOUND = \n\tNot found: {0} +PROPERTIES_FILE_NOT_FOUND = \nEclipseLink JAXBContextFactory must be specified in the jaxb.properties file to use EclipseLink MOXy for schema generation.\n\ +javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory +CONTEXT_FACTORY_NOT_FOUND = \nThe JAXBContextFactory {0} \n\ +configured in the jaxb.properties file could not be located on the project classpath. \n\ +The JAXB provider that defines this factory should be added to the project classpath, \n\ +or the jaxb.properties file should be removed to use the default provider. |