Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authortle2010-03-08 23:08:12 +0000
committertle2010-03-08 23:08:12 +0000
commit56586bdf5eacabda460df942f9a6ab2f2ce0c4a7 (patch)
treee23ad1f295d6cc5b6f6e52a515c9bef0decd079a /jpa
parent9daa03cb20a10a52c546a4b1a769f05c59f972e7 (diff)
downloadwebtools.dali-56586bdf5eacabda460df942f9a6ab2f2ce0c4a7.tar.gz
webtools.dali-56586bdf5eacabda460df942f9a6ab2f2ce0c4a7.tar.xz
webtools.dali-56586bdf5eacabda460df942f9a6ab2f2ce0c4a7.zip
296503 - [EclipseLink] Support invocation of JAXB schema generator
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.classpath7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.cvsignore1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.project28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/META-INF/MANIFEST.MF10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/about.html47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/build.properties19
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/plugin.properties24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/src/org/eclipse/jpt/jaxb/core/schemagen/Main.java127
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/SchemaGenerator.java375
11 files changed, 649 insertions, 1 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.classpath b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.classpath
new file mode 100644
index 0000000000..64c5e31b7a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <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 kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.cvsignore b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.cvsignore
new file mode 100644
index 0000000000..c5e82d7458
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.cvsignore
@@ -0,0 +1 @@
+bin \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.project b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.project
new file mode 100644
index 0000000000..025cb3b6fa
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.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.jaxb.core.schemagen/.settings/org.eclipse.jdt.core.prefs b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..0017ae69e5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Mon Mar 08 17:03:03 EST 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.jaxb.core.schemagen/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..2584fc3c44
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.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.jaxb.core.schemagen;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: javax.xml.bind;bundle-version="2.1.9"
+Export-Package: org.eclipse.jpt.jaxb.core.schemagen
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/about.html b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/about.html
new file mode 100644
index 0000000000..071f586b21
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.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&#8217;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.jaxb.core.schemagen/build.properties b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/build.properties
new file mode 100644
index 0000000000..31bcee6209
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/build.properties
@@ -0,0 +1,19 @@
+###############################################################################
+# 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
+###############################################################################
+javacSource=1.5
+javacTarget=1.5
+source.. = src/
+output.. = bin/
+bin.includes = .,\
+ META-INF/,\
+ about.html,\
+ plugin.properties
+jars.compile.order = .
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/plugin.properties b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/plugin.properties
new file mode 100644
index 0000000000..2e7dfca4c9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.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 - JAXB Support - Schema Generation
+providerName = Eclipse Web Tools Platform
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/src/org/eclipse/jpt/jaxb/core/schemagen/Main.java b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/src/org/eclipse/jpt/jaxb/core/schemagen/Main.java
new file mode 100644
index 0000000000..4b993caa60
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.core.schemagen/src/org/eclipse/jpt/jaxb/core/schemagen/Main.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+* 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.core.schemagen;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.transform.stream.StreamResult;
+
+import javax.xml.transform.Result;
+
+/**
+ * Generate a JAXB Schema
+ */
+public class Main
+{
+ private String sourcePackageName;
+ private String targetSchemaName;
+ private boolean isDebugMode;
+
+ // ********** static methods **********
+
+ public static void main(String[] args) throws Exception {
+ new Main().execute(args);
+ }
+
+ // ********** constructors **********
+
+ private Main() {
+ super();
+ }
+
+ // ********** behavior **********
+
+ protected void execute(String[] args) throws Exception {
+
+ this.initializeWith(args);
+
+ this.generate();
+ }
+
+ private void generate() throws Exception {
+ // Create the JAXBContext
+ JAXBContext jaxbContext = JAXBContext.newInstance(this.sourcePackageName);
+
+ // Generate an XML Schema
+ SchemaOutputResolver schemaOutputResolver =
+ new JptSchemaOutputResolver(this.targetSchemaName);
+
+ jaxbContext.generateSchema(schemaOutputResolver);
+ }
+
+ private void initializeWith(String[] args) {
+ this.sourcePackageName = this.getSourcePackageName(args);
+ this.targetSchemaName = this.getTargetSchemaName(args);
+
+ this.isDebugMode = this.getDebugMode(args);
+ }
+
+ // ********** argument queries **********
+
+ private String getSourcePackageName(String[] args) {
+
+ return this.getArgumentValue("-p", args);
+ }
+
+ private String getTargetSchemaName(String[] args) {
+
+ return this.getArgumentValue("-s", args);
+ }
+
+ private boolean getDebugMode(String[] args) {
+
+ return this.argumentExists("-debug", args);
+ }
+
+ private String getArgumentValue(String argument, String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ String arg = args[i];
+ if (arg.toLowerCase().equals(argument)) {
+ int j = i + 1;
+ if (j < args.length) {
+ return args[j];
+ }
+ }
+ }
+ return null;
+ }
+
+ private boolean argumentExists(String argument, String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ String arg = args[i];
+ if (arg.toLowerCase().equals(argument)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
+
+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/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF
index 13c5b084d5..e1e2578174 100644
--- a/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/META-INF/MANIFEST.MF
@@ -9,11 +9,13 @@ Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Require-Bundle: org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
+Require-Bundle: javax.xml.bind;bundle-version="[2.1.9,3.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.jdt.ui;bundle-version="[3.6.0,4.0.0)",
org.eclipse.jpt.core;bundle-version="[2.0.0,3.0.0)",
org.eclipse.jpt.ui;bundle-version="[2.0.0,3.0.0)",
org.eclipse.jpt.utility;bundle-version="[1.2.0,2.0.0)",
diff --git a/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/SchemaGenerator.java b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/SchemaGenerator.java
new file mode 100644
index 0000000000..416257f395
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/core/internal/SchemaGenerator.java
@@ -0,0 +1,375 @@
+/*******************************************************************************
+* 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.core.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.ILaunchesListener2;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.osgi.service.datalocation.Location;
+import org.osgi.framework.Bundle;
+
+/**
+ * ClassesGenerator
+ */
+public class SchemaGenerator
+{
+ static public String LAUNCH_CONFIG_NAME = "JAXB Schema Gen Run Config"; //$NON-NLS-1$
+ static public String JAXB_SCHEMA_GEN_PACKAGE_NAME = "org.eclipse.jpt.jaxb.core.schemagen"; //$NON-NLS-1$
+ static public String JAXB_SCHEMA_GEN_CLASS = JAXB_SCHEMA_GEN_PACKAGE_NAME + ".Main"; //$NON-NLS-1$
+ static public String JAXB_SCHEMA_GEN_JAR = JAXB_SCHEMA_GEN_PACKAGE_NAME + "_"; //$NON-NLS-1$
+ static public String PLUGINS_DIR = "plugins/"; //$NON-NLS-1$
+
+ private IVMInstall jre;
+ private ILaunchConfigurationWorkingCopy launchConfig;
+ private ILaunch launch;
+
+ private final JpaProject jpaProject;
+ private final String targetSchemaName;
+ private final String outputDir;
+ private final String sourcePackageName;
+ private final String mainType;
+ private final boolean isDebug = true; // TODO
+
+ // ********** static methods **********
+
+ public static void generate(
+ JpaProject project,
+ String targetSchemaName,
+ String outputDir,
+ String sourcePackageName,
+ IProgressMonitor monitor) {
+ if (project == null) {
+ throw new NullPointerException();
+ }
+ new SchemaGenerator(project,
+ targetSchemaName,
+ outputDir,
+ sourcePackageName,
+ monitor).generate();
+ }
+
+ // ********** constructors **********
+
+ protected SchemaGenerator(
+ JpaProject jpaProject,
+ String targetSchemaName,
+ String outputDir,
+ String sourcePackageName,
+ @SuppressWarnings("unused") IProgressMonitor monitor) {
+ super();
+ this.jpaProject = jpaProject;
+ this.targetSchemaName = targetSchemaName;
+ this.outputDir = outputDir;
+ this.sourcePackageName = sourcePackageName;
+ this.mainType = JAXB_SCHEMA_GEN_CLASS;
+
+ this.initialize();
+ }
+
+ // ********** behavior **********
+
+ protected void initialize() {
+ try {
+ this.jre = this.getProjectJRE();
+ if (this.jre == null) {
+ String message = "Could not identify the VM."; //$NON-NLS-1$
+ throw new RuntimeException(message);
+ }
+ this.launchConfig = this.buildLaunchConfiguration();
+ }
+ catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void generate() {
+ String projectLocation = this.jpaProject.getProject().getLocation().toString();
+
+ this.initializeLaunchConfiguration(projectLocation);
+
+ this.addLaunchListener();
+ this.launch = this.saveAndLaunchConfig();
+ }
+
+ private void initializeLaunchConfiguration(String projectLocation) {
+
+ this.specifyJRE(this.jre.getName(), this.jre.getVMInstallType().getId());
+
+ this.specifyProject(this.getJpaProject().getProject().getName());
+ this.specifyMainType(this.mainType);
+
+ this.specifyProgramArguments(
+ this.targetSchemaName,
+ this.outputDir,
+ this.sourcePackageName); // -d -p
+ this.specifyWorkingDir(projectLocation);
+
+ this.specifyClasspathProperties(this.getJpaProject(), this.buildBootstrapJarPath());
+ }
+
+ protected void postGenerate() {
+ try {
+ if ( ! this.isDebug) {
+ this.removeLaunchConfiguration(LAUNCH_CONFIG_NAME);
+ }
+ }
+ catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // ********** Launch Configuration Setup **********
+
+ private void specifyClasspathProperties(JpaProject project, IPath bootstrapJar) {
+ List<String> classpath = new ArrayList<String>();
+ try {
+ // Schema_Gen jar
+ classpath.add(this.getArchiveClasspathEntry(bootstrapJar).getMemento());
+ // Default Project classpath
+ classpath.add(this.getDefaultProjectClasspathEntry(project.getJavaProject()).getMemento());
+ // System Library
+ classpath.add(this.getSystemLibraryClasspathEntry().getMemento());
+ }
+ catch (CoreException e) {
+ throw new RuntimeException("An error occurs generating a memento", e);
+ }
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
+ }
+
+ private void specifyJRE(String jreName, String vmId) {
+
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jreName);
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, vmId);
+ }
+
+ private void specifyProject(String projectName) {
+
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
+ }
+
+ private void specifyMainType(String mainType) {
+
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainType);
+ }
+
+ private void specifyProgramArguments(
+ String targetSchemaName,
+ String outputDir,
+ String sourcePackageName) {
+
+ StringBuffer programArguments = new StringBuffer();
+ // package
+ programArguments.append(" -p "); //$NON-NLS-1$
+ programArguments.append(sourcePackageName);
+ // schema
+ programArguments.append(" -s "); //$NON-NLS-1$
+ programArguments.append(targetSchemaName);
+
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArguments.toString());
+ }
+
+ private void specifyWorkingDir(String projectLocation) {
+
+ File workingDir = new Path(projectLocation).toFile();
+ this.launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workingDir.getAbsolutePath());
+ }
+
+ // ********** LaunchConfig **********
+
+ private ILaunchConfigurationWorkingCopy buildLaunchConfiguration() throws CoreException {
+ ILaunchConfigurationWorkingCopy launchConfig = null;
+ this.removeLaunchConfiguration(LAUNCH_CONFIG_NAME);
+
+ ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
+
+ launchConfig = type.newInstance(null, LAUNCH_CONFIG_NAME);
+ return launchConfig;
+ }
+
+ private void removeLaunchConfiguration(String launchConfigurationName) throws CoreException {
+
+ ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
+
+ ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
+ for (int i = 0; i < configurations.length; i++) {
+ ILaunchConfiguration configuration = configurations[i];
+ if (configuration.getName().equals(launchConfigurationName)) {
+ configuration.delete();
+ break;
+ }
+ }
+ }
+
+ private ILaunch saveAndLaunchConfig() {
+ ILaunchConfiguration configuration = null;
+ ILaunch result = null;
+ try {
+ configuration = this.launchConfig.doSave();
+ }
+ catch (CoreException saveException) {
+ throw new RuntimeException("Could not save LaunchConfig", saveException);
+ }
+ try {
+ result = configuration.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
+ }
+ catch (CoreException lauchException) {
+ throw new RuntimeException("An error occured during launch", lauchException);
+ }
+ return result;
+ }
+
+ private void addLaunchListener() {
+
+ this.getLaunchManager().addLaunchListener(this.buildLaunchListener());
+ }
+
+ private ILaunchesListener2 buildLaunchListener() {
+ return new ILaunchesListener2() {
+
+ public void launchesTerminated(ILaunch[] launches) {
+ for (int i = 0; i < launches.length; i++) {
+ ILaunch launch = launches[i];
+ if (launch.equals(SchemaGenerator.this.getLaunch())) {
+
+ SchemaGenerator.this.postGenerate();
+ return;
+ }
+ }
+ }
+
+ public void launchesAdded(ILaunch[] launches) {
+ // not interested to this event
+ }
+
+ public void launchesChanged(ILaunch[] launches) {
+ // not interested to this event
+ }
+
+ public void launchesRemoved(ILaunch[] launches) {
+ // not interested to this event
+ }
+ };
+ }
+
+ // ********** Queries **********
+
+ private IRuntimeClasspathEntry getSystemLibraryClasspathEntry() throws CoreException {
+
+ IPath systemLibsPath = new Path(JavaRuntime.JRE_CONTAINER);
+ return JavaRuntime.newRuntimeContainerClasspathEntry(systemLibsPath, IRuntimeClasspathEntry.STANDARD_CLASSES);
+ }
+
+ private IRuntimeClasspathEntry getArchiveClasspathEntry(IPath archivePath) {
+
+ IRuntimeClasspathEntry archiveEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(archivePath);
+ archiveEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
+
+ return archiveEntry;
+ }
+
+ private IRuntimeClasspathEntry getDefaultProjectClasspathEntry(IJavaProject project) {
+
+ IRuntimeClasspathEntry projectEntry = JavaRuntime.newDefaultProjectClasspathEntry(project);
+ projectEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
+
+ return projectEntry;
+ }
+
+ protected JpaProject getJpaProject() {
+ return this.jpaProject;
+ }
+
+ private IVMInstall getProjectJRE() throws CoreException {
+ return JavaRuntime.getVMInstall(this.getJpaProject().getJavaProject());
+ }
+
+ protected ILaunch getLaunch() {
+ return this.launch;
+ }
+
+ protected ILaunchManager getLaunchManager() {
+ return DebugPlugin.getDefault().getLaunchManager();
+ }
+
+ // ********** private method **********
+
+ private IPath buildBootstrapJarPath() {
+ try {
+ File jarInstallDir = this.getBundleParentDir(JptCorePlugin.PLUGIN_ID);
+
+ List<File> result = new ArrayList<File>();
+ this.findFile(JAXB_SCHEMA_GEN_JAR, jarInstallDir, result);
+ if (result.isEmpty()) {
+ throw new RuntimeException("Could not find: " + JAXB_SCHEMA_GEN_PACKAGE_NAME + "_version.jar in: " + jarInstallDir);
+ }
+ File ddlGenJarFile = result.get(0);
+ String ddlGenJarPath = ddlGenJarFile.getCanonicalPath();
+ return new Path(ddlGenJarPath);
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void findFile(String fileName, File directory, List<? super File> list) {
+ if(directory.listFiles() == null) {
+ throw new RuntimeException("Could not find directory: " + directory);
+ }
+ for (File file : directory.listFiles()) {
+ if (file.getName().startsWith(fileName)) {
+ list.add(file);
+ }
+ if (file.isDirectory()) {
+ this.findFile(fileName, file, list);
+ }
+ }
+ }
+
+ private File getBundleParentDir(String bundleName) throws IOException {
+
+ if (Platform.inDevelopmentMode()) {
+ Location eclipseHomeLoc = Platform.getInstallLocation();
+ String eclipseHome = eclipseHomeLoc.getURL().getPath();
+ if ( ! eclipseHome.endsWith(PLUGINS_DIR)) {
+ eclipseHome += PLUGINS_DIR;
+ }
+ return new File(eclipseHome);
+ }
+ Bundle bundle = Platform.getBundle(bundleName);
+ return FileLocator.getBundleFile(bundle).getParentFile();
+ }
+
+}

Back to the top