Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e51105c5547eaaeb4752f998c4193323399c3374 (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
138
/*******************************************************************************
 * Copyright (c) 2006 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:
 *    Justin Chen
 *******************************************************************************/
package org.eclipse.jst.jsf.core.internal.jsflibraryconfig;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.core.internal.Messages;

/**
 * To construct implementation library and component libraries from sticky values 
 * in DialogSettings as saved libraries.  
 * 
 * @author Justin Chen - Oracle
 */
public class JSFLibraryConfigDialogSettingData implements JSFLibraryConfiglModelSource {
	/**
	 * Delimintor for parsing a persistent property string.
	 */
	final protected static String SEPARATOR =":";	//$NON-NLS-1$

	final private JSFLibraryRegistryUtil jsfLibReg;
	final private boolean dftImplLibDeployFlag;
	final private String[] savedCompLibs;
	private JSFLibraryReference selJSFLibImpl;	// lazy initialized	
	private List selJSFLibComp;							// lazy initialized
	
	/**
	 * Constructor
	 * @param implLibDeployFlag String  valid options are "true" or "false"
	 * @param compLibs String[]  saved component library settings in string array
	 * 
	public JSFLibraryConfigDialogSettingData(String implLibDeployFlag, String[] compLibs) {
		this.jsfLibReg = JSFLibraryRegistryUtil.getInstance();
		this.dftImplLibDeployFlag = implLibDeployFlag;
		this.savedCompLibs = compLibs;
		
		// Verify and log a message if a saved component library no longer exists. 
		verifySavedLibAvailability();
	}
	*/
	public JSFLibraryConfigDialogSettingData(boolean implLibDeployFlag, String[] compLibs) {
		this.jsfLibReg = JSFLibraryRegistryUtil.getInstance();
		this.dftImplLibDeployFlag = implLibDeployFlag;
		this.savedCompLibs = compLibs;
		
		// Verify and log a message if a saved component library no longer exists. 
		verifySavedLibAvailability();
	}	
	
	/**
	 * There is no saved JSFImplLibrary per se if initializing from DialogSettings 
	 * since default implementation library is always selected and only the 
	 * deployment flag is saved.  
	 * 
	 * A null is returned when there is no default 
	 * implementation library in registry.
	 *     
	 * @return selJSFLibImpl JSFLibraryReference return default implementation library with updated deployment flag 
	 */
	public JSFLibraryReference getJSFImplementationLibrary() {
		if (selJSFLibImpl == null) {
			// To instanciate a JSFLibraryReference object from default impl lib as the saved library.  
			JSFLibraryReference dftImplLib = jsfLibReg.getDefaultJSFImplementationLibrary(); 		
			if (dftImplLib != null) {
				selJSFLibImpl = new JSFLibraryReference(dftImplLib.getLibrary(), 
						true,	// selected 
						dftImplLibDeployFlag);
			}
		}
		return selJSFLibImpl;
	}
	
	/**
	 * Return the list of saved component libraries and their deployment settings.
	 * 
	 * @return selJSFLibComp List 
	 */
	public List getJSFComponentLibraries() {
		if (selJSFLibComp == null) {
			selJSFLibComp = new ArrayList();		
			
			if (savedCompLibs != null && savedCompLibs.length > 0) {
				JSFLibraryReference lib = null;
				String item;
				String[] attributes;
				String id;
				boolean deploy = false;
				
				for (int i = 0; i < savedCompLibs.length; i++) {
					item = savedCompLibs[i];
					attributes = item.split(SEPARATOR);
					
					id = attributes[0];				
					deploy = Boolean.valueOf(attributes[1]).booleanValue();
					
					lib = jsfLibReg.getJSFLibraryReferencebyID(id);
					if (lib != null) {
						selJSFLibComp.add(new JSFLibraryReference(lib.getLibrary(), true, deploy));
					} /*else {
						// already logged if a saved component library is no longer available.
					}*/
				}
			}
		}
		return selJSFLibComp;
	}

	/**
	 * Only need to verify component library availability from sticky settings.
	 */
 	private void verifySavedLibAvailability() {
		if (savedCompLibs != null && savedCompLibs.length > 0) {
			String item = null;
			String[] attributes;

			for (int i = 0; i < savedCompLibs.length; i++) {
				item = savedCompLibs[i];
				attributes = item.split(SEPARATOR);
													
				if (jsfLibReg.getJSFLibraryReferencebyID(attributes[0]) == null) {
					JSFCorePlugin.log(IStatus.INFO, Messages.JSFLibCfgDialogSettingData_Sticky_Component_Lib_Not_Exist);
				}
			}  				
		}	
 	}
	
}

Back to the top