All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.core.platform.PlatformClassLoader Maven / Gradle / Ivy

package org.snapscript.core.platform;

import java.lang.reflect.Constructor;
import java.util.concurrent.atomic.AtomicReference;

import org.snapscript.core.Any;
import org.snapscript.core.ContextClassLoader;
import org.snapscript.core.convert.proxy.ProxyWrapper;
import org.snapscript.core.function.index.FunctionIndexer;

public class PlatformClassLoader {
   
   private final AtomicReference reference;
   private final PlatformNameBuilder builder;
   private final ClassLoader loader;
   
   public PlatformClassLoader() {
      this.reference = new AtomicReference();
      this.loader = new ContextClassLoader(Any.class);
      this.builder = new PlatformNameBuilder();
   }

   public Constructor loadConstructor(){
      Constructor constructor = reference.get();
      
      if(constructor == null) {
         try {
            PlatformType platform = PlatformType.resolveType();
            String type = builder.createFullName(platform);
            Class value = loader.loadClass(type);
            
            constructor = value.getDeclaredConstructor(FunctionIndexer.class, ProxyWrapper.class);
            reference.set(constructor);
         }catch(Exception e) {
            throw new IllegalStateException("Could not load constructor", e);
         }
      }
      return constructor;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy