Package org.openntf.domino.xsp.helpers

Source Code of org.openntf.domino.xsp.helpers.ServerBean

/**
*
*/
package org.openntf.domino.xsp.helpers;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

import com.ibm.designer.runtime.domino.adapter.HttpService;
import com.ibm.designer.runtime.domino.adapter.LCDEnvironment;
import com.ibm.domino.xsp.module.nsf.NSFComponentModule;
import com.ibm.domino.xsp.module.nsf.NSFService;

/**
* @author Nathan T. Freeman
*
*         Server-scope map
*/
public final class ServerBean extends ConcurrentHashMap<String, Object> {
  private static final long serialVersionUID = 1L;
  private static final Logger log_ = Logger.getLogger(ServerBean.class.getName());
  private final static ServerBean instance_ = new ServerBean();

  /**
   * Constructor
   */
  private ServerBean() {

  }

  /**
   * Method to get the currently-loaded instance
   *
   * @return ServerBean
   * @since org.openntf.domino.xsp 4.5.0
   */
  public static ServerBean getCurrentInstance() {
    return instance_;
  }

  public void cacheObject(final String key, final String filepath, final String className) {
    try {
      final ServerBean thisBean = this;
      AccessController.doPrivileged(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
          NSFService nsfservice = null;
          for (HttpService service : LCDEnvironment.getInstance().getServices()) {
            if (service instanceof NSFService) {
              nsfservice = (NSFService) service;
              break;
            }
          }
          if (nsfservice != null) {
            try {
              NSFComponentModule forcedMod = nsfservice.loadModule(filepath);
              Class<?> klazz = forcedMod.getModuleClassLoader().loadClass(className);
              Object cacheMeIfYouCan = klazz.newInstance();
              thisBean.put(key, cacheMeIfYouCan);
            } catch (Throwable t) {
              t.printStackTrace();
            }
          }
          return null;
        }
      });
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

}
TOP

Related Classes of org.openntf.domino.xsp.helpers.ServerBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.