⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 props.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 JAVA
字号:
package com.wls8unleashed.jms;

import java.util.*;
import java.io.*;
import javax.naming.*;

/**
 * Properties file helper. Helps read values from
 * properties file easily.
 */
public class Props {
 
 // The build.properties file name used with the examples.
 private static String FILE_NAME = "build.properties";
 private static Properties props = null;
 
 /**
  * Get an instance of the build.properties file.
  */
 private static void getInstance(){
    props = new Properties();
    try{
      props.load(new FileInputStream(FILE_NAME));
    }
    catch(IOException e){
      System.out.println("PROBLEM FINDING FILE NAME "
                        + FILE_NAME + " ... EXITING ...");
      System.exit(1);
    }
 }
 
 /**
  * Return a property value given a name and create
  * properties file handle if doesn't already exist.
  */
 public static String get(String name){
   if(props == null){
      getInstance();
   }
   
   return (String) props.get(name);
 }
 
 /**
  * Construct a JNDI initial context from the
  * properties file info.
  */
 public static Context getInitialContext(){
    Context ctx = null;
  
    // Get properties for naming service
    String jndiFactory = Props.get("jndi.factory");
    String providerURL = Props.get("jndi.provider.url");
    
    // Create hashtable of JNDI properties
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory);
    env.put(Context.PROVIDER_URL, providerURL);
    
    // Return handle to JNDI context
    try{
      ctx = new InitialContext(env);
    }
    catch(Exception e){
      System.out.println("PROBLEM CREATING JNDI CONTEXT...EXITING...");
      System.exit(1);
    }
        
    return ctx;
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -