Skip to main content
summaryrefslogtreecommitdiffstats
blob: 66e94cd0bfff26ca5632bb595415bcf35d194104 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*******************************************************************************
 * Copyright (c) 2010 IBM 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:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20100413   307552 ericdp@ca.ibm.com - Eric D. Peters, JAX-RS and Java EE 6 setup is incorrect
 *******************************************************************************/
package org.eclipse.jst.ws.jaxrs.core.internal.jaxrslibraryproviderconfig;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jst.ws.jaxrs.core.internal.JAXRSCorePlugin;
import org.eclipse.jst.ws.jaxrs.core.internal.Messages;
import org.eclipse.jst.ws.jaxrs.core.internal.project.facet.IJAXRSFacetInstallDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;

/**
 * A singleton maintains lists of Library Providers
 * 
 */
public class JAXRSLibraryProviderUtil {
	private static JAXRSLibraryProviderUtil instance = null;

	private static List<JAXRSLibraryProvider> libraryProviders = new Vector<JAXRSLibraryProvider>();

	private static final String JAXRS_LIBRARY_PROVIDER_EXT_PT = "jaxrsLibraryProvider"; 


	/**
	 * Private constructor
	 */
	private JAXRSLibraryProviderUtil() {
		// nothing to do
	}
	
	public static boolean isUpdateDDCheckBoxSelectedByDefault(String libraryID) {
		if (libraryID == null)
			return false;

		JAXRSLibraryProviderUtil.getInstance();
		java.util.List<JAXRSLibraryProvider> libraryProviders = getLibraryProviders();

		Iterator<JAXRSLibraryProvider> libraryProvidersIterator = libraryProviders
				.iterator();
		while (libraryProvidersIterator.hasNext()) {
			JAXRSLibraryProvider thisLibraryProvider = libraryProvidersIterator
					.next();
			if (libraryID.equals(thisLibraryProvider.getLibraryProviderID())) {
				return thisLibraryProvider.getUpdateDDCheckBoxSelected();
			}

		}

		return false;
	}

	public static boolean isUpdateDDCheckBoxSupportAvailable(String libraryID) {
		if (libraryID == null || libraryID.length() == 0)
			return false;

		JAXRSLibraryProviderUtil.getInstance();
		java.util.List<JAXRSLibraryProvider> libraryProviders = getLibraryProviders();

		Iterator<JAXRSLibraryProvider> libraryProvidersIterator = libraryProviders
				.iterator();
		while (libraryProvidersIterator.hasNext()) {
			JAXRSLibraryProvider thisLibraryProvider = libraryProvidersIterator
					.next();
			if (libraryID.equals(thisLibraryProvider.getLibraryProviderID())) {
				if (thisLibraryProvider.getShowUpdateDDCheckBox()) {
					return true;
				}
			}

		}

		return false;
	}
	
	public static String getServletClassName(String libraryID) {
		String toReturn = "";
		if (libraryID == null || libraryID.length() == 0)
			return toReturn;

		JAXRSLibraryProviderUtil.getInstance();
		java.util.List<JAXRSLibraryProvider> libraryProviders = getLibraryProviders();

		Iterator<JAXRSLibraryProvider> libraryProvidersIterator = libraryProviders
				.iterator();
		while (libraryProvidersIterator.hasNext()) {
			JAXRSLibraryProvider thisLibraryProvider = libraryProvidersIterator
					.next();
			if (libraryID.equals(thisLibraryProvider.getLibraryProviderID())) {
					return thisLibraryProvider.getServletClassName() != null ? thisLibraryProvider.getServletClassName() : toReturn;
			}

		}

		return toReturn;
	}

	/**
	 * Return the singleton instance of JAXRSLibraryProviderUtil.
	 * 
	 * @return JAXRSLibraryProviderUtil
	 */
	public synchronized static JAXRSLibraryProviderUtil getInstance() {
		if (instance == null) {
			instance = new JAXRSLibraryProviderUtil();
			instance.loadLibraryProvidersExtensions();
		}
		return instance;
	}

	/**
	 * Creates jax-rs library provider items from extension points.
	 */
	private void loadLibraryProvidersExtensions() {
		try {
			IExtensionPoint point = Platform.getExtensionRegistry()
					.getExtensionPoint(JAXRSCorePlugin.PLUGIN_ID, JAXRS_LIBRARY_PROVIDER_EXT_PT);
			IExtension[] extensions = point.getExtensions();
			for (int i = 0; i < extensions.length; i++) {
				IExtension ext = extensions[i];
				for (int j = 0; j < ext.getConfigurationElements().length; j++) {
					JAXRSLibraryProviderCreationHelper newLibCreator = new JAXRSLibraryProviderCreationHelper(
							ext.getConfigurationElements()[j]);
					JAXRSLibraryProvider newLibraryProvider = newLibCreator.create();

					if (newLibraryProvider != null) 
						libraryProviders.add(newLibraryProvider);
				}
			}
		} catch (InvalidRegistryObjectException e) {
			JAXRSCorePlugin.log(IStatus.ERROR,
					Messages.JAXRSLibraryProvider_ErrorLoadingFromExtPt, e);
		}
	}

	public static List<JAXRSLibraryProvider> getLibraryProviders() {
		return libraryProviders;
	}

}

Back to the top