Skip to content

Package: HandlerHelperUtil

HandlerHelperUtil

nameinstructionbranchcomplexitylinemethod
loadClass(String, String)
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.internal.ui.util;
15:
16: import org.eclipse.core.runtime.Platform;
17: import org.osgi.framework.Bundle;
18:
19: /**
20: * Utility methods for helpers which shall not be exposed as API.
21: *
22: * @author jfaltermeier
23: *
24: */
25: public final class HandlerHelperUtil {
26:
27:         private HandlerHelperUtil() {
28:                 // util
29:         }
30:
31:         /**
32:          * Loads the specified class from the given bundle.
33:          *
34:          * @param bundleName the bundle name
35:          * @param clazz the class name
36:          * @return the loaded class
37:          * @throws ClassNotFoundException in case the class could not be loaded
38:          *
39:          * @param <T> the type of the class to load
40:          */
41:         @SuppressWarnings("unchecked")
42:         public static <T> Class<T> loadClass(String bundleName, String clazz) throws ClassNotFoundException {
43:                 final Bundle bundle = Platform.getBundle(bundleName);
44:•                if (bundle == null) {
45:                         // TODO externalize strings
46:                         throw new ClassNotFoundException(clazz + " cannot be loaded because bundle " + bundleName //$NON-NLS-1$
47:                                 + " cannot be resolved"); //$NON-NLS-1$
48:                 }
49:                 return (Class<T>) bundle.loadClass(clazz);
50:
51:         }
52:
53: }