Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vnetpublishing.clojure.osgi.namespaces;
- import java.lang.reflect.Field;
- import java.lang.reflect.Modifier;
- import java.util.concurrent.ConcurrentHashMap;
- import clojure.lang.Namespace;
- import clojure.lang.Symbol;
- public class ClojureNamespacesFactory {
- public static ConcurrentHashMap<Symbol, Namespace> createNamespaces() {
- return new ConcurrentHashMap<Symbol, Namespace>();
- }
- public static void registerNamespaces( ConcurrentHashMap<Symbol, Namespace> ns) {
- Field namespaces;
- try {
- namespaces = Namespace.class.getDeclaredField("namespaces");
- namespaces.setAccessible(true);
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(namespaces, namespaces.getModifiers() & ~Modifier.FINAL);
- namespaces.set(null, ns);
- } catch (NoSuchFieldException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement