blob: b50906ebe22e810357c5010db9557c11b388439d (
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
128
129
130
131
132
133
134
135
136
|
/*******************************************************************************
* 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.context;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
/**
* the context model root
*/
public class GenericRootContextNode
extends AbstractJaxbContextNode
implements JaxbRootContextNode
{
/* This object has no parent, so it must point to the JAXB project explicitly. */
protected final JaxbProject jaxbProject;
/* Main context objects. */
protected final PackageContainer packageContainer;
public GenericRootContextNode(JaxbProject jaxbProject) {
super(null); // the JPA project is not really a "parent"...
if (jaxbProject == null) {
throw new NullPointerException();
}
this.jaxbProject = jaxbProject;
this.packageContainer = new PackageContainer();
}
@Override
protected boolean requiresParent() {
return false;
}
public void synchronizeWithResourceModel() {
this.syncPackages();
}
public void update() {
this.updatePackages();
}
// ********** AbstractJaxbNode overrides **********
@Override
public JaxbProject getJaxbProject() {
return this.jaxbProject;
}
@Override
public IResource getResource() {
return this.getProject();
}
protected IProject getProject() {
return this.jaxbProject.getProject();
}
// ************* packages ***************
public Iterable<JaxbPackage> getPackages() {
return this.packageContainer.getContextElements();
}
public int getPackagesSize() {
return this.packageContainer.getContextElementsSize();
}
protected JaxbPackage addPackage(JaxbPackage contextPackage, List<JaxbPackage> packages) {
this.addItemToCollection(contextPackage, packages, PACKAGES_COLLECTION);
return contextPackage;
}
protected void removePackage(JaxbPackage contextPackage, List<JaxbPackage> packages) {
this.removeItemFromCollection(contextPackage, packages, PACKAGES_COLLECTION);
}
protected void syncPackages() {
this.packageContainer.synchronizeWithResourceModel();
}
protected void updatePackages() {
//In this case we need to actually "sync" the list of packages since this is dependent on JaxbFiles
//and an update will be called when jaxb files are added/removed, not a synchronizeWithResourceModel
this.packageContainer.update();
}
protected JaxbPackage buildPackage(JavaResourcePackage resourcePackage) {
return this.getFactory().buildPackage(this, resourcePackage);
}
protected Iterable<JavaResourcePackage> getResourcePackages() {
return this.getJaxbProject().getAnnotatedJavaResourcePackages();
}
/**
* package container adapter
*/
protected class PackageContainer
extends ContextCollectionContainer<JaxbPackage, JavaResourcePackage>
{
@Override
protected String getContextElementsPropertyName() {
return PACKAGES_COLLECTION;
}
@Override
public JaxbPackage buildContextElement(JavaResourcePackage resourceElement) {
return GenericRootContextNode.this.buildPackage(resourceElement);
}
@Override
public Iterable<JavaResourcePackage> getResourceElements() {
return GenericRootContextNode.this.getResourcePackages();
}
@Override
public JavaResourcePackage getResourceElement(JaxbPackage contextElement) {
return contextElement.getResourcePackage();
}
}
}
|