1 package com.atlassian.plugin.module;
2
3 import com.atlassian.plugin.ModuleDescriptor;
4 import com.atlassian.plugin.PluginParseException;
5
6 import java.lang.reflect.Constructor;
7
8
9
10
11
12
13 public class LegacyModuleFactory implements ModuleFactory {
14
15 public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor) throws PluginParseException {
16 throw new UnsupportedOperationException(" create Module not supported by LegacyModuleFactory. Use PrefixDelegatingModuleFactory instead.");
17 }
18
19 public <T> Class<T> getModuleClass(String name, ModuleDescriptor<T> moduleDescriptor) throws ModuleClassNotFoundException {
20
21 try {
22
23 @SuppressWarnings("unchecked")
24 final Class<T> loadedClass = moduleDescriptor.getPlugin().loadClass(name, null);
25
26
27 try {
28 final Constructor<T> noargConstructor = loadedClass.getConstructor();
29 if (noargConstructor != null) {
30 noargConstructor.newInstance();
31 }
32 } catch (final NoSuchMethodException e) {
33
34 }
35 return loadedClass;
36 } catch (final ClassNotFoundException e) {
37 throw new PluginParseException("Could not load class: " + name, e);
38 } catch (final NoClassDefFoundError e) {
39 throw new PluginParseException("Error retrieving dependency of class: " + name + ". Missing class: " + e.getMessage(), e);
40 } catch (final UnsupportedClassVersionError e) {
41 throw new PluginParseException("Class version is incompatible with current JVM: " + name, e);
42 } catch (final Throwable t) {
43 throw new PluginParseException(t);
44 }
45 }
46 }