Skip to main content
summaryrefslogtreecommitdiffstats
blob: f9f39e9deaaa3f06f5509ff6eed1661ac9c63d6b (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
137
/*******************************************************************************
 * Copyright (c) 2005 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:
 *    Ian Trimble - initial API and implementation
 *******************************************************************************/ 
package org.eclipse.jst.jsf.core.jsfappconfig;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jst.jsf.facesconfig.emf.FacesConfigType;
import org.eclipse.jst.jsf.facesconfig.util.FacesConfigArtifactEdit;

/**
 * ArtifactEditJSFAppConfigProvider uses FacesConfigArtifactEdit to provide
 * the root element of an application configuration model.
 * 
 * <p><b>Provisional API - subject to change</b></p>
 * 
 * @author Ian Trimble - Oracle
 */
public class ArtifactEditJSFAppConfigProvider extends AbstractJSFAppConfigProvider {

	/**
	 * IFile instance that represents an application configuration resource
	 * file.
	 */
	protected IFile appConfigFile = null;

	/**
	 * FacesConfigArtifactEdit instance used to get the application
	 * configuration model.
	 */
	protected FacesConfigArtifactEdit facesConfigArtifactEdit = null;

	/**
	 * Cached {@link FacesConfigType} instance.
	 */
	protected FacesConfigType facesConfig = null;

	/**
	 * Creates an instance, storing the passed IFile instance for subsequent
	 * processing.
	 * 
	 * @param appConfigFile IFile instance that represents an application
	 * configuration resource file
	 */
	public ArtifactEditJSFAppConfigProvider(IFile appConfigFile) {
		this.appConfigFile = appConfigFile;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.core.jsfappconfig.IJSFAppConfigProvider#getFacesConfigModel()
	 */
	public FacesConfigType getFacesConfigModel() {
		if (facesConfig == null) {
			if (appConfigFile != null) {
				IProject project = appConfigFile.getProject();
				IPath appConfigFilePath = JSFAppConfigUtils.getWebContentFolderRelativePath(appConfigFile);
				if (appConfigFilePath != null) {
					facesConfigArtifactEdit = FacesConfigArtifactEdit.getFacesConfigArtifactEditForRead(project, appConfigFilePath.toString());
					if (facesConfigArtifactEdit != null) {
						facesConfig = facesConfigArtifactEdit.getFacesConfig();
						if (facesConfig != null) {
							jsfAppConfigLocater.getJSFAppConfigManager().addFacesConfigChangeAdapter(facesConfig);
						}
					}
				}
			}
		}
		return facesConfig;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.jsf.core.jsfappconfig.IJSFAppConfigProvider#releaseFacesConfigModel()
	 */
	public void releaseFacesConfigModel() {
		jsfAppConfigLocater.getJSFAppConfigManager().removeFacesConfigChangeAdapter(facesConfig);
		if (facesConfigArtifactEdit != null) {
			facesConfigArtifactEdit.dispose();
		}
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object otherObject) {
		boolean equals = false;
		if (otherObject != null && otherObject instanceof ArtifactEditJSFAppConfigProvider) {
			IFile otherAppConfigFile = ((ArtifactEditJSFAppConfigProvider)otherObject).appConfigFile;
			if (appConfigFile != null) {
				equals = appConfigFile.equals(otherAppConfigFile);
			} else {
				equals = otherAppConfigFile == null;
			}
		}
		return equals;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return appConfigFile != null ? appConfigFile.hashCode() : 0;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		StringBuffer sb = new StringBuffer("ArtifactEditJSFAppConfigProvider["); //$NON-NLS-1$
		if (appConfigFile != null) {
			sb.append(appConfigFile.toString());
		} else {
			sb.append("null"); //$NON-NLS-1$
		}
		sb.append("]"); //$NON-NLS-1$
		return sb.toString();
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#finalize()
	 */
	protected void finalize() {
		releaseFacesConfigModel();
	}

}

Back to the top