📄 ior.java
字号:
/* IOR.java -- Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.CORBA;import gnu.CORBA.CDR.BufferredCdrInput;import gnu.CORBA.CDR.BufferedCdrOutput;import gnu.CORBA.CDR.AbstractCdrInput;import gnu.CORBA.CDR.AbstractCdrOutput;import gnu.CORBA.GIOP.CharSets_OSF;import gnu.CORBA.GIOP.CodeSetServiceContext;import org.omg.CORBA.BAD_PARAM;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.ULongSeqHelper;import org.omg.IOP.TAG_INTERNET_IOP;import org.omg.IOP.TAG_MULTIPLE_COMPONENTS;import org.omg.IOP.TaggedComponent;import org.omg.IOP.TaggedComponentHelper;import org.omg.IOP.TaggedProfile;import org.omg.IOP.TaggedProfileHelper;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.zip.Adler32;/** * The implementaton of the Interoperable Object Reference (IOR). IOR can be * compared with the Internet address for a web page, it provides means to * locate the CORBA service on the web. IOR contains the host address, port * number, the object identifier (key) inside the server, the communication * protocol version, supported charsets and so on. * * Ths class provides method for encoding and decoding the IOR information * from/to the stringified references, usually returned by * {@link org.omg.CORBA.ORB#String object_to_string()}. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) * * @see org.mog.CORBA.Object.object_to_string(Object forObject) * @see string_to_object(String IOR) */public class IOR{ /** * The code sets tagged component, normally part of the Internet profile. This * compone consists of the two componenets itself. */ public static class CodeSets_profile { public CodeSets_profile() { int[] supported = CharSets_OSF.getSupportedCharSets(); narrow.native_set = CharSets_OSF.NATIVE_CHARACTER; narrow.conversion = supported; wide.native_set = CharSets_OSF.NATIVE_WIDE_CHARACTER; wide.conversion = supported; } /** * The code set component. */ public static class CodeSet_component { /** * The conversion code sets. */ public int[] conversion; /** * The native code set. */ public int native_set; /** * Read from the CDR stream. */ public void read(org.omg.CORBA.portable.InputStream in) { native_set = in.read_ulong(); conversion = ULongSeqHelper.read(in); } /** * Get a string representation. */ public String toString() { StringBuffer b = new StringBuffer(); b.append("native " + name(native_set)); if (conversion != null && conversion.length > 0) { b.append(" conversion "); for (int i = 0; i < conversion.length; i++) { b.append(name(conversion[i])); b.append(' '); } } b.append(' '); return b.toString(); } /** * Get a better formatted multiline string representation. */ public String toStringFormatted() { StringBuffer b = new StringBuffer(); b.append("\n Native set " + name(native_set)); if (conversion != null && conversion.length > 0) { b.append("\n Other supported sets:\n "); for (int i = 0; i < conversion.length; i++) { b.append(name(conversion[i])); b.append(' '); } } b.append("\n"); return b.toString(); } /** * Write into CDR stream. */ public void write(org.omg.CORBA.portable.OutputStream out) { out.write_long(native_set); ULongSeqHelper.write(out, conversion); } private String name(int set) { return "0x" + Integer.toHexString(set) + " (" + CharSets_OSF.getName(set) + ") "; } } /** * The agreed tag for the Codesets profile. */ public static final int TAG_CODE_SETS = 1; /** * Information about narrow character encoding (TCS-C). */ public CodeSet_component narrow = new CodeSet_component(); /** * About wide character encoding (TCS-W). */ public CodeSet_component wide = new CodeSet_component(); /** * The negotiated coding result for this IOR. Saves time, requred for * negotiation computations. */ public CodeSetServiceContext negotiated; /** * Read the code set profile information from the given input stream. * * @param profile a stream to read from. */ public void read(AbstractCdrInput profile) { BufferredCdrInput encapsulation = profile.read_encapsulation(); narrow.read(encapsulation); wide.read(encapsulation); } /** * Returns a string representation. */ public String toString() { return "Narrow char: " + narrow + ", Wide char: " + wide; } /** * Write the code set profile information into the given input stream. * * @param profile a stream to write into. */ public void write(AbstractCdrOutput profile) { AbstractCdrOutput encapsulation = profile.createEncapsulation(); narrow.write(encapsulation); wide.write(encapsulation); try { encapsulation.close(); } catch (IOException ex) { throw new InternalError(); } } } /** * The internet profile. */ public class Internet_profile { /** * The agreed tag for the Internet profile. */ public static final int TAG_INTERNET_IOP = 0; /** * The host. */ public String host; /** * The IIOP version (initialised to 1.2 by default). */ public Version version = new Version(1, 2); /** * The port. */ public int port; /** * The code sets component in the internet profile of this IOR. This is not * a separate profile. */ public CodeSets_profile CodeSets = new CodeSets_profile(); /** * Reserved for all components of this profile, this array holds the * components other than code set components. */ ArrayList components = new ArrayList(); /** * Return the human readable representation. */ public String toString() { StringBuffer b = new StringBuffer(); b.append(host); b.append(":"); b.append(port); b.append(" (v"); b.append(version); b.append(")"); if (components.size() > 0) b.append(" " + components.size() + " extra components."); return b.toString(); } /** * Write the internet profile (except the heading tag. */ public void write(AbstractCdrOutput out) { try { // Need to write the Internet profile into the separate // stream as we must know the size in advance. AbstractCdrOutput b = out.createEncapsulation(); version.write(b); b.write_string(host); b.write_ushort((short) (port & 0xFFFF)); // Write the object key. b.write_long(key.length); b.write(key); // Number of the tagged components. b.write_long(1 + components.size()); b.write_long(CodeSets_profile.TAG_CODE_SETS); CodeSets.write(b); TaggedComponent t; for (int i = 0; i < components.size(); i++) { t = (TaggedComponent) components.get(i); TaggedComponentHelper.write(b, t); } b.close(); } catch (Exception e) { MARSHAL m = new MARSHAL("Unable to write Internet profile."); m.minor = Minor.IOR; m.initCause(e); throw m; } } } /** * The standard minor code, indicating that the string to object converstio * has failed due non specific reasons. */ public static final int FAILED = 10; /** * The internet profile of this IOR. */ public Internet_profile Internet = new Internet_profile(); /** * The object repository Id. */ public String Id; /** * The object key. */ public byte[] key; /** * All tagged profiles of this IOR, except the separately defined Internet * profile. */ ArrayList profiles = new ArrayList(); /** * True if the profile was encoded using the Big Endian or the encoding is not * known. * * false if it was encoded using the Little Endian. */ public boolean Big_Endian = true; /** * Create an empty instance, initialising the code sets to default values. */ public IOR() { } /** * Parse the provided stringifed reference. * * @param stringified_reference, in the form of IOR:nnnnnn..... * * @return the parsed IOR * * @throws BAD_PARAM, minor code 10, if the IOR cannot be parsed. * * TODO corballoc and other alternative formats. */ public static IOR parse(String stringified_reference) throws BAD_PARAM { try { if (!stringified_reference.startsWith("IOR:")) throw new BAD_PARAM("The string refernce must start with IOR:", FAILED, CompletionStatus.COMPLETED_NO); IOR r = new IOR(); ByteArrayOutputStream buf = new ByteArrayOutputStream(); String x = stringified_reference; x = x.substring(x.indexOf(":") + 1); char cx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -