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
16 public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor) throws PluginParseException
17 {
18 throw new UnsupportedOperationException(" create Module not supported by LegacyModuleFactory. Use PrefixDelegatingModuleFactory instead.");
19 }
20
21 public <T> Class<T> getModuleClass(String name, ModuleDescriptor<T> moduleDescriptor) throws ModuleClassNotFoundException {
22
23 try
24 {
25
26 @SuppressWarnings ("unchecked")
27 final Class<T> loadedClass = (Class<T>) moduleDescriptor.getPlugin().loadClass(name, null);
28
29
30 try
31 {
32 final Constructor<T> noargConstructor = loadedClass.getConstructor(new Class[] { });
33 if (noargConstructor != null)
34 {
35 loadedClass.newInstance();
36 }
37 }
38 catch (final NoSuchMethodException e)
39 {
40
41 }
42 return loadedClass;
43 }
44 catch (final ClassNotFoundException e)
45 {
46 throw new PluginParseException("Could not load class: " + name, e);
47 }
48 catch (final NoClassDefFoundError e)
49 {
50 throw new PluginParseException("Error retrieving dependency of class: " + name + ". Missing class: " + e.getMessage(), e);
51 }
52 catch (final UnsupportedClassVersionError e)
53 {
54 throw new PluginParseException("Class version is incompatible with current JVM: " + name, e);
55 }
56 catch (final Throwable t)
57 {
58 throw new PluginParseException(t);
59 }
60 }
61 }