001/* _NamingContextExtStub.java -- 002 Copyright (C) 2005, 2006 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package org.omg.CosNaming; 040 041import gnu.CORBA.NamingService.NameTransformer; 042 043import org.omg.CORBA.MARSHAL; 044import org.omg.CORBA.ObjectHelper; 045import org.omg.CORBA.portable.ApplicationException; 046import org.omg.CORBA.portable.Delegate; 047import org.omg.CORBA.portable.InputStream; 048import org.omg.CORBA.portable.OutputStream; 049import org.omg.CORBA.portable.RemarshalException; 050import org.omg.CosNaming.NamingContextExtPackage.AddressHelper; 051import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress; 052import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper; 053import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper; 054import org.omg.CosNaming.NamingContextExtPackage.URLStringHelper; 055import org.omg.CosNaming.NamingContextPackage.CannotProceed; 056import org.omg.CosNaming.NamingContextPackage.InvalidName; 057import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper; 058import org.omg.CosNaming.NamingContextPackage.NotFound; 059 060/** 061 * The extended naming context stub (proxy), used on the client side. 062 * The most of the {@link NamingContextExt} methods contain the code 063 * for remote invocaton. However as remote invocation is potencially an 064 * expensive step, some trivial methods, not requiring access to the 065 * naming database, are handled locally (see the method descriptions for 066 * details). 067 * 068 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) 069 */ 070public class _NamingContextExtStub 071 extends _NamingContextStub 072 implements NamingContextExt 073{ 074 /** 075 * Use serialVersionUID (v1.4) for interoperability. 076 */ 077 private static final long serialVersionUID = 6333293895664182866L; 078 079 /** 080 * This stub can be the base of the two CORBA objects, so it 081 * has two repository ids. 082 */ 083 private static String[] __ids = 084 { NamingContextExtHelper.id(), NamingContextHelper.id() }; 085 086 /** 087 * The local name form converter. 088 */ 089 private NameTransformer converter = new NameTransformer(); 090 091 /** 092 * Create the naming context stub. 093 */ 094 public _NamingContextExtStub() 095 { 096 super(); 097 } 098 099 /** 100 * Create the naming context stub with the given delegate. 101 */ 102 _NamingContextExtStub(Delegate delegate) 103 { 104 super(delegate); 105 } 106 107 /** 108 * Return the array of repository ids for this object. 109 * This stub can be the base of the two CORBA objects, so it 110 * has two repository ids, for {@link NamingContext} and 111 * for {@link NamingContextExt}. 112 */ 113 public String[] _ids() 114 { 115 return (String[]) __ids.clone(); 116 } 117 118 /** {@inheritDoc} */ 119 public org.omg.CORBA.Object resolve_str(String a_name_string) 120 throws NotFound, CannotProceed, InvalidName 121 { 122 InputStream in = null; 123 try 124 { 125 OutputStream _out = _request("resolve_str", true); 126 StringNameHelper.write(_out, a_name_string); 127 in = _invoke(_out); 128 129 return ObjectHelper.read(in); 130 } 131 catch (ApplicationException ex) 132 { 133 in = ex.getInputStream(); 134 135 String id = ex.getId(); 136 throw4(in, id); 137 138 // Should never happen. 139 throw new InternalError(); 140 } 141 catch (RemarshalException _rm) 142 { 143 return resolve_str(a_name_string); 144 } 145 finally 146 { 147 _releaseReply(in); 148 } 149 } 150 151 /** 152 * Converts the string name representation into the array 153 * name representation. 154 * 155 * This method is handled locally. 156 */ 157 public NameComponent[] to_name(String a_name_string) 158 throws InvalidName 159 { 160 return converter.toName(a_name_string); 161 } 162 163 /** 164 * Convert the name array representation to the name string 165 * representation. 166 * 167 * This method is handled locally. 168 */ 169 public String to_string(NameComponent[] a_name) 170 throws InvalidName 171 { 172 return converter.toString(a_name); 173 } 174 175 /** {@inheritDoc} */ 176 public String to_url(String an_address, String a_name_string) 177 throws InvalidAddress, InvalidName 178 { 179 InputStream in = null; 180 try 181 { 182 OutputStream _out = _request("to_url", true); 183 AddressHelper.write(_out, an_address); 184 StringNameHelper.write(_out, a_name_string); 185 in = _invoke(_out); 186 187 return URLStringHelper.read(in); 188 } 189 catch (ApplicationException ex) 190 { 191 in = ex.getInputStream(); 192 193 String id = ex.getId(); 194 if (id.equals(InvalidAddressHelper.id())) 195 throw InvalidAddressHelper.read(in); 196 else if (id.equals(InvalidNameHelper.id())) 197 throw InvalidNameHelper.read(in); 198 else 199 throw new MARSHAL(id); 200 } 201 catch (RemarshalException _rm) 202 { 203 return to_url(an_address, a_name_string); 204 } 205 finally 206 { 207 _releaseReply(in); 208 } 209 } 210}