?? soapconveror.java
字號:
// ----------------------------------------------------------------------------
// $Source: /cvs/vas2006/webpro2/webpro_java/src/com/onewaveinc/portalman/webpro/soap/SOAPConveror.java,v $
// ----------------------------------------------------------------------------
// Copyright (c) 2002 by Onewave Inc.
// ----------------------------------------------------------------------------
// $Id: SOAPConveror.java,v 1.1.1.1 2006/08/01 05:49:34 zhengx Exp $
// ----------------------------------------------------------------------------
// $Log: SOAPConveror.java,v $
// Revision 1.1.1.1 2006/08/01 05:49:34 zhengx
// no message
//
// Revision 1.1 2006/06/02 03:33:17 wuyan
// *** empty log message ***
//
// Revision 1.1 2005/12/08 10:37:59 like
// no message
//
// Revision 1.1 2003/07/28 06:30:15 zengc
// no message
//
// ----------------------------------------------------------------------------
package com.onewaveinc.portalman.webpro.soap;
/**
* <p>Title: PortalMAN SDK API Documentation</p>
* <p>Description: OneWave Technologies., Inc. PortalMAN Value-add Management Platform 3rd Software Development Kit</p>
* <p>Copyright: Copyright (c) 2002 </p>
* <p>Company: OneWave Technologies., Inc.</p>
* @author 3rd AAA & ICP Integration Developement Team
* @version 1.5
*/
import java.lang.reflect.*;
import java.text.*;
public class SOAPConveror {
public static Object getEncodeEntity(Object entity,String returnObject){
Method[] in_methods, out_methods;
Field[] in_fields, out_fields;
Object outObj = null;
try{
in_methods = getAllMethods(entity.getClass());
in_fields = getAllFields(entity.getClass());
outObj = Class.forName(returnObject).newInstance();
out_methods = getAllMethods(outObj.getClass());
out_fields = getAllFields(outObj.getClass());
for (int i = 0; i < out_fields.length;i++){
try {
Method setMethod = getMethod("set",out_fields[i],out_methods);
Method getMethod = getMethod("get",out_fields[i],in_methods);
if(getMethod != null & setMethod != null){
Object getResult = getMethod.invoke(entity,null);
if (getResult != null){
String setResult = encode(getResult);
Object[] args = new Object[]{setResult};
//System.out.println("==============" + setMethod.getName() + setResult);
setMethod.invoke(outObj,args);
//System.out.println("==============" + setMethod.getName());
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}catch(Exception e){
e.printStackTrace();
}
return outObj;
}
private static Method getMethod(String methodPerfix,Field aField,Method[] methods) throws Exception {
Method objGetMethod=null;
String fieldName = Character.toUpperCase(aField.getName().charAt(0))
+aField.getName().substring(1);
String getMethodName = methodPerfix + fieldName;
for(int j=0; j<methods.length; j++){
if(methods[j].getName().equalsIgnoreCase(getMethodName)){
return methods[j];
}
}
return objGetMethod;
}
private static String encode(Object obj){
if(obj instanceof java.util.Date){
java.util.Date value = (java.util.Date) obj;
return valueOf(value);
}
return obj.toString();
}
public static String valueOf(boolean value){
return (new Boolean(value)).toString();
}
public static String valueOf(String value){
return value;
}
public static String valueOf(double value){
return Double.toString(value);
}
public static String valueOf(int value){
return Integer.toString(value);
}
public static String valueOf(long value){
return Long.toString(value);
}
public static String valueOf(float value){
return Float.toString(value);
}
public static String valueOf(short value){
return Short.toString(value);
}
public static String valueOf(java.util.Date value){
if(value == null){
return null;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
return dateFormat.format(value);
}
private static String get2byteString(int in){
String a = "00" + in;
return a.substring(a.length()-2,a.length());
}
public static Object getDecodeEntity(Object entity,String returnObject){
Method[] in_methods, out_methods;
Field[] in_fields, out_fields;
Object outObj = null;
try{
in_methods = getAllMethods(entity.getClass());
in_fields = getAllFields(entity.getClass());
outObj = Class.forName(returnObject).newInstance();
out_methods = getAllMethods(outObj.getClass());
out_fields = getAllFields(outObj.getClass());
for (int i = 0; i < out_fields.length;i++){
try {
Method setMethod = getMethod("set",out_fields[i],out_methods);
Method getMethod = getMethod("get",out_fields[i],in_methods);
if(getMethod != null & setMethod != null){
Class para = setMethod.getParameterTypes()[0];
String getResult = (String) getMethod.invoke(entity,null);
if (getResult != null){
Object setResult = decode(getResult,para);
Object[] args = new Object[]{setResult};
//System.out.println("==============" + setMethod.getName() + setResult + para.getName());
setMethod.invoke(outObj,args);
//System.out.println("==============" + setMethod.getName() + setResult);
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}catch(Exception e){
e.printStackTrace();
}
return outObj;
}
private static Object decode(String in,Class para){
Object result = null;
if (in == null){
return null;
}
try {
if(para.equals(boolean.class)){
return Boolean.valueOf(in);
}else if(para.equals(double.class)){
return Double.valueOf(in);
}else if(para.equals(int.class)){
return Integer.valueOf(in);
}else if(para.equals(long.class)){
return Long.valueOf(in);
}else if(para.equals(float.class)){
return Float.valueOf(in);
}else if(para.equals(short.class)){
return Short.valueOf(in);
}else if(para.equals(String.class)){
return in;
}else if(para.equals(java.util.Date.class)){
return getDate(in);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
public static String getString(String value){
return value;
}
public static boolean getBoolean(String value){
return Boolean.valueOf(value).booleanValue();
}
public static int getInt(String value) throws Exception{
return Integer.parseInt(value);
}
public static long getLong(String value) throws Exception{
return Long.parseLong(value);
}
public static short getShort(String value) throws Exception{
return Short.parseShort(value);
}
public static float getFloat(String value) throws Exception{
return Float.parseFloat(value);
}
public static double getDouble(String value) throws Exception{
return Double.parseDouble(value);
}
public static java.util.Date getDate(String value) throws Exception{
if(value!=null && value.length() == 14){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
return dateFormat.parse(value);
}
return null;
}
private static Method[] getAllMethods(Class myClass){
return com.onewaveinc.portalman.webpro.security.SecurityMgr.getMethods(myClass);
}
private static Field[] getAllFields(Class myClass){
return com.onewaveinc.portalman.webpro.security.SecurityMgr.getFields(myClass);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -