Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 85b5a9224de41971cbaccf4b10f70ec6485b6858 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
* Copyright (c) 2010, 2012 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.dbws.eclipselink.core.internal.gen;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jpt.common.core.gen.JptGenerator;
import org.eclipse.jpt.common.core.internal.gen.AbstractJptGenerator;
import org.eclipse.jpt.common.utility.internal.StringTools;

/**
 *  DbwsGenerator
 */
public class DbwsGenerator extends AbstractJptGenerator
{
	static public String LAUNCH_CONFIG_NAME = "DBWS Gen Run Config";   //$NON-NLS-1$
	static public String DBWS_GEN_PACKAGE_NAME = "org.eclipse.jpt.dbws.eclipselink.core.gen";   //$NON-NLS-1$
	static public String DBWS_GEN_CLASS = DBWS_GEN_PACKAGE_NAME + ".Main";	  //$NON-NLS-1$

	static public String DBWS_GEN_JAR_PREFIX = DBWS_GEN_PACKAGE_NAME + "_";	//$NON-NLS-1$
	
	private final String builderFileName;
	private final String stageDirName;
	private final String driverJarList;

	// ********** constructors **********

	public DbwsGenerator(
			IJavaProject javaProject, 
			String builderFileName, 
			String stageDirName, 
			String driverJarList) {
		super(javaProject);
		this.builderFileName = builderFileName;
		this.stageDirName = stageDirName;
		this.driverJarList = driverJarList;
	}

	// ********** overrides **********
	
	@Override
	protected String getMainType() {
		return DBWS_GEN_CLASS;
	}

	@Override
	protected String getLaunchConfigName() {
		return LAUNCH_CONFIG_NAME;
	}

	@Override
	protected String getBootstrapJarPrefix() {
		return DBWS_GEN_JAR_PREFIX;
	}

	@Override
	protected void preGenerate(IProgressMonitor monitor) {
		// do nothing
		
	}

	// ********** Launch Configuration Setup **********

	@Override
	protected List<String> buildClasspath() throws CoreException {
		List<String> classpath = new ArrayList<String>();
		// DBWS_Gen jar
		classpath.add(this.getBootstrapJarClasspathEntry().getMemento());
		// Default Project classpath
		classpath.add(this.getDefaultProjectClasspathEntry().getMemento());
		// JDBC jar
		if( ! StringTools.stringIsEmpty(this.driverJarList)) {
			classpath.add(this.getJdbcJarClasspathEntry().getMemento());
		}
		// System Library  
		classpath.add(this.getSystemLibraryClasspathEntry().getMemento());
		return classpath;
	}
	
	@Override
	protected void specifyProgramArguments() {

		StringBuffer programArguments = new StringBuffer();

		// builderFile
		programArguments.append(" -builderFile \"");	  //$NON-NLS-1$
		programArguments.append(this.builderFileName);
		programArguments.append('"');

		// stageDir
		programArguments.append(" -stageDir \"");	  //$NON-NLS-1$
		programArguments.append(this.stageDirName);
		programArguments.append('"');

		// packageAs
		programArguments.append(" -packageAs eclipse");	  //$NON-NLS-1$

		this.getLaunchConfig().setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArguments.toString());
	}

	// ********** private methods **********

	private IRuntimeClasspathEntry getJdbcJarClasspathEntry() {
		return getArchiveClasspathEntry(this.buildJdbcJarPath());
	}
	
	private IPath buildJdbcJarPath() {
		return new Path(this.driverJarList);
	}
	
	
}

Back to the top