Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1077b49b4b13e4a214f1b18ad08c26e2442b2843 (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
/*******************************************************************************
 * Copyright (c) 2010, 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.core.tests.internal.projects;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject;
import org.eclipse.jpt.common.utility.Command;
import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer;
import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
import org.eclipse.jpt.jaxb.core.JaxbFacet;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;

/**
 * This builds and holds a "JAXB" project.
 * Support for adding packages and types.
 * 
 * The JPA project's settings (platform, database connection, etc.) can be
 * controlled by building a data model and passing it into the constructor.
 */
public class TestJaxbProject
		extends TestJavaProject {
	
	private final JaxbProject jaxbProject;
	
	
	// ***** static methods *****
	
	public static final String JAXB_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.jaxb.jar";
	public static final String ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.eclipselink.jar";
	
	public static String jaxbJarName() {
		return getSystemProperty(JAXB_JAR_NAME_SYSTEM_PROPERTY);
	}
	
	public static String eclipselinkJarName() {
		return getSystemProperty(ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY);
	}
	
	private static String getSystemProperty(String propertyName) {
		return System.getProperty(propertyName);
	}
	
	
	// ********** builders **********
	
	public static TestJaxbProject buildJaxbProject(
			String baseProjectName, boolean autoBuild, IDataModel config)
			throws CoreException {
		return new TestJaxbProject(baseProjectName, autoBuild, config);
	}
	
	
	// ********** constructors/initialization **********
	
	public TestJaxbProject(String projectName) throws CoreException {
		this(projectName, false);
	}
	
	public TestJaxbProject(String projectName, boolean autoBuild) throws CoreException {
		this(projectName, autoBuild, null);
	}
	
	public TestJaxbProject(String projectName, boolean autoBuild, IDataModel config) throws CoreException {
		super(projectName, autoBuild);
		String jaxbFacetVersion = 
				((IProjectFacetVersion) config.getProperty(IFacetDataModelProperties.FACET_VERSION)).getVersionString();
		this.installFacet(JaxbFacet.ID, jaxbFacetVersion, config);
		this.addJar(jaxbJarName());
		if (eclipselinkJarName() != null) {
			this.addJar(eclipselinkJarName());
		}
		this.jaxbProject = JptJaxbCorePlugin.getJaxbProject(this.getProject());
		this.jaxbProject.setContextModelSynchronizer(this.buildSynchronousContextModelSynchronizer());
		this.jaxbProject.setUpdateSynchronizer(this.buildSynchronousUpdateSynchronizer());
	}
	
	protected Synchronizer buildSynchronousContextModelSynchronizer() {
		return new SynchronousSynchronizer(this.buildSynchronousContextModelSynchronizerCommand());
	}

	protected Command buildSynchronousContextModelSynchronizerCommand() {
		return new SynchronousContextModelSynchronizerCommand();
	}

	protected class SynchronousContextModelSynchronizerCommand implements Command {
		public void execute() {
			TestJaxbProject.this.jaxbProject.synchronizeContextModel(new NullProgressMonitor());
		}
	}
	
	protected CallbackSynchronizer buildSynchronousUpdateSynchronizer() {
		return new CallbackSynchronousSynchronizer(this.buildSynchronousUpdateSynchronizerCommand());
	}

	protected Command buildSynchronousUpdateSynchronizerCommand() {
		return new SynchronousUpdateSynchronizerCommand();
	}

	protected class SynchronousUpdateSynchronizerCommand implements Command {
		public void execute() {
			TestJaxbProject.this.jaxbProject.update(new NullProgressMonitor());
		}
	}
	
	
	// ********** public methods **********
	
	public JaxbProject getJaxbProject() {
		return this.jaxbProject;
	}
}

Back to the top