Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 12ce71d299a6d76224383705844debbfd97f1da0 (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
/*******************************************************************************
 * Copyright (c) 2007 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.core.internal.platform;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jpt.core.internal.IPersistentType;
import org.eclipse.jpt.core.internal.content.java.IJavaTypeMapping;
import org.eclipse.jpt.core.internal.content.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.content.java.JavaPersistentType;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;

public abstract class JavaTypeContext extends BaseContext
	implements TypeContext
{
	private IJavaTypeMapping typeMapping;
	
	private Collection<JavaPersistentAttributeContext> javaPersistentAttributeContexts;
	
	private boolean refreshed;
	
	public JavaTypeContext(IContext parentContext, IJavaTypeMapping typeMapping) {
		super(parentContext);
		this.typeMapping = typeMapping;
		this.javaPersistentAttributeContexts = buildJavaPersistentAttributeContexts();
	}

	protected Collection<JavaPersistentAttributeContext> buildJavaPersistentAttributeContexts() {
		Collection<JavaPersistentAttributeContext> persistentAttributes = new ArrayList<JavaPersistentAttributeContext>();
		for (Iterator<JavaPersistentAttribute> i = getPersistentType().getAttributes().iterator(); i.hasNext(); ) {
			persistentAttributes.add(new JavaPersistentAttributeContext(this, i.next()));
		}
		
		return persistentAttributes;
	}
	
	
	@Override
	protected void initialize() {}
	
	protected void populateGeneratorRepository(GeneratorRepository generatorRepository) {
		for (JavaPersistentAttributeContext context : getJavaPersistentAttributeContexts()) {
			context.populateGeneratorRepository(generatorRepository);
		}
	}

	public void refreshDefaults(DefaultsContext defaultsContext) {
		this.refreshed = true;
		this.getPersistentType().refreshDefaults(defaultsContext);
		for (JavaPersistentAttributeContext context : this.javaPersistentAttributeContexts) {
			context.refreshDefaults(defaultsContext);
		}
	}
	
	public JavaPersistentType getPersistentType() {
		return (JavaPersistentType) typeMapping.getPersistentType();
	}
	
	protected IJavaTypeMapping getTypeMapping() {
		return typeMapping;
	}
	
	protected Collection<JavaPersistentAttributeContext> getJavaPersistentAttributeContexts() {
		return this.javaPersistentAttributeContexts;
	}

	public boolean isRefreshed() {
		return this.refreshed;
	}
	
	public boolean contains(IPersistentType persistentType) {
		return persistentType == getPersistentType();
	}
	
	public void addToMessages(List<IMessage> messages) {
		addAttributeMessages(messages);
	}
	
	protected void addAttributeMessages(List<IMessage> messages) {
		for (JavaPersistentAttributeContext attributeContext : javaPersistentAttributeContexts) {
			attributeContext.addToMessages(messages);
		}
	}
}

Back to the top