diff options
author | tle | 2010-04-19 16:53:25 +0000 |
---|---|---|
committer | tle | 2010-04-19 16:53:25 +0000 |
commit | 8893618a739cc8c20e2ce44febb4a7d065f061f8 (patch) | |
tree | beb2c53a9038652e3a6a223f01d7772a5d34063b /jpa/plugins | |
parent | fe0ed73fdcaa67126f81f4852b22638830e1b349 (diff) | |
download | webtools.dali-8893618a739cc8c20e2ce44febb4a7d065f061f8.tar.gz webtools.dali-8893618a739cc8c20e2ce44febb4a7d065f061f8.tar.xz webtools.dali-8893618a739cc8c20e2ce44febb4a7d065f061f8.zip |
Initial check-in.
Diffstat (limited to 'jpa/plugins')
10 files changed, 348 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.classpath b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.classpath new file mode 100644 index 0000000000..4e4bf7088d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.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="org.eclipse.jpt.eclipselink.jaxb.core.schemagensrc.zip"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.cvsignore b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.cvsignore new file mode 100644 index 0000000000..c5e82d7458 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.cvsignore @@ -0,0 +1 @@ +bin
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.project b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.project new file mode 100644 index 0000000000..b85bb2e115 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.jpt.eclipselink.jaxb.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/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.settings/org.eclipse.jdt.core.prefs b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..8fb4ff705c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.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/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..14d1e491f8 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-Vendor: %providerName +Bundle-SymbolicName: org.eclipse.jpt.eclipselink.jaxb.core.schemagen;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: lib/eclipselink.jar +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: javax.xml.bind diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/about.html b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/about.html new file mode 100644 index 0000000000..071f586b21 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.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/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/build.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/build.properties new file mode 100644 index 0000000000..a3ffe71f6c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.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/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/lib/eclipselink.jar b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/lib/eclipselink.jar Binary files differnew file mode 100644 index 0000000000..855e644c5e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/lib/eclipselink.jar diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/plugin.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/plugin.properties new file mode 100644 index 0000000000..c05741163a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.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/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/src/org/eclipse/jpt/eclipselink/jaxb/core/schemagen/Main.java b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/src/org/eclipse/jpt/eclipselink/jaxb/core/schemagen/Main.java new file mode 100644 index 0000000000..25f4152b7f --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.jaxb.core.schemagen/src/org/eclipse/jpt/eclipselink/jaxb/core/schemagen/Main.java @@ -0,0 +1,202 @@ +/******************************************************************************* +* 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.eclipselink.jaxb.core.schemagen; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.persistence.jaxb.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.stream.StreamResult; + +import javax.xml.transform.Result; + +/** + * 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 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() { + System.out.println("MOXy:"); //$NON-NLS-1$ + + // Create the JAXBContext + JAXBContext jaxbContext = this.buildJaxbContext(); + + // Generate an XML Schema + if(jaxbContext != null) { + SchemaOutputResolver schemaOutputResolver = + new JptSchemaOutputResolver(this.targetSchemaName); + + jaxbContext.generateSchema(schemaOutputResolver); + + System.out.println("\nSchema " + this.targetSchemaName + " generated"); //$NON-NLS-1$ + } + } + + private JAXBContext buildJaxbContext() { + JAXBContext jaxbContext = null; + try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + + Class[] sourceClasses = this.buildSourceClasses(this.sourceClassNames, loader); + + jaxbContext = (JAXBContext)JAXBContext.newInstance(sourceClasses); + + } + catch (JAXBException e) { + String message = e.getMessage(); + if(message.indexOf(NO_FACTORY_CLASS) > -1) { + System.err.println(message); + } + else { + e.printStackTrace(); + } + System.err.println("\nSchema " + this.targetSchemaName + " not created"); //$NON-NLS-1$ + } + return jaxbContext; + } + + 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)); +// if(this.isDebugMode) { + System.out.println(className); //$NON-NLS-1$ +// } + } + catch (ClassNotFoundException e) { + System.err.println("\n\tNot found: " + className); //$NON-NLS-1$ + } + } + return sourceClasses.toArray(new Class[0]); + } + + // ********** 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; + } +} |