001: /*
002: * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.corba.se.impl.ior.iiop;
027:
028: import java.util.Iterator;
029:
030: import org.omg.IOP.TAG_INTERNET_IOP;
031:
032: import org.omg.CORBA_2_3.portable.InputStream;
033: import org.omg.CORBA_2_3.portable.OutputStream;
034:
035: import com.sun.corba.se.spi.ior.TaggedComponent;
036: import com.sun.corba.se.spi.ior.TaggedProfile;
037: import com.sun.corba.se.spi.ior.TaggedProfileTemplate;
038: import com.sun.corba.se.spi.ior.TaggedProfileTemplateBase;
039: import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
040: import com.sun.corba.se.spi.ior.ObjectId;
041: import com.sun.corba.se.spi.ior.IdentifiableContainerBase;
042: import com.sun.corba.se.spi.ior.IdentifiableBase;
043:
044: import com.sun.corba.se.impl.ior.EncapsulationUtility;
045:
046: import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
047: import com.sun.corba.se.spi.ior.iiop.IIOPAddress;
048: import com.sun.corba.se.spi.ior.iiop.IIOPFactories;
049:
050: import com.sun.corba.se.impl.encoding.EncapsOutputStream;
051:
052: import com.sun.corba.se.impl.encoding.CDROutputStream;
053:
054: import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
055: import com.sun.corba.se.spi.orb.ORB;
056:
057: /**
058: * @author
059: * If getMinorVersion==0, this does not contain any tagged components
060: */
061: public class IIOPProfileTemplateImpl extends TaggedProfileTemplateBase
062: implements IIOPProfileTemplate {
063: private ORB orb;
064: private GIOPVersion giopVersion;
065: private IIOPAddress primary;
066:
067: public boolean equals(Object obj) {
068: if (!(obj instanceof IIOPProfileTemplateImpl))
069: return false;
070:
071: IIOPProfileTemplateImpl other = (IIOPProfileTemplateImpl) obj;
072:
073: return super .equals(obj)
074: && giopVersion.equals(other.giopVersion)
075: && primary.equals(other.primary);
076: }
077:
078: public int hashCode() {
079: return super .hashCode() ^ giopVersion.hashCode()
080: ^ primary.hashCode();
081: }
082:
083: public TaggedProfile create(ObjectKeyTemplate oktemp, ObjectId id) {
084: return IIOPFactories.makeIIOPProfile(orb, oktemp, id, this );
085: }
086:
087: public GIOPVersion getGIOPVersion() {
088: return giopVersion;
089: }
090:
091: public IIOPAddress getPrimaryAddress() {
092: return primary;
093: }
094:
095: public IIOPProfileTemplateImpl(ORB orb, GIOPVersion version,
096: IIOPAddress primary) {
097: this .orb = orb;
098: this .giopVersion = version;
099: this .primary = primary;
100: if (giopVersion.getMinor() == 0)
101: // Adding tagged components is not allowed for IIOP 1.0,
102: // so this template is complete and should be made immutable.
103: makeImmutable();
104: }
105:
106: public IIOPProfileTemplateImpl(InputStream istr) {
107: byte major = istr.read_octet();
108: byte minor = istr.read_octet();
109: giopVersion = GIOPVersion.getInstance(major, minor);
110: primary = new IIOPAddressImpl(istr);
111: orb = (ORB) (istr.orb());
112: // Handle any tagged components (if applicable)
113: if (minor > 0)
114: EncapsulationUtility.readIdentifiableSequence(this , orb
115: .getTaggedComponentFactoryFinder(), istr);
116:
117: makeImmutable();
118: }
119:
120: public void write(ObjectKeyTemplate okeyTemplate, ObjectId id,
121: OutputStream os) {
122: giopVersion.write(os);
123: primary.write(os);
124:
125: // Note that this is NOT an encapsulation: do not marshal
126: // the endianness flag. However, the length is required.
127: // Note that this cannot be accomplished with a codec!
128:
129: // Use the byte order of the given stream
130: OutputStream encapsulatedOS = new EncapsOutputStream((ORB) os
131: .orb(), ((CDROutputStream) os).isLittleEndian());
132:
133: okeyTemplate.write(id, encapsulatedOS);
134: EncapsulationUtility.writeOutputStream(encapsulatedOS, os);
135:
136: if (giopVersion.getMinor() > 0)
137: EncapsulationUtility.writeIdentifiableSequence(this , os);
138: }
139:
140: /** Write out this IIOPProfileTemplateImpl only.
141: */
142: public void writeContents(OutputStream os) {
143: giopVersion.write(os);
144: primary.write(os);
145:
146: if (giopVersion.getMinor() > 0)
147: EncapsulationUtility.writeIdentifiableSequence(this , os);
148: }
149:
150: public int getId() {
151: return TAG_INTERNET_IOP.value;
152: }
153:
154: public boolean isEquivalent(TaggedProfileTemplate temp) {
155: if (!(temp instanceof IIOPProfileTemplateImpl))
156: return false;
157:
158: IIOPProfileTemplateImpl tempimp = (IIOPProfileTemplateImpl) temp;
159:
160: return primary.equals(tempimp.primary);
161: }
162:
163: }
|