Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8f371e5096f43a9d27fa2ec45949c60f49200304 (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
/*******************************************************************************
 * Copyright (c) 2001, 2007 Oracle Corporation and others.
 * 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 Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.core.jsflibraryconfiguration.internal;

import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants;
import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil;
import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.PluginProvidedJSFLibrary;
import org.eclipse.jst.jsf.core.jsflibraryconfiguration.JSFLibraryConfigurationHelper;
import org.eclipse.jst.jsf.core.jsflibraryconfiguration.JSFLibraryReference;
import org.eclipse.jst.jsf.core.jsflibraryconfiguration.JSFLibraryReferenceServerSupplied;

/**
 * Factory for producing facade objects for references to the internal EMF JSF Library classes
 */
public class JSFLibraryReferenceFacadeFactory {
	/**
	 * Returns a JSFLibraryReferenceUserDefined or JSFLibraryReferencePluginProvided instance.
	 * Will not create a JSFLibraryReferenceServerSupplied as there is no cp entry.   Use createServerSuppliedJSFLibRef instead.
	 * @param cpEntry
	 * @return an instance of JSFLibraryInternalReference.  Null will be returned if the cpEntry is not a 
	 */
	public static JSFLibraryReference create(final IClasspathEntry cpEntry) {
		if (JSFLibraryConfigurationHelper.isJSFLibraryContainer(cpEntry)){
			return createReference(cpEntry);
		}
		return null;
	}

	/**
	 * @return instance of {@link JSFLibraryReferenceServerSupplied}
	 */
	public static JSFLibraryReferenceServerSupplied createServerSuppliedJSFLibRef(){
		return new JSFLibraryReferenceServerSuppliedImpl();
	}


	/**
	 * @param cpEntry
	 * @return {@link JSFLibraryReference}
	 */
	private static JSFLibraryReference createReference(
			final IClasspathEntry cpEntry) {
		
		String libID = cpEntry.getPath().segment(1).toString();
		org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryInternalReference libRef = JSFLibraryRegistryUtil.getInstance().getJSFLibraryReferencebyID(libID);
		if (libRef!= null){
			boolean isDeployed = getJ2EEModuleDependency(cpEntry);
			if (libRef.getLibrary() != null && libRef.getLibrary() instanceof PluginProvidedJSFLibrary)
				return new JSFLibraryReferencePluginProvidedImpl(libRef, isDeployed);
			
			return new JSFLibraryReferenceUserDefinedImpl(libRef, isDeployed);
		}
		return null;
	}

	private static boolean getJ2EEModuleDependency(IClasspathEntry cpEntry) {
		IClasspathAttribute[] attrs = cpEntry.getExtraAttributes();
		for (int i=0;i<attrs.length;i++){
			IClasspathAttribute attr = attrs[i];
			if (attr.getName().equals(IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY)){
				return true;
			}
		}
		return false;
	}
}

Back to the top