128 } |
128 } |
129 } |
129 } |
130 } |
130 } |
131 |
131 |
132 /** |
132 /** |
|
133 * Wrapper class for java.lang.reflect.Module. To materialize a handle use the static factory |
|
134 * methods Module#getModule(Class<?>) or Module#getUnnamedModule(ClassLoader). |
|
135 */ |
|
136 public static class Module { |
|
137 |
|
138 private final Object theRealModule; |
|
139 |
|
140 private Module(Object module) { |
|
141 this.theRealModule = module; |
|
142 init(); |
|
143 } |
|
144 |
|
145 public static Module getModule(Class<?> clazz) { |
|
146 try { |
|
147 init(); |
|
148 Object result = getModuleMethod.invoke(clazz, new Object[0]); |
|
149 return new Module(result); |
|
150 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
|
151 | SecurityException ex) { |
|
152 throw new Abort(ex); |
|
153 } |
|
154 } |
|
155 |
|
156 public static Module getUnnamedModule(ClassLoader classLoader) { |
|
157 try { |
|
158 init(); |
|
159 Object result = getUnnamedModuleMethod.invoke(classLoader, new Object[0]); |
|
160 return new Module(result); |
|
161 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException |
|
162 | SecurityException ex) { |
|
163 throw new Abort(ex); |
|
164 } |
|
165 } |
|
166 |
|
167 public Module addExports(String pn, Module other) { |
|
168 try { |
|
169 addExportsMethod.invoke(theRealModule, new Object[] { pn, other.theRealModule}); |
|
170 } catch (IllegalAccessException | InvocationTargetException ex) { |
|
171 throw new Abort(ex); |
|
172 } |
|
173 return this; |
|
174 } |
|
175 |
|
176 public Module addUses(Class<?> st) { |
|
177 try { |
|
178 addUsesMethod.invoke(theRealModule, new Object[] { st }); |
|
179 } catch (IllegalAccessException | InvocationTargetException ex) { |
|
180 throw new Abort(ex); |
|
181 } |
|
182 return this; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------------------- |
|
186 // on java.lang.reflect.Module |
|
187 private static Method addExportsMethod = null; |
|
188 // on java.lang.reflect.Module |
|
189 private static Method addUsesMethod = null; |
|
190 // on java.lang.Class |
|
191 private static Method getModuleMethod; |
|
192 // on java.lang.ClassLoader |
|
193 private static Method getUnnamedModuleMethod; |
|
194 |
|
195 private static void init() { |
|
196 if (addExportsMethod == null) { |
|
197 try { |
|
198 Class<?> moduleClass = Class.forName("java.lang.reflect.Module", false, null); |
|
199 addUsesMethod = moduleClass.getDeclaredMethod("addUses", new Class<?>[] { Class.class }); |
|
200 addExportsMethod = moduleClass.getDeclaredMethod("addExports", |
|
201 new Class<?>[] { String.class, moduleClass }); |
|
202 getModuleMethod = Class.class.getDeclaredMethod("getModule", new Class<?>[0]); |
|
203 getUnnamedModuleMethod = ClassLoader.class.getDeclaredMethod("getUnnamedModule", new Class<?>[0]); |
|
204 } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { |
|
205 throw new Abort(ex); |
|
206 } |
|
207 } |
|
208 } |
|
209 } |
|
210 |
|
211 /** |
133 * Wrapper class for java.lang.module.Configuration. |
212 * Wrapper class for java.lang.module.Configuration. |
134 */ |
213 */ |
135 public static final class Configuration { |
214 public static final class Configuration { |
136 private final Object theRealConfiguration; |
215 private final Object theRealConfiguration; |
137 |
216 |