blob: 906a4e1cb51f2af13d896cb8363fbb1c37f30d65 (
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
|
/*******************************************************************************
* Copyright (c) 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.jpa.core.internal;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jpt.jpa.core.JpaPlatform;
import org.eclipse.jpt.jpa.core.JpaPreferences;
import org.eclipse.jpt.jpa.core.JpaWorkspace;
import org.eclipse.jpt.jpa.core.context.XmlFile;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformManager;
public class XmlFileAdapterFactory
implements IAdapterFactory
{
private static final Class<?>[] ADAPTER_LIST = new Class[] {
JpaPlatform.Config.class
};
public Class<?>[] getAdapterList() {
return ADAPTER_LIST;
}
public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
if (adaptableObject instanceof XmlFile) {
return this.getAdapter(((XmlFile) adaptableObject).getXmlResource().getFile(), adapterType);
}
return null;
}
private Object getAdapter(IResource resource, Class<?> adapterType) {
if (adapterType == JpaPlatform.Config.class) {
return this.getJpaPlatformConfig(resource);
}
return null;
}
private JpaPlatform.Config getJpaPlatformConfig(IResource resource) {
JpaPlatformManager jpaPlatformManager = this.getJpaPlatformManager(resource.getWorkspace());
return (jpaPlatformManager == null) ? null : jpaPlatformManager.getJpaPlatformConfig(JpaPreferences.getJpaPlatformID(resource.getProject()));
}
private JpaPlatformManager getJpaPlatformManager(IWorkspace workspace) {
JpaWorkspace jpaWorkspace = this.getJpaWorkspace(workspace);
return (jpaWorkspace == null) ? null : jpaWorkspace.getJpaPlatformManager();
}
private JpaWorkspace getJpaWorkspace(IWorkspace workspace) {
return (JpaWorkspace) workspace.getAdapter(JpaWorkspace.class);
}
}
|