HExEBTestUtil

 

/**
 * $Id$
 * $Revision$
 * $Date$
 *****************************************************************************
 * Copyright 2006 Hong Kong Air Cargo Terminals Ltd. All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Hong Kong Air Cargo Terminals Ltd. ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Hactl.
 *****************************************************************************
 * Revision History
 *****************************************************************************
 * Date              Author          Description
 * Nov 2, 2006 Roman Lee       Initial version
 *****************************************************************************
 
*/

package  com.hacis.hex.eb.test.util;

import  java.lang.reflect.InvocationTargetException;
import  java.lang.reflect.Method;

import  javax.ejb.EJBHome;

import  com.hactl.framework.controller.ServiceLocator;
import  com.hactl.framework.exception.HException;
import  com.hactl.framework.exception.HObjectNotFoundException;
import  com.hactl.framework.exception.HRemoteCallException;

public   class  HExEBTestUtil  {
    
public EJBHome setEjbHome(String jndiName) throws HException {
        
try{
            ServiceLocator service 
= ServiceLocator.getInstance();
            EJBHome ejbHome 
= service.getEJBEntity(jndiName);
            
return ejbHome;
        }

        
catch (javax.naming.NamingException e) {
            
throw new HObjectNotFoundException(e);
        }

        
catch (java.rmi.RemoteException e) {
            
throw new HRemoteCallException(e);
        }
 
        
catch ( Exception e ) {
            
throw new HException(e);
        }

    }


    
public String toString(Object stu) throws Exception {
        System.out.println(
"start");
        java.lang.reflect.Field[] fields 
= null
        StringBuffer strBuffer 
= new StringBuffer();
        String fieldName;
        String newFieldName;
        
int j = 1;
        
try {
            fields 
= (Class.forName(stu.getClass().getName()).getDeclaredFields());
            
for (int i = 0; i < fields.length; i++{
                    strBuffer.append(fields[i].getName());
                    strBuffer.append(
" = ");
                    fieldName 
= fields[i].getName();
                    
char firstChar[] = {fieldName.charAt(0)};
                    String str 
= new String(firstChar);
                    String otherStr 
= fieldName.substring(1, fieldName.length());
                    newFieldName 
= "get" + str.toUpperCase() + otherStr;
                    Method met 
= stu.getClass().getMethod(newFieldName, new Class[0]);
                    String returnStr 
= met.invoke(stu, null).toString();
                    strBuffer.append(returnStr);
                    strBuffer.append(
" ");                
            }

        }
catch(NoSuchMethodException e){
            e.printStackTrace();
        }
catch (Exception e){
            e.printStackTrace();
            
throw e;
        }

        
return strBuffer.toString();
    }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值