Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5554ab7b8621a74627250dea6baee1dd4d86d3c8 (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
/*******************************************************************************
 * Copyright (c) 2007 Oracle Corporation.
 * 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.jst.jsf.common.metadata.internal;

import org.eclipse.jst.jsf.common.metadata.Model;

/**
 * Responsible for loading and holding onto the standard metadata model using the IDomainLoadingStrategy.
 * Wraps the model (root) with the strategy used for loading it, along with the identifying key (modelKeyDescriptor)
 */
public class MetaDataModel {

	private Object root;
	private ModelKeyDescriptor modelKeyDescriptor;
	private IDomainLoadingStrategy strategy;
	private boolean refresh;
	
	/**
	 * Constructor
	 * @param key
	 * @param strategy
	 */
	public MetaDataModel(ModelKeyDescriptor key, IDomainLoadingStrategy strategy){
		this.modelKeyDescriptor = key;
		this.strategy = strategy;
	}

	/**
	 * @return the root of the model.  
	 */
	public Object getRoot(){
		return root;
	}
	
	/**
	 * @param root 
	 */
	public void setRoot(Object root){
		this.root = root;
		if (root != null)
			((Model)root).setCurrentModelContext(modelKeyDescriptor);
	}
	
	/**
	 * @return ModelKeyDescriptor for this model
	 */
	public ModelKeyDescriptor getModelKey(){
		return modelKeyDescriptor;
	}

//	public void accept(IEntityVisitor visitor){
//		if (getRoot() instanceof Model)
//			visitor.visit((Model)getRoot());
//	}

	/**
	 * @return true if the model is null or is not, in fact, a {@link Model}
	 */
	public boolean isEmpty() {
		if (root == null || !(root instanceof Model))
			return true;
				
		return false;
	}
	
	/**
	 * Load the model.  Delegates to the strategy.
	 */
	public void load(){
		strategy.load(this);
	}
	
	/**
	 * Reloads the model delegating to strategy reload
	 * @throws ModelNotSetException
	 */
	public void reload()throws ModelNotSetException{
		setRoot(null);
		refresh = false;
		strategy.reload();
	}

	/**
	 * @return flag indicating that the model is stale
	 */
	public boolean needsRefresh() {		
		return refresh;
	}
	
	/**
	 * Flag that model is stale
	 */
	public void setNeedsRefresh() {		
		refresh = true;
	}
	
	/**
	 * Cleans up the model releasing references.
	 */
	public void cleanup(){
		if (strategy != null)
			strategy.cleanup();
		strategy = null;
		root = null;
		modelKeyDescriptor = null;
	}

}

Back to the top