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

📄 corbafacility.java

📁 UCS (Ultra Corba Simulator) is one more powerful corba client/servant simulator tool than other simi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.corba.mnq.tool;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.TypeCode;
import org.omg.DynamicAny.DynAnyFactory;
import org.omg.DynamicAny.DynAnyFactoryHelper;
import org.omg.DynamicAny.DynArray;
import org.omg.DynamicAny.DynEnum;
import org.omg.DynamicAny.DynSequence;
import org.omg.DynamicAny.DynStruct;
import org.omg.DynamicAny.DynUnion;
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;

import com.corba.mnq.tool.idl.IdlExcept;

/**
 * This utility class helps working with a Corba Any in an 3GPP environment.
 * Especially, it contains a method to convert the contents of an Any to a
 * String which can be used for tracing.
 * 
 * @author Christan Spreuer (demf1372)
 */
public final class CorbaFacility {

	/** used for java.util.logging */
	private static final Logger LOG = Logger.getLogger(CorbaFacility.class
			.getName());

	public static DynAnyFactory factory;

	public static ORB orb = null;

	static {
		try {
			orb = org.omg.CORBA.ORB.init(new String[0], null);
			factory = DynAnyFactoryHelper.narrow(orb
					.resolve_initial_references("DynAnyFactory"));
		} catch (Exception e) {
			LOG.log(Level.SEVERE, e.getMessage(), e);
		}
	}

	/**
	 * Returns the logger object for use by
	 * {@link com.siemens.icm.nm.fw.tracing.FFLoggable FFLoggable}.
	 * 
	 * @return the logger to use
	 */
	public Logger getLogger() {
		return LOG;
	}

	private CorbaFacility() {
		// private constructor to prevent creating any objects.
	}

	/**
	 * @param a
	 *            Any type
	 * @param includeId
	 *            a boolean value, indicate whether results should include id
	 *            content.
	 * @return String
	 */
	private static String printAny(Any a, boolean includedId) {
		String ret = "";

		try {
			TypeCode tc = a.type();
			while (tc.kind() == TCKind.tk_alias) {
				tc = tc.content_type();
			}

			switch (tc.kind().value()) {
			case TCKind._tk_null:
				ret = ret + "null";
				break;
			case TCKind._tk_void:
				ret = ret + "void";
				break;
			// short type
			case TCKind._tk_short:
				ret = printShort(a, ret, includedId);
				break;
			// long type
			case TCKind._tk_long:
				ret = printLong(a, ret, includedId);
				break;
			// unsigned short type
			case TCKind._tk_ushort:
				ret = printUShort(a, ret, includedId);
				break;
			// unsigned long type
			case TCKind._tk_ulong:
				ret = printULong(a, ret, includedId);
				break;
			// float type
			case TCKind._tk_float:
				ret = printFloat(a, ret, includedId);
				break;
			// double type
			case TCKind._tk_double:
				ret = printDouble(a, ret, includedId);
				break;
			// boolean type
			case TCKind._tk_boolean:
				ret = printBoolean(a, ret, includedId);
				break;
			// char type
			case TCKind._tk_char:
				ret = printChar(a, ret, includedId);
				break;
			// octet type
			case TCKind._tk_octet:
				ret = printOctet(a, ret, includedId);
				break;
			// any type
			case TCKind._tk_any:
				ret = ret + printAny(a.extract_any(), includedId);
				break;
			// typecode type
			case TCKind._tk_TypeCode:
				ret = printTypeCode(a, ret, includedId);
				break;
			// principal type
			case TCKind._tk_Principal:
				ret = printPrincipal(a, ret, includedId);
				break;
			// objref type
			case TCKind._tk_objref:
				ret = printObjref(a, ret, includedId);
				break;
			// struct type
			case TCKind._tk_struct:
				ret = printStruct(a, ret, includedId);
				break;
			// union type
			case TCKind._tk_union:
				ret = printUnion(a, ret, includedId);
				break;
			// enum type
			case TCKind._tk_enum:
				ret = printEnum(a, ret, includedId);
				break;
			// string type
			case TCKind._tk_string:
				ret = printString(a, ret, includedId);
				break;
			// sequence type
			case TCKind._tk_sequence:
				ret = printSequence(a, ret, includedId);
				break;
			// array type
			case TCKind._tk_array:
				ret = printArray(a, ret, includedId);
				break;
			// alias type
			case TCKind._tk_alias:
				ret = ret + "alias";
				break;
			// except type
			case TCKind._tk_except:
				ret = printException(a, ret, includedId);
				break;
			// long long type
			case TCKind._tk_longlong:
				ret = printLonglong(a, ret, includedId);
				break;
			// unsigned long long type
			case TCKind._tk_ulonglong:
				ret = printUlonglong(a, ret, includedId);
				break;
			// long double type
			case TCKind._tk_longdouble:
				ret = printLongdouble(a, ret, includedId);
				break;
			// wchar type
			case TCKind._tk_wchar:
				ret = printWchar(a, ret, includedId);
				break;
			// wstring type
			case TCKind._tk_wstring:
				ret = printWstring(a, ret, includedId);
				break;
			// fixed type
			case TCKind._tk_fixed:
				ret = printFixed(a, ret, includedId);
				break;
			case TCKind._tk_value:
				ret = printValue(a, ret, includedId);
				break;
			case TCKind._tk_value_box:
				ret = ret + "value_box";
				break;
			case TCKind._tk_native:
				ret = ret + "native";
				break;
			case TCKind._tk_abstract_interface:
				ret = ret + "abstract_interface";
				break;
			default:
				// ret=ret+"Unknown, kind " + a.type().kind().value();
				ret += "<null,kind=" + a.type().kind().value() + ">";
			}
			// ret=ret+"\n";
			return ret;
		} catch (Exception e) {
			LOG.log(Level.SEVERE, e.getMessage(), e);
			return ret;
		}
	}

	/**
	 * @param a
	 *            Any type
	 * @return String
	 */
	private static String printValueAny(Any a) {
		return printAny(a, false);
	}

	/**
	 * Dummy (as no objects of this class exists), added to suppress JLint
	 * warnings as there are other toString()-methods.
	 * 
	 * @return nothing special.
	 */
	public String toString() {
		return super.toString();
	}

	/**
	 * Converts the contents of the Any to a String which can be used for
	 * tracing.
	 * 
	 * @param any
	 *            the Any.
	 * @param verbose
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	public static String toString(Any any, boolean verbose) {
		return printAny(any, verbose);
	}

	/**
	 * Converts the contents of the Any to a String which only include the value
	 * content.
	 * 
	 * @param any
	 *            the Any.
	 * @return a String that describes the Any.
	 */
	public static String toValueString(Any any) {
		return printValueAny(any);
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printShort(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Short: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_short();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printLong(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Long: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_long();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printUShort(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "UShort: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_ushort();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printULong(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "ULong: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_ulong();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printFloat(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Float: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_float();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printDouble(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Double: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_double();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printBoolean(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Boolean: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_boolean();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printChar(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Char: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_char();
	}

	/**
	 * @param a
	 *            Any type
	 * @param ret
	 *            string which the results should be appended to.
	 * @param includedId
	 *            if true, then included id information if false, then ignor id
	 *            information
	 * @return a String that describes the Any.
	 */
	private static String printOctet(Any a, String ret, boolean includedId) {
		String id;
		if (includedId) {
			try {
				id = a.type().id() + ": ";
			} catch (Throwable e) {
				id = "Octet: ";
			}
		} else {
			id = "";
		}
		return ret + id + a.create_input_stream().read_octet();
	}

⌨️ 快捷键说明

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