Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package com.vnetpublishing.clojure.osgi.namespaces;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.lang.reflect.Modifier;
  5. import java.util.concurrent.ConcurrentHashMap;
  6.  
  7. import clojure.lang.Namespace;
  8. import clojure.lang.Symbol;
  9.  
  10. public class ClojureNamespacesFactory {
  11.     public static ConcurrentHashMap<Symbol, Namespace> createNamespaces() {
  12.          return new ConcurrentHashMap<Symbol, Namespace>();
  13.     }
  14.    
  15.     public static void registerNamespaces( ConcurrentHashMap<Symbol, Namespace> ns)  {
  16.         Field namespaces;
  17.         try {
  18.             namespaces = Namespace.class.getDeclaredField("namespaces");
  19.             namespaces.setAccessible(true);
  20.            
  21.  
  22.             Field modifiersField = Field.class.getDeclaredField("modifiers");
  23.             modifiersField.setAccessible(true);
  24.             modifiersField.setInt(namespaces, namespaces.getModifiers() & ~Modifier.FINAL);
  25.            
  26.            
  27.            
  28.             namespaces.set(null, ns);
  29.         } catch (NoSuchFieldException e) {
  30.             // TODO Auto-generated catch block
  31.             e.printStackTrace();
  32.         } catch (SecurityException e) {
  33.             // TODO Auto-generated catch block
  34.             e.printStackTrace();
  35.         } catch (IllegalArgumentException e) {
  36.             // TODO Auto-generated catch block
  37.             e.printStackTrace();
  38.         } catch (IllegalAccessException e) {
  39.             // TODO Auto-generated catch block
  40.             e.printStackTrace();
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement