From 8f523f3a1047919d3563daf1ef47ba87336ebe89 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 15 Nov 2005 23:20:01 +0000 Subject: Imported GNU Classpath 0.19 + gcj-import-20051115. * sources.am: Regenerated. * Makefile.in: Likewise. * scripts/makemake.tcl: Use glob -nocomplain. From-SVN: r107049 --- .../classpath/gnu/CORBA/CDR/AbstractCdrInput.java | 1768 ++++++++++++++++++++ .../classpath/gnu/CORBA/CDR/AbstractCdrOutput.java | 1047 ++++++++++++ .../classpath/gnu/CORBA/CDR/AbstractDataInput.java | 392 +++++ .../gnu/CORBA/CDR/AbstractDataOutput.java | 185 ++ libjava/classpath/gnu/CORBA/CDR/AligningInput.java | 131 ++ .../classpath/gnu/CORBA/CDR/AligningOutput.java | 148 ++ .../classpath/gnu/CORBA/CDR/ArrayValueHelper.java | 254 +++ .../gnu/CORBA/CDR/BigEndianInputStream.java | 2 +- .../gnu/CORBA/CDR/BigEndianOutputStream.java | 2 +- .../classpath/gnu/CORBA/CDR/BufferedCdrOutput.java | 156 ++ .../classpath/gnu/CORBA/CDR/BufferredCdrInput.java | 153 ++ .../gnu/CORBA/CDR/EncapsulationStream.java | 146 ++ libjava/classpath/gnu/CORBA/CDR/HeadlessInput.java | 749 +++++++++ libjava/classpath/gnu/CORBA/CDR/IDLTypeHelper.java | 169 ++ .../gnu/CORBA/CDR/LittleEndianInputStream.java | 2 +- .../gnu/CORBA/CDR/LittleEndianOutputStream.java | 2 +- .../gnu/CORBA/CDR/UnknownExceptionCtxHandler.java | 292 ++++ libjava/classpath/gnu/CORBA/CDR/VMVio.java | 101 ++ libjava/classpath/gnu/CORBA/CDR/Vio.java | 1459 ++++++++++++---- .../gnu/CORBA/CDR/abstractDataInputStream.java | 392 ----- .../gnu/CORBA/CDR/abstractDataOutputStream.java | 185 -- .../gnu/CORBA/CDR/aligningInputStream.java | 122 -- .../gnu/CORBA/CDR/aligningOutputStream.java | 121 -- libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java | 115 -- libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java | 115 -- libjava/classpath/gnu/CORBA/CDR/cdrInput.java | 1672 ------------------ libjava/classpath/gnu/CORBA/CDR/cdrOutput.java | 1009 ----------- .../gnu/CORBA/CDR/encapsulatedOutput.java | 146 -- libjava/classpath/gnu/CORBA/CDR/gnuRuntime.java | 336 ++++ .../classpath/gnu/CORBA/CDR/gnuValueStream.java | 71 + libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java | 166 -- .../classpath/gnu/CORBA/CdrEncapsCodecImpl.java | 358 ++++ libjava/classpath/gnu/CORBA/Connected_objects.java | 11 - libjava/classpath/gnu/CORBA/CorbaList.java | 115 ++ .../classpath/gnu/CORBA/DefaultSocketFactory.java | 79 + libjava/classpath/gnu/CORBA/DynAn/AbstractAny.java | 177 ++ .../classpath/gnu/CORBA/DynAn/DivideableAny.java | 514 ++++++ libjava/classpath/gnu/CORBA/DynAn/RecordAny.java | 405 +++++ .../classpath/gnu/CORBA/DynAn/UndivideableAny.java | 493 ++++++ .../gnu/CORBA/DynAn/ValueChangeListener.java | 50 + .../classpath/gnu/CORBA/DynAn/abstractDynAny.java | 177 -- .../classpath/gnu/CORBA/DynAn/abstractRecord.java | 405 ----- .../classpath/gnu/CORBA/DynAn/anyDivideable.java | 514 ------ .../classpath/gnu/CORBA/DynAn/anyUndivideable.java | 493 ------ libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java | 28 +- .../gnu/CORBA/DynAn/gnuDynAnyFactory.java | 8 +- libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java | 14 +- libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java | 2 +- libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java | 2 +- .../classpath/gnu/CORBA/DynAn/gnuDynStruct.java | 4 +- libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java | 10 +- libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java | 14 +- .../classpath/gnu/CORBA/DynAn/gnuDynValueBox.java | 6 +- .../gnu/CORBA/DynAn/valueChangedListener.java | 50 - .../classpath/gnu/CORBA/EmptyExceptionHolder.java | 1 + libjava/classpath/gnu/CORBA/ExceptionCreator.java | 245 --- .../classpath/gnu/CORBA/ForwardRequestHelper.java | 1 + libjava/classpath/gnu/CORBA/Functional_ORB.java | 1627 ------------------ libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java | 5 +- libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java | 10 +- .../gnu/CORBA/GIOP/CodeSetServiceContext.java | 224 +++ .../classpath/gnu/CORBA/GIOP/ContextHandler.java | 76 + libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java | 23 +- .../classpath/gnu/CORBA/GIOP/MessageHeader.java | 200 ++- libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java | 10 +- .../classpath/gnu/CORBA/GIOP/RequestHeader.java | 10 +- .../classpath/gnu/CORBA/GIOP/ServiceContext.java | 88 +- .../gnu/CORBA/GIOP/contextSupportingHeader.java | 76 - libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java | 224 --- .../classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java | 14 +- .../gnu/CORBA/GIOP/v1_0/RequestHeader.java | 14 +- .../classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java | 16 +- .../gnu/CORBA/GIOP/v1_2/RequestHeader.java | 27 +- libjava/classpath/gnu/CORBA/GeneralHolder.java | 178 ++ libjava/classpath/gnu/CORBA/HolderLocator.java | 184 ++ libjava/classpath/gnu/CORBA/IOR.java | 96 +- libjava/classpath/gnu/CORBA/IOR_Delegate.java | 466 ------ .../classpath/gnu/CORBA/IOR_contructed_object.java | 109 -- .../gnu/CORBA/Interceptor/IORInterceptors.java | 83 +- .../gnu/CORBA/Interceptor/Registrator.java | 8 +- .../gnu/CORBA/Interceptor/gnuIcCurrent.java | 4 +- .../gnu/CORBA/Interceptor/gnuIorInfo.java | 44 +- .../CORBA/Interceptor/gnuServerRequestInfo.java | 20 + libjava/classpath/gnu/CORBA/IorDelegate.java | 442 +++++ libjava/classpath/gnu/CORBA/IorObject.java | 118 ++ libjava/classpath/gnu/CORBA/IorProvider.java | 52 + libjava/classpath/gnu/CORBA/Minor.java | 282 ++++ libjava/classpath/gnu/CORBA/NamingService/Ext.java | 2 +- .../NamingService/NameComponentComparator.java | 98 ++ .../gnu/CORBA/NamingService/NameParser.java | 197 ++- .../gnu/CORBA/NamingService/NameTransformer.java | 328 ++++ .../gnu/CORBA/NamingService/NamingMap.java | 2 +- .../NamingService/NamingServiceTransient.java | 10 +- .../gnu/CORBA/NamingService/cmpNameComponent.java | 98 -- .../gnu/CORBA/NamingService/snConverter.java | 328 ---- libjava/classpath/gnu/CORBA/ObjectCreator.java | 397 +++-- libjava/classpath/gnu/CORBA/OctetHolder.java | 4 +- libjava/classpath/gnu/CORBA/OrbFocused.java | 375 +++++ libjava/classpath/gnu/CORBA/OrbFunctional.java | 1766 +++++++++++++++++++ libjava/classpath/gnu/CORBA/OrbRestricted.java | 529 ++++++ libjava/classpath/gnu/CORBA/Poa/AOM.java | 382 +++++ .../classpath/gnu/CORBA/Poa/AccessiblePolicy.java | 62 + .../classpath/gnu/CORBA/Poa/DynamicImpHandler.java | 85 + .../classpath/gnu/CORBA/Poa/ForwardedServant.java | 16 +- libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java | 79 +- libjava/classpath/gnu/CORBA/Poa/LocalRequest.java | 42 +- libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java | 51 +- .../gnu/CORBA/Poa/ServantDelegateImpl.java | 232 +++ .../classpath/gnu/CORBA/Poa/StandardPolicies.java | 128 ++ .../classpath/gnu/CORBA/Poa/activeObjectMap.java | 394 ----- libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java | 85 - .../gnu/CORBA/Poa/gnuAdapterActivator.java | 2 +- .../gnu/CORBA/Poa/gnuIdAssignmentPolicy.java | 2 +- .../gnu/CORBA/Poa/gnuIdUniquenessPolicy.java | 2 +- .../gnu/CORBA/Poa/gnuImplicitActivationPolicy.java | 2 +- .../classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java | 2 +- libjava/classpath/gnu/CORBA/Poa/gnuPOA.java | 471 ++++-- libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java | 60 +- .../gnu/CORBA/Poa/gnuRequestProcessingPolicy.java | 2 +- .../classpath/gnu/CORBA/Poa/gnuServantObject.java | 60 +- .../gnu/CORBA/Poa/gnuServantRetentionPolicy.java | 2 +- .../classpath/gnu/CORBA/Poa/gnuThreadPolicy.java | 2 +- libjava/classpath/gnu/CORBA/Poa/policySets.java | 128 -- .../classpath/gnu/CORBA/Poa/servantDelegate.java | 232 --- libjava/classpath/gnu/CORBA/Poa/vPolicy.java | 62 - libjava/classpath/gnu/CORBA/RawReply.java | 95 ++ .../classpath/gnu/CORBA/ResponseHandlerImpl.java | 189 +++ libjava/classpath/gnu/CORBA/Restricted_ORB.java | 524 ------ .../classpath/gnu/CORBA/ServiceRequestAdapter.java | 10 +- libjava/classpath/gnu/CORBA/SimpleDelegate.java | 294 ++++ libjava/classpath/gnu/CORBA/Simple_delegate.java | 276 --- libjava/classpath/gnu/CORBA/SocketRepository.java | 86 +- .../classpath/gnu/CORBA/StreamBasedRequest.java | 60 + libjava/classpath/gnu/CORBA/StreamHolder.java | 123 ++ libjava/classpath/gnu/CORBA/StubLocator.java | 110 ++ libjava/classpath/gnu/CORBA/TypeCodeHelper.java | 35 +- libjava/classpath/gnu/CORBA/TypeKindNamer.java | 183 ++ libjava/classpath/gnu/CORBA/Version.java | 26 +- libjava/classpath/gnu/CORBA/WCharHolder.java | 4 +- libjava/classpath/gnu/CORBA/WStringHolder.java | 6 +- libjava/classpath/gnu/CORBA/_PolicyImplBase.java | 3 +- libjava/classpath/gnu/CORBA/aliasTypeCode.java | 142 -- libjava/classpath/gnu/CORBA/binaryReply.java | 95 -- .../gnu/CORBA/bufferedResponseHandler.java | 189 --- libjava/classpath/gnu/CORBA/cdrEncapsCodec.java | 356 ---- libjava/classpath/gnu/CORBA/corbaArrayList.java | 115 -- libjava/classpath/gnu/CORBA/fixedTypeCode.java | 145 -- libjava/classpath/gnu/CORBA/generalTypeCode.java | 243 --- libjava/classpath/gnu/CORBA/gnuAny.java | 139 +- libjava/classpath/gnu/CORBA/gnuCodecFactory.java | 2 +- libjava/classpath/gnu/CORBA/gnuContextList.java | 2 +- libjava/classpath/gnu/CORBA/gnuExceptionList.java | 2 +- libjava/classpath/gnu/CORBA/gnuNVList.java | 6 +- libjava/classpath/gnu/CORBA/gnuRequest.java | 134 +- libjava/classpath/gnu/CORBA/gnuValueHolder.java | 2 +- libjava/classpath/gnu/CORBA/holderFactory.java | 184 -- .../gnu/CORBA/interfaces/SocketFactory.java | 95 ++ .../classpath/gnu/CORBA/interfaces/package.html | 49 + .../gnu/CORBA/primitiveArrayTypeCode.java | 265 --- libjava/classpath/gnu/CORBA/primitiveTypeCode.java | 196 --- libjava/classpath/gnu/CORBA/recordTypeCode.java | 245 --- libjava/classpath/gnu/CORBA/recursiveTypeCode.java | 78 - libjava/classpath/gnu/CORBA/streamReadyHolder.java | 120 -- libjava/classpath/gnu/CORBA/streamRequest.java | 60 - libjava/classpath/gnu/CORBA/stringTypeCode.java | 83 - libjava/classpath/gnu/CORBA/stubFinder.java | 110 -- libjava/classpath/gnu/CORBA/typeNamer.java | 180 -- .../gnu/CORBA/typecodes/AliasTypeCode.java | 148 ++ .../gnu/CORBA/typecodes/ArrayTypeCode.java | 272 +++ .../gnu/CORBA/typecodes/FixedTypeCode.java | 152 ++ .../gnu/CORBA/typecodes/GeneralTypeCode.java | 249 +++ .../gnu/CORBA/typecodes/PrimitiveTypeCode.java | 201 +++ .../gnu/CORBA/typecodes/RecordTypeCode.java | 252 +++ .../gnu/CORBA/typecodes/RecursiveTypeCode.java | 84 + .../gnu/CORBA/typecodes/StringTypeCode.java | 89 + libjava/classpath/gnu/CORBA/typecodes/package.html | 48 + libjava/classpath/gnu/CORBA/universalHolder.java | 174 -- libjava/classpath/gnu/classpath/ByteArray.java | 109 ++ .../classpath/gnu/classpath/SystemProperties.java | 6 - .../gnu/classpath/jdwp/event/VmDeathEvent.java | 85 + .../classpath/jdwp/event/filters/StepFilter.java | 2 +- .../jdwp/event/filters/ThreadOnlyFilter.java | 2 +- .../jdwp/processor/ArrayReferenceCommandSet.java | 3 +- .../jdwp/processor/ArrayTypeCommandSet.java | 3 +- .../processor/ClassLoaderReferenceCommandSet.java | 3 +- .../processor/ClassObjectReferenceCommandSet.java | 3 +- .../jdwp/processor/ClassTypeCommandSet.java | 3 +- .../jdwp/processor/EventRequestCommandSet.java | 3 +- .../classpath/jdwp/processor/MethodCommandSet.java | 3 +- .../jdwp/processor/ObjectReferenceCommandSet.java | 3 +- .../jdwp/processor/ReferenceTypeCommandSet.java | 3 +- .../jdwp/processor/StackFrameCommandSet.java | 3 +- .../jdwp/processor/StringReferenceCommandSet.java | 3 +- .../processor/ThreadGroupReferenceCommandSet.java | 3 +- .../jdwp/processor/ThreadReferenceCommandSet.java | 3 +- .../jdwp/processor/VirtualMachineCommandSet.java | 13 +- libjava/classpath/gnu/java/awt/AWTUtilities.java | 9 +- libjava/classpath/gnu/java/awt/EmbeddedWindow.java | 6 +- libjava/classpath/gnu/java/awt/FocusManager.java | 52 - .../gnu/java/awt/peer/gtk/GdkFontMetrics.java | 29 +- .../gnu/java/awt/peer/gtk/GdkGraphics.java | 12 +- .../gnu/java/awt/peer/gtk/GdkGraphics2D.java | 53 +- .../gnu/java/awt/peer/gtk/GdkTextLayout.java | 5 +- .../gnu/java/awt/peer/gtk/GtkChoicePeer.java | 3 - .../gnu/java/awt/peer/gtk/GtkComponentPeer.java | 7 +- .../gnu/java/awt/peer/gtk/GtkDialogPeer.java | 28 +- .../gnu/java/awt/peer/gtk/GtkFramePeer.java | 3 +- .../classpath/gnu/java/awt/peer/qt/QtToolkit.java | 4 +- .../gnu/java/beans/DummyAppletContext.java | 37 +- .../gnu/java/beans/decoder/BooleanHandler.java | 4 +- libjava/classpath/gnu/java/io/PlatformHelper.java | 5 - .../classpath/gnu/java/net/LineInputStream.java | 13 +- .../protocol/http/ByteArrayResponseBodyReader.java | 123 -- .../java/net/protocol/http/ChunkedInputStream.java | 2 +- .../gnu/java/net/protocol/http/Cookie.java | 2 +- .../gnu/java/net/protocol/http/HTTPConnection.java | 174 +- .../java/net/protocol/http/HTTPURLConnection.java | 108 +- .../gnu/java/net/protocol/http/Headers.java | 85 +- .../protocol/http/LimitedLengthInputStream.java | 220 +++ .../gnu/java/net/protocol/http/Request.java | 191 +-- .../gnu/java/net/protocol/http/Response.java | 55 +- .../java/net/protocol/http/ResponseBodyReader.java | 70 - .../net/protocol/http/event/ConnectionEvent.java | 81 - .../protocol/http/event/ConnectionListener.java | 58 - .../java/net/protocol/http/event/RequestEvent.java | 107 -- .../net/protocol/http/event/RequestListener.java | 70 - .../gnu/java/net/protocol/http/event/package.html | 46 - .../gnu/java/net/protocol/jar/Connection.java | 23 +- .../classpath/gnu/java/nio/SocketChannelImpl.java | 2 +- .../gnu/java/nio/channels/FileChannelImpl.java | 3 +- .../gnu/java/nio/charset/UTF_16Decoder.java | 19 +- .../gnu/java/nio/charset/UnicodeLittle.java | 2 +- .../gnu/java/nio/charset/iconv/IconvProvider.java | 6 +- .../classpath/gnu/java/rmi/dgc/DGCImpl_Stub.java | 2 +- .../gnu/java/rmi/server/RMIClassLoaderImpl.java | 350 ++++ .../gnu/java/rmi/server/RMIObjectInputStream.java | 2 +- .../gnu/java/rmi/server/UnicastServer.java | 5 +- .../classpath/gnu/java/security/PolicyFile.java | 6 +- .../classpath/gnu/java/security/der/BitString.java | 13 + .../classpath/gnu/java/security/der/DERReader.java | 2 +- .../provider/DiffieHellmanKeyFactoryImpl.java | 123 ++ .../DiffieHellmanKeyPairGeneratorImpl.java | 86 + .../classpath/gnu/java/security/provider/Gnu.java | 15 +- .../java/security/x509/ext/BasicConstraints.java | 2 +- .../gnu/java/security/x509/ext/Extension.java | 10 +- .../classpath/gnu/java/text/BaseBreakIterator.java | 7 +- .../gnu/javax/crypto/DiffieHellmanImpl.java | 159 ++ .../gnu/javax/crypto/GnuDHPrivateKey.java | 90 + .../classpath/gnu/javax/crypto/RSACipherImpl.java | 311 ++++ .../gnu/javax/imageio/bmp/BMPDecoder.java | 169 ++ .../gnu/javax/imageio/bmp/BMPException.java | 47 + .../gnu/javax/imageio/bmp/BMPFileHeader.java | 128 ++ .../gnu/javax/imageio/bmp/BMPImageReader.java | 153 ++ .../gnu/javax/imageio/bmp/BMPImageReaderSpi.java | 123 ++ .../gnu/javax/imageio/bmp/BMPInfoHeader.java | 201 +++ .../gnu/javax/imageio/bmp/DecodeBF16.java | 104 ++ .../gnu/javax/imageio/bmp/DecodeBF32.java | 108 ++ .../gnu/javax/imageio/bmp/DecodeRGB1.java | 96 ++ .../gnu/javax/imageio/bmp/DecodeRGB24.java | 77 + .../gnu/javax/imageio/bmp/DecodeRGB4.java | 92 + .../gnu/javax/imageio/bmp/DecodeRGB8.java | 90 + .../gnu/javax/imageio/bmp/DecodeRLE4.java | 176 ++ .../gnu/javax/imageio/bmp/DecodeRLE8.java | 143 ++ .../classpath/gnu/javax/rmi/CORBA/CorbaInput.java | 297 ++++ .../classpath/gnu/javax/rmi/CORBA/CorbaOutput.java | 219 +++ .../javax/rmi/CORBA/DefaultWriteObjectTester.java | 85 + .../gnu/javax/rmi/CORBA/DelegateFactory.java | 76 +- .../CORBA/PortableRemoteObjectDelegateImpl.java | 352 +++- .../gnu/javax/rmi/CORBA/RmiUtilities.java | 946 +++++++++++ .../gnu/javax/rmi/CORBA/StubDelegateImpl.java | 262 ++- .../gnu/javax/rmi/CORBA/TieTargetRecord.java | 93 + .../gnu/javax/rmi/CORBA/UtilDelegateImpl.java | 714 +++++++- .../javax/rmi/CORBA/ValueHandlerDelegateImpl.java | 163 ++ .../gnu/javax/rmi/CORBA/ValueHandlerImpl.java | 82 - .../classpath/gnu/javax/rmi/PortableServer.java | 141 -- .../javax/sound/midi/alsa/AlsaInputPortDevice.java | 130 ++ .../sound/midi/alsa/AlsaMidiDeviceProvider.java | 216 +++ .../sound/midi/alsa/AlsaMidiSequencerDevice.java | 519 ++++++ .../sound/midi/alsa/AlsaOutputPortDevice.java | 131 ++ .../gnu/javax/sound/midi/alsa/AlsaPortDevice.java | 153 ++ .../sound/midi/dssi/DSSIMidiDeviceProvider.java | 173 ++ .../gnu/javax/sound/midi/dssi/DSSISynthesizer.java | 745 +++++++++ .../classpath/gnu/xml/aelfred2/JAXPFactory.java | 2 +- libjava/classpath/gnu/xml/aelfred2/SAXDriver.java | 4 +- libjava/classpath/gnu/xml/dom/DomDocument.java | 50 +- .../gnu/xml/libxmlj/dom/GnomeDocument.java | 48 +- .../gnu/xml/pipeline/ValidationConsumer.java | 2 +- .../gnu/xml/stream/XMLOutputFactoryImpl.java | 3 +- .../gnu/xml/stream/XMLStreamWriterImpl.java | 81 +- .../gnu/xml/transform/StreamSerializer.java | 6 +- .../gnu/xml/transform/TransformerImpl.java | 8 +- 291 files changed, 28480 insertions(+), 16247 deletions(-) create mode 100644 libjava/classpath/gnu/CORBA/CDR/AbstractCdrInput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/AbstractCdrOutput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/AbstractDataInput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/AbstractDataOutput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/AligningInput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/AligningOutput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/ArrayValueHelper.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/BufferedCdrOutput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/BufferredCdrInput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/EncapsulationStream.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/HeadlessInput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/IDLTypeHelper.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/UnknownExceptionCtxHandler.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/VMVio.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/cdrInput.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/cdrOutput.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/gnuRuntime.java create mode 100644 libjava/classpath/gnu/CORBA/CDR/gnuValueStream.java delete mode 100644 libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java create mode 100644 libjava/classpath/gnu/CORBA/CdrEncapsCodecImpl.java create mode 100644 libjava/classpath/gnu/CORBA/CorbaList.java create mode 100644 libjava/classpath/gnu/CORBA/DefaultSocketFactory.java create mode 100644 libjava/classpath/gnu/CORBA/DynAn/AbstractAny.java create mode 100644 libjava/classpath/gnu/CORBA/DynAn/DivideableAny.java create mode 100644 libjava/classpath/gnu/CORBA/DynAn/RecordAny.java create mode 100644 libjava/classpath/gnu/CORBA/DynAn/UndivideableAny.java create mode 100644 libjava/classpath/gnu/CORBA/DynAn/ValueChangeListener.java delete mode 100644 libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java delete mode 100644 libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java delete mode 100644 libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java delete mode 100644 libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java delete mode 100644 libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java delete mode 100644 libjava/classpath/gnu/CORBA/ExceptionCreator.java delete mode 100644 libjava/classpath/gnu/CORBA/Functional_ORB.java create mode 100644 libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java create mode 100644 libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java delete mode 100644 libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java delete mode 100644 libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java create mode 100644 libjava/classpath/gnu/CORBA/GeneralHolder.java create mode 100644 libjava/classpath/gnu/CORBA/HolderLocator.java delete mode 100644 libjava/classpath/gnu/CORBA/IOR_Delegate.java delete mode 100644 libjava/classpath/gnu/CORBA/IOR_contructed_object.java create mode 100644 libjava/classpath/gnu/CORBA/IorDelegate.java create mode 100644 libjava/classpath/gnu/CORBA/IorObject.java create mode 100644 libjava/classpath/gnu/CORBA/IorProvider.java create mode 100644 libjava/classpath/gnu/CORBA/Minor.java create mode 100644 libjava/classpath/gnu/CORBA/NamingService/NameComponentComparator.java create mode 100644 libjava/classpath/gnu/CORBA/NamingService/NameTransformer.java delete mode 100644 libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java delete mode 100644 libjava/classpath/gnu/CORBA/NamingService/snConverter.java create mode 100644 libjava/classpath/gnu/CORBA/OrbFocused.java create mode 100644 libjava/classpath/gnu/CORBA/OrbFunctional.java create mode 100644 libjava/classpath/gnu/CORBA/OrbRestricted.java create mode 100644 libjava/classpath/gnu/CORBA/Poa/AOM.java create mode 100644 libjava/classpath/gnu/CORBA/Poa/AccessiblePolicy.java create mode 100644 libjava/classpath/gnu/CORBA/Poa/DynamicImpHandler.java create mode 100644 libjava/classpath/gnu/CORBA/Poa/ServantDelegateImpl.java create mode 100644 libjava/classpath/gnu/CORBA/Poa/StandardPolicies.java delete mode 100644 libjava/classpath/gnu/CORBA/Poa/activeObjectMap.java delete mode 100644 libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java delete mode 100644 libjava/classpath/gnu/CORBA/Poa/policySets.java delete mode 100644 libjava/classpath/gnu/CORBA/Poa/servantDelegate.java delete mode 100644 libjava/classpath/gnu/CORBA/Poa/vPolicy.java create mode 100644 libjava/classpath/gnu/CORBA/RawReply.java create mode 100644 libjava/classpath/gnu/CORBA/ResponseHandlerImpl.java delete mode 100644 libjava/classpath/gnu/CORBA/Restricted_ORB.java create mode 100644 libjava/classpath/gnu/CORBA/SimpleDelegate.java delete mode 100644 libjava/classpath/gnu/CORBA/Simple_delegate.java create mode 100644 libjava/classpath/gnu/CORBA/StreamBasedRequest.java create mode 100644 libjava/classpath/gnu/CORBA/StreamHolder.java create mode 100644 libjava/classpath/gnu/CORBA/StubLocator.java create mode 100644 libjava/classpath/gnu/CORBA/TypeKindNamer.java delete mode 100644 libjava/classpath/gnu/CORBA/aliasTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/binaryReply.java delete mode 100644 libjava/classpath/gnu/CORBA/bufferedResponseHandler.java delete mode 100644 libjava/classpath/gnu/CORBA/cdrEncapsCodec.java delete mode 100644 libjava/classpath/gnu/CORBA/corbaArrayList.java delete mode 100644 libjava/classpath/gnu/CORBA/fixedTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/generalTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/holderFactory.java create mode 100644 libjava/classpath/gnu/CORBA/interfaces/SocketFactory.java create mode 100644 libjava/classpath/gnu/CORBA/interfaces/package.html delete mode 100644 libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/primitiveTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/recordTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/recursiveTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/streamReadyHolder.java delete mode 100644 libjava/classpath/gnu/CORBA/streamRequest.java delete mode 100644 libjava/classpath/gnu/CORBA/stringTypeCode.java delete mode 100644 libjava/classpath/gnu/CORBA/stubFinder.java delete mode 100644 libjava/classpath/gnu/CORBA/typeNamer.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/AliasTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/ArrayTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/FixedTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/GeneralTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/PrimitiveTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/RecordTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/RecursiveTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/StringTypeCode.java create mode 100644 libjava/classpath/gnu/CORBA/typecodes/package.html delete mode 100644 libjava/classpath/gnu/CORBA/universalHolder.java create mode 100644 libjava/classpath/gnu/classpath/ByteArray.java create mode 100644 libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java delete mode 100644 libjava/classpath/gnu/java/awt/FocusManager.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java create mode 100644 libjava/classpath/gnu/java/net/protocol/http/LimitedLengthInputStream.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/ResponseBodyReader.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/event/ConnectionEvent.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/event/ConnectionListener.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/event/RequestEvent.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/event/RequestListener.java delete mode 100644 libjava/classpath/gnu/java/net/protocol/http/event/package.html create mode 100644 libjava/classpath/gnu/java/rmi/server/RMIClassLoaderImpl.java create mode 100644 libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java create mode 100644 libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java create mode 100644 libjava/classpath/gnu/javax/crypto/DiffieHellmanImpl.java create mode 100644 libjava/classpath/gnu/javax/crypto/GnuDHPrivateKey.java create mode 100644 libjava/classpath/gnu/javax/crypto/RSACipherImpl.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/BMPDecoder.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/BMPException.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/BMPFileHeader.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/BMPImageReader.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/BMPImageReaderSpi.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/BMPInfoHeader.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeBF16.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeBF32.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeRGB1.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeRGB24.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeRGB4.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeRGB8.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeRLE4.java create mode 100644 libjava/classpath/gnu/javax/imageio/bmp/DecodeRLE8.java create mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/CorbaInput.java create mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/CorbaOutput.java create mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/DefaultWriteObjectTester.java create mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/RmiUtilities.java create mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/TieTargetRecord.java create mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerDelegateImpl.java delete mode 100644 libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerImpl.java delete mode 100644 libjava/classpath/gnu/javax/rmi/PortableServer.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java create mode 100644 libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java (limited to 'libjava/classpath/gnu') diff --git a/libjava/classpath/gnu/CORBA/CDR/AbstractCdrInput.java b/libjava/classpath/gnu/CORBA/CDR/AbstractCdrInput.java new file mode 100644 index 0000000..866ec2c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/AbstractCdrInput.java @@ -0,0 +1,1768 @@ +/* AbstractCdrInput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.BigDecimalHelper; +import gnu.CORBA.OrbFunctional; +import gnu.CORBA.GIOP.CharSets_OSF; +import gnu.CORBA.GIOP.CodeSetServiceContext; +import gnu.CORBA.IOR; +import gnu.CORBA.IorDelegate; +import gnu.CORBA.Minor; +import gnu.CORBA.TypeCodeHelper; +import gnu.CORBA.Unexpected; +import gnu.CORBA.Version; +import gnu.CORBA.gnuAny; +import gnu.CORBA.StubLocator; + +import org.omg.CORBA.Any; +import org.omg.CORBA.AnySeqHolder; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BooleanSeqHolder; +import org.omg.CORBA.CharSeqHolder; +import org.omg.CORBA.DoubleSeqHolder; +import org.omg.CORBA.FloatSeqHolder; +import org.omg.CORBA.LongLongSeqHolder; +import org.omg.CORBA.LongSeqHolder; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.OctetSeqHolder; +import org.omg.CORBA.ShortSeqHolder; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.ULongLongSeqHolder; +import org.omg.CORBA.ULongSeqHolder; +import org.omg.CORBA.UShortSeqHolder; +import org.omg.CORBA.WCharSeqHolder; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.ObjectImpl; + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Serializable; + +import java.math.BigDecimal; + +/** + * A simple CORBA CDR (common data representation) input stream, reading data + * from the given {@link java.io.InputStream}. The primitive types are aligned + * on they natural boundaries by implementing the abstract method + * {@link #align(int boundary)}. + * + * The same class also implements {@link org.omg.CORBA.DataInputStream} to read + * the object content in a user defined way. + * + * TODO This class uses 16 bits per Unicode character only, as it was until jdk + * 1.4 inclusive. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public abstract class AbstractCdrInput + extends org.omg.CORBA_2_3.portable.InputStream + implements org.omg.CORBA.DataInputStream +{ + /** + * The runtime, associated with this stream. This field is only used when + * reading and writing value types and filled-in in gnu.CORBA.CDR.Vio. + */ + public transient gnuRuntime runtime; + + /** + * The message, explaining that the exception has been thrown due unexpected + * end of the input stream. This usually happens the server and client + * disagree on communication or data representation rules. + */ + protected static final String UNEXP_EOF = "Unexpected end of stream"; + + /** + * This instance is used to convert primitive data types into the byte + * sequences. + */ + protected AbstractDataInput b; + + /** + * The input stream, from where the data are actually being read. + */ + protected java.io.InputStream actual_stream; + + /** + * The associated orb, if any. + */ + protected ORB orb; + + /** + * The GIOP version. + */ + protected Version giop = new Version(1, 2); + + /** + * The code set information. + */ + protected CodeSetServiceContext codeset = CodeSetServiceContext.STANDARD; + + /** + * The name of the currently used narrow charset, null if the native narrow + * charset is used. + */ + private String narrow_charset = null; + + /** + * The name of the currently used wide charset, null if the native wide + * charset is used. + */ + private String wide_charset = null; + + /** + * True if the native code set is used for narrow characters. If the set is + * native, no the intermediate Reader object is instantiated when writing + * characters. + */ + private boolean narrow_native; + + /** + * True if the native code set is used for wide characters. If the set is + * native, no the intermediate Reader object is instantiated when writing + * characters. + */ + private boolean wide_native; + + /** + * If true, the stream expect the multi-byte data in the form "less + * significant byte first" (Little Endian). This is the opposite to the java + * standard (Big Endian). + */ + private boolean little_endian; + + /** + * Creates the stream. The stream reads Big Endian by default. + * + * @param readFrom a stream to read CORBA input from. + */ + public AbstractCdrInput(java.io.InputStream readFrom) + { + setInputStream(readFrom); + setCodeSet(CodeSetServiceContext.STANDARD); + } + + /** + * Creates the stream, requiring the subsequent call of + * {@link #setInputStream(java.io.InputStream)}. + */ + public AbstractCdrInput() + { + setCodeSet(CodeSetServiceContext.STANDARD); + } + + /** + * Set the Big Endian or Little Endian encoding. The stream reads Big Endian + * by default. + * + * @param use_little_endian if true, the stream expect the multi-byte data in + * the form "less significant byte first" (Little Endian). This is the + * opposite to the java standard (Big Endian). + */ + public void setBigEndian(boolean use_big_endian) + { + little_endian = !use_big_endian; + setInputStream(actual_stream); + } + + /** + * Get the used encoding. + * + * @param true for Big Endian, false for Little Endian. + */ + public boolean isBigEndian() + { + return !little_endian; + } + + /** + * Clone all important settings to another stream. + */ + public void cloneSettings(AbstractCdrInput stream) + { + stream.setBigEndian(isBigEndian()); + stream.setCodeSet(getCodeSet()); + stream.setVersion(giop); + stream.setOrb(orb); + } + + /** + * Set the input stream that receives the CORBA input. + * + * @param readFrom the stream. + */ + public void setInputStream(java.io.InputStream readFrom) + { + if (little_endian) + b = new LittleEndianInputStream(readFrom); + else + b = new BigEndianInputStream(readFrom); + + actual_stream = readFrom; + } + + /** + * Set the alignment offset, if the index of the first byte in the stream is + * different from 0. + */ + public abstract void setOffset(int offset); + + /** + * Set the orb, associated with this stream. + * + * @param an_orb + */ + public void setOrb(ORB an_orb) + { + orb = an_orb; + } + + /** + * Set the GIOP version. Some data types are written differently for the + * different versions. The default version is 1.0 . + */ + public void setVersion(Version giop_version) + { + giop = giop_version; + } + + /** + * Align the curretn position at the given natural boundary. + */ + public abstract void align(int boundary); + + /** + * Reads the CORBA unsigned long (java int), returning the value in the + * sufficiently large java long. + */ + public long gnu_read_ulong() + { + try + { + long l = b.readInt(); + l &= 0xFFFFFFF; + return l; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the unsigned short integer value and return it as java int, + * sufficiently large to hold all values. + */ + public int gnu_read_ushort() + { + try + { + align(2); + return b.readUnsignedShort(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Return the associated {@link ORB}. + * + * @return the associated {@link ORB} or null is no such is set. + */ + public ORB orb() + { + return orb; + } + + /** + * Read a single byte directly from the buffer. + */ + public int read() + throws java.io.IOException + { + try + { + return b.read(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + } + + /** + * Read bytes directly from the buffer. + */ + public int read(byte[] x, int ofs, int len) + throws java.io.IOException + { + try + { + return b.read(x, ofs, len); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + } + + /** + * Read bytes directly from the buffer. + */ + public int read(byte[] x) + throws java.io.IOException + { + try + { + return b.read(x); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + } + + /** + * Read the CORBA object. The object to read is represented in the form of the + * plain (not a string-encoded) IOR profile without the heading endian + * indicator. The responsible method for reading such data is + * {@link IOR.read_no_endian}. + * + * The returned object is usually casted into the given type using the .narrow + * method of its helper, despite in some cases the direct cast would also + * work. + * + * The null objects are recognised from the empty profile set. For such + * objects, null is returned. + * + * @return the loaded and constructed object. + */ + public org.omg.CORBA.Object read_Object() + { + try + { + IOR ior = new IOR(); + ior._read_no_endian(this); + + if (ior.Id == null) + return null; + + // Check maybe this is a remote reference to the local object. + // This is only possible if we access the repository of the + // connected object. + if (orb instanceof OrbFunctional) + { + OrbFunctional forb = (OrbFunctional) orb; + org.omg.CORBA.Object local = forb.find_local_object(ior); + if (local != null) + return local; + } + + // Search for the available stubs. + ObjectImpl impl = StubLocator.search(orb, ior); + try + { + if (impl._get_delegate() == null) + impl._set_delegate(new IorDelegate(orb, ior)); + } + catch (BAD_OPERATION ex) + { + // Some colaborants may throw this exception + // in response to the attempt to get the unset delegate. + impl._set_delegate(new IorDelegate(orb, ior)); + } + + return impl; + } + catch (IOException ex) + { + MARSHAL bad = new MARSHAL(); + bad.minor = Minor.IOR; + bad.initCause(ex); + throw bad; + } + } + + /** + * Read the type code. The type code format is defined in the CORBA + * documenation. + */ + public TypeCode read_TypeCode() + { + try + { + return TypeCodeHelper.read(this); + } + + catch (Bounds ex) + { + throw new Unexpected(); + } + catch (BadKind ex) + { + throw new Unexpected(); + } + } + + /** + * Read the CORBA {@link Any}. This method first reads the type code, then + * delegates the functionality to {@link Any#read_value}. + */ + public Any read_any() + { + TypeCode ty = read_TypeCode(); + gnuAny any = new gnuAny(); + any.read_value(this, ty); + return any; + } + + /** + * Read the boolean, treating any non zero byte as true, zero byte as false. + */ + public boolean read_boolean() + { + try + { + return b.read() == 0 ? false : true; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the array of boolean. + */ + public void read_boolean_array(boolean[] x, int offs, int len) + { + try + { + for (int i = offs; i < offs + len; i++) + { + x[i] = b.read() == 0 ? false : true; + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a character using narrow charset encoding. Depending form which + * encoding is set, this still can be Unicode or ever wider. + */ + public char read_char() + { + try + { + if (narrow_native) + return (char) b.read(); + else + return (char) new InputStreamReader((InputStream) b, narrow_charset).read(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a character array, using narrow charset encoding. + */ + public void read_char_array(char[] x, int offset, int length) + { + try + { + if (narrow_native) + { + for (int i = offset; i < offset + length; i++) + x[i] = (char) b.read(); + } + else + { + InputStreamReader reader = new InputStreamReader((InputStream) b, + narrow_charset); + reader.read(x, offset, length); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the double value, IEEE 754 format. + */ + public double read_double() + { + try + { + align(8); + return b.readDouble(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(); + } + } + + /** + * Read the array of double values, IEEE 754 format. + */ + public void read_double_array(double[] x, int offs, int len) + { + try + { + align(8); + for (int i = offs; i < offs + len; i++) + { + x[i] = b.readDouble(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the encapsulated stream. If the encapsulated sequence appears to be in + * the Little endian format, the flag of the returned stream is set to read + * Little endian. + */ + public BufferredCdrInput read_encapsulation() + { + try + { + int l = read_long(); + + byte[] r = new byte[l]; + int n = 0; + reading: while (n < r.length) + { + n += read(r, n, r.length - n); + } + + BufferredCdrInput capsule = new BufferredCdrInput(r); + capsule.setOrb(orb); + + int endian = capsule.read_octet(); + + if (endian != 0) + { + capsule.setBigEndian(false); + } + + return capsule; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA fixed (the end of the fixed can be determined + * by its last byte). The scale is always assumed to be zero. + */ + public BigDecimal read_fixed() + { + try + { + return BigDecimalHelper.read(this, 0); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the float value, IEEE 754 format. + */ + public float read_float() + { + try + { + align(4); + return b.readFloat(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read an array of float values, IEEE 754 format. + */ + public void read_float_array(float[] x, int offs, int len) + { + try + { + align(4); + for (int i = offs; i < offs + len; i++) + { + x[i] = b.readFloat(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA long (java int), high byte first. + */ + public int read_long() + { + try + { + align(4); + return b.readInt(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read an array of CORBA longs (java ints). + */ + public void read_long_array(int[] x, int offs, int len) + { + try + { + align(4); + for (int i = offs; i < offs + len; i++) + { + x[i] = b.readInt(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA long long (java long). + */ + public long read_longlong() + { + try + { + align(8); + return b.readLong(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read an array of CORBA long longs (java longs). + */ + public void read_longlong_array(long[] x, int offs, int len) + { + try + { + align(8); + for (int i = offs; i < offs + len; i++) + { + x[i] = b.readLong(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a single byte. + */ + public byte read_octet() + { + try + { + return b.readByte(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the byte array. + */ + public void read_octet_array(byte[] x, int offs, int len) + { + try + { + b.read(x, offs, len); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the length of the byte array as CORBA long and then the array itseld. + */ + public byte[] read_sequence() + { + try + { + int l = read_long(); + byte[] buf = new byte[l]; + if (l > 0) + { + b.readFully(buf); + } + return buf; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA short integer. + */ + public short read_short() + { + try + { + align(2); + return b.readShort(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the array of CORBA short integer values. + */ + public void read_short_array(short[] x, int offs, int len) + { + try + { + align(2); + for (int i = offs; i < offs + len; i++) + { + x[i] = b.readShort(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a singe byte string. The method firs reads the byte array and then + * calls a constructor to create a string from this array. The character + * encoding, if previously set, is taken into consideration. + * + * @return a loaded string. + */ + public String read_string() + { + int n = 0; + try + { + align(4); + + n = b.readInt(); + byte[] s = new byte[n]; + b.read(s); + + // Discard the null terminator. + if (narrow_charset == null) + return new String(s, 0, n - 1); + else + return new String(s, 0, n - 1, narrow_charset); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(); + } + catch (NegativeArraySizeException nex) + { + MARSHAL m = new MARSHAL("Input stream broken, got " + n + "(0x" + + Integer.toHexString(n) + ") as a string size"); + m.minor = Minor.Negative; + throw m; + } + } + + /** + * Reads the CORBA unsigned long (java int), delegating functionality to + * {@link #read_long}. + */ + public int read_ulong() + { + return read_long(); + } + + /** + * Reads the array of CORBA unsigned long (java integer) values, delegating + * functionality to {@link #real_long_array}. + */ + public void read_ulong_array(int[] x, int offs, int len) + { + read_long_array(x, offs, len); + } + + /** + * Read the CORBA unsigned long long value, delegating functionality to + * {@link #read_longlong}. There is no way to return values over the limit of + * the java signed long in other way than returning the negative value. + */ + public long read_ulonglong() + { + return read_longlong(); + } + + /** + * Reads the array of CORBA long long (java long) values, delegating + * functionality to {@link #real_longlong_array}. + */ + public void read_ulonglong_array(long[] x, int offs, int len) + { + read_longlong_array(x, offs, len); + } + + /** + * Read the unsigned short integer value. Due strange specification, the + * returned value must be the short type as well, so the the best solution + * seems just to delegete functionality to read_short. + */ + public short read_ushort() + { + return read_short(); + } + + /** + * Read an array of unsigned short values, delegating the functionality to + * {@link read_short_array}. + */ + public void read_ushort_array(short[] x, int offs, int len) + { + read_short_array(x, offs, len); + } + + /** + * Reads the wide character using the encoding, specified in the wide_charset. + */ + public char read_wchar() + { + try + { + if (giop.until_inclusive(1, 1)) + { + align(2); + + if (wide_native) + return (char) b.readShort(); + else + return (char) new InputStreamReader((InputStream) b, wide_charset).read(); + } + else + { + int l = b.read(); + if (l == 2 && wide_native) + return b.readChar(); + else if (l <= 0) + { + MARSHAL m = new MARSHAL("wchar size " + l); + m.minor = Minor.Negative; + throw m; + } + else + { + byte[] bytes = new byte[l]; + b.readFully(bytes); + String cs; + + if (bytes.length > 2 && bytes[0] == 0xFE && bytes[1] == 0xFF) + cs = new String(bytes, 2, bytes.length - 2, wide_charset); + else if (bytes.length > 2 && bytes[0] == 0xFF + && bytes[1] == 0xFE) + { + // Litle endian detected - swap bytes. + byte t; + for (int i = 3; i < bytes.length; i = i + 2) + { + t = bytes[i]; + bytes[i - 1] = bytes[i]; + bytes[i] = t; + } + cs = new String(bytes, 2, bytes.length - 2, wide_charset); + } + else + cs = new String(bytes, wide_charset); + + return cs.charAt(0); + } + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(); + } + } + + /** + * Read an array of "wide chars", each representing a two byte Unicode + * character, high byte first. + */ + public void read_wchar_array(char[] x, int offset, int length) + { + try + { + if (giop.until_inclusive(1, 1)) + align(2); + + if (wide_native) + { + for (int i = offset; i < offset + length; i++) + x[i] = (char) b.readShort(); + } + else + { + InputStreamReader reader = new InputStreamReader((InputStream) b, + wide_charset); + reader.read(x, offset, length); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Reads the string in wide character format (ussually UTF-16, Unicode). Takes + * the currently set charset into consideration. + * + * If the native (UTF-16) encoding is used of the GIOP protocol is before 1.2, + * delegates functionality to "plain" {@link #read_wstring_UTF_16}. + */ + public String read_wstring() + { + // Native encoding or word oriented data. + if (wide_native || giop.until_inclusive(1, 1)) + return read_wstring_UTF_16(); + try + { + align(4); + + int n = b.readInt(); + byte[] s = new byte[n]; + b.read(s); + + return new String(s, 0, n, wide_charset); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Reads first length of the string and the all characters as an Unicode + * (UTF-16) characters. Mind that GIOP 1.1 has the extra null character at the + * end that must be discarded. + */ + public String read_wstring_UTF_16() + { + try + { + int p = 0; + int n = read_long(); + + if (n<0) + { + MARSHAL m = new MARSHAL("Negative string size"); + m.minor = Minor.Negative; + throw m; + } + + // The null terminator that is no longer present since 1.2 . + int nt = giop.since_inclusive(1, 2) ? 0 : 1; + + // Convert bytes to shorts. + n = n / 2; + + // Empty string. + if (n == 0) + return ""; + + char[] s = new char[n]; + + for (int i = 0; i < s.length; i++) + s[i] = (char) b.readShort(); + + // Check for the byte order marker here. + if (s[0] == 0xFEFF) + { + // Big endian encoding - do nothing, but move the pointer + // one position forward. + p = 1; + } + else if (s[0] == 0xFFFE) + { + // Little endian encoding, swap the bytes and move one + // position forward. + p = 1; + + for (int i = p; i < s.length; i++) + s[i] = swap(s[i]); + } + + // Discard the null terminator and, if needed, the endian marker. + String r = new String(s, p, n - nt - p); + return r; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.minor = Minor.EOF; + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Swap bytes in the character. + */ + public static char swap(char x) + { + int hi; + int lo; + + lo = x & 0xFF; + hi = (x >> 8) & 0xFF; + + return (char) ((lo << 8) | hi); + } + + /** + * Set the current code set context. + */ + public void setCodeSet(CodeSetServiceContext a_codeset) + { + this.codeset = a_codeset; + narrow_charset = CharSets_OSF.getName(codeset.char_data); + wide_charset = CharSets_OSF.getName(codeset.wide_char_data); + + narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data; + wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data; + } + + /** + * Get the current code set context. + */ + public CodeSetServiceContext getCodeSet() + { + return codeset; + } + + /** + * Read the object that is an instance of the given class. The current + * implementation delegates functionality to the parameterless + * {@link readObject()}. + * + * @param klass a class of that this object the instance is. + * + * @return the returned object. + */ + public org.omg.CORBA.Object read_Object(Class klass) + { + return read_Object(); + } + + /** + * Read a value type structure from the stream. + * + * OMG specification states the writing format is outside the scope of GIOP + * definition. This implementation uses java serialization mechanism, calling + * {@link ObjectInputStream#readObject} + * + * @return an value type structure, unmarshaled from the stream + */ + public Serializable read_Value() + { + return read_value(); + } + + /** + * Read the abstract interface. An abstract interface can be either CORBA + * value type or CORBA object and is returned as an abstract java.lang.Object. + * + * As specified in OMG specification, this reads a single boolean and then + * delegates either to {@link #read_Object()} (for false) or to + * {@link #read_Value()} (for true). + * + * @return an abstract interface, unmarshaled from the stream + */ + public java.lang.Object read_Abstract() + { + return read_abstract_interface(); + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_char_array(CharSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_char_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_wchar_array(WCharSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_wchar_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the char array to fit the newly read + * values. + * + * @param holder_value the existing char array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private char[] ensureArray(char[] holder_value, int offset, int length) + { + if (holder_value == null) + return new char[offset + length]; + else if (holder_value.length < offset + length) + { + char[] value = new char[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_ulong_array(ULongSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulong_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_long_array(LongSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulong_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the int array to fit the newly read values. + * + * @param holder_value the existing int array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private int[] ensureArray(int[] holder_value, int offset, int length) + { + if (holder_value == null) + return new int[offset + length]; + else if (holder_value.length < offset + length) + { + int[] value = new int[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_float_array(FloatSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_float_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the float array to fit the newly read + * values. + * + * @param holder_value the existing float array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private float[] ensureArray(float[] holder_value, int offset, int length) + { + if (holder_value == null) + return new float[offset + length]; + else if (holder_value.length < offset + length) + { + float[] value = new float[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_double_array(DoubleSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_double_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the double array to fit the newly read + * values. + * + * @param holder_value the existing double array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private double[] ensureArray(double[] holder_value, int offset, int length) + { + if (holder_value == null) + return new double[offset + length]; + else if (holder_value.length < offset + length) + { + double[] value = new double[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_short_array(ShortSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_short_array(holder.value, offset, length); + } + + /** {@inheritDoc} */ + public void read_ushort_array(UShortSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ushort_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the short array to fit the newly read + * values. + * + * @param holder_value the existing short array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private short[] ensureArray(short[] holder_value, int offset, int length) + { + if (holder_value == null) + return new short[offset + length]; + else if (holder_value.length < offset + length) + { + short[] value = new short[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_octet_array(OctetSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_octet_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the byte array to fit the newly read + * values. + * + * @param holder_value the existing byte array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private byte[] ensureArray(byte[] holder_value, int offset, int length) + { + if (holder_value == null) + return new byte[offset + length]; + else if (holder_value.length < offset + length) + { + byte[] value = new byte[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_longlong_array(LongLongSeqHolder holder, int offset, + int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_longlong_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_ulonglong_array(ULongLongSeqHolder holder, int offset, + int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulonglong_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the array of longs to fit the newly read + * values. + * + * @param holder_value the existing array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private long[] ensureArray(long[] holder_value, int offset, int length) + { + if (holder_value == null) + return new long[offset + length]; + else if (holder_value.length < offset + length) + { + long[] value = new long[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_boolean_array(BooleanSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_boolean_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the array of booleans to fit the newly read + * values. + * + * @param holder_value the existing array of booleans, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private boolean[] ensureArray(boolean[] holder_value, int offset, int length) + { + if (holder_value == null) + return new boolean[offset + length]; + else if (holder_value.length < offset + length) + { + boolean[] value = new boolean[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does not + * fit into the holder value field, that array must be resized. The + * implementation follows this rule. If the holder value field contains null, + * it is newly instantiated. + */ + public void read_any_array(AnySeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + for (int i = offset; i < offset + length; i++) + { + holder.value[i] = read_any(); + } + } + + /** + * If required, allocate or resize the array of Anys to fit the newly read + * values. + * + * @param holder_value the existing array of Anys, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private Any[] ensureArray(Any[] holder_value, int offset, int length) + { + if (holder_value == null) + return new Any[offset + length]; + else if (holder_value.length < offset + length) + { + Any[] value = new Any[offset + length]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * This method is required to represent the DataInputStream as a value type + * object. + * + * @return a single entity "IDL:omg.org/CORBA/DataInputStream:1.0", always. + */ + public String[] _truncatable_ids() + { + return new String[] { "IDL:omg.org/CORBA/DataInputStream:1.0" }; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/AbstractCdrOutput.java b/libjava/classpath/gnu/CORBA/CDR/AbstractCdrOutput.java new file mode 100644 index 0000000..7b4d5ec --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/AbstractCdrOutput.java @@ -0,0 +1,1047 @@ +/* AbstractCdrOutput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.BigDecimalHelper; +import gnu.CORBA.IOR; +import gnu.CORBA.IorProvider; +import gnu.CORBA.Minor; +import gnu.CORBA.TypeCodeHelper; +import gnu.CORBA.Unexpected; +import gnu.CORBA.Version; +import gnu.CORBA.GIOP.CharSets_OSF; +import gnu.CORBA.GIOP.CodeSetServiceContext; +import gnu.CORBA.typecodes.PrimitiveTypeCode; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.DataInputStream; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UserException; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * A simple CORBA CDR (common data representation) + * output stream, writing data into the + * given {@link java.io.OutputStream}. + * + * The same class also implements the {@link DataInputStream}, + * providing support for writing the value type objects + * in a user defined way. + * + * TODO This class uses 16 bits per Unicode character only, as it was until + * jdk 1.4 inclusive. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public abstract class AbstractCdrOutput + extends org.omg.CORBA_2_3.portable.OutputStream + implements org.omg.CORBA.DataOutputStream +{ + /** + * The runtime, associated with this stream. This field is only used when + * reading and writing value types and filled-in in gnu.CORBA.CDR.Vio. + */ + public transient gnuRuntime runtime; + + /** + * This instance is used to convert primitive data types into the + * byte sequences. + */ + protected AbstractDataOutput b; + + /** + * The associated orb, if any. + */ + protected ORB orb; + + /** + * The GIOP version. + */ + protected Version giop = new Version(1, 2); + + /** + * The code set information. + */ + protected CodeSetServiceContext codeset; + + /** + * The name of the currently used narrow charset. + */ + private String narrow_charset; + + /** + * The name of the currently used wide charset, null if + * the native wide charset is used. + */ + private String wide_charset; + + /** + * True if the native code set is used for narrow characters. + * If the set is native, no the intermediate Reader object + * is instantiated when writing characters. + */ + private boolean narrow_native; + + /** + * True if the native code set is used for wide characters. + * If the set is native, no the intermediate Reader object + * is instantiated when writing characters. + */ + private boolean wide_native; + + /** + * If true, the Little Endian encoding is used to write the + * data. Otherwise, the Big Endian encoding is used. + */ + private boolean little_endian; + + /** + * The stream whre the data are actually written. + */ + private java.io.OutputStream actual_stream; + + /** + * Creates the stream. + * + * @param writeTo a stream to write CORBA output to. + */ + public AbstractCdrOutput(java.io.OutputStream writeTo) + { + setOutputStream(writeTo); + setCodeSet(CodeSetServiceContext.STANDARD); + } + + /** + * Creates the stream, requiring the subsequent call + * of {@link #setOutputStream(java.io.OutputStream)}. + */ + public AbstractCdrOutput() + { + setCodeSet(CodeSetServiceContext.STANDARD); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public abstract void setOffset(int an_offset); + + /** + * Clone all important settings to another stream. + */ + public void cloneSettings(AbstractCdrOutput stream) + { + stream.setBigEndian(!little_endian); + stream.setCodeSet(getCodeSet()); + stream.setVersion(giop); + stream.setOrb(orb); + } + + /** + * Set the current code set context. + */ + public void setCodeSet(CodeSetServiceContext a_codeset) + { + this.codeset = a_codeset; + narrow_charset = CharSets_OSF.getName(codeset.char_data); + wide_charset = CharSets_OSF.getName(codeset.wide_char_data); + + narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data; + wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data; + } + + /** + * Get the current code set context. + */ + public CodeSetServiceContext getCodeSet() + { + return codeset; + } + + /** + * Set the orb, associated with this stream. + * @param an_orb + */ + public void setOrb(ORB an_orb) + { + orb = an_orb; + } + + /** + * Set the output stream that receives the CORBA output. + * + * @param writeTo the stream. + */ + public void setOutputStream(java.io.OutputStream writeTo) + { + if (little_endian) + b = new LittleEndianOutputStream(writeTo); + else + b = new BigEndianOutputStream(writeTo); + + actual_stream = writeTo; + } + + /** + * Set the GIOP version. Some data types are written differently + * for the different versions. The default version is 1.0 . + */ + public void setVersion(Version giop_version) + { + giop = giop_version; + } + + /** + * Specify if the stream should use the Big Endian (usual for java) + * or Little Encoding. The default is Big Endian. + * + * @param use_big_endian if true, use Big Endian, if false, + * use Little Endian. + */ + public void setBigEndian(boolean use_big_endian) + { + little_endian = !use_big_endian; + setOutputStream(actual_stream); + } + + /** + * Align the curretn position at the given natural boundary. + */ + public abstract void align(int boundary); + + /** + * Create the encapsulation stream, associated with the current + * stream. The encapsulated stream must be closed. When being + * closed, the encapsulation stream writes its buffer into + * this stream using the CORBA CDR encapsulation rules. + * + * It is not allowed to write to the current stream directly + * before the encapsulation stream is closed. + * + * The encoding (Big/Little Endian) inside the encapsulated + * sequence is the same as used into the parent stream. + * + * @return the encapsulated stream. + */ + public AbstractCdrOutput createEncapsulation() + { + return new EncapsulationStream(this, !little_endian); + } + + /** + * Return the associated {@link ORB}. + * @return the associated {@link ORB} or null is no such is set. + */ + public ORB orb() + { + return orb; + } + + /** + * Write a single byte. + * @param a byte to write (low 8 bits are written). + */ + public void write(int n) + { + try + { + b.write(n); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Write bytes directly into the underlying stream. + */ + public void write(byte[] x) + throws java.io.IOException + { + b.write(x); + } + + /** + * Write bytes directly into the underlying stream. + */ + public void write(byte[] x, int ofs, int len) + throws java.io.IOException + { + b.write(x, ofs, len); + } + + /** + * Following the specification, this is not implemented. + * Override to get the functionality. + */ + public void write_Context(Context context, ContextList contexts) + { + throw new NO_IMPLEMENT(); + } + + /** + * Read the CORBA object. The object is written form of the plain (not a + * string-encoded) IOR profile without the heading endian indicator. The + * responsible method for reading such data is {@link IOR.write_no_endian}. + * + * The null value is written as defined in OMG specification (zero length + * string, followed by an empty set of profiles). + */ + public void write_Object(org.omg.CORBA.Object x) + { + ORB w_orb = orb; + if (x instanceof IorProvider) + { + ((IorProvider) x).getIor()._write_no_endian(this); + return; + } + else if (x == null) + { + IOR.write_null(this); + return; + } + else if (x instanceof ObjectImpl) + { + Delegate d = ((ObjectImpl) x)._get_delegate(); + + if (d instanceof IorProvider) + { + ((IorProvider) d).getIor()._write_no_endian(this); + return; + } + else + { + ORB d_orb = d.orb(x); + if (d_orb != null) + w_orb = d_orb; + } + } + + // Either this is not an ObjectImpl or it has the + // unexpected delegate. Try to convert via ORBs + // object_to_string(). + if (w_orb != null) + { + IOR ior = IOR.parse(w_orb.object_to_string(x)); + ior._write_no_endian(this); + return; + } + else + throw new BAD_OPERATION( + "Please set the ORB for this stream, cannot write " + + x.getClass().getName()); + } + + /** + * Write the TypeCode. This implementation delegates functionality + * to {@link cdrTypeCode}. + * + * @param x a TypeCode to write. + */ + public void write_TypeCode(TypeCode x) + { + try + { + TypeCodeHelper.write(this, x); + } + catch (UserException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes an instance of the CORBA {@link Any}. + * This method writes the typecode, followed + * by value itself. In Any contains null + * (value not set), the {@link TCKind#tk_null} + * is written. + * + * @param x the {@link Any} to write. + */ + public void write_any(Any x) + { + Streamable value = x.extract_Streamable(); + if (value != null) + { + write_TypeCode(x.type()); + value._write(this); + } + else + { + PrimitiveTypeCode p = new PrimitiveTypeCode(TCKind.tk_null); + write_TypeCode(p); + } + } + + /** + * Writes a single byte, 0 for false, + * 1 for true. + * + * @param x the value to write + */ + public void write_boolean(boolean x) + { + try + { + b.write(x ? 1 : 0); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the boolean array. + * + * @param x array + * @param ofs offset + * @param len length. + */ + public void write_boolean_array(boolean[] x, int ofs, int len) + { + try + { + for (int i = ofs; i < ofs + len; i++) + { + b.write(x [ i ] ? 1 : 0); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the lower byte of the passed parameter. + * @param x the char to write + * + * It is effective to write more characters at once. + */ + public void write_char(char x) + { + try + { + if (narrow_native) + b.write(x); + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, narrow_charset); + ow.write(x); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the lower bytes of the passed array members. + * + * @param chars an array + * @param offsets offset + * @param length length + */ + public void write_char_array(char[] chars, int offset, int length) + { + try + { + if (narrow_native) + { + for (int i = offset; i < offset + length; i++) + { + b.write(chars [ i ]); + } + } + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, narrow_charset); + ow.write(chars, offset, length); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the double value (IEEE 754 format). + */ + public void write_double(double x) + { + try + { + align(8); + b.writeDouble(x); + } + catch (Exception ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of double values. + */ + public void write_double_array(double[] x, int ofs, int len) + { + try + { + align(8); + for (int i = ofs; i < ofs + len; i++) + { + b.writeDouble(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes CORBA fixed, storing all digits but not the scale. + * The end of the record on fixed can + * be determined from its last byte. + */ + public void write_fixed(BigDecimal fixed) + { + try + { + BigDecimalHelper.write(this, fixed); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + catch (BadKind ex) + { + Unexpected.error(ex); + } + } + + /** + * Write the float value (IEEE 754 format). + */ + public void write_float(float x) + { + try + { + align(4); + b.writeFloat(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes an array of the float values. + */ + public void write_float_array(float[] x, int ofs, int len) + { + try + { + align(4); + for (int i = ofs; i < ofs + len; i++) + { + b.writeFloat(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the integer value (CORBA long, four bytes, high byte first). + * @param x the value to write. + */ + public void write_long(int x) + { + try + { + align(4); + b.writeInt(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of integer (CORBA long) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_long_array(int[] x, int ofs, int len) + { + try + { + align(4); + for (int i = ofs; i < ofs + len; i++) + { + b.writeInt(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the long (CORBA long long) value, 8 bytes, + * high byte first. + * + * @param x the value to write. + */ + public void write_longlong(long x) + { + try + { + align(8); + b.writeLong(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of longs (CORBA long longs) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_longlong_array(long[] x, int ofs, int len) + { + try + { + align(8); + for (int i = ofs; i < ofs + len; i++) + { + b.writeLong(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes this byte. + * @param x + */ + public void write_octet(byte x) + { + try + { + b.writeByte(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of bytes (CORBA octets) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_octet_array(byte[] x, int ofs, int len) + { + try + { + b.write(x, ofs, len); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes first the size of array, and then the byte array using + * the {@link java.io.OutputStream#write(byte[]) }. The sequence + * being written is preceeded by the int, representing the array + * length. + */ + public void write_sequence(byte[] buf) + { + try + { + write_long(buf.length); + write(buf); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.minor = Minor.CDR; + t.initCause(ex); + throw t; + } + } + + /** + * Writes the contents of the provided stream. + * The sequence being written is preceeded by the int, + * representing the stream buffer length (the number of + * bytes being subsequently written). + */ + public void write_sequence(BufferedCdrOutput from) + { + try + { + write_long(from.buffer.size()); + from.buffer.writeTo(this); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.minor = Minor.CDR; + t.initCause(ex); + throw t; + } + } + + /** + * Writes the two byte integer (short), high byte first. + * + * @param x the integer to write. + */ + public void write_short(short x) + { + try + { + align(2); + b.writeShort(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of short (two byte integer) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_short_array(short[] x, int ofs, int len) + { + try + { + align(2); + for (int i = ofs; i < ofs + len; i++) + { + b.writeShort(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the string. This implementation first calls + * String.getBytes() and then writes the length of the returned + * array (as CORBA ulong) and the returned array itself. + * + * The encoding information, if previously set, is taken + * into consideration. + * + * @param x the string to write. + */ + public void write_string(String x) + { + try + { + byte[] ab = x.getBytes(narrow_charset); + write_long(ab.length + 1); + write(ab); + + // write null terminator. + write(0); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the CORBA unsigned long in the same way as CORBA long. + */ + public void write_ulong(int x) + { + write_long(x); + } + + /** + * Writes the array of CORBA unsigned longs in the same way as + * array of ordinary longs. + */ + public void write_ulong_array(int[] x, int ofs, int len) + { + write_long_array(x, ofs, len); + } + + /** + * Write the unsigned long long in the same way as an ordinary long long. + * + * @param x a value to write. + */ + public void write_ulonglong(long x) + { + write_longlong(x); + } + + /** + * Write the array of unsingel long longs in the same way + * an an array of the ordinary long longs. + */ + public void write_ulonglong_array(long[] x, int ofs, int len) + { + write_longlong_array(x, ofs, len); + } + + /** + * Write the unsigned short in the same way as an ordinary short. + */ + public void write_ushort(short x) + { + write_short(x); + } + + /** + * Write an array of unsigned short integersin the same way + * as an array of ordinary short integers. + */ + public void write_ushort_array(short[] x, int ofs, int len) + { + write_short_array(x, ofs, len); + } + + /** + * Writes the character as two byte short integer (Unicode value), high byte + * first. Writes in Big Endian, but never writes the endian indicator. + * + * The character is always written using the native UTF-16BE charset because + * its size under arbitrary encoding is not evident. + */ + public void write_wchar(char x) + { + try + { + if (giop.until_inclusive(1, 1)) + { + align(2); + + if (wide_native) + b.writeShort(x); + else + { + OutputStreamWriter ow = new OutputStreamWriter( + (OutputStream) b, wide_charset); + ow.write(x); + ow.flush(); + } + } + else if (wide_native) + { + b.writeByte(2); + b.writeChar(x); + } + else + { + String encoded = new String(new char[] { x }); + byte[] bytes = encoded.getBytes(wide_charset); + b.write(bytes.length + 2); + b.write(bytes); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Write the array of wide chars. + * + * @param chars the array of wide chars + * @param offset offset + * @param length length + * + * The char array is always written using the native UTF-16BE charset because + * the character size under arbitrary encoding is not evident. + */ + public void write_wchar_array(char[] chars, int offset, int length) + { + try + { + if (giop.until_inclusive(1, 1)) + align(2); + + if (wide_native) + { + for (int i = offset; i < offset + length; i++) + { + b.writeShort(chars [ i ]); + } + } + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, wide_charset); + ow.write(chars, offset, length); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the length of the string in bytes (not characters) and + * then all characters as two byte unicode chars. Adds the + * Big Endian indicator, 0xFFFE, at the beginning and null wide char at + * the end. + * + * @param x the string to write. + */ + public void write_wstring(String x) + { + try + { + if (giop.since_inclusive(1, 2)) + { + byte[] bytes = x.getBytes(wide_charset); + write_sequence(bytes); + } + else + { + // Encoding with null terminator always in UTF-16. + // The wide null terminator needs extra two bytes. + write_long(2 * x.length() + 2); + + for (int i = 0; i < x.length(); i++) + { + b.writeShort(x.charAt(i)); + } + + // Write null terminator. + b.writeShort(0); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** {@inheritDoc} */ + public void write_any_array(Any[] anys, int offset, int length) + { + for (int i = offset; i < offset + length; i++) + { + write_any(anys [ i ]); + } + } + + public String[] _truncatable_ids() + { + /**@todo Implement this org.omg.CORBA.portable.ValueBase abstract method*/ + throw new java.lang.UnsupportedOperationException("Method _truncatable_ids() not yet implemented."); + } + + /** {@inheritDoc} */ + public void write_Abstract(java.lang.Object value) + { + write_abstract_interface(value); + } + + /** {@inheritDoc} */ + public void write_Value(Serializable value) + { + write_value(value); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/AbstractDataInput.java b/libjava/classpath/gnu/CORBA/CDR/AbstractDataInput.java new file mode 100644 index 0000000..4d120fa --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/AbstractDataInput.java @@ -0,0 +1,392 @@ +/* AbstractDataInput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import java.io.IOException; + +/** + * Some data input stream that can be either Big or + * Little Endian. + * + * This class reuses code from GNU Classpath DataInputStream. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface AbstractDataInput +{ + /** + * This method reads bytes from the underlying stream into the specified + * byte array buffer. It will attempt to fill the buffer completely, but + * may return a short count if there is insufficient data remaining to be + * read to fill the buffer. + * + * @param b The buffer into which bytes will be read. + * + * @return The actual number of bytes read, or -1 if end of stream reached + * before reading any bytes. + * + * @exception IOException If an error occurs. + */ + int read(byte[] b) + throws IOException; + + /** + * This method reads bytes from the underlying stream into the specified + * byte array buffer. It will attempt to read len bytes and + * will start storing them at position off into the buffer. + * This method can return a short count if there is insufficient data + * remaining to be read to complete the desired read length. + * + * @param b The buffer into which bytes will be read. + * @param off The offset into the buffer to start storing bytes. + * @param len The requested number of bytes to read. + * + * @return The actual number of bytes read, or -1 if end of stream reached + * before reading any bytes. + * + * @exception IOException If an error occurs. + */ + int read(byte[] b, int off, int len) + throws IOException; + + /** + * This method reads a Java boolean value from an input stream. It does + * so by reading a single byte of data. If that byte is zero, then the + * value returned is false. If the byte is non-zero, then + * the value returned is true. + *

+ * This method can read a boolean written by an object + * implementing the writeBoolean() method in the + * DataOutput interface. + * + * @return The boolean value read + * + * @exception EOFException If end of file is reached before reading + * the boolean + * @exception IOException If any other error occurs + * + * @see DataOutput#writeBoolean + */ + boolean readBoolean() + throws IOException; + + /** + * This method reads a Java byte value from an input stream. The value + * is in the range of -128 to 127. + *

+ * This method can read a byte written by an object + * implementing the writeByte() method in the + * DataOutput interface. + * + * @return The byte value read + * + * @exception EOFException If end of file is reached before reading the byte + * @exception IOException If any other error occurs + * + * @see DataOutput#writeByte + */ + byte readByte() + throws IOException; + + /** + * This method reads a Java char value from an input stream. + * It operates by reading two bytes from the stream and converting them to + * a single 16-bit Java char. The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 and byte2 + * represent the first and second byte read from the stream + * respectively, they will be transformed to a char in + * the following manner: + *

+ * (char)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF) + *

+ * This method can read a char written by an object + * implementing the writeChar() method in the + * DataOutput interface. + * + * @return The char value read + * + * @exception EOFException If end of file is reached before reading the char + * @exception IOException If any other error occurs + * + * @see DataOutput#writeChar + */ + char readChar() + throws IOException; + + /** + * This method reads a Java double value from an input stream. It operates + * by first reading a long value from the stream by calling the + * readLong() method in this interface, then converts + * that long to a double using the + * longBitsToDouble method in the class + * java.lang.Double + *

+ * This method can read a double written by an object + * implementing the writeDouble() method in the + * DataOutput interface. + * + * @return The double value read + * + * @exception EOFException If end of file is reached before reading + * the double + * @exception IOException If any other error occurs + * + * @see DataOutput#writeDouble + * @see java.lang.Double#longBitsToDouble + */ + double readDouble() + throws IOException; + + /** + * This method reads a Java float value from an input stream. It + * operates by first reading an int value from the + * stream by calling the readInt() method in this + * interface, then converts that int to a + * float using the intBitsToFloat method + * in the class java.lang.Float + *

+ * This method can read a float written by an object + * implementing the writeFloat() method in the + * DataOutput interface. + * + * @return The float value read + * + * @exception EOFException If end of file is reached before reading the float + * @exception IOException If any other error occurs + * + * @see DataOutput#writeFloat + * @see java.lang.Float#intBitsToFloat + */ + float readFloat() + throws IOException; + + /** + * This method reads raw bytes into the passed array until the array is + * full. Note that this method blocks until the data is available and + * throws an exception if there is not enough data left in the stream to + * fill the buffer. Note also that zero length buffers are permitted. + * In this case, the method will return immediately without reading any + * bytes from the stream. + * + * @param b The buffer into which to read the data + * + * @exception EOFException If end of file is reached before filling the + * buffer + * @exception IOException If any other error occurs + */ + void readFully(byte[] b) + throws IOException; + + /** + * This method reads a Java int value from an input stream + * It operates by reading four bytes from the stream and converting them to + * a single Java int. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 through byte4 represent + * the first four bytes read from the stream, they will be + * transformed to an int in the following manner: + *

+ * (int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + + * ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF))) + *

+ * The value returned is in the range of -2147483648 to 2147483647. + *

+ * This method can read an int written by an object + * implementing the writeInt() method in the + * DataOutput interface. + * + * @return The int value read + * + * @exception EOFException If end of file is reached before reading the int + * @exception IOException If any other error occurs + * + * @see DataOutput#writeInt + */ + int readInt() + throws IOException; + + /** + * This method reads a Java long value from an input stream + * It operates by reading eight bytes from the stream and converting them to + * a single Java long. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 through byte8 represent + * the first eight bytes read from the stream, they will be + * transformed to an long in the following manner: + *

+ * (long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + + * ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + + * ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + + * ((byte7 & 0xFF) << 8) + (byte8 & 0xFF))) + * + *

+ * The value returned is in the range of -9223372036854775808 to + * 9223372036854775807. + *

+ * This method can read an long written by an object + * implementing the writeLong() method in the + * DataOutput interface. + * + * @return The long value read + * + * @exception EOFException If end of file is reached before reading the long + * @exception IOException If any other error occurs + * + * @see DataOutput#writeLong + */ + long readLong() + throws IOException; + + /** + * This method reads a signed 16-bit value into a Java in from the + * stream. It operates by reading two bytes from the stream and + * converting them to a single 16-bit Java short. The + * two bytes are stored most significant byte first (i.e., "big + * endian") regardless of the native host byte ordering. + *

+ * As an example, if byte1 and byte2 + * represent the first and second byte read from the stream + * respectively, they will be transformed to a short. in + * the following manner: + *

+ * (short)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF)) + *

+ * The value returned is in the range of -32768 to 32767. + *

+ * This method can read a short written by an object + * implementing the writeShort() method in the + * DataOutput interface. + * + * @return The short value read + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeShort + */ + short readShort() + throws IOException; + + /** + * This method reads 8 unsigned bits into a Java int + * value from the stream. The value returned is in the range of 0 to + * 255. + *

+ * This method can read an unsigned byte written by an object + * implementing the writeUnsignedByte() method in the + * DataOutput interface. + * + * @return The unsigned bytes value read as a Java int. + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeByte + */ + int readUnsignedByte() + throws IOException; + + /** + * This method reads 16 unsigned bits into a Java int value from the stream. + * It operates by reading two bytes from the stream and converting them to + * a single Java int The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + *

+ * As an example, if byte1 and byte2 + * represent the first and second byte read from the stream + * respectively, they will be transformed to an int in + * the following manner: + *

+ * (int)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF)) + *

+ * The value returned is in the range of 0 to 65535. + *

+ * This method can read an unsigned short written by an object + * implementing the writeUnsignedShort() method in the + * DataOutput interface. + * + * @return The unsigned short value read as a Java int + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeShort + */ + int readUnsignedShort() + throws IOException; + + /** + * Read a single byte. + * + * @return a byte, extracted from the stream or -1 if + * EOF has been reached. + * @throws IOException + */ + public int read() + throws IOException; + + /** + * This method attempts to skip and discard the specified number of bytes + * in the input stream. It may actually skip fewer bytes than requested. + * This method will not skip any bytes if passed a negative number of bytes + * to skip. + * + * @param n The requested number of bytes to skip. + * + * @return The requested number of bytes to skip. + * + * @exception IOException If an error occurs. + * @specnote The JDK docs claim that this returns the number of bytes + * actually skipped. The JCL claims that this method can throw an + * EOFException. Neither of these appear to be true in the JDK 1.3's + * implementation. This tries to implement the actual JDK behaviour. + */ + int skipBytes(int n) + throws IOException; +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/AbstractDataOutput.java b/libjava/classpath/gnu/CORBA/CDR/AbstractDataOutput.java new file mode 100644 index 0000000..e37c0cb --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/AbstractDataOutput.java @@ -0,0 +1,185 @@ +/* AbstractDataOutput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import java.io.IOException; + +/** + * An abstract data output stream that could write data in either + * Big Endian or Little Endian format. + * + * This class reuses code from GNU Classpath DataOutputStream. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface AbstractDataOutput +{ + /** + * This method flushes any unwritten bytes to the underlying stream. + * + * @exception IOException If an error occurs. + */ + void flush() + throws IOException; + + /** + * This method writes the specified byte (passed as an int) + * to the underlying output stream. + * + * @param value The byte to write, passed as an int. + * + * @exception IOException If an error occurs. + */ + void write(int value) + throws IOException; + + /** + * This method writes len bytes from the specified byte array + * buf starting at position offset into the + * buffer to the underlying output stream. + * + * @param buf The byte array to write from. + * @param offset The index into the byte array to start writing from. + * @param len The number of bytes to write. + * + * @exception IOException If an error occurs. + */ + void write(byte[] buf, int offset, int len) + throws IOException; + + /** + * Write the complete byte array. + * @throws IOException + */ + void write(byte[] buf) + throws IOException; + + /** + * This method writes a Java boolean value to an output stream. If + * value is true, a byte with the value of + * 1 will be written, otherwise a byte with the value of 0 will be + * written. + * + * The value written can be read using the readBoolean + * method in DataInput. + * + * @param value The boolean value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeBoolean(boolean value) + throws IOException; + + /** + * This method writes a Java byte value to an output stream. The + * byte to be written will be in the lowest 8 bits of the + * int value passed. + * + * The value written can be read using the readByte or + * readUnsignedByte methods in DataInput. + * + * @param value The byte to write to the stream, passed as + * the low eight bits of an int. + * + * @exception IOException If an error occurs + */ + void writeByte(int value) + throws IOException; + + /** + * This method writes a Java short value to an output stream. The + * char to be written will be in the lowest 16 bits of the int + * value passed. + * + * @exception IOException If an error occurs + */ + void writeShort(int value) + throws IOException; + + /** + * This method writes a Java char value to an output stream. The + * char to be written will be in the lowest 16 bits of the int + * value passed. + * + * @exception IOException If an error occurs + */ + void writeChar(int value) + throws IOException; + + /** + * This method writes a Java int value to an output stream. + * + * @param value The int value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeInt(int value) + throws IOException; + + /** + * This method writes a Java long value to an output stream. + * + * @param value The long value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeLong(long value) + throws IOException; + + /** + * This method writes a Java float value to the stream. + * @param value The float value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeFloat(float value) + throws IOException; + + /** + * This method writes a Java double value to the stream. + * + * @param value The double value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeDouble(double value) + throws IOException; +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/AligningInput.java b/libjava/classpath/gnu/CORBA/CDR/AligningInput.java new file mode 100644 index 0000000..e271062 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/AligningInput.java @@ -0,0 +1,131 @@ +/* AligningInput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import java.io.ByteArrayInputStream; + +import org.omg.CORBA.BAD_PARAM; + +/** + * The input stream with the possibility to align on the + * word (arbitrary size) boundary. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class AligningInput + extends ByteArrayInputStream +{ + /** + * The alignment offset. + */ + private int offset = 0; + + /** + * Create a stream, reading form the given buffer. + * + * @param a_buffer a buffer to read from. + */ + public AligningInput(byte[] a_buffer) + { + super(a_buffer); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + offset = an_offset; + } + + /** + * Skip several bytes, aligning the internal pointer on the + * selected boundary. + * + * @throws BAD_PARAM, minor code 0, the alignment is not possible, + * usually due the wrong parameter value. + */ + public void align(int alignment) + { + try + { + int d = (pos + offset) % alignment; + if (d > 0) + { + skip(alignment - d); + } + } + catch (Exception ex) + { + BAD_PARAM p = new BAD_PARAM("Unable to align at " + alignment); + p.initCause(ex); + throw p; + } + } + + /** + * Get the byte buffer, from where the data are read. + */ + public byte[] getBuffer() + { + return buf; + } + + /** + * Get the current position in the buffer. + * + * @return The position in the buffer, taking offset into consideration. + */ + public int getPosition() + { + return pos + offset; + } + + /** + * Jump to the given position, taking offset into consideration. + */ + public void seek(int position) + { + if (position < offset || position > (count+offset)) + throw new ArrayIndexOutOfBoundsException(position + + " is out of valid ["+offset+".." + (count+offset) + "[ range"); + pos = position - offset; + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/AligningOutput.java b/libjava/classpath/gnu/CORBA/CDR/AligningOutput.java new file mode 100644 index 0000000..135f75a --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/AligningOutput.java @@ -0,0 +1,148 @@ +/* AligningOutput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import java.io.ByteArrayOutputStream; + +import org.omg.CORBA.BAD_PARAM; + +/** + * The input stream with the possibility to align on the + * word (arbitrary size) boundary. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class AligningOutput + extends ByteArrayOutputStream +{ + /** + * The alignment offset. + */ + private int offset = 0; + + /** + * Create a stream with the default intial buffer size. + */ + public AligningOutput() + { + } + + /** + * Create a stream with the given intial buffer size. + */ + public AligningOutput(int initial_size) + { + super(initial_size); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + offset = an_offset; + } + + /** + * Skip several bytes, aligning the internal pointer on the + * selected boundary. + * + * @throws BAD_PARAM, minor code 0, the alignment is not possible, + * usually due the wrong parameter value. + */ + public void align(int alignment) + { + try + { + int d = (count + offset) % alignment; + if (d > 0) + { + skip(alignment - d); + } + } + catch (Exception ex) + { + BAD_PARAM p = new BAD_PARAM("Unable to align at " + alignment); + p.initCause(ex); + throw p; + } + } + + /** + * Write the specified number of zero bytes. + * + * @param bytes the number of zero bytes to write. + */ + public void skip(int bytes) + { + for (int i = 0; i < bytes; i++) + { + write(0); + } + } + + /** + * Get the current position in the buffer. + * + * @return The position in the buffer, taking offset into consideration. + */ + public int getPosition() + { + return size()+offset; + } + + /** + * Seek to the given position (not in use). + */ + public void seek(int position) + { + count = position - offset; + } + + /** + * Get the buffer without copying it. Use with care. + */ + public byte[] getBuffer() + { + return buf; + } + + +} diff --git a/libjava/classpath/gnu/CORBA/CDR/ArrayValueHelper.java b/libjava/classpath/gnu/CORBA/CDR/ArrayValueHelper.java new file mode 100644 index 0000000..7a4d9c5 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/ArrayValueHelper.java @@ -0,0 +1,254 @@ +/* ArrayValueHelper.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.ObjectCreator; + +import org.omg.CORBA.BooleanSeqHelper; +import org.omg.CORBA.CharSeqHelper; +import org.omg.CORBA.DoubleSeqHelper; +import org.omg.CORBA.FloatSeqHelper; +import org.omg.CORBA.LongLongSeqHelper; +import org.omg.CORBA.LongSeqHelper; +import org.omg.CORBA.OctetSeqHelper; +import org.omg.CORBA.ShortSeqHelper; +import org.omg.CORBA.portable.BoxedValueHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +import java.io.Serializable; +import java.lang.reflect.Array; +import java.rmi.Remote; + +import javax.rmi.CORBA.Util; +import javax.rmi.CORBA.ValueHandler; + +/** + * Writes arrays as a boxed value types. A single instance is used to write a + * single array. This class is only used with RMI/IIOP, to handle array boxed + * values. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +class ArrayValueHelper + implements BoxedValueHelper +{ + /** + * The value handler (one for all instances). + */ + static ValueHandler handler = Util.createValueHandler(); + + /** + * A class of the array being written. + */ + Class arrayClass; + + /** + * The array component class. + */ + Class component; + + /** + * The array component repository Id. + */ + String componentId; + + /** + * If true, the array members are written as objects rather than as values. + * True for Remotes and CORBA objects. + */ + boolean written_as_object() + { + return org.omg.CORBA.Object.class.isAssignableFrom(component) + || Remote.class.isAssignableFrom(component); + } + + /** + * Creates the instance of the helper to write this specific array class. + */ + ArrayValueHelper(Class an_arrayClass) + { + arrayClass = an_arrayClass; + } + + /** + * Get the array repository Id that will be the RMI repository id. + */ + public String get_id() + { + return ObjectCreator.getRepositoryId(arrayClass); + } + + /** + * Read the array from the input stream. + */ + public Serializable read_value(InputStream input) + { + if (input instanceof HeadlessInput) + { + ((HeadlessInput) input).subsequentCalls = true; + } + + component = arrayClass.getComponentType(); + + if (component.equals(byte.class)) + return OctetSeqHelper.read(input); + else if (component.equals(String.class)) + { + // String array is optimized because this may be frequent. + String[] s = new String[input.read_long()]; + + for (int i = 0; i < s.length; i++) + s[i] = (String) Vio.read(input, Vio.m_StringValueHelper); + return s; + } + else if (component.equals(int.class)) + return LongSeqHelper.read(input); + else if (component.equals(long.class)) + return LongLongSeqHelper.read(input); + else if (component.equals(double.class)) + return DoubleSeqHelper.read(input); + else if (component.equals(float.class)) + return FloatSeqHelper.read(input); + else if (component.equals(boolean.class)) + return BooleanSeqHelper.read(input); + else if (component.equals(short.class)) + return ShortSeqHelper.read(input); + else if (component.equals(char.class)) + return CharSeqHelper.read(input); + else + { + // Read others, use reflection. + int n = input.read_long(); + + gnuValueStream s = null; + + Serializable array = (Serializable) Array.newInstance(component, n); + if (written_as_object()) + for (int i = 0; i < n; i++) + { + gnuRuntime g; + int position; + if (input instanceof gnuValueStream) + { + s = (gnuValueStream) input; + g = s.getRunTime(); + position = s.getPosition(); + } + else + { + g = null; + position = -1; + } + + if (input instanceof HeadlessInput) + ((HeadlessInput) input).subsequentCalls = true; + + Object o = handler.readValue(input, position, component, null, g); + Array.set(array, i, o); + } + else + for (int i = 0; i < n; i++) + Array.set(array, i, Vio.read(input, component)); + return array; + } + } + + /** + * Write the array to the input stream. + */ + public void write_value(OutputStream output, Serializable value) + { + if (output instanceof gnuValueStream) + { + gnuRuntime r = ((gnuValueStream) output).getRunTime(); + if (r != null) + r.target = null; + } + + if (value instanceof byte[]) + OctetSeqHelper.write(output, (byte[]) value); + else if (value instanceof String[]) + { + String[] s = (String[]) value; + output.write_long(s.length); + for (int i = 0; i < s.length; i++) + Vio.write(output, s[i], Vio.m_StringValueHelper); + } + else if (value instanceof int[]) + LongSeqHelper.write(output, (int[]) value); + else if (value instanceof long[]) + LongLongSeqHelper.write(output, (long[]) value); + else if (value instanceof double[]) + DoubleSeqHelper.write(output, (double[]) value); + else if (value instanceof float[]) + FloatSeqHelper.write(output, (float[]) value); + else if (value instanceof boolean[]) + BooleanSeqHelper.write(output, (boolean[]) value); + else if (value instanceof short[]) + ShortSeqHelper.write(output, (short[]) value); + else if (value instanceof char[]) + CharSeqHelper.write(output, (char[]) value); + else + { + // Write others, use reflection. + component = arrayClass.getComponentType(); + + int n = Array.getLength(value); + output.write_long(n); + if (written_as_object()) + for (int i = 0; i < n; i++) + { + Object o = Array.get(value, i); + if (o == null) + output.write_Object(null); + else + // CORBA objects have another notation. + handler.writeValue(output, (Serializable) o); + } + else + { + for (int i = 0; i < n; i++) + Vio.write(output, (Serializable) Array.get(value, i), + component); + } + + } + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java b/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java index bc01939..1559d75 100644 --- a/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java +++ b/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java @@ -49,7 +49,7 @@ import java.io.InputStream; */ public class BigEndianInputStream extends DataInputStream - implements abstractDataInputStream + implements AbstractDataInput { /** * Delegates to the parent constructor. diff --git a/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java index e0aa7da..7d3b02e 100644 --- a/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java +++ b/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java @@ -50,7 +50,7 @@ import java.io.OutputStream; */ public class BigEndianOutputStream extends DataOutputStream - implements abstractDataOutputStream + implements AbstractDataOutput { /** * Delegate functionality to the parent constructor. diff --git a/libjava/classpath/gnu/CORBA/CDR/BufferedCdrOutput.java b/libjava/classpath/gnu/CORBA/CDR/BufferedCdrOutput.java new file mode 100644 index 0000000..69bf95b --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/BufferedCdrOutput.java @@ -0,0 +1,156 @@ +/* BufferedCdrOutput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import java.io.ByteArrayOutputStream; + +/** + * A CORBA output stream, writing data into the internal buffer ({@link ByteArrayOutputStream}). + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class BufferedCdrOutput + extends AbstractCdrOutput + implements gnuValueStream +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The byte buffer. + */ + public final AligningOutput buffer; + + /** + * Creates the instance with the given initial buffer size. + * + * @param bufSize the buffer size. + */ + public BufferedCdrOutput(int bufSize) + { + buffer = new AligningOutput(bufSize); + setOutputStream(buffer); + } + + /** + * Creates the instance with the default buffer size. + */ + public BufferedCdrOutput() + { + buffer = new AligningOutput(); + setOutputStream(buffer); + } + + /** + * Set the alignment offset, if the index of the first byte in the stream is + * different from 0. + */ + public void setOffset(int an_offset) + { + buffer.setOffset(an_offset); + } + + /** + * Align the curretn position at the given natural boundary. + */ + public void align(int boundary) + { + buffer.align(boundary); + } + + /** + * Return the input stream that reads the previously written values. + */ + public org.omg.CORBA.portable.InputStream create_input_stream() + { + BufferredCdrInput in = new BufferredCdrInput(buffer.toByteArray()); + in.setOrb(orb); + + in.setVersion(giop); + in.setCodeSet(getCodeSet()); + + return in; + } + + /** + * Resets (clears) the buffer. + */ + public void reset() + { + buffer.reset(); + setOutputStream(buffer); + } + + /** + * Get the current position in the buffer. + * + * @return The position in the buffer, taking offset into consideration. + */ + public int getPosition() + { + return buffer.getPosition(); + } + + /** + * Get the associated RunTime. + */ + public gnuRuntime getRunTime() + { + return runtime; + } + + /** + * Replace the instance of RunTime. + */ + public void setRunTime(gnuRuntime a_runtime) + { + runtime = a_runtime; + } + + /** + * Seek to the given position. + */ + public void seek(int position) + { + buffer.seek(position); + } + +} diff --git a/libjava/classpath/gnu/CORBA/CDR/BufferredCdrInput.java b/libjava/classpath/gnu/CORBA/CDR/BufferredCdrInput.java new file mode 100644 index 0000000..f0159a8 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/BufferredCdrInput.java @@ -0,0 +1,153 @@ +/* BufferredCdrInput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + + +/** + * The CDR input stream that reads data from the byte buffer. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class BufferredCdrInput + extends AbstractCdrInput + implements gnuValueStream +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The byte array input stream to read data from. + */ + public final AligningInput buffer; + + /** + * Creates the CDR input stream that reads from the given buffer + * array. + * + * @param a_buffer an array to read from. + */ + public BufferredCdrInput(byte[] a_buffer) + { + buffer = new AligningInput(a_buffer); + setInputStream(buffer); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int offset) + { + buffer.setOffset(offset); + } + + /** + * Skip several bytes, aligning the internal pointer on the + * selected boundary. + */ + public void align(int alignment) + { + buffer.align(alignment); + } + + /** + * Mark the current position. + * @param ahead + */ + public synchronized void mark(int ahead) + { + buffer.mark(ahead); + } + + /** + * Checks if marking is supported. + * @return + */ + public boolean markSupported() + { + return buffer.markSupported(); + } + + /** + * Resets the stream to the previously marked position. + */ + public void reset() + { + buffer.reset(); + setInputStream(buffer); + } + + /** + * Get the current position in the buffer. + * + * @return The position in the buffer, taking offset into consideration. + */ + public int getPosition() + { + return buffer.getPosition(); + } + + /** + * Jump to the given position, taking offset into consideration. + */ + public void seek(int position) + { + buffer.seek(position); + setInputStream(buffer); + } + + /** + * Get the associated RunTime. + */ + public gnuRuntime getRunTime() + { + return runtime; + } + + /** + * Replace the instance of RunTime. + */ + public void setRunTime(gnuRuntime a_runtime) + { + runtime = a_runtime; + } + +} diff --git a/libjava/classpath/gnu/CORBA/CDR/EncapsulationStream.java b/libjava/classpath/gnu/CORBA/CDR/EncapsulationStream.java new file mode 100644 index 0000000..4945d9c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/EncapsulationStream.java @@ -0,0 +1,146 @@ +/* EncapsulationOutput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import java.io.IOException; + +/** + * The encapsulated data, as they are defined by CORBA specification. + * This includes the extra 0 byte (Big endian) in the beginning. + * When written to the parent steam, the encapsulated data are preceeded + * by the data length in bytes. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class EncapsulationStream + extends AbstractCdrOutput +{ + /** + * The Big Endian (most siginificant byte first flag). + */ + public static final byte BIG_ENDIAN = 0; + + /** + * The Little Endian (least siginificant byte first flag). + */ + public static final byte LITTLE_ENDIAN = 1; + + /** + * The byte buffer. + */ + public final AligningOutput buffer; + + /** + * The stream, where the data are being encapsulated. + */ + public final org.omg.CORBA.portable.OutputStream parent; + + /** + * Create the EncapsulationOutput with the given parent stream + * and the specified encoding. + */ + public EncapsulationStream(org.omg.CORBA.portable.OutputStream _parent, + boolean use_big_endian) + { + super(); + buffer = new AligningOutput(); + setOutputStream(buffer); + parent = _parent; + write(use_big_endian?BIG_ENDIAN:LITTLE_ENDIAN); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + buffer.setOffset(an_offset); + } + + /** + * Align the curretn position at the given natural boundary. + */ + public void align(int boundary) + { + buffer.align(boundary); + } + + /** + * Writes the content of the encapsulated output into the parent + * buffer. + */ + public void close() + { + try + { + parent.write_long(buffer.size()); + buffer.writeTo(parent); + } + catch (IOException ex) + { + InternalError err = new InternalError(); + err.initCause(ex); + throw err; + } + } + + /** + * Return the input stream that reads the previously written values. + */ + public org.omg.CORBA.portable.InputStream create_input_stream() + { + BufferredCdrInput in = new BufferredCdrInput(buffer.toByteArray()); + in.setOrb(orb); + + in.setVersion(giop); + in.setCodeSet(getCodeSet()); + + return in; + } + + /** + * Resets (clears) the buffer. + */ + public void reset() + { + buffer.reset(); + setOutputStream(buffer); + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/HeadlessInput.java b/libjava/classpath/gnu/CORBA/CDR/HeadlessInput.java new file mode 100644 index 0000000..0c18daf --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/HeadlessInput.java @@ -0,0 +1,749 @@ +/* HeadlessInput.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.Minor; + +import org.omg.CORBA.Any; +import org.omg.CORBA.AnySeqHolder; +import org.omg.CORBA.BooleanSeqHolder; +import org.omg.CORBA.CharSeqHolder; +import org.omg.CORBA.Context; +import org.omg.CORBA.DataInputStream; +import org.omg.CORBA.DoubleSeqHolder; +import org.omg.CORBA.FloatSeqHolder; +import org.omg.CORBA.LongLongSeqHolder; +import org.omg.CORBA.LongSeqHolder; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.OctetSeqHolder; +import org.omg.CORBA.Principal; +import org.omg.CORBA.ShortSeqHolder; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.ULongLongSeqHolder; +import org.omg.CORBA.ULongSeqHolder; +import org.omg.CORBA.UShortSeqHolder; +import org.omg.CORBA.WCharSeqHolder; +import org.omg.CORBA.portable.BoxedValueHelper; +import org.omg.CORBA.portable.InputStream; + +import java.io.IOException; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * Substitutes the main stream in factories when the header is already behind. + * Overrides methods that may be invoked from the factory, forcing not to read + * the header if called first time on this stream. + * + * This stream reverts to default behavior if one or more call are made (reading + * value types that are nested fields of the value type). + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class HeadlessInput + extends org.omg.CORBA_2_3.portable.InputStream + implements DataInputStream, gnuValueStream +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Indicates that no positional information is available. + */ + static final int NONE = -1; + + /** + * If true, this is not the first call. + */ + public boolean subsequentCalls; + + /** + * The enclosed stream. + */ + final BufferredCdrInput stream; + + /** + * Create an instance, reading from the given buffer. + * + * @param a_stram a stream from where the data will be read. + * @param inheritSettings a stream from that endian and other settings are + * inherited. + */ + public HeadlessInput(BufferredCdrInput a_stream, InputStream inheritSettings) + { + stream = a_stream; + + if (inheritSettings instanceof AbstractCdrInput) + { + AbstractCdrInput t = (AbstractCdrInput) inheritSettings; + t.cloneSettings(stream); + } + else if (stream.orb() == null) + stream.setOrb(inheritSettings.orb()); + + if (inheritSettings instanceof gnuValueStream + && stream.getRunTime() == null) + { + stream.setRunTime(((gnuValueStream) inheritSettings).getRunTime()); + } + } + + /** + * Tries to read using boxed value helper. + */ + public Serializable read_value(BoxedValueHelper helper) + { + if (subsequentCalls) + return stream.read_value(helper); + else + { + subsequentCalls = true; + return helper.read_value(this); + } + } + + /** + * Tries to locate a factory using repository id. + */ + public Serializable read_value(String repository_id) + { + if (subsequentCalls) + return stream.read_value(repository_id); + else + { + subsequentCalls = true; + Serializable value = (Serializable) Vio.readValue(this, NONE, null, + null, repository_id, null, null); + return value; + } + } + + /** + * Try to read when having an unitialised value. + */ + public Serializable read_value(Serializable value) + { + if (subsequentCalls) + return stream.read_value(value); + else + { + subsequentCalls = true; + value = (Serializable) Vio.readValue(this, NONE, value, null, null, + null, null); + return value; + } + } + + /** + * Try to read when having an unitialised value. + */ + public Serializable read_value(Class clz) + { + if (subsequentCalls) + return stream.read_value(clz); + else + { + try + { + subsequentCalls = true; + Serializable value = (Serializable) Vio.instantiateAnyWay(clz); + value = (Serializable) Vio.readValue(this, NONE, value, null, null, + null, null); + return value; + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("Can't read an instance of " + + clz.getName()); + m.minor = Minor.Value; + m.initCause(ex); + throw m; + } + } + } + + /** + * Delegates functionality to the underlying stream. + */ + public int available() + throws IOException + { + return stream.available(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void close() + throws IOException + { + stream.close(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void mark(int readlimit) + { + stream.mark(readlimit); + } + + /** + * Delegates functionality to the underlying stream. + */ + public boolean markSupported() + { + return stream.markSupported(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public ORB orb() + { + return stream.orb(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Object read_abstract_interface() + { + return stream.read_abstract_interface(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Object read_abstract_interface(Class clz) + { + return stream.read_abstract_interface(clz); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Any read_any() + { + return stream.read_any(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_boolean_array(boolean[] value, int offset, int length) + { + stream.read_boolean_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public boolean read_boolean() + { + return stream.read_boolean(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_char_array(char[] value, int offset, int length) + { + stream.read_char_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public char read_char() + { + return stream.read_char(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Context read_Context() + { + return stream.read_Context(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_double_array(double[] value, int offset, int length) + { + stream.read_double_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public double read_double() + { + return stream.read_double(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public BigDecimal read_fixed() + { + return stream.read_fixed(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_float_array(float[] value, int offset, int length) + { + stream.read_float_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public float read_float() + { + return stream.read_float(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_long_array(int[] value, int offset, int length) + { + stream.read_long_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public int read_long() + { + return stream.read_long(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_longlong_array(long[] value, int offset, int length) + { + stream.read_longlong_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public long read_longlong() + { + return stream.read_longlong(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public org.omg.CORBA.Object read_Object() + { + return stream.read_Object(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public org.omg.CORBA.Object read_Object(Class klass) + { + return stream.read_Object(klass); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_octet_array(byte[] value, int offset, int length) + { + stream.read_octet_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public byte read_octet() + { + return stream.read_octet(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Principal read_Principal() + { + return stream.read_Principal(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_short_array(short[] value, int offset, int length) + { + stream.read_short_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public short read_short() + { + return stream.read_short(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public String read_string() + { + return stream.read_string(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public TypeCode read_TypeCode() + { + return stream.read_TypeCode(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_ulong_array(int[] value, int offset, int length) + { + stream.read_ulong_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public int read_ulong() + { + return stream.read_ulong(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_ulonglong_array(long[] value, int offset, int length) + { + stream.read_ulonglong_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public long read_ulonglong() + { + return stream.read_ulonglong(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_ushort_array(short[] value, int offset, int length) + { + stream.read_ushort_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public short read_ushort() + { + return stream.read_ushort(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Serializable read_value() + { + return read_value((Serializable) null); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_wchar_array(char[] value, int offset, int length) + { + stream.read_wchar_array(value, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public char read_wchar() + { + return stream.read_wchar(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public String read_wstring() + { + return stream.read_wstring(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public int read() + throws IOException + { + return stream.read(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public int read(byte[] b, int off, int len) + throws IOException + { + return stream.read(b, off, len); + } + + /** + * Delegates functionality to the underlying stream. + */ + public int read(byte[] b) + throws IOException + { + return stream.read(b); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void reset() + throws IOException + { + stream.reset(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public long skip(long n) + throws IOException + { + return stream.skip(n); + } + + /** + * Get a string representation. + */ + public String toString() + { + return "HeadlessInput+" + stream.toString(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public String[] _truncatable_ids() + { + return stream._truncatable_ids(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public Object read_Abstract() + { + return stream.read_Abstract(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_any_array(AnySeqHolder holder, int offset, int length) + { + stream.read_any_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_boolean_array(BooleanSeqHolder holder, int offset, int length) + { + stream.read_boolean_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_char_array(CharSeqHolder holder, int offset, int length) + { + stream.read_char_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_double_array(DoubleSeqHolder holder, int offset, int length) + { + stream.read_double_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_float_array(FloatSeqHolder holder, int offset, int length) + { + stream.read_float_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_long_array(LongSeqHolder holder, int offset, int length) + { + stream.read_long_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_longlong_array(LongLongSeqHolder holder, int offset, + int length) + { + stream.read_longlong_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_octet_array(OctetSeqHolder holder, int offset, int length) + { + stream.read_octet_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_short_array(ShortSeqHolder holder, int offset, int length) + { + stream.read_short_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_ulong_array(ULongSeqHolder holder, int offset, int length) + { + stream.read_ulong_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_ulonglong_array(ULongLongSeqHolder holder, int offset, + int length) + { + stream.read_ulonglong_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_ushort_array(UShortSeqHolder holder, int offset, int length) + { + stream.read_ushort_array(holder, offset, length); + } + + /** + * Delegates functionality to read_value. + */ + public Serializable read_Value() + { + return read_value(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public void read_wchar_array(WCharSeqHolder holder, int offset, int length) + { + stream.read_wchar_array(holder, offset, length); + } + + /** + * Delegates functionality to the underlying stream. + */ + public int getPosition() + { + return stream.getPosition(); + } + + /** + * Delegates functionality to the underlying stream. + */ + public gnuRuntime getRunTime() + { + return stream.runtime; + } + + /** + * Replace the instance of RunTime. + */ + public void setRunTime(gnuRuntime a_runtime) + { + stream.runtime = a_runtime; + } + + /** + * Delegates functionality to the underlying stream. + */ + public void seek(int position) + { + stream.seek(position); + } + +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/IDLTypeHelper.java b/libjava/classpath/gnu/CORBA/CDR/IDLTypeHelper.java new file mode 100644 index 0000000..3259a48 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/IDLTypeHelper.java @@ -0,0 +1,169 @@ +/* IDLTypeHelper.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.Minor; + +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.portable.BoxedValueHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +/** + * Handles case when the CORBA IDL type with the known helper is wrapped into + * Value type. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class IDLTypeHelper + implements BoxedValueHelper +{ + /** + * A helper class. + */ + protected Class helper; + + /** + * Argument values for Helper.id(). + */ + static final Object[] ARGS_ID_V = new Object[0]; + + /** + * Argument types for Helper.id()). + */ + static final Class[] ARGS_ID = new Class[0]; + + /** + * Argument types for Helper.read. + */ + static final Class[] ARGS_READ = new Class[] { org.omg.CORBA.portable.InputStream.class }; + + /** + * Create an IDLTypeHelper that works via given helper class. + */ + public IDLTypeHelper(Class a_helperClass) + { + helper = a_helperClass; + } + + /** + * Get the Id, returned by this helper (use reflection). + */ + public String get_id() + { + try + { + Method m = helper.getMethod("id", ARGS_ID); + return (String) m.invoke(null, ARGS_ID_V); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(msg() + " id()"); + m.minor = Minor.Boxed; + m.initCause(ex); + throw m; + } + } + + /** + * Read an instance from the stream. + */ + public Serializable read_value(InputStream input) + { + try + { + Method m = helper.getMethod("read", ARGS_READ); + return (Serializable) m.invoke(null, new Object[] { input }); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(msg() + " read(..)"); + m.minor = Minor.Boxed; + m.initCause(ex); + throw m; + } + } + + /** + * Write the instance to the stream. + */ + public void write_value(OutputStream output, Serializable value) + { + try + { + Method[] m = helper.getMethods(); + + for (int i = 0; i < m.length; i++) + { + if (m[i].getName().equals("write") + && ((m[i].getModifiers() & Modifier.STATIC) != 0)) + { + Class[] p = m[i].getParameterTypes(); + + if (p.length == 2 && OutputStream.class.isAssignableFrom(p[0]) + && p[1].isAssignableFrom(value.getClass())) + { + m[i].invoke(null, new Object[] { output, value }); + return; + } + } + } + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(msg() + " write(..)"); + m.minor = Minor.Boxed; + m.initCause(ex); + throw m; + } + } + + /** + * Create the start of message for exceptions. + */ + String msg() + { + return "Failed calling " + helper.getName() + " method: "; + } + +} diff --git a/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java b/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java index b71a9a4..02cfa08 100644 --- a/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java +++ b/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java @@ -55,7 +55,7 @@ import java.io.PushbackInputStream; */ public class LittleEndianInputStream extends FilterInputStream - implements abstractDataInputStream + implements AbstractDataInput { // Byte buffer, used to make primitive read calls more efficient. byte[] buf = new byte[ 8 ]; diff --git a/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java index a6d56cf..6791a82 100644 --- a/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java +++ b/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java @@ -55,7 +55,7 @@ import java.io.OutputStream; */ public class LittleEndianOutputStream extends FilterOutputStream - implements abstractDataOutputStream + implements AbstractDataOutput { /** * This method initializes an instance of DataOutputStream to diff --git a/libjava/classpath/gnu/CORBA/CDR/UnknownExceptionCtxHandler.java b/libjava/classpath/gnu/CORBA/CDR/UnknownExceptionCtxHandler.java new file mode 100644 index 0000000..314dd8e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/UnknownExceptionCtxHandler.java @@ -0,0 +1,292 @@ +/* UnknownExceptionCtxHandler.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.Minor; +import gnu.CORBA.ObjectCreator; +import gnu.CORBA.GIOP.ServiceContext; + +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.StringValueHelper; +import org.omg.CORBA.portable.OutputStream; + +import java.lang.reflect.Constructor; +import java.util.StringTokenizer; + +import javax.rmi.CORBA.Util; + +/** + * Reads the data about an unknown exception from the UnknownExceptionInfo. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class UnknownExceptionCtxHandler + extends Vio +{ + /** + * Encode exception and add its recored to the message service contexts. + */ + public static ServiceContext[] addExceptionContext(ServiceContext[] current, + Throwable exception, Object details) + { + try + { + ServiceContext[] c = new ServiceContext[current.length + 1]; + if (current.length > 0) + System.arraycopy(current, 0, c, 0, current.length); + + BufferedCdrOutput output = new BufferedCdrOutput(); + + if (details instanceof OutputStream) + output.setOrb(((OutputStream) output).orb()); + + if (details instanceof AbstractCdrOutput) + ((AbstractCdrOutput) details).cloneSettings(output); + + write(output, exception); + + ServiceContext xc = new ServiceContext(); + xc.context_id = ServiceContext.UnknownExceptionInfo; + xc.context_data = output.buffer.toByteArray(); + c[current.length] = xc; + return c; + } + catch (Exception ex) + { + ex.printStackTrace(); + return current; + } + } + + /** + * Write data about unknown exception. + */ + public static void write(BufferedCdrOutput output, Throwable t) + { + t.fillInStackTrace(); + output.write_Value(t); + } + + /** + * Read the data about an unknown exception from the UnknownExceptionInfo. + * Following the documentation, this must be just value type, but it seems + * that in Sun's implementation is is not, as starts from 0x0. For value type, + * this would be null. + * + * TODO Implement reading and writing in Sun format, making Classpath IIOP + * interoperable with Sun's implementation. Current inmplementation reads and + * reproduces the exception class type only. + * + * @param input the input stream to read the context (orb and other settings + * are inherited from the main stream that received the message). + * + * @param contexts all service contexts that were present in the message. + * + * @return the Throwable, extracted from context, on null, if this has failed. + */ + public static Throwable read(BufferredCdrInput input, ServiceContext[] contexts) + { + input.mark(Integer.MAX_VALUE); + + int h = input.read_long(); + if (h == 0) + { + // This block reads exception info in the Sun specific format. + // (currently we read the exception name only). + try + { + // We may need to jump back if the value is read via value + // factory. + input.mark(512); + + int value_tag = input.read_long(); + checkTag(value_tag); + + String codebase = null; + String[] ids = null; + String id = null; + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + return (Throwable) readIndirection(input); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present. The codebase is a space + // separated list of URLs from where the implementing + // code can be downloaded. + codebase = read_string(input); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present. + ids = read_string_array(input); + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present. + id = read_string(input); + } + } + + java.lang.Object ox = createInstance(id, ids, codebase); + + return (Throwable) ox; + } + catch (Exception ex) + { + ex.printStackTrace(); + return null; + } + } + else + { + input.reset(); + // Read as defined in OMG documentation. + return (Throwable) input.read_Value(); + } + } + + /** + * Load exception by name and create the instance. The reason why this is + * different from Vio is because some exceptions have no parameterless + * constructor, but have a constructor with the string parameter instead. + */ + static Object createInstance(String id, String[] ids, String codebase) + { + Object o = _createInstance(id, codebase); + + if (ids != null) + for (int i = 0; i < ids.length && o == null; i++) + o = _createInstance(ids[i], codebase); + return o; + } + + static Object _createInstance(String id, String codebase) + { + if (id == null) + return null; + if (id.equals(StringValueHelper.id())) + return ""; + StringTokenizer st = new StringTokenizer(id, ":"); + + String prefix = st.nextToken(); + if (prefix.equalsIgnoreCase("IDL")) + return ObjectCreator.Idl2Object(id); + else if (prefix.equalsIgnoreCase("RMI")) + { + String className = st.nextToken(); + String hashCode = st.nextToken(); + String sid = null; + if (st.hasMoreElements()) + sid = st.nextToken(); + + try + { + Class objectClass = Util.loadClass(className, codebase, + Vio.class.getClassLoader()); + + String rid = ObjectCreator.getRepositoryId(objectClass); + + if (!rid.equals(id)) + { + // If direct string comparison fails, compare by meaning. + StringTokenizer st2 = new StringTokenizer(rid, ":"); + if (!st2.nextToken().equals("RMI")) + throw new InternalError("RMI format expected: '" + rid + "'"); + if (!st2.nextToken().equals(className)) + throwIt("Class name mismatch", id, rid, null); + + try + { + long h1 = Long.parseLong(hashCode, 16); + long h2 = Long.parseLong(st2.nextToken(), 16); + if (h1 != h2) + throwIt("Hashcode mismatch", id, rid, null); + + if (sid != null && st2.hasMoreTokens()) + { + long s1 = Long.parseLong(hashCode, 16); + long s2 = Long.parseLong(st2.nextToken(), 16); + if (s1 != s2) + throwIt("serialVersionUID mismatch", id, rid, null); + } + } + catch (NumberFormatException e) + { + throwIt("Invalid hashcode or svuid format: ", id, rid, e); + } + } + + // Some RemoteExceptions have no public parameterless constructor, + // but they have constructor taking string as parameter. + try + { + return objectClass.newInstance(); + } + catch (Exception ex) + { + // Try instantiate passing string as parameter. + Constructor c = objectClass.getConstructor(new Class[] { String.class }); + return c.newInstance(new Object[] { "" }); + } + } + catch (MARSHAL m) + { + m.minor = Minor.Instantiation; + throw m; + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("Unable to instantiate " + id); + m.minor = Minor.Instantiation; + m.initCause(ex); + throw m; + } + } + else + throw new NO_IMPLEMENT("Unsupported prefix " + prefix + ":"); + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/VMVio.java b/libjava/classpath/gnu/CORBA/CDR/VMVio.java new file mode 100644 index 0000000..9b719fd --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/VMVio.java @@ -0,0 +1,101 @@ +/* VMVio.java -- Native operations, required by value IO. + 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 modify + it under the terms of the GNU General Public License as published by + the 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, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +/** + * This is a temporary replacement for the native call that would allocate + * objects without public constructors. The replacement only allocates + * objects with public parameterless constructor and objects with public + * constructor taking string (like some Throwables). + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * + * TODO FIXME replace by native call like in VMObjectInputStream. + * Required modification of Classpath the build system. + */ + + +package gnu.CORBA.CDR; + +import java.lang.reflect.Constructor; + +public class VMVio +{ + /** + * Allocates a new Object of type clazz but without running the default + * constructor on it. It then calls the given constructor on it. The given + * constructor method comes from the constr_clazz which is a super class of + * the given clazz. + */ + public static Object allocateObject(Class clazz, Class constr_clazz, + Constructor constructor) + throws InstantiationException + { + try + { + Constructor c = clazz.getConstructor(new Class[0]); + c.setAccessible(true); + return c.newInstance(new Object[0]); + } + catch (Exception ex) + { + try + { + Constructor c = clazz.getConstructor(new Class[] { String.class }); + return c.newInstance(new Object[] { "" }); + } + catch (Exception ex2) + { + Constructor c[] = clazz.getConstructors(); + + for (int i = 0; i < c.length; i++) + { + try + { + c[i].setAccessible(true); + Class[] args = c[i].getParameterTypes(); + return c[i].newInstance(new Object[args.length]); + } + catch (Exception ex3) + { + // Try another one. + } + } + } + throw new InstantiationException(clazz.getName()); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/Vio.java b/libjava/classpath/gnu/CORBA/CDR/Vio.java index 0a37132..fd878cb3 100644 --- a/libjava/classpath/gnu/CORBA/CDR/Vio.java +++ b/libjava/classpath/gnu/CORBA/CDR/Vio.java @@ -1,4 +1,4 @@ -/* gnuValueBaseHelper.java -- +/* Vio.java -- Value type IO operations. Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.CORBA.CDR; +import gnu.CORBA.Minor; import gnu.CORBA.ObjectCreator; import org.omg.CORBA.CustomMarshal; @@ -46,106 +47,144 @@ import org.omg.CORBA.DataOutputStream; import org.omg.CORBA.MARSHAL; import org.omg.CORBA.NO_IMPLEMENT; import org.omg.CORBA.StringSeqHelper; +import org.omg.CORBA.StringValueHelper; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.WStringValueHelper; import org.omg.CORBA.portable.BoxedValueHelper; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.OutputStream; import org.omg.CORBA.portable.Streamable; import org.omg.CORBA.portable.ValueFactory; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.StringTokenizer; -import java.lang.reflect.Method; +import javax.rmi.CORBA.Util; +import javax.rmi.CORBA.ValueHandler; /** * A specialised class for reading and writing the value types. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public abstract class Vio { /** - * If true, wrap value type data into chunks. This decrease the - * performance, but is required for the interoperability with - * Sun's CORBA implementation. Chunking may increase the security, - * as there is more control on the number of bytes being transferred. - * + * If true, wrap value type data into chunks. This decrease the performance, + * and is not required for interoperability with jdk 1.5, but is left in the + * implementation as the optional mode for solving possible interoperability + * problems with non-Sun CORBA implementations. + * * The current implementation would accept both single chunk or multiple - * chunks, but will always send a single chunk. + * chunks, but will always send a single chunk (if true) or unchunked data (if + * false). */ - public static boolean USE_CHUNKING = true; + public static boolean USE_CHUNKING = false; /** - * The first field in the value record. The last octet may contain - * additional flags (vf_CODEBASE, vf_ID and vf_MULTIPLE_IDS). The tag - * value is different for the indirections (vt_INDIRECTION) and - * nulls (vt_NULL). + * The first field in the value record. The last octet may contain additional + * flags (vf_CODEBASE, vf_ID and vf_MULTIPLE_IDS). The tag value is different + * for the indirections (vt_INDIRECTION) and nulls (vt_NULL). */ public static final int vt_VALUE_TAG = 0x7fffff00; /** - * The value tag flag, indicating that the codebase URL is present - * in the value tag record. + * The value tag flag, indicating that the codebase URL is present in the + * value tag record. */ public static final int vf_CODEBASE = 0x1; /** - * The value tag flag, indicating that a single repository id is present - * in the value tag record. + * The value tag flag, indicating that a single repository id is present in + * the value tag record. */ public static final int vf_ID = 0x2; /** - * The value tag flag, indicating, that there are multiple repository - * ids present in the record. If this flag is set, the flag vf_ID must - * also be set, resulting the value of the least significant byte 0x6. + * The value tag flag, indicating, that there are multiple repository ids + * present in the record. If this flag is set, the flag vf_ID must also be + * set, resulting the value of the least significant byte 0x6. */ public static final int vf_MULTIPLE_IDS = 0x4; /** * The value tag flag, indicating the presence of chunking. Each chunk is - * preceeded by a positive int, indicating the number of bytes in the chunk. - * A sequence of chunks is terminated by a non positive int. + * preceeded by a positive int, indicating the number of bytes in the chunk. A + * sequence of chunks is terminated by a non positive int. */ public static final int vf_CHUNKING = 0x8; /** * The indirection tag value. Such tag must be followed by the CORBA long, * indicating the offset in the CORBA message, where the indirected - * information is present. This offset is assumed zero at the position - * where the mentioned CORBA long starts and can refer both forward - * (positive values) and backward (negative values). + * information is present. This offset is assumed zero at the position where + * the mentioned CORBA long starts and can refer both forward (positive + * values) and backward (negative values). */ public static final int vt_INDIRECTION = 0xffffffff; /** - * This tag value means that the value object being transferred is equal - * to null. + * This tag value means that the value object being transferred is equal to + * null. */ public static final int vt_NULL = 0x0; /** - * Read the value base from the given input stream. Determines the - * required class from the repository id. This includes operations - * that are not required when an unitialised instance or at least - * class of the value type is known. Hence it may be faster to use - * the alternative methods, read(InputStream, Class) or - * read(InputStream, Serializable). - * + * The size of CORBA long (java int). + */ + static final int INT_SIZE = 4; + + /** + * The String value helper (one instance is sufficient). + */ + public static final WStringValueHelper m_StringValueHelper = new WStringValueHelper(); + + /** + * An instance of the value handler. + */ + static ValueHandler handler = Util.createValueHandler(); + + /** + * Read the value base from the given input stream. Determines the required + * class from the repository id. This includes operations that are not + * required when an unitialised instance or at least class of the value type + * is known. Hence it may be faster to use the alternative methods, + * read(InputStream, Class) or read(InputStream, Serializable). + * * @param input a stream to read from. - * + * @param repository_id a repository id of the object being read, may be null. + * * @return the loaded value. - * + * * @throws MARSHAL if the reading has failed due any reason. */ public static Serializable read(InputStream input) { - // Explicitly prevent the stream from closing as we may need - // to read the subsequent bytes as well. Stream may be auto-closed - // in its finalizer. + return read(input, (String) null); + } + + /** + * Read the value base from the given input stream. Determines the required + * class from the repository id. This includes operations that are not + * required when an unitialised instance or at least class of the value type + * is known. Hence it may be faster to use the alternative methods, + * read(InputStream, Class) or read(InputStream, Serializable). + * + * @param an_input a stream to read from. + * @param repository_id a repository id of the object being read, may be null. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input, String repository_id) + { try { + final int position = getCurrentPosition(input); // We may need to jump back if the value is read via value factory. input.mark(512); @@ -154,18 +193,13 @@ public abstract class Vio String codebase = null; String[] ids = null; - String id = null; - - // The existing implementing object. - java.lang.Object ox = null; + String id = repository_id; // Check for the agreed null value. if (value_tag == vt_NULL) return null; else if (value_tag == vt_INDIRECTION) - - // TODO FIXME Implement support for indirections. - throw new NO_IMPLEMENT("Indirections unsupported"); + return readIndirection(input); else { // Read the value. @@ -174,152 +208,173 @@ public abstract class Vio // The codebase is present. The codebase is a space // separated list of URLs from where the implementing // code can be downloaded. - codebase = input.read_string(); + codebase = read_string(input); } if ((value_tag & vf_MULTIPLE_IDS) != 0) { // Multiple supported repository ids are present. - ids = StringSeqHelper.read(input); - for (int i = 0; (i < ids.length) && (ox == null); i++) - { - ox = ObjectCreator.Idl2Object(ids [ i ]); - - if (ox == null) - { - // Try to find the value factory. - ValueFactory f = - ((org.omg.CORBA_2_3.ORB) input.orb()).lookup_value_factory(ids [ i ]); - - if (f != null) - { - // Reset, as the value factory reads from beginning. - input.reset(); - return f.read_value((org.omg.CORBA_2_3.portable.InputStream) input); - } - } - } + ids = read_string_array(input); } else if ((value_tag & vf_ID) != 0) { // Single supported repository id is present. - id = input.read_string(); - ox = ObjectCreator.Idl2Object(id); - - if (ox == null) - { - // Try to find the value factory. - ValueFactory f = - ((org.omg.CORBA_2_3.ORB) input.orb()).lookup_value_factory(id); - - if (f != null) - { - input.reset(); - return f.read_value((org.omg.CORBA_2_3.portable.InputStream) input); - } - } + id = read_string(input); } } - if (ox == null) - throw new MARSHAL("Unable to instantiate the value type"); + BoxedValueHelper helper = getHelper(null, id); + // The existing implementing object. + java.lang.Object ox = null; + + if (helper != null) + ox = null; // Helper will care about the instantiating. + else if (id.equals(WStringValueHelper.id())) + helper = m_StringValueHelper; else - { - read_instance(input, ox, value_tag, null); - return (Serializable) ox; - } + ox = createInstance(id, ids, codebase); + return (Serializable) read_instance(input, position, ox, value_tag, + helper, id, ids, codebase); } catch (Exception ex) { - throw new MARSHAL(ex + ":" + ex.getMessage()); + MARSHAL m = new MARSHAL(); + m.minor = Minor.Value; + m.initCause(ex); + throw m; } } /** - * Read the value base from the given input stream when - * the value base class is available. Hence there is no need - * to guess it from the repository id. - * + * Read the value base from the given input stream when the value base class + * is available. Hence there is no need to guess it from the repository id. + * * @param input a stream to read from. * @param value_class the class of the value being read. - * + * * @return the loaded value. - * + * * @throws MARSHAL if the reading has failed due any reason. */ public static Serializable read(InputStream input, Class value_class) { - // Explicitly prevent the stream from closing as we may need - // to read the subsequent bytes as well. Stream may be auto-closed - // in its finalizer. + final int position = getCurrentPosition(input); + + String id = null; + String[] ids = null; + String codebase = null; + try { int value_tag = input.read_long(); checkTag(value_tag); - // The existing implementing object. - java.lang.Object ox = value_class.newInstance(); - // Check for the agreed null value. if (value_tag == vt_NULL) return null; else if (value_tag == vt_INDIRECTION) - - // TODO FIXME Implement support for indirections. - throw new NO_IMPLEMENT("Indirections unsupported"); + return readIndirection(input); else { // Read the value. if ((value_tag & vf_CODEBASE) != 0) { - // The codebase is present, but skip it. - input.read_string(); + // The codebase is present. + codebase = read_string(input); } if ((value_tag & vf_MULTIPLE_IDS) != 0) { - // Multiple supported repository ids are present, but skip them. - StringSeqHelper.read(input); + // Multiple supported repository ids are present. + ids = read_string_array(input); } else if ((value_tag & vf_ID) != 0) { - // Single supported repository id is present, but skip it. - input.read_string(); + // Single supported repository id is present. + id = read_string(input); } } - read_instance(input, ox, value_tag, null); + BoxedValueHelper vHelper = id != null ? getHelper(value_class, id) + : getHelper(value_class, ids); + + java.lang.Object ox; + + if (vHelper == null) + { + try + { + ox = createInstance(id, ids, codebase); + } + catch (Exception e) + { + ox = null; + } + + if (ox != null) + { + if (value_class != null + && !value_class.isAssignableFrom(ox.getClass())) + { + MARSHAL m = new MARSHAL(ox.getClass() + " is not a " + + value_class.getName()); + m.minor = Minor.ClassCast; + throw m; + } + } + } + else + ox = null; + + ox = read_instance(input, position, ox, value_tag, vHelper, id, ids, + codebase); return (Serializable) ox; } + catch (MARSHAL m) + { + throw m; + } + catch (SystemException sysEx) + { + // OK. + throw sysEx; + } catch (Exception ex) { - throw new MARSHAL(ex + ":" + ex.getMessage()); + MARSHAL m = new MARSHAL("Cant read " + value_class); + m.minor = Minor.Value; + m.initCause(ex); + throw m; } } /** - * Read the value base from the given input stream when - * the unitialised instance is available. Hence there is no need - * to guess the class from the repository id and then to instantiate - * an instance. - * + * Read the value base from the given input stream when the unitialised + * instance is available. Hence there is no need to guess the class from the + * repository id and then to instantiate an instance. + * * @param input a stream to read from. - * - * @param value_instance an pre-created instance of the value. If the - * helper is not null, this parameter is ignored an should be null. - * - * @param helper a helper to create an instance and read the object- - * specific part of the record. If the value_instance is used instead, - * this parameter should be null. - * + * + * @param value_instance an pre-created instance of the value. If the helper + * is not null, this parameter is ignored an should be null. + * + * @param helper a helper to create an instance and read the object- specific + * part of the record. If the value_instance is used instead, this parameter + * should be null. + * * @return the loaded value. - * + * * @throws MARSHAL if the reading has failed due any reason. */ public static Object read(InputStream input, Object value_instance, - Object helper - ) + BoxedValueHelper helper) { + final int position = getCurrentPosition(input); + + String id = null; + String[] ids = null; + String codebase = null; + try { int value_tag = input.read_long(); @@ -329,207 +384,396 @@ public abstract class Vio if (value_tag == vt_NULL) return null; else if (value_tag == vt_INDIRECTION) - - // TODO FIXME Implement support for indirections. - throw new NO_IMPLEMENT("Indirections unsupported"); + return readIndirection(input); else { // Read the value. if ((value_tag & vf_CODEBASE) != 0) { - // The codebase is present, but skip it. - input.read_string(); + // The codebase is present. + codebase = read_string(input); } if ((value_tag & vf_MULTIPLE_IDS) != 0) { - // Multiple supported repository ids are present, but skip them. - StringSeqHelper.read(input); + // Multiple supported repository ids are present. + ids = read_string_array(input); } else if ((value_tag & vf_ID) != 0) { - // Single supported repository id is present, but skip it. - input.read_string(); + // Single supported repository id is present. + id = read_string(input); } } - value_instance = - read_instance(input, value_instance, value_tag, helper); + Class value_class = value_instance == null ? null + : value_instance.getClass(); + + if (helper == null) + helper = id != null ? getHelper(value_class, id) : getHelper( + value_class, ids); + + value_instance = read_instance(input, position, value_instance, + value_tag, helper, id, ids, codebase); return value_instance; } catch (Exception ex) { - throw new MARSHAL(ex + ":" + ex.getMessage()); + MARSHAL m = new MARSHAL(); + m.minor = Minor.Value; + m.initCause(ex); + throw m; } } /** - * Read using provided boxed value helper. This method expects - * the full value type header, followed by contents, that are - * delegated to the provided helper. It handles null. - * + * Read using provided boxed value helper. This method expects the full value + * type header, followed by contents, that are delegated to the provided + * helper. It handles null. + * * @param input the stream to read from. - * @param helper the helper that reads the type-specific part of - * the content. - * - * @return the value, created by the helper, or null if the - * header indicates that null was previously written. + * @param helper the helper that reads the type-specific part of the content. + * + * @return the value, created by the helper, or null if the header indicates + * that null was previously written. */ - public static Serializable read(InputStream input, Object helper) + public static Serializable read(InputStream input, BoxedValueHelper helper) { return (Serializable) read(input, null, helper); } /** - * Fill in the instance fields by the data from the input stream. - * The method assumes that the value header, if any, is already - * behind. The information from the stream is stored into the - * passed ox parameter. - * + * Fill in the instance fields by the data from the input stream. The method + * assumes that the value header, if any, is already behind. The information + * from the stream is stored into the passed ox parameter. + * * @param input an input stream to read from. - * + * * @param value a pre-instantiated value type object, must be either - * Streamable or CustomMarshal. If the helper is used, this parameter - * is ignored and should be null. - * + * Streamable or CustomMarshal. If the helper is used, this parameter is + * ignored and should be null. + * * @param value_tag the tag that must be read previously. - * @param helper the helper for read object specific part; may be - * null to read in using other methods. - * + * @param helper the helper for read object specific part; may be null to read + * in using other methods. + * * @return the value that was read. */ - private static Object read_instance(InputStream input, Object value, - int value_tag, Object helper - ) + static Object read_instance(InputStream input, final int position, + Object value, int value_tag, BoxedValueHelper helper, String id, + String[] ids, String codebase) { + if (helper != m_StringValueHelper && id != null) + if (id.equals(StringValueHelper.id())) + { + value = null; + helper = m_StringValueHelper; + } + try { if ((value_tag & vf_CHUNKING) != 0) { - ByteArrayOutputStream bout = null; - int n = -1; - - // Read all chunks. - int chunk_size = input.read_long(); - if (chunk_size < 0) - throw new MARSHAL("Invalid first chunk size " + chunk_size); - - byte[] r = new byte[ chunk_size ]; - - while (chunk_size > 0) - { - if (r.length < chunk_size) - r = new byte[ chunk_size + 256 ]; - - n = 0; - reading: - while (n < chunk_size) - n += input.read(r, n, r.length - n); - - // Read the size of the next chunk. - chunk_size = input.read_long(); - - // If the value is non negative, there is more than one chunk. - // Accumulate chunks in the buffer. - // The last chunk (or the only chunk, if only one chunk is - // present) is not written in the buffer. It is stored in the - // array r, avoiding unnecessary buffer operations. - if (chunk_size > 0) - { - bout = new ByteArrayOutputStream(2 * chunk_size); - bout.write(r, 0, chunk_size); - } - } + BufferedCdrOutput output = createBuffer(input, 1024); + // Read the current (not a nested one) value in this spec case. + readNestedValue(value_tag, input, output, -1); + BufferredCdrInput ci = new BufferredCdrInput(output.buffer.getBuffer()); + ci.setRunTime(output.getRunTime()); - if (bout != null) - { - // More than one chunk was present. - // Add the last chunk. - bout.write(r, 0, n); - input = new noHeaderInput(bout.toByteArray()); - } - else - { - // Only one chunk was present. - input = new noHeaderInput(r); - } + input = new HeadlessInput(ci, input); } else { - if (input instanceof cdrBufInput) + if (input instanceof BufferredCdrInput) { // Highly probable case. - input = - new noHeaderInput(((cdrBufInput) input).buffer.getBuffer()); + input = new HeadlessInput((BufferredCdrInput) input, null); + } + else if (input instanceof HeadlessInput) + { + // There is no need to instantiate one more HeadlessInput + // as we can just reset. + ((HeadlessInput) input).subsequentCalls = false; } else { - cdrBufOutput bout = new cdrBufOutput(); + BufferedCdrOutput bout = new BufferedCdrOutput(); int c; while ((c = input.read()) >= 0) bout.write((byte) c); - input = new noHeaderInput(bout.buffer.toByteArray()); + input = new HeadlessInput( + (BufferredCdrInput) bout.create_input_stream(), input); } } } catch (IOException ex) { MARSHAL m = new MARSHAL("Unable to read chunks"); + m.minor = Minor.Value; m.initCause(ex); throw m; } - // The user-defines io operations are implemented. - if (value instanceof CustomMarshal) + return readValue(input, position, value, helper, id, ids, codebase); + } + + /** + * Create a buffer, inheriting critical settings from the passed input stream. + */ + private static BufferedCdrOutput createBuffer(InputStream input, int proposed_size) + { + BufferedCdrOutput bout; + bout = new BufferedCdrOutput(2 * proposed_size + 256); + + if (input instanceof BufferredCdrInput) { - CustomMarshal marsh = (CustomMarshal) value; - try + BufferredCdrInput in = (BufferredCdrInput) input; + bout.setBigEndian(in.isBigEndian()); + } + + if (input instanceof gnuValueStream) + bout.setRunTime(((gnuValueStream) input).getRunTime()); + else + bout.setRunTime(new gnuRuntime(null, null)); + return bout; + } + + /** + * Read the chunked nested value from the given input stream, transferring the + * contents to the given output stream. + * + * @param value_tag the value tag of the value being read. + * @param input the input stream from where the remainder of the nested value + * must be read. + * @param output the output stream where the unchunked nested value must be + * copied. + * + * @return the tag that ended the nested value. + */ + public static int readNestedValue(int value_tag, InputStream input, + BufferedCdrOutput output, int level) + throws IOException + { + String id = null; + if (level < -1) + { + // For the first level, this information is already behind. + output.write_long(value_tag - vf_CHUNKING); + + // The nested value should be aways chunked. + if ((value_tag & vf_CHUNKING) == 0) + { + MARSHAL m = new MARSHAL("readNestedValue: must be chunked"); + m.minor = Minor.Chunks; + throw m; + } + else if (value_tag == vt_NULL) + { + MARSHAL m = new MARSHAL("readNestedValue: nul"); + m.minor = Minor.Chunks; + throw m; + } + else if (value_tag == vt_INDIRECTION) { - marsh.unmarshal((DataInputStream) input); + MARSHAL m = new MARSHAL("readNestedValue: indirection"); + m.minor = Minor.Chunks; + throw m; } - catch (ClassCastException ex) + else { - incorrect_plug_in(ex); + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + String codebase = read_string(input); + write_string(output, codebase); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present. + String[] ids = read_string_array(input); + id = ids[0]; + write_string_array(output, ids); + } + else if ((value_tag & vf_ID) != 0) + { + id = read_string(input); + write_string(output, id); + } } } + + int n = -1; + + // Read all chunks. + int chunk_size; + + byte[] r = null; + + while (true) + { + // Read the size of the next chunk or it may also be the + // header of the nested value. + chunk_size = input.read_long(); + + // End of chunk terminator. + if (chunk_size < 0 && chunk_size >= level) + return chunk_size; + else if (chunk_size >= 0x7FFFFF00) + { + int onInput = getCurrentPosition(input) - 4; + int onOutput = output.getPosition(); + output.getRunTime().redirect(onInput, onOutput); + // Value over 0x7FFFFF00 indicates that the nested value + // starts here. Read the nested value, storing it into the output. + // First parameter is actually the value tag. + chunk_size = readNestedValue(chunk_size, input, output, level - 1); + if (chunk_size < 0 && chunk_size >= level) + return chunk_size; + } + else + { + // The chunk follows. + if (r == null || r.length < chunk_size) + r = new byte[chunk_size + 256]; + + n = 0; + reading: while (n < chunk_size) + n += input.read(r, n, chunk_size - n); + output.write(r, 0, n); + } + } + } + + /** + * Read the value (the header must be behind). + */ + public static Serializable readValue(InputStream input, final int position, + Object value, BoxedValueHelper helper, String id, String[] ids, + String codebase) + { + gnuRuntime g; + gnuValueStream c = ((gnuValueStream) input); + if (c.getRunTime() == null) + { + g = new gnuRuntime(codebase, value); + c.setRunTime(g); + } + else + { + g = c.getRunTime(); + g.addCodeBase(codebase); + g.target = (Serializable) value; + } + if (value != null) + g.objectWritten(value, position); + + if (input instanceof HeadlessInput) + ((HeadlessInput) input).subsequentCalls = false; + + boolean ok = true; + + // The user-defined io operations are implemented. + if (value instanceof CustomMarshal) + { + CustomMarshal marsh = (CustomMarshal) value; + marsh.unmarshal((DataInputStream) input); + } else // The IDL-generated io operations are implemented. if (value instanceof Streamable) { ((Streamable) value)._read(input); } - else if (helper instanceof BoxedValueHelper) - value = ((BoxedValueHelper) helper).read_value(input); - else if (helper instanceof ValueFactory) - value = - ((ValueFactory) helper).read_value((org.omg.CORBA_2_3.portable.InputStream) input); + else if (helper != null) + { + // If helper is non-null the value should normally be null. + value = helper.read_value(input); + g.objectWritten(value, position); + } else + { + ok = false; + ValueFactory factory = null; + org.omg.CORBA_2_3.ORB orb = (org.omg.CORBA_2_3.ORB) input.orb(); - // Stating the interfaces that the USER should use. - throw new MARSHAL("The " + value.getClass().getName() + - " must implement either StreamableValue or CustomValue." - ); + if (id != null) + factory = orb.lookup_value_factory(id); - // The negative end of state marker is expected from OMG standard. - // If the chunking is used, this marker is already extracted. - if ((value_tag & vf_CHUNKING) == 0) + if (factory == null && ids != null) + { + for (int i = 0; i < ids.length && factory == null; i++) + { + factory = orb.lookup_value_factory(ids[i]); + } + } + + if (factory != null) + { + value = factory.read_value((org.omg.CORBA_2_3.portable.InputStream) input); + ok = true; + } + } + + if (!ok && value instanceof Serializable) + // Delegate to ValueHandler { - int eor = input.read_long(); - if (eor >= 0) - throw new MARSHAL("End of state marker has an invalid value " + eor); + if (ids != null && ids.length > 0) + id = ids[0]; + + value = handler.readValue(input, position, value.getClass(), id, g); + ok = true; } - return value; + if (!ok) + { + if (value != null) + { + MARSHAL m = new MARSHAL(value.getClass().getName() + + " must be Streamable, CustomMarshal or Serializable"); + m.minor = Minor.UnsupportedValue; + throw m; + } + else + { + MARSHAL m = new MARSHAL("Unable to instantiate " + id + ":" + list(ids) + + " helper " + helper); + m.minor = Minor.UnsupportedValue; + throw m; + } + } + else + return (Serializable) value; + } + + /** + * Conveniency method to list ids in exception reports. + */ + static String list(String[] s) + { + if (s == null) + return "null"; + else + { + StringBuffer b = new StringBuffer("{"); + for (int i = 0; i < s.length; i++) + { + b.append(s[i]); + b.append(" "); + } + b.append("}"); + return b.toString(); + } } /** * Write the value base into the given stream. - * + * * @param output a stream to write to. - * + * * @param value a value type object, must be either Streamable or * CustomMarshal. - * + * * @throws MARSHAL if the writing failed due any reason. */ public static void write(OutputStream output, Serializable value) @@ -537,45 +781,82 @@ public abstract class Vio // Write null if this is a null value. if (value == null) output.write_long(vt_NULL); + else if (value instanceof String) + write(output, value, m_StringValueHelper); else - write(output, value, ObjectCreator.toIDL(value.getClass().getName())); - } - - /** - * Write the value base into the given stream, stating that it is an - * instance of the given class. The written record has no repository - * id and requires to supply a class or initialised instance for reading - * rather than an actual class it is. - * - * This results writing a different repository id. - * - * If the passed value implements the {@link CustomMarshal}, - * the helper uses {@link CustomMarshal#marshal} - * to write the content in a user defined way. Otherwise, - * this implementation initialises the {@link ObjectOutputStream} - * and writes through it. - * + write(output, value, value.getClass()); + } + + /** + * Write the value base into the given stream, stating that it is an instance + * of the given class. + * * @param output a stream to write to. - * + * * @param value a value to write. - * + * * @throws MARSHAL if the writing failed due any reason. */ public static void write(OutputStream output, Serializable value, - Class substitute - ) + Class substitute) { // Write null if this is a null value. if (value == null) output.write_long(vt_NULL); + else if (value instanceof String || substitute == String.class) + writeString(output, value); + else + { + String vId = ObjectCreator.getRepositoryId(value.getClass()); + if (substitute == null || value.getClass().equals(substitute)) + write_instance(output, value, vId, getHelper(value.getClass(), vId)); + else + { + String vC = ObjectCreator.getRepositoryId(substitute); + String[] ids = new String[] { vId, vC }; + BoxedValueHelper h = getHelper(substitute.getClass(), ids); + // If the helper is available, it is also responsible for + // providing the repository Id. Otherwise, write both + // ids. + if (h == null) + write_instance(output, value, ids, null); + else + write_instance(output, value, h.get_id(), null); + } + } + } + /** + * Write the value base into the given stream, supplementing it with an array + * of the provided repository ids plus the repository id, derived from the + * passed value. + * + * @param output a stream to write to. + * + * @param value a value to write. + * + * @throws MARSHAL if the writing failed due any reason. + */ + public static void write(OutputStream output, Serializable value, + String[] multiple_ids) + { + // Write null if this is a null value. + if (value == null) + output.write_long(vt_NULL); else - write(output, value, ObjectCreator.toIDL(substitute.getName())); + { + String[] ids = new String[multiple_ids.length + 1]; + ids[0] = ObjectCreator.getRepositoryId(value.getClass()); + System.arraycopy(multiple_ids, 0, ids, 1, multiple_ids.length); + BoxedValueHelper h = getHelper(value.getClass(), ids); + write_instance(output, value, ids, h); + } } /** - * Write value when its repository Id is explicitly given. - * + * Write value when its repository Id is explicitly given. Only this Id is + * written, the type of value is not taken into consideration. + * * @param output an output stream to write into. * @param value a value to write. * @param id a value repository id. @@ -585,172 +866,608 @@ public abstract class Vio if (value == null) output.write_long(vt_NULL); else - write_instance(output, value, id, null); + write_instance(output, value, id, getHelper(value.getClass(), id)); } /** - * Write standard value type header, followed by contents, produced - * by the boxed value helper. - * + * Write standard value type header, followed by contents, produced by the + * boxed value helper. + * * @param output the stream to write to. * @param value the value to write, can be null. - * @param helper the helper that writes the value content if it is - * not null. + * @param helper the helper that writes the value content if it is not null + * (must be provided for this method). */ public static void write(OutputStream output, Serializable value, - Object helper - ) + BoxedValueHelper helper) { + if (helper == null) + throw new AssertionError("Helper must be provided"); if (value == null) output.write_long(vt_NULL); else + write_instance(output, value, helper.get_id(), helper); + } + + /** + * Write the parameter that is surely a string and not null. + */ + private static void writeString(OutputStream output, Serializable string) + { + write_instance(output, string, m_StringValueHelper.get_id(), + m_StringValueHelper); + } + + /** + * Write value when its repository Id is explicitly given. Does not handle + * null. + * + * @param output an output stream to write into. + * @param value a value to write. + * @param id a value repository id (can be either single string or string + * array). + * @param helper a helper, writing object - specifical part. Can be null if + * the value should be written using other methods. + */ + static void write_instance(OutputStream output, Serializable value, + Object ids, BoxedValueHelper helper) + { + gnuValueStream rout = null; + gnuRuntime runtime = null; + + try { - String id; + if (output instanceof gnuValueStream) + { + int position; + rout = (gnuValueStream) output; + runtime = rout.getRunTime(); + + if (runtime == null) + { + runtime = new gnuRuntime(null, value); + rout.setRunTime(runtime); + rout.getRunTime().objectWritten(value, + position = rout.getPosition()); + } + else if (runtime.target == value) + { + if (!writeSelf(output, value)) + throw new InternalError("Recursive helper call for " + + value.getClass().getName()); + return; + } + else + { + position = runtime.isWrittenAt(value); + if (position >= 0) + { + // The object was already written. + output.write_long(vt_INDIRECTION); + output.write_long(position - rout.getPosition()); + // Replacing object write data by indirection reference. + return; + } + else + { + runtime.objectWritten(value, position = rout.getPosition()); + } + } + } + + int value_tag = vt_VALUE_TAG; + + if (ids instanceof String) + value_tag |= vf_ID; + else if (ids instanceof String[]) + // OMG standard requires to set both flags. + value_tag |= vf_MULTIPLE_IDS | vf_ID; - if (helper instanceof BoxedValueHelper) - id = ((BoxedValueHelper) helper).get_id(); + int chunkSizeLocation; + + OutputStream outObj; + + if (USE_CHUNKING) + { + // Wrap the value being written into one chunk (makes sense only for + // compatibility reasons). + outObj = output; + value_tag |= vf_CHUNKING; + } + else + outObj = output; + + output.write_long(value_tag); + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + write_string_array(output, (String[]) ids); + else if ((value_tag & vf_ID) != 0) + write_string(output, (String) ids); + + if (USE_CHUNKING) + { + // So far, write 0x55555555 instead of the chunk size (alignment may + // take place). + output.write_long(0x55555555); + // If the chunking is involved, the chunk size must be written here. + chunkSizeLocation = rout.getPosition() - INT_SIZE; + } else - id = ""; + // Not in use for this case. + chunkSizeLocation = -1; + + writeValue(outObj, value, helper); - write_instance(output, value, id, helper); + if (USE_CHUNKING) + { + // Write the chunk size where the place for it was reserved. + int chunkSize = rout.getPosition() - chunkSizeLocation - INT_SIZE; + int current = rout.getPosition(); + rout.seek(chunkSizeLocation); + output.write_long(chunkSize); + rout.seek(current); + + // The end of record marker. + output.write_long(-1); + } + } + finally + { + if (runtime != null) + runtime.target = null; } } /** - * Write value when its repository Id is explicitly given. - * Does not handle null. - * - * @param output an output stream to write into. - * @param value a value to write. - * @param id a value repository id. - * @param helper a helper, writing object - specifica part. Can be null - * if the value should be written unsing other methods. + * Write value (after header). */ - private static void write_instance(OutputStream output, Serializable value, - String id, Object helper - ) + static void writeValue(OutputStream output, Serializable value, + BoxedValueHelper helper) { - // This implementation always writes a single repository id. - // It never writes multiple repository ids and currently does not use - // a codebase. - int value_tag = vt_VALUE_TAG | vf_ID; + ((gnuValueStream) output).getRunTime().target = value; + if (helper != null) + helper.write_value(output, value); + else if (!writeSelf(output, value)) + { + // Try to find helper via class loader. + boolean ok = false; - OutputStream outObj; - cdrBufOutput out = null; + if (!ok) + { + if (output instanceof BufferedCdrOutput) + { + BufferedCdrOutput b = (BufferedCdrOutput) output; + if (b.runtime == null) + b.runtime = new gnuRuntime(null, value); + } - if (USE_CHUNKING) + handler.writeValue(output, value); + } + } + } + + /** + * Try to write value supposing that it implements self-streamable interfaces. + * Return false if it does not or true on success. + */ + static boolean writeSelf(OutputStream output, Serializable value) + { + // User defined write method is present. + if (value instanceof CustomMarshal) { - out = new cdrBufOutput(); - out.setOrb(output.orb()); - outObj = out; - value_tag |= vf_CHUNKING; + ((CustomMarshal) value).marshal((DataOutputStream) output); + return true; } - else - outObj = output; + else if (value instanceof Streamable) + { + ((Streamable) value)._write(output); + return true; + } + return false; + } - output.write_long(value_tag); - output.write_string(id); + /** + * Read the indirection data and return the object that was already written to + * this stream. + * + * @param an_input the input stream, must be BufferredCdrInput. + */ + static Serializable readIndirection(InputStream an_input) + { + if (!(an_input instanceof gnuValueStream)) + throw new NO_IMPLEMENT(gnuValueStream.class.getName() + + " expected as parameter"); - if (helper instanceof BoxedValueHelper) + gnuValueStream in = (gnuValueStream) an_input; + + int current_pos = in.getPosition(); + + int offset = an_input.read_long(); + if (offset > -INT_SIZE) { - ((BoxedValueHelper) helper).write_value(outObj, value); + MARSHAL m = new MARSHAL("Indirection tag refers to " + offset + + " (must be less than -" + INT_SIZE + ")"); + m.minor = Minor.Offset; + throw m; } - else - // User defince write method is present. - if (value instanceof CustomMarshal) + + int stored_at = current_pos + offset; + + if (in.getRunTime() == null) + { + MARSHAL m = new MARSHAL(stored_at + " offset " + offset + ": not written"); + m.minor = Minor.Value; + throw m; + } + + return (Serializable) in.getRunTime().isObjectWrittenAt(stored_at, offset); + } + + /** + * Check the passed value tag for correctness. + * + * @param value_tag a tag to check, must be between 0x7fffff00 and 0x7fffffff + * + * @throws MARSHAL if the tag is outside this interval. + */ + static void checkTag(int value_tag) + { + if ((value_tag < 0x7fffff00 || value_tag > 0x7fffffff) + && value_tag != vt_NULL && value_tag != vt_INDIRECTION) + { + MARSHAL m = new MARSHAL("Invalid value record, unsupported header tag: " + + value_tag + " (0x" + Integer.toHexString(value_tag) + ")"); + m.minor = Minor.ValueHeaderTag; + throw m; + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0 && (value_tag & vf_ID) == 0) { + MARSHAL m = new MARSHAL("Invalid value record header flag combination (0x" + + Integer.toHexString(value_tag) + ")"); + m.minor = Minor.ValueHeaderFlags; + throw m; + } + } + + /** + * Throw MARSHAL. + */ + static void throwIt(String msg, String id1, String id2, Throwable e) + throws MARSHAL + { + MARSHAL m = new MARSHAL(msg + ":'" + id1 + "' versus '" + id2 + "'"); + if (e != null) + m.initCause(e); + m.minor = Minor.Value; + throw m; + } + + /** + * Load class by name and create the instance. + */ + static Object createInstance(String id, String[] ids, String codebase) + { + Object o = null; + + if (id != null) + o = _createInstance(id, codebase); + + if (ids != null) + for (int i = 0; i < ids.length && o == null; i++) + o = _createInstance(ids[i], codebase); + return o; + } + + static Object _createInstance(String id, String codebase) + { + if (id == null) + return null; + if (id.equals(StringValueHelper.id())) + return ""; + StringTokenizer st = new StringTokenizer(id, ":"); + + String prefix = st.nextToken(); + if (prefix.equalsIgnoreCase("IDL")) + return ObjectCreator.Idl2Object(id); + else if (prefix.equalsIgnoreCase("RMI")) + { + String className = st.nextToken(); + String hashCode = st.nextToken(); + String sid = null; + if (st.hasMoreElements()) + sid = st.nextToken(); + try { - ((CustomMarshal) value).marshal((DataOutputStream) outObj); + Class objectClass = Util.loadClass(className, codebase, + Vio.class.getClassLoader()); + + String rid = ObjectCreator.getRepositoryId(objectClass); + + if (!rid.equals(id)) + { + // If direct string comparison fails, compare by meaning. + StringTokenizer st2 = new StringTokenizer(rid, ":"); + if (!st2.nextToken().equals("RMI")) + throw new InternalError("RMI format expected: '" + rid + "'"); + if (!st2.nextToken().equals(className)) + throwIt("Class name mismatch", id, rid, null); + + try + { + long h1 = Long.parseLong(hashCode, 16); + long h2 = Long.parseLong(st2.nextToken(), 16); + if (h1 != h2) + throwIt("Hashcode mismatch", id, rid, null); + + if (sid != null && st2.hasMoreTokens()) + { + long s1 = Long.parseLong(hashCode, 16); + long s2 = Long.parseLong(st2.nextToken(), 16); + if (s1 != s2) + throwIt("serialVersionUID mismatch", id, rid, null); + } + } + catch (NumberFormatException e) + { + throwIt("Invalid hashcode or svuid format: ", id, rid, e); + } + } + + // Low - level instantiation required here. + return instantiateAnyWay(objectClass); } - catch (ClassCastException ex) + catch (Exception ex) { - incorrect_plug_in(ex); + MARSHAL m = new MARSHAL("Unable to instantiate " + id); + m.minor = Minor.Instantiation; + m.initCause(ex); + throw m; } } - else if (value instanceof Streamable) + else + throw new NO_IMPLEMENT("Unsupported prefix " + prefix + ":"); + } + + /** + * Read string, expecting the probable indirection. + */ + static String read_string(InputStream input) + { + gnuValueStream g = (gnuValueStream) input; + int previous = g.getPosition(); + int l = input.read_long(); + if (l != vt_INDIRECTION) { - ((Streamable) value)._write(outObj); + g.seek(previous); + String s = input.read_string(); + if (g.getRunTime() == null) + g.setRunTime(new gnuRuntime(null, null)); + g.getRunTime().singleIdWritten(s, previous); + return s; } else { - // Try to find helper via class loader. - boolean ok = false; - try + gnuRuntime r = g.getRunTime(); + int base = g.getPosition(); + int delta = input.read_long(); + if (r == null) { - Class helperClass = Class.forName(ObjectCreator.toHelperName(id)); - - // It will be the helper for the encapsulated boxed value, not the - // for the global boxed value type itself. - Method write = - helperClass.getMethod("write", - new Class[] - { - org.omg.CORBA.portable.OutputStream.class, value.getClass() - } - ); - write.invoke(null, new Object[] { outObj, value }); - ok = true; + previous = g.getPosition(); + g.seek(base + delta); + String indir = input.read_string(); + g.seek(previous); + return indir; } - catch (Exception ex) + else { - ok = false; + return (String) r.isObjectWrittenAt(base + delta, delta); } + } + } - // Stating the interfaces that the USER should use. - if (!ok) - throw new MARSHAL("The " + value.getClass().getName() + - " must implement either StreamableValue" + " or CustomValue." - ); + /** + * Read string array, expecting the probable indirection. + */ + static String[] read_string_array(InputStream input) + { + gnuValueStream g = (gnuValueStream) input; + int previous = g.getPosition(); + int l = input.read_long(); + if (l != vt_INDIRECTION) + { + g.seek(previous); + String[] s = StringSeqHelper.read(input); + if (g.getRunTime() == null) + g.setRunTime(new gnuRuntime(null, null)); + g.getRunTime().objectWritten(s, previous); + return s; } + else + { + gnuRuntime r = g.getRunTime(); + int base = g.getPosition(); + int delta = input.read_long(); + if (r == null) + { + previous = g.getPosition(); + g.seek(base + delta); + String[] indir = StringSeqHelper.read(input); + g.seek(previous); + return indir; + } + else + { + return (String[]) r.isObjectWrittenAt(base + delta, delta); + } + } + } - if (USE_CHUNKING) + /** + * Write repository Id, probably shared. + */ + static void write_string(OutputStream output, String id) + { + if (output instanceof gnuValueStream) { - output.write_long(out.buffer.size()); - try + gnuValueStream b = (gnuValueStream) output; + if (b != null) + { + int written = b.getRunTime().idWrittenAt(id); + if (written >= 0) + { + // Reuse existing id record. + output.write_long(vt_INDIRECTION); + int p = b.getPosition(); + output.write_long(written - p); + } + else + { + b.getRunTime().singleIdWritten(id, b.getPosition()); + output.write_string(id); + } + } + } + else + output.write_string(id); + } + + /** + * Write repository Id, probably shared. + */ + static void write_string_array(OutputStream output, String[] ids) + { + if (output instanceof gnuValueStream) + { + gnuValueStream b = (gnuValueStream) output; + if (b != null) { - out.buffer.writeTo(output); + int written = b.getRunTime().idWrittenAt(ids); + if (written >= 0) + { + // Reuse existing id record. + output.write_long(vt_INDIRECTION); + int p = b.getPosition(); + output.write_long(written - p); + } + else + { + b.getRunTime().multipleIdsWritten(ids, b.getPosition()); + StringSeqHelper.write(output, ids); + } } - catch (IOException ex) + } + else + StringSeqHelper.write(output, ids); + } + + /** + * Get the helper that could write the given object, or null if no pre-defined + * helper available for this object. + */ + public static BoxedValueHelper getHelper(Class x, Object ids) + { + if (x != null && x.equals(String.class)) + return m_StringValueHelper; + else if (x != null && x.isArray()) + return new ArrayValueHelper(x); + else if (ids instanceof String) + return locateHelper((String) ids); + else if (ids instanceof String[]) + { + String[] ia = (String[]) ids; + BoxedValueHelper h; + for (int i = 0; i < ia.length; i++) { - MARSHAL m = new MARSHAL(); - m.initCause(ex); - throw m; + h = locateHelper(ia[i]); + if (h != null) + return h; } + return null; } + else + return null; + } - // The end of record marker, required by OMG standard. - output.write_long(-1); + /** + * Get the helper that could write the given object, or null if no pre-defined + * helper available for this object. + */ + public static BoxedValueHelper getHelper(Class x, String id) + { + if (x != null && x.equals(String.class)) + return m_StringValueHelper; + else if (x != null && x.isArray()) + return new ArrayValueHelper(x); + else + return locateHelper(id); } /** - * This can be called if the alternative CORBA implementation - * is incorrectly plugged in. - * - * @throws NO_IMPLEMENT, always. + * Try to locate helper from the repository id. */ - static void incorrect_plug_in(Throwable ex) throws NO_IMPLEMENT + static BoxedValueHelper locateHelper(String id) { - NO_IMPLEMENT no = new NO_IMPLEMENT("Incorrect CORBA plug-in"); - no.initCause(ex); - throw no; + if (id != null) + { + if (id.equals(m_StringValueHelper.get_id())) + return m_StringValueHelper; + else + // Try to locate helper for IDL type. + if (id.startsWith("IDL:")) + { + try + { + Class helperClass = ObjectCreator.findHelper(id); + if (BoxedValueHelper.class.isAssignableFrom(helperClass)) + return (BoxedValueHelper) helperClass.newInstance(); + else if (helperClass != null) + return new IDLTypeHelper(helperClass); + else + return null; + } + catch (Exception ex) + { + return null; + } + } + } + return null; } /** - * Check the passed value tag for correctness. - * - * @param value_tag a tag to check, must be between 0x7fffff00 and 0x7fffffff - * - * @throws MARSHAL if the tag is outside this interval. + * Get the current position. */ - private static final void checkTag(int value_tag) + static int getCurrentPosition(InputStream x) { - if ((value_tag < 0x7fffff00 || value_tag > 0x7fffffff) && - value_tag != vt_NULL && - value_tag != vt_INDIRECTION - ) - throw new MARSHAL("Invalid value record, unsupported header tag: " + - value_tag - ); + if (x instanceof gnuValueStream) + return ((gnuValueStream) x).getPosition(); + else + return 0; + } + + /** + * Instantiate an instance of this class anyway; also in the case when it has + * no parameterless or any other constructor. The fields will be assigned + * while reading the class from the stream. + * + * @param clazz a class for that the instance should be instantiated. + */ + public static Object instantiateAnyWay(Class clazz) + throws Exception + { + Class first_nonserial = clazz; + + while (Serializable.class.isAssignableFrom(first_nonserial) + || Modifier.isAbstract(first_nonserial.getModifiers())) + first_nonserial = first_nonserial.getSuperclass(); + + final Class local_constructor_class = first_nonserial; + + Constructor constructor = local_constructor_class.getDeclaredConstructor(new Class[0]); + + return VMVio.allocateObject(clazz, constructor.getDeclaringClass(), + constructor); } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java b/libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java deleted file mode 100644 index be92625..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java +++ /dev/null @@ -1,392 +0,0 @@ -/* abstractDataInputStream.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import java.io.IOException; - -/** - * Some data input stream that can be either Big or - * Little Endian. - * - * This class reuses code from GNU Classpath DataInputStream. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface abstractDataInputStream -{ - /** - * This method reads bytes from the underlying stream into the specified - * byte array buffer. It will attempt to fill the buffer completely, but - * may return a short count if there is insufficient data remaining to be - * read to fill the buffer. - * - * @param b The buffer into which bytes will be read. - * - * @return The actual number of bytes read, or -1 if end of stream reached - * before reading any bytes. - * - * @exception IOException If an error occurs. - */ - int read(byte[] b) - throws IOException; - - /** - * This method reads bytes from the underlying stream into the specified - * byte array buffer. It will attempt to read len bytes and - * will start storing them at position off into the buffer. - * This method can return a short count if there is insufficient data - * remaining to be read to complete the desired read length. - * - * @param b The buffer into which bytes will be read. - * @param off The offset into the buffer to start storing bytes. - * @param len The requested number of bytes to read. - * - * @return The actual number of bytes read, or -1 if end of stream reached - * before reading any bytes. - * - * @exception IOException If an error occurs. - */ - int read(byte[] b, int off, int len) - throws IOException; - - /** - * This method reads a Java boolean value from an input stream. It does - * so by reading a single byte of data. If that byte is zero, then the - * value returned is false. If the byte is non-zero, then - * the value returned is true. - *

- * This method can read a boolean written by an object - * implementing the writeBoolean() method in the - * DataOutput interface. - * - * @return The boolean value read - * - * @exception EOFException If end of file is reached before reading - * the boolean - * @exception IOException If any other error occurs - * - * @see DataOutput#writeBoolean - */ - boolean readBoolean() - throws IOException; - - /** - * This method reads a Java byte value from an input stream. The value - * is in the range of -128 to 127. - *

- * This method can read a byte written by an object - * implementing the writeByte() method in the - * DataOutput interface. - * - * @return The byte value read - * - * @exception EOFException If end of file is reached before reading the byte - * @exception IOException If any other error occurs - * - * @see DataOutput#writeByte - */ - byte readByte() - throws IOException; - - /** - * This method reads a Java char value from an input stream. - * It operates by reading two bytes from the stream and converting them to - * a single 16-bit Java char. The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 and byte2 - * represent the first and second byte read from the stream - * respectively, they will be transformed to a char in - * the following manner: - *

- * (char)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF) - *

- * This method can read a char written by an object - * implementing the writeChar() method in the - * DataOutput interface. - * - * @return The char value read - * - * @exception EOFException If end of file is reached before reading the char - * @exception IOException If any other error occurs - * - * @see DataOutput#writeChar - */ - char readChar() - throws IOException; - - /** - * This method reads a Java double value from an input stream. It operates - * by first reading a long value from the stream by calling the - * readLong() method in this interface, then converts - * that long to a double using the - * longBitsToDouble method in the class - * java.lang.Double - *

- * This method can read a double written by an object - * implementing the writeDouble() method in the - * DataOutput interface. - * - * @return The double value read - * - * @exception EOFException If end of file is reached before reading - * the double - * @exception IOException If any other error occurs - * - * @see DataOutput#writeDouble - * @see java.lang.Double#longBitsToDouble - */ - double readDouble() - throws IOException; - - /** - * This method reads a Java float value from an input stream. It - * operates by first reading an int value from the - * stream by calling the readInt() method in this - * interface, then converts that int to a - * float using the intBitsToFloat method - * in the class java.lang.Float - *

- * This method can read a float written by an object - * implementing the writeFloat() method in the - * DataOutput interface. - * - * @return The float value read - * - * @exception EOFException If end of file is reached before reading the float - * @exception IOException If any other error occurs - * - * @see DataOutput#writeFloat - * @see java.lang.Float#intBitsToFloat - */ - float readFloat() - throws IOException; - - /** - * This method reads raw bytes into the passed array until the array is - * full. Note that this method blocks until the data is available and - * throws an exception if there is not enough data left in the stream to - * fill the buffer. Note also that zero length buffers are permitted. - * In this case, the method will return immediately without reading any - * bytes from the stream. - * - * @param b The buffer into which to read the data - * - * @exception EOFException If end of file is reached before filling the - * buffer - * @exception IOException If any other error occurs - */ - void readFully(byte[] b) - throws IOException; - - /** - * This method reads a Java int value from an input stream - * It operates by reading four bytes from the stream and converting them to - * a single Java int. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 through byte4 represent - * the first four bytes read from the stream, they will be - * transformed to an int in the following manner: - *

- * (int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + - * ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF))) - *

- * The value returned is in the range of -2147483648 to 2147483647. - *

- * This method can read an int written by an object - * implementing the writeInt() method in the - * DataOutput interface. - * - * @return The int value read - * - * @exception EOFException If end of file is reached before reading the int - * @exception IOException If any other error occurs - * - * @see DataOutput#writeInt - */ - int readInt() - throws IOException; - - /** - * This method reads a Java long value from an input stream - * It operates by reading eight bytes from the stream and converting them to - * a single Java long. The bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 through byte8 represent - * the first eight bytes read from the stream, they will be - * transformed to an long in the following manner: - *

- * (long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + - * ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + - * ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + - * ((byte7 & 0xFF) << 8) + (byte8 & 0xFF))) - * - *

- * The value returned is in the range of -9223372036854775808 to - * 9223372036854775807. - *

- * This method can read an long written by an object - * implementing the writeLong() method in the - * DataOutput interface. - * - * @return The long value read - * - * @exception EOFException If end of file is reached before reading the long - * @exception IOException If any other error occurs - * - * @see DataOutput#writeLong - */ - long readLong() - throws IOException; - - /** - * This method reads a signed 16-bit value into a Java in from the - * stream. It operates by reading two bytes from the stream and - * converting them to a single 16-bit Java short. The - * two bytes are stored most significant byte first (i.e., "big - * endian") regardless of the native host byte ordering. - *

- * As an example, if byte1 and byte2 - * represent the first and second byte read from the stream - * respectively, they will be transformed to a short. in - * the following manner: - *

- * (short)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF)) - *

- * The value returned is in the range of -32768 to 32767. - *

- * This method can read a short written by an object - * implementing the writeShort() method in the - * DataOutput interface. - * - * @return The short value read - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeShort - */ - short readShort() - throws IOException; - - /** - * This method reads 8 unsigned bits into a Java int - * value from the stream. The value returned is in the range of 0 to - * 255. - *

- * This method can read an unsigned byte written by an object - * implementing the writeUnsignedByte() method in the - * DataOutput interface. - * - * @return The unsigned bytes value read as a Java int. - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeByte - */ - int readUnsignedByte() - throws IOException; - - /** - * This method reads 16 unsigned bits into a Java int value from the stream. - * It operates by reading two bytes from the stream and converting them to - * a single Java int The two bytes are stored most - * significant byte first (i.e., "big endian") regardless of the native - * host byte ordering. - *

- * As an example, if byte1 and byte2 - * represent the first and second byte read from the stream - * respectively, they will be transformed to an int in - * the following manner: - *

- * (int)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF)) - *

- * The value returned is in the range of 0 to 65535. - *

- * This method can read an unsigned short written by an object - * implementing the writeUnsignedShort() method in the - * DataOutput interface. - * - * @return The unsigned short value read as a Java int - * - * @exception EOFException If end of file is reached before reading the value - * @exception IOException If any other error occurs - * - * @see DataOutput#writeShort - */ - int readUnsignedShort() - throws IOException; - - /** - * Read a single byte. - * - * @return a byte, extracted from the stream or -1 if - * EOF has been reached. - * @throws IOException - */ - public int read() - throws IOException; - - /** - * This method attempts to skip and discard the specified number of bytes - * in the input stream. It may actually skip fewer bytes than requested. - * This method will not skip any bytes if passed a negative number of bytes - * to skip. - * - * @param n The requested number of bytes to skip. - * - * @return The requested number of bytes to skip. - * - * @exception IOException If an error occurs. - * @specnote The JDK docs claim that this returns the number of bytes - * actually skipped. The JCL claims that this method can throw an - * EOFException. Neither of these appear to be true in the JDK 1.3's - * implementation. This tries to implement the actual JDK behaviour. - */ - int skipBytes(int n) - throws IOException; -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java deleted file mode 100644 index 2f9b8c4..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java +++ /dev/null @@ -1,185 +0,0 @@ -/* abstractDataOutputStream.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import java.io.IOException; - -/** - * An abstract data output stream that could write data in either - * Big Endian or Little Endian format. - * - * This class reuses code from GNU Classpath DataOutputStream. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - * @author Warren Levy (warrenl@cygnus.com) - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public interface abstractDataOutputStream -{ - /** - * This method flushes any unwritten bytes to the underlying stream. - * - * @exception IOException If an error occurs. - */ - void flush() - throws IOException; - - /** - * This method writes the specified byte (passed as an int) - * to the underlying output stream. - * - * @param value The byte to write, passed as an int. - * - * @exception IOException If an error occurs. - */ - void write(int value) - throws IOException; - - /** - * This method writes len bytes from the specified byte array - * buf starting at position offset into the - * buffer to the underlying output stream. - * - * @param buf The byte array to write from. - * @param offset The index into the byte array to start writing from. - * @param len The number of bytes to write. - * - * @exception IOException If an error occurs. - */ - void write(byte[] buf, int offset, int len) - throws IOException; - - /** - * Write the complete byte array. - * @throws IOException - */ - void write(byte[] buf) - throws IOException; - - /** - * This method writes a Java boolean value to an output stream. If - * value is true, a byte with the value of - * 1 will be written, otherwise a byte with the value of 0 will be - * written. - * - * The value written can be read using the readBoolean - * method in DataInput. - * - * @param value The boolean value to write to the stream - * - * @exception IOException If an error occurs - */ - void writeBoolean(boolean value) - throws IOException; - - /** - * This method writes a Java byte value to an output stream. The - * byte to be written will be in the lowest 8 bits of the - * int value passed. - * - * The value written can be read using the readByte or - * readUnsignedByte methods in DataInput. - * - * @param value The byte to write to the stream, passed as - * the low eight bits of an int. - * - * @exception IOException If an error occurs - */ - void writeByte(int value) - throws IOException; - - /** - * This method writes a Java short value to an output stream. The - * char to be written will be in the lowest 16 bits of the int - * value passed. - * - * @exception IOException If an error occurs - */ - void writeShort(int value) - throws IOException; - - /** - * This method writes a Java char value to an output stream. The - * char to be written will be in the lowest 16 bits of the int - * value passed. - * - * @exception IOException If an error occurs - */ - void writeChar(int value) - throws IOException; - - /** - * This method writes a Java int value to an output stream. - * - * @param value The int value to write to the stream - * - * @exception IOException If an error occurs - */ - void writeInt(int value) - throws IOException; - - /** - * This method writes a Java long value to an output stream. - * - * @param value The long value to write to the stream - * - * @exception IOException If an error occurs - */ - void writeLong(long value) - throws IOException; - - /** - * This method writes a Java float value to the stream. - * @param value The float value to write to the stream - * - * @exception IOException If an error occurs - */ - void writeFloat(float value) - throws IOException; - - /** - * This method writes a Java double value to the stream. - * - * @param value The double value to write to the stream - * - * @exception IOException If an error occurs - */ - void writeDouble(double value) - throws IOException; -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java b/libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java deleted file mode 100644 index a719b32..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java +++ /dev/null @@ -1,122 +0,0 @@ -/* aligningInputStream.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import java.io.ByteArrayInputStream; - -import org.omg.CORBA.BAD_PARAM; - -/** - * The input stream with the possibility to align on the - * word (arbitrary size) boundary. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class aligningInputStream - extends ByteArrayInputStream -{ - /** - * The alignment offset. - */ - private int offset = 0; - - /** - * Create a stream, reading form the given buffer. - * - * @param a_buffer a buffer to read from. - */ - public aligningInputStream(byte[] a_buffer) - { - super(a_buffer); - } - - /** - * Create a stream, reading from the given buffer region. - * - * @param a_buffer a buffer to read from. - * @param offset the offset of the region. - * @param length thr length of the region. - */ - public aligningInputStream(byte[] a_buffer, int offset, int length) - { - super(a_buffer, offset, length); - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public void setOffset(int an_offset) - { - offset = an_offset; - } - - /** - * Skip several bytes, aligning the internal pointer on the - * selected boundary. - * - * @throws BAD_PARAM, minor code 0, the alignment is not possible, - * usually due the wrong parameter value. - */ - public void align(int alignment) - { - try - { - int d = (pos + offset) % alignment; - if (d > 0) - { - skip(alignment - d); - } - } - catch (Exception ex) - { - BAD_PARAM p = new BAD_PARAM("Unable to align at " + alignment); - p.initCause(ex); - throw p; - } - } - - /** - * Get the byte buffer, from where the data are read. - */ - public byte[] getBuffer() - { - return buf; - } -} diff --git a/libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java deleted file mode 100644 index 8a682c1..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java +++ /dev/null @@ -1,121 +0,0 @@ -/* aligningOutputStream.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -import org.omg.CORBA.BAD_PARAM; - -/** - * The input stream with the possibility to align on the - * word (arbitrary size) boundary. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class aligningOutputStream - extends ByteArrayOutputStream -{ - /** - * The alignment offset. - */ - private int offset = 0; - - /** - * Create a stream with the default intial buffer size. - */ - public aligningOutputStream() - { - } - - /** - * Create a stream with the given intial buffer size. - */ - public aligningOutputStream(int initial_size) - { - super(initial_size); - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public void setOffset(int an_offset) - { - offset = an_offset; - } - - /** - * Skip several bytes, aligning the internal pointer on the - * selected boundary. - * - * @throws BAD_PARAM, minor code 0, the alignment is not possible, - * usually due the wrong parameter value. - */ - public void align(int alignment) - { - try - { - int d = (count + offset) % alignment; - if (d > 0) - { - skip(alignment - d); - } - } - catch (Exception ex) - { - BAD_PARAM p = new BAD_PARAM("Unable to align at " + alignment); - p.initCause(ex); - throw p; - } - } - - /** - * Write the specified number of zero bytes. - * - * @param bytes the number of zero bytes to write. - */ - public void skip(int bytes) - { - for (int i = 0; i < bytes; i++) - { - write(0); - } - } -} diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java b/libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java deleted file mode 100644 index 3cab721..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java +++ /dev/null @@ -1,115 +0,0 @@ -/* cdrBufInput.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - - -/** - * The CDR input stream that reads data from the byte buffer. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - * - * TODO character encoding. Now the encoding can be set, but it is ignored. - * If you take this task, scan 'TODO character encoding' for - * relevant places. - */ -public class cdrBufInput - extends cdrInput -{ - /** - * The byte array input stream to read data from. - */ - public final aligningInputStream buffer; - - /** - * Creates the CDR input stream that reads from the given buffer - * array. - * - * @param a_buffer an array to read from. - */ - public cdrBufInput(byte[] a_buffer) - { - buffer = new aligningInputStream(a_buffer); - setInputStream(buffer); - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public void setOffset(int offset) - { - buffer.setOffset(offset); - } - - /** - * Skip several bytes, aligning the internal pointer on the - * selected boundary. - */ - public void align(int alignment) - { - buffer.align(alignment); - } - - /** - * Mark the current position. - * @param ahead - */ - public synchronized void mark(int ahead) - { - buffer.mark(ahead); - } - - /** - * Checks if marking is supported. - * @return - */ - public boolean markSupported() - { - return buffer.markSupported(); - } - - /** - * Resets the stream to the previously marked position. - */ - public void reset() - { - buffer.reset(); - setInputStream(buffer); - } -} diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java b/libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java deleted file mode 100644 index 47f5f17..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java +++ /dev/null @@ -1,115 +0,0 @@ -/* cdrBufOutput.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import java.io.ByteArrayOutputStream; - -/** - * A CORBA output stream, writing data into the internal - * buffer ({@link ByteArrayOutputStream}). - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class cdrBufOutput - extends cdrOutput -{ - /** - * The byte buffer. - */ - public final aligningOutputStream buffer; - - /** - * Creates the instance with the given initial buffer size. - * @param bufSize the buffer size. - */ - public cdrBufOutput(int bufSize) - { - buffer = new aligningOutputStream(bufSize); - setOutputStream(buffer); - } - - /** - * Creates the instance with the default buffer size. - */ - public cdrBufOutput() - { - buffer = new aligningOutputStream(); - setOutputStream(buffer); - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public void setOffset(int an_offset) - { - buffer.setOffset(an_offset); - } - - /** - * Align the curretn position at the given natural boundary. - */ - public void align(int boundary) - { - buffer.align(boundary); - } - - /** - * Return the input stream that reads the previously written values. - */ - public org.omg.CORBA.portable.InputStream create_input_stream() - { - cdrBufInput in = new cdrBufInput(buffer.toByteArray()); - in.setOrb(orb); - - in.setVersion(giop); - in.setCodeSet(getCodeSet()); - - return in; - } - - /** - * Resets (clears) the buffer. - */ - public void reset() - { - buffer.reset(); - setOutputStream(buffer); - } -} diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrInput.java b/libjava/classpath/gnu/CORBA/CDR/cdrInput.java deleted file mode 100644 index 69f9c8c..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/cdrInput.java +++ /dev/null @@ -1,1672 +0,0 @@ -/* cdrInput.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import gnu.CORBA.BigDecimalHelper; -import gnu.CORBA.Functional_ORB; -import gnu.CORBA.GIOP.CharSets_OSF; -import gnu.CORBA.GIOP.cxCodeSet; -import gnu.CORBA.IOR; -import gnu.CORBA.IOR_Delegate; -import gnu.CORBA.TypeCodeHelper; -import gnu.CORBA.Unexpected; -import gnu.CORBA.Version; -import gnu.CORBA.gnuAny; -import gnu.CORBA.stubFinder; - -import org.omg.CORBA.Any; -import org.omg.CORBA.AnySeqHolder; -import org.omg.CORBA.BAD_OPERATION; -import org.omg.CORBA.BooleanSeqHolder; -import org.omg.CORBA.CharSeqHolder; -import org.omg.CORBA.DoubleSeqHolder; -import org.omg.CORBA.FloatSeqHolder; -import org.omg.CORBA.LongLongSeqHolder; -import org.omg.CORBA.LongSeqHolder; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.ORB; -import org.omg.CORBA.OctetSeqHolder; -import org.omg.CORBA.ShortSeqHolder; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; -import org.omg.CORBA.TypeCodePackage.Bounds; -import org.omg.CORBA.ULongLongSeqHolder; -import org.omg.CORBA.ULongSeqHolder; -import org.omg.CORBA.UShortSeqHolder; -import org.omg.CORBA.WCharSeqHolder; -import org.omg.CORBA.portable.InputStream; -import org.omg.CORBA.portable.ObjectImpl; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Serializable; - -import java.math.BigDecimal; - -/** - * A simple CORBA CDR (common data representation) - * input stream, reading data from the - * given {@link java.io.InputStream}. The primitive types - * are aligned on they natural boundaries by implementing the - * abstract method {@link #align(int boundary)}. - * - * The same class also implements {@link org.omg.CORBA.DataInputStream} to - * read the object content in a user defined way. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public abstract class cdrInput - extends org.omg.CORBA_2_3.portable.InputStream - implements org.omg.CORBA.DataInputStream -{ - /** - * The message, explaining that the exception has been thrown due - * unexpected end of the input stream. This usually happens the - * server and client disagree on communication or data representation - * rules. - */ - protected static final String UNEXP_EOF = "Unexpected end of stream"; - - /** - * This instance is used to convert primitive data types into the - * byte sequences. - */ - protected abstractDataInputStream b; - - /** - * The input stream, from where the data are actually - * being read. - */ - protected java.io.InputStream actual_stream; - - /** - * The associated orb, if any. - */ - protected ORB orb; - - /** - * The GIOP version. - */ - protected Version giop = new Version(1, 2); - - /** - * The code set information. - */ - protected cxCodeSet codeset = cxCodeSet.STANDARD; - - /** - * The name of the currently used narrow charset, null if - * the native narrow charset is used. - */ - private String narrow_charset = null; - - /** - * The name of the currently used wide charset, null if - * the native wide charset is used. - */ - private String wide_charset = null; - - /** - * True if the native code set is used for narrow characters. - * If the set is native, no the intermediate Reader object - * is instantiated when writing characters. - */ - private boolean narrow_native; - - /** - * True if the native code set is used for wide characters. - * If the set is native, no the intermediate Reader object - * is instantiated when writing characters. - */ - private boolean wide_native; - - /** - * If true, the stream expect - * the multi-byte data in the form "less significant byte - * first" (Little Endian). This is the opposite to the - * java standard (Big Endian). - */ - private boolean little_endian; - - /** - * Creates the stream. The stream reads Big Endian by - * default. - * - * @param readFrom a stream to read CORBA input from. - */ - public cdrInput(java.io.InputStream readFrom) - { - setInputStream(readFrom); - setCodeSet(cxCodeSet.STANDARD); - } - - /** - * Creates the stream, requiring the subsequent call - * of {@link #setInputStream(java.io.InputStream)}. - */ - public cdrInput() - { - setCodeSet(cxCodeSet.STANDARD); - } - - /** - * Set the Big Endian or Little Endian encoding. - * The stream reads Big Endian by default. - * - * @param use_little_endian if true, the stream expect - * the multi-byte data in the form "less significant byte - * first" (Little Endian). This is the opposite to the - * java standard (Big Endian). - */ - public void setBigEndian(boolean use_big_endian) - { - little_endian = !use_big_endian; - setInputStream(actual_stream); - } - - /** - * Set the input stream that receives the CORBA input. - * - * @param readFrom the stream. - */ - public void setInputStream(java.io.InputStream readFrom) - { - if (little_endian) - b = new LittleEndianInputStream(readFrom); - else - b = new BigEndianInputStream(readFrom); - - actual_stream = readFrom; - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public abstract void setOffset(int offset); - - /** - * Set the orb, associated with this stream. - * @param an_orb - */ - public void setOrb(ORB an_orb) - { - orb = an_orb; - } - - /** - * Set the GIOP version. Some data types are written differently - * for the different versions. The default version is 1.0 . - */ - public void setVersion(Version giop_version) - { - giop = giop_version; - } - - /** - * Align the curretn position at the given natural boundary. - */ - public abstract void align(int boundary); - - /** - * Reads the CORBA unsigned long (java int), returning the - * value in the sufficiently large java long. - */ - public long gnu_read_ulong() - { - try - { - long l = b.readInt(); - l &= 0xFFFFFFF; - return l; - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the unsigned short integer value and return it as java - * int, sufficiently large to hold all values. - */ - public int gnu_read_ushort() - { - try - { - align(2); - return b.readUnsignedShort(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Return the associated {@link ORB}. - * @return the associated {@link ORB} or null is no such is set. - */ - public ORB orb() - { - return orb; - } - - /** - * Read a single byte directly from the buffer. - */ - public int read() - throws java.io.IOException - { - try - { - return b.read(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - } - - /** - * Read bytes directly from the buffer. - */ - public int read(byte[] x, int ofs, int len) - throws java.io.IOException - { - try - { - return b.read(x, ofs, len); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - } - - /** - * Read bytes directly from the buffer. - */ - public int read(byte[] x) - throws java.io.IOException - { - try - { - return b.read(x); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - } - - /** - * Read the CORBA object. The object to read is represented in the - * form of the plain (not a string-encoded) IOR profile without the - * heading endian indicator. The responsible method for reading such - * data is {@link IOR.read_no_endian}. - * - * The returned object is usually casted into the given type using - * the .narrow method of its helper, despite in some cases the direct - * cast would also work. - * - * The null objects are recognised from the empty profile set. - * For such objects, null is returned. - * - * @return the loaded and constructed object. - */ - public org.omg.CORBA.Object read_Object() - { - try - { - IOR ior = new IOR(); - ior._read_no_endian(this); - - if (ior.Id == null) - return null; - - // Check maybe this is a remote reference to the local object. - // This is only possible if we access the repository of the - // connected object. - if (orb instanceof Functional_ORB) - { - Functional_ORB forb = (Functional_ORB) orb; - org.omg.CORBA.Object local = forb.find_local_object(ior); - if (local != null) - return local; - } - - // Search for the available stubs. - ObjectImpl impl = stubFinder.search(orb, ior); - try - { - if (impl._get_delegate() == null) - impl._set_delegate(new IOR_Delegate(orb, ior)); - } - catch (BAD_OPERATION ex) - { - // Some colaborants may throw this exception - // in response to the attempt to get the unset delegate. - impl._set_delegate(new IOR_Delegate(orb, ior)); - } - - return impl; - } - catch (IOException ex) - { - BAD_OPERATION bad = new BAD_OPERATION(); - bad.initCause(ex); - throw bad; - } - } - - /** - * Read the type code. The type code format is defined in the - * CORBA documenation. - */ - public TypeCode read_TypeCode() - { - try - { - return TypeCodeHelper.read(this); - } - - catch (Bounds ex) - { - throw new Unexpected(); - } - catch (BadKind ex) - { - throw new Unexpected(); - } - } - - /** - * Read the CORBA {@link Any}. This method first reads the - * type code, then delegates the functionality - * to {@link Any#read_value}. - */ - public Any read_any() - { - TypeCode ty = read_TypeCode(); - gnuAny any = new gnuAny(); - any.read_value(this, ty); - return any; - } - - /** - * Read the boolean, treating any non zero byte as true, - * zero byte as false. - */ - public boolean read_boolean() - { - try - { - return b.read() == 0 ? false : true; - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the array of boolean. - */ - public void read_boolean_array(boolean[] x, int offs, int len) - { - try - { - for (int i = offs; i < offs + len; i++) - { - x [ i ] = b.read() == 0 ? false : true; - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read a character using narrow charset encoding. Depending form - * which encoding is set, this still can be Unicode or ever wider. - */ - public char read_char() - { - try - { - if (narrow_native) - return (char) b.read(); - else - return (char) new InputStreamReader((InputStream) b, narrow_charset).read(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read a character array, using narrow charset encoding. - */ - public void read_char_array(char[] x, int offset, int length) - { - try - { - if (narrow_native) - { - for (int i = offset; i < offset + length; i++) - x [ i ] = (char) b.read(); - } - else - { - InputStreamReader reader = - new InputStreamReader((InputStream) b, narrow_charset); - reader.read(x, offset, length); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the double value, IEEE 754 format. - */ - public double read_double() - { - try - { - align(8); - return b.readDouble(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(); - } - } - - /** - * Read the array of double values, IEEE 754 format. - */ - public void read_double_array(double[] x, int offs, int len) - { - try - { - align(8); - for (int i = offs; i < offs + len; i++) - { - x [ i ] = b.readDouble(); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the encapsulated stream. - * If the encapsulated sequence appears to be in the - * Little endian format, the flag of the returned stream - * is set to read Little endian. - */ - public cdrBufInput read_encapsulation() - { - try - { - int l = read_long(); - - byte[] r = new byte[ l ]; - int n = 0; - reading: - while (n < r.length) - { - n += read(r, n, r.length - n); - } - - cdrBufInput capsule = new cdrBufInput(r); - capsule.setOrb(orb); - - int endian = capsule.read_octet(); - - if (endian != 0) - { - capsule.setBigEndian(false); - } - - return capsule; - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the CORBA fixed (the end of the fixed - * can be determined by its last byte). The scale is always - * assumed to be zero. - */ - public BigDecimal read_fixed() - { - try - { - return BigDecimalHelper.read(this, 0); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the float value, IEEE 754 format. - */ - public float read_float() - { - try - { - align(4); - return b.readFloat(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read an array of float values, IEEE 754 format. - */ - public void read_float_array(float[] x, int offs, int len) - { - try - { - align(4); - for (int i = offs; i < offs + len; i++) - { - x [ i ] = b.readFloat(); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the CORBA long (java int), high byte first. - */ - public int read_long() - { - try - { - align(4); - return b.readInt(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read an array of CORBA longs (java ints). - */ - public void read_long_array(int[] x, int offs, int len) - { - try - { - align(4); - for (int i = offs; i < offs + len; i++) - { - x [ i ] = b.readInt(); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the CORBA long long (java long). - */ - public long read_longlong() - { - try - { - align(8); - return b.readLong(); - } - catch (EOFException ex) - { - throw new MARSHAL(UNEXP_EOF); - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read an array of CORBA long longs (java longs). - */ - public void read_longlong_array(long[] x, int offs, int len) - { - try - { - align(8); - for (int i = offs; i < offs + len; i++) - { - x [ i ] = b.readLong(); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read a single byte. - */ - public byte read_octet() - { - try - { - return b.readByte(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the byte array. - */ - public void read_octet_array(byte[] x, int offs, int len) - { - try - { - b.read(x, offs, len); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the length of the byte array as CORBA long and then - * the array itseld. - */ - public byte[] read_sequence() - { - try - { - int l = read_long(); - byte[] b = new byte[ l ]; - if (l > 0) - { - read(b); - } - return b; - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the CORBA short integer. - */ - public short read_short() - { - try - { - align(2); - return b.readShort(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read the array of CORBA short integer values. - */ - public void read_short_array(short[] x, int offs, int len) - { - try - { - align(2); - for (int i = offs; i < offs + len; i++) - { - x [ i ] = b.readShort(); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Read a singe byte string. The method firs reads the - * byte array and then calls a constructor to create a - * string from this array. The character encoding, if - * previously set, is taken into consideration. - * - * @return a loaded string. - */ - public String read_string() - { - try - { - align(4); - - int n = b.readInt(); - byte[] s = new byte[ n ]; - b.read(s); - - // Discard the null terminator. - if (narrow_charset == null) - return new String(s, 0, n - 1); - else - return new String(s, 0, n - 1, narrow_charset); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(); - } - } - - /** - * Reads the CORBA unsigned long (java int), delegating - * functionality to {@link #read_long}. - */ - public int read_ulong() - { - return read_long(); - } - - /** - * Reads the array of CORBA unsigned long (java integer) values, - * delegating functionality to - * {@link #real_long_array}. - */ - public void read_ulong_array(int[] x, int offs, int len) - { - read_long_array(x, offs, len); - } - - /** - * Read the CORBA unsigned long long value, - * delegating functionality to {@link #read_longlong}. - * There is no way to return values over the limit of - * the java signed long in other way than returning - * the negative value. - */ - public long read_ulonglong() - { - return read_longlong(); - } - - /** - * Reads the array of CORBA long long (java long) values, - * delegating functionality to - * {@link #real_longlong_array}. - */ - public void read_ulonglong_array(long[] x, int offs, int len) - { - read_longlong_array(x, offs, len); - } - - /** - * Read the unsigned short integer value. Due strange specification, - * the returned value must be the short type as well, so the - * the best solution seems just to delegete functionality to - * read_short. - */ - public short read_ushort() - { - return read_short(); - } - - /** - * Read an array of unsigned short values, delegating the - * functionality to {@link read_short_array}. - */ - public void read_ushort_array(short[] x, int offs, int len) - { - read_short_array(x, offs, len); - } - - /** - * Reads the wide character using the encoding, specified in the - * wide_charset. - */ - public char read_wchar() - { - try - { - if (giop.until_inclusive(1, 1)) - align(2); - - if (wide_native) - return (char) b.readShort(); - else - return (char) new InputStreamReader((InputStream) b, wide_charset).read(); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - catch (IOException ex) - { - throw new Unexpected(); - } - } - - /** - * Read an array of "wide chars", each representing a two byte - * Unicode character, high byte first. - */ - public void read_wchar_array(char[] x, int offset, int length) - { - try - { - if (giop.until_inclusive(1, 1)) - align(2); - - if (wide_native) - { - for (int i = offset; i < offset + length; i++) - x [ i ] = (char) b.readShort(); - } - else - { - InputStreamReader reader = - new InputStreamReader((InputStream) b, wide_charset); - reader.read(x, offset, length); - } - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Reads the string in wide character format - * (ussually UTF-16, Unicode). Takes the currently set charset - * into consideration. - * - * If the native (UTF-16) encoding is used - * of the GIOP protocol is before 1.2, delegates functionality - * to "plain" {@link #read_wstring_UTF_16}. - */ - public String read_wstring() - { - // Native encoding or word oriented data. - if (wide_native || giop.until_inclusive(1, 1)) - return read_wstring_UTF_16(); - try - { - align(4); - - int n = b.readInt(); - byte[] s = new byte[ n ]; - b.read(s); - - return new String(s, 0, n, wide_charset); - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Reads first length of the string and the all characters as an - * Unicode (UTF-16) characters. Mind that GIOP 1.1 has the extra - * null character at the end that must be discarded. - */ - public String read_wstring_UTF_16() - { - try - { - int p = 0; - int n = read_long(); - - // The null terminator that is no longer present since 1.2 . - int nt = giop.since_inclusive(1, 2) ? 0 : 1; - - // Convert bytes to shorts. - n = n / 2; - - char[] s = new char[ n ]; - - for (int i = 0; i < s.length; i++) - s [ i ] = (char) b.readShort(); - - // Check for the byte order marker here. - if (s [ 0 ] == 0xFEFF) - { - // Big endian encoding - do nothing, but move the pointer - // one position forward. - p = 1; - } - else if (s [ 0 ] == 0xFFFE) - { - // Little endian encoding, swap the bytes and move one - // position forward. - p = 1; - - for (int i = p; i < s.length; i++) - s [ i ] = swap(s [ i ]); - } - - // Discard the null terminator and, if needed, the endian marker. - String r = new String(s, p, n - nt - p); - return r; - } - catch (EOFException ex) - { - MARSHAL t = new MARSHAL(UNEXP_EOF); - t.initCause(ex); - throw t; - } - - catch (IOException ex) - { - throw new Unexpected(ex); - } - } - - /** - * Swap bytes in the character. - */ - public static char swap(char x) - { - int hi; - int lo; - - lo = x & 0xFF; - hi = (x >> 8) & 0xFF; - - return (char) ((lo << 8) | hi); - } - - /** - * Set the current code set context. - */ - public void setCodeSet(cxCodeSet a_codeset) - { - this.codeset = a_codeset; - narrow_charset = CharSets_OSF.getName(codeset.char_data); - wide_charset = CharSets_OSF.getName(codeset.wide_char_data); - - narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data; - wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data; - } - - /** - * Get the current code set context. - */ - public cxCodeSet getCodeSet() - { - return codeset; - } - - /** - * Read the object that is an instance of the given class. The current - * implementation delegates functionality to the parameterless - * {@link readObject()}. - * - * @param klass a class of that this object the instance is. - * - * @return the returned object. - */ - public org.omg.CORBA.Object read_Object(Class klass) - { - return read_Object(); - } - - /** - * Read a value type structure from the stream. - * - * OMG specification states the writing format is outside the scope - * of GIOP definition. This implementation uses java serialization - * mechanism, calling {@link ObjectInputStream#readObject} - * - * @return an value type structure, unmarshaled from the stream - */ - public Serializable read_Value() - { - return read_value(); - } - - /** - * Read the abstract interface. An abstract interface can be either - * CORBA value type or CORBA object and is returned as an abstract - * java.lang.Object. - * - * As specified in OMG specification, this reads a single - * boolean and then delegates either to {@link #read_Object()} (for false) - * or to {@link #read_Value()} (for true). - * - * @return an abstract interface, unmarshaled from the stream - */ - public java.lang.Object read_Abstract() - { - return read_abstract_interface(); - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_char_array(CharSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_char_array(holder.value, offset, length); - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_wchar_array(WCharSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_wchar_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the char array to fit the newly - * read values. - * - * @param holder_value the existing char array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private char[] ensureArray(char[] holder_value, int offset, int length) - { - if (holder_value == null) - return new char[ offset + length ]; - else if (holder_value.length < offset + length) - { - char[] value = new char[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_ulong_array(ULongSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_ulong_array(holder.value, offset, length); - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_long_array(LongSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_ulong_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the int array to fit the newly - * read values. - * - * @param holder_value the existing int array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private int[] ensureArray(int[] holder_value, int offset, int length) - { - if (holder_value == null) - return new int[ offset + length ]; - else if (holder_value.length < offset + length) - { - int[] value = new int[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_float_array(FloatSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_float_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the float array to fit the newly - * read values. - * - * @param holder_value the existing float array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private float[] ensureArray(float[] holder_value, int offset, int length) - { - if (holder_value == null) - return new float[ offset + length ]; - else if (holder_value.length < offset + length) - { - float[] value = new float[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_double_array(DoubleSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_double_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the double array to fit the newly - * read values. - * - * @param holder_value the existing double array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private double[] ensureArray(double[] holder_value, int offset, int length) - { - if (holder_value == null) - return new double[ offset + length ]; - else if (holder_value.length < offset + length) - { - double[] value = new double[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_short_array(ShortSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_short_array(holder.value, offset, length); - } - - /** {@inheritDoc} */ - public void read_ushort_array(UShortSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_ushort_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the short array to fit the newly - * read values. - * - * @param holder_value the existing short array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private short[] ensureArray(short[] holder_value, int offset, int length) - { - if (holder_value == null) - return new short[ offset + length ]; - else if (holder_value.length < offset + length) - { - short[] value = new short[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_octet_array(OctetSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_octet_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the byte array to fit the newly - * read values. - * - * @param holder_value the existing byte array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private byte[] ensureArray(byte[] holder_value, int offset, int length) - { - if (holder_value == null) - return new byte[ offset + length ]; - else if (holder_value.length < offset + length) - { - byte[] value = new byte[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_longlong_array(LongLongSeqHolder holder, int offset, - int length - ) - { - holder.value = ensureArray(holder.value, offset, length); - read_longlong_array(holder.value, offset, length); - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_ulonglong_array(ULongLongSeqHolder holder, int offset, - int length - ) - { - holder.value = ensureArray(holder.value, offset, length); - read_ulonglong_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the array of longs to fit the newly - * read values. - * - * @param holder_value the existing array, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private long[] ensureArray(long[] holder_value, int offset, int length) - { - if (holder_value == null) - return new long[ offset + length ]; - else if (holder_value.length < offset + length) - { - long[] value = new long[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_boolean_array(BooleanSeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - read_boolean_array(holder.value, offset, length); - } - - /** - * If required, allocate or resize the array of booleans to fit the newly - * read values. - * - * @param holder_value the existing array of booleans, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private boolean[] ensureArray(boolean[] holder_value, int offset, int length) - { - if (holder_value == null) - return new boolean[ offset + length ]; - else if (holder_value.length < offset + length) - { - boolean[] value = new boolean[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * Read an array. In OMG specification is written that if the data does - * not fit into the holder value field, that array must be resized. - * The implementation follows this rule. If the holder value field - * contains null, it is newly instantiated. - */ - public void read_any_array(AnySeqHolder holder, int offset, int length) - { - holder.value = ensureArray(holder.value, offset, length); - for (int i = offset; i < offset + length; i++) - { - holder.value [ i ] = read_any(); - } - } - - /** - * If required, allocate or resize the array of Anys to fit the newly - * read values. - * - * @param holder_value the existing array of Anys, may be null. - * @param offset the required offset to read. - * @param length the length of the new sequence. - * - * @return the allocated or resized array, same array if no such operations - * are required. - */ - private Any[] ensureArray(Any[] holder_value, int offset, int length) - { - if (holder_value == null) - return new Any[ offset + length ]; - else if (holder_value.length < offset + length) - { - Any[] value = new Any[ offset + length ]; - System.arraycopy(holder_value, 0, value, 0, holder_value.length); - return value; - } - else - return holder_value; - } - - /** - * This method is required to represent the DataInputStream as a value - * type object. - * - * @return a single entity "IDL:omg.org/CORBA/DataInputStream:1.0", - * always. - */ - public String[] _truncatable_ids() - { - return new String[] { "IDL:omg.org/CORBA/DataInputStream:1.0" }; - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrOutput.java b/libjava/classpath/gnu/CORBA/CDR/cdrOutput.java deleted file mode 100644 index 85f341c..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/cdrOutput.java +++ /dev/null @@ -1,1009 +0,0 @@ -/* cdrOutput.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import gnu.CORBA.BigDecimalHelper; -import gnu.CORBA.GIOP.CharSets_OSF; -import gnu.CORBA.GIOP.cxCodeSet; -import gnu.CORBA.Poa.gnuServantObject; -import gnu.CORBA.IOR; -import gnu.CORBA.Simple_delegate; -import gnu.CORBA.TypeCodeHelper; -import gnu.CORBA.Unexpected; -import gnu.CORBA.Version; -import gnu.CORBA.primitiveTypeCode; - -import org.omg.CORBA.Any; -import org.omg.CORBA.BAD_OPERATION; -import org.omg.CORBA.Context; -import org.omg.CORBA.ContextList; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.NO_IMPLEMENT; -import org.omg.CORBA.ORB; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; -import org.omg.CORBA.UserException; -import org.omg.CORBA.portable.Delegate; -import org.omg.CORBA.portable.ObjectImpl; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.Streamable; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Serializable; - -import java.math.BigDecimal; - -/** - * A simple CORBA CDR (common data representation) - * output stream, writing data into the - * given {@link java.io.OutputStream}. - * - * The same class also implements the {@link DataInputStream}, - * providing support for writing the value type objects - * in a user defined way. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public abstract class cdrOutput - extends org.omg.CORBA_2_3.portable.OutputStream - implements org.omg.CORBA.DataOutputStream -{ - /** - * This instance is used to convert primitive data types into the - * byte sequences. - */ - protected abstractDataOutputStream b; - - /** - * The associated orb, if any. - */ - protected ORB orb; - - /** - * The GIOP version. - */ - protected Version giop = new Version(1, 2); - - /** - * The code set information. - */ - protected cxCodeSet codeset; - - /** - * The name of the currently used narrow charset. - */ - private String narrow_charset; - - /** - * The name of the currently used wide charset, null if - * the native wide charset is used. - */ - private String wide_charset; - - /** - * True if the native code set is used for narrow characters. - * If the set is native, no the intermediate Reader object - * is instantiated when writing characters. - */ - private boolean narrow_native; - - /** - * True if the native code set is used for wide characters. - * If the set is native, no the intermediate Reader object - * is instantiated when writing characters. - */ - private boolean wide_native; - - /** - * If true, the Little Endian encoding is used to write the - * data. Otherwise, the Big Endian encoding is used. - */ - private boolean little_endian; - - /** - * The stream whre the data are actually written. - */ - private java.io.OutputStream actual_stream; - - /** - * Creates the stream. - * - * @param writeTo a stream to write CORBA output to. - */ - public cdrOutput(java.io.OutputStream writeTo) - { - setOutputStream(writeTo); - setCodeSet(cxCodeSet.STANDARD); - } - - /** - * Creates the stream, requiring the subsequent call - * of {@link #setOutputStream(java.io.OutputStream)}. - */ - public cdrOutput() - { - setCodeSet(cxCodeSet.STANDARD); - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public abstract void setOffset(int an_offset); - - /** - * Set the current code set context. - */ - public void setCodeSet(cxCodeSet a_codeset) - { - this.codeset = a_codeset; - narrow_charset = CharSets_OSF.getName(codeset.char_data); - wide_charset = CharSets_OSF.getName(codeset.wide_char_data); - - narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data; - wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data; - } - - /** - * Get the current code set context. - */ - public cxCodeSet getCodeSet() - { - return codeset; - } - - /** - * Set the orb, associated with this stream. - * @param an_orb - */ - public void setOrb(ORB an_orb) - { - orb = an_orb; - } - - /** - * Set the output stream that receives the CORBA output. - * - * @param writeTo the stream. - */ - public void setOutputStream(java.io.OutputStream writeTo) - { - if (little_endian) - b = new LittleEndianOutputStream(writeTo); - else - b = new BigEndianOutputStream(writeTo); - - actual_stream = writeTo; - } - - /** - * Set the GIOP version. Some data types are written differently - * for the different versions. The default version is 1.0 . - */ - public void setVersion(Version giop_version) - { - giop = giop_version; - } - - /** - * Specify if the stream should use the Big Endian (usual for java) - * or Little Encoding. The default is Big Endian. - * - * @param use_big_endian if true, use Big Endian, if false, - * use Little Endian. - */ - public void setBigEndian(boolean use_big_endian) - { - little_endian = !use_big_endian; - setOutputStream(actual_stream); - } - - /** - * Align the curretn position at the given natural boundary. - */ - public abstract void align(int boundary); - - /** - * Create the encapsulation stream, associated with the current - * stream. The encapsulated stream must be closed. When being - * closed, the encapsulation stream writes its buffer into - * this stream using the CORBA CDR encapsulation rules. - * - * It is not allowed to write to the current stream directly - * before the encapsulation stream is closed. - * - * The encoding (Big/Little Endian) inside the encapsulated - * sequence is the same as used into the parent stream. - * - * @return the encapsulated stream. - */ - public cdrOutput createEncapsulation() - { - return new encapsulatedOutput(this, !little_endian); - } - - /** - * Return the associated {@link ORB}. - * @return the associated {@link ORB} or null is no such is set. - */ - public ORB orb() - { - return orb; - } - - /** - * Write a single byte. - * @param a byte to write (low 8 bits are written). - */ - public void write(int n) - { - try - { - b.write(n); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Write bytes directly into the underlying stream. - */ - public void write(byte[] x) - throws java.io.IOException - { - b.write(x); - } - - /** - * Write bytes directly into the underlying stream. - */ - public void write(byte[] x, int ofs, int len) - throws java.io.IOException - { - b.write(x, ofs, len); - } - - /** - * Following the specification, this is not implemented. - * Override to get the functionality. - */ - public void write_Context(Context context, ContextList contexts) - { - throw new NO_IMPLEMENT(); - } - - /** - * Read the CORBA object. The object is written - * form of the plain (not a string-encoded) IOR profile without the - * heading endian indicator. The responsible method for reading such - * data is {@link IOR.write_no_endian}. - * - * The null value is written as defined in OMG specification - * (zero length string, followed by an empty set of profiles). - */ - public void write_Object(org.omg.CORBA.Object x) - { - if (x == null) - { - IOR.write_null(this); - return; - } - else if (x instanceof gnuServantObject) - { - // The ORB may be different if several ORBs coexist - // in the same machine. - gnuServantObject g = (gnuServantObject) x; - IOR ior = g.orb.getLocalIor(x); - ior._write_no_endian(this); - return; - } - else if (x instanceof ObjectImpl) - { - Delegate d = ((ObjectImpl) x)._get_delegate(); - - if (d instanceof Simple_delegate) - { - Simple_delegate ido = (Simple_delegate) d; - ido.getIor()._write_no_endian(this); - return; - } - } - - // Either this is not an ObjectImpl or it has the - // unexpected delegate. Try to convert via ORBs - // object_to_string(). - if (orb != null) - { - IOR ior = IOR.parse(orb.object_to_string(x)); - ior._write_no_endian(this); - return; - } - else - throw new BAD_OPERATION("Please set the ORB for this stream."); - } - - /** - * Write the TypeCode. This implementation delegates functionality - * to {@link cdrTypeCode}. - * - * @param x a TypeCode to write. - */ - public void write_TypeCode(TypeCode x) - { - try - { - TypeCodeHelper.write(this, x); - } - catch (UserException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes an instance of the CORBA {@link Any}. - * This method writes the typecode, followed - * by value itself. In Any contains null - * (value not set), the {@link TCKind#tk_null} - * is written. - * - * @param x the {@link Any} to write. - */ - public void write_any(Any x) - { - Streamable value = x.extract_Streamable(); - if (value != null) - { - write_TypeCode(x.type()); - value._write(this); - } - else - { - primitiveTypeCode p = new primitiveTypeCode(TCKind.tk_null); - write_TypeCode(p); - } - } - - /** - * Writes a single byte, 0 for false, - * 1 for true. - * - * @param x the value to write - */ - public void write_boolean(boolean x) - { - try - { - b.write(x ? 1 : 0); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the boolean array. - * - * @param x array - * @param ofs offset - * @param len length. - */ - public void write_boolean_array(boolean[] x, int ofs, int len) - { - try - { - for (int i = ofs; i < ofs + len; i++) - { - b.write(x [ i ] ? 1 : 0); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the lower byte of the passed parameter. - * @param x the char to write - * - * It is effective to write more characters at once. - */ - public void write_char(char x) - { - try - { - if (narrow_native) - b.write(x); - else - { - OutputStreamWriter ow = - new OutputStreamWriter((OutputStream) b, narrow_charset); - ow.write(x); - ow.flush(); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the lower bytes of the passed array members. - * - * @param chars an array - * @param offsets offset - * @param length length - */ - public void write_char_array(char[] chars, int offset, int length) - { - try - { - if (narrow_native) - { - for (int i = offset; i < offset + length; i++) - { - b.write(chars [ i ]); - } - } - else - { - OutputStreamWriter ow = - new OutputStreamWriter((OutputStream) b, narrow_charset); - ow.write(chars, offset, length); - ow.flush(); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the double value (IEEE 754 format). - */ - public void write_double(double x) - { - try - { - align(8); - b.writeDouble(x); - } - catch (Exception ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the array of double values. - */ - public void write_double_array(double[] x, int ofs, int len) - { - try - { - align(8); - for (int i = ofs; i < ofs + len; i++) - { - b.writeDouble(x [ i ]); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes CORBA fixed, storing all digits but not the scale. - * The end of the record on fixed can - * be determined from its last byte. - */ - public void write_fixed(BigDecimal fixed) - { - try - { - BigDecimalHelper.write(this, fixed); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - catch (BadKind ex) - { - Unexpected.error(ex); - } - } - - /** - * Write the float value (IEEE 754 format). - */ - public void write_float(float x) - { - try - { - align(4); - b.writeFloat(x); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes an array of the float values. - */ - public void write_float_array(float[] x, int ofs, int len) - { - try - { - align(4); - for (int i = ofs; i < ofs + len; i++) - { - b.writeFloat(x [ i ]); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the integer value (CORBA long, four bytes, high byte first). - * @param x the value to write. - */ - public void write_long(int x) - { - try - { - align(4); - b.writeInt(x); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the array of integer (CORBA long) values. - * - * @param x value - * @param ofs offset - * @param len length - */ - public void write_long_array(int[] x, int ofs, int len) - { - try - { - align(4); - for (int i = ofs; i < ofs + len; i++) - { - b.writeInt(x [ i ]); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the long (CORBA long long) value, 8 bytes, - * high byte first. - * - * @param x the value to write. - */ - public void write_longlong(long x) - { - try - { - align(8); - b.writeLong(x); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the array of longs (CORBA long longs) values. - * - * @param x value - * @param ofs offset - * @param len length - */ - public void write_longlong_array(long[] x, int ofs, int len) - { - try - { - align(8); - for (int i = ofs; i < ofs + len; i++) - { - b.writeLong(x [ i ]); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes this byte. - * @param x - */ - public void write_octet(byte x) - { - try - { - b.writeByte(x); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the array of bytes (CORBA octets) values. - * - * @param x value - * @param ofs offset - * @param len length - */ - public void write_octet_array(byte[] x, int ofs, int len) - { - try - { - b.write(x, ofs, len); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes first the size of array, and then the byte array using - * the {@link java.io.OutputStream#write(byte[]) }. The sequence - * being written is preceeded by the int, representing the array - * length. - */ - public void write_sequence(byte[] buf) - { - try - { - write_long(buf.length); - write(buf); - } - catch (IOException ex) - { - MARSHAL t = new MARSHAL(); - t.initCause(ex); - throw t; - } - } - - /** - * Writes the contents of the provided stream. - * The sequence being written is preceeded by the int, - * representing the stream buffer length (the number of - * bytes being subsequently written). - */ - public void write_sequence(cdrBufOutput from) - { - try - { - write_long(from.buffer.size()); - from.buffer.writeTo(this); - } - catch (IOException ex) - { - MARSHAL t = new MARSHAL(); - t.initCause(ex); - throw t; - } - } - - /** - * Writes the two byte integer (short), high byte first. - * - * @param x the integer to write. - */ - public void write_short(short x) - { - try - { - align(2); - b.writeShort(x); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the array of short (two byte integer) values. - * - * @param x value - * @param ofs offset - * @param len length - */ - public void write_short_array(short[] x, int ofs, int len) - { - try - { - align(2); - for (int i = ofs; i < ofs + len; i++) - { - b.writeShort(x [ i ]); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the string. This implementation first calls - * String.getBytes() and then writes the length of the returned - * array (as CORBA ulong) and the returned array itself. - * - * The encoding information, if previously set, is taken - * into consideration. - * - * @param x the string to write. - */ - public void write_string(String x) - { - try - { - byte[] ab = x.getBytes(narrow_charset); - write_long(ab.length + 1); - write(ab); - - // write null terminator. - write(0); - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the CORBA unsigned long in the same way as CORBA long. - */ - public void write_ulong(int x) - { - write_long(x); - } - - /** - * Writes the array of CORBA unsigned longs in the same way as - * array of ordinary longs. - */ - public void write_ulong_array(int[] x, int ofs, int len) - { - write_long_array(x, ofs, len); - } - - /** - * Write the unsigned long long in the same way as an ordinary long long. - * - * @param x a value to write. - */ - public void write_ulonglong(long x) - { - write_longlong(x); - } - - /** - * Write the array of unsingel long longs in the same way - * an an array of the ordinary long longs. - */ - public void write_ulonglong_array(long[] x, int ofs, int len) - { - write_longlong_array(x, ofs, len); - } - - /** - * Write the unsigned short in the same way as an ordinary short. - */ - public void write_ushort(short x) - { - write_short(x); - } - - /** - * Write an array of unsigned short integersin the same way - * as an array of ordinary short integers. - */ - public void write_ushort_array(short[] x, int ofs, int len) - { - write_short_array(x, ofs, len); - } - - /** - * Writes the character as two byte short integer (Unicode value), - * high byte first. Writes in Big Endian, but never writes the - * endian indicator. - * - * The character is always written using the native UTF-16BE charset - * because its size under arbitrary encoding is not evident. - */ - public void write_wchar(char x) - { - try - { - if (giop.until_inclusive(1, 1)) - align(2); - - if (wide_native) - b.writeShort(x); - else - { - OutputStreamWriter ow = - new OutputStreamWriter((OutputStream) b, wide_charset); - ow.write(x); - ow.flush(); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Write the array of wide chars. - * - * @param chars the array of wide chars - * @param offset offset - * @param length length - * - * The char array is always written using the native UTF-16BE charset - * because the character size under arbitrary encoding is not evident. - */ - public void write_wchar_array(char[] chars, int offset, int length) - { - try - { - if (giop.until_inclusive(1, 1)) - align(2); - - if (wide_native) - { - for (int i = offset; i < offset + length; i++) - { - b.writeShort(chars [ i ]); - } - } - else - { - OutputStreamWriter ow = - new OutputStreamWriter((OutputStream) b, wide_charset); - ow.write(chars, offset, length); - ow.flush(); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** - * Writes the length of the string in bytes (not characters) and - * then all characters as two byte unicode chars. Adds the - * Big Endian indicator, 0xFFFE, at the beginning and null wide char at - * the end. - * - * @param x the string to write. - */ - public void write_wstring(String x) - { - try - { - if (giop.since_inclusive(1, 2)) - { - byte[] bytes = x.getBytes(wide_charset); - write_sequence(bytes); - } - else - { - // Encoding with null terminator always in UTF-16. - // The wide null terminator needs extra two bytes. - write_long(2 * x.length() + 2); - - for (int i = 0; i < x.length(); i++) - { - b.writeShort(x.charAt(i)); - } - - // Write null terminator. - b.writeShort(0); - } - } - catch (IOException ex) - { - Unexpected.error(ex); - } - } - - /** {@inheritDoc} */ - public void write_any_array(Any[] anys, int offset, int length) - { - for (int i = offset; i < offset + length; i++) - { - write_any(anys [ i ]); - } - } - - public String[] _truncatable_ids() - { - /**@todo Implement this org.omg.CORBA.portable.ValueBase abstract method*/ - throw new java.lang.UnsupportedOperationException("Method _truncatable_ids() not yet implemented."); - } - - /** {@inheritDoc} */ - public void write_Abstract(java.lang.Object value) - { - write_Abstract(value); - } - - /** {@inheritDoc} */ - public void write_Value(Serializable value) - { - write_Value(value); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java b/libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java deleted file mode 100644 index 3350291..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java +++ /dev/null @@ -1,146 +0,0 @@ -/* EncapsulationOutput.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import java.io.IOException; - -/** - * The encapsulated data, as they are defined by CORBA specification. - * This includes the extra 0 byte (Big endian) in the beginning. - * When written to the parent steam, the encapsulated data are preceeded - * by the data length in bytes. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class encapsulatedOutput - extends cdrOutput -{ - /** - * The Big Endian (most siginificant byte first flag). - */ - public static final byte BIG_ENDIAN = 0; - - /** - * The Little Endian (least siginificant byte first flag). - */ - public static final byte LITTLE_ENDIAN = 1; - - /** - * The byte buffer. - */ - public final aligningOutputStream buffer; - - /** - * The stream, where the data are being encapsulated. - */ - public final org.omg.CORBA.portable.OutputStream parent; - - /** - * Create the EncapsulationOutput with the given parent stream - * and the specified encoding. - */ - public encapsulatedOutput(org.omg.CORBA.portable.OutputStream _parent, - boolean use_big_endian) - { - super(); - buffer = new aligningOutputStream(); - setOutputStream(buffer); - parent = _parent; - write(use_big_endian?BIG_ENDIAN:LITTLE_ENDIAN); - } - - /** - * Set the alignment offset, if the index of the first byte in the - * stream is different from 0. - */ - public void setOffset(int an_offset) - { - buffer.setOffset(an_offset); - } - - /** - * Align the curretn position at the given natural boundary. - */ - public void align(int boundary) - { - buffer.align(boundary); - } - - /** - * Writes the content of the encapsulated output into the parent - * buffer. - */ - public void close() - { - try - { - parent.write_long(buffer.size()); - buffer.writeTo(parent); - } - catch (IOException ex) - { - InternalError err = new InternalError(); - err.initCause(ex); - throw err; - } - } - - /** - * Return the input stream that reads the previously written values. - */ - public org.omg.CORBA.portable.InputStream create_input_stream() - { - cdrBufInput in = new cdrBufInput(buffer.toByteArray()); - in.setOrb(orb); - - in.setVersion(giop); - in.setCodeSet(getCodeSet()); - - return in; - } - - /** - * Resets (clears) the buffer. - */ - public void reset() - { - buffer.reset(); - setOutputStream(buffer); - } -} diff --git a/libjava/classpath/gnu/CORBA/CDR/gnuRuntime.java b/libjava/classpath/gnu/CORBA/CDR/gnuRuntime.java new file mode 100644 index 0000000..774c928 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/gnuRuntime.java @@ -0,0 +1,336 @@ +/* gnuRuntime.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.Minor; + +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.MARSHAL; + +import java.io.Serializable; +import java.util.Comparator; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; +import java.util.TreeSet; + +/** + * Our implementation of the sending context runtime. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuRuntime + extends LocalObject + implements org.omg.SendingContext.RunTime +{ + /** + * The data entry about the object that was written. + */ + static class Entry + { + /** + * The stream position, where the object was written. + */ + int at; + + /** + * The object that was written. + */ + Object object; + + public String toString() + { + return object + "[" + at + "] "+object.getClass().getName(); + } + } + + /** + * The instruction that the actual object is stored at different location. + * Used when processing chunked data where positions shifts due removing the + * chunking tags. + */ + static class Redirection + extends Entry + { + public String toString() + { + return "->" + at; + } + } + + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The history of the written objects, maps object to records. The different + * objects must be treated as different regardless that .equals returns. + */ + private Map sh_objects = new IdentityHashMap(); + + /** + * The written repository Ids that can be shared. + */ + private Map sh_ids = new TreeMap(new Comparator() + { + public int compare(Object a, Object b) + { + if (a instanceof String && b instanceof String) + // Comparing string with string. + return ((String) a).compareTo((String) b); + else if (a instanceof String[] && b instanceof String[]) + { + // Comparing array with array. + String[] sa = (String[]) a; + String[] sb = (String[]) b; + + if (sa.length != sb.length) + return sa.length - sb.length; + else + { + int c; + for (int i = 0; i < sa.length; i++) + { + c = sa[i].compareTo(sb[i]); + if (c != 0) + return c; + } + return 0; + } + } + else + // Comparing string with array. + return a instanceof String ? 1 : -1; + } + }); + + /** + * The history of the written objects, maps positions to records. The + * different objects must be treated as different regardless that .equals + * returns. + */ + private Map positions = new HashMap(); + + /** + * The Codebase. + */ + private String codebase; + + /** + * The pre-created instance of the object being written (avoid + * re-instantiation). + */ + public Serializable target; + + /** + * Create Runtime. + * + * @param a_id a repository Id, if only one Id was specified in the stream. + * @param a_ids a repository Ids, if the multiple Ids were specified in te + * stream. + * @param a_codabase a codebase, if it was specified in the stream. + */ + public gnuRuntime(String a_codebase, Object a_target) + { + if (a_target instanceof Serializable) + target = (Serializable) a_target; + + codebase = a_codebase; + } + + /** + * Mark the given object as written at the given position. + */ + public void objectWritten(Object object, int at) + { + if (object == null || at < 0) + return; // No positional information provided. + if (sh_objects.containsKey(object)) + throw new AssertionError("Repetetive writing of the same object " + + object + " at " + at + dump()); + + Entry e = new Entry(); + e.at = at; + e.object = object; + + sh_objects.put(object, e); + positions.put(new Integer(at), e); + } + + /** + * Check if the object is already written. + * + * @return the position, at that the object is allready written or -1 if it is + * not yet written. + */ + public int isWrittenAt(Object x) + { + Entry e = (Entry) sh_objects.get(x); + return e == null ? -1 : e.at; + } + + /** + * Set redirection, indicating that the object, searched at the p_searched + * position can be actually found at the p_present position. + */ + public void redirect(int p_searched, int p_present) + { + Redirection redirection = new Redirection(); + redirection.at = p_present; + positions.put(new Integer(p_searched), redirection); + } + + /** + * Get the object, written at the given position. This returs both shared + * objects and repository Ids. + * + * @return the position, at that the object is allready written. + * + * @throws MARSHAL if there is no object written at that position. + */ + public Object isObjectWrittenAt(int x, int offset) + { + Entry e = (Entry) positions.get(new Integer(x)); + if (e instanceof Redirection) + return isObjectWrittenAt(e.at, offset); + else if (e != null) + return e.object; + else + { + MARSHAL m = new MARSHAL("No object was written at " + x + + " (offset " + offset + ") r " + this + dump()); + m.minor = Minor.Graph; + throw m; + } + } + + /** + * Mark the given object as written at the given position. + */ + public void singleIdWritten(String id, int at) + { + if (sh_ids.containsKey(id)) + throw new InternalError("Repetetive writing of the same string " + + id + dump()); + + Entry e = new Entry(); + e.at = at; + e.object = id; + + sh_ids.put(id, e); + positions.put(new Integer(at), e); + } + + /** + * Mark the given object as written at the given position. + */ + public void multipleIdsWritten(String[] ids, int at) + { + if (sh_ids.containsKey(ids)) + throw new InternalError("Repetetive writing of the same string " + + ids + dump()); + + Entry e = new Entry(); + e.at = at; + e.object = ids; + + sh_ids.put(ids, e); + positions.put(new Integer(at), e); + } + + /** + * Check if the object is already written. + * + * @return the position, at that the object is allready written or -1 if it is + * not yet written. + */ + public int idWrittenAt(Object x) + { + Entry e = (Entry) sh_ids.get(x); + return e == null ? -1 : e.at; + } + + /** + * Get the codebase. + */ + public String getCodeBase() + { + return codebase; + } + + /** + * Set the codebase, preserving the old value if the passed parameter is null + * and forming the space delimited list if both new and old values are not + * null. + */ + public void addCodeBase(String base) + { + if (base != null) + { + if (codebase == null) + codebase = base; + else + codebase = codebase + " " + base; + } + } + + /** + * Dump all objects that are currently stored. + */ + public String dump() + { + StringBuffer b = new StringBuffer(" Stream content: \n"); + + // Sort by position. + TreeSet t = new TreeSet(positions.keySet()); + Iterator p = t.iterator(); + + while (p.hasNext()) + { + Object k = p.next(); + b.append(" " + k + ": " + ((Entry) positions.get(k)).toString() + + "\n"); + } + return b.toString(); + } + +} diff --git a/libjava/classpath/gnu/CORBA/CDR/gnuValueStream.java b/libjava/classpath/gnu/CORBA/CDR/gnuValueStream.java new file mode 100644 index 0000000..663c9901 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/gnuValueStream.java @@ -0,0 +1,71 @@ +/* gnuValueStream.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +/** + * A stream, implementing this interface, provides methods to get/set a position + * and get the RunTime. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface gnuValueStream +{ + /** + * Get the current position in the buffer. + * + * @return The position in the buffer, taking offset into consideration. + */ + public int getPosition(); + + /** + * Jump to the given position, taking offset into consideration. + */ + public void seek(int position); + + /** + * Get the RunTime information. + */ + public gnuRuntime getRunTime(); + + /** + * Replace the instance of RunTime. + */ + public void setRunTime(gnuRuntime a_runtime); + +} diff --git a/libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java b/libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java deleted file mode 100644 index 0c787dd..0000000 --- a/libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java +++ /dev/null @@ -1,166 +0,0 @@ -/* noHeaderInput.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.CDR; - -import org.omg.CORBA.CustomMarshal; -import org.omg.CORBA.DataInputStream; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.portable.BoxedValueHelper; -import org.omg.CORBA.portable.Streamable; -import org.omg.CORBA.portable.ValueFactory; - -import java.io.Serializable; - -/** - * Substitutes the main stream in factories when the header is already - * behind. Overrides methods that may be invoked from the factory, - * forcing not to read the header if called first time on this stream. - * - * This stream reverts to default behavior if one or more call are - * made (reading value types that are nested fields of the value type). - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -class noHeaderInput - extends cdrBufInput - implements DataInputStream -{ - /** - * If true, this is not the first call. - */ - boolean notFirst; - - /** - * Create an instance, reading from the given buffer. - */ - public noHeaderInput(byte[] buffer) - { - super(buffer); - } - - /** - * Read when knowning the class instance. - */ - public Serializable read_value(Class clz) - { - if (notFirst) - return super.read_value(clz); - else - { - try - { - notFirst = true; - return read_value((Serializable) clz.newInstance()); - } - catch (Exception ex) - { - MARSHAL m = new MARSHAL("Unable to create an instance"); - m.initCause(ex); - throw m; - } - } - } - - /** - * Tries to read using boxed value helper. - */ - public Serializable read_value(BoxedValueHelper helper) - { - if (notFirst) - return super.read_value(helper); - else - { - notFirst = true; - return helper.read_value(this); - } - } - - /** - * Tries to locate a factory using repository id. - */ - public Serializable read_value(String repository_id) - { - if (notFirst) - return super.read_value(repository_id); - else - { - notFirst = true; - - ValueFactory factory = - ((org.omg.CORBA_2_3.ORB) orb()).lookup_value_factory(repository_id); - if (factory == null) - throw new MARSHAL("No factory"); - return factory.read_value(this); - } - } - - /** - * Try to read when having an unitialised value. - */ - public Serializable read_value(Serializable value) - { - if (notFirst) - return super.read_value(value); - else - { - notFirst = true; - - // The user-defines io operations are implemented. - if (value instanceof CustomMarshal) - { - CustomMarshal marsh = (CustomMarshal) value; - try - { - marsh.unmarshal((DataInputStream) this); - } - catch (ClassCastException ex) - { - Vio.incorrect_plug_in(ex); - } - } - else - // The IDL-generated io operations are implemented. - if (value instanceof Streamable) - { - ((Streamable) value)._read(this); - } - return value; - } - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CdrEncapsCodecImpl.java b/libjava/classpath/gnu/CORBA/CdrEncapsCodecImpl.java new file mode 100644 index 0000000..93dd1cd --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CdrEncapsCodecImpl.java @@ -0,0 +1,358 @@ +/* CdrEncapsCodecImpl.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; +import gnu.CORBA.CDR.AbstractCdrOutput; + +import org.omg.CORBA.Any; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UserException; +import org.omg.IOP.Codec; +import org.omg.IOP.CodecPackage.FormatMismatch; +import org.omg.IOP.CodecPackage.InvalidTypeForEncoding; +import org.omg.IOP.CodecPackage.TypeMismatch; + +/** + * The local {@link Codec} implementation for ENCODING_CDR_ENCAPS + * encoding. This is a local implementation; the remote side should + * have its own Codec of this kind. + * + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class CdrEncapsCodecImpl + extends LocalObject + implements Codec +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * If set to true, no wide string or wide character is allowed (GIOP 1.0). + */ + private final boolean noWide; + + /** + * The version of this encoding. + */ + private final Version version; + + /** + * The associated ORB. + */ + protected final ORB orb; + + /** + * If true, this Codec writes the record length (as int) in the beginning + * of the record. This indicator is part of the formal OMG standard, but it is + * missing in Sun's implementation. Both Suns's and this Codec detects + * the indicator, if present, but can also decode data where this information + * is missing. If the length indicator is missing, the first four bytes in + * Suns encoding are equal to 0 (Big Endian marker). + */ + private boolean lengthIndicator = true; + + /** + * Create an instance of this Codec, encoding following the given version. + */ + public CdrEncapsCodecImpl(ORB _orb, Version _version) + { + orb = _orb; + version = _version; + noWide = version.until_inclusive(1, 0); + } + + /** + * Return the array of repository ids for this object. + * + * @return { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }, always. + */ + public String[] _ids() + { + return new String[] { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }; + } + + /** + * Decode the contents of the byte array into Any. + * The byte array may have the optional four byte length indicator + * in the beginning. If these four bytes are zero, it is assumed, + * that no length indicator is present. + */ + public Any decode(byte[] them) + throws FormatMismatch + { + BufferredCdrInput input = createInput(them); + BufferredCdrInput encapsulation = createEncapsulation(them, input); + + TypeCode type = encapsulation.read_TypeCode(); + + try + { + checkTypePossibility("", type); + } + catch (InvalidTypeForEncoding ex) + { + throw new FormatMismatch(ex.getMessage()); + } + + return readAny(type, encapsulation); + } + + private BufferredCdrInput createEncapsulation(byte[] them, BufferredCdrInput input) + { + BufferredCdrInput encapsulation; + + if ((them [ 0 ] | them [ 1 ] | them [ 2 ] | them [ 3 ]) == 0) + { + // Skip that appears to be the always present Big Endian marker. + encapsulation = input; + input.read_short(); + } + else + encapsulation = input.read_encapsulation(); + return encapsulation; + } + + /** {@inheritDoc} */ + public byte[] encode(Any that) + throws InvalidTypeForEncoding + { + checkTypePossibility("", that.type()); + + BufferedCdrOutput output = createOutput(that); + + // BufferedCdrOutput has internal support for this encoding. + AbstractCdrOutput encapsulation = output.createEncapsulation(); + + try + { + TypeCodeHelper.write(encapsulation, that.type()); + that.write_value(encapsulation); + + encapsulation.close(); + output.close(); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(); + m.minor = Minor.Encapsulation; + m.initCause(ex); + throw m; + } + return output.buffer.toByteArray(); + } + + /** + * Decode the value, stored in the byte array, into Any, assuming, + * that the byte array holds the data structure, defined by the + * given typecode. + * + * The byte array may have the optional four byte length indicator + * in the beginning. If these four bytes are zero, it is assumed, + * that no length indicator is present. + */ + public Any decode_value(byte[] them, TypeCode type) + throws FormatMismatch, TypeMismatch + { + try + { + checkTypePossibility("", type); + } + catch (InvalidTypeForEncoding ex) + { + throw new TypeMismatch(ex.getMessage()); + } + + BufferredCdrInput input = createInput(them); + BufferredCdrInput encapsulation = createEncapsulation(them, input); + return readAny(type, encapsulation); + } + + /** + * Read an Any from the given stream. + * + * @param type a type of the Any to read. + * @param input the encapsulation stream. + */ + private Any readAny(TypeCode type, BufferredCdrInput encapsulation) + throws MARSHAL + { + gnuAny a = new gnuAny(); + a.setOrb(orb); + + // BufferredCdrInput has internal support for this encoding. + a.read_value(encapsulation, type); + return a; + } + + /** {@inheritDoc} */ + public byte[] encode_value(Any that) + throws InvalidTypeForEncoding + { + checkTypePossibility("", that.type()); + + BufferedCdrOutput output = createOutput(that); + + AbstractCdrOutput encapsulation = output.createEncapsulation(); + + try + { + that.write_value(encapsulation); + + encapsulation.close(); + output.close(); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(); + m.minor = Minor.Encapsulation; + m.initCause(ex); + throw m; + } + return output.buffer.toByteArray(); + } + + /** + * Create the CDR output stream for writing the given Any. + * The BufferedCdrOutput has internal support for encapsulation encodings. + * + * @param that the Any that will be written. + * + * @return the stream. + * + * @throws InvalidTypeForEncoding if that Any cannot be written under the + * given version. + */ + private BufferedCdrOutput createOutput(Any that) + throws InvalidTypeForEncoding + { + BufferedCdrOutput output = new BufferedCdrOutput(); + output.setOrb(orb); + output.setVersion(version); + return output; + } + + /** + * Checks if the given type can be encoded. Currently only checks for wide + * strings and wide chars for GIOP 1.0. + * + * @param t a typecode to chek. + * + * @throws InvalidTypeForEncoding if the typecode is not valid for the given + * version. + */ + private void checkTypePossibility(String name, TypeCode t) + throws InvalidTypeForEncoding + { + if (noWide) + { + try + { + int kind = t.kind().value(); + + if (kind == TCKind._tk_wchar || kind == TCKind._tk_wstring) + throw new InvalidTypeForEncoding(name + " wide char in " + + version + ); + else if (kind == TCKind._tk_alias || kind == TCKind._tk_array || + kind == TCKind._tk_sequence + ) + checkTypePossibility("Array member", t.content_type()); + + else if (kind == TCKind._tk_struct || kind == TCKind._tk_union) + { + for (int i = 0; i < t.member_count(); i++) + { + checkTypePossibility(t.member_name(i), t.member_type(i)); + } + } + } + catch (UserException ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + } + } + + /** + * Create the CDR input stream for reading the given byte array. + * + * @param them a byte array to read. + * + * @return the stream. + */ + private BufferredCdrInput createInput(byte[] them) + { + BufferredCdrInput input = new BufferredCdrInput(them); + input.setOrb(orb); + input.setVersion(version); + return input; + } + + /** + * Check if the Codec writes the length indicator. + */ + public boolean hasLengthIndicator() + { + return lengthIndicator; + } + + /** + * Sets if the Codec must write the record length in the beginning of the + * array. Encodings both with and without that indicator are understood + * both by Suns and this codec, but the OMG specification seems requiring + * it. The default behavior is to use the length indicator. + * + * @param use_lengthIndicator + */ + public void setUseLengthIndicator(boolean use_lengthIndicator) + { + lengthIndicator = use_lengthIndicator; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Connected_objects.java b/libjava/classpath/gnu/CORBA/Connected_objects.java index b7eefb1..ce57610 100644 --- a/libjava/classpath/gnu/CORBA/Connected_objects.java +++ b/libjava/classpath/gnu/CORBA/Connected_objects.java @@ -90,17 +90,6 @@ public class Connected_objects * applicable. */ public final java.lang.Object identity; - - public boolean equals(java.lang.Object other) - { - if (other instanceof cObject) - { - cObject o = (cObject) other; - return o.object.equals(object) && o.port == port; - } - else - return false; - } } /** diff --git a/libjava/classpath/gnu/CORBA/CorbaList.java b/libjava/classpath/gnu/CORBA/CorbaList.java new file mode 100644 index 0000000..25bea923 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CorbaList.java @@ -0,0 +1,115 @@ +/* CorbaList.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import java.io.Serializable; + +import java.util.ArrayList; + +import org.omg.CORBA.Bounds; + +/** + * This class is used to store array lists. Differently from + * the java.util lists, + * it throws {@link org.omg.CORBA.Bounds} rather than + * {@link IndexOutOfBoundsException}. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class CorbaList + extends ArrayList + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Creates the list with the given initial size. + */ + public CorbaList(int initial_size) + { + super(initial_size); + } + + /** + * Creates the list with the default size. + */ + public CorbaList() + { + } + + /** + * Remove the item at the given index. + * @param at the index + * @throws org.omg.CORBA.Bounds if the index is out of bounds. + */ + public void drop(int at) + throws Bounds + { + try + { + super.remove(at); + } + catch (IndexOutOfBoundsException ex) + { + throw new Bounds("[" + at + "], valid [0.." + size() + "]"); + } + } + + /** + * Get the item at the given index. + * @param at the index + * @return the item at the index + * @throws org.omg.CORBA.Bounds if the index is out of bounds. + */ + public Object item(int at) + throws Bounds + { + try + { + return super.get(at); + } + catch (IndexOutOfBoundsException ex) + { + throw new Bounds("[" + at + "], valid [0.." + size() + "]"); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/DefaultSocketFactory.java b/libjava/classpath/gnu/CORBA/DefaultSocketFactory.java new file mode 100644 index 0000000..51df047 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DefaultSocketFactory.java @@ -0,0 +1,79 @@ +/* DefaultSocketFactory.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 modify + it under the terms of the GNU General Public License as published by + the 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, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.interfaces.SocketFactory; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * The default socket factory that forges "plain" server and client sockets. The + * class can be replaced by setting the gnu.CORBA.SocketFactory property. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class DefaultSocketFactory + implements SocketFactory +{ + /** + * It is enough to have one instance of this class for all ORBs. + */ + public static final DefaultSocketFactory Singleton = new DefaultSocketFactory(); + + /** + * Create a client socket. + */ + public Socket createClientSocket(String host, int port) + throws IOException + { + return new Socket(host, port); + } + + /** + * Create a server socket. + */ + public ServerSocket createServerSocket(int port) + throws IOException + { + return new ServerSocket(port); + } + +} diff --git a/libjava/classpath/gnu/CORBA/DynAn/AbstractAny.java b/libjava/classpath/gnu/CORBA/DynAn/AbstractAny.java new file mode 100644 index 0000000..7060f86 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/AbstractAny.java @@ -0,0 +1,177 @@ +/* AbstractAny.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.TypeKindNamer; + +import org.omg.CORBA.Any; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TypeCode; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; + +import java.io.Serializable; + +/** + * The top of our DynAny implementation, this class provides ORB that is + * required to create anys and factory that is required to initialise DynAnys. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class AbstractAny + extends LocalObject + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The "initial final_type" that can be an alias of the known final_type. + */ + public TypeCode official_type; + + /** + * The "basic" final_type to that the final_type finally evaluates. + */ + public final TypeCode final_type; + + /** + * The DynAny factory, required in initializations. + */ + public final gnuDynAnyFactory factory; + + /** + * The ORB, to that this DynAny belongs. + */ + public final ORB orb; + + /** + * The minor code, indicating the error, related to work with non - GNU + * Classpath DynAny. + */ + short MINOR = 8148; + + /** + * The message about the empty structure or exception. + */ + static final String EMPTY = "Empty structure with no fields."; + + /** + * The message about the structure or exception size mismatch. + */ + static final String SIZE = "Size mismatch."; + + /** + * The message about the content of this DynAny being equal to + * null + */ + static final String ISNULL = "The content is null"; + + /** + * The change value listener. + */ + ValueChangeListener listener; + + /** + * Create the abstract dyn any. + */ + public AbstractAny(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + official_type = oType; + final_type = aType; + factory = aFactory; + orb = anOrb; + } + + /** + * Get the typecode. + */ + public TypeCode type() + { + return official_type; + } + + /** + * Create the Any. + */ + public Any createAny() + { + return orb.create_any(); + } + + /** + * The "value changed" listener. + */ + protected void valueChanged() + { + if (listener != null) + listener.changed(); + } + + /** + * Check the type. + */ + void checkType(TypeCode expected, TypeCode actual) + throws TypeMismatch + { + if (!expected.equal(actual)) + throw new TypeMismatch(typeMismatch(expected, actual)); + } + + /** + * Format "Type mismatch" string. + */ + String typeMismatch(TypeCode expected, TypeCode actual) + { + return TypeKindNamer.nameIt(expected) + " expected " + + TypeKindNamer.nameIt(actual); + } + + /** + * Format "size mismatch" string. + */ + String sizeMismatch(int here, int other) + { + return "Size mismatch, " + other + " (expected " + here + ")"; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/DivideableAny.java b/libjava/classpath/gnu/CORBA/DynAn/DivideableAny.java new file mode 100644 index 0000000..c96cbed --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/DivideableAny.java @@ -0,0 +1,514 @@ +/* DivideableAny.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.TypeKindNamer; + +import org.omg.CORBA.Any; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UNKNOWN; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynValueCommon; + +import java.io.Serializable; + +/** + * Provides a base for DynAnys, having multiple components. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class DivideableAny + extends AbstractAny + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The array of the components that in general case may have different + * final_type. + */ + protected DynAny[] array; + + /** + * The internal pointer. + */ + protected int pos = 0; + + public DivideableAny(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + } + + /** + * Advance forward. + */ + public boolean next() + { + pos++; + return array.length > pos; + } + + /** + * Set zero position. + */ + public void rewind() + { + pos = 0; + } + + /** + * Set a position. + */ + public boolean seek(int p) + { + pos = p; + return pos >= 0 && array.length > pos; + } + + /** + * Get the insertion point as DynAny. This method may throw exceptions if the + * current insertion point does not support reading or insertion of the + * primitive types. + * + * @return the focused component, from where the primitve value can be read or + * where it can be inserted. + * @throws InvalidValue if the primitive value cannot be inserted at the given + * point. + */ + protected DynAny focused() + throws InvalidValue, TypeMismatch + { + if (pos >= 0 && pos < array.length) + { + if (array [ pos ].component_count() == 0) + return array [ pos ]; + else + throw new TypeMismatch("Multiple coponents at " + pos); + } + else + throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + + (array.length - 1) + ); + } + + /** {@inheritDoc} */ + public int component_count() + { + return array.length; + } + + /** + * Return the second (enclosed any) that is stored in the wrapped Any. + */ + public Any get_any() + throws TypeMismatch, InvalidValue + { + return focused().get_any(); + } + + /** {@inheritDoc} */ + public boolean get_boolean() + throws TypeMismatch, InvalidValue + { + return focused().get_boolean(); + } + + /** {@inheritDoc} */ + public char get_char() + throws TypeMismatch, InvalidValue + { + return focused().get_char(); + } + + /** {@inheritDoc} */ + public double get_double() + throws TypeMismatch, InvalidValue + { + return focused().get_double(); + } + + /** {@inheritDoc} */ + public float get_float() + throws TypeMismatch, InvalidValue + { + return focused().get_float(); + } + + /** {@inheritDoc} */ + public int get_long() + throws TypeMismatch, InvalidValue + { + return focused().get_long(); + } + + /** {@inheritDoc} */ + public long get_longlong() + throws TypeMismatch, InvalidValue + { + return focused().get_longlong(); + } + + /** {@inheritDoc} */ + public byte get_octet() + throws TypeMismatch, InvalidValue + { + return focused().get_octet(); + } + + /** {@inheritDoc} */ + public Object get_reference() + throws TypeMismatch, InvalidValue + { + return focused().get_reference(); + } + + /** {@inheritDoc} */ + public short get_short() + throws TypeMismatch, InvalidValue + { + return focused().get_short(); + } + + /** {@inheritDoc} */ + public String get_string() + throws TypeMismatch, InvalidValue + { + return focused().get_string(); + } + + /** {@inheritDoc} */ + public TypeCode get_typecode() + throws TypeMismatch, InvalidValue + { + return focused().get_typecode(); + } + + /** {@inheritDoc} */ + public int get_ulong() + throws TypeMismatch, InvalidValue + { + return focused().get_ulong(); + } + + /** {@inheritDoc} */ + public long get_ulonglong() + throws TypeMismatch, InvalidValue + { + return focused().get_ulonglong(); + } + + /** {@inheritDoc} */ + public short get_ushort() + throws TypeMismatch, InvalidValue + { + return focused().get_ushort(); + } + + /** {@inheritDoc} */ + public Serializable get_val() + throws TypeMismatch, InvalidValue + { + if (pos >= 0 && pos < array.length) + { + if (array [ pos ] instanceof DynValueCommon) + return array [ pos ].get_val(); + else + throw new TypeMismatch(); + } + else + throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + + (array.length - 1) + ); + } + + /** {@inheritDoc} */ + public char get_wchar() + throws TypeMismatch, InvalidValue + { + return focused().get_wchar(); + } + + /** {@inheritDoc} */ + public String get_wstring() + throws TypeMismatch, InvalidValue + { + return focused().get_wstring(); + } + + /** {@inheritDoc} */ + public void insert_any(Any a_x) + throws TypeMismatch, InvalidValue + { + focused().insert_any(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_boolean(boolean a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_boolean(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_char(char a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_char(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_double(double a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_double(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_float(float a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_float(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_long(int a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_long(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_longlong(long a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_longlong(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_octet(byte a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_octet(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_reference(Object a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_reference(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_short(short a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_short(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_string(String a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_string(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_typecode(TypeCode a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_typecode(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_ulong(int a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_ulong(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_ulonglong(long a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_ulonglong(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_ushort(short a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_ushort(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_val(Serializable a_x) + throws InvalidValue, TypeMismatch + { + if (pos >= 0 && pos < array.length) + { + if (array [ pos ] instanceof DynValueCommon) + array [ pos ].insert_val(a_x); + else + throw new TypeMismatch(); + } + else + throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + + (array.length - 1) + ); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_wchar(char a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_wchar(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_wstring(String a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_wstring(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public DynAny get_dyn_any() + throws TypeMismatch, InvalidValue + { + return focused().get_dyn_any(); + } + + /** {@inheritDoc} */ + public void insert_dyn_any(DynAny insert_it) + throws TypeMismatch, InvalidValue + { + focused().insert_dyn_any(insert_it); + } + + /** + * Get current component. + * + * @return current component or null if the pointer is out of + * bounds. + */ + public DynAny current_component() + throws TypeMismatch + { + if (array.length == 0) + throw new TypeMismatch("empty"); + return (pos >= 0 && pos < array.length) ? array [ pos ] : null; + } + + /** + * No action, cleanup is done by garbage collector in java. + */ + public void destroy() + { + } + + /** + * Involved in equal(DynAny). + */ + public abstract Any to_any() + throws TypeMismatch; + + /** + * Compares with other DynAny for equality. The final_type, array size and + * array members must match. + */ + public boolean equal(DynAny other) + { + try + { + if (!official_type.equal(other.type())) + return false; + else if (other instanceof DivideableAny) + { + DivideableAny x = (DivideableAny) other; + if (x.array.length != array.length) + return false; + + for (int i = 0; i < array.length; i++) + { + if (!array [ i ].equal(x.array [ i ])) + return false; + } + return true; + } + else if (other == null || other instanceof AbstractAny) + return false; + else + return other.to_any().equal(to_any()); + } + catch (TypeMismatch e) + { + UNKNOWN u = new UNKNOWN(MINOR, CompletionStatus.COMPLETED_NO); + u.initCause(e); + throw u; + } + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/RecordAny.java b/libjava/classpath/gnu/CORBA/DynAn/RecordAny.java new file mode 100644 index 0000000..a3e3680 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/RecordAny.java @@ -0,0 +1,405 @@ +/* RecordAny.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; +import gnu.CORBA.HolderLocator; + +import org.omg.CORBA.Any; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynStruct; +import org.omg.DynamicAny.DynValueCommonOperations; +import org.omg.DynamicAny.NameDynAnyPair; +import org.omg.DynamicAny.NameValuePair; + +import java.io.Serializable; + +import java.lang.reflect.Field; + +/** + * A shared base for both dynamic structure an dynamic value final_type. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class RecordAny + extends DivideableAny + implements DynAny, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + String[] fNames; + + /** + * Creates the structure with the given typecode. + * + * @param fields The DynAny's, representing the fields of the structure. + */ + public RecordAny(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + } + + /** @inheritDoc */ + public TCKind current_member_kind() + throws TypeMismatch, InvalidValue + { + if (array.length == 0) + throw new TypeMismatch(EMPTY); + try + { + return final_type.member_type(pos).kind(); + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + catch (Bounds e) + { + InvalidValue t = new InvalidValue(); + t.initCause(e); + throw t; + } + } + + /** @inheritDoc */ + public String current_member_name() + throws TypeMismatch, InvalidValue + { + if (array.length == 0) + throw new TypeMismatch(EMPTY); + try + { + return final_type.member_name(pos); + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + catch (Bounds e) + { + InvalidValue t = new InvalidValue(); + t.initCause(e); + throw t; + } + } + + /** + * Get content of the structure. This method must be defined on a different + * name because get_members_as_dyn_any() throws exception only in some of the + * supported interfaces. + */ + public NameDynAnyPair[] gnu_get_members_as_dyn_any() + { + NameDynAnyPair[] r = new NameDynAnyPair[ array.length ]; + for (int i = 0; i < r.length; i++) + { + try + { + r [ i ] = new NameDynAnyPair(fNames [ i ], array [ i ]); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + return r; + } + + /** + * Get content of the structure. This method must be defined on a different + * name because get_members_as_dyn_any() throws exception only in some of the + * supported interfaces. + */ + public NameValuePair[] gnu_get_members() + { + NameValuePair[] r = new NameValuePair[ array.length ]; + for (int i = 0; i < r.length; i++) + { + try + { + r [ i ] = new NameValuePair(fNames [ i ], array [ i ].to_any()); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + return r; + } + + /** + * Set members from the provided array. + */ + public void set_members_as_dyn_any(NameDynAnyPair[] value) + throws TypeMismatch, InvalidValue + { + if (value.length != array.length) + throw new InvalidValue(sizeMismatch(array.length, value.length)); + + for (int i = 0; i < value.length; i++) + { + DynAny dynAny = value [ i ].value; + checkType(dynAny.type(), i); + checkName(value [ i ].id, i); + + array [ i ] = dynAny; + } + pos = 0; + } + + /** + * Check the name at the given position ("" matches everything). + */ + private void checkName(String xName, int i) + throws TypeMismatch + { + if (xName.length() > 0 && fNames [ i ].length() > 0) + if (!xName.equals(fNames [ i ])) + throw new TypeMismatch("Field name mismatch " + xName + " expected " + + fNames [ i ] + ); + } + + /** + * Check the type at the given position. + */ + private void checkType(TypeCode t, int i) + throws TypeMismatch + { + if (!array [ i ].type().equal(t)) + throw new TypeMismatch(typeMismatch(array [ i ].type(), t) + " field " + + i + ); + } + + /** + * Set members from the provided array. + */ + public void set_members(NameValuePair[] value) + throws TypeMismatch, InvalidValue + { + if (value.length != array.length) + throw new InvalidValue(sizeMismatch(array.length, value.length)); + + for (int i = 0; i < value.length; i++) + { + Any any = value [ i ].value; + checkType(any.type(), i); + checkName(value [ i ].id, i); + + array [ i ].from_any(any); + } + pos = 0; + } + + /** @inheritDoc */ + public void assign(DynAny from) + throws TypeMismatch + { + checkType(official_type, from.type()); + if (from instanceof DynStruct) + { + try + { + set_members_as_dyn_any(((DynStruct) from).get_members_as_dyn_any()); + } + catch (InvalidValue e) + { + TypeMismatch t = new TypeMismatch("Invalid value"); + t.initCause(e); + throw t; + } + } + else + throw new TypeMismatch("Not a DynStruct"); + } + + /** + * Create a copy. + */ + public DynAny copy() + { + DynAny[] c = new DynAny[ array.length ]; + for (int i = 0; i < c.length; i++) + { + c [ i ] = array [ i ].copy(); + } + + RecordAny d = newInstance(official_type, final_type, factory, orb); + d.array = c; + return d; + } + + /** + * Create a new instance when copying. + */ + protected abstract RecordAny newInstance(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, + ORB anOrb + ); + + /** + * Done via reflection. + */ + public Any to_any() + { + try + { + Streamable sHolder = HolderLocator.createHolder(official_type); + + Class sHolderClass = sHolder.getClass(); + Field sHolderValue = sHolderClass.getField("value"); + Class sClass = sHolderValue.getType(); + + Object structure = sClass.newInstance(); + Object member; + Any am; + Field vread; + Field vwrite; + Streamable memberHolder; + + for (int i = 0; i < array.length; i++) + { + am = array [ i ].to_any(); + memberHolder = am.extract_Streamable(); + vwrite = structure.getClass().getField(final_type.member_name(i)); + vread = memberHolder.getClass().getField("value"); + member = vread.get(memberHolder); + vwrite.set(structure, member); + } + + Any g = createAny(); + sHolderValue.set(sHolder, structure); + g.insert_Streamable(sHolder); + g.type(official_type); + return g; + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + + /** + * Done via reflection. + */ + public void from_any(Any an_any) + throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + try + { + Streamable s = an_any.extract_Streamable(); + if (s == null) + { + if (this instanceof DynValueCommonOperations) + { + ((DynValueCommonOperations) this).set_to_null(); + return; + } + else + throw new InvalidValue(ISNULL); + } + + Object structure = s.getClass().getField("value").get(s); + if (structure == null && (this instanceof DynValueCommonOperations)) + { + ((DynValueCommonOperations) this).set_to_null(); + return; + } + + Any member; + Streamable holder; + Object field; + TypeCode fType; + Field fField; + + for (int i = 0; i < array.length; i++) + { + fField = structure.getClass().getField(fNames [ i ]); + field = fField.get(structure); + fType = array [ i ].type(); + holder = HolderLocator.createHolder(fType); + + member = createAny(); + holder.getClass().getField("value").set(holder, field); + member.insert_Streamable(holder); + member.type(fType); + + array [ i ].from_any(member); + } + + if (this instanceof DynValueCommonOperations) + ((DynValueCommonOperations) this).set_to_value(); + } + catch (InvalidValue v) + { + throw v; + } + catch (NoSuchFieldException ex) + { + TypeMismatch v = + new TypeMismatch("holder value does not match typecode"); + v.initCause(ex); + throw v; + } + catch (Exception ex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(ex); + throw t; + } + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/UndivideableAny.java b/libjava/classpath/gnu/CORBA/DynAn/UndivideableAny.java new file mode 100644 index 0000000..da4e961 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/UndivideableAny.java @@ -0,0 +1,493 @@ +/* Undivideable.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import java.io.Serializable; + +import org.omg.CORBA.Any; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CORBA.TypeCode; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; + +/** + * Represent DynAny that has no internal components (DynEnum and so on). The + * methods, related to internal components, throw exceptions or return agreed + * values like null. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class UndivideableAny + extends AbstractAny + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Create a new instance with the given typecode. + */ + public UndivideableAny(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb) + { + super(oType, aType, aFactory, anOrb); + } + + /** + * There are no components. + * + * @return 0, always. + */ + public int component_count() + { + return 0; + } + + /** + * There is no current component. + * + * @throws TypeMismatch, always. + */ + public DynAny current_component() + throws TypeMismatch + { + throw new TypeMismatch("Not applicable"); + } + + /** + * Returns without action. + */ + public void destroy() + { + } + + /** + * Not in use. + */ + public Any get_any() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public boolean get_boolean() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public char get_char() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public double get_double() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public DynAny get_dyn_any() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public float get_float() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public int get_long() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public long get_longlong() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public byte get_octet() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public Object get_reference() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public short get_short() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public String get_string() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public TypeCode get_typecode() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public int get_ulong() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public long get_ulonglong() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public short get_ushort() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public Serializable get_val() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public char get_wchar() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public String get_wstring() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_any(Any an_any) + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_boolean(boolean a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_char(char a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_double(double a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_dyn_any(DynAny insert_it) + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_float(float a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_long(int a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_longlong(long a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_octet(byte a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_reference(Object a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_short(short a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_string(String a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_typecode(TypeCode a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_ulong(int a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_ulonglong(long a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_ushort(short a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_val(Serializable a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_wchar(char a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_wstring(String a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public boolean next() + { + return false; + } + + /** + * Not in use. + */ + public void rewind() + { + } + + /** + * Not in use. + */ + public boolean seek(int p) + { + return false; + } + + /** + * Get the typecode of this enumeration. + */ + public TypeCode type() + { + return official_type; + } + + /** + * Compares with other DynAny for equality. + */ + public boolean equals(java.lang.Object other) + { + if (other instanceof DynAny) + return equal((DynAny) other); + else + return false; + } + + /** + * This depends on an object. + */ + public abstract boolean equal(DynAny other); + +} diff --git a/libjava/classpath/gnu/CORBA/DynAn/ValueChangeListener.java b/libjava/classpath/gnu/CORBA/DynAn/ValueChangeListener.java new file mode 100644 index 0000000..5972761 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/ValueChangeListener.java @@ -0,0 +1,50 @@ +/* ValueChangeListener.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +/** + * An interface, able to receive notification about the change of value + * of some DynAny. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface ValueChangeListener +{ + void changed(); +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java b/libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java deleted file mode 100644 index 47176c4..0000000 --- a/libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java +++ /dev/null @@ -1,177 +0,0 @@ -/* abstractDynAny.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.DynAn; - -import gnu.CORBA.typeNamer; - -import org.omg.CORBA.Any; -import org.omg.CORBA.LocalObject; -import org.omg.CORBA.ORB; -import org.omg.CORBA.TypeCode; -import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; - -import java.io.Serializable; - -/** - * The top of our DynAny implementation, this class provides ORB that is - * required to create anys and factory that is required to initialise DynAnys. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class abstractDynAny - extends LocalObject - implements Serializable -{ - /** - * Use serialVersionUID for interoperability. - */ - private static final long serialVersionUID = 1; - - /** - * The "initial final_type" that can be an alias of the known final_type. - */ - public TypeCode official_type; - - /** - * The "basic" final_type to that the final_type finally evaluates. - */ - public final TypeCode final_type; - - /** - * The DynAny factory, required in initializations. - */ - public final gnuDynAnyFactory factory; - - /** - * The ORB, to that this DynAny belongs. - */ - public final ORB orb; - - /** - * The minor code, indicating the error, related to work with non - GNU - * Classpath DynAny. - */ - short MINOR = 8148; - - /** - * The message about the empty structure or exception. - */ - static final String EMPTY = "Empty structure with no fields."; - - /** - * The message about the structure or exception size mismatch. - */ - static final String SIZE = "Size mismatch."; - - /** - * The message about the content of this DynAny being equal to - * null - */ - static final String ISNULL = "The content is null"; - - /** - * The change value listener. - */ - valueChangedListener listener; - - /** - * Create the abstract dyn any. - */ - public abstractDynAny(TypeCode oType, TypeCode aType, - gnuDynAnyFactory aFactory, ORB anOrb - ) - { - official_type = oType; - final_type = aType; - factory = aFactory; - orb = anOrb; - } - - /** - * Get the typecode. - */ - public TypeCode type() - { - return official_type; - } - - /** - * Create the Any. - */ - public Any createAny() - { - return orb.create_any(); - } - - /** - * The "value changed" listener. - */ - protected void valueChanged() - { - if (listener != null) - listener.changed(); - } - - /** - * Check the type. - */ - void checkType(TypeCode expected, TypeCode actual) - throws TypeMismatch - { - if (!expected.equal(actual)) - throw new TypeMismatch(typeMismatch(expected, actual)); - } - - /** - * Format "Type mismatch" string. - */ - String typeMismatch(TypeCode expected, TypeCode actual) - { - return typeNamer.nameIt(expected) + " expected " + - typeNamer.nameIt(actual); - } - - /** - * Format "size mismatch" string. - */ - String sizeMismatch(int here, int other) - { - return "Size mismatch, " + other + " (expected " + here + ")"; - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java b/libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java deleted file mode 100644 index 8d8b7a5..0000000 --- a/libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java +++ /dev/null @@ -1,405 +0,0 @@ -/* abstractRecord.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.DynAn; - -import gnu.CORBA.Unexpected; -import gnu.CORBA.holderFactory; - -import org.omg.CORBA.Any; -import org.omg.CORBA.ORB; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; -import org.omg.CORBA.TypeCodePackage.Bounds; -import org.omg.CORBA.portable.Streamable; -import org.omg.DynamicAny.DynAny; -import org.omg.DynamicAny.DynAnyPackage.InvalidValue; -import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; -import org.omg.DynamicAny.DynStruct; -import org.omg.DynamicAny.DynValueCommonOperations; -import org.omg.DynamicAny.NameDynAnyPair; -import org.omg.DynamicAny.NameValuePair; - -import java.io.Serializable; - -import java.lang.reflect.Field; - -/** - * A shared base for both dynamic structure an dynamic value final_type. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class abstractRecord - extends anyDivideable - implements DynAny, Serializable -{ - /** - * Use serialVersionUID for interoperability. - */ - private static final long serialVersionUID = 1; - String[] fNames; - - /** - * Creates the structure with the given typecode. - * - * @param fields The DynAny's, representing the fields of the structure. - */ - public abstractRecord(TypeCode oType, TypeCode aType, - gnuDynAnyFactory aFactory, ORB anOrb - ) - { - super(oType, aType, aFactory, anOrb); - } - - /** @inheritDoc */ - public TCKind current_member_kind() - throws TypeMismatch, InvalidValue - { - if (array.length == 0) - throw new TypeMismatch(EMPTY); - try - { - return final_type.member_type(pos).kind(); - } - catch (BadKind e) - { - TypeMismatch t = new TypeMismatch(); - t.initCause(e); - throw t; - } - catch (Bounds e) - { - InvalidValue t = new InvalidValue(); - t.initCause(e); - throw t; - } - } - - /** @inheritDoc */ - public String current_member_name() - throws TypeMismatch, InvalidValue - { - if (array.length == 0) - throw new TypeMismatch(EMPTY); - try - { - return final_type.member_name(pos); - } - catch (BadKind e) - { - TypeMismatch t = new TypeMismatch(); - t.initCause(e); - throw t; - } - catch (Bounds e) - { - InvalidValue t = new InvalidValue(); - t.initCause(e); - throw t; - } - } - - /** - * Get content of the structure. This method must be defined on a different - * name because get_members_as_dyn_any() throws exception only in some of the - * supported interfaces. - */ - public NameDynAnyPair[] gnu_get_members_as_dyn_any() - { - NameDynAnyPair[] r = new NameDynAnyPair[ array.length ]; - for (int i = 0; i < r.length; i++) - { - try - { - r [ i ] = new NameDynAnyPair(fNames [ i ], array [ i ]); - } - catch (Exception ex) - { - throw new Unexpected(ex); - } - } - return r; - } - - /** - * Get content of the structure. This method must be defined on a different - * name because get_members_as_dyn_any() throws exception only in some of the - * supported interfaces. - */ - public NameValuePair[] gnu_get_members() - { - NameValuePair[] r = new NameValuePair[ array.length ]; - for (int i = 0; i < r.length; i++) - { - try - { - r [ i ] = new NameValuePair(fNames [ i ], array [ i ].to_any()); - } - catch (Exception ex) - { - throw new Unexpected(ex); - } - } - return r; - } - - /** - * Set members from the provided array. - */ - public void set_members_as_dyn_any(NameDynAnyPair[] value) - throws TypeMismatch, InvalidValue - { - if (value.length != array.length) - throw new InvalidValue(sizeMismatch(array.length, value.length)); - - for (int i = 0; i < value.length; i++) - { - DynAny dynAny = value [ i ].value; - checkType(dynAny.type(), i); - checkName(value [ i ].id, i); - - array [ i ] = dynAny; - } - pos = 0; - } - - /** - * Check the name at the given position ("" matches everything). - */ - private void checkName(String xName, int i) - throws TypeMismatch - { - if (xName.length() > 0 && fNames [ i ].length() > 0) - if (!xName.equals(fNames [ i ])) - throw new TypeMismatch("Field name mismatch " + xName + " expected " + - fNames [ i ] - ); - } - - /** - * Check the type at the given position. - */ - private void checkType(TypeCode t, int i) - throws TypeMismatch - { - if (!array [ i ].type().equal(t)) - throw new TypeMismatch(typeMismatch(array [ i ].type(), t) + " field " + - i - ); - } - - /** - * Set members from the provided array. - */ - public void set_members(NameValuePair[] value) - throws TypeMismatch, InvalidValue - { - if (value.length != array.length) - throw new InvalidValue(sizeMismatch(array.length, value.length)); - - for (int i = 0; i < value.length; i++) - { - Any any = value [ i ].value; - checkType(any.type(), i); - checkName(value [ i ].id, i); - - array [ i ].from_any(any); - } - pos = 0; - } - - /** @inheritDoc */ - public void assign(DynAny from) - throws TypeMismatch - { - checkType(official_type, from.type()); - if (from instanceof DynStruct) - { - try - { - set_members_as_dyn_any(((DynStruct) from).get_members_as_dyn_any()); - } - catch (InvalidValue e) - { - TypeMismatch t = new TypeMismatch("Invalid value"); - t.initCause(e); - throw t; - } - } - else - throw new TypeMismatch("Not a DynStruct"); - } - - /** - * Create a copy. - */ - public DynAny copy() - { - DynAny[] c = new DynAny[ array.length ]; - for (int i = 0; i < c.length; i++) - { - c [ i ] = array [ i ].copy(); - } - - abstractRecord d = newInstance(official_type, final_type, factory, orb); - d.array = c; - return d; - } - - /** - * Create a new instance when copying. - */ - protected abstract abstractRecord newInstance(TypeCode oType, TypeCode aType, - gnuDynAnyFactory aFactory, - ORB anOrb - ); - - /** - * Done via reflection. - */ - public Any to_any() - { - try - { - Streamable sHolder = holderFactory.createHolder(official_type); - - Class sHolderClass = sHolder.getClass(); - Field sHolderValue = sHolderClass.getField("value"); - Class sClass = sHolderValue.getType(); - - Object structure = sClass.newInstance(); - Object member; - Any am; - Field vread; - Field vwrite; - Streamable memberHolder; - - for (int i = 0; i < array.length; i++) - { - am = array [ i ].to_any(); - memberHolder = am.extract_Streamable(); - vwrite = structure.getClass().getField(final_type.member_name(i)); - vread = memberHolder.getClass().getField("value"); - member = vread.get(memberHolder); - vwrite.set(structure, member); - } - - Any g = createAny(); - sHolderValue.set(sHolder, structure); - g.insert_Streamable(sHolder); - g.type(official_type); - return g; - } - catch (Exception e) - { - throw new Unexpected(e); - } - } - - /** - * Done via reflection. - */ - public void from_any(Any an_any) - throws TypeMismatch, InvalidValue - { - checkType(official_type, an_any.type()); - try - { - Streamable s = an_any.extract_Streamable(); - if (s == null) - { - if (this instanceof DynValueCommonOperations) - { - ((DynValueCommonOperations) this).set_to_null(); - return; - } - else - throw new InvalidValue(ISNULL); - } - - Object structure = s.getClass().getField("value").get(s); - if (structure == null && (this instanceof DynValueCommonOperations)) - { - ((DynValueCommonOperations) this).set_to_null(); - return; - } - - Any member; - Streamable holder; - Object field; - TypeCode fType; - Field fField; - - for (int i = 0; i < array.length; i++) - { - fField = structure.getClass().getField(fNames [ i ]); - field = fField.get(structure); - fType = array [ i ].type(); - holder = holderFactory.createHolder(fType); - - member = createAny(); - holder.getClass().getField("value").set(holder, field); - member.insert_Streamable(holder); - member.type(fType); - - array [ i ].from_any(member); - } - - if (this instanceof DynValueCommonOperations) - ((DynValueCommonOperations) this).set_to_value(); - } - catch (InvalidValue v) - { - throw v; - } - catch (NoSuchFieldException ex) - { - TypeMismatch v = - new TypeMismatch("holder value does not match typecode"); - v.initCause(ex); - throw v; - } - catch (Exception ex) - { - TypeMismatch t = new TypeMismatch(); - t.initCause(ex); - throw t; - } - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java b/libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java deleted file mode 100644 index 5f52c80..0000000 --- a/libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java +++ /dev/null @@ -1,514 +0,0 @@ -/* anyDivideable.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.DynAn; - -import gnu.CORBA.typeNamer; - -import org.omg.CORBA.Any; -import org.omg.CORBA.CompletionStatus; -import org.omg.CORBA.ORB; -import org.omg.CORBA.Object; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.UNKNOWN; -import org.omg.DynamicAny.DynAny; -import org.omg.DynamicAny.DynAnyPackage.InvalidValue; -import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; -import org.omg.DynamicAny.DynValueCommon; - -import java.io.Serializable; - -/** - * Provides a base for DynAnys, having multiple components. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class anyDivideable - extends abstractDynAny - implements Serializable -{ - /** - * Use serialVersionUID for interoperability. - */ - private static final long serialVersionUID = 1; - - /** - * The array of the components that in general case may have different - * final_type. - */ - protected DynAny[] array; - - /** - * The internal pointer. - */ - protected int pos = 0; - - public anyDivideable(TypeCode oType, TypeCode aType, - gnuDynAnyFactory aFactory, ORB anOrb - ) - { - super(oType, aType, aFactory, anOrb); - } - - /** - * Advance forward. - */ - public boolean next() - { - pos++; - return array.length > pos; - } - - /** - * Set zero position. - */ - public void rewind() - { - pos = 0; - } - - /** - * Set a position. - */ - public boolean seek(int p) - { - pos = p; - return pos >= 0 && array.length > pos; - } - - /** - * Get the insertion point as DynAny. This method may throw exceptions if the - * current insertion point does not support reading or insertion of the - * primitive types. - * - * @return the focused component, from where the primitve value can be read or - * where it can be inserted. - * @throws InvalidValue if the primitive value cannot be inserted at the given - * point. - */ - protected DynAny focused() - throws InvalidValue, TypeMismatch - { - if (pos >= 0 && pos < array.length) - { - if (array [ pos ].component_count() == 0) - return array [ pos ]; - else - throw new TypeMismatch("Multiple coponents at " + pos); - } - else - throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + - (array.length - 1) - ); - } - - /** {@inheritDoc} */ - public int component_count() - { - return array.length; - } - - /** - * Return the second (enclosed any) that is stored in the wrapped Any. - */ - public Any get_any() - throws TypeMismatch, InvalidValue - { - return focused().get_any(); - } - - /** {@inheritDoc} */ - public boolean get_boolean() - throws TypeMismatch, InvalidValue - { - return focused().get_boolean(); - } - - /** {@inheritDoc} */ - public char get_char() - throws TypeMismatch, InvalidValue - { - return focused().get_char(); - } - - /** {@inheritDoc} */ - public double get_double() - throws TypeMismatch, InvalidValue - { - return focused().get_double(); - } - - /** {@inheritDoc} */ - public float get_float() - throws TypeMismatch, InvalidValue - { - return focused().get_float(); - } - - /** {@inheritDoc} */ - public int get_long() - throws TypeMismatch, InvalidValue - { - return focused().get_long(); - } - - /** {@inheritDoc} */ - public long get_longlong() - throws TypeMismatch, InvalidValue - { - return focused().get_longlong(); - } - - /** {@inheritDoc} */ - public byte get_octet() - throws TypeMismatch, InvalidValue - { - return focused().get_octet(); - } - - /** {@inheritDoc} */ - public Object get_reference() - throws TypeMismatch, InvalidValue - { - return focused().get_reference(); - } - - /** {@inheritDoc} */ - public short get_short() - throws TypeMismatch, InvalidValue - { - return focused().get_short(); - } - - /** {@inheritDoc} */ - public String get_string() - throws TypeMismatch, InvalidValue - { - return focused().get_string(); - } - - /** {@inheritDoc} */ - public TypeCode get_typecode() - throws TypeMismatch, InvalidValue - { - return focused().get_typecode(); - } - - /** {@inheritDoc} */ - public int get_ulong() - throws TypeMismatch, InvalidValue - { - return focused().get_ulong(); - } - - /** {@inheritDoc} */ - public long get_ulonglong() - throws TypeMismatch, InvalidValue - { - return focused().get_ulonglong(); - } - - /** {@inheritDoc} */ - public short get_ushort() - throws TypeMismatch, InvalidValue - { - return focused().get_ushort(); - } - - /** {@inheritDoc} */ - public Serializable get_val() - throws TypeMismatch, InvalidValue - { - if (pos >= 0 && pos < array.length) - { - if (array [ pos ] instanceof DynValueCommon) - return array [ pos ].get_val(); - else - throw new TypeMismatch(); - } - else - throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + - (array.length - 1) - ); - } - - /** {@inheritDoc} */ - public char get_wchar() - throws TypeMismatch, InvalidValue - { - return focused().get_wchar(); - } - - /** {@inheritDoc} */ - public String get_wstring() - throws TypeMismatch, InvalidValue - { - return focused().get_wstring(); - } - - /** {@inheritDoc} */ - public void insert_any(Any a_x) - throws TypeMismatch, InvalidValue - { - focused().insert_any(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_boolean(boolean a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_boolean(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_char(char a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_char(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_double(double a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_double(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_float(float a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_float(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_long(int a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_long(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_longlong(long a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_longlong(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_octet(byte a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_octet(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_reference(Object a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_reference(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_short(short a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_short(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_string(String a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_string(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_typecode(TypeCode a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_typecode(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_ulong(int a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_ulong(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_ulonglong(long a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_ulonglong(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_ushort(short a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_ushort(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_val(Serializable a_x) - throws InvalidValue, TypeMismatch - { - if (pos >= 0 && pos < array.length) - { - if (array [ pos ] instanceof DynValueCommon) - array [ pos ].insert_val(a_x); - else - throw new TypeMismatch(); - } - else - throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + - (array.length - 1) - ); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_wchar(char a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_wchar(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public void insert_wstring(String a_x) - throws InvalidValue, TypeMismatch - { - focused().insert_wstring(a_x); - valueChanged(); - } - - /** {@inheritDoc} */ - public DynAny get_dyn_any() - throws TypeMismatch, InvalidValue - { - return focused().get_dyn_any(); - } - - /** {@inheritDoc} */ - public void insert_dyn_any(DynAny insert_it) - throws TypeMismatch, InvalidValue - { - focused().insert_dyn_any(insert_it); - } - - /** - * Get current component. - * - * @return current component or null if the pointer is out of - * bounds. - */ - public DynAny current_component() - throws TypeMismatch - { - if (array.length == 0) - throw new TypeMismatch("empty"); - return (pos >= 0 && pos < array.length) ? array [ pos ] : null; - } - - /** - * No action, cleanup is done by garbage collector in java. - */ - public void destroy() - { - } - - /** - * Involved in equal(DynAny). - */ - public abstract Any to_any() - throws TypeMismatch; - - /** - * Compares with other DynAny for equality. The final_type, array size and - * array members must match. - */ - public boolean equal(DynAny other) - { - try - { - if (!official_type.equal(other.type())) - return false; - else if (other instanceof anyDivideable) - { - anyDivideable x = (anyDivideable) other; - if (x.array.length != array.length) - return false; - - for (int i = 0; i < array.length; i++) - { - if (!array [ i ].equal(x.array [ i ])) - return false; - } - return true; - } - else if (other == null || other instanceof abstractDynAny) - return false; - else - return other.to_any().equal(to_any()); - } - catch (TypeMismatch e) - { - UNKNOWN u = new UNKNOWN(MINOR, CompletionStatus.COMPLETED_NO); - u.initCause(e); - throw u; - } - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java b/libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java deleted file mode 100644 index b31a6b3..0000000 --- a/libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java +++ /dev/null @@ -1,493 +0,0 @@ -/* Undivideable.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.DynAn; - -import java.io.Serializable; - -import org.omg.CORBA.Any; -import org.omg.CORBA.ORB; -import org.omg.CORBA.Object; -import org.omg.CORBA.TypeCode; -import org.omg.DynamicAny.DynAny; -import org.omg.DynamicAny.DynAnyPackage.InvalidValue; -import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; - -/** - * Represent DynAny that has no internal components (DynEnum and so on). The - * methods, related to internal components, throw exceptions or return agreed - * values like null. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class anyUndivideable - extends abstractDynAny - implements Serializable -{ - /** - * Use serialVersionUID for interoperability. - */ - private static final long serialVersionUID = 1; - - /** - * Create a new instance with the given typecode. - */ - public anyUndivideable(TypeCode oType, TypeCode aType, - gnuDynAnyFactory aFactory, ORB anOrb) - { - super(oType, aType, aFactory, anOrb); - } - - /** - * There are no components. - * - * @return 0, always. - */ - public int component_count() - { - return 0; - } - - /** - * There is no current component. - * - * @throws TypeMismatch, always. - */ - public DynAny current_component() - throws TypeMismatch - { - throw new TypeMismatch("Not applicable"); - } - - /** - * Returns without action. - */ - public void destroy() - { - } - - /** - * Not in use. - */ - public Any get_any() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public boolean get_boolean() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public char get_char() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public double get_double() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public DynAny get_dyn_any() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public float get_float() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public int get_long() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public long get_longlong() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public byte get_octet() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public Object get_reference() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public short get_short() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public String get_string() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public TypeCode get_typecode() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public int get_ulong() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public long get_ulonglong() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public short get_ushort() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public Serializable get_val() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public char get_wchar() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public String get_wstring() - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_any(Any an_any) - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_boolean(boolean a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_char(char a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_double(double a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_dyn_any(DynAny insert_it) - throws TypeMismatch, InvalidValue - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_float(float a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_long(int a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_longlong(long a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_octet(byte a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_reference(Object a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_short(short a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_string(String a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_typecode(TypeCode a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_ulong(int a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_ulonglong(long a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_ushort(short a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_val(Serializable a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_wchar(char a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public void insert_wstring(String a_x) - throws InvalidValue, TypeMismatch - { - throw new TypeMismatch(); - } - - /** - * Not in use. - */ - public boolean next() - { - return false; - } - - /** - * Not in use. - */ - public void rewind() - { - } - - /** - * Not in use. - */ - public boolean seek(int p) - { - return false; - } - - /** - * Get the typecode of this enumeration. - */ - public TypeCode type() - { - return official_type; - } - - /** - * Compares with other DynAny for equality. - */ - public boolean equals(java.lang.Object other) - { - if (other instanceof DynAny) - return equal((DynAny) other); - else - return false; - } - - /** - * This depends on an object. - */ - public abstract boolean equal(DynAny other); - -} diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java index 015628e..23141de 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java @@ -38,14 +38,14 @@ exception statement from your version. */ package gnu.CORBA.DynAn; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.BufferedCdrOutput; import gnu.CORBA.OctetHolder; import gnu.CORBA.Unexpected; import gnu.CORBA.WCharHolder; import gnu.CORBA.WStringHolder; -import gnu.CORBA.holderFactory; -import gnu.CORBA.typeNamer; -import gnu.CORBA.universalHolder; +import gnu.CORBA.HolderLocator; +import gnu.CORBA.TypeKindNamer; +import gnu.CORBA.GeneralHolder; import org.omg.CORBA.Any; import org.omg.CORBA.AnyHolder; @@ -84,7 +84,7 @@ import java.util.Arrays; * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class gnuDynAny extends abstractDynAny implements DynAny, Serializable +public class gnuDynAny extends AbstractAny implements DynAny, Serializable { /** * Use serialVersionUID for interoperability. @@ -132,7 +132,7 @@ public class gnuDynAny extends abstractDynAny implements DynAny, Serializable { if (holder != null) { - cdrBufOutput buffer = new cdrBufOutput(); + BufferedCdrOutput buffer = new BufferedCdrOutput(); holder._write(buffer); gnuDynAny other; @@ -165,7 +165,7 @@ public class gnuDynAny extends abstractDynAny implements DynAny, Serializable public DynAny current_component() throws TypeMismatch { throw new TypeMismatch("Not applicable for " + - typeNamer.nameIt(final_type) + TypeKindNamer.nameIt(final_type) ); } @@ -193,14 +193,14 @@ public class gnuDynAny extends abstractDynAny implements DynAny, Serializable { throw new InvalidValue(ISNULL); } - else if (a_holder instanceof universalHolder) + else if (a_holder instanceof GeneralHolder) { - holder = holderFactory.createHolder(official_type); + holder = HolderLocator.createHolder(official_type); if (holder == null) - holder = holderFactory.createHolder(final_type); + holder = HolderLocator.createHolder(final_type); if (holder == null) - holder = ((universalHolder) a_holder).Clone(); + holder = ((GeneralHolder) a_holder).Clone(); else { InputStream in = an_any.create_input_stream(); @@ -890,7 +890,7 @@ public class gnuDynAny extends abstractDynAny implements DynAny, Serializable */ public boolean equal(DynAny other) { - if (other instanceof abstractDynAny) + if (other instanceof AbstractAny) { if (other instanceof gnuDynAny) { @@ -899,10 +899,10 @@ public class gnuDynAny extends abstractDynAny implements DynAny, Serializable if (!x.holder.getClass().equals(holder.getClass())) return false; - cdrBufOutput b1 = new cdrBufOutput(); + BufferedCdrOutput b1 = new BufferedCdrOutput(); x.holder._write(b1); - cdrBufOutput b2 = new cdrBufOutput(b1.buffer.size() + 10); + BufferedCdrOutput b2 = new BufferedCdrOutput(b1.buffer.size() + 10); holder._write(b2); return Arrays.equals(b1.buffer.toByteArray(), diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java index dd17628..b8b39bf 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java @@ -40,8 +40,8 @@ package gnu.CORBA.DynAn; import gnu.CORBA.Poa.ORB_1_4; import gnu.CORBA.Unexpected; -import gnu.CORBA.holderFactory; -import gnu.CORBA.typeNamer; +import gnu.CORBA.HolderLocator; +import gnu.CORBA.TypeKindNamer; import org.omg.CORBA.Any; import org.omg.CORBA.LocalObject; @@ -227,7 +227,7 @@ public class gnuDynAnyFactory */ public DynAny create_simple(TypeCode official, TypeCode type) { - Streamable holder = holderFactory.createHolder(type); + Streamable holder = HolderLocator.createHolder(type); return new gnuDynAny(holder, official, type, this, orb); } @@ -314,7 +314,7 @@ public class gnuDynAnyFactory case TCKind._tk_Principal : case TCKind._tk_abstract_interface : throw new InconsistentTypeCode("Following API, the " + - typeNamer.nameIt(type) + + TypeKindNamer.nameIt(type) + " must not be supported." ); diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java index 1c08496..825cd0a 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java @@ -39,7 +39,7 @@ exception statement from your version. */ package gnu.CORBA.DynAn; import gnu.CORBA.Unexpected; -import gnu.CORBA.holderFactory; +import gnu.CORBA.HolderLocator; import org.omg.CORBA.Any; import org.omg.CORBA.BAD_PARAM; @@ -66,7 +66,7 @@ import java.lang.reflect.Field; * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class gnuDynArray - extends anyDivideable + extends DivideableAny implements DynArray, Serializable { /** @@ -238,10 +238,10 @@ public class gnuDynArray try { Streamable memberHolder = - holderFactory.createHolder(official_components); + HolderLocator.createHolder(official_components); if (memberHolder == null) - memberHolder = holderFactory.createHolder(final_components); + memberHolder = HolderLocator.createHolder(final_components); Class memberHolderClass = memberHolder.getClass(); Class memberClass = memberHolderClass.getField("value").getType(); @@ -260,7 +260,7 @@ public class gnuDynArray Array.set(members, i, member); } - Streamable arrayHolder = holderFactory.createHolder(official_type); + Streamable arrayHolder = HolderLocator.createHolder(official_type); arrayHolder.getClass().getField("value").set(arrayHolder, members); Any g = createAny(); @@ -296,9 +296,9 @@ public class gnuDynArray { if (holderClass == null) { - holder = holderFactory.createHolder(official_components); + holder = HolderLocator.createHolder(official_components); if (holder == null) - holder = holderFactory.createHolder(final_components); + holder = HolderLocator.createHolder(final_components); holderClass = holder.getClass(); } else diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java index 2fccc85..6eb7fe2 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java @@ -60,7 +60,7 @@ import java.util.Arrays; * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class gnuDynEnum extends anyUndivideable implements DynEnum +public class gnuDynEnum extends UndivideableAny implements DynEnum { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java index 39b0022..9655f03 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java @@ -57,7 +57,7 @@ import java.math.BigDecimal; * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class gnuDynFixed extends anyUndivideable implements DynFixed +public class gnuDynFixed extends UndivideableAny implements DynFixed { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java index b086d64..b15aff3 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java @@ -54,7 +54,7 @@ import org.omg.DynamicAny.DynAny; * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class gnuDynStruct - extends abstractRecord + extends RecordAny implements DynStruct, Serializable { /** @@ -89,7 +89,7 @@ public class gnuDynStruct } /** @inheritDoc */ - protected abstractRecord newInstance(TypeCode oType, TypeCode aType, + protected RecordAny newInstance(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory, ORB anOrb) { return new gnuDynStruct(oType, aType, aFactory, anOrb); diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java index ad41e24..ef5aed6 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java @@ -62,8 +62,8 @@ import java.io.Serializable; * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class gnuDynUnion - extends anyDivideable - implements DynUnion, Serializable, valueChangedListener + extends DivideableAny + implements DynUnion, Serializable, ValueChangeListener { /** * Use serialVersionUID for interoperability. @@ -96,7 +96,7 @@ public class gnuDynUnion discriminator = factory.create_dyn_any_from_type_code(final_type.discriminator_type()); - ((abstractDynAny) discriminator).listener = this; + ((AbstractAny) discriminator).listener = this; if (final_type.default_index() >= 0) set_to_default_member(); @@ -114,7 +114,7 @@ public class gnuDynUnion /* * (non-Javadoc) * - * @see gnu.CORBA.DynAn.anyDivideable#to_any() + * @see gnu.CORBA.DynAn.DivideableAny#to_any() */ public Any to_any() { @@ -171,7 +171,7 @@ public class gnuDynUnion gnuDynUnion other = new gnuDynUnion(official_type, final_type, factory, orb); other.discriminator = discriminator.copy(); - ((abstractDynAny) other.discriminator).listener = other; + ((AbstractAny) other.discriminator).listener = other; if (array.length == 1) { other.array = new DynAny[] { other.discriminator }; diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java index c2db947..0c31d40 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.CORBA.DynAn; +import gnu.CORBA.Minor; import gnu.CORBA.Unexpected; import org.omg.CORBA.Any; @@ -66,7 +67,7 @@ import java.io.Serializable; * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class gnuDynValue extends abstractRecord implements DynValue, +public class gnuDynValue extends RecordAny implements DynValue, Serializable { /** @@ -243,7 +244,7 @@ public class gnuDynValue extends abstractRecord implements DynValue, /** * Create a new instance. */ - protected abstractRecord newInstance(TypeCode oType, TypeCode aType, + protected RecordAny newInstance(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory, ORB anOrb ) { @@ -301,9 +302,12 @@ public class gnuDynValue extends abstractRecord implements DynValue, ValueFactory factory = ((org.omg.CORBA_2_3.ORB) orb).lookup_value_factory(official_type.id()); if (factory == null) - throw new MARSHAL("Factory for " + official_type.id() + - " not registered." - ); + { + MARSHAL m = new MARSHAL("Factory for " + official_type.id() + + " not registered."); + m.minor = Minor.Factory; + throw m; + } OutputStream out = orb.create_output_stream(); diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java index 66e18f3..a13e9fc 100644 --- a/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java @@ -39,7 +39,7 @@ exception statement from your version. */ package gnu.CORBA.DynAn; import gnu.CORBA.Unexpected; -import gnu.CORBA.holderFactory; +import gnu.CORBA.HolderLocator; import org.omg.CORBA.Any; import org.omg.CORBA.ORB; @@ -65,7 +65,7 @@ import java.lang.reflect.Field; * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class gnuDynValueBox - extends anyDivideable + extends DivideableAny implements DynValueBox, Serializable { /** @@ -208,7 +208,7 @@ public class gnuDynValueBox { try { - Streamable holder = holderFactory.createHolder(content); + Streamable holder = HolderLocator.createHolder(content); Field v = holder.getClass().getField("value"); v.set(holder, s); diff --git a/libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java b/libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java deleted file mode 100644 index 94ddffb..0000000 --- a/libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java +++ /dev/null @@ -1,50 +0,0 @@ -/* valueChangedListener.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.DynAn; - -/** - * An interface, able to receive notification about the change of value - * of some DynAny. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public interface valueChangedListener -{ - void changed(); -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java b/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java index 890ca5f..8fc8697 100644 --- a/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java +++ b/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java @@ -125,6 +125,7 @@ public class EmptyExceptionHolder catch (Exception ex) { BAD_OPERATION bad = new BAD_OPERATION(); + bad.minor = Minor.CDR; bad.initCause(ex); throw bad; } diff --git a/libjava/classpath/gnu/CORBA/ExceptionCreator.java b/libjava/classpath/gnu/CORBA/ExceptionCreator.java deleted file mode 100644 index 8b75205..0000000 --- a/libjava/classpath/gnu/CORBA/ExceptionCreator.java +++ /dev/null @@ -1,245 +0,0 @@ -/* ExceptionCreator.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.CompletionStatus; -import org.omg.CORBA.CompletionStatusHelper; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.SystemException; -import org.omg.CORBA.UNKNOWN; -import org.omg.CORBA.UserException; -import org.omg.CORBA.portable.InputStream; -import org.omg.CORBA.portable.OutputStream; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -/** - * Creates the objects from the agreed IDL names. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class ExceptionCreator -{ - /** - * The standard OMG prefix. - */ - public static final String OMG_PREFIX = "omg.org/"; - - /** - * The standard java prefix. - */ - public static final String JAVA_PREFIX = "org.omg."; - - /** - * Create the system exception with the given idl name. - * - * @param idl the exception IDL name, must match the syntax - * "IDL::1.0". - * @param minor the exception minor code. - * @param completed the exception completion status. - * - * @return the created exception. - */ - public static SystemException createSystemException(String idl, int minor, - CompletionStatus completed - ) - { - try - { - String cl = toClassName(idl); - Class exClass = Class.forName(cl); - - Constructor constructor = - exClass.getConstructor(new Class[] - { - String.class, int.class, - CompletionStatus.class - } - ); - - Object exception = - constructor.newInstance(new Object[] - { - " Remote exception " + idl + ", minor " + - minor + ", " + completed + ".", - new Integer(minor), completed - } - ); - - return (SystemException) exception; - } - catch (Exception ex) - { - ex.printStackTrace(); - return new UNKNOWN("Unsupported system exception", minor, completed); - } - } - - /** - * Read the system exception from the given stream. - * @param input the CDR stream to read from. - * @return the exception that has been stored in the stream - * (IDL name, minor code and completion status). - */ - public static SystemException readSystemException(InputStream input) - { - String idl = input.read_string(); - int minor = input.read_ulong(); - CompletionStatus status = CompletionStatusHelper.read(input); - - SystemException exception = - ExceptionCreator.createSystemException(idl, minor, status); - - return exception; - } - - /** - * Reads the user exception, having the given Id, from the - * input stream. The id is expected to be in the form like - * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' - * - * @param idl the exception idl name. - * @param input the stream to read from. - * - * @return the loaded exception. - * @return null if the helper class cannot be found. - */ - public static UserException readUserException(String idl, InputStream input) - { - try - { - String helper = toHelperName(idl); - Class helperClass = Class.forName(helper); - - Method read = - helperClass.getMethod("read", - new Class[] - { - org.omg.CORBA.portable.InputStream.class - } - ); - - return (UserException) read.invoke(null, new Object[] { input }); - } - catch (MARSHAL mex) - { - // This one is ok to throw - throw mex; - } - catch (Exception ex) - { - ex.printStackTrace(); - return null; - } - } - - /** - * Writes the system exception data to CDR output stream. - * - * @param output a stream to write data to. - * @param ex an exception to write. - */ - public static void writeSystemException(OutputStream output, - SystemException ex - ) - { - String exIDL = toIDL(ex.getClass().getName()); - output.write_string(exIDL); - output.write_ulong(ex.minor); - CompletionStatusHelper.write(output, ex.completed); - } - - /** - * Converts teh given IDL name to class name. - * - * @param IDL the idl name. - * - */ - protected static String toClassName(String IDL) - { - String s = IDL; - int a = s.indexOf(':') + 1; - int b = s.lastIndexOf(':'); - - s = IDL.substring(a, b); - - if (s.startsWith(OMG_PREFIX)) - s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); - - return s.replace('/', '.'); - } - - /** - * Gets the helper class name from the string like - * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' - * - * @param IDL the idl name. - */ - protected static String toHelperName(String IDL) - { - String s = IDL; - int a = s.indexOf(':') + 1; - int b = s.lastIndexOf(':'); - - s = IDL.substring(a, b); - - if (s.startsWith(OMG_PREFIX)) - s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); - - return s.replace('/', '.') + "Helper"; - } - - /** - * Convert the class name to IDL name. - * - * @param cn the class name. - * - * @return the idl name. - */ - protected static String toIDL(String cn) - { - if (cn.startsWith(JAVA_PREFIX)) - cn = cn.substring(JAVA_PREFIX.length()); - - cn = cn.replace('.', '/'); - - return "IDL:" + OMG_PREFIX + cn + ":1.0"; - } -} diff --git a/libjava/classpath/gnu/CORBA/ForwardRequestHelper.java b/libjava/classpath/gnu/CORBA/ForwardRequestHelper.java index c7fae5b..cbdf46f 100644 --- a/libjava/classpath/gnu/CORBA/ForwardRequestHelper.java +++ b/libjava/classpath/gnu/CORBA/ForwardRequestHelper.java @@ -81,6 +81,7 @@ public abstract class ForwardRequestHelper catch (ClassCastException cex) { BAD_OPERATION bad = new BAD_OPERATION("ForwardRequest expected"); + bad.minor = Minor.Any; bad.initCause(cex); throw bad; } diff --git a/libjava/classpath/gnu/CORBA/Functional_ORB.java b/libjava/classpath/gnu/CORBA/Functional_ORB.java deleted file mode 100644 index 1565b2c..0000000 --- a/libjava/classpath/gnu/CORBA/Functional_ORB.java +++ /dev/null @@ -1,1627 +0,0 @@ -/* Functional_ORB.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; -import gnu.CORBA.GIOP.CloseMessage; -import gnu.CORBA.GIOP.ErrorMessage; -import gnu.CORBA.GIOP.MessageHeader; -import gnu.CORBA.GIOP.ReplyHeader; -import gnu.CORBA.GIOP.RequestHeader; -import gnu.CORBA.NamingService.NameParser; -import gnu.CORBA.NamingService.NamingServiceTransient; -import gnu.CORBA.Poa.gnuForwardRequest; - -import org.omg.CORBA.BAD_OPERATION; -import org.omg.CORBA.BAD_PARAM; -import org.omg.CORBA.CompletionStatus; -import org.omg.CORBA.DATA_CONVERSION; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.NO_RESOURCES; -import org.omg.CORBA.OBJECT_NOT_EXIST; -import org.omg.CORBA.Object; -import org.omg.CORBA.ORBPackage.InvalidName; -import org.omg.CORBA.Request; -import org.omg.CORBA.SystemException; -import org.omg.CORBA.UNKNOWN; -import org.omg.CORBA.WrongTransaction; -import org.omg.CORBA.portable.Delegate; -import org.omg.CORBA.portable.InvokeHandler; -import org.omg.CORBA.portable.ObjectImpl; -import org.omg.CosNaming.NamingContextExt; -import org.omg.CosNaming.NamingContextExtHelper; - -import java.applet.Applet; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; -import java.net.UnknownHostException; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Properties; -import java.util.StringTokenizer; -import java.util.TreeMap; - -/** - * The ORB implementation, capable to handle remote invocations on the - * registered object. This class implements all features, required till the jdk - * 1.3 inclusive, but does not support the POA that appears since 1.4. The POA - * is supported by {@link gnu.CORBA.Poa.ORB_1_4}. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class Functional_ORB extends Restricted_ORB -{ - /** - * A server, responsible for listening on requests on some local port. The ORB - * may listen on multiple ports and process the requests in separate threads. - * Normally the server takes one port per object being served. - */ - class portServer extends Thread - { - /** - * The number of the currently running parallel threads. - */ - int running_threads; - - /** - * The port on that this portServer is listening for requests. - */ - int s_port; - - /** - * The server socket of this portServer. - */ - ServerSocket service; - - /** - * True if the serving node must shutdown due call of the close_now(). - */ - boolean terminated; - - /** - * Create a new portServer, serving on specific port. - */ - portServer(int _port) - { - s_port = _port; - } - - /** - * Enter the serving loop (get request/process it). All portServer normally - * terminate thy threads when the Functional_ORB.running is set to false. - */ - public void run() - { - try - { - service = new ServerSocket(s_port); - } - catch (IOException ex) - { - BAD_OPERATION bad = - new BAD_OPERATION("Unable to open the server socket."); - bad.initCause(ex); - throw bad; - } - - while (running) - { - try - { - tick(); - } - catch (SocketException ex) - { - // May be thrown when the service is closed by - // the close_now(). - if (terminated) - return; - } - catch (Exception iex) - { - // Wait 5 seconds. Do not terminate the - // service due potentially transient error. - try - { - Thread.sleep(5000); - } - catch (InterruptedException ex) - { - } - } - } - } - - /** - * Perform a single serving step. - * - * @throws java.lang.Exception - */ - void tick() throws Exception - { - serve(this, service); - } - - /** - * Forcibly close the server socket and mark this port as free. - */ - public void close_now() - { - try - { - terminated = true; - service.close(); - } - catch (Exception ex) - { - // This may happen if the service has not been opened or - // cannot be closed. Return without action. - } - } - - /** - * If the thread is no longer in use, close the socket (if opened). - */ - protected void finalize() - { - close_now(); - } - } - - /** - * A server, responsible for listening on requests on some local port and - * serving multiple requests (probably to the different objects) on the same - * thread. - */ - class sharedPortServer extends portServer - { - /** - * Create a new portServer, serving on specific port. - */ - sharedPortServer(int _port) - { - super(_port); - } - - /** - * Perform a single serving step. - * - * @throws java.lang.Exception - */ - void tick() throws Exception - { - Socket request = service.accept(); - serveStep(request, false); - } - } - - /** - * The default value where the first instance of this ORB will start looking - * for a free port. - */ - public static int DEFAULT_INITIAL_PORT = 1126; - - /** - * The property of port, on that this ORB is listening for requests from - * clients. This class supports one port per ORB only. - */ - public static final String LISTEN_ON = "gnu.classpath.CORBA.ListenOn"; - - /** - * The property, defining the IOR of the intial reference to resolve. - */ - public static final String REFERENCE = "org.omg.CORBA.ORBInitRef"; - - /** - * The property, defining the port on that the default name service is - * running. - */ - public static final String NS_PORT = "org.omg.CORBA.ORBInitialPort"; - - /** - * The property, defining the host on that the default name service is - * running. - */ - public static final String NS_HOST = "org.omg.CORBA.ORBInitialHost"; - - /** - * The string, defining the naming service initial reference. - */ - public static final String NAME_SERVICE = "NameService"; - - /** - * The if the client has once opened a socket, it should start sending the - * message header in a given time. Otherwise the server will close the socket. - * This prevents server hang when the client opens the socket, but does not - * send any message, usually due crash on the client side. - */ - public static String START_READING_MESSAGE = - "gnu.classpath.CORBA.TOUT_START_READING_MESSAGE"; - - /** - * If the client has started to send the request message, the socket time out - * changes to the specified value. - */ - public static String WHILE_READING = - "gnu.classpath.CORBA.TOUT_WHILE_READING"; - - /** - * If the message body is received, the time out changes to the specifice - * value. This must be longer, as includes time, required to process the - * received task. We make it 40 minutes. - */ - public static String AFTER_RECEIVING = - "gnu.classpath.CORBA.TOUT_AFTER_RECEIVING"; - - /** - * The address of the local host. - */ - public final String LOCAL_HOST; - - /** - * The if the client has once opened a socket, it should start sending the - * message header in a given time. Otherwise the server will close the socket. - * This prevents server hang when the client opens the socket, but does not - * send any message, usually due crash on the client side. - */ - private int TOUT_START_READING_MESSAGE = 20 * 1000; - - // (Here and below, we use * to make the meaning of the constant clearler). - - /** - * If the client has started to send the request message, the socket time out - * changes to the specified value. - */ - private int TOUT_WHILE_READING = 2 * 60 * 1000; - - /** - * If the message body is received, the time out changes to the specifice - * value. This must be longer, as includes time, required to process the - * received task. We make it 40 minutes. - */ - private int TOUT_AFTER_RECEIVING = 40 * 60 * 1000; - - /** - * Some clients tend to submit multiple requests over the same socket. The - * server waits for the next request on the same socket for the duration, - * specified below. In additions, the request of this implementation also - * waits for the same duration before closing the socket. The default time is - * seven seconds. - */ - public static int TANDEM_REQUESTS = 7000; - - /** - * The map of the already conncted objects. - */ - protected final Connected_objects connected_objects = - new Connected_objects(); - - /** - * The maximal CORBA version, supported by this ORB. The default value 0 means - * that the ORB will not check the request version while trying to respond. - */ - protected Version max_version; - - /** - * Setting this value to false causes the ORB to shutdown after the latest - * serving operation is complete. - */ - protected boolean running; - - /** - * The map of the initial references. - */ - protected Map initial_references = new TreeMap(); - - /** - * The currently active portServers. - */ - private ArrayList portServers = new ArrayList(); - - /** - * The host, on that the name service is expected to be running. - */ - private String ns_host; - - /** - * Probably free port, under that the ORB will try listening for remote - * requests first. When the new object is connected, this port is used first, - * then it is incremented by 1, etc. If the given port is not available, up to - * 20 subsequent values are tried and then the parameterless server socket - * contructor is called. The constant is shared between multiple instances of - * this ORB. - */ - private static int Port = DEFAULT_INITIAL_PORT; - - /** - * The port, on that the name service is expected to be running. - */ - private int ns_port = 900; - - /** - * The name parser. - */ - NameParser nameParser = new NameParser(); - - /** - * The instance, stored in this field, handles the asynchronous dynamic - * invocations. - */ - protected Asynchron asynchron = new Asynchron(); - - /** - * The list of the freed ports. The ORB reuses ports, when possible. - */ - protected LinkedList freed_ports = new LinkedList(); - - /** - * Maps a single-threaded POAs to they sharedPortServants. - */ - protected Hashtable identities = new Hashtable(); - - /** - * The maximal allowed number of the currently running parallel threads per - * object. For security reasons, this is made private and unchangeable. After - * exceeding this limit, the NO_RESOURCES is thrown back to the client. - */ - private int MAX_RUNNING_THREADS = 256; - - /** - * Create the instance of the Functional ORB. - */ - public Functional_ORB() - { - try - { - LOCAL_HOST = ns_host = InetAddress.getLocalHost().getHostAddress(); - initial_references.put("CodecFactory", new gnuCodecFactory(this)); - } - catch (UnknownHostException ex) - { - BAD_OPERATION bad = - new BAD_OPERATION("Unable to open the server socket."); - bad.initCause(ex); - throw bad; - } - } - - /** - * If the max version is assigned, the orb replies with the error message if - * the request version is above the supported 1.2 version. This behavior is - * recommended by OMG, but not all implementations respond that error message - * by re-sending the request, encoded in the older version. - */ - public void setMaxVersion(Version max_supported) - { - max_version = max_supported; - } - - /** - * Get the maximal supported GIOP version or null if the version is not - * checked. - */ - public Version getMaxVersion() - { - return max_version; - } - - /** - * Get the currently free port, starting from the initially set port and going - * up max 20 steps, then trying to bind into any free address. - * - * @return the currently available free port. - * - * @throws NO_RESOURCES if the server socked cannot be opened on the local - * host. - */ - public int getFreePort() throws BAD_OPERATION - { - ServerSocket s; - int a_port; - - try - { - // If there are some previously freed ports, use them first. - if (!freed_ports.isEmpty()) - { - Integer free = (Integer) freed_ports.getLast(); - freed_ports.removeLast(); - s = new ServerSocket(free.intValue()); - s.close(); - return free.intValue(); - } - } - catch (Exception ex) - { - // This may be thrown if the request for the new port has arrived - // before the current service is completly shutdown. - // OK then, use a new port. - } - - for (a_port = Port; a_port < Port + 20; a_port++) - { - try - { - s = new ServerSocket(a_port); - s.close(); - Port = a_port + 1; - return a_port; - } - catch (IOException ex) - { - // Repeat the loop if this exception has been thrown. - } - } - - try - { - // Try any port. - s = new ServerSocket(); - a_port = s.getLocalPort(); - s.close(); - return a_port; - } - catch (IOException ex) - { - NO_RESOURCES bad = - new NO_RESOURCES("Unable to open the server socket."); - bad.initCause(ex); - throw bad; - } - } - - /** - * Set the port, on that the server is listening for the client requests. If - * only one object is connected to the orb, the server will be try listening - * on this port first. It the port is busy, or if more objects are connected, - * the subsequent object will receive a larger port values, skipping - * unavailable ports, if required. The change applies globally. - * - * @param a_Port a port, on that the server is listening for requests. - */ - public static void setPort(int a_Port) - { - Port = a_Port; - } - - /** - * Connect the given CORBA object to this ORB. After the object is connected, - * it starts receiving remote invocations via this ORB. - * - * The ORB tries to connect the object to the port, that has been previously - * set by {@link setPort(int)}. On failure, it tries 20 subsequent larger - * values and then calls the parameterless server socked constructor to get - * any free local port. If this fails, the {@link NO_RESOURCES} is thrown. - * - * @param object the object, must implement the {@link InvokeHandler}) - * interface. - * - * @throws BAD_PARAM if the object does not implement the - * {@link InvokeHandler}). - */ - public void connect(org.omg.CORBA.Object object) - { - int a_port = getFreePort(); - - Connected_objects.cObject ref = connected_objects.add(object, a_port); - IOR ior = createIOR(ref); - prepareObject(object, ior); - if (running) - startService(ior); - } - - /** - * Connect the given CORBA object to this ORB, explicitly specifying the - * object key. - * - * The ORB tries to connect the object to the port, that has been previously - * set by {@link setPort(int)}. On failure, it tries 20 subsequent larger - * values and then calls the parameterless server socked constructor to get - * any free local port. If this fails, the {@link NO_RESOURCES} is thrown. - * - * @param object the object, must implement the {@link InvokeHandler}) - * interface. - * @param key the object key, usually used to identify the object from remote - * side. - * - * @throws BAD_PARAM if the object does not implement the - * {@link InvokeHandler}). - */ - public void connect(org.omg.CORBA.Object object, byte[] key) - { - int a_port = getFreePort(); - - Connected_objects.cObject ref = - connected_objects.add(key, object, a_port, null); - IOR ior = createIOR(ref); - prepareObject(object, ior); - if (running) - startService(ior); - } - - /** - * Connect the given CORBA object to this ORB, explicitly specifying the - * object key and the identity of the thread (and port), where the object must - * be served. The identity is normally the POA. - * - * The new port server will be started only if there is no one already running - * for the same identity. Otherwise, the task of the existing port server will - * be widened, including duty to serve the given object. All objects, - * connected to a single identity by this method, will process they requests - * subsequently in the same thread. The method is used when the expected - * number of the objects is too large to have a single port and thread per - * object. This method is used by POAs, having a single thread policy. - * - * @param object the object, must implement the {@link InvokeHandler}) - * interface. - * @param key the object key, usually used to identify the object from remote - * side. - * @param port the port, where the object must be connected. - * - * @throws BAD_PARAM if the object does not implement the - * {@link InvokeHandler}). - */ - public void connect_1_thread(org.omg.CORBA.Object object, byte[] key, - java.lang.Object identity - ) - { - sharedPortServer shared = (sharedPortServer) identities.get(identity); - if (shared == null) - { - int a_port = getFreePort(); - shared = new sharedPortServer(a_port); - identities.put(identity, shared); - if (running) - { - portServers.add(shared); - shared.start(); - } - } - - Connected_objects.cObject ref = - connected_objects.add(key, object, shared.s_port, identity); - IOR ior = createIOR(ref); - prepareObject(object, ior); - } - - /** - * Start the service on the given port of this IOR. - * - * @param ior the ior (only Internet.port is used). - */ - public void startService(IOR ior) - { - portServer p = new portServer(ior.Internet.port); - portServers.add(p); - p.start(); - } - - /** - * Destroy this server, releasing the occupied resources. - */ - public void destroy() - { - portServer p; - for (int i = 0; i < portServers.size(); i++) - { - p = (portServer) portServers.get(i); - p.close_now(); - } - super.destroy(); - } - - /** - * Disconnect the given CORBA object from this ORB. The object will be no - * longer receiving the remote invocations. In response to the remote - * invocation on this object, the ORB will send the exception - * {@link OBJECT_NOT_EXIST}. The object, however, is not destroyed and can - * receive the local invocations. - * - * @param object the object to disconnect. - */ - public void disconnect(org.omg.CORBA.Object object) - { - Connected_objects.cObject rmKey = null; - - // Handle the case when it is possible to get the object key. - // Handle the case when the object is known, but not local. - if (object instanceof ObjectImpl) - { - Delegate delegate = ((ObjectImpl) object)._get_delegate(); - if (delegate instanceof Simple_delegate) - { - byte[] key = ((Simple_delegate) delegate).getIor().key; - rmKey = connected_objects.get(key); - } - } - - // Try to find and disconned the object that is not an instance of the - // object implementation. - if (rmKey == null) - rmKey = connected_objects.getKey(object); - if (rmKey != null) - { - // Find and stop the corresponding portServer. - portServer p; - StopService: - for (int i = 0; i < portServers.size(); i++) - { - p = (portServer) portServers.get(i); - if (p.s_port == rmKey.port && !(p instanceof sharedPortServer)) - { - p.close_now(); - freed_ports.addFirst(new Integer(rmKey.port)); - break StopService; - } - connected_objects.remove(rmKey.key); - } - } - } - - /** - * Notifies ORB that the shared service indentity (usually POA) is destroyed. - * The matching shared port server is terminated and the identity table entry - * is deleted. If this identity is not known for this ORB, the method returns - * without action. - * - * @param identity the identity that has been destroyed. - */ - public void identityDestroyed(java.lang.Object identity) - { - if (identity == null) - return; - - sharedPortServer ise = (sharedPortServer) identities.get(identity); - if (ise != null) - { - synchronized (connected_objects) - { - ise.close_now(); - identities.remove(identity); - - Connected_objects.cObject obj; - Map.Entry m; - Iterator iter = connected_objects.entrySet().iterator(); - while (iter.hasNext()) - { - m = (Map.Entry) iter.next(); - obj = (Connected_objects.cObject) m.getValue(); - if (obj.identity == identity) - iter.remove(); - } - } - } - } - - /** - * Find the local object, connected to this ORB. - * - * @param ior the ior of the potentially local object. - * - * @return the local object, represented by the given IOR, or null if this is - * not a local connected object. - */ - public org.omg.CORBA.Object find_local_object(IOR ior) - { - // Must be the same host. - if (!ior.Internet.host.equals(LOCAL_HOST)) - return null; - - // Must be the same port. - if (ior.Internet.port != Port) - return null; - - return find_connected_object(ior.key); - } - - /** - * List the initially available CORBA objects (services). - * - * @return a list of services. - * - * @see resolve_initial_references(String) - */ - public String[] list_initial_services() - { - String[] refs = new String[ initial_references.size() ]; - int p = 0; - - Iterator iter = initial_references.keySet().iterator(); - while (iter.hasNext()) - { - refs [ p++ ] = (String) iter.next(); - } - return refs; - } - - /** - * Get the IOR reference string for the given object. The string embeds - * information about the object repository Id, its access key and the server - * internet address and port. With this information, the object can be found - * by another ORB, possibly located on remote computer. - * - * @param the CORBA object - * @return the object IOR representation. - * - * @throws BAD_PARAM if the object has not been previously connected to this - * ORB. - * - * @throws BAD_OPERATION in the unlikely case if the local host address cannot - * be resolved. - * - * @see string_to_object(String) - */ - public String object_to_string(org.omg.CORBA.Object forObject) - { - // Handle the case when the object is known, but not local. - if (forObject instanceof ObjectImpl) - { - Delegate delegate = ((ObjectImpl) forObject)._get_delegate(); - if (delegate instanceof Simple_delegate) - return ((Simple_delegate) delegate).getIor().toStringifiedReference(); - } - - // Handle the case when the object is local. - Connected_objects.cObject rec = connected_objects.getKey(forObject); - - if (rec == null) - throw new BAD_PARAM("The object " + forObject + - " has not been previously connected to this ORB" - ); - - IOR ior = createIOR(rec); - - return ior.toStringifiedReference(); - } - - /** - * Get the local IOR for the given object, null if the object is not local. - */ - public IOR getLocalIor(org.omg.CORBA.Object forObject) - { - Connected_objects.cObject rec = connected_objects.getKey(forObject); - if (rec == null) - return null; - else - return createIOR(rec); - } - - /** - * Find and return the easily accessible CORBA object, addressed by name. - * - * @param name the object name. - * @return the object - * - * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name is not - * associated with the known object. - */ - public org.omg.CORBA.Object resolve_initial_references(String name) - throws InvalidName - { - org.omg.CORBA.Object object = null; - try - { - object = (org.omg.CORBA.Object) initial_references.get(name); - if (object == null && name.equals(NAME_SERVICE)) - { - object = getDefaultNameService(); - if (object != null) - initial_references.put(NAME_SERVICE, object); - } - } - catch (Exception ex) - { - InvalidName err = new InvalidName(name); - err.initCause(ex); - throw err; - } - if (object != null) - return object; - else - throw new InvalidName("Not found: '" + name + "'"); - } - - /** - * Start the ORBs main working cycle (receive invocation - invoke on the local - * object - send response - wait for another invocation). - * - * The method only returns after calling {@link #shutdown(boolean)}. - */ - public void run() - { - running = true; - - // Instantiate the port server for each socket. - Iterator iter = connected_objects.entrySet().iterator(); - Map.Entry m; - Connected_objects.cObject obj; - - while (iter.hasNext()) - { - m = (Map.Entry) iter.next(); - obj = (Connected_objects.cObject) m.getValue(); - - portServer subserver; - - if (obj.identity == null) - { - subserver = new portServer(obj.port); - portServers.add(subserver); - } - else - subserver = (portServer) identities.get(obj.identity); - - if (!subserver.isAlive()) - { - // Reuse the current thread for the last portServer. - if (!iter.hasNext()) - { - // Discard the iterator, eliminating lock checks. - iter = null; - subserver.run(); - return; - } - else - subserver.start(); - } - } - } - - /** - * Shutdown the ORB server. - * - * @param wait_for_completion if true, the current thread is suspended until - * the shutdown process is complete. - */ - public void shutdown(boolean wait_for_completion) - { - super.shutdown(wait_for_completion); - running = false; - - if (!wait_for_completion) - { - for (int i = 0; i < portServers.size(); i++) - { - portServer p = (portServer) portServers.get(i); - p.close_now(); - } - } - } - - /** - * Find and return the CORBA object, addressed by the given IOR string - * representation. The object can (an usually is) located on a remote - * computer, possibly running a different (not necessary java) CORBA - * implementation. - * - * @param ior the object IOR representation string. - * - * @return the found CORBA object. - * @see object_to_string(org.omg.CORBA.Object) - */ - public org.omg.CORBA.Object string_to_object(String an_ior) - { - return nameParser.corbaloc(an_ior, this); - } - - /** - * Convert ior reference to CORBA object. - */ - public org.omg.CORBA.Object ior_to_object(IOR ior) - { - org.omg.CORBA.Object object = find_local_object(ior); - if (object == null) - { - ObjectImpl impl = stubFinder.search(this, ior); - try - { - if (impl._get_delegate() == null) - impl._set_delegate(new IOR_Delegate(this, ior)); - } - catch (BAD_OPERATION ex) - { - // Some colaborants may throw this exception - // in response to the attempt to get the unset delegate. - impl._set_delegate(new IOR_Delegate(this, ior)); - } - - object = impl; - connected_objects.add(ior.key, impl, ior.Internet.port, null); - } - return object; - } - - /** - * Get the default naming service for the case when there no NameService - * entries. - */ - protected org.omg.CORBA.Object getDefaultNameService() - { - if (initial_references.containsKey(NAME_SERVICE)) - return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE); - - IOR ior = new IOR(); - ior.Id = NamingContextExtHelper.id(); - ior.Internet.host = ns_host; - ior.Internet.port = ns_port; - ior.key = NamingServiceTransient.getDefaultKey(); - - IOR_contructed_object iorc = new IOR_contructed_object(this, ior); - NamingContextExt namer = NamingContextExtHelper.narrow(iorc); - initial_references.put(NAME_SERVICE, namer); - return namer; - } - - /** - * Find and return the object, that must be previously connected to this ORB. - * Return null if no such object is available. - * - * @param key the object key. - * - * @return the connected object, null if none. - */ - protected org.omg.CORBA.Object find_connected_object(byte[] key) - { - Connected_objects.cObject ref = connected_objects.get(key); - return ref == null ? null : ref.object; - } - - /** - * Set the ORB parameters. This method is normally called from - * {@link #init(Applet, Properties)}. - * - * @param app the current applet. - * - * @param props application specific properties, passed as the second - * parameter in {@link #init(Applet, Properties)}. Can be null. - */ - protected void set_parameters(Applet app, Properties props) - { - useProperties(props); - - String[][] para = app.getParameterInfo(); - if (para != null) - { - for (int i = 0; i < para.length; i++) - { - if (para [ i ] [ 0 ].equals(LISTEN_ON)) - Port = Integer.parseInt(para [ i ] [ 1 ]); - if (para [ i ] [ 0 ].equals(REFERENCE)) - { - StringTokenizer st = - new StringTokenizer(para [ i ] [ 1 ], "="); - initial_references.put(st.nextToken(), - string_to_object(st.nextToken()) - ); - } - - if (para [ i ] [ 0 ].equals(NS_HOST)) - ns_host = para [ i ] [ 1 ]; - if (para [ i ] [ 0 ].equals(START_READING_MESSAGE)) - TOUT_START_READING_MESSAGE = Integer.parseInt(para [ i ] [ 1 ]); - if (para [ i ] [ 0 ].equals(WHILE_READING)) - TOUT_WHILE_READING = Integer.parseInt(para [ i ] [ 1 ]); - if (para [ i ] [ 0 ].equals(AFTER_RECEIVING)) - TOUT_AFTER_RECEIVING = Integer.parseInt(para [ i ] [ 1 ]); - try - { - if (para [ i ] [ 0 ].equals(NS_PORT)) - ns_port = Integer.parseInt(para [ i ] [ 1 ]); - } - catch (NumberFormatException ex) - { - BAD_PARAM bad = - new BAD_PARAM("Invalid " + NS_PORT + - "property, unable to parse '" + - props.getProperty(NS_PORT) + "'" - ); - bad.initCause(ex); - throw bad; - } - } - } - } - - /** - * Set the ORB parameters. This method is normally called from - * {@link #init(String[], Properties)}. - * - * @param para the parameters, that were passed as the parameters to the - * main(String[] args) method of the current standalone - * application. - * - * @param props application specific properties that were passed as a second - * parameter in {@link init(String[], Properties)}). Can be null. - */ - protected void set_parameters(String[] para, Properties props) - { - if (para.length > 1) - { - for (int i = 0; i < para.length - 1; i++) - { - if (para [ i ].endsWith("ListenOn")) - Port = Integer.parseInt(para [ i + 1 ]); - if (para [ i ].endsWith("ORBInitRef")) - { - StringTokenizer st = new StringTokenizer(para [ i + 1 ], "="); - initial_references.put(st.nextToken(), - string_to_object(st.nextToken()) - ); - } - - if (para [ i ].endsWith("ORBInitialHost")) - ns_host = para [ i + 1 ]; - try - { - if (para [ i ].endsWith("ORBInitialPort")) - ns_port = Integer.parseInt(para [ i + 1 ]); - } - catch (NumberFormatException ex) - { - throw new BAD_PARAM("Invalid " + para [ i ] + - "parameter, unable to parse '" + - props.getProperty(para [ i + 1 ]) + "'" - ); - } - } - } - - useProperties(props); - } - - /** - * Create IOR for the given object references. - */ - protected IOR createIOR(Connected_objects.cObject ref) - throws BAD_OPERATION - { - IOR ior = new IOR(); - ior.key = ref.key; - ior.Internet.port = ref.port; - - if (ref.object instanceof ObjectImpl) - { - ObjectImpl imp = (ObjectImpl) ref.object; - if (imp._ids().length > 0) - ior.Id = imp._ids() [ 0 ]; - } - if (ior.Id == null) - ior.Id = ref.object.getClass().getName(); - try - { - ior.Internet.host = InetAddress.getLocalHost().getHostAddress(); - ior.Internet.port = ref.port; - } - catch (UnknownHostException ex) - { - throw new BAD_OPERATION("Cannot resolve the local host address"); - } - return ior; - } - - /** - * Prepare object for connecting it to this ORB. - * - * @param object the object being connected. - * - * @throws BAD_PARAM if the object does not implement the - * {@link InvokeHandler}). - */ - private void prepareObject(org.omg.CORBA.Object object, IOR ior) - throws BAD_PARAM - { - /* - * if (!(object instanceof InvokeHandler)) throw new - * BAD_PARAM(object.getClass().getName() + " does not implement - * InvokeHandler. " ); - */ - - // If no delegate is set, set the default delegate. - if (object instanceof ObjectImpl) - { - ObjectImpl impl = (ObjectImpl) object; - try - { - if (impl._get_delegate() == null) - impl._set_delegate(new Simple_delegate(this, ior)); - } - catch (BAD_OPERATION ex) - { - // Some colaborants may throw this exception. - impl._set_delegate(new Simple_delegate(this, ior)); - } - } - } - - /** - * Write the response message. - * - * @param net_out the stream to write response into - * @param msh_request the request message header - * @param rh_request the request header - * @param handler the invocation handler that has been used to invoke the - * operation - * @param sysEx the system exception, thrown during the invocation, null if - * none. - * - * @throws IOException - */ - private void respond_to_client(OutputStream net_out, - MessageHeader msh_request, RequestHeader rh_request, - bufferedResponseHandler handler, SystemException sysEx - ) throws IOException - { - // Set the reply header properties. - ReplyHeader reply = handler.reply_header; - - if (sysEx != null) - reply.reply_status = ReplyHeader.SYSTEM_EXCEPTION; - else if (handler.isExceptionReply()) - reply.reply_status = ReplyHeader.USER_EXCEPTION; - else - reply.reply_status = ReplyHeader.NO_EXCEPTION; - reply.request_id = rh_request.request_id; - - cdrBufOutput out = - new cdrBufOutput(50 + handler.getBuffer().buffer.size()); - out.setOrb(this); - - out.setOffset(msh_request.getHeaderSize()); - - reply.write(out); - - if (msh_request.version.since_inclusive(1, 2)) - { - out.align(8); - - // Write the reply data from the handler. The handler data already - // include the necessary heading zeroes for alignment. - } - handler.getBuffer().buffer.writeTo(out); - - MessageHeader msh_reply = new MessageHeader(); - - msh_reply.version = msh_request.version; - msh_reply.message_type = MessageHeader.REPLY; - msh_reply.message_size = out.buffer.size(); - - // Write the reply. - msh_reply.write(net_out); - out.buffer.writeTo(net_out); - net_out.flush(); - } - - /** - * Forward request to another target, as indicated by the passed exception. - */ - private void forward_request(OutputStream net_out, - MessageHeader msh_request, RequestHeader rh_request, gnuForwardRequest info - ) throws IOException - { - MessageHeader msh_forward = new MessageHeader(); - msh_forward.version = msh_request.version; - - ReplyHeader rh_forward = msh_forward.create_reply_header(); - msh_forward.message_type = MessageHeader.REPLY; - rh_forward.reply_status = info.forwarding_code; - rh_forward.request_id = rh_request.request_id; - - // The forwarding code is either LOCATION_FORWARD or LOCATION_FORWARD_PERM. - cdrBufOutput out = new cdrBufOutput(); - out.setOrb(this); - out.setOffset(msh_forward.getHeaderSize()); - - rh_forward.write(out); - - if (msh_forward.version.since_inclusive(1, 2)) - out.align(8); - out.write_Object(info.forward_reference); - - msh_forward.message_size = out.buffer.size(); - - // Write the forwarding instruction. - msh_forward.write(net_out); - out.buffer.writeTo(net_out); - net_out.flush(); - } - - /** - * Contains a single servicing task. - * - * Normally, each task matches a single remote invocation. However under - * frequent tandem submissions the same task may span over several - * invocations. - * - * @param serverSocket the ORB server socket. - * - * @throws MARSHAL - * @throws IOException - */ - void serve(final portServer p, ServerSocket serverSocket) - throws MARSHAL, IOException - { - final Socket service; - service = serverSocket.accept(); - - // Tell the server there are no more resources. - if (p.running_threads >= MAX_RUNNING_THREADS) - { - serveStep(service, true); - return; - } - - new Thread() - { - public void run() - { - try - { - synchronized (p) - { - p.running_threads++; - } - serveStep(service, false); - } - finally - { - synchronized (p) - { - p.running_threads--; - } - } - } - }.start(); - } - - /** - * A single servicing step, when the client socket is alrady open. - * - * Normally, each task matches a single remote invocation. However under - * frequent tandem submissions the same task may span over several - * invocations. - * - * @param service the opened client socket. - * @param no_resources if true, the "NO RESOURCES" exception is thrown to the - * client. - */ - void serveStep(Socket service, boolean no_resources) - { - try - { - Serving: - while (true) - { - InputStream in = service.getInputStream(); - service.setSoTimeout(TOUT_START_READING_MESSAGE); - - MessageHeader msh_request = new MessageHeader(); - - try - { - msh_request.read(in); - } - catch (MARSHAL ex) - { - // This exception may be thrown due closing the connection. - return; - } - - if (max_version != null) - { - if (!msh_request.version.until_inclusive(max_version.major, - max_version.minor - ) - ) - { - OutputStream out = service.getOutputStream(); - new ErrorMessage(max_version).write(out); - return; - } - } - - byte[] r = new byte[ msh_request.message_size ]; - - int n = 0; - - service.setSoTimeout(TOUT_WHILE_READING); - - reading: - while (n < r.length) - { - n += in.read(r, n, r.length - n); - } - - service.setSoTimeout(TOUT_AFTER_RECEIVING); - - if (msh_request.message_type == MessageHeader.REQUEST) - { - RequestHeader rh_request; - - cdrBufInput cin = new cdrBufInput(r); - cin.setOrb(this); - cin.setVersion(msh_request.version); - cin.setOffset(msh_request.getHeaderSize()); - cin.setBigEndian(msh_request.isBigEndian()); - - rh_request = msh_request.create_request_header(); - - // Read header and auto set the charset. - rh_request.read(cin); - - // in 1.2 and higher, align the current position at - // 8 octet boundary. - if (msh_request.version.since_inclusive(1, 2)) - { - cin.align(8); - - // find the target object. - } - - InvokeHandler target = - (InvokeHandler) find_connected_object(rh_request.object_key); - - // Prepare the reply header. This must be done in advance, - // as the size must be known for handler to set alignments - // correctly. - ReplyHeader rh_reply = msh_request.create_reply_header(); - - // TODO log errors about not existing objects and methods. - bufferedResponseHandler handler = - new bufferedResponseHandler(this, msh_request, rh_reply, - rh_request - ); - - SystemException sysEx = null; - - try - { - if (no_resources) - throw new NO_RESOURCES(); - if (target == null) - throw new OBJECT_NOT_EXIST(); - target._invoke(rh_request.operation, cin, handler); - } - catch (gnuForwardRequest forwarded) - { - OutputStream sou = service.getOutputStream(); - forward_request(sou, msh_request, rh_request, forwarded); - if (service != null && !service.isClosed()) - { - // Wait for the subsequent invocations on the - // same socket for the TANDEM_REQUEST duration. - service.setSoTimeout(TANDEM_REQUESTS); - continue Serving; - } - } - catch (SystemException ex) - { - sysEx = ex; - - org.omg.CORBA.portable.OutputStream ech = - handler.createExceptionReply(); - ObjectCreator.writeSystemException(ech, ex); - } - catch (Exception except) - { - except.printStackTrace(); - sysEx = - new UNKNOWN("Unknown", 2, - CompletionStatus.COMPLETED_MAYBE - ); - - org.omg.CORBA.portable.OutputStream ech = - handler.createExceptionReply(); - - ObjectCreator.writeSystemException(ech, sysEx); - } - - // Write the response. - if (rh_request.isResponseExpected()) - { - OutputStream sou = service.getOutputStream(); - respond_to_client(sou, msh_request, rh_request, handler, - sysEx - ); - } - } - else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION || - msh_request.message_type == MessageHeader.MESSAGE_ERROR - ) - { - CloseMessage.close(service.getOutputStream()); - service.close(); - return; - } - ; - - // TODO log error: "Not a request message." - if (service != null && !service.isClosed()) - - // Wait for the subsequent invocations on the - // same socket for the TANDEM_REQUEST duration. - service.setSoTimeout(TANDEM_REQUESTS); - else - return; - } - } - catch (SocketException ex) - { - // OK. - return; - } - catch (IOException ioex) - { - // Network error, probably transient. - // TODO log it. - return; - } - } - - private void useProperties(Properties props) - { - if (props != null) - { - if (props.containsKey(LISTEN_ON)) - Port = Integer.parseInt(props.getProperty(LISTEN_ON)); - if (props.containsKey(NS_HOST)) - ns_host = props.getProperty(NS_HOST); - try - { - if (props.containsKey(NS_PORT)) - ns_port = Integer.parseInt(props.getProperty(NS_PORT)); - if (props.containsKey(START_READING_MESSAGE)) - TOUT_START_READING_MESSAGE = - Integer.parseInt(props.getProperty(START_READING_MESSAGE)); - if (props.containsKey(WHILE_READING)) - TOUT_WHILE_READING = - Integer.parseInt(props.getProperty(WHILE_READING)); - if (props.containsKey(AFTER_RECEIVING)) - TOUT_AFTER_RECEIVING = - Integer.parseInt(props.getProperty(AFTER_RECEIVING)); - } - catch (NumberFormatException ex) - { - throw new BAD_PARAM("Invalid " + NS_PORT + - "property, unable to parse '" + props.getProperty(NS_PORT) + - "'" - ); - } - - Enumeration en = props.elements(); - while (en.hasMoreElements()) - { - String item = (String) en.nextElement(); - if (item.equals(REFERENCE)) - initial_references.put(item, - string_to_object(props.getProperty(item)) - ); - } - } - } - - /** - * Get the next instance with a response being received. If all currently sent - * responses not yet processed, this method pauses till at least one of them - * is complete. If there are no requests currently sent, the method pauses - * till some request is submitted and the response is received. This strategy - * is identical to the one accepted by Suns 1.4 ORB implementation. - * - * The returned response is removed from the list of the currently submitted - * responses and is never returned again. - * - * @return the previously sent request that now contains the received - * response. - * - * @throws WrongTransaction If the method was called from the transaction - * scope different than the one, used to send the request. The exception can - * be raised only if the request is implicitly associated with some particular - * transaction. - */ - public Request get_next_response() throws org.omg.CORBA.WrongTransaction - { - return asynchron.get_next_response(); - } - - /** - * Find if any of the requests that have been previously sent with - * {@link #send_multiple_requests_deferred}, have a response yet. - * - * @return true if there is at least one response to the previously sent - * request, false otherwise. - */ - public boolean poll_next_response() - { - return asynchron.poll_next_response(); - } - - /** - * Send multiple prepared requests expecting to get a reply. All requests are - * send in parallel, each in its own separate thread. When the reply arrives, - * it is stored in the agreed fields of the corresponing request data - * structure. If this method is called repeatedly, the new requests are added - * to the set of the currently sent requests, but the old set is not - * discarded. - * - * @param requests the prepared array of requests. - * - * @see #poll_next_response() - * @see #get_next_response() - * @see Request#send_deferred() - */ - public void send_multiple_requests_deferred(Request[] requests) - { - asynchron.send_multiple_requests_deferred(requests); - } - - /** - * Send multiple prepared requests one way, do not caring about the answer. - * The messages, containing requests, will be marked, indicating that the - * sender is not expecting to get a reply. - * - * @param requests the prepared array of requests. - * - * @see Request#send_oneway() - */ - public void send_multiple_requests_oneway(Request[] requests) - { - asynchron.send_multiple_requests_oneway(requests); - } - - /** - * Set the flag, forcing all server threads to terminate. - */ - protected void finalize() throws java.lang.Throwable - { - running = false; - super.finalize(); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java b/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java index f3f35db..bffb026 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java +++ b/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java @@ -47,7 +47,10 @@ import java.util.Set; /** * This class contains the codes, used to identify character sets * in CORBA. These codes are defined in Open Software Foundation (OSF) - * code set registry + * code set registry. + * + * The name of this class specially sets "OSF" apart if somebody would start + * searching Open Software Foundation abbreviation. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ diff --git a/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java b/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java index d884329..38039c2 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java +++ b/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java @@ -38,15 +38,13 @@ exception statement from your version. */ package gnu.CORBA.GIOP; -import gnu.CORBA.IOR; +import gnu.CORBA.Minor; import org.omg.CORBA.MARSHAL; import java.io.IOException; import java.io.OutputStream; -import java.net.Socket; - /** * The explicit command to close the connection. * @@ -60,6 +58,11 @@ import java.net.Socket; public class CloseMessage extends MessageHeader { + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + /** * The singleton close message is typically enough, despite new * instances may be instantiated if the specific version field @@ -95,6 +98,7 @@ public class CloseMessage catch (IOException ex) { MARSHAL m = new MARSHAL("Unable to flush the stream"); + m.minor = Minor.Header; m.initCause(ex); throw m; } diff --git a/libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java b/libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java new file mode 100644 index 0000000..ab565db --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java @@ -0,0 +1,224 @@ +/* CodeSet_sctx.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.GIOP; + +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; +import gnu.CORBA.IOR; +import gnu.CORBA.IOR.CodeSets_profile; + +import java.io.IOException; + +/** + * The code set service context. This context must be included in all + * messages that use wide characters. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class CodeSetServiceContext + extends ServiceContext +{ + /** + * The context code sets id. + */ + public static final int ID = 1; + + /** + * The standard component to include in the messages. + */ + public static final CodeSetServiceContext STANDARD = new CodeSetServiceContext(); + + /** + * The encoding, used to transfer the narrow (1 byte) character data. + * The default value is taken from {@link CharSets_OSF#NATIVE_CHARACTER}. + */ + public int char_data = CharSets_OSF.NATIVE_CHARACTER; + + /** + * The encoding, used to transfer the wide character data. + * The default value is taken from + * {@link CharSets_OSF#NATIVE_WIDE_CHARACTER}. + */ + public int wide_char_data = CharSets_OSF.NATIVE_WIDE_CHARACTER; + + /** + * Find and return the code set service context in the give + * contexts array. Returns {@link #STANDARD} if no code set + * context is present. + * + * @param contexts the array of contexts, can be null. + */ + public static CodeSetServiceContext find(ServiceContext[] contexts) + { + if (contexts != null) + for (int i = 0; i < contexts.length; i++) + { + if (contexts [ i ] instanceof CodeSetServiceContext) + return (CodeSetServiceContext) contexts [ i ]; + } + return STANDARD; + } + + /** + * Select the suitable encoding that is defined in the provided profile. + * + * TODO character encoding. Now the encoding can be set, but it is ignored. + * If you take this task, scan 'TODO character encoding' for + * relevant places. + */ + public static CodeSetServiceContext negotiate(IOR.CodeSets_profile profile) + { + if (profile.negotiated != null) + return profile.negotiated; + + CodeSetServiceContext use = new CodeSetServiceContext(); + + use.char_data = + negotiate(profile.narrow, STANDARD.char_data, CharSets_OSF.ISO8859_1); + + use.wide_char_data = + negotiate(profile.wide, STANDARD.wide_char_data, CharSets_OSF.UTF16); + + profile.negotiated = use; + + return use; + } + + /** + * Read the context from the given stream. Does not read the + * code sets id. + */ + public void readContext(AbstractCdrInput input) + { + AbstractCdrInput encap = input.read_encapsulation(); + + char_data = encap.read_ulong(); + wide_char_data = encap.read_ulong(); + } + + /** + * Return a string representation. + */ + public String toString() + { + return " Encoding: narrow " + name(char_data) + ", wide " + + name(wide_char_data) + ". "; + } + + /** + * Write the context to the given stream, including the code + * sets id. + */ + public void write(AbstractCdrOutput output) + { + output.write_ulong(ID); + + AbstractCdrOutput enout = output.createEncapsulation(); + + enout.write_long(char_data); + enout.write_ulong(wide_char_data); + + try + { + enout.close(); + } + catch (IOException ex) + { + InternalError t = new InternalError(); + t.initCause(ex); + throw t; + } + } + + /** + * Negotiate about the character encoding. Prefer our native encoding, + * if no, prefer IORs native encoding, if no, find any encoding, + * supported by both sides, if no, return the specified final decission. + * + * @param profile the component profile in IOR. + * @param our_native our native encoding + * @param final_decission the encoding that must be returned if no + * compromise is found. + * + * @return the resulted encoding. + */ + protected static int negotiate(IOR.CodeSets_profile.CodeSet_component profile, + int our_native, int final_decission + ) + { + // If our and IORs native sets match, use the native set. + if (profile.native_set == our_native) + return our_native; + + // If the native sets do not match, but the IOR says it + // supports our native set, use our native set. + if (profile.conversion != null) + for (int i = 0; i < profile.conversion.length; i++) + { + if (our_native == profile.conversion [ i ]) + return our_native; + } + + // At this point, we suggest to use the IORs native set. + int[] allSupported = CharSets_OSF.getSupportedCharSets(); + + for (int s = 0; s < allSupported.length; s++) + if (allSupported [ s ] == profile.native_set) + return profile.native_set; + + // Any compromise left? + if (profile.conversion != null) + for (int s = 0; s < allSupported.length; s++) + for (int i = 0; i < profile.conversion.length; i++) + if (allSupported [ s ] == profile.conversion [ i ]) + return allSupported [ s ]; + + // Return the CORBA default char encoding. + return final_decission; + } + + /** + * Conveniency method, used in toString() + */ + private String name(int set) + { + return "0x" + Integer.toHexString(set) + " (" + CharSets_OSF.getName(set) + + ") "; + } +} diff --git a/libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java b/libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java new file mode 100644 index 0000000..77ea20e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java @@ -0,0 +1,76 @@ +/* ContextHandler.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.GIOP; + +import org.omg.CORBA.BAD_INV_ORDER; + +/** + * A header, supporting the service contexts. Such header has a context field + * and methods for adding the new contexts. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class ContextHandler +{ + + /** + * Empty array, indicating that no service context is available. + */ + protected static final ServiceContext[] NO_CONTEXT = new ServiceContext[0]; + + /** + * The context data. + */ + public ServiceContext[] service_context = NO_CONTEXT; + + /** + * Add service context to this header. + * + * @param context_to_add context to add. + * @param replace if true, the existing context with this ID is replaced. + * Otherwise, BAD_INV_ORDER is throwsn. + */ + public void addContext(org.omg.IOP.ServiceContext context_to_add, + boolean replace) + throws BAD_INV_ORDER + { + service_context = ServiceContext.add(service_context, context_to_add, + replace); + } +} diff --git a/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java b/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java index 8d3b353..99942fe 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java +++ b/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java @@ -38,7 +38,9 @@ exception statement from your version. */ package gnu.CORBA.GIOP; +import gnu.CORBA.OrbFunctional; import gnu.CORBA.IOR; +import gnu.CORBA.Minor; import java.io.IOException; import java.io.OutputStream; @@ -46,6 +48,7 @@ import java.io.OutputStream; import java.net.Socket; import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; /** * The error message is sent in response to the message, encoded @@ -59,6 +62,11 @@ import org.omg.CORBA.MARSHAL; public class ErrorMessage extends MessageHeader { + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + /** * Create a new error message, setting the message field * to the {@link MESSAGE_ERROR} and the version number to @@ -73,14 +81,22 @@ public class ErrorMessage /** * Send the error message to the given IOR address. * - * @param to the IOR address (host and port, other fields + * @param ior the IOR address (host and port, other fields * are not used). + * + * @param orb the ORB, sending the error message. */ - public void send(IOR ior) + public void send(IOR ior, ORB orb) { try { - Socket socket = new Socket(ior.Internet.host, ior.Internet.port); + Socket socket; + + if (orb instanceof OrbFunctional) + socket = ((OrbFunctional) orb).socketFactory.createClientSocket( + ior.Internet.host, ior.Internet.port); + else + socket = new Socket(ior.Internet.host, ior.Internet.port); OutputStream socketOutput = socket.getOutputStream(); write(socketOutput); @@ -90,6 +106,7 @@ public class ErrorMessage catch (IOException ex) { MARSHAL t = new MARSHAL(); + t.minor = Minor.Header; t.initCause(ex); throw t; } diff --git a/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java b/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java index 61c46e1..e1bdb51 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java @@ -1,4 +1,4 @@ -/* MessageHeader.java -- GIOP 1.0 message header. +/* MessageHeader.java -- GIOP message header. Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,33 +38,39 @@ exception statement from your version. */ package gnu.CORBA.GIOP; +import gnu.CORBA.Minor; +import gnu.CORBA.Version; +import gnu.CORBA.CDR.BigEndianInputStream; import gnu.CORBA.CDR.BigEndianOutputStream; import gnu.CORBA.CDR.LittleEndianInputStream; import gnu.CORBA.CDR.LittleEndianOutputStream; -import gnu.CORBA.CDR.abstractDataOutputStream; -import gnu.CORBA.Version; +import gnu.CORBA.CDR.AbstractDataInput; +import gnu.CORBA.CDR.AbstractDataOutput; import org.omg.CORBA.MARSHAL; import org.omg.CORBA.portable.IDLEntity; -import java.io.DataInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; - +import java.net.Socket; import java.util.Arrays; -import gnu.CORBA.CDR.BigEndianInputStream; -import gnu.CORBA.CDR.abstractDataInputStream; -import java.io.InputStream; /** * The GIOP message header. - * + * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public class MessageHeader implements IDLEntity { /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** * Request message. */ public static final byte REQUEST = 0; @@ -80,16 +86,15 @@ public class MessageHeader public static final byte CANCEL_REQUEST = 2; /** - * Locate request message, used to check the server ability to - * process requests for the object reference. - * This message is also used to get the + * Locate request message, used to check the server ability to process + * requests for the object reference. This message is also used to get the * address where the object reference should be sent. */ public static final byte LOCATE_REQUEST = 3; /** - * Locate reply message, sent in response to the - * {@link #LocateRequest} message. + * Locate reply message, sent in response to the {@link #LocateRequest} + * message. */ public static final byte LOCATE_REPLY = 4; @@ -104,8 +109,8 @@ public class MessageHeader public static final byte MESSAGE_ERROR = 6; /** - * The fragment messge, following the previous message that - * has more fragments flag set. Added in GIOP 1.1 + * The fragment messge, following the previous message that has more fragments + * flag set. Added in GIOP 1.1 */ public static final byte FRAGMENT = 7; @@ -117,12 +122,9 @@ public class MessageHeader /** * The message type names. */ - protected static String[] types = - new String[] - { - "Request", "Reply", "Cancel", "Locate request", "Locate reply", - "Close connection", "Error", "Fragment" - }; + protected static String[] types = new String[] { "Request", "Reply", + "Cancel", "Locate request", "Locate reply", "Close connection", "Error", + "Fragment" }; /** * The GIOP version. Initialised to 1.0 . @@ -154,7 +156,7 @@ public class MessageHeader /** * Create an empty message header, corresponding the given version. - * + * * @param major the major message header version. * @param minor the minot message header version. */ @@ -164,8 +166,8 @@ public class MessageHeader } /** - * Checks if the message is encoded in the Big Endian, most significant - * byte first. + * Checks if the message is encoded in the Big Endian, most significant byte + * first. */ public boolean isBigEndian() { @@ -173,10 +175,18 @@ public class MessageHeader } /** + * Checks if the message is partial, and more subsequent fragments follow. + */ + public boolean moreFragmentsFollow() + { + return (flags & 0x2) != 0; + } + + /** * Set the encoding to use. - * - * @param use_big_endian if true (default), the Big Endian - * encoding is used. If false, the Little Endian encoding is used. + * + * @param use_big_endian if true (default), the Big Endian encoding is used. + * If false, the Little Endian encoding is used. */ public void setBigEndian(boolean use_big_endian) { @@ -196,16 +206,16 @@ public class MessageHeader /** * Get the message type as string. - * + * * @param type the message type as int (the field {@link message_type}). - * + * * @return the message type as string. */ public String getTypeString(int type) { try { - return types [ type ]; + return types[type]; } catch (ArrayIndexOutOfBoundsException ex) { @@ -215,10 +225,10 @@ public class MessageHeader /** * Creates reply header, matching the message header version number. - * + * * @return one of {@link gnu.CORBA.GIOP.v1_0.ReplyHeader}, - * {@link gnu.CORBA.GIOP.v1_2.ReplyHeader}, etc - depending on - * the version number in this header. + * {@link gnu.CORBA.GIOP.v1_2.ReplyHeader}, etc - depending on the version + * number in this header. */ public ReplyHeader create_reply_header() { @@ -230,10 +240,10 @@ public class MessageHeader /** * Creates request header, matching the message header version number. - * + * * @return one of {@link gnu.CORBA.GIOP.v1_0.RequestHeader}, - * {@link gnu.CORBA.GIOP.v1_2.RequestHeader}, etc - depending on - * the version number in this header. + * {@link gnu.CORBA.GIOP.v1_2.RequestHeader}, etc - depending on the version + * number in this header. */ public RequestHeader create_request_header() { @@ -261,24 +271,28 @@ public class MessageHeader /** * Read the header from the stream. - * + * * @param istream a stream to read from. - * + * * @throws MARSHAL if this is not a GIOP 1.0 header. */ public void read(java.io.InputStream istream) - throws MARSHAL + throws MARSHAL { try { - byte[] xMagic = new byte[ MAGIC.length ]; + byte[] xMagic = new byte[MAGIC.length]; istream.read(xMagic); if (!Arrays.equals(xMagic, MAGIC)) - throw new MARSHAL("Not a GIOP message"); + { + MARSHAL m = new MARSHAL("Not a GIOP message"); + m.minor = Minor.Giop; + throw m; + } version = Version.read_version(istream); - abstractDataInputStream din; + AbstractDataInput din; flags = (byte) istream.read(); @@ -295,6 +309,7 @@ public class MessageHeader catch (IOException ex) { MARSHAL t = new MARSHAL(); + t.minor = Minor.Header; t.initCause(ex); throw t; } @@ -302,26 +317,26 @@ public class MessageHeader /** * Get the short string summary of the message. - * + * * @return a short message summary. */ public String toString() { - return "GIOP " + version + ", " + (isBigEndian() ? "Big" : "Little") + - " endian, " + getTypeString(message_type) + ", " + message_size + - " bytes. "; + return "GIOP " + version + ", " + (isBigEndian() ? "Big" : "Little") + + " endian, " + getTypeString(message_type) + ", " + message_size + + " bytes. "; } /** * Write the header to stream. - * + * * @param out a stream to write into. */ public void write(java.io.OutputStream out) { try { - abstractDataOutputStream dout; + AbstractDataOutput dout; if (isBigEndian()) dout = new BigEndianOutputStream(out); @@ -333,18 +348,99 @@ public class MessageHeader // Write version number. version.write((OutputStream) dout); - dout.write(flags); - dout.write(message_type); - dout.writeInt(message_size); } catch (IOException ex) { MARSHAL t = new MARSHAL(); + t.minor = Minor.Header; t.initCause(ex); throw t; } } + + /** + * Read data, followed by the message header. Handle fragmented messages. + * + * @param source the data source to read from. + * @param service the socket on that the time outs are set. Can be null (no + * timeouts are set). + * @param to_read the timeout while reading the message. + * @param to_pause the timeout for pauses between the message parts. + */ + public byte[] readMessage(InputStream source, Socket service, int to_read, + int to_pause) + { + try + { + byte[] r = new byte[message_size]; + + int n = 0; + if (service != null) + service.setSoTimeout(to_read); + + reading: while (n < r.length) + { + n += source.read(r, n, r.length - n); + } + if (service != null) + service.setSoTimeout(to_pause); + + // Read the message remainder if the message is fragmented. + if (moreFragmentsFollow()) + { + ByteArrayOutputStream buffer = new ByteArrayOutputStream( + 2 * r.length); + buffer.write(r); + + if (r.length < 10) + // Increase the buffer size if the default value (size of the + // previous message) is really too small. + r = new byte[1024]; + + MessageHeader h2 = new MessageHeader(); + + do + { + h2.read(source); + + int dn; + + n = 0; + reading: while (n < h2.message_size) + { + dn = source.read(r, 0, h2.message_size - n); + + if (n == 0 && service != null) + service.setSoTimeout(to_read); + + if (n == 0 && version.since_inclusive(1, 2)) + { + // Skip the four byte request id. + buffer.write(r, 4, dn - 4); + } + else + buffer.write(r, 0, dn); + n = +dn; + } + + if (service != null) + service.setSoTimeout(to_pause); + } + while (h2.moreFragmentsFollow()); + return buffer.toByteArray(); + } + else + return r; + } + catch (IOException ioex) + { + MARSHAL m = new MARSHAL("Unable to read the message continuation."); + m.minor = Minor.Header; + m.initCause(ioex); + throw m; + } + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java index f0f4093..d144829 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java @@ -38,8 +38,8 @@ exception statement from your version. */ package gnu.CORBA.GIOP; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; /** * The header of the standard reply. @@ -47,7 +47,7 @@ import gnu.CORBA.CDR.cdrOutput; * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public abstract class ReplyHeader - extends contextSupportingHeader + extends ContextHandler { /** * Reply status, if no exception occured. @@ -121,7 +121,7 @@ public abstract class ReplyHeader * * @param in a stream to read from. */ - public abstract void read(cdrInput in); + public abstract void read(AbstractCdrInput in); /** * Returns a short string representation. @@ -141,5 +141,5 @@ public abstract class ReplyHeader * * @param out a stream to write into. */ - public abstract void write(cdrOutput out); + public abstract void write(AbstractCdrOutput out); } diff --git a/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java index 17cccb8..3cfadfd 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java @@ -38,8 +38,8 @@ exception statement from your version. */ package gnu.CORBA.GIOP; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; import org.omg.CORBA.portable.IDLEntity; @@ -49,7 +49,7 @@ import org.omg.CORBA.portable.IDLEntity; * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public abstract class RequestHeader - extends contextSupportingHeader + extends ContextHandler implements IDLEntity { /** @@ -137,7 +137,7 @@ public abstract class RequestHeader * * @param in a stream to read from. */ - public abstract void read(cdrInput in); + public abstract void read(AbstractCdrInput in); /** * Return a string representation. @@ -149,6 +149,6 @@ public abstract class RequestHeader * * @param out a stream to write into. */ - public abstract void write(cdrOutput out); + public abstract void write(AbstractCdrOutput out); } diff --git a/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java b/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java index 29a8ea8..7851951 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java +++ b/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java @@ -38,8 +38,8 @@ exception statement from your version. */ package gnu.CORBA.GIOP; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; import org.omg.CORBA.BAD_INV_ORDER; import org.omg.CORBA.BAD_PARAM; @@ -48,7 +48,7 @@ import org.omg.CORBA.portable.IDLEntity; /** * Contains the ORB service data being passed. - * + * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public class ServiceContext @@ -59,6 +59,50 @@ public class ServiceContext */ private static final long serialVersionUID = 1; + /* Standard values for the context_id. */ + public static final int TransactionService = 0; + + /** + * Defines code sets, used to encode wide and narrow characters. Required for + * messages with data structures, involving wide characters. + */ + public static final int CodeSets = 1; + + public static final int ChainBypassCheck = 2; + + public static final int ChainBypassInfo = 3; + + public static final int LogicalThreadId = 4; + + public static final int BI_DIR_IIOP = 5; + + public static final int SendingContextRunTime = 6; + + public static final int INVOCATION_POLICIES = 7; + + public static final int FORWARDED_IDENTITY = 8; + + /** + * Contains exception details if exception being transferred is other than + * System or User exception. javax.rmi uses this context to transfer arbitrary + * java exceptions as CORBA value types. + */ + public static final int UnknownExceptionInfo = 9; + + public static final int RTCorbaPriority = 10; + + public static final int RTCorbaPriorityRange = 11; + + public static final int FT_GROUP_VERSION = 12; + + public static final int FT_REQUEST = 13; + + public static final int ExceptionDetailMessage = 14; + + public static final int SecurityAttributeService = 15; + + public static final int ActivityService = 16; + /** * The context id (for instance, 0x1 for code sets context). At the moment of * writing, the OMG defines 16 standard values and provides rules to register @@ -90,18 +134,18 @@ public class ServiceContext /** * Read the context values from the stream. - * + * * @param istream a stream to read from. */ - public static ServiceContext read(cdrInput istream) + public static ServiceContext read(AbstractCdrInput istream) { int id = istream.read_ulong(); switch (id) { - case cxCodeSet.ID: + case CodeSetServiceContext.ID: - cxCodeSet codeset = new cxCodeSet(); + CodeSetServiceContext codeset = new CodeSetServiceContext(); codeset.readContext(istream); return codeset; @@ -117,7 +161,7 @@ public class ServiceContext /** * Read a sequence of contexts from the input stream. */ - public static ServiceContext[] readSequence(cdrInput istream) + public static ServiceContext[] readSequence(AbstractCdrInput istream) { int size = istream.read_long(); ServiceContext[] value = new gnu.CORBA.GIOP.ServiceContext[size]; @@ -128,10 +172,10 @@ public class ServiceContext /** * Write the context values into the stream. - * + * * @param ostream a stream to write the data to. */ - public void write(cdrOutput ostream) + public void write(AbstractCdrOutput ostream) { ostream.write_ulong(context_id); ostream.write_sequence(context_data); @@ -140,7 +184,7 @@ public class ServiceContext /** * Write the sequence of contexts into the input stream. */ - public static void writeSequence(cdrOutput ostream, ServiceContext[] value) + public static void writeSequence(AbstractCdrOutput ostream, ServiceContext[] value) { ostream.write_long(value.length); for (int i = 0; i < value.length; i++) @@ -172,8 +216,7 @@ public class ServiceContext // Replace context. if (!replace) throw new BAD_INV_ORDER("Repetetive setting of the context " - + service_context.context_id, 15, - CompletionStatus.COMPLETED_NO); + + service_context.context_id, 15, CompletionStatus.COMPLETED_NO); else cx[exists] = service_context; } @@ -205,15 +248,13 @@ public class ServiceContext // Replace context. if (!replace) throw new BAD_INV_ORDER("Repetetive setting of the context " - + service_context.context_id, 15, - CompletionStatus.COMPLETED_NO); + + service_context.context_id, 15, CompletionStatus.COMPLETED_NO); else cx[exists] = new ServiceContext(service_context); return cx; } } - /** * Find context with the given name in the context array. */ @@ -227,8 +268,8 @@ public class ServiceContext } /** - * Find context with the given name in the context array, - * converting into org.omg.IOP.ServiceContext. + * Find context with the given name in the context array, converting into + * org.omg.IOP.ServiceContext. */ public static org.omg.IOP.ServiceContext findContext(int ctx_name, ServiceContext[] cx) @@ -240,6 +281,17 @@ public class ServiceContext } /** + * Find context with the given name in the context array without conversions. + */ + public static ServiceContext find(int ctx_name, ServiceContext[] cx) + { + for (int i = 0; i < cx.length; i++) + if (cx[i].context_id == ctx_name) + return cx[i]; + return null; + } + + /** * Return a string representation. */ public String toString() diff --git a/libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java b/libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java deleted file mode 100644 index ba6c1f8..0000000 --- a/libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java +++ /dev/null @@ -1,76 +0,0 @@ -/* contextSupportingHeader.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.GIOP; - -import org.omg.CORBA.BAD_INV_ORDER; - -/** - * A header, supporting the service contexts. Such header has a context field - * and methods for adding the new contexts. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class contextSupportingHeader -{ - - /** - * Empty array, indicating that no service context is available. - */ - protected static final ServiceContext[] NO_CONTEXT = new ServiceContext[0]; - - /** - * The context data. - */ - public ServiceContext[] service_context = NO_CONTEXT; - - /** - * Add service context to this header. - * - * @param context_to_add context to add. - * @param replace if true, the existing context with this ID is replaced. - * Otherwise, BAD_INV_ORDER is throwsn. - */ - public void addContext(org.omg.IOP.ServiceContext context_to_add, - boolean replace) - throws BAD_INV_ORDER - { - service_context = ServiceContext.add(service_context, context_to_add, - replace); - } -} diff --git a/libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java b/libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java deleted file mode 100644 index 7f42c07..0000000 --- a/libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java +++ /dev/null @@ -1,224 +0,0 @@ -/* CodeSet_sctx.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.GIOP; - -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; -import gnu.CORBA.IOR; -import gnu.CORBA.IOR.CodeSets_profile; - -import java.io.IOException; - -/** - * The code set service context. This context must be included in all - * messages that use wide characters. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class cxCodeSet - extends ServiceContext -{ - /** - * The context code sets id. - */ - public static final int ID = 1; - - /** - * The standard component to include in the messages. - */ - public static final cxCodeSet STANDARD = new cxCodeSet(); - - /** - * The encoding, used to transfer the narrow (1 byte) character data. - * The default value is taken from {@link CharSets_OSF#NATIVE_CHARACTER}. - */ - public int char_data = CharSets_OSF.NATIVE_CHARACTER; - - /** - * The encoding, used to transfer the wide character data. - * The default value is taken from - * {@link CharSets_OSF#NATIVE_WIDE_CHARACTER}. - */ - public int wide_char_data = CharSets_OSF.NATIVE_WIDE_CHARACTER; - - /** - * Find and return the code set service context in the give - * contexts array. Returns {@link #STANDARD} if no code set - * context is present. - * - * @param contexts the array of contexts, can be null. - */ - public static cxCodeSet find(ServiceContext[] contexts) - { - if (contexts != null) - for (int i = 0; i < contexts.length; i++) - { - if (contexts [ i ] instanceof cxCodeSet) - return (cxCodeSet) contexts [ i ]; - } - return STANDARD; - } - - /** - * Select the suitable encoding that is defined in the provided profile. - * - * TODO character encoding. Now the encoding can be set, but it is ignored. - * If you take this task, scan 'TODO character encoding' for - * relevant places. - */ - public static cxCodeSet negotiate(IOR.CodeSets_profile profile) - { - if (profile.negotiated != null) - return profile.negotiated; - - cxCodeSet use = new cxCodeSet(); - - use.char_data = - negotiate(profile.narrow, STANDARD.char_data, CharSets_OSF.ISO8859_1); - - use.wide_char_data = - negotiate(profile.wide, STANDARD.wide_char_data, CharSets_OSF.UTF16); - - profile.negotiated = use; - - return use; - } - - /** - * Read the context from the given stream. Does not read the - * code sets id. - */ - public void readContext(cdrInput input) - { - cdrInput encap = input.read_encapsulation(); - - char_data = encap.read_ulong(); - wide_char_data = encap.read_ulong(); - } - - /** - * Return a string representation. - */ - public String toString() - { - return " Encoding: narrow " + name(char_data) + ", wide " + - name(wide_char_data) + ". "; - } - - /** - * Write the context to the given stream, including the code - * sets id. - */ - public void write(cdrOutput output) - { - output.write_ulong(ID); - - cdrOutput enout = output.createEncapsulation(); - - enout.write_long(char_data); - enout.write_ulong(wide_char_data); - - try - { - enout.close(); - } - catch (IOException ex) - { - InternalError t = new InternalError(); - t.initCause(ex); - throw t; - } - } - - /** - * Negotiate about the character encoding. Prefer our native encoding, - * if no, prefer IORs native encoding, if no, find any encoding, - * supported by both sides, if no, return the specified final decission. - * - * @param profile the component profile in IOR. - * @param our_native our native encoding - * @param final_decission the encoding that must be returned if no - * compromise is found. - * - * @return the resulted encoding. - */ - protected static int negotiate(IOR.CodeSets_profile.CodeSet_component profile, - int our_native, int final_decission - ) - { - // If our and IORs native sets match, use the native set. - if (profile.native_set == our_native) - return our_native; - - // If the native sets do not match, but the IOR says it - // supports our native set, use our native set. - if (profile.conversion != null) - for (int i = 0; i < profile.conversion.length; i++) - { - if (our_native == profile.conversion [ i ]) - return our_native; - } - - // At this point, we suggest to use the IORs native set. - int[] allSupported = CharSets_OSF.getSupportedCharSets(); - - for (int s = 0; s < allSupported.length; s++) - if (allSupported [ s ] == profile.native_set) - return profile.native_set; - - // Any compromise left? - if (profile.conversion != null) - for (int s = 0; s < allSupported.length; s++) - for (int i = 0; i < profile.conversion.length; i++) - if (allSupported [ s ] == profile.conversion [ i ]) - return allSupported [ s ]; - - // Return the CORBA default char encoding. - return final_decission; - } - - /** - * Conveniency method, used in toString() - */ - private String name(int set) - { - return "0x" + Integer.toHexString(set) + " (" + CharSets_OSF.getName(set) + - ") "; - } -} diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java index 27181ca..c085c17 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java @@ -38,10 +38,10 @@ exception statement from your version. */ package gnu.CORBA.GIOP.v1_0; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; import gnu.CORBA.GIOP.ServiceContext; -import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.GIOP.CodeSetServiceContext; /** * The header of the standard reply. @@ -98,13 +98,13 @@ public class ReplyHeader * @param in a stream to read from. */ - public void read(cdrInput in) + public void read(AbstractCdrInput in) { service_context = ServiceContext.readSequence(in); request_id = in.read_ulong(); reply_status = in.read_ulong(); - in.setCodeSet(cxCodeSet.find(service_context)); + in.setCodeSet(CodeSetServiceContext.find(service_context)); } /** @@ -128,12 +128,12 @@ public class ReplyHeader * * @param out a stream to write into. */ - public void write(cdrOutput out) + public void write(AbstractCdrOutput out) { ServiceContext.writeSequence(out, service_context); out.write_ulong(request_id); out.write_ulong(reply_status); - out.setCodeSet(cxCodeSet.find(service_context)); + out.setCodeSet(CodeSetServiceContext.find(service_context)); } } diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java index 7ede4e5..5cf723c 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java @@ -38,10 +38,10 @@ exception statement from your version. */ package gnu.CORBA.GIOP.v1_0; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; import gnu.CORBA.GIOP.ServiceContext; -import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.GIOP.CodeSetServiceContext; import org.omg.CORBA.portable.IDLEntity; @@ -112,7 +112,7 @@ public class RequestHeader * * @param in a stream to read from. */ - public void read(cdrInput in) + public void read(AbstractCdrInput in) { service_context = ServiceContext.readSequence(in); request_id = in.read_ulong(); @@ -121,7 +121,7 @@ public class RequestHeader operation = in.read_string(); requesting_principal = in.read_sequence(); - in.setCodeSet(cxCodeSet.find(service_context)); + in.setCodeSet(CodeSetServiceContext.find(service_context)); } /** @@ -143,7 +143,7 @@ public class RequestHeader * * @param out a stream to write into. */ - public void write(cdrOutput out) + public void write(AbstractCdrOutput out) { ServiceContext.writeSequence(out, service_context); out.write_ulong(request_id); @@ -152,6 +152,6 @@ public class RequestHeader out.write_string(operation); out.write_sequence(requesting_principal); - out.setCodeSet(cxCodeSet.find(service_context)); + out.setCodeSet(CodeSetServiceContext.find(service_context)); } } diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java index c3f51a3..3fc1541 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java @@ -38,10 +38,10 @@ exception statement from your version. */ package gnu.CORBA.GIOP.v1_2; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; import gnu.CORBA.GIOP.ServiceContext; -import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.GIOP.CodeSetServiceContext; /** * GIOP 1.2 reply header. @@ -56,7 +56,7 @@ public class ReplyHeader */ public ReplyHeader() { - service_context = new ServiceContext[] { cxCodeSet.STANDARD }; + service_context = new ServiceContext[] { CodeSetServiceContext.STANDARD }; } /** @@ -89,13 +89,13 @@ public class ReplyHeader * * @param in a stream to read from. */ - public void read(cdrInput in) + public void read(AbstractCdrInput in) { request_id = in.read_ulong(); reply_status = in.read_ulong(); service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in); - in.setCodeSet(cxCodeSet.find(service_context)); + in.setCodeSet(CodeSetServiceContext.find(service_context)); } /** @@ -107,12 +107,12 @@ public class ReplyHeader * * @param out a stream to write into. */ - public void write(cdrOutput out) + public void write(AbstractCdrOutput out) { out.write_ulong(request_id); out.write_ulong(reply_status); gnu.CORBA.GIOP.ServiceContext.writeSequence(out, service_context); - out.setCodeSet(cxCodeSet.find(service_context)); + out.setCodeSet(CodeSetServiceContext.find(service_context)); } } diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java index d294d00..6b37b6c 100644 --- a/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java @@ -38,10 +38,11 @@ exception statement from your version. */ package gnu.CORBA.GIOP.v1_2; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.Minor; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.CDR.AbstractCdrOutput; import gnu.CORBA.GIOP.ServiceContext; -import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.GIOP.CodeSetServiceContext; import java.io.IOException; @@ -58,6 +59,11 @@ import org.omg.CORBA.NO_IMPLEMENT; public class RequestHeader extends gnu.CORBA.GIOP.v1_0.RequestHeader { + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + /** * Indicates that the object is addressed by the object key. */ @@ -89,7 +95,7 @@ public class RequestHeader */ public RequestHeader() { - service_context = new ServiceContext[] { cxCodeSet.STANDARD }; + service_context = new ServiceContext[] { CodeSetServiceContext.STANDARD }; } /** @@ -123,7 +129,7 @@ public class RequestHeader * * @param in a stream to read from. */ - public void read(cdrInput in) + public void read(AbstractCdrInput in) { try { @@ -150,20 +156,23 @@ public class RequestHeader throw new NO_IMPLEMENT("Object addressing by by IOR addressing info"); default : - throw new MARSHAL("Unknow addressing method in request, " + + MARSHAL m = new MARSHAL("Unknow addressing method in request, " + AddressingDisposition ); + m.minor = Minor.UnsupportedAddressing; + throw m; } operation = in.read_string(); service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in); // No requesting principal in this new format. - in.setCodeSet(cxCodeSet.find(service_context)); + in.setCodeSet(CodeSetServiceContext.find(service_context)); } catch (IOException ex) { MARSHAL t = new MARSHAL(); + t.minor = Minor.Header; t.initCause(ex); throw t; } @@ -186,7 +195,7 @@ public class RequestHeader * * @param out a stream to write into. */ - public void write(cdrOutput out) + public void write(AbstractCdrOutput out) { out.write_ulong(request_id); @@ -208,6 +217,6 @@ public class RequestHeader ServiceContext.writeSequence(out, service_context); // No requesting principal in this new format. - out.setCodeSet(cxCodeSet.find(service_context)); + out.setCodeSet(CodeSetServiceContext.find(service_context)); } } diff --git a/libjava/classpath/gnu/CORBA/GeneralHolder.java b/libjava/classpath/gnu/CORBA/GeneralHolder.java new file mode 100644 index 0000000..ffba69d --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GeneralHolder.java @@ -0,0 +1,178 @@ +/* universalStreamable.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; + +/** + * This class holds the abstract binary data array of the Streamable + * being stored. It is used to insert and extract into {@link Any} objects + * that have no holder, but have the helper classes. + * Encoding/decoding then must be performed by the helper. This class is + * defined as package private because it is not idiot proof and + * must be used with care. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class GeneralHolder + implements Streamable +{ + /** + * The binary data, stored inside this holder. + */ + private BufferedCdrOutput value = new BufferedCdrOutput(); + + /** + * Create the universal holder that uses the given buffer to store the data. + */ + public GeneralHolder(BufferedCdrOutput buffer) + { + value = buffer; + } + + /** + * Reads into the internal buffer till the end of stream is + * reached. No alignment operations are performed. This operation + * normally reads from the stream, where the single value, + * stored using {@link #_write}, is written. + * + * @throws MARSHALL, if the IOException is thrown during the + * stream operation. + */ + public void _read(InputStream input) + { + try + { + if (input instanceof BufferredCdrInput) + { + BufferredCdrInput b = (BufferredCdrInput) input; + value.write(b.buffer.getBuffer()); + } + else + { + int c; + + do + { + c = input.read(); + if (c >= 0) + value.write(c); + } + while (c >= 0); + } + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.minor = Minor.Any; + t.initCause(ex); + throw t; + } + } + + /** + * The type is not known and cannot be returned. + * + * @throws BAD_OPERATION, always. + */ + public TypeCode _type() + { + BAD_OPERATION bad = new BAD_OPERATION(); + bad.minor = Minor.Inappropriate; + throw bad; + } + + /** + * Writes the binary data being stored into the given output + * stream. This operation supposes that the current stream + * position is 0 or satisfies the required alignments anyway. + * + * @throws MARSHAL if the IOExeption is thrown when writing the + * byte array. + */ + public void _write(OutputStream output) + { + try + { + value.buffer.writeTo(output); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.minor = Minor.Any; + t.initCause(ex); + throw t; + } + } + + /** + * Get the input stream that reads the fields of the stored value. + */ + InputStream getInputStream() + { + return value.create_input_stream(); + } + + /** + * Clone. + */ + public GeneralHolder Clone() + { + try + { + BufferedCdrOutput nb = new BufferedCdrOutput(value.buffer.size()); + value.buffer.writeTo(nb); + return new GeneralHolder(nb); + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/HolderLocator.java b/libjava/classpath/gnu/CORBA/HolderLocator.java new file mode 100644 index 0000000..edd4d2c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/HolderLocator.java @@ -0,0 +1,184 @@ +/* HolderLocator.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.AnyHolder; +import org.omg.CORBA.AnySeqHolder; +import org.omg.CORBA.BooleanHolder; +import org.omg.CORBA.BooleanSeqHolder; +import org.omg.CORBA.CharHolder; +import org.omg.CORBA.CharSeqHolder; +import org.omg.CORBA.DoubleHolder; +import org.omg.CORBA.DoubleSeqHolder; +import org.omg.CORBA.FixedHolder; +import org.omg.CORBA.FloatHolder; +import org.omg.CORBA.FloatSeqHolder; +import org.omg.CORBA.IntHolder; +import org.omg.CORBA.LongHolder; +import org.omg.CORBA.LongLongSeqHolder; +import org.omg.CORBA.LongSeqHolder; +import org.omg.CORBA.OctetSeqHolder; +import org.omg.CORBA.PrincipalHolder; +import org.omg.CORBA.ShortHolder; +import org.omg.CORBA.ShortSeqHolder; +import org.omg.CORBA.StringHolder; +import org.omg.CORBA.StringSeqHolder; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodeHolder; +import org.omg.CORBA.ULongLongSeqHolder; +import org.omg.CORBA.ULongSeqHolder; +import org.omg.CORBA.UShortSeqHolder; +import org.omg.CORBA.WCharSeqHolder; +import org.omg.CORBA.WStringSeqHolder; +import org.omg.CORBA.portable.Streamable; +import org.omg.CORBA.ObjectHolder; + +/** + * Creates the suitable holder for storing the value of the given final_type. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class HolderLocator +{ + /** + * The array, sufficiently large to use any {@link TCKind}._tk* constant as + * an index. + */ + private static final Class[] holders; + + private static final Class[] seqHolders; + + static + { + holders = new Class[32]; + holders[TCKind._tk_Principal] = PrincipalHolder.class; + holders[TCKind._tk_TypeCode] = TypeCodeHolder.class; + holders[TCKind._tk_any] = AnyHolder.class; + holders[TCKind._tk_boolean] = BooleanHolder.class; + holders[TCKind._tk_char] = CharHolder.class; + holders[TCKind._tk_double] = DoubleHolder.class; + holders[TCKind._tk_float] = FloatHolder.class; + holders[TCKind._tk_fixed] = FixedHolder.class; + holders[TCKind._tk_long] = IntHolder.class; + holders[TCKind._tk_longdouble] = DoubleHolder.class; + holders[TCKind._tk_longlong] = LongHolder.class; + holders[TCKind._tk_octet] = OctetHolder.class; + holders[TCKind._tk_short] = ShortHolder.class; + holders[TCKind._tk_string] = StringHolder.class; + holders[TCKind._tk_ulong] = IntHolder.class; + holders[TCKind._tk_ulonglong] = LongHolder.class; + holders[TCKind._tk_ushort] = ShortHolder.class; + holders[TCKind._tk_wchar] = WCharHolder.class; + holders[TCKind._tk_wstring] = WStringHolder.class; + holders[TCKind._tk_objref] = ObjectHolder.class; + + seqHolders = new Class[32]; + + seqHolders[TCKind._tk_ulonglong] = ULongLongSeqHolder.class; + seqHolders[TCKind._tk_short] = ShortSeqHolder.class; + seqHolders[TCKind._tk_octet] = OctetSeqHolder.class; + seqHolders[TCKind._tk_any] = AnySeqHolder.class; + seqHolders[TCKind._tk_long] = LongSeqHolder.class; + seqHolders[TCKind._tk_longlong] = LongLongSeqHolder.class; + seqHolders[TCKind._tk_float] = FloatSeqHolder.class; + seqHolders[TCKind._tk_double] = DoubleSeqHolder.class; + seqHolders[TCKind._tk_char] = CharSeqHolder.class; + seqHolders[TCKind._tk_boolean] = BooleanSeqHolder.class; + seqHolders[TCKind._tk_wchar] = WCharSeqHolder.class; + seqHolders[TCKind._tk_ushort] = UShortSeqHolder.class; + seqHolders[TCKind._tk_ulong] = ULongSeqHolder.class; + seqHolders[TCKind._tk_string] = StringSeqHolder.class; + seqHolders[TCKind._tk_wstring] = WStringSeqHolder.class; + } + + /** + * Create a holder for storing the value of the given built-in final_type. This + * function returns the defined holders for the built-in primitive types and + * they sequences. + * + * @param t the typecode + * + * @return an instance of the corresponding built-in holder of null if no such + * is defined for this final_type. The holder is created with a parameterless + * constructor. + */ + public static Streamable createHolder(TypeCode t) + { + try + { + int kind = t.kind().value(); + int componentKind; + + Streamable holder = null; + + if (kind < holders.length && holders[kind] != null) + holder = (Streamable) holders[kind].newInstance(); + + if (holder != null) + return holder; + + switch (kind) + { + case TCKind._tk_sequence: + componentKind = t.content_type().kind().value(); + if (componentKind < seqHolders.length) + return (Streamable) seqHolders[componentKind].newInstance(); + break; + + default: + break; + } + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + + try + { + Object ox = ObjectCreator.createObject(t.id(), "Holder"); + return (Streamable) ox; + } + catch (Exception ex) + { + return null; + } + } +} diff --git a/libjava/classpath/gnu/CORBA/IOR.java b/libjava/classpath/gnu/CORBA/IOR.java index 02e94aa..5d6d315 100644 --- a/libjava/classpath/gnu/CORBA/IOR.java +++ b/libjava/classpath/gnu/CORBA/IOR.java @@ -38,12 +38,12 @@ exception statement from your version. */ package gnu.CORBA; -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; -import gnu.CORBA.CDR.cdrInput; -import gnu.CORBA.CDR.cdrOutput; +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.cxCodeSet; +import gnu.CORBA.GIOP.CodeSetServiceContext; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.CompletionStatus; @@ -59,6 +59,8 @@ 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 @@ -174,16 +176,16 @@ public class IOR * The negotiated coding result for this IOR. Saves time, requred for * negotiation computations. */ - public cxCodeSet negotiated; + public CodeSetServiceContext negotiated; /** * Read the code set profile information from the given input stream. * * @param profile a stream to read from. */ - public void read(cdrInput profile) + public void read(AbstractCdrInput profile) { - cdrBufInput encapsulation = profile.read_encapsulation(); + BufferredCdrInput encapsulation = profile.read_encapsulation(); narrow.read(encapsulation); wide.read(encapsulation); } @@ -201,9 +203,9 @@ public class IOR * * @param profile a stream to write into. */ - public void write(cdrOutput profile) + public void write(AbstractCdrOutput profile) { - cdrOutput encapsulation = profile.createEncapsulation(); + AbstractCdrOutput encapsulation = profile.createEncapsulation(); narrow.write(encapsulation); wide.write(encapsulation); try @@ -274,13 +276,13 @@ public class IOR /** * Write the internet profile (except the heading tag. */ - public void write(cdrOutput out) + public void write(AbstractCdrOutput out) { try { // Need to write the Internet profile into the separate // stream as we must know the size in advance. - cdrOutput b = out.createEncapsulation(); + AbstractCdrOutput b = out.createEncapsulation(); version.write(b); b.write_string(host); @@ -310,6 +312,7 @@ public class IOR catch (Exception e) { MARSHAL m = new MARSHAL("Unable to write Internet profile."); + m.minor = Minor.IOR; m.initCause(e); throw m; } @@ -392,7 +395,7 @@ public class IOR buf.write(cx); } - cdrBufInput cdr = new cdrBufInput(buf.toByteArray()); + BufferredCdrInput cdr = new BufferredCdrInput(buf.toByteArray()); r._read(cdr); return r; @@ -411,7 +414,7 @@ public class IOR * @param c a stream to read from. * @throws IOException if the stream throws it. */ - public void _read(cdrInput c) + public void _read(AbstractCdrInput c) throws IOException, BAD_PARAM { int endian; @@ -433,13 +436,13 @@ public class IOR * If the stream contains a null value, the Id and Internet fields become * equal to null. Otherwise Id contains some string (possibly empty). * - * Id is checked for null in cdrInput that then returns null instead of + * Id is checked for null in AbstractCdrInput that then returns null instead of * object. * * @param c a stream to read from. * @throws IOException if the stream throws it. */ - public void _read_no_endian(cdrInput c) + public void _read_no_endian(AbstractCdrInput c) throws IOException, BAD_PARAM { Id = c.read_string(); @@ -456,7 +459,7 @@ public class IOR for (int i = 0; i < n_profiles; i++) { int tag = c.read_long(); - cdrBufInput profile = c.read_encapsulation(); + BufferredCdrInput profile = c.read_encapsulation(); if (tag == Internet_profile.TAG_INTERNET_IOP) { @@ -515,7 +518,7 @@ public class IOR * Write this IOR record to the provided CDR stream. This procedure writes the * zero (Big Endian) marker first. */ - public void _write(cdrOutput out) + public void _write(AbstractCdrOutput out) { // Always use Big Endian. out.write(0); @@ -528,7 +531,7 @@ public class IOR * The null value is written as defined in OMG specification (zero length * string, followed by an empty set of profiles). */ - public static void write_null(cdrOutput out) + public static void write_null(AbstractCdrOutput out) { // Empty Id string. out.write_string(""); @@ -541,7 +544,7 @@ public class IOR * Write this IOR record to the provided CDR stream. The procedure writed data * in Big Endian, but does NOT add any endian marker to the beginning. */ - public void _write_no_endian(cdrOutput out) + public void _write_no_endian(AbstractCdrOutput out) { // Write repository id. out.write_string(Id); @@ -595,7 +598,7 @@ public class IOR */ public String toStringifiedReference() { - cdrBufOutput out = new cdrBufOutput(); + BufferedCdrOutput out = new BufferedCdrOutput(); _write(out); @@ -675,7 +678,7 @@ public class IOR TaggedComponent[] present; if (profile.profile_data.length > 0) { - cdrBufInput in = new cdrBufInput(profile.profile_data); + BufferredCdrInput in = new BufferredCdrInput(profile.profile_data); present = new TaggedComponent[in.read_long()]; @@ -687,7 +690,7 @@ public class IOR else present = new TaggedComponent[0]; - cdrBufOutput out = new cdrBufOutput(profile.profile_data.length + BufferedCdrOutput out = new BufferedCdrOutput(profile.profile_data.length + component.component_data.length + 8); @@ -715,4 +718,51 @@ public class IOR // The future supported tagged profiles should be added here. throw new BAD_PARAM("Unsupported profile type " + profile.tag); } + + /** + * Checks for equality. + */ + public boolean equals(Object x) + { + if (x instanceof IOR) + { + boolean keys; + boolean hosts = true; + + IOR other = (IOR) x; + + if (Internet==null || other.Internet==null) + return Internet == other.Internet; + + if (key != null && other.key != null) + keys = Arrays.equals(key, other.key); + else + keys = key == other.key; + + if (Internet != null && Internet.host != null) + if (other.Internet != null && other.Internet.host != null) + hosts = other.Internet.host.equals(Internet.host); + + return keys & hosts && Internet.port==other.Internet.port; + } + else + return false; + } + + /** + * Get the hashcode of this IOR. + */ + public int hashCode() + { + Adler32 adler = new Adler32(); + if (key != null) + adler.update(key); + if (Internet != null) + { + if (Internet.host != null) + adler.update(Internet.host.getBytes()); + adler.update(Internet.port); + } + return (int) adler.getValue(); + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IOR_Delegate.java b/libjava/classpath/gnu/CORBA/IOR_Delegate.java deleted file mode 100644 index 3b64eb5..0000000 --- a/libjava/classpath/gnu/CORBA/IOR_Delegate.java +++ /dev/null @@ -1,466 +0,0 @@ -/* gnuDelegate.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.GIOP.ReplyHeader; -import gnu.CORBA.Poa.activeObjectMap; - -import org.omg.CORBA.CompletionStatus; -import org.omg.CORBA.Context; -import org.omg.CORBA.ContextList; -import org.omg.CORBA.ExceptionList; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.NVList; -import org.omg.CORBA.NamedValue; -import org.omg.CORBA.ORB; -import org.omg.CORBA.Request; -import org.omg.CORBA.portable.ApplicationException; -import org.omg.CORBA.portable.InputStream; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.RemarshalException; -import org.omg.PortableInterceptor.ForwardRequest; - -import java.io.IOException; - -import java.net.Socket; - -/** - * The Classpath implementation of the {@link Delegate} functionality in the - * case, when the object was constructed from an IOR object. The IOR can be - * constructed from the stringified object reference. - * - * There is an different instance of this delegate for each CORBA object. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class IOR_Delegate extends Simple_delegate -{ - /** - * True if the current IOR does not map into the local servant. If false, the - * IOR is either local or should be checked. - */ - boolean remote_ior; - - /** - * If not null, this field contains data about the local servant. - */ - activeObjectMap.Obj local_ior; - - /** - * Contructs an instance of object using the given IOR. - */ - public IOR_Delegate(ORB an_orb, IOR an_ior) - { - super(an_orb, an_ior); - } - - /** - * Creates the request to invoke the method on this object. - * - * @param target the object, for that the operation must be invoked. - * @param context context (null allowed) - * @param operation the method name - * @param parameters the method parameters - * @param returns the return value holder - * @param exceptions the exceptions that can be thrown by the method - * @param ctx_list the context list (null allowed) - * - * @return the created request. - */ - public Request create_request(org.omg.CORBA.Object target, Context context, - String operation, NVList parameters, NamedValue returns - ) - { - gnuRequest request = getRequestInstance(target); - - request.setIor(getIor()); - request.set_target(target); - - request.setOperation(operation); - request.set_args(parameters); - request.m_context = context; - request.set_result(returns); - request.setORB(orb); - - return request; - } - - /** - * Creates the request to invoke the method on this object. - * - * @param target the object, for that the operation must be invoked. - * @param context context (null allowed) - * @param operation the method name - * @param parameters the method parameters - * @param returns the return value holder - * - * @return the created request. - */ - public Request create_request(org.omg.CORBA.Object target, Context context, - String operation, NVList parameters, NamedValue returns, - ExceptionList exceptions, ContextList ctx_list - ) - { - gnuRequest request = getRequestInstance(target); - - request.setIor(ior); - request.set_target(target); - - request.setOperation(operation); - request.set_args(parameters); - request.m_context = context; - request.set_result(returns); - request.set_exceptions(exceptions); - request.set_context_list(ctx_list); - request.setORB(orb); - - return request; - } - - /** - * Get the instance of request. - */ - protected gnuRequest getRequestInstance(org.omg.CORBA.Object target) - { - return new gnuRequest(); - } - - /** - * Invoke operation on the given object, als handling temproray and permanent - * redirections. The ReplyHeader.LOCATION_FORWARD will cause to resend the - * request to the new direction. The ReplyHeader.LOCATION_FORWARD_PERM will - * cause additionally to remember the new location by this delegate, so - * subsequent calls will be immediately delivered to the new target. - * - * @param target the target object. - * @param output the output stream, previously returned by - * {@link #request(org.omg.CORBA.Object, String, boolean)}. - * - * @return the input stream, to read the response from or null for a one-way - * request. - * - * @throws SystemException if the SystemException has been thrown on the - * remote side (the exact type and the minor code matches the data of the - * remote exception that has been thrown). - * - * @throws org.omg.CORBA.portable.ApplicationException as specified. - * @throws org.omg.CORBA.portable.RemarshalException as specified. - */ - public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) - throws ApplicationException, RemarshalException - { - streamRequest request = (streamRequest) output; - Forwardings: - while (true) - { - try - { - if (request.response_expected) - { - binaryReply response = request.request.submit(); - - // Read reply header. - ReplyHeader rh = response.header.create_reply_header(); - cdrBufInput input = response.getStream(); - input.setOrb(orb); - rh.read(input); - request.request.m_rph = rh; - - boolean moved_permanently = false; - - switch (rh.reply_status) - { - case ReplyHeader.NO_EXCEPTION : - if (request.request.m_interceptor != null) - request.request.m_interceptor. - receive_reply(request.request.m_info); - if (response.header.version.since_inclusive(1, 2)) - input.align(8); - return input; - - case ReplyHeader.SYSTEM_EXCEPTION : - if (response.header.version.since_inclusive(1, 2)) - input.align(8); - showException(request, input); - - throw ObjectCreator.readSystemException(input); - - case ReplyHeader.USER_EXCEPTION : - if (response.header.version.since_inclusive(1, 2)) - input.align(8); - showException(request, input); - - throw new ApplicationException(request. - request.m_exception_id, input - ); - - case ReplyHeader.LOCATION_FORWARD_PERM : - moved_permanently = true; - - case ReplyHeader.LOCATION_FORWARD : - if (response.header.version.since_inclusive(1, 2)) - input.align(8); - - IOR forwarded = new IOR(); - try - { - forwarded._read_no_endian(input); - } - catch (IOException ex) - { - MARSHAL t = - new MARSHAL("Cant read forwarding info", 5102, - CompletionStatus.COMPLETED_NO - ); - t.initCause(ex); - throw t; - } - - gnuRequest prev = request.request; - gnuRequest r = getRequestInstance(target); - - r.m_interceptor = prev.m_interceptor; - r.m_slots = prev.m_slots; - - r.m_args = prev.m_args; - r.m_context = prev.m_context; - r.m_context_list = prev.m_context_list; - r.m_environment = prev.m_environment; - r.m_exceptions = prev.m_exceptions; - r.m_operation = prev.m_operation; - r.m_parameter_buffer = prev.m_parameter_buffer; - r.m_parameter_buffer.request = r; - r.m_result = prev.m_result; - r.m_target = prev.m_target; - r.oneWay = prev.oneWay; - r.m_forward_ior = forwarded; - - if (r.m_interceptor != null) - r.m_interceptor.receive_other(r.m_info); - - r.setIor(forwarded); - - IOR_contructed_object it = - new IOR_contructed_object(orb, forwarded); - - r.m_target = it; - - request.request = r; - - IOR prev_ior = getIor(); - - setIor(forwarded); - - try - { - return invoke(it, request); - } - finally - { - if (!moved_permanently) - setIor(prev_ior); - } - - default : - throw new MARSHAL("Unknow reply status: " + - rh.reply_status, 8000 + rh.reply_status, - CompletionStatus.COMPLETED_NO - ); - } - } - else - { - request.request.send_oneway(); - return null; - } - } - catch (ForwardRequest forwarded) - { - ForwardRequest fw = forwarded; - Forwarding2: - while (true) - { - try - { - gnuRequest prev = request.request; - gnuRequest r = getRequestInstance(target); - - r.m_interceptor = prev.m_interceptor; - r.m_args = prev.m_args; - r.m_context = prev.m_context; - r.m_context_list = prev.m_context_list; - r.m_environment = prev.m_environment; - r.m_exceptions = prev.m_exceptions; - r.m_operation = prev.m_operation; - r.m_parameter_buffer = prev.m_parameter_buffer; - r.m_parameter_buffer.request = r; - r.m_result = prev.m_result; - r.m_target = prev.m_target; - r.oneWay = prev.oneWay; - - r.m_forwarding_target = fw.forward; - - if (r.m_interceptor != null) - r.m_interceptor.receive_other(r.m_info); - - r.m_target = fw.forward; - request.request = r; - break Forwarding2; - } - catch (ForwardRequest e) - { - forwarded = e; - } - } - } - } - } - - /** - * Show exception to interceptor. - */ - void showException(streamRequest request, cdrBufInput input) - throws ForwardRequest - { - input.mark(2048); - request.request.m_exception_id = input.read_string(); - input.reset(); - - if (request.request.m_interceptor != null) - request.request.m_interceptor.receive_exception(request.request.m_info); - } - - /** - * Create a request to invoke the method of this CORBA object. - * - * @param target the CORBA object, to that this operation must be applied. - * @param operation the name of the method to invoke. - * - * @return the request. - */ - public Request request(org.omg.CORBA.Object target, String operation) - { - gnuRequest request = getRequestInstance(target); - - request.setIor(ior); - request.set_target(target); - - request.setOperation(operation); - request.setORB(orb); - - return request; - } - - /** - * Create a request to invoke the method of this CORBA object. - * - * @param target the CORBA object, to that this operation must be applied. - * @param operation the name of the method to invoke. - * @param response_expected specifies if this is one way message or the - * response to the message is expected. - * - * @return the stream where the method arguments should be written. - */ - public OutputStream request(org.omg.CORBA.Object target, String operation, - boolean response_expected - ) - { - gnuRequest request = getRequestInstance(target); - - request.setIor(ior); - request.set_target(target); - request.setOperation(operation); - - streamRequest out = request.getParameterStream(); - out.response_expected = response_expected; - request.setORB(orb); - - return out; - } - - /** - * If there is an opened cache socket to access this object, close that - * socket. - * - * @param target The target is not used, this delegate requires a single - * instance per object. - */ - public void release(org.omg.CORBA.Object target) - { - String key = ior.Internet.host + ":" + ior.Internet.port; - - Socket socket = SocketRepository.get_socket(key); - try - { - if (socket != null) - { - socket.close(); - } - } - catch (IOException ex) - { - // do nothing, then. - } - } - - /** - * Reset the remote_ior flag, forcing to check if the object is local on the - * next getRequestInstance call. - */ - public void setIor(IOR an_ior) - { - super.setIor(an_ior); - remote_ior = false; - local_ior = null; - } - - /** - * Checks if the ior is local so far it is easy. - */ - public boolean is_local(org.omg.CORBA.Object self) - { - if (remote_ior) - return false; - else if (local_ior != null) - return true; - else - return super.is_local(self); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IOR_contructed_object.java b/libjava/classpath/gnu/CORBA/IOR_contructed_object.java deleted file mode 100644 index 2fab707..0000000 --- a/libjava/classpath/gnu/CORBA/IOR_contructed_object.java +++ /dev/null @@ -1,109 +0,0 @@ -/* IOR_contructed_object.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.ORB; -import org.omg.CORBA.portable.ObjectImpl; - -/** - * Implements an object, constructed from an IOR reference. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class IOR_contructed_object - extends ObjectImpl -{ - /** - * The IOR, from which the object was constructed. - */ - protected final IOR ior; - - /** - * The object id, as defined in IOR. - */ - protected final String[] id; - - /** - * Create the object from the given IOR. - * - * @param an_ior the IOR. - */ - public IOR_contructed_object(ORB orb, IOR an_ior) - { - ior = an_ior; - _set_delegate(new IOR_Delegate(orb, ior)); - id = new String[] { ior.Id }; - } - - /** - * Create the object from the given string IOR representation. - * - * @param an_ior the IOR in the string form. - */ - public IOR_contructed_object(Functional_ORB orb, String an_ior) - { - ior = IOR.parse(an_ior); - _set_delegate(new IOR_Delegate(orb, ior)); - id = new String[] { ior.Id }; - } - - public String[] _ids() - { - return id; - } - - /** - * Get a string reference for this object. - * - * @return the class name:IOR profile - */ - public String toString() - { - return getClass().getName() + ":IOR:" + ior; - } - - /** - * Calls realease on the delegate. - */ - protected void finalize() - throws java.lang.Throwable - { - _get_delegate().release(this); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java b/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java index 8875698..2b77de5 100644 --- a/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java +++ b/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java @@ -38,16 +38,20 @@ exception statement from your version. */ package gnu.CORBA.Interceptor; +import org.omg.CORBA.OBJ_ADAPTER; +import org.omg.CORBA.OMGVMCID; import org.omg.PortableInterceptor.IORInfo; import org.omg.PortableInterceptor.IORInterceptor; import org.omg.PortableInterceptor.IORInterceptorOperations; +import org.omg.PortableInterceptor.IORInterceptor_3_0Operations; +import org.omg.PortableInterceptor.ObjectReferenceTemplate; /** * A block of the all registered IOR interceptors. * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class IORInterceptors implements IORInterceptorOperations +public class IORInterceptors implements IORInterceptor_3_0Operations { /** * The array of all registered IOR interceptors. @@ -106,4 +110,81 @@ public class IORInterceptors implements IORInterceptorOperations { return getClass().getName(); } + + /** + * Call this method for all registered CORBA 3.0 interceptors. + */ + public void adapter_manager_state_changed(int adapterManagerId, short adapterState) + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + if (interceptors[i] instanceof IORInterceptor_3_0Operations) + { + ((IORInterceptor_3_0Operations) interceptors[i]). + adapter_manager_state_changed(adapterManagerId, adapterState); + } + } + catch (Exception exc) + { + OBJ_ADAPTER oa = new OBJ_ADAPTER("components_established failed"); + oa.initCause(exc); + oa.minor = 6 | OMGVMCID.value; + throw oa; + } + } + } + + /** + * Call this method for all registered CORBA 3.0 interceptors. + */ + public void adapter_state_changed(ObjectReferenceTemplate[] adapters, short adaptersState) + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + if (interceptors[i] instanceof IORInterceptor_3_0Operations) + { + ((IORInterceptor_3_0Operations) interceptors[i]). + adapter_state_changed(adapters, adaptersState); + } + } + catch (Exception exc) + { + OBJ_ADAPTER oa = new OBJ_ADAPTER("components_established failed"); + oa.initCause(exc); + oa.minor = 6 | OMGVMCID.value; + throw oa; + } + } + } + + /** + * Call this method for all registered CORBA 3.0 interceptors. + * + * @throws OBJ_ADAPTER minor 6 on any failure (as defined by OMG specs). + */ + public void components_established(IORInfo info) + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + if (interceptors[i] instanceof IORInterceptor_3_0Operations) + { + ((IORInterceptor_3_0Operations) interceptors[i]). + components_established(info); + } + } + catch (Exception exc) + { + OBJ_ADAPTER oa = new OBJ_ADAPTER("components_established failed"); + oa.initCause(exc); + oa.minor = 6 | OMGVMCID.value; + throw oa; + } + } + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java b/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java index ff35cd0..4bb895b 100644 --- a/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java +++ b/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java @@ -39,6 +39,7 @@ exception statement from your version. */ package gnu.CORBA.Interceptor; import gnu.CORBA.Poa.ORB_1_4; +import gnu.CORBA.ObjectCreator; import gnu.CORBA.gnuCodecFactory; import org.omg.CORBA.BAD_INV_ORDER; @@ -87,7 +88,7 @@ public class Registrator extends LocalObject implements ORBInitInfo /** * The agreed properties prefix. */ - public final static String m_prefix = + public static final String m_prefix = "org.omg.PortableInterceptor.ORBInitializerClass."; /** @@ -182,7 +183,8 @@ public class Registrator extends LocalObject implements ORBInitInfo try { String cn = sk.substring(m_prefix.length()); - Class iClass = Class.forName(cn); + Class iClass = ObjectCreator.forName(cn); + ORBInitializer initializer = (ORBInitializer) iClass.newInstance(); m_initializers.add(initializer); @@ -467,4 +469,4 @@ public class Registrator extends LocalObject implements ORBInitInfo { return m_ior.size() > 0; } -} +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java index ee8af7f..a33afc3 100644 --- a/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java @@ -38,7 +38,7 @@ exception statement from your version. */ package gnu.CORBA.Interceptor; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.BufferedCdrOutput; import gnu.CORBA.Poa.ORB_1_4; import org.omg.CORBA.Any; @@ -198,7 +198,7 @@ public class gnuIcCurrent extends ObjectImpl implements Current Any[] r = get_slots(); Any[] copy = new Any[ r.length ]; - cdrBufOutput buf = new cdrBufOutput(); + BufferedCdrOutput buf = new BufferedCdrOutput(); buf.setOrb(orb); for (int i = 0; i < copy.length; i++) diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java index 1c406cb..256a28c 100644 --- a/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java @@ -40,12 +40,14 @@ package gnu.CORBA.Interceptor; import gnu.CORBA.IOR; import gnu.CORBA.Poa.ORB_1_4; +import gnu.CORBA.Poa.gnuPOA; import org.omg.CORBA.LocalObject; import org.omg.CORBA.Policy; import org.omg.IOP.TaggedComponent; import org.omg.PortableInterceptor.IORInfo; -import org.omg.PortableServer.POA; +import org.omg.PortableInterceptor.ObjectReferenceFactory; +import org.omg.PortableInterceptor.ObjectReferenceTemplate; /** * Implements IORInfo. @@ -67,7 +69,7 @@ public class gnuIorInfo extends LocalObject implements IORInfo /** * The POA, to that IOR is related. */ - public final POA poa; + public final gnuPOA poa; /** * The IOR itself. @@ -77,7 +79,7 @@ public class gnuIorInfo extends LocalObject implements IORInfo /** * Create an instance. */ - public gnuIorInfo(ORB_1_4 an_orb, POA a_poa, IOR an_ior) + public gnuIorInfo(ORB_1_4 an_orb, gnuPOA a_poa, IOR an_ior) { orb = an_orb; poa = a_poa; @@ -113,8 +115,42 @@ public class gnuIorInfo extends LocalObject implements IORInfo /** * Return the state of the object POA. */ - short state() + public short state() { return (short) poa.the_POAManager().get_state().value(); } + + /** + * Get the adapter template, associated with this poa. + */ + public ObjectReferenceTemplate adapter_template() + { + return poa.getReferenceTemplate(); + } + + /** + * Get the object factory of the current POA. + */ + public ObjectReferenceFactory current_factory() + { + return poa.getReferenceFactory(); + } + + /** + * Set the object factory of the current POA. + */ + public void current_factory(ObjectReferenceFactory factory) + { + poa.setReferenceFactory(factory); + } + + /** + * The method currently uses system identity hashcode that should be + * different for each object. + */ + public int manager_id() + { + // The System.identityHashCode is also called in gnuPoaManager. + return System.identityHashCode(poa.the_POAManager()); + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java index 5f75f76..8d5c681 100644 --- a/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java @@ -42,6 +42,7 @@ import gnu.CORBA.GIOP.ReplyHeader; import gnu.CORBA.GIOP.RequestHeader; import gnu.CORBA.ObjectCreator; import gnu.CORBA.Poa.gnuServantObject; +import gnu.CORBA.OrbFunctional; import gnu.CORBA.Unexpected; import gnu.CORBA.gnuRequest; @@ -453,4 +454,23 @@ public class gnuServerRequestInfo extends LocalObject } return p; } + + /** @inheritDoc */ + public String[] adapter_name() + { + return m_object.poa.getReferenceTemplate().adapter_name(); + } + + /** @inheritDoc */ + public String orb_id() + { + return m_object.orb.orb_id; + } + + /** @inheritDoc */ + public String server_id() + { + return OrbFunctional.server_id; + } + } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IorDelegate.java b/libjava/classpath/gnu/CORBA/IorDelegate.java new file mode 100644 index 0000000..27fb5de --- /dev/null +++ b/libjava/classpath/gnu/CORBA/IorDelegate.java @@ -0,0 +1,442 @@ +/* gnuDelegate.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.GIOP.ReplyHeader; + +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.PortableInterceptor.ForwardRequest; + +import java.io.IOException; + +import java.net.Socket; + +/** + * The Classpath implementation of the {@link Delegate} functionality in the + * case, when the object was constructed from an IOR object. The IOR can be + * constructed from the stringified object reference. + * + * There is an different instance of this delegate for each CORBA object. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class IorDelegate extends SimpleDelegate +{ + /** + * Contructs an instance of object using the given IOR. + */ + public IorDelegate(ORB an_orb, IOR an_ior) + { + super(an_orb, an_ior); + } + + /** + * Creates the request to invoke the method on this object. + * + * @param target the object, for that the operation must be invoked. + * @param context context (null allowed) + * @param operation the method name + * @param parameters the method parameters + * @param returns the return value holder + * @param exceptions the exceptions that can be thrown by the method + * @param ctx_list the context list (null allowed) + * + * @return the created request. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, NamedValue returns + ) + { + gnuRequest request = getRequestInstance(target); + + request.setIor(getIor()); + request.set_target(target); + + request.setOperation(operation); + request.set_args(parameters); + request.m_context = context; + request.set_result(returns); + request.setORB(orb); + + return request; + } + + /** + * Creates the request to invoke the method on this object. + * + * @param target the object, for that the operation must be invoked. + * @param context context (null allowed) + * @param operation the method name + * @param parameters the method parameters + * @param returns the return value holder + * + * @return the created request. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, NamedValue returns, + ExceptionList exceptions, ContextList ctx_list + ) + { + gnuRequest request = getRequestInstance(target); + + request.setIor(ior); + request.set_target(target); + + request.setOperation(operation); + request.set_args(parameters); + request.m_context = context; + request.set_result(returns); + request.set_exceptions(exceptions); + request.set_context_list(ctx_list); + request.setORB(orb); + + return request; + } + + /** + * Get the instance of request. + */ + protected gnuRequest getRequestInstance(org.omg.CORBA.Object target) + { + return new gnuRequest(); + } + + /** + * Invoke operation on the given object, als handling temproray and permanent + * redirections. The ReplyHeader.LOCATION_FORWARD will cause to resend the + * request to the new direction. The ReplyHeader.LOCATION_FORWARD_PERM will + * cause additionally to remember the new location by this delegate, so + * subsequent calls will be immediately delivered to the new target. + * + * @param target the target object. + * @param output the output stream, previously returned by + * {@link #request(org.omg.CORBA.Object, String, boolean)}. + * + * @return the input stream, to read the response from or null for a one-way + * request. + * + * @throws SystemException if the SystemException has been thrown on the + * remote side (the exact type and the minor code matches the data of the + * remote exception that has been thrown). + * + * @throws org.omg.CORBA.portable.ApplicationException as specified. + * @throws org.omg.CORBA.portable.RemarshalException as specified. + */ + public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) + throws ApplicationException, RemarshalException + { + StreamBasedRequest request = (StreamBasedRequest) output; + Forwardings: while (true) + { + try + { + if (request.response_expected) + { + RawReply response = request.request.submit(); + + // Read reply header. + ReplyHeader rh = response.header.create_reply_header(); + BufferredCdrInput input = response.getStream(); + input.setOrb(orb); + rh.read(input); + request.request.m_rph = rh; + + boolean moved_permanently = false; + + switch (rh.reply_status) + { + case ReplyHeader.NO_EXCEPTION: + if (request.request.m_interceptor != null) + request.request.m_interceptor.receive_reply(request.request.m_info); + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + return input; + + case ReplyHeader.SYSTEM_EXCEPTION: + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + showException(request, input); + + throw ObjectCreator.readSystemException(input, + rh.service_context); + + case ReplyHeader.USER_EXCEPTION: + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + showException(request, input); + + throw new ApplicationException( + request.request.m_exception_id, input); + + case ReplyHeader.LOCATION_FORWARD_PERM: + moved_permanently = true; + + case ReplyHeader.LOCATION_FORWARD: + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + + IOR forwarded = new IOR(); + try + { + forwarded._read_no_endian(input); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL("Cant read forwarding info", + 5102, CompletionStatus.COMPLETED_NO); + t.initCause(ex); + throw t; + } + + gnuRequest prev = request.request; + gnuRequest r = getRequestInstance(target); + + r.m_interceptor = prev.m_interceptor; + r.m_slots = prev.m_slots; + + r.m_args = prev.m_args; + r.m_context = prev.m_context; + r.m_context_list = prev.m_context_list; + r.m_environment = prev.m_environment; + r.m_exceptions = prev.m_exceptions; + r.m_operation = prev.m_operation; + r.m_parameter_buffer = prev.m_parameter_buffer; + r.m_parameter_buffer.request = r; + r.m_result = prev.m_result; + r.m_target = prev.m_target; + r.oneWay = prev.oneWay; + r.m_forward_ior = forwarded; + + if (r.m_interceptor != null) + r.m_interceptor.receive_other(r.m_info); + + r.setIor(forwarded); + + IorObject it = new IorObject(orb, + forwarded); + + r.m_target = it; + + request.request = r; + + IOR prev_ior = getIor(); + + setIor(forwarded); + + try + { + return invoke(it, request); + } + finally + { + if (!moved_permanently) + setIor(prev_ior); + } + + default: + throw new MARSHAL("Unknow reply status: " + + rh.reply_status, 8000 + rh.reply_status, + CompletionStatus.COMPLETED_NO); + } + } + else + { + request.request.send_oneway(); + return null; + } + } + catch (ForwardRequest forwarded) + { + ForwardRequest fw = forwarded; + Forwarding2: while (true) + { + try + { + gnuRequest prev = request.request; + gnuRequest r = getRequestInstance(target); + + r.m_interceptor = prev.m_interceptor; + r.m_args = prev.m_args; + r.m_context = prev.m_context; + r.m_context_list = prev.m_context_list; + r.m_environment = prev.m_environment; + r.m_exceptions = prev.m_exceptions; + r.m_operation = prev.m_operation; + r.m_parameter_buffer = prev.m_parameter_buffer; + r.m_parameter_buffer.request = r; + r.m_result = prev.m_result; + r.m_target = prev.m_target; + r.oneWay = prev.oneWay; + + r.m_forwarding_target = fw.forward; + + if (r.m_interceptor != null) + r.m_interceptor.receive_other(r.m_info); + + r.m_target = fw.forward; + request.request = r; + break Forwarding2; + } + catch (ForwardRequest e) + { + forwarded = e; + } + } + } + } + } + + /** + * Show exception to interceptor. + */ + void showException(StreamBasedRequest request, BufferredCdrInput input) + throws ForwardRequest + { + input.mark(2048); + request.request.m_exception_id = input.read_string(); + input.reset(); + + if (request.request.m_interceptor != null) + request.request.m_interceptor.receive_exception(request.request.m_info); + } + + /** + * Create a request to invoke the method of this CORBA object. + * + * @param target the CORBA object, to that this operation must be applied. + * @param operation the name of the method to invoke. + * + * @return the request. + */ + public Request request(org.omg.CORBA.Object target, String operation) + { + gnuRequest request = getRequestInstance(target); + + request.setIor(ior); + request.set_target(target); + + request.setOperation(operation); + request.setORB(orb); + + return request; + } + + /** + * Create a request to invoke the method of this CORBA object. + * + * @param target the CORBA object, to that this operation must be applied. + * @param operation the name of the method to invoke. + * @param response_expected specifies if this is one way message or the + * response to the message is expected. + * + * @return the stream where the method arguments should be written. + */ + public OutputStream request(org.omg.CORBA.Object target, String operation, + boolean response_expected + ) + { + gnuRequest request = getRequestInstance(target); + + request.setIor(ior); + request.set_target(target); + request.setOperation(operation); + + StreamBasedRequest out = request.getParameterStream(); + out.response_expected = response_expected; + request.setORB(orb); + out.setOrb(orb); + + return out; + } + + /** + * If there is an opened cache socket to access this object, close that + * socket. + * + * @param target The target is not used, this delegate requires a single + * instance per object. + */ + public void release(org.omg.CORBA.Object target) + { + String key = ior.Internet.host + ":" + ior.Internet.port; + + Socket socket = SocketRepository.get_socket(key); + try + { + if (socket != null) + { + socket.close(); + } + } + catch (IOException ex) + { + // do nothing, then. + } + } + + /** + * Reset the remote_ior flag, forcing to check if the object is local on the + * next getRequestInstance call. + */ + public void setIor(IOR an_ior) + { + super.setIor(an_ior); + } + + /** + * Checks if the ior is local so far it is easy. + */ + public boolean is_local(org.omg.CORBA.Object self) + { + return false; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IorObject.java b/libjava/classpath/gnu/CORBA/IorObject.java new file mode 100644 index 0000000..02f5a49 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/IorObject.java @@ -0,0 +1,118 @@ +/* IorObject.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * Implements an object, constructed from an IOR reference. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class IorObject + extends ObjectImpl + implements IorProvider +{ + /** + * The IOR, from which the object was constructed. + */ + protected final IOR ior; + + /** + * The object id, as defined in IOR. + */ + protected final String[] id; + + /** + * Create the object from the given IOR. + * + * @param an_ior the IOR. + */ + public IorObject(ORB orb, IOR an_ior) + { + ior = an_ior; + _set_delegate(new IorDelegate(orb, ior)); + id = new String[] { ior.Id }; + } + + /** + * Create the object from the given string IOR representation. + * + * @param an_ior the IOR in the string form. + */ + public IorObject(OrbFunctional orb, String an_ior) + { + ior = IOR.parse(an_ior); + _set_delegate(new IorDelegate(orb, ior)); + id = new String[] { ior.Id }; + } + + /** + * Get the IOR of this object. + */ + public IOR getIor() + { + return ior; + } + + public String[] _ids() + { + return id; + } + + /** + * Get a string reference for this object. + * + * @return the class name:IOR profile + */ + public String toString() + { + return getClass().getName() + ":IOR:" + ior; + } + + /** + * Calls realease on the delegate. + */ + protected void finalize() + throws java.lang.Throwable + { + _get_delegate().release(this); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IorProvider.java b/libjava/classpath/gnu/CORBA/IorProvider.java new file mode 100644 index 0000000..875b5de --- /dev/null +++ b/libjava/classpath/gnu/CORBA/IorProvider.java @@ -0,0 +1,52 @@ +/* IorProvider.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.CORBA; + +/** + * Marks the possibility of the implementing object to return the associated + * IOR. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface IorProvider +{ + /** + * Get the IOR of the associated object. + */ + IOR getIor(); +} diff --git a/libjava/classpath/gnu/CORBA/Minor.java b/libjava/classpath/gnu/CORBA/Minor.java new file mode 100644 index 0000000..511a34d --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Minor.java @@ -0,0 +1,282 @@ +/* Minor.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 modify + it under the terms of the GNU General Public License as published by + the 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, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.CORBA; + + +/** + * Provides information and operations, related to about the 20 bit vendor minor + * code Id. This code is included into all CORBA system exceptions and is also + * transferred to remote side. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface Minor +{ + // Note: MARSHAL done. + + /* MARSHAL */ + + /** + * The GNU Classpath VMCID. The last 12 bits can be used to mark up to 4096 + * possible exceptions. + */ + int vendor = 0x47430000; + + /* + * Minor codes form MARSHAL exception. + */ + + /** + * The message being received is not a GIOP message. It does not start from + * the expected magic sequence byte[] { 'G', 'I', 'O', 'P' }. + */ + int Giop = 1 | vendor; + + /** + * The unexpected IOException while reading or writing the GIOP message header + * or the subsequent request or response header + */ + int Header = 2 | vendor; + + /** + * The data stream ended before reading all expected values from it. This + * usually means that the CORBA message is corrupted, but may also indicate + * that the server expects the remote method being invoked to have more or + * different parameters. + */ + int EOF = 3 | vendor; + + /** + * The unexpected IOException while reading or writing the data via Commond + * Data Representation stream. + */ + int CDR = 5 | vendor; + + /** + * The unexpected IOException while reading or writing the Value type. + */ + int Value = 6 | vendor; + + /** + * The unexpected IOException while handling request forwarding. + */ + int Forwarding = 7 | vendor; + + /** + * The unexpected IOException while handling data encapsulation, tagged + * components, tagged profiles, etc. + */ + int Encapsulation = 8 | vendor; + + /** + * The unexpected IOException while inserting or extracting data to/from the + * Any or DynamicAny. + */ + int Any = 9 | vendor; + + /** + * The unexpected UserException in the context where it cannot be handled and + * must be converted to the SystemException. + */ + int UserException = 10 | vendor; + + /** + * While the operation could formally be applied to the target, the OMG + * standard states that it is actually not applicable. For example, some CORBA + * objects like POA are always local and should not be passed to or returned + * from the remote side. + */ + int Inappropriate = 11 | vendor; + + /** + * When reading data, it was discovered that size of the data structure like + * string, sequence or character is written as the negative number. + */ + int Negative = 12 | vendor; + + /** + * Reference to non-existing node in the data grapth while reading the value + * types. + */ + int Graph = 14 | vendor; + + /** + * Unexpected exception was thrown from the IDL type helper while handling the + * object of this type as a boxed value. + */ + int Boxed = 15 | vendor; + + /** + * Unable to instantiate an value type object while reading it from the + * stream. + */ + int Instantiation = 16 | vendor; + + /** + * The header tag of the value type being read from the CDR stream contains an + * unexpected value outside 0x7fffff00 .. 0x7fffffff and also not null and not + * an indirection. + */ + int ValueHeaderTag = 17 | vendor; + + /** + * The header tag flags of the value type being read from the CDR stream make + * the invalid combination (for instance, 0x7fffff04). + */ + int ValueHeaderFlags = 18 | vendor; + + /** + * The value type class, written on the wire, is not compatible with the + * expected class, passed as a parameter to the InputStream.read_value. + */ + int ClassCast = 19 | vendor; + + /** + * Positive or otherwise invalid indirection offset when reading the data + * graph of the value type. + */ + int Offset = 20 | vendor; + + /** + * Errors while reading the chunked value type. + */ + int Chunks = 21 | vendor; + + /** + * No means are provided to write this value type. + */ + int UnsupportedValue = 22 | vendor; + + /** + * The value factory, required for the operation being invoked, is not + * registered with this ORB. + */ + int Factory = 23 | vendor; + + /** + * Unsupported object addressing method in GIOP request header. + */ + int UnsupportedAddressing = 24 | vendor; + + /** + * Invalid stringified object reference (IOR). + */ + int IOR = 25 | vendor; + + /** + * Problems with converting between stubs, ties, interfaces and + * implementations. + */ + int TargetConversion = 26 | vendor; + + /** + * Problems with reading or writing the fields of the value type object. + */ + int ValueFields = 27 | vendor; + + /** + * The instance of the value type is not serializable. + */ + int NonSerializable = 28 | vendor; + + /* BAD_OPERATION */ + + /** + * The remote side requested to invoke the method that is not available on + * that target (client and server probably disagree in the object definition). + */ + int Method = 0 | vendor; + + /** + * Failed to activate the inactive object. + */ + int Activation = 10 | vendor; + + /* + * Any - Attempt to extract from the Any value of the different type that was + * stored into that Any. + */ + + /* ClassCast - Unable to narrow the object into stub. */ + + /** + * The policies, applying to ORB or POA prevent the requested operation. + */ + int Policy = 11 | vendor; + + /** + * Socket related errors like failure to open socket on the expected port, + * failure to get a free port when required and so on. + */ + int Socket = 12 | vendor; + + /** + * The passed value for enumeration is outside the valid range for that + * enumeration. + */ + int Enumeration = 14 | vendor; + + /** + * The passed policy code is outside the valid range of the possible policies + * for the given policy type. + */ + int PolicyType = 15 | vendor; + + /* NO_RESOURCES */ + + /** + * Unable to get a free port for a new socket. Proably too many objects under + * unsuitable POA policy. + */ + int Ports = 20 | vendor; + + /** + * Too many parallel calls (too many parallel threads). The thread control + * prevents malicios client from knocking the server out by suddenly + * submitting large number of requests. + */ + int Threads = 21 | vendor; + + /** + * The IOR starts with file://, http:// or ftp://, but this local or remote + * resource is not accessible. + */ + int Missing_IOR = 22 | vendor; + +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/Ext.java b/libjava/classpath/gnu/CORBA/NamingService/Ext.java index fb7406c..ee27e68 100644 --- a/libjava/classpath/gnu/CORBA/NamingService/Ext.java +++ b/libjava/classpath/gnu/CORBA/NamingService/Ext.java @@ -73,7 +73,7 @@ public class Ext * The converter class converts between string and array form of the * name. */ - private snConverter converter = new snConverter(); + private NameTransformer converter = new NameTransformer(); /** * Create the extensions for the given instance of the context. diff --git a/libjava/classpath/gnu/CORBA/NamingService/NameComponentComparator.java b/libjava/classpath/gnu/CORBA/NamingService/NameComponentComparator.java new file mode 100644 index 0000000..6116ba9 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/NameComponentComparator.java @@ -0,0 +1,98 @@ +/* NameComponentComparator.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.NamingService; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CosNaming.NameComponent; + +import java.util.Comparator; + +/** + * This class implements the name component comparator, needed to + * sort and compare the name components in maps and sorted sets. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public final class NameComponentComparator + implements Comparator +{ + /** + * The singleton instance of the name comparator. + */ + public static final NameComponentComparator singleton = new NameComponentComparator(); + + /** + * It is enough to have a singleton. + */ + private NameComponentComparator() + { + } + + /** + * Compare the two names components. + * + * @param nc_a the first name component. + * @param nc_b the second name component. + * + * @return 0 if the name components are equal, non zero value + * as result of comparison otherwise. + * + * @throws BAD_PARAM if one of the components is empty or + * has {@link NameComponent#id} or {@link NameComponent#kind} + * field intialised to null. + */ + public final int compare(Object nc_a, Object nc_b) + { + NameComponent a = (NameComponent) nc_a; + NameComponent b = (NameComponent) nc_b; + + int cn = a.id.compareTo(b.id); + if (cn != 0) + return cn; + return a.kind.compareTo(b.kind); + } + + /** + * All instances of this class are equal. + */ + public boolean equals(Object x) + { + return x instanceof NameComponentComparator; + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/NameParser.java b/libjava/classpath/gnu/CORBA/NamingService/NameParser.java index f886cf9..422db1c 100644 --- a/libjava/classpath/gnu/CORBA/NamingService/NameParser.java +++ b/libjava/classpath/gnu/CORBA/NamingService/NameParser.java @@ -1,44 +1,45 @@ /* NameParser.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 modify - it under the terms of the GNU General Public License as published by - the 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, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ package gnu.CORBA.NamingService; -import gnu.CORBA.Functional_ORB; +import gnu.CORBA.Minor; +import gnu.CORBA.OrbFunctional; import gnu.CORBA.IOR; import gnu.CORBA.Unexpected; import gnu.CORBA.Version; @@ -51,11 +52,15 @@ import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CORBA.portable.Delegate; import org.omg.CORBA.portable.ObjectImpl; import org.omg.CosNaming.NamingContext; -import org.omg.CosNaming.NamingContextExtHelper; -import org.omg.CosNaming.NamingContextHelper; import org.omg.CosNaming._NamingContextStub; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; import java.util.StringTokenizer; @@ -74,7 +79,7 @@ import java.util.StringTokenizer; * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class NameParser - extends snConverter + extends NameTransformer { /** * The corbaloc prefix. @@ -90,6 +95,21 @@ public class NameParser * The IOR prefix. */ public static final String pxIOR = "ior"; + + /** + * The file:// prefix. + */ + public static final String pxFILE = "file://"; + + /** + * The ftp:// prefix. + */ + public static final String pxFTP = "ftp://"; + + /** + * The http:// prefix. + */ + public static final String pxHTTP = "http://"; /** * Marks iiop protocol. @@ -114,7 +134,7 @@ public class NameParser /** * The string to name converter, initialized on demand. */ - static snConverter converter; + static NameTransformer converter; /** * The current position. @@ -134,6 +154,9 @@ public class NameParser * 2. corbaloc:rir:[/key]
* 3. corbaname:[iiop][version.subversion@]:host[:port]/key
* 4. corbaname:rir:[/key]
+ * 5. file://[file name]
+ * 6. http://[url]
+ * 7. ftp://[url]
* * Protocol defaults to IOP, the object key defaults to the NameService. * @@ -143,9 +166,31 @@ public class NameParser * @return the resolved object. */ public synchronized org.omg.CORBA.Object corbaloc(String corbaloc, - Functional_ORB orb) + OrbFunctional orb) throws BAD_PARAM { + return corbaloc(corbaloc, orb, 0); + } + + /** + * Parse controlling against the infinite recursion loop. + */ + private org.omg.CORBA.Object corbaloc(String corbaloc, + OrbFunctional orb, int recursion) + { + // The used CORBA specification does not state how many times we should to + //redirect, but the infinite loop may be used to knock out the system. + // by malicious attempt. + if (recursion > 10) + throw new DATA_CONVERSION("More than 10 redirections"); + + if (corbaloc.startsWith(pxFILE)) + return corbaloc(readFile(corbaloc.substring(pxFILE.length())), orb, recursion+1); + else if (corbaloc.startsWith(pxHTTP)) + return corbaloc(readUrl(corbaloc), orb, recursion+1); + else if (corbaloc.startsWith(pxFTP)) + return corbaloc(readUrl(corbaloc), orb, recursion+1); + boolean corbaname; // The alternative addresses, if given. @@ -304,6 +349,70 @@ public class NameParser else throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'"); } + + /** + * Read IOR from the file in the local file system. + */ + String readFile(String file) + { + File f = new File(file); + if (!f.exists()) + { + DATA_CONVERSION err = new DATA_CONVERSION(f.getAbsolutePath() + + " does not exist."); + err.minor = Minor.Missing_IOR; + } + try + { + char[] c = new char[(int) f.length()]; + FileReader fr = new FileReader(f); + fr.read(c); + fr.close(); + return new String(c).trim(); + } + catch (IOException ex) + { + DATA_CONVERSION d = new DATA_CONVERSION(); + d.initCause(ex); + d.minor = Minor.Missing_IOR; + throw (d); + } + } + + /** + * Read IOR from the remote URL. + */ + String readUrl(String url) + { + URL u; + try + { + u = new URL(url); + } + catch (MalformedURLException mex) + { + throw new BAD_PARAM("Malformed URL: '" + url + "'"); + } + + try + { + InputStreamReader r = new InputStreamReader(u.openStream()); + + StringBuffer b = new StringBuffer(); + int c; + + while ((c = r.read()) > 0) + b.append((char) c); + + return b.toString().trim(); + } + catch (Exception exc) + { + DATA_CONVERSION d = new DATA_CONVERSION("Reading " + url + " failed."); + d.minor = Minor.Missing_IOR; + throw d; + } + } private org.omg.CORBA.Object resolve(org.omg.CORBA.Object object) { @@ -329,7 +438,7 @@ public class NameParser } if (converter == null) - converter = new snConverter(); + converter = new NameTransformer(); try { @@ -380,7 +489,7 @@ public class NameParser static NameParser n = new NameParser(); - static void corbalocT(String ior, Functional_ORB orb) + static void corbalocT(String ior, OrbFunctional orb) { System.out.println(ior); System.out.println(n.corbaloc(ior, orb)); @@ -391,7 +500,7 @@ public class NameParser { try { - Functional_ORB orb = (Functional_ORB) ORB.init(args, null); + OrbFunctional orb = (OrbFunctional) ORB.init(args, null); corbalocT("corbaloc:iiop:1.3@155axyz.com/Prod/aTradingService", orb); corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb); corbalocT("corbaloc:iiop:355cxyz.com/Prod/cTradingService", orb); diff --git a/libjava/classpath/gnu/CORBA/NamingService/NameTransformer.java b/libjava/classpath/gnu/CORBA/NamingService/NameTransformer.java new file mode 100644 index 0000000..0e0782a --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/NameTransformer.java @@ -0,0 +1,328 @@ +/* NameTransformer.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.NamingService; + +import org.omg.CORBA.IntHolder; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContextPackage.InvalidName; + +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * This class converts between string and array representations of the + * multi component object names. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameTransformer +{ + /** + * A string, indicating the escape character. + */ + public static final String ESCAPE = "\\"; + + /** + * Convert the string name representation into the array name + * representation. See {@link #toString(NameComponent)} for the + * description of this format. + * + * @param name the string form of the name. + * + * @return the array form of the name. + * + * @throws InvalidName if the name cannot be parsed. + */ + public NameComponent[] toName(String a_name) + throws InvalidName + { + ArrayList components = new ArrayList(); + StringTokenizer st = new StringTokenizer(a_name, "./\\", true); + + String id; + String kind; + String next; + + // Create the buffer array, reserving the last element for null. + String[] n = new String[ st.countTokens() + 1 ]; + + int pp = 0; + while (st.hasMoreTokens()) + n [ pp++ ] = st.nextToken(); + + IntHolder p = new IntHolder(); + + NameComponent node = readNode(p, n); + + while (node != null) + { + components.add(node); + node = readNode(p, n); + } + + NameComponent[] name = new NameComponent[ components.size() ]; + for (int i = 0; i < name.length; i++) + { + name [ i ] = (NameComponent) components.get(i); + } + + NameValidator.check(name); + + return name; + } + + /** + * Converts the name into its string representation, as defined in + * the specification CORBA naming service. + * + * A string representation for the name consists of the name components, + * separated by a slash '/' character (for example, 'a/b/c'). If the + * {@link NameComponent#kind} field is not empty, it is given after + * period ('.'), for example 'a.b/c.d/.' . + * The period alone represents node where part where both + * {@link NameComponent#kind} and {@link NameComponent#id} are empty strings. + * + * If slash or dot are part of the name, they are escaped by backslash ('\'). + * If the backslash itself is part of the name, it is doubled. + * + * @param a_name a name to convert. + * @return a string representation. + */ + public String toString(NameComponent[] a_name) + throws InvalidName + { + NameValidator.check(a_name); + + StringBuffer b = new StringBuffer(); + + NameComponent n; + + for (int ni = 0; ni < a_name.length; ni++) + { + n = a_name [ ni ]; + appEscaping(b, n.id); + if (n.kind.length() > 0) + { + b.append('.'); + appEscaping(b, n.kind); + } + + if (ni < a_name.length - 1) + b.append('/'); + } + return b.toString(); + } + + /** + * Append the contents of the string to this + * string buffer, inserting the escape sequences, where required. + * + * @param b a buffer to append the contents to. + * @param s a string to append. + */ + private void appEscaping(StringBuffer b, String s) + { + char c; + for (int i = 0; i < s.length(); i++) + { + c = s.charAt(i); + switch (c) + { + case '.' : + case '/' : + case '\\' : + b.append('\\'); + b.append(c); + break; + + default : + b.append(c); + break; + } + } + } + + /** + * Assert the end of the current name component. + */ + private void assertEndOfNode(IntHolder p, String[] t) + throws InvalidName + { + if (t [ p.value ] != null) + if (!t [ p.value ].equals("/")) + throw new InvalidName("End of node expected at token " + p.value); + } + + /** + * Read the named component node. After reading the current positon + * advances to the beginning of the next node in an array. + * + * @param p the current position being wrapped inside the passed + * IntHolder. + * + * @param t the text buffer. + * + * @return the created node. + */ + private NameComponent readNode(IntHolder p, String[] t) + throws InvalidName + { + // End of stream has been reached. + if (t [ p.value ] == null) + return null; + + NameComponent n = new NameComponent(); + + if (t [ p.value ].equals(".")) + { + // The 'id' is missing, but the 'kind' may follow. + n.id = ""; + p.value++; + n.kind = readPart(p, t); + assertEndOfNode(p, t); + if (t [ p.value ] != null) + p.value++; + } + else if (t [ p.value ].equals("/")) + { + // This is not allowed here and may happen only + // on two subsequent slashes. + throw new InvalidName("Unexpected '/' token " + p.value); + } + else + { + n.id = readPart(p, t); + + // If some chars follow the id. + if (t [ p.value ] != null) + { + // Dot means that the kind part follows + if (t [ p.value ].equals(".")) + { + p.value++; + n.kind = readPart(p, t); + assertEndOfNode(p, t); + if (t [ p.value ] != null) + p.value++; + } + + // The next name component follows - advance to + // the beginning of the next name component. + else if (t [ p.value ].equals("/")) + { + n.kind = ""; + p.value++; + } + else + throw new InvalidName("Unexpected '" + t [ p.value ] + + "' at token " + p.value + ); + } + else + + // Id, and then end of sequence. + n.kind = ""; + } + + return n; + } + + /** + * Read the name part (id or kind). + * + * @param p the current position. After reading, advances + * to the beginning of the next name fragment. + * + * @param t the string buffer. + * + * @return the name part with resolved escape sequences. + */ + private String readPart(IntHolder p, String[] t) + { + StringBuffer part = new StringBuffer(); + + while (t [ p.value ] != null && !t [ p.value ].equals(".") && + !t [ p.value ].equals("/") + ) + { + if (t [ p.value ].equals(ESCAPE)) + { + p.value++; + part.append(t [ p.value ]); + } + else + part.append(t [ p.value ]); + + p.value++; + } + + return part.toString(); + } + + public static void main(String[] args) + { + NameComponent a = new NameComponent("a", "ak"); + NameComponent b = new NameComponent("b/z", "b.k"); + NameComponent c = new NameComponent("c", ""); + + NameTransformer sn = new NameTransformer(); + + try + { + String s = sn.toString(new NameComponent[] { a, b, c }); + System.out.println(s); + + //NameComponent[] k = toName("a.k/b.k2/c/d/."); + //NameComponent[] k = toName("a.bc/.b/c.x"); + + NameComponent[] k = sn.toName(s); + System.out.println("ToString"); + + for (int i = 0; i < k.length; i++) + { + System.out.println(k [ i ].id + ":" + k [ i ].kind); + } + } + catch (InvalidName ex) + { + ex.printStackTrace(); + } + } + +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java b/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java index a69b061..95deb00 100644 --- a/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java +++ b/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java @@ -66,7 +66,7 @@ public class NamingMap */ public NamingMap() { - map = new TreeMap(cmpNameComponent.singleton); + map = new TreeMap(NameComponentComparator.singleton); } /** diff --git a/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java b/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java index e46bed7..bf72637 100644 --- a/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java +++ b/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java @@ -1,4 +1,4 @@ -/* Server.java -- +/* NamingServiceTransient.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,7 +38,7 @@ exception statement from your version. */ package gnu.CORBA.NamingService; -import gnu.CORBA.Functional_ORB; +import gnu.CORBA.OrbFunctional; import gnu.CORBA.IOR; import org.omg.CosNaming.NamingContextExt; @@ -102,7 +102,7 @@ public class NamingServiceTransient try { // Create and initialize the ORB - final Functional_ORB orb = new Functional_ORB(); + final OrbFunctional orb = new OrbFunctional(); if (args.length > 1) for (int i = 0; i < args.length - 1; i++) @@ -114,7 +114,7 @@ public class NamingServiceTransient iorf = args[i + 1]; } - Functional_ORB.setPort(port); + OrbFunctional.setPort(port); // Create the servant and register it with the ORB NamingContextExt namer = new Ext(new TransientContext()); @@ -159,6 +159,6 @@ public class NamingServiceTransient // Restore the default value for allocating ports for the subsequent // objects. - Functional_ORB.setPort(Functional_ORB.DEFAULT_INITIAL_PORT); + OrbFunctional.setPort(OrbFunctional.DEFAULT_INITIAL_PORT); } } diff --git a/libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java b/libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java deleted file mode 100644 index 1e06fb8..0000000 --- a/libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java +++ /dev/null @@ -1,98 +0,0 @@ -/* cmpNameComponent.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.NamingService; - -import org.omg.CORBA.BAD_PARAM; -import org.omg.CosNaming.NameComponent; - -import java.util.Comparator; - -/** - * This class implements the name component comparator, needed to - * sort and compare the name components in maps and sorted sets. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public final class cmpNameComponent - implements Comparator -{ - /** - * The singleton instance of the name comparator. - */ - public static final cmpNameComponent singleton = new cmpNameComponent(); - - /** - * It is enough to have a singleton. - */ - private cmpNameComponent() - { - } - - /** - * Compare the two names components. - * - * @param nc_a the first name component. - * @param nc_b the second name component. - * - * @return 0 if the name components are equal, non zero value - * as result of comparison otherwise. - * - * @throws BAD_PARAM if one of the components is empty or - * has {@link NameComponent#id} or {@link NameComponent#kind} - * field intialised to null. - */ - public final int compare(Object nc_a, Object nc_b) - { - NameComponent a = (NameComponent) nc_a; - NameComponent b = (NameComponent) nc_b; - - int cn = a.id.compareTo(b.id); - if (cn != 0) - return cn; - return a.kind.compareTo(b.kind); - } - - /** - * All instances of this class are equal. - */ - public boolean equals(Object x) - { - return x instanceof cmpNameComponent; - } -} diff --git a/libjava/classpath/gnu/CORBA/NamingService/snConverter.java b/libjava/classpath/gnu/CORBA/NamingService/snConverter.java deleted file mode 100644 index a9b9219..0000000 --- a/libjava/classpath/gnu/CORBA/NamingService/snConverter.java +++ /dev/null @@ -1,328 +0,0 @@ -/* snConverter.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.NamingService; - -import org.omg.CORBA.IntHolder; -import org.omg.CosNaming.NameComponent; -import org.omg.CosNaming.NamingContextPackage.InvalidName; - -import java.util.ArrayList; -import java.util.StringTokenizer; - -/** - * This class converts between string and array representations of the - * multi component object names. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class snConverter -{ - /** - * A string, indicating the escape character. - */ - public static final String ESCAPE = "\\"; - - /** - * Convert the string name representation into the array name - * representation. See {@link #toString(NameComponent)} for the - * description of this format. - * - * @param name the string form of the name. - * - * @return the array form of the name. - * - * @throws InvalidName if the name cannot be parsed. - */ - public NameComponent[] toName(String a_name) - throws InvalidName - { - ArrayList components = new ArrayList(); - StringTokenizer st = new StringTokenizer(a_name, "./\\", true); - - String id; - String kind; - String next; - - // Create the buffer array, reserving the last element for null. - String[] n = new String[ st.countTokens() + 1 ]; - - int pp = 0; - while (st.hasMoreTokens()) - n [ pp++ ] = st.nextToken(); - - IntHolder p = new IntHolder(); - - NameComponent node = readNode(p, n); - - while (node != null) - { - components.add(node); - node = readNode(p, n); - } - - NameComponent[] name = new NameComponent[ components.size() ]; - for (int i = 0; i < name.length; i++) - { - name [ i ] = (NameComponent) components.get(i); - } - - NameValidator.check(name); - - return name; - } - - /** - * Converts the name into its string representation, as defined in - * the specification CORBA naming service. - * - * A string representation for the name consists of the name components, - * separated by a slash '/' character (for example, 'a/b/c'). If the - * {@link NameComponent#kind} field is not empty, it is given after - * period ('.'), for example 'a.b/c.d/.' . - * The period alone represents node where part where both - * {@link NameComponent#kind} and {@link NameComponent#id} are empty strings. - * - * If slash or dot are part of the name, they are escaped by backslash ('\'). - * If the backslash itself is part of the name, it is doubled. - * - * @param a_name a name to convert. - * @return a string representation. - */ - public String toString(NameComponent[] a_name) - throws InvalidName - { - NameValidator.check(a_name); - - StringBuffer b = new StringBuffer(); - - NameComponent n; - - for (int ni = 0; ni < a_name.length; ni++) - { - n = a_name [ ni ]; - appEscaping(b, n.id); - if (n.kind.length() > 0) - { - b.append('.'); - appEscaping(b, n.kind); - } - - if (ni < a_name.length - 1) - b.append('/'); - } - return b.toString(); - } - - /** - * Append the contents of the string to this - * string buffer, inserting the escape sequences, where required. - * - * @param b a buffer to append the contents to. - * @param s a string to append. - */ - private void appEscaping(StringBuffer b, String s) - { - char c; - for (int i = 0; i < s.length(); i++) - { - c = s.charAt(i); - switch (c) - { - case '.' : - case '/' : - case '\\' : - b.append('\\'); - b.append(c); - break; - - default : - b.append(c); - break; - } - } - } - - /** - * Assert the end of the current name component. - */ - private void assertEndOfNode(IntHolder p, String[] t) - throws InvalidName - { - if (t [ p.value ] != null) - if (!t [ p.value ].equals("/")) - throw new InvalidName("End of node expected at token " + p.value); - } - - /** - * Read the named component node. After reading the current positon - * advances to the beginning of the next node in an array. - * - * @param p the current position being wrapped inside the passed - * IntHolder. - * - * @param t the text buffer. - * - * @return the created node. - */ - private NameComponent readNode(IntHolder p, String[] t) - throws InvalidName - { - // End of stream has been reached. - if (t [ p.value ] == null) - return null; - - NameComponent n = new NameComponent(); - - if (t [ p.value ].equals(".")) - { - // The 'id' is missing, but the 'kind' may follow. - n.id = ""; - p.value++; - n.kind = readPart(p, t); - assertEndOfNode(p, t); - if (t [ p.value ] != null) - p.value++; - } - else if (t [ p.value ].equals("/")) - { - // This is not allowed here and may happen only - // on two subsequent slashes. - throw new InvalidName("Unexpected '/' token " + p.value); - } - else - { - n.id = readPart(p, t); - - // If some chars follow the id. - if (t [ p.value ] != null) - { - // Dot means that the kind part follows - if (t [ p.value ].equals(".")) - { - p.value++; - n.kind = readPart(p, t); - assertEndOfNode(p, t); - if (t [ p.value ] != null) - p.value++; - } - - // The next name component follows - advance to - // the beginning of the next name component. - else if (t [ p.value ].equals("/")) - { - n.kind = ""; - p.value++; - } - else - throw new InvalidName("Unexpected '" + t [ p.value ] + - "' at token " + p.value - ); - } - else - - // Id, and then end of sequence. - n.kind = ""; - } - - return n; - } - - /** - * Read the name part (id or kind). - * - * @param p the current position. After reading, advances - * to the beginning of the next name fragment. - * - * @param t the string buffer. - * - * @return the name part with resolved escape sequences. - */ - private String readPart(IntHolder p, String[] t) - { - StringBuffer part = new StringBuffer(); - - while (t [ p.value ] != null && !t [ p.value ].equals(".") && - !t [ p.value ].equals("/") - ) - { - if (t [ p.value ].equals(ESCAPE)) - { - p.value++; - part.append(t [ p.value ]); - } - else - part.append(t [ p.value ]); - - p.value++; - } - - return part.toString(); - } - - public static void main(String[] args) - { - NameComponent a = new NameComponent("a", "ak"); - NameComponent b = new NameComponent("b/z", "b.k"); - NameComponent c = new NameComponent("c", ""); - - snConverter sn = new snConverter(); - - try - { - String s = sn.toString(new NameComponent[] { a, b, c }); - System.out.println(s); - - //NameComponent[] k = toName("a.k/b.k2/c/d/."); - //NameComponent[] k = toName("a.bc/.b/c.x"); - - NameComponent[] k = sn.toName(s); - System.out.println("ToString"); - - for (int i = 0; i < k.length; i++) - { - System.out.println(k [ i ].id + ":" + k [ i ].kind); - } - } - catch (InvalidName ex) - { - ex.printStackTrace(); - } - } - -} diff --git a/libjava/classpath/gnu/CORBA/ObjectCreator.java b/libjava/classpath/gnu/CORBA/ObjectCreator.java index 81c1d06..5937e76 100644 --- a/libjava/classpath/gnu/CORBA/ObjectCreator.java +++ b/libjava/classpath/gnu/CORBA/ObjectCreator.java @@ -38,27 +38,37 @@ exception statement from your version. */ package gnu.CORBA; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.UnknownExceptionCtxHandler; +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; +import gnu.CORBA.CDR.AbstractCdrInput; +import gnu.CORBA.GIOP.ServiceContext; +import gnu.CORBA.typecodes.RecordTypeCode; +import gnu.classpath.VMStackWalker; import org.omg.CORBA.Any; import org.omg.CORBA.CompletionStatus; import org.omg.CORBA.CompletionStatusHelper; import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.StructMember; import org.omg.CORBA.SystemException; import org.omg.CORBA.TCKind; import org.omg.CORBA.UNKNOWN; import org.omg.CORBA.UserException; +import org.omg.CORBA.portable.IDLEntity; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ValueBase; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.Map; +import java.util.WeakHashMap; + +import javax.rmi.CORBA.Util; /** * Creates java objects from the agreed IDL names for the simple case when the * CORBA object is directly mapped into the locally defined java class. - * + * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public class ObjectCreator @@ -79,91 +89,137 @@ public class ObjectCreator public static final String CLASSPATH_PREFIX = "gnu.CORBA."; /** + * Maps classes to they IDL or RMI names. Computing RMI name is an expensive + * operations, so frequently used RMI keys are reused. The map must be weak to + * ensure that the class can be unloaded, when applicable. + */ + public static Map m_names = new WeakHashMap(); + + /** + * Maps IDL strings into known classes. The map must be weak to ensure that + * the class can be unloaded, when applicable. + */ + public static Map m_classes = new WeakHashMap(); + + /** + * Maps IDL types to they helpers. + */ + public static Map m_helpers = new WeakHashMap(); + + /** * Try to instantiate an object with the given IDL name. The object must be * mapped to the local java class. The omg.org domain must be mapped into the * object in either org/omg or gnu/CORBA namespace. - * + * * @param IDL name * @return instantiated object instance or null if no such available. */ public static java.lang.Object createObject(String idl, String suffix) { - try - { - return Class.forName(toClassName(JAVA_PREFIX, idl) + suffix) - .newInstance(); - } - catch (Exception ex) + synchronized (m_classes) { - try + Class known = (Class) (suffix == null ? m_classes.get(idl) + : m_classes.get(idl + 0xff + suffix)); + Object object; + + if (known != null) { - return Class.forName(toClassName(CLASSPATH_PREFIX, idl) + suffix) - .newInstance(); + try + { + return known.newInstance(); + } + catch (Exception ex) + { + RuntimeException rex = new RuntimeException(idl + " suffix " + + suffix, ex); + throw rex; + } } - catch (Exception exex) + else { - return null; + if (suffix == null) + suffix = ""; + try + { + known = forName(toClassName(JAVA_PREFIX, idl) + suffix); + object = known.newInstance(); + } + catch (Exception ex) + { + try + { + known = forName(toClassName(CLASSPATH_PREFIX, idl) + + suffix); + object = known.newInstance(); + } + catch (Exception exex) + { + return null; + } + } + m_classes.put(idl + 0xff + suffix, known); + return object; } } } /** - * Create the system exception with the given idl name. - * - * @param idl the exception IDL name, must match the syntax "IDL::1.0". - * @param minor the exception minor code. - * @param completed the exception completion status. - * - * @return the created exception. + * Read the system exception from the given stream. + * + * @param input the CDR stream to read from. + * @param contexts the service contexts in request/reply header/ + * + * @return the exception that has been stored in the stream (IDL name, minor + * code and completion status). */ - public static SystemException createSystemException(String idl, int minor, - CompletionStatus completed - ) + public static SystemException readSystemException(InputStream input, + ServiceContext[] contexts) { + SystemException exception; + + String idl = input.read_string(); + int minor = input.read_ulong(); + CompletionStatus completed = CompletionStatusHelper.read(input); + try { - String cl = toClassName(JAVA_PREFIX, idl); - Class exClass = Class.forName(cl); - - Constructor constructor = - exClass.getConstructor(new Class[] - { - String.class, int.class, CompletionStatus.class - } - ); - - Object exception = - constructor.newInstance(new Object[] - { - " Remote exception " + idl + ", minor " + minor + ", " + - completed + ".", new Integer(minor), completed - } - ); - - return (SystemException) exception; + exception = (SystemException) createObject(idl, null); + exception.minor = minor; + exception.completed = completed; } catch (Exception ex) { - ex.printStackTrace(); - return new UNKNOWN("Unsupported system exception", minor, completed); + UNKNOWN u = new UNKNOWN("Unsupported system exception " + idl, minor, + completed); + u.initCause(ex); + throw u; } - } - /** - * Read the system exception from the given stream. - * - * @param input the CDR stream to read from. - * @return the exception that has been stored in the stream (IDL name, minor - * code and completion status). - */ - public static SystemException readSystemException(InputStream input) - { - String idl = input.read_string(); - int minor = input.read_ulong(); - CompletionStatus status = CompletionStatusHelper.read(input); + try + { + // If UnknownExceptionInfo is present in the contexts, read it and + // set as a cause of this exception. + ServiceContext uEx = ServiceContext.find( + ServiceContext.UnknownExceptionInfo, contexts); - SystemException exception = - ObjectCreator.createSystemException(idl, minor, status); + if (uEx != null) + { + BufferredCdrInput in = new BufferredCdrInput(uEx.context_data); + in.setOrb(in.orb()); + if (input instanceof AbstractCdrInput) + { + ((AbstractCdrInput) input).cloneSettings(in); + } + + Throwable t = UnknownExceptionCtxHandler.read(in, contexts); + exception.initCause(t); + } + } + catch (Exception ex) + { + // Unsupported context format. Do not terminate as the user program may + // not need it. + } return exception; } @@ -172,10 +228,10 @@ public class ObjectCreator * Reads the user exception, having the given Id, from the input stream. The * id is expected to be in the form like * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' - * + * * @param idl the exception idl name. * @param input the stream to read from. - * + * * @return the loaded exception. * @return null if the helper class cannot be found. */ @@ -183,13 +239,10 @@ public class ObjectCreator { try { - String helper = toHelperName(idl); - Class helperClass = Class.forName(helper); + Class helperClass = findHelper(idl); - Method read = - helperClass.getMethod("read", - new Class[] { org.omg.CORBA.portable.InputStream.class } - ); + Method read = helperClass.getMethod("read", + new Class[] { org.omg.CORBA.portable.InputStream.class }); return (UserException) read.invoke(null, new Object[] { input }); } @@ -208,7 +261,7 @@ public class ObjectCreator /** * Gets the helper class name from the string like * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' - * + * * @param IDL the idl name. */ public static String toHelperName(String IDL) @@ -227,15 +280,14 @@ public class ObjectCreator /** * Writes the system exception data to CDR output stream. - * + * * @param output a stream to write data to. * @param ex an exception to write. */ public static void writeSystemException(OutputStream output, - SystemException ex - ) + SystemException ex) { - String exIDL = toIDL(ex.getClass().getName()); + String exIDL = getRepositoryId(ex.getClass()); output.write_string(exIDL); output.write_ulong(ex.minor); CompletionStatusHelper.write(output, ex.completed); @@ -243,9 +295,9 @@ public class ObjectCreator /** * Converts the given IDL name to class name. - * + * * @param IDL the idl name. - * + * */ protected static String toClassName(String prefix, String IDL) { @@ -265,34 +317,43 @@ public class ObjectCreator * Converts the given IDL name to class name and tries to load the matching * class. The OMG prefix (omg.org) is replaced by the java prefix org.omg. No * other prefixes are added. - * + * * @param IDL the idl name. - * - * TODO Cache the returned classes, avoiding these string manipulations each - * time the conversion is required. - * + * * @return the matching class or null if no such is available. */ public static Class Idl2class(String IDL) { - String s = IDL; - int a = s.indexOf(':') + 1; - int b = s.lastIndexOf(':'); - - s = IDL.substring(a, b); - - if (s.startsWith(OMG_PREFIX)) - s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); - - String cn = s.replace('/', '.'); - - try + synchronized (m_classes) { - return Class.forName(cn); - } - catch (ClassNotFoundException ex) - { - return null; + Class c = (Class) m_classes.get(IDL); + + if (c != null) + return c; + else + { + String s = IDL; + int a = s.indexOf(':') + 1; + int b = s.lastIndexOf(':'); + + s = IDL.substring(a, b); + + if (s.startsWith(OMG_PREFIX)) + s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); + + String cn = s.replace('/', '.'); + + try + { + c = forName(cn); + m_classes.put(IDL, c); + return c; + } + catch (ClassNotFoundException ex) + { + return null; + } + } } } @@ -301,9 +362,9 @@ public class ObjectCreator * and create an object instance with parameterless constructor. The OMG * prefix (omg.org) is replaced by the java prefix org.omg. No other prefixes * are added. - * + * * @param IDL the idl name. - * + * * @return instantiated object instance or null if such attempt was not * successful. */ @@ -325,34 +386,53 @@ public class ObjectCreator } /** - * Convert the class name to IDL name. - * - * @param cn the class name. - * - * @return the idl name. + * Convert the class name to IDL or RMI name (repository id). If the class + * inherits from IDLEntity, ValueBase or SystemException, returns repository + * Id in the IDL:(..) form. If it does not, returns repository Id in the + * RMI:(..) form. + * + * @param cx the class for that the name must be computed. + * + * @return the idl or rmi name. */ - public static String toIDL(String cn) + public static synchronized String getRepositoryId(Class cx) { - if (cn.startsWith(JAVA_PREFIX)) - cn = OMG_PREFIX + cn.substring(JAVA_PREFIX.length()).replace('.', '/'); - else if (cn.startsWith(CLASSPATH_PREFIX)) - cn = - OMG_PREFIX + - cn.substring(CLASSPATH_PREFIX.length()).replace('.', '/'); - - return "IDL:" + cn + ":1.0"; + String name = (String) m_names.get(cx); + if (name != null) + return name; + + String cn = cx.getName(); + if (!(IDLEntity.class.isAssignableFrom(cx) + || ValueBase.class.isAssignableFrom(cx) || SystemException.class.isAssignableFrom(cx))) + { + // Not an IDL entity. + name = Util.createValueHandler().getRMIRepositoryID(cx); + } + else + { + if (cn.startsWith(JAVA_PREFIX)) + cn = OMG_PREFIX + + cn.substring(JAVA_PREFIX.length()).replace('.', '/'); + else if (cn.startsWith(CLASSPATH_PREFIX)) + cn = OMG_PREFIX + + cn.substring(CLASSPATH_PREFIX.length()).replace('.', '/'); + + name = "IDL:" + cn + ":1.0"; + } + m_names.put(cx, name); + return name; } /** * Insert the passed parameter into the given Any, assuming that the helper * class is available. The helper class must have the "Helper" suffix and be * in the same package as the class of the object being inserted. - * + * * @param into the target to insert. - * + * * @param object the object to insert. It can be any object as far as the * corresponding helper is provided. - * + * * @return true on success, false otherwise. */ public static boolean insertWithHelper(Any into, Object object) @@ -360,12 +440,10 @@ public class ObjectCreator try { String helperClassName = object.getClass().getName() + "Helper"; - Class helperClass = Class.forName(helperClassName); + Class helperClass = forName(helperClassName); - Method insert = - helperClass.getMethod("insert", - new Class[] { Any.class, object.getClass() } - ); + Method insert = helperClass.getMethod("insert", new Class[] { + Any.class, object.getClass() }); insert.invoke(null, new Object[] { into, object }); @@ -385,20 +463,20 @@ public class ObjectCreator { try { - cdrBufOutput output = new cdrBufOutput(); + BufferedCdrOutput output = new BufferedCdrOutput(); - String m_exception_id = toIDL(exception.getClass().getName()); + String m_exception_id = getRepositoryId(exception.getClass()); output.write_string(m_exception_id); output.write_ulong(exception.minor); CompletionStatusHelper.write(output, exception.completed); String name = getDefaultName(m_exception_id); - universalHolder h = new universalHolder(output); + GeneralHolder h = new GeneralHolder(output); into.insert_Streamable(h); - recordTypeCode r = new recordTypeCode(TCKind.tk_except); + RecordTypeCode r = new RecordTypeCode(TCKind.tk_except); r.setId(m_exception_id); r.setName(name); into.type(r); @@ -444,4 +522,69 @@ public class ObjectCreator if (!ok) throw new InternalError("Exception wrapping broken"); } + + /** + * Find helper for the class with the given name. + */ + public static Class findHelper(String idl) + { + synchronized (m_helpers) + { + Class c = (Class) m_helpers.get(idl); + if (c != null) + return c; + try + { + String helper = toHelperName(idl); + c = forName(helper); + + m_helpers.put(idl, c); + return c; + } + catch (Exception ex) + { + return null; + } + } + } + + /** + * Load the class with the given name. This method tries to use the context + * class loader first. If this fails, it searches for the suitable class + * loader in the caller stack trace. This method is a central point where all + * requests to find a class by name are delegated. + */ + public static Class forName(String className) throws ClassNotFoundException + { + try + { + return Class.forName(className, true, + Thread.currentThread().getContextClassLoader()); + } + catch (ClassNotFoundException nex) + { + /** + * Returns the first user defined class loader on the call stack, or + * null when no non-null class loader was found. + */ + Class[] ctx = VMStackWalker.getClassContext(); + for (int i = 0; i < ctx.length; i++) + { + // Since we live in a class loaded by the bootstrap + // class loader, getClassLoader is safe to call without + // needing to be wrapped in a privileged action. + ClassLoader cl = ctx[i].getClassLoader(); + try + { + if (cl != null) + return Class.forName(className, true, cl); + } + catch (ClassNotFoundException nex2) + { + // Try next. + } + } + } + throw new ClassNotFoundException(className); + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/OctetHolder.java b/libjava/classpath/gnu/CORBA/OctetHolder.java index 02fd9a4..06d7538 100644 --- a/libjava/classpath/gnu/CORBA/OctetHolder.java +++ b/libjava/classpath/gnu/CORBA/OctetHolder.java @@ -38,7 +38,7 @@ exception statement from your version. */ package gnu.CORBA; -import gnu.CORBA.primitiveTypeCode; +import gnu.CORBA.typecodes.PrimitiveTypeCode; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.OutputStream; @@ -64,7 +64,7 @@ public final class OctetHolder * The default type code for this holder. */ private static final TypeCode t_octet = - new primitiveTypeCode(TCKind.tk_octet); + new PrimitiveTypeCode(TCKind.tk_octet); /** * The long (CORBA octet) value, diff --git a/libjava/classpath/gnu/CORBA/OrbFocused.java b/libjava/classpath/gnu/CORBA/OrbFocused.java new file mode 100644 index 0000000..a0f9993 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/OrbFocused.java @@ -0,0 +1,375 @@ +/* OrbFocused.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.Poa.ORB_1_4; + +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.NO_RESOURCES; +import org.omg.CORBA.portable.InvokeHandler; + +import java.applet.Applet; +import java.net.ServerSocket; +import java.util.Iterator; +import java.util.Properties; +import java.util.Random; +import java.util.StringTokenizer; + +/** + * This class implements the ORB that uses a single port or the restricted port + * range for all its objects. It is required to for use together with various + * firewalls that does not allow opening multiple randomly selected ports, as + * the defauld CORBA implementation used to do. The firewal must be configured + * to allow CORBA to work on one fixed port or (for better performance) on a + * small fixed range of ports. This does not restrict the maximal number of the + * connected objects as the objects can share the same port. + * + * The used port or the used port range can be specified via property + * gnu.CORBA.ListenerPort. The value of this property is a single port or range + * of ports, boundary values (inclusive) being separeted by dash (for instance, + * "1245-1250"). + * + * It is possible to instantiate multiple instances of the focused ORBs and + * combine them with the ordinary ORBs. If you instantiate several instances of + * the focused ORBs on the same host, they used port sets should not overlap. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class OrbFocused + extends ORB_1_4 +{ + /** + * The name of the fixed port range property. The presence of this property + * indicates that the default focused ORB must be used. + */ + public static final String LISTENER_PORT = "gnu.CORBA.ListenerPort"; + + /** + * The start of the range of the available ports, inclusive. + */ + int m_ports_from = -1; + + /** + * The end of the range of the available ports, inclusive. + */ + int m_ports_to = -1; + + /** + * The requests to port are served in parallel threads. + */ + static final int PARALLEL = 0; + + /** + * The requests to port are served in the same thread. + */ + static final int SEQUENTIAL = 1; + + /** + * The random number generator to get a random port in the valid range. + */ + Random m_random = new Random(); + + /** + * Parse the "gnu.CORBA.ListenerPort" property and initialize the valid port + * set range. + */ + public void setPortRange(String property) + { + int from, to; + try + { + StringTokenizer st = new StringTokenizer(property, " -"); + if (st.countTokens() == 1) + from = to = Integer.parseInt(st.nextToken()); + else + { + from = Integer.parseInt(st.nextToken()); + to = Integer.parseInt(st.nextToken()); + m_random = new Random(); + } + setPortRange(from, to); + } + catch (Exception ex) + { + throw new BAD_PARAM("Unable to parse port range '" + property + "'"); + } + } + + /** + * Set the port range. + * + * @param from - start of the port range, inclusive. + * @param to - end of the port range, inclusive. + */ + public void setPortRange(int from, int to) + { + if (from < 0 || to < 0 || to < from) + throw new BAD_PARAM("Invalid range"); + m_ports_from = from; + m_ports_to = to; + } + + /** + * Get the port from the previously specified usage range. + */ + int getPortFromRange(int attempt) + { + if (m_ports_from == m_ports_to) + return m_ports_from; + else if (m_ports_to - m_ports_from < RANDOM_PORT_ATTEMPTS) + return m_ports_from + (attempt % (m_ports_to - m_ports_from + 1)); + else + return m_random.nextInt(m_ports_to - m_ports_from + 1) + m_ports_from; + } + + /** + * Get the shared port server where the new object can be added. This may + * result reusing the existing server or instantiating a new server. If the + * new server is instantiated and the ORB is already running, the server is + * started. + */ + protected portServer getPortServer(int type) + { + portServer p; + + int n; + if (m_ports_from < m_ports_to) + n = RANDOM_PORT_ATTEMPTS; + else + n = 1; + + Ports: for (int a = 0; a < n; a++) + { + int port = getPortFromRange(a); + for (int i = 0; i < portServers.size(); i++) + { + p = (portServer) portServers.get(i); + if (p.s_port == port) + { + return (portServer) p; + } + } + // The server is not yet instantiated. Instantiate. + try + { + // Check if the port is ok: + ServerSocket s = socketFactory.createServerSocket(port); + s.close(); + + portServer shared; + + switch (type) + { + case PARALLEL: + shared = new portServer(port); + break; + + case SEQUENTIAL: + shared = new sharedPortServer(port); + break; + + default: + throw new InternalError("Invalid server type " + type); + } + + portServers.add(shared); + + if (running) + shared.start(); + + return shared; + } + catch (Exception ex) + { + // Port is taken or probably other problems. + continue Ports; + } + } + throw new NO_RESOURCES("No free port available at " + m_ports_from + "-" + + m_ports_to, Minor.Ports, CompletionStatus.COMPLETED_NO); + } + + /** + * Start the ORBs main working cycle (receive invocation - invoke on the local + * object - send response - wait for another invocation). + * + * The method only returns after calling {@link #shutdown(boolean)}. + */ + public void run() + { + if (m_ports_from < 0 || m_ports_to < 0) + throw new BAD_INV_ORDER("For " + getClass().getName() + " " + + LISTENER_PORT + " property must be set"); + + running = true; + + // Start all port servers. In the current subclass, the portServers + // collection must be already filled in. + Iterator iter = portServers.iterator(); + + while (iter.hasNext()) + { + portServer subserver = (portServer) iter.next(); + + if (!subserver.isAlive()) + { + // Reuse the current thread for the last portServer. + if (!iter.hasNext()) + { + // Discard the iterator. + iter = null; + subserver.run(); + return; + } + else + subserver.start(); + } + } + } + + /** + * Get free port from the allowed range. This method instantiates the port + * server for the returned port. + */ + public int getFreePort() + throws BAD_OPERATION + { + portServer s = getPortServer(PARALLEL); + return s.s_port; + } + + /** + * Connect the given CORBA object to this ORB, explicitly specifying the + * object key and the identity of the thread (and port), where the object must + * be served. The identity is normally the POA. + * + * The new port server will be started only if there is no one already running + * for the same identity. Otherwise, the task of the existing port server will + * be widened, including duty to serve the given object. All objects, + * connected to a single identity by this method, will process they requests + * subsequently in the same thread. The method is used when the expected + * number of the objects is too large to have a single port and thread per + * object. This method is used by POAs, having a single thread policy. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * @param key the object key, usually used to identify the object from remote + * side. + * @param port the port, where the object must be connected. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect_1_thread(org.omg.CORBA.Object object, byte[] key, + java.lang.Object identity) + { + sharedPortServer shared = (sharedPortServer) identities.get(identity); + if (shared == null) + { + shared = (sharedPortServer) getPortServer(SEQUENTIAL); + identities.put(identity, shared); + if (running) + { + shared.start(); + } + } + + Connected_objects.cObject ref = connected_objects.add(key, object, + shared.s_port, identity); + IOR ior = createIOR(ref); + prepareObject(object, ior); + } + + /** + * In this type of ORB, the service is started by {@link #getPortServer}. The + * method below is not in use and should return without action. + */ + public void startService(IOR ior) + { + } + + /** + * Set parameters (additionally search for the port range property). + */ + protected void set_parameters(Applet applet, Properties props) + { + super.set_parameters(applet, props); + String lp = applet.getParameter(LISTENER_PORT); + if (lp != null) + setPortRange(lp); + } + + /** + * Set parameters (additionally search for the port range property). + */ + protected void set_parameters(String[] args, Properties props) + { + super.set_parameters(args, props); + String lp = null; + + String lpKey = "-" + LISTENER_PORT; + + if (args != null) + if (args.length >= 2) + { + for (int i = 0; i < args.length - 1; i++) + if (args[i].equals(lpKey)) + lp = args[i + 1]; + } + + if (lp != null) + setPortRange(lp); + + } + + /** + * Additionally set the port range property, when applicable. + */ + protected void useProperties(Properties props) + { + super.useProperties(props); + String lp = props.getProperty(LISTENER_PORT); + if (lp != null) + setPortRange(lp); + } + +} diff --git a/libjava/classpath/gnu/CORBA/OrbFunctional.java b/libjava/classpath/gnu/CORBA/OrbFunctional.java new file mode 100644 index 0000000..f147e81 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/OrbFunctional.java @@ -0,0 +1,1766 @@ +/* OrbFunctional.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.UnknownExceptionCtxHandler; +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; +import gnu.CORBA.GIOP.CloseMessage; +import gnu.CORBA.GIOP.ErrorMessage; +import gnu.CORBA.GIOP.MessageHeader; +import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.GIOP.RequestHeader; +import gnu.CORBA.NamingService.NameParser; +import gnu.CORBA.NamingService.NamingServiceTransient; +import gnu.CORBA.Poa.gnuForwardRequest; +import gnu.CORBA.interfaces.SocketFactory; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_RESOURCES; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.Request; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.WrongTransaction; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.UnknownException; +import org.omg.CosNaming.NamingContextExt; +import org.omg.CosNaming.NamingContextExtHelper; + +import java.applet.Applet; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Properties; +import java.util.Random; +import java.util.StringTokenizer; +import java.util.TreeMap; + +/** + * The ORB implementation, capable to handle remote invocations on the + * registered object. This class implements all features, required till the jdk + * 1.3 inclusive, but does not support the POA that appears since 1.4. The POA + * is supported by {@link gnu.CORBA.Poa.ORB_1_4}. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class OrbFunctional extends OrbRestricted +{ + /** + * A server, responsible for listening on requests on some local port. The ORB + * may listen on multiple ports and process the requests in separate threads. + * Normally the server takes one port per object being served. + */ + protected class portServer + extends Thread + { + /** + * The number of the currently running parallel threads. + */ + int running_threads; + + /** + * The port on that this portServer is listening for requests. + */ + int s_port; + + /** + * The server socket of this portServer. + */ + ServerSocket service; + + /** + * True if the serving node must shutdown due call of the close_now(). + */ + boolean terminated; + + /** + * Create a new portServer, serving on specific port. + */ + portServer(int _port) + { + s_port = _port; + setDaemon(true); + try + { + service = socketFactory.createServerSocket(s_port); + } + catch (IOException ex) + { + BAD_OPERATION bad = new BAD_OPERATION( + "Unable to open the server socket at " + s_port); + bad.minor = Minor.Socket; + bad.initCause(ex); + throw bad; + } + } + + /** + * Enter the serving loop (get request/process it). All portServer normally + * terminate thy threads when the OrbFunctional.running is set to false. + */ + public void run() + { + while (running) + { + try + { + tick(); + } + catch (SocketException ex) + { + // May be thrown when the service is closed by + // the close_now(). + if (terminated) + return; + } + catch (Exception iex) + { + // Wait. Do not terminate the + // service due potentially transient error. + try + { + Thread.sleep(TWAIT_SERVER_ERROR_PAUSE); + } + catch (InterruptedException ex) + { + } + } + } + } + + /** + * Perform a single serving step. + * + * @throws java.lang.Exception + */ + void tick() + throws Exception + { + serve(this, service); + } + + /** + * Forcibly close the server socket and mark this port as free. + */ + public void close_now() + { + try + { + terminated = true; + service.close(); + } + catch (Exception ex) + { + // This may happen if the service has not been opened or + // cannot be closed. Return without action. + } + } + + /** + * If the thread is no longer in use, close the socket (if opened). + */ + protected void finalize() + { + close_now(); + } + } + + /** + * A server, responsible for listening on requests on some local port and + * serving multiple requests (probably to the different objects) on the same + * thread. + */ + protected class sharedPortServer extends portServer + { + /** + * Create a new portServer, serving on specific port. + */ + sharedPortServer(int _port) + { + super(_port); + } + + /** + * Perform a single serving step. + * + * @throws java.lang.Exception + */ + void tick() throws Exception + { + Socket request = service.accept(); + serveStep(request, false); + } + } + + /** + * The default value where the first instance of this ORB will start looking + * for a free port. + */ + public static int DEFAULT_INITIAL_PORT = 1126; + + /** + * When trying to open the socket on a random port, start of the interval to + * try. + */ + public static int RANDOM_PORT_FROM = 1024; + + /** + * When trying to open the socket on a random port, end of the interval to + * try. + */ + public static int RANDOM_PORT_TO = 4024; + + /** + * The number of attempts to try when opening random port. + */ + public static int RANDOM_PORT_ATTEMPTS = 64; + + /** + * The property of port, on that this ORB is listening for requests from + * clients. This class supports one port per ORB only. + */ + public static final String LISTEN_ON = "gnu.classpath.CORBA.ListenOn"; + + /** + * The property, defining the IOR of the intial reference to resolve. + */ + public static final String REFERENCE = "org.omg.CORBA.ORBInitRef"; + + /** + * The property, defining the port on that the default name service is + * running. + */ + public static final String NS_PORT = "org.omg.CORBA.ORBInitialPort"; + + /** + * The property, defining the host on that the default name service is + * running. + */ + public static final String NS_HOST = "org.omg.CORBA.ORBInitialHost"; + + /** + * The string, defining the naming service initial reference. + */ + public static final String NAME_SERVICE = "NameService"; + + /** + * Defines the ORB ID that is accessible by IOR interceptors. + */ + public static final String ORB_ID = "org.omg.CORBA.ORBid"; + + + /** + * Defines the SERVER ID that is accessible by IOR interceptors. + */ + public static final String SERVER_ID = "org.omg.CORBA.ServerId"; + + /** + * The if the client has once opened a socket, it should start sending the + * message header in a given time. Otherwise the server will close the socket. + * This prevents server hang when the client opens the socket, but does not + * send any message, usually due crash on the client side. + */ + public static String START_READING_MESSAGE = + "gnu.classpath.CORBA.TOUT_START_READING_MESSAGE"; + + /** + * If the client has started to send the request message, the socket time out + * changes to the specified value. + */ + public static String WHILE_READING = + "gnu.classpath.CORBA.TOUT_WHILE_READING"; + + /** + * If the message body is received, the time out changes to the specifice + * value. This must be longer, as includes time, required to process the + * received task. We make it 40 minutes. + */ + public static String AFTER_RECEIVING = + "gnu.classpath.CORBA.TOUT_AFTER_RECEIVING"; + + /** + * The server waits for this duration after the potentially transient error + * during its servicing cycle. + */ + public static String SERVER_ERROR_PAUSE = + "gnu.classpath.CORBA.SERVER_ERROR_PAUSE"; + + /** + * The address of the local host. + */ + public final String LOCAL_HOST; + + /** + * The if the client has once opened a socket, it should start sending the + * message header in a given time. Otherwise the server will close the socket. + * This prevents server hang when the client opens the socket, but does not + * send any message, usually due crash on the client side. + */ + public int TOUT_START_READING_MESSAGE = 20 * 1000; + + // (Here and below, we use * to make the meaning of the constant clearler). + + /** + * If the client has started to send the request message, the socket time out + * changes to the specified value. + */ + public int TOUT_WHILE_READING = 2 * 60 * 1000; + + /** + * If the message body is received, the time out changes to the specifice + * value. This must be longer, as includes time, required to process the + * received task. We make it 40 minutes. + */ + public int TOUT_AFTER_RECEIVING = 40 * 60 * 1000; + + /** + * The server waits for this duration after the potentially transient error + * during its servicing cycle. + */ + public int TWAIT_SERVER_ERROR_PAUSE = 5000; + + /** + * Some clients tend to submit multiple requests over the same socket. The + * server waits for the next request on the same socket for the duration, + * specified below. In additions, the request of this implementation also + * waits for the same duration before closing the socket. The default time is + * seven seconds. + */ + public static int TANDEM_REQUESTS = 7000; + + /** + * The Id of this ORB. + */ + public String orb_id = "orb_"+hashCode(); + + /** + * The Id of this Server. This field is defined static to ensure it has + * the same value over all ORB's in this machine. + */ + public static String server_id = "server_"+OrbFunctional.class.hashCode(); + + /** + * The map of the already conncted objects. + */ + protected final Connected_objects connected_objects = + new Connected_objects(); + + /** + * The maximal CORBA version, supported by this ORB. The default value 0 means + * that the ORB will not check the request version while trying to respond. + */ + protected Version max_version; + + /** + * Setting this value to false causes the ORB to shutdown after the latest + * serving operation is complete. + */ + protected boolean running; + + /** + * The map of the initial references. + */ + protected Map initial_references = new TreeMap(); + + /** + * The currently active portServers. + */ + protected ArrayList portServers = new ArrayList(); + + /** + * The host, on that the name service is expected to be running. + */ + private String ns_host; + + /** + * Probably free port, under that the ORB will try listening for remote + * requests first. When the new object is connected, this port is used first, + * then it is incremented by 1, etc. If the given port is not available, up to + * 20 subsequent values are tried and then the parameterless server socket + * contructor is called. The constant is shared between multiple instances of + * this ORB. + */ + private static int Port = DEFAULT_INITIAL_PORT; + + /** + * The port, on that the name service is expected to be running. + */ + private int ns_port = 900; + + /** + * The name parser. + */ + NameParser nameParser = new NameParser(); + + /** + * The instance, stored in this field, handles the asynchronous dynamic + * invocations. + */ + protected Asynchron asynchron = new Asynchron(); + + /** + * The list of the freed ports. The ORB reuses ports, when possible. + */ + protected LinkedList freed_ports = new LinkedList(); + + /** + * Maps a single-threaded POAs to they sharedPortServants. + */ + protected Hashtable identities = new Hashtable(); + + /** + * The maximal allowed number of the currently running parallel threads per + * object. For security reasons, this is made private and unchangeable. After + * exceeding this limit, the NO_RESOURCES is thrown back to the client. + */ + private int MAX_RUNNING_THREADS = 256; + + /** + * The producer of the client and server sockets for this ORB. + */ + public SocketFactory socketFactory = DefaultSocketFactory.Singleton; + + /** + * Create the instance of the Functional ORB. + */ + public OrbFunctional() + { + try + { + LOCAL_HOST = ns_host = InetAddress.getLocalHost().getHostAddress(); + initial_references.put("CodecFactory", new gnuCodecFactory(this)); + } + catch (UnknownHostException ex) + { + BAD_OPERATION bad = + new BAD_OPERATION("Unable to open the server socket."); + bad.initCause(ex); + throw bad; + } + } + + /** + * If the max version is assigned, the orb replies with the error message if + * the request version is above the supported 1.2 version. This behavior is + * recommended by OMG, but not all implementations respond that error message + * by re-sending the request, encoded in the older version. + */ + public void setMaxVersion(Version max_supported) + { + max_version = max_supported; + } + + /** + * Get the maximal supported GIOP version or null if the version is not + * checked. + */ + public Version getMaxVersion() + { + return max_version; + } + + /** + * Get the currently free port, starting from the initially set port and going + * up max 20 steps, then trying to bind into any free address. + * + * @return the currently available free port. + * + * @throws NO_RESOURCES if the server socked cannot be opened on the local + * host. + */ + public int getFreePort() + throws BAD_OPERATION + { + ServerSocket s; + int a_port; + + try + { + // If there are some previously freed ports, use them first. + if (!freed_ports.isEmpty()) + { + Integer free = (Integer) freed_ports.getLast(); + freed_ports.removeLast(); + s = socketFactory.createServerSocket(free.intValue()); + s.close(); + return free.intValue(); + } + } + catch (Exception ex) + { + // This may be thrown if the request for the new port has arrived + // before the current service is completly shutdown. + // OK then, use a new port. + } + + for (a_port = Port; a_port < Port + 20; a_port++) + { + try + { + s = socketFactory.createServerSocket(a_port); + s.close(); + Port = a_port + 1; + return a_port; + } + catch (IOException ex) + { + // Repeat the loop if this exception has been thrown. + } + } + + Random rand = new Random(); + // Try any random port in the interval RANDOM_PORT_FROM.RANDOM_PORT_TO. + int range = RANDOM_PORT_TO - RANDOM_PORT_FROM; + IOException ioex = null; + for (int i = 0; i < RANDOM_PORT_ATTEMPTS; i++) + { + try + { + a_port = RANDOM_PORT_FROM + rand.nextInt(range); + s = socketFactory.createServerSocket(a_port); + s.close(); + return a_port; + } + catch (IOException ex) + { + // Repeat the loop if this exception has been thrown. + ioex = ex; + } + } + + NO_RESOURCES bad = new NO_RESOURCES("Unable to open the server socket."); + bad.minor = Minor.Ports; + if (ioex != null) + bad.initCause(ioex); + throw bad; + } + + /** + * Set the port, on that the server is listening for the client requests. If + * only one object is connected to the orb, the server will be try listening + * on this port first. It the port is busy, or if more objects are connected, + * the subsequent object will receive a larger port values, skipping + * unavailable ports, if required. The change applies globally. + * + * @param a_Port a port, on that the server is listening for requests. + */ + public static void setPort(int a_Port) + { + Port = a_Port; + } + + /** + * Connect the given CORBA object to this ORB. After the object is connected, + * it starts receiving remote invocations via this ORB. + * + * The ORB tries to connect the object to the port, that has been previously + * set by {@link setPort(int)}. On failure, it tries 20 subsequent larger + * values and then calls the parameterless server socked constructor to get + * any free local port. If this fails, the {@link NO_RESOURCES} is thrown. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect(org.omg.CORBA.Object object) + { + int a_port = getFreePort(); + + Connected_objects.cObject ref = connected_objects.add(object, a_port); + IOR ior = createIOR(ref); + prepareObject(object, ior); + if (running) + startService(ior); + } + + /** + * Connect the given CORBA object to this ORB, explicitly specifying the + * object key. + * + * The ORB tries to connect the object to the port, that has been previously + * set by {@link setPort(int)}. On failure, it tries 20 subsequent larger + * values and then calls the parameterless server socked constructor to get + * any free local port. If this fails, the {@link NO_RESOURCES} is thrown. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * @param key the object key, usually used to identify the object from remote + * side. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect(org.omg.CORBA.Object object, byte[] key) + { + int a_port = getFreePort(); + + Connected_objects.cObject ref = + connected_objects.add(key, object, a_port, null); + IOR ior = createIOR(ref); + prepareObject(object, ior); + if (running) + startService(ior); + } + + /** + * Connect the given CORBA object to this ORB, explicitly specifying the + * object key and the identity of the thread (and port), where the object must + * be served. The identity is normally the POA. + * + * The new port server will be started only if there is no one already running + * for the same identity. Otherwise, the task of the existing port server will + * be widened, including duty to serve the given object. All objects, + * connected to a single identity by this method, will process they requests + * subsequently in the same thread. The method is used when the expected + * number of the objects is too large to have a single port and thread per + * object. This method is used by POAs, having a single thread policy. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * @param key the object key, usually used to identify the object from remote + * side. + * @param port the port, where the object must be connected. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect_1_thread(org.omg.CORBA.Object object, byte[] key, + java.lang.Object identity + ) + { + sharedPortServer shared = (sharedPortServer) identities.get(identity); + if (shared == null) + { + int a_port = getFreePort(); + shared = new sharedPortServer(a_port); + identities.put(identity, shared); + if (running) + { + portServers.add(shared); + shared.start(); + } + } + + Connected_objects.cObject ref = + connected_objects.add(key, object, shared.s_port, identity); + IOR ior = createIOR(ref); + prepareObject(object, ior); + } + + /** + * Start the service on the given port of this IOR. + * + * @param ior the ior (only Internet.port is used). + */ + public void startService(IOR ior) + { + portServer p = new portServer(ior.Internet.port); + portServers.add(p); + p.start(); + } + + /** + * Destroy this server, releasing the occupied resources. + */ + public void destroy() + { + portServer p; + for (int i = 0; i < portServers.size(); i++) + { + p = (portServer) portServers.get(i); + p.close_now(); + } + super.destroy(); + } + + /** + * Disconnect the given CORBA object from this ORB. The object will be no + * longer receiving the remote invocations. In response to the remote + * invocation on this object, the ORB will send the exception + * {@link OBJECT_NOT_EXIST}. The object, however, is not destroyed and can + * receive the local invocations. + * + * @param object the object to disconnect. + */ + public void disconnect(org.omg.CORBA.Object object) + { + Connected_objects.cObject rmKey = null; + + // Handle the case when it is possible to get the object key. + // Handle the case when the object is known, but not local. + if (object instanceof ObjectImpl) + { + Delegate delegate = ((ObjectImpl) object)._get_delegate(); + if (delegate instanceof SimpleDelegate) + { + byte[] key = ((SimpleDelegate) delegate).getIor().key; + rmKey = connected_objects.get(key); + } + } + + // Try to find and disconned the object that is not an instance of the + // object implementation. + if (rmKey == null) + rmKey = connected_objects.getKey(object); + if (rmKey != null) + { + // Find and stop the corresponding portServer. + portServer p; + StopService: + for (int i = 0; i < portServers.size(); i++) + { + p = (portServer) portServers.get(i); + if (p.s_port == rmKey.port && !(p instanceof sharedPortServer)) + { + p.close_now(); + freed_ports.addFirst(new Integer(rmKey.port)); + break StopService; + } + connected_objects.remove(rmKey.key); + } + } + } + + /** + * Notifies ORB that the shared service indentity (usually POA) is destroyed. + * The matching shared port server is terminated and the identity table entry + * is deleted. If this identity is not known for this ORB, the method returns + * without action. + * + * @param identity the identity that has been destroyed. + */ + public void identityDestroyed(java.lang.Object identity) + { + if (identity == null) + return; + + sharedPortServer ise = (sharedPortServer) identities.get(identity); + if (ise != null) + { + synchronized (connected_objects) + { + ise.close_now(); + identities.remove(identity); + + Connected_objects.cObject obj; + Map.Entry m; + Iterator iter = connected_objects.entrySet().iterator(); + while (iter.hasNext()) + { + m = (Map.Entry) iter.next(); + obj = (Connected_objects.cObject) m.getValue(); + if (obj.identity == identity) + iter.remove(); + } + } + } + } + + /** + * Find the local object, connected to this ORB. + * + * @param ior the ior of the potentially local object. + * + * @return the local object, represented by the given IOR, or null if this is + * not a local connected object. + */ + public org.omg.CORBA.Object find_local_object(IOR ior) + { + // Must be the same host. + if (!ior.Internet.host.equals(LOCAL_HOST)) + return null; + + return find_connected_object(ior.key, ior.Internet.port); + } + + /** + * List the initially available CORBA objects (services). + * + * @return a list of services. + * + * @see resolve_initial_references(String) + */ + public String[] list_initial_services() + { + String[] refs = new String[ initial_references.size() ]; + int p = 0; + + Iterator iter = initial_references.keySet().iterator(); + while (iter.hasNext()) + { + refs [ p++ ] = (String) iter.next(); + } + return refs; + } + + /** + * Get the IOR reference string for the given object. The string embeds + * information about the object repository Id, its access key and the server + * internet address and port. With this information, the object can be found + * by another ORB, possibly located on remote computer. + * + * @param the CORBA object + * @return the object IOR representation. + * + * @throws BAD_PARAM if the object has not been previously connected to this + * ORB. + * + * @throws BAD_OPERATION in the unlikely case if the local host address cannot + * be resolved. + * + * @see string_to_object(String) + */ + public String object_to_string(org.omg.CORBA.Object forObject) + { + // Handle the case when the object is known, but not local. + if (forObject instanceof ObjectImpl) + { + Delegate delegate = ((ObjectImpl) forObject)._get_delegate(); + if (delegate instanceof SimpleDelegate) + return ((SimpleDelegate) delegate).getIor().toStringifiedReference(); + } + + // Handle the case when the object is local. + Connected_objects.cObject rec = connected_objects.getKey(forObject); + + if (rec == null) + throw new BAD_PARAM("The object " + forObject + + " has not been previously connected to this ORB" + ); + + IOR ior = createIOR(rec); + + return ior.toStringifiedReference(); + } + + /** + * Get the local IOR for the given object, null if the object is not local. + */ + public IOR getLocalIor(org.omg.CORBA.Object forObject) + { + Connected_objects.cObject rec = connected_objects.getKey(forObject); + if (rec == null) + return null; + else + return createIOR(rec); + } + + /** + * Find and return the easily accessible CORBA object, addressed by name. + * + * @param name the object name. + * @return the object + * + * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name is not + * associated with the known object. + */ + public org.omg.CORBA.Object resolve_initial_references(String name) + throws InvalidName + { + org.omg.CORBA.Object object = null; + try + { + object = (org.omg.CORBA.Object) initial_references.get(name); + if (object == null && name.equals(NAME_SERVICE)) + { + object = getDefaultNameService(); + if (object != null) + initial_references.put(NAME_SERVICE, object); + } + } + catch (Exception ex) + { + InvalidName err = new InvalidName(name); + err.initCause(ex); + throw err; + } + if (object != null) + return object; + else + throw new InvalidName("Not found: '" + name + "'"); + } + + /** + * Start the ORBs main working cycle (receive invocation - invoke on the local + * object - send response - wait for another invocation). + * + * The method only returns after calling {@link #shutdown(boolean)}. + */ + public void run() + { + running = true; + + // Instantiate the port server for each socket. + Iterator iter = connected_objects.entrySet().iterator(); + Map.Entry m; + Connected_objects.cObject obj; + + while (iter.hasNext()) + { + m = (Map.Entry) iter.next(); + obj = (Connected_objects.cObject) m.getValue(); + + portServer subserver; + + if (obj.identity == null) + { + subserver = new portServer(obj.port); + portServers.add(subserver); + } + else + subserver = (portServer) identities.get(obj.identity); + + if (!subserver.isAlive()) + { + // Reuse the current thread for the last portServer. + if (!iter.hasNext()) + { + // Discard the iterator, eliminating lock checks. + iter = null; + subserver.run(); + return; + } + else + subserver.start(); + } + } + } + + /** + * Start the server in a new thread, if not already running. This method is + * used to ensure that the objects being transfered will be served from the + * remote side, if required. If the ORB is started using this method, it + * starts as a daemon thread. + */ + public void ensureRunning() + { + final OrbFunctional THIS = this; + + if (!running) + { + Thread t = new Thread() + { + public void run() + { + THIS.run(); + } + }; + t.setDaemon(true); + t.start(); + } + } + + /** + * Shutdown the ORB server. + * + * @param wait_for_completion if true, the current thread is suspended until + * the shutdown process is complete. + */ + public void shutdown(boolean wait_for_completion) + { + super.shutdown(wait_for_completion); + running = false; + + if (!wait_for_completion) + { + for (int i = 0; i < portServers.size(); i++) + { + portServer p = (portServer) portServers.get(i); + p.close_now(); + } + } + } + + /** + * Find and return the CORBA object, addressed by the given IOR string + * representation. The object can (an usually is) located on a remote + * computer, possibly running a different (not necessary java) CORBA + * implementation. + * + * @param ior the object IOR representation string. + * + * @return the found CORBA object. + * @see object_to_string(org.omg.CORBA.Object) + */ + public org.omg.CORBA.Object string_to_object(String an_ior) + { + return nameParser.corbaloc(an_ior, this); + } + + /** + * Convert ior reference to CORBA object. + */ + public org.omg.CORBA.Object ior_to_object(IOR ior) + { + org.omg.CORBA.Object object = find_local_object(ior); + if (object == null) + { + ObjectImpl impl = StubLocator.search(this, ior); + try + { + if (impl._get_delegate() == null) + impl._set_delegate(new IorDelegate(this, ior)); + } + catch (BAD_OPERATION ex) + { + // Some colaborants may throw this exception + // in response to the attempt to get the unset delegate. + impl._set_delegate(new IorDelegate(this, ior)); + } + + object = impl; + // TODO remove commented out code below. + // connected_objects.add(ior.key, impl, ior.Internet.port, null); + } + return object; + } + + /** + * Get the default naming service for the case when there no NameService + * entries. + */ + protected org.omg.CORBA.Object getDefaultNameService() + { + if (initial_references.containsKey(NAME_SERVICE)) + return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE); + + IOR ior = new IOR(); + ior.Id = NamingContextExtHelper.id(); + ior.Internet.host = ns_host; + ior.Internet.port = ns_port; + ior.key = NamingServiceTransient.getDefaultKey(); + + IorObject iorc = new IorObject(this, ior); + NamingContextExt namer = NamingContextExtHelper.narrow(iorc); + initial_references.put(NAME_SERVICE, namer); + return namer; + } + + /** + * Find and return the object, that must be previously connected to this ORB. + * Return null if no such object is available. + * + * @param key the object key. + * @param port the port where the object is connected. + * + * @return the connected object, null if none. + */ + protected org.omg.CORBA.Object find_connected_object(byte[] key, int port) + { + Connected_objects.cObject ref = connected_objects.get(key); + if (ref == null) + return null; + if (port >= 0 && ref.port != port) + return null; + else + return ref.object; + } + + /** + * Set the ORB parameters. This method is normally called from + * {@link #init(Applet, Properties)}. + * + * @param app the current applet. + * + * @param props application specific properties, passed as the second + * parameter in {@link #init(Applet, Properties)}. Can be null. + */ + protected void set_parameters(Applet app, Properties props) + { + useProperties(props); + + String[][] para = app.getParameterInfo(); + if (para != null) + { + for (int i = 0; i < para.length; i++) + { + if (para[i][0].equals(LISTEN_ON)) + Port = Integer.parseInt(para[i][1]); + if (para[i][0].equals(REFERENCE)) + { + StringTokenizer st = new StringTokenizer(para[i][1], "="); + initial_references.put(st.nextToken(), + string_to_object(st.nextToken())); + } + + if (para[i][0].equals(ORB_ID)) + orb_id = para[i][1]; + + if (para[i][0].equals(SERVER_ID)) + server_id = para[i][1]; + + if (para[i][0].equals(NS_HOST)) + ns_host = para[i][1]; + if (para[i][0].equals(START_READING_MESSAGE)) + TOUT_START_READING_MESSAGE = Integer.parseInt(para[i][1]); + if (para[i][0].equals(WHILE_READING)) + TOUT_WHILE_READING = Integer.parseInt(para[i][1]); + if (para[i][0].equals(AFTER_RECEIVING)) + TOUT_AFTER_RECEIVING = Integer.parseInt(para[i][1]); + try + { + if (para[i][0].equals(NS_PORT)) + ns_port = Integer.parseInt(para[i][1]); + } + catch (NumberFormatException ex) + { + BAD_PARAM bad = new BAD_PARAM("Invalid " + NS_PORT + + "property, unable to parse '" + props.getProperty(NS_PORT) + + "'"); + bad.initCause(ex); + throw bad; + } + } + } + } + + /** + * Set the ORB parameters. This method is normally called from + * {@link #init(String[], Properties)}. + * + * @param para the parameters, that were passed as the parameters to the + * main(String[] args) method of the current standalone + * application. + * + * @param props application specific properties that were passed as a second + * parameter in {@link init(String[], Properties)}). Can be null. + */ + protected void set_parameters(String[] para, Properties props) + { + if (para.length > 1) + { + for (int i = 0; i < para.length - 1; i++) + { + if (para[i].endsWith("ListenOn")) + Port = Integer.parseInt(para[i + 1]); + if (para[i].endsWith("ORBInitRef")) + { + StringTokenizer st = new StringTokenizer(para[i + 1], "="); + initial_references.put(st.nextToken(), + string_to_object(st.nextToken())); + } + + if (para[i].endsWith("ORBInitialHost")) + ns_host = para[i + 1]; + + if (para[i].endsWith("ServerId")) + server_id = para[i++]; + else if (para[i].endsWith("ORBid")) + orb_id = para[i++]; + + try + { + if (para[i].endsWith("ORBInitialPort")) + ns_port = Integer.parseInt(para[i + 1]); + } + catch (NumberFormatException ex) + { + throw new BAD_PARAM("Invalid " + para[i] + + "parameter, unable to parse '" + + props.getProperty(para[i + 1]) + "'"); + } + } + } + + useProperties(props); + } + + /** + * Create IOR for the given object references. + */ + protected IOR createIOR(Connected_objects.cObject ref) + throws BAD_OPERATION + { + IOR ior = new IOR(); + ior.key = ref.key; + ior.Internet.port = ref.port; + + if (ref.object instanceof ObjectImpl) + { + ObjectImpl imp = (ObjectImpl) ref.object; + if (imp._ids().length > 0) + ior.Id = imp._ids() [ 0 ]; + } + if (ior.Id == null) + ior.Id = ref.object.getClass().getName(); + try + { + ior.Internet.host = InetAddress.getLocalHost().getHostAddress(); + ior.Internet.port = ref.port; + } + catch (UnknownHostException ex) + { + throw new BAD_OPERATION("Cannot resolve the local host address"); + } + return ior; + } + + /** + * Prepare object for connecting it to this ORB. + * + * @param object the object being connected. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + protected void prepareObject(org.omg.CORBA.Object object, IOR ior) + throws BAD_PARAM + { + /* + * if (!(object instanceof InvokeHandler)) throw new + * BAD_PARAM(object.getClass().getName() + " does not implement + * InvokeHandler. " ); + */ + + // If no delegate is set, set the default delegate. + if (object instanceof ObjectImpl) + { + ObjectImpl impl = (ObjectImpl) object; + try + { + if (impl._get_delegate() == null) + impl._set_delegate(new SimpleDelegate(this, ior)); + } + catch (BAD_OPERATION ex) + { + // Some colaborants may throw this exception. + impl._set_delegate(new SimpleDelegate(this, ior)); + } + } + } + + /** + * Write the response message. + * + * @param net_out the stream to write response into + * @param msh_request the request message header + * @param rh_request the request header + * @param handler the invocation handler that has been used to invoke the + * operation + * @param sysEx the system exception, thrown during the invocation, null if + * none. + * + * @throws IOException + */ + private void respond_to_client(OutputStream net_out, + MessageHeader msh_request, RequestHeader rh_request, + ResponseHandlerImpl handler, SystemException sysEx + ) throws IOException + { + // Set the reply header properties. + ReplyHeader reply = handler.reply_header; + + if (sysEx != null) + reply.reply_status = ReplyHeader.SYSTEM_EXCEPTION; + else if (handler.isExceptionReply()) + reply.reply_status = ReplyHeader.USER_EXCEPTION; + else + reply.reply_status = ReplyHeader.NO_EXCEPTION; + reply.request_id = rh_request.request_id; + + BufferedCdrOutput out = + new BufferedCdrOutput(50 + handler.getBuffer().buffer.size()); + out.setOrb(this); + + out.setOffset(msh_request.getHeaderSize()); + + reply.write(out); + + if (msh_request.version.since_inclusive(1, 2)) + { + out.align(8); + + // Write the reply data from the handler. The handler data already + // include the necessary heading zeroes for alignment. + } + handler.getBuffer().buffer.writeTo(out); + + MessageHeader msh_reply = new MessageHeader(); + + msh_reply.version = msh_request.version; + msh_reply.message_type = MessageHeader.REPLY; + msh_reply.message_size = out.buffer.size(); + + // Write the reply. + msh_reply.write(net_out); + out.buffer.writeTo(net_out); + net_out.flush(); + } + + /** + * Forward request to another target, as indicated by the passed exception. + */ + private void forward_request(OutputStream net_out, + MessageHeader msh_request, RequestHeader rh_request, gnuForwardRequest info + ) throws IOException + { + MessageHeader msh_forward = new MessageHeader(); + msh_forward.version = msh_request.version; + + ReplyHeader rh_forward = msh_forward.create_reply_header(); + msh_forward.message_type = MessageHeader.REPLY; + rh_forward.reply_status = info.forwarding_code; + rh_forward.request_id = rh_request.request_id; + + // The forwarding code is either LOCATION_FORWARD or LOCATION_FORWARD_PERM. + BufferedCdrOutput out = new BufferedCdrOutput(); + out.setOrb(this); + out.setOffset(msh_forward.getHeaderSize()); + + rh_forward.write(out); + + if (msh_forward.version.since_inclusive(1, 2)) + out.align(8); + out.write_Object(info.forward_reference); + + msh_forward.message_size = out.buffer.size(); + + // Write the forwarding instruction. + msh_forward.write(net_out); + out.buffer.writeTo(net_out); + net_out.flush(); + } + + /** + * Contains a single servicing task. + * + * Normally, each task matches a single remote invocation. However under + * frequent tandem submissions the same task may span over several + * invocations. + * + * @param serverSocket the ORB server socket. + * + * @throws MARSHAL + * @throws IOException + */ + void serve(final portServer p, ServerSocket serverSocket) + throws MARSHAL, IOException + { + final Socket service; + service = serverSocket.accept(); + + // Tell the server there are no more resources. + if (p.running_threads >= MAX_RUNNING_THREADS) + { + serveStep(service, true); + return; + } + + new Thread() + { + public void run() + { + try + { + synchronized (p) + { + p.running_threads++; + } + serveStep(service, false); + } + finally + { + synchronized (p) + { + p.running_threads--; + } + } + } + }.start(); + } + + /** + * A single servicing step, when the client socket is alrady open. + * + * Normally, each task matches a single remote invocation. However under + * frequent tandem submissions the same task may span over several + * invocations. + * + * @param service the opened client socket. + * @param no_resources if true, the "NO RESOURCES" exception is thrown to the + * client. + */ + void serveStep(Socket service, boolean no_resources) + { + try + { + Serving: while (true) + { + InputStream in = service.getInputStream(); + service.setSoTimeout(TOUT_START_READING_MESSAGE); + + MessageHeader msh_request = new MessageHeader(); + + try + { + msh_request.read(in); + } + catch (MARSHAL ex) + { + // This exception may be thrown due closing the connection. + return; + } + + if (max_version != null) + { + if (!msh_request.version.until_inclusive(max_version.major, + max_version.minor)) + { + OutputStream out = service.getOutputStream(); + new ErrorMessage(max_version).write(out); + return; + } + } + + byte[] r = msh_request.readMessage(in, service, TOUT_WHILE_READING, + TOUT_AFTER_RECEIVING); + + if (msh_request.message_type == MessageHeader.REQUEST) + { + RequestHeader rh_request; + + BufferredCdrInput cin = new BufferredCdrInput(r); + cin.setOrb(this); + cin.setVersion(msh_request.version); + cin.setOffset(msh_request.getHeaderSize()); + cin.setBigEndian(msh_request.isBigEndian()); + + rh_request = msh_request.create_request_header(); + + // Read header and auto set the charset. + rh_request.read(cin); + + // in 1.2 and higher, align the current position at + // 8 octet boundary. + if (msh_request.version.since_inclusive(1, 2)) + { + cin.align(8); + + // find the target object. + } + + InvokeHandler target = (InvokeHandler) find_connected_object( + rh_request.object_key, -1); + + // Prepare the reply header. This must be done in advance, + // as the size must be known for handler to set alignments + // correctly. + ReplyHeader rh_reply = msh_request.create_reply_header(); + + // TODO log errors about not existing objects and methods. + ResponseHandlerImpl handler = new ResponseHandlerImpl( + this, msh_request, rh_reply, rh_request); + + SystemException sysEx = null; + + try + { + if (no_resources) + { + NO_RESOURCES no = new NO_RESOURCES("Too many parallel calls"); + no.minor = Minor.Threads; + throw no; + } + if (target == null) + throw new OBJECT_NOT_EXIST(); + target._invoke(rh_request.operation, cin, handler); + } + catch (gnuForwardRequest forwarded) + { + OutputStream sou = service.getOutputStream(); + forward_request(sou, msh_request, rh_request, forwarded); + if (service != null && !service.isClosed()) + { + // Wait for the subsequent invocations on the + // same socket for the TANDEM_REQUEST duration. + service.setSoTimeout(TANDEM_REQUESTS); + continue Serving; + } + } + catch (UnknownException uex) + { + sysEx = new UNKNOWN("Unknown", 2, + CompletionStatus.COMPLETED_MAYBE); + sysEx.initCause(uex.originalEx); + + org.omg.CORBA.portable.OutputStream ech = handler.createExceptionReply(); + + rh_reply.service_context = UnknownExceptionCtxHandler.addExceptionContext( + rh_reply.service_context, uex.originalEx, ech); + + ObjectCreator.writeSystemException(ech, sysEx); + } + catch (SystemException ex) + { + sysEx = ex; + + org.omg.CORBA.portable.OutputStream ech = handler.createExceptionReply(); + + rh_reply.service_context = UnknownExceptionCtxHandler.addExceptionContext( + rh_reply.service_context, ex, ech); + + ObjectCreator.writeSystemException(ech, ex); + } + catch (Exception except) + { + // This should never happen under normal operation and + // can only indicate errors in user object implementation. + // We inform the user. + except.printStackTrace(); + + sysEx = new UNKNOWN("Unknown", 2, + CompletionStatus.COMPLETED_MAYBE); + sysEx.initCause(except); + + org.omg.CORBA.portable.OutputStream ech = handler.createExceptionReply(); + + rh_reply.service_context = UnknownExceptionCtxHandler.addExceptionContext( + rh_reply.service_context, except, ech); + + ObjectCreator.writeSystemException(ech, sysEx); + } + + // Write the response. + if (rh_request.isResponseExpected()) + { + OutputStream sou = service.getOutputStream(); + respond_to_client(sou, msh_request, rh_request, handler, + sysEx); + } + } + else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION + || msh_request.message_type == MessageHeader.MESSAGE_ERROR) + { + CloseMessage.close(service.getOutputStream()); + service.close(); + return; + } + + if (service != null && !service.isClosed()) + + // Wait for the subsequent invocations on the + // same socket for the TANDEM_REQUEST duration. + service.setSoTimeout(TANDEM_REQUESTS); + else + return; + } + } + catch (SocketException ex) + { + // OK. + return; + } + catch (IOException ioex) + { + // Network error, probably transient. + // TODO log it. + return; + } + } + + /** + * Set the ORB parameters from the properties that were accumulated + * from several locations. + */ + protected void useProperties(Properties props) + { + if (props != null) + { + if (props.containsKey(LISTEN_ON)) + Port = Integer.parseInt(props.getProperty(LISTEN_ON)); + if (props.containsKey(NS_HOST)) + ns_host = props.getProperty(NS_HOST); + try + { + if (props.containsKey(NS_PORT)) + ns_port = Integer.parseInt(props.getProperty(NS_PORT)); + if (props.containsKey(START_READING_MESSAGE)) + TOUT_START_READING_MESSAGE = + Integer.parseInt(props.getProperty(START_READING_MESSAGE)); + if (props.containsKey(WHILE_READING)) + TOUT_WHILE_READING = + Integer.parseInt(props.getProperty(WHILE_READING)); + if (props.containsKey(AFTER_RECEIVING)) + TOUT_AFTER_RECEIVING = + Integer.parseInt(props.getProperty(AFTER_RECEIVING)); + if (props.containsKey(SERVER_ERROR_PAUSE)) + TWAIT_SERVER_ERROR_PAUSE = + Integer.parseInt(props.getProperty(SERVER_ERROR_PAUSE)); + } + catch (NumberFormatException ex) + { + throw new BAD_PARAM("Invalid " + NS_PORT + + "property, unable to parse '" + props.getProperty(NS_PORT) + + "'" + ); + } + + if (props.containsKey(SocketFactory.PROPERTY)) + { + String factory = null; + try + { + factory = props.getProperty(SocketFactory.PROPERTY); + if (factory!=null) + socketFactory = (SocketFactory) + ObjectCreator.forName(factory).newInstance(); + } + catch (Exception ex) + { + BAD_PARAM p = new BAD_PARAM("Bad socket factory "+factory); + p.initCause(ex); + throw p; + } + } + + if (props.containsKey(ORB_ID)) + orb_id = props.getProperty(ORB_ID); + + if (props.containsKey(SERVER_ID)) + server_id = props.getProperty(SERVER_ID); + + Enumeration en = props.elements(); + while (en.hasMoreElements()) + { + String item = (String) en.nextElement(); + if (item.equals(REFERENCE)) + initial_references.put(item, + string_to_object(props.getProperty(item)) + ); + } + } + } + + /** + * Get the next instance with a response being received. If all currently sent + * responses not yet processed, this method pauses till at least one of them + * is complete. If there are no requests currently sent, the method pauses + * till some request is submitted and the response is received. This strategy + * is identical to the one accepted by Suns 1.4 ORB implementation. + * + * The returned response is removed from the list of the currently submitted + * responses and is never returned again. + * + * @return the previously sent request that now contains the received + * response. + * + * @throws WrongTransaction If the method was called from the transaction + * scope different than the one, used to send the request. The exception can + * be raised only if the request is implicitly associated with some particular + * transaction. + */ + public Request get_next_response() throws org.omg.CORBA.WrongTransaction + { + return asynchron.get_next_response(); + } + + /** + * Find if any of the requests that have been previously sent with + * {@link #send_multiple_requests_deferred}, have a response yet. + * + * @return true if there is at least one response to the previously sent + * request, false otherwise. + */ + public boolean poll_next_response() + { + return asynchron.poll_next_response(); + } + + /** + * Send multiple prepared requests expecting to get a reply. All requests are + * send in parallel, each in its own separate thread. When the reply arrives, + * it is stored in the agreed fields of the corresponing request data + * structure. If this method is called repeatedly, the new requests are added + * to the set of the currently sent requests, but the old set is not + * discarded. + * + * @param requests the prepared array of requests. + * + * @see #poll_next_response() + * @see #get_next_response() + * @see Request#send_deferred() + */ + public void send_multiple_requests_deferred(Request[] requests) + { + asynchron.send_multiple_requests_deferred(requests); + } + + /** + * Send multiple prepared requests one way, do not caring about the answer. + * The messages, containing requests, will be marked, indicating that the + * sender is not expecting to get a reply. + * + * @param requests the prepared array of requests. + * + * @see Request#send_oneway() + */ + public void send_multiple_requests_oneway(Request[] requests) + { + asynchron.send_multiple_requests_oneway(requests); + } + + /** + * Set the flag, forcing all server threads to terminate. + */ + protected void finalize() throws java.lang.Throwable + { + running = false; + super.finalize(); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/OrbRestricted.java b/libjava/classpath/gnu/CORBA/OrbRestricted.java new file mode 100644 index 0000000..c040180 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/OrbRestricted.java @@ -0,0 +1,529 @@ +/* RestrictedORB.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferedCdrOutput; +import gnu.CORBA.typecodes.AliasTypeCode; +import gnu.CORBA.typecodes.ArrayTypeCode; +import gnu.CORBA.typecodes.RecordTypeCode; +import gnu.CORBA.typecodes.StringTypeCode; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.Environment; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.Request; +import org.omg.CORBA.StructMember; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.UnionMember; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ValueFactory; +import org.omg.PortableInterceptor.ClientRequestInterceptorOperations; +import org.omg.PortableInterceptor.IORInterceptorOperations; +import org.omg.PortableInterceptor.IORInterceptor_3_0Operations; +import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; + +import java.applet.Applet; + +import java.util.Hashtable; +import java.util.Properties; + +/** + * This class implements so-called Singleton ORB, a highly restricted version + * that cannot communicate over network. This ORB is provided for the + * potentially malicious applets with heavy security restrictions. It, however, + * supports some basic features that might be needed even when the network + * access is not granted. + * + * This ORB can only create typecodes, {@link Any}, {@link ContextList}, + * {@link NVList} and {@link org.omg.CORBA.portable.OutputStream} that writes to + * an internal buffer. + * + * All other methods throw the {@link NO_IMPLEMENT} exception. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class OrbRestricted extends org.omg.CORBA_2_3.ORB +{ + /** + * The singleton instance of this ORB. + */ + public static final ORB Singleton = new OrbRestricted(); + + /** + * The cumulated listener for all IOR interceptors. Interceptors are used by + * {@link gnu.CORBA.Poa.ORB_1_4}. + */ + public IORInterceptor_3_0Operations iIor; + + /** + * The cumulated listener for all server request interceptors. Interceptors + * are used by {@link gnu.CORBA.Poa.ORB_1_4}. + */ + public ServerRequestInterceptorOperations iServer; + + /** + * The cumulated listener for all client request interceptros. Interceptors + * are used by {@link gnu.CORBA.Poa.ORB_1_4}. + */ + public ClientRequestInterceptorOperations iClient; + + /** + * The required size of the interceptor slot array. + */ + public int icSlotSize = 0; + + /** + * The value factories. + */ + protected Hashtable factories = new Hashtable(); + + /** + * The policy factories. + */ + protected Hashtable policyFactories = new Hashtable(); + + /** + * Create a new instance of the RestrictedORB. This is used in derived classes + * only. + */ + protected OrbRestricted() + { + } + + /** {@inheritDoc} */ + public TypeCode create_alias_tc(String id, String name, TypeCode typecode) + { + return new AliasTypeCode(typecode, id, name); + } + + /** {@inheritDoc} */ + public Any create_any() + { + gnuAny any = new gnuAny(); + any.setOrb(this); + return any; + } + + /** {@inheritDoc} */ + public TypeCode create_array_tc(int length, TypeCode element_type) + { + ArrayTypeCode p = + new ArrayTypeCode(TCKind.tk_array, element_type); + p.setLength(length); + return p; + } + + /** {@inheritDoc} */ + public ContextList create_context_list() + { + return new gnuContextList(); + } + + /** {@inheritDoc} */ + public TypeCode create_enum_tc(String id, String name, String[] values) + { + RecordTypeCode r = new RecordTypeCode(TCKind.tk_enum); + for (int i = 0; i < values.length; i++) + { + r.field().name = values [ i ]; + } + + r.setId(id); + r.setName(name); + + return r; + } + + /** {@inheritDoc} */ + public Environment create_environment() + { + return new gnuEnvironment(); + } + + /** {@inheritDoc} */ + public ExceptionList create_exception_list() + { + return new gnuExceptionList(); + } + + /** {@inheritDoc} */ + public TypeCode create_exception_tc(String id, String name, + StructMember[] members + ) + { + RecordTypeCode r = new RecordTypeCode(TCKind.tk_except); + r.setId(id); + r.setName(name); + + for (int i = 0; i < members.length; i++) + { + r.add(members [ i ]); + } + + return r; + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public TypeCode create_interface_tc(String id, String name) + { + no(); + return null; + } + + /** {@inheritDoc} */ + public NVList create_list(int count) + { + return new gnuNVList(count); + } + + /** {@inheritDoc} */ + public NamedValue create_named_value(String s, Any any, int flags) + { + return new gnuNamedValue(); + } + + /** {@inheritDoc} */ + public OutputStream create_output_stream() + { + BufferedCdrOutput stream = new BufferedCdrOutput(); + stream.setOrb(this); + return stream; + } + + /** {@inheritDoc} */ + public TypeCode create_sequence_tc(int bound, TypeCode element_type) + { + ArrayTypeCode p = + new ArrayTypeCode(TCKind.tk_sequence, element_type); + p.setLength(bound); + return p; + } + + /** {@inheritDoc} */ + public TypeCode create_string_tc(int bound) + { + StringTypeCode p = new StringTypeCode(TCKind.tk_string); + p.setLength(bound); + return p; + } + + /** {@inheritDoc} */ + public TypeCode create_struct_tc(String id, String name, + StructMember[] members + ) + { + RecordTypeCode r = new RecordTypeCode(TCKind.tk_struct); + r.setId(id); + r.setName(name); + + for (int i = 0; i < members.length; i++) + { + r.add(members [ i ]); + } + + return r; + } + + /** {@inheritDoc} */ + public TypeCode create_union_tc(String id, String name, + TypeCode discriminator_type, UnionMember[] members + ) + { + RecordTypeCode r = new RecordTypeCode(TCKind.tk_union); + r.setId(id); + r.setName(name); + r.setDiscriminator_type(discriminator_type); + r.setDefaultIndex(0); + + for (int i = 0; i < members.length; i++) + { + r.add(members [ i ]); + } + + return r; + } + + /** {@inheritDoc} */ + public TypeCode create_wstring_tc(int bound) + { + StringTypeCode p = new StringTypeCode(TCKind.tk_wstring); + p.setLength(bound); + return p; + } + + /** {@inheritDoc} */ + public TypeCode get_primitive_tc(TCKind tcKind) + { + try + { + return TypeKindNamer.getPrimitveTC(tcKind); + } + catch (BadKind ex) + { + throw new BAD_PARAM("This is not a primitive type code: " + + tcKind.value() + ); + } + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public String[] list_initial_services() + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public String object_to_string(org.omg.CORBA.Object forObject) + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws InvalidName never in this class, but it is thrown in the derived + * classes. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object resolve_initial_references(String name) + throws InvalidName + { + no(); + throw new InternalError(); + } + + /** + * Shutdown the ORB server. + * + * For RestrictedORB, returns witout action. + */ + public void run() + { + } + + /** + * Shutdown the ORB server. + * + * For RestrictedORB, returns witout action. + */ + public void shutdown(boolean wait_for_completion) + { + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object string_to_object(String IOR) + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + protected void set_parameters(Applet app, Properties props) + { + no(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + protected void set_parameters(String[] args, Properties props) + { + no(); + } + + /** + * Throws an exception, stating that the given method is not supported by the + * Restricted ORB. + */ + private final void no() + { + // Apart the programming errors, this can only happen if the + // malicious code is trying to do that it is not allowed. + throw new NO_IMPLEMENT("Use init(args, props) for the functional version."); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public Request get_next_response() throws org.omg.CORBA.WrongTransaction + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public boolean poll_next_response() + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public void send_multiple_requests_deferred(Request[] requests) + { + no(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public void send_multiple_requests_oneway(Request[] requests) + { + no(); + } + + /** + * Register the value factory under the given repository id. + */ + public ValueFactory register_value_factory(String repository_id, + ValueFactory factory + ) + { + factories.put(repository_id, factory); + return factory; + } + + /** + * Unregister the value factroy. + */ + public void unregister_value_factory(String id) + { + factories.remove(id); + } + + /** + * Look for the value factory for the value, having the given repository id. + * The implementation checks for the registered value factories first. If none + * found, it tries to load and instantiate the class, mathing the given naming + * convention. If this faild, null is returned. + * + * @param repository_id a repository id. + * + * @return a found value factory, null if none. + */ + public ValueFactory lookup_value_factory(String repository_id) + { + ValueFactory f = (ValueFactory) factories.get(repository_id); + if (f != null) + { + return f; + } + + f = (ValueFactory) ObjectCreator.createObject(repository_id, + "DefaultFactory" + ); + if (f != null) + { + factories.put(repository_id, f); + } + return f; + } + + /** + * Destroy the interceptors, if they are present. + */ + public void destroy() + { + if (iIor != null) + { + iIor.destroy(); + iIor = null; + } + + if (iServer != null) + { + iServer.destroy(); + iServer = null; + } + + if (iClient != null) + { + iClient.destroy(); + iClient = null; + } + + super.destroy(); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/AOM.java b/libjava/classpath/gnu/CORBA/Poa/AOM.java new file mode 100644 index 0000000..9faf088 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/AOM.java @@ -0,0 +1,382 @@ +/* AOM.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.Poa; + +import gnu.CORBA.ByteArrayComparator; + +import org.omg.PortableServer.Servant; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * Implements the conception of the Active Object Map. + * If the POA supports the RETAIN policy, it maintains an Active + * Object Map, that associates Object Ids with active servants. + * Each association constitutes an active object. We use a single map + * for all POAs on the given orb. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class AOM +{ + /** + * The reference data about the object, placed on the AOM. + */ + public class Obj + { + /** + * Create an initialised instance. + */ + Obj(org.omg.CORBA.Object _object, byte[] _key, Servant _servant, gnuPOA _poa) + { + object = _object; + key = _key; + servant = _servant; + poa = _poa; + } + + /** + * The object. + */ + public final org.omg.CORBA.Object object; + + /** + * The servant, serving the given object. + */ + public Servant servant; + + /** + * The local servant that once served this object. + * This field is used by {@link ForwardedServant} when it discovers that + * the forwarding chaing returns back to the original location. + * It should not be used anywhere else. + */ + Servant primary_servant; + + /** + * The POA, where the object is connected. + */ + public final gnuPOA poa; + + /** + * The object key. + */ + public final byte[] key; + + /** + * If true, this entry is deactivated. + */ + public boolean deactivated; + + /** + * Set the servant value, preserving any non null + * value as the primary servant. + */ + public void setServant(Servant s) + { + if (primary_servant == null) + primary_servant = s; + servant = s; + } + + /** + * Get the servant. + */ + public Servant getServant() + { + return servant; + } + + /** + * Get the deactivation state. + */ + public boolean isDeactiveted() + { + return deactivated; + } + + /** + * Set the deactivation state. + */ + public void setDeactivated(boolean state) + { + deactivated = state; + } + } + + /** + * The free number to give for the next instance. + * This field is incremented each time the + * new collection of the connected objects is created. + * Each collection has its own unique instance number. + */ + private static long free_id; + + /** + * The map of the all connected objects, maps the object key to the + * object. + */ + Map objects = new TreeMap(new ByteArrayComparator()); + + /** + * Get the record of the stored object. If the object is mapped + * several times under the different keys, one of the mappings + * is used. + * + * @param object the stored object + * + * @return the record about the stored object, null if + * this object is not stored here. + */ + public Obj findObject(org.omg.CORBA.Object stored_object) + { + if (stored_object == null) + return null; + + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + Obj ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (Obj) item.getValue(); + if (stored_object.equals(ref.object)) + return ref; + } + return null; + } + + /** + * Find the reference info for the given servant. + * If the servant is mapped to several objects, this + * returns the first found occurence. + * + * @param servant a servant to find. + * + * @return the servant/object/POA binding or null if no such found. + */ + public Obj findServant(Servant servant) + { + if (servant == null) + return null; + + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + Obj ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (Obj) item.getValue(); + if (servant.equals(ref.servant)) + return ref; + } + return null; + } + + /** + * Find the reference info for the given servant. + * If the servant is mapped to several objects, this + * returns the first found occurence. + * + * @param servant a servant to find. + * @param speficies if to search for the inactive (true) or active + * (false) servant. A servant with unmatching activity is ignored + * by this method. + * + * @return the servant/object/POA binding or null if no such found. + */ + public Obj findServant(Servant servant, boolean inactive) + { + if (servant == null) + return null; + + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + Obj ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (Obj) item.getValue(); + if (ref.deactivated == inactive) + if (ref.servant != null) + if (servant.equals(ref.servant)) + return ref; + } + return null; + } + + /** + * Add the new object to the repository. The object key is + * generated automatically. + * + * @param object the object to add. + * @param servant a servant, serving the given object. + * @param poa the poa, where the object is connected. + * + * @return the newly created object record. + */ + public Obj add(org.omg.CORBA.Object object, Servant servant, gnuPOA poa) + { + return add(generateObjectKey(object), object, servant, poa); + } + + /** + * Add the new object to the repository. + * + * @param key the object key. + * @param object the object to add. + * @param servant a servant, serving the given object. + * @param poa the POA, where the object is connected. + */ + public Obj add(byte[] key, org.omg.CORBA.Object object, Servant servant, + gnuPOA poa + ) + { + Obj rec = new Obj(object, key, servant, poa); + objects.put(key, rec); + return rec; + } + + /** + * Add the new object to the repository. + * + * @param delegate the delegate, providing data about the servant, key, POA + * and object. + * @param port the port that this object would take. + */ + public Obj add(ServantDelegateImpl delegate) + { + Obj rec = + new Obj(delegate.object, delegate.servant_id, delegate.servant, + delegate.poa + ); + objects.put(delegate.servant_id, rec); + return rec; + } + + /** + * Put back the definition structure that has probably been removed earlier. + */ + public void put(Obj obj) + { + objects.put(obj.key, obj); + } + + /** + * Get the stored object. + * + * @param key the key (in the byte array form). + * + * @return the matching object, null if none is matching. + */ + public Obj get(byte[] key) + { + return (Obj) objects.get(key); + } + + /** + * Get the map key set. + */ + public Set keySet() + { + return objects.keySet(); + } + + /** + * Remove the given object, indiciating it by the key. + * + * @param object the object to remove. + */ + public void remove(byte[] key) + { + objects.remove(key); + } + + /** + * Generate the object key, unique in the currently + * running java virtual machine. The passed object + * parameter is currently not in use. + * + * @return the generated key. + */ + protected byte[] generateObjectKey(org.omg.CORBA.Object object) + { + byte[] key; + + // The repetetive keys cannot be generated, but theoretically + // the same keys can be passed when calling add(byte[]...). + // Hence we check if the key is not already in the map and, + // if it is, use the subsequent value. + do + { + key = getFreeId(); + } + while (objects.containsKey(key)); + return key; + } + + /** + * Get the next free 8 byte id, surely unique between calls of this + * method for the currently running virtual machine. + */ + public static synchronized byte[] getFreeId() + { + byte[] r = new byte[ 8 ]; + + // Start from the faster-changing. + r [ 0 ] = ((byte) (0xff & free_id)); + r [ 1 ] = ((byte) (0xff & (free_id >> 8))); + r [ 2 ] = ((byte) (0xff & (free_id >> 16))); + r [ 3 ] = ((byte) (0xff & (free_id >> 24))); + r [ 4 ] = ((byte) (0xff & (free_id >> 32))); + r [ 5 ] = ((byte) (0xff & (free_id >> 40))); + r [ 6 ] = ((byte) (0xff & (free_id >> 48))); + r [ 7 ] = ((byte) (0xff & (free_id >> 56))); + + free_id++; + + return r; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/AccessiblePolicy.java b/libjava/classpath/gnu/CORBA/Poa/AccessiblePolicy.java new file mode 100644 index 0000000..44ebaf4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/AccessiblePolicy.java @@ -0,0 +1,62 @@ +/* AccessiblePolicy.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.Poa; + +import org.omg.CORBA.Policy; + +/** + * The Classpath implementation of the policy, providing the policy + * value and the code of the policy type. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface AccessiblePolicy + extends Policy +{ + /** + * Get the value of this policy + */ + java.lang.Object getValue(); + + /** + * Get the integer code of this policy value. + */ + int getCode(); + +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/DynamicImpHandler.java b/libjava/classpath/gnu/CORBA/Poa/DynamicImpHandler.java new file mode 100644 index 0000000..903f8bf --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/DynamicImpHandler.java @@ -0,0 +1,85 @@ +/* DynamicImpHandler.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.Poa; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.PortableServer.DynamicImplementation; + +/** + * The InvokeHandler, indicating, that the target is a dynamic + * implementation rather than an invoke handler. These two + * types are not substitutable, but in some methods have possibility + * just to handle them differently. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class DynamicImpHandler + implements InvokeHandler +{ + /** + * The servant that is a dynamic implementation rather than + * invoke handler. + */ + public final DynamicImplementation servant; + + /** + * Create a new instance, wrapping some dyn implementation. + * @param _servant + */ + public DynamicImpHandler(DynamicImplementation _servant) + { + servant = _servant; + } + + /** + * We cannot invoke properly without having parameter info. + * + * @throws BAD_OPERATION, always. + */ + public OutputStream _invoke(String method, InputStream input, + ResponseHandler handler + ) + { + throw new BAD_OPERATION(servant + " is not an InvokeHandler."); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/ForwardedServant.java b/libjava/classpath/gnu/CORBA/Poa/ForwardedServant.java index 2df378d..b1d5eaf 100644 --- a/libjava/classpath/gnu/CORBA/Poa/ForwardedServant.java +++ b/libjava/classpath/gnu/CORBA/Poa/ForwardedServant.java @@ -39,8 +39,9 @@ exception statement from your version. */ package gnu.CORBA.Poa; import gnu.CORBA.IOR; -import gnu.CORBA.IOR_Delegate; -import gnu.CORBA.IOR_contructed_object; +import gnu.CORBA.IorDelegate; +import gnu.CORBA.IorObject; +import gnu.CORBA.Minor; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.CompletionStatus; @@ -101,9 +102,9 @@ public class ForwardedServant ObjectImpl fto = (ObjectImpl) a_ref; // Check maybe the remote side forwarded back to our local object. - if (fto instanceof IOR_contructed_object) + if (fto instanceof IorObject) { - IOR_contructed_object iref = (IOR_contructed_object) fto; + IorObject iref = (IorObject) fto; // Check maybe the IOR is local. ORB t_orb = iref._orb(); @@ -111,13 +112,13 @@ public class ForwardedServant { ORB_1_4 orb = (ORB_1_4) t_orb; Delegate d = iref._get_delegate(); - if (d instanceof IOR_Delegate) + if (d instanceof IorDelegate) { - IOR_Delegate ird = (IOR_Delegate) iref._get_delegate(); + IorDelegate ird = (IorDelegate) iref._get_delegate(); IOR ior = ird.getIor(); if (orb.LOCAL_HOST.equalsIgnoreCase(ior.Internet.host)) { - activeObjectMap.Obj rx = orb.rootPOA.findIorKey(ior.key); + AOM.Obj rx = orb.rootPOA.findIorKey(ior.key); if (rx != null) { if (rx.object == fto || @@ -175,6 +176,7 @@ public class ForwardedServant catch (IOException io_ex) { MARSHAL m = new MARSHAL(); + m.minor = Minor.Forwarding; m.initCause(io_ex); throw m; } diff --git a/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java b/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java index 7af3369..72dd8f0 100644 --- a/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java +++ b/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java @@ -38,8 +38,10 @@ exception statement from your version. */ package gnu.CORBA.Poa; -import gnu.CORBA.CDR.cdrOutput; -import gnu.CORBA.streamRequest; +import gnu.CORBA.CDR.AbstractCdrOutput; +import gnu.CORBA.IOR; +import gnu.CORBA.IorProvider; +import gnu.CORBA.StreamBasedRequest; import org.omg.CORBA.ARG_INOUT; import org.omg.CORBA.Bounds; @@ -68,17 +70,22 @@ import java.util.Arrays; * A local delegate, transferring all object requests to the locally available * servant. This class is involved in handling the method invocations on the * local object, obtained by POA.create_reference_with_id. - * + * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate +public class LocalDelegate + extends org.omg.CORBA_2_3.portable.Delegate + implements IorProvider { /** * The same servant as an invocation handler. */ gnuServantObject object; + String operation; - final gnuPOA poa; + + public final gnuPOA poa; + final byte[] Id; /** @@ -91,6 +98,14 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate poa = a_poa; Id = an_id; } + + /** + * Get the IOR of the connected object. + */ + public IOR getIor() + { + return object.getIor(); + } public Request request(org.omg.CORBA.Object target, String method) { @@ -107,8 +122,7 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate } public boolean is_equivalent(org.omg.CORBA.Object target, - org.omg.CORBA.Object other - ) + org.omg.CORBA.Object other) { if (target == other) return true; @@ -157,9 +171,9 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate /** * Check if this object could be named by the given repository id. - * + * * @param idl_id the repository id to check. - * + * * @return true if it is one of the possible repository ids of this object. */ public boolean is_a(org.omg.CORBA.Object a_servant, String idl_id) @@ -167,7 +181,7 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate String[] maybe = object._ids(); for (int i = 0; i < maybe.length; i++) { - if (maybe [ i ].equals(idl_id)) + if (maybe[i].equals(idl_id)) return true; } return false; @@ -186,8 +200,7 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate */ public Request create_request(org.omg.CORBA.Object target, Context context, String method, NVList parameters, NamedValue returns, - ExceptionList exceptions, ContextList ctx_list - ) + ExceptionList exceptions, ContextList ctx_list) { operation = method; @@ -204,8 +217,7 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate * Create request for using with DII. */ public Request create_request(org.omg.CORBA.Object target, Context context, - String method, NVList parameters, NamedValue returns - ) + String method, NVList parameters, NamedValue returns) { operation = method; @@ -226,23 +238,20 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate /** * Create a request to invoke the method of this CORBA object. - * + * * @param operation the name of the method to invoke. * @param response_expected specifies if this is one way message or the * response to the message is expected. - * + * * @return the stream where the method arguments should be written. */ public org.omg.CORBA.portable.OutputStream request( - org.omg.CORBA.Object target, - String method, - boolean response_expected - ) + org.omg.CORBA.Object target, String method, boolean response_expected) { operation = method; // Check if the object is not explicitly deactivated. - activeObjectMap.Obj e = poa.aom.get(Id); + AOM.Obj e = poa.aom.get(Id); if (e != null && e.isDeactiveted()) { if (poa.servant_activator != null || poa.servant_locator != null) @@ -280,7 +289,7 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate /** * Make an invocation. - * + * * @param target not in use. * @param output the stream request that should be returned by * {@link #m_request} in this method. @@ -292,31 +301,29 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate { try { - streamRequest sr = (streamRequest) output; + StreamBasedRequest sr = (StreamBasedRequest) output; LocalRequest lr = (LocalRequest) sr.request; - InvokeHandler handler = - lr.object.getHandler(lr.operation(), lr.cookie, false); + InvokeHandler handler = lr.object.getHandler(lr.operation(), lr.cookie, + false); - if (handler instanceof dynImpHandler) + if (handler instanceof DynamicImpHandler) { // The local request known how to handle it, but the different // method must be called. lr.invoke(); // The encapsulation will inherit orb, endian, charsets, etc. - cdrOutput buf = sr.createEncapsulation(); + AbstractCdrOutput buf = sr.createEncapsulation(); // Write all request parameters to the buffer stream. if (lr.env().exception() != null) { try { - UnknownUserException uex = - (UnknownUserException) lr.env().exception(); + UnknownUserException uex = (UnknownUserException) lr.env().exception(); throw new ApplicationException(uex.except.type().id(), - uex.except.create_input_stream() - ); + uex.except.create_input_stream()); } catch (BadKind ex) { @@ -334,9 +341,8 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate for (int i = 0; i < lr.arguments().count(); i++) { a = lr.arguments().item(i); - if (a.flags() == ARG_INOUT.value || - a.flags() == ARG_INOUT.value - ) + if (a.flags() == ARG_INOUT.value + || a.flags() == ARG_INOUT.value) { a.value().write_value(buf); } @@ -362,10 +368,7 @@ public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate try { return ((ObjectImpl) f.forward_reference)._invoke(f.forward_reference._request( - operation, - true - ) - ); + operation, true)); } catch (RemarshalException e) { diff --git a/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java b/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java index a727499..a2c0bb1 100644 --- a/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java +++ b/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java @@ -38,19 +38,19 @@ exception statement from your version. */ package gnu.CORBA.Poa; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.BufferedCdrOutput; import gnu.CORBA.GIOP.MessageHeader; import gnu.CORBA.GIOP.v1_2.ReplyHeader; import gnu.CORBA.GIOP.v1_2.RequestHeader; import gnu.CORBA.Interceptor.gnuClientRequestInfo; import gnu.CORBA.Interceptor.gnuServerRequestInfo; +import gnu.CORBA.typecodes.RecordTypeCode; import gnu.CORBA.ObjectCreator; import gnu.CORBA.Unexpected; import gnu.CORBA.gnuAny; import gnu.CORBA.gnuRequest; -import gnu.CORBA.recordTypeCode; -import gnu.CORBA.streamReadyHolder; -import gnu.CORBA.streamRequest; +import gnu.CORBA.StreamHolder; +import gnu.CORBA.StreamBasedRequest; import org.omg.CORBA.ARG_OUT; import org.omg.CORBA.Any; @@ -115,7 +115,7 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, /** * The buffer to write into. */ - cdrBufOutput buffer; + BufferedCdrOutput buffer; /** * The responsible POA. @@ -252,7 +252,7 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, handler = object.getHandler(operation(), cookie, false); } - cdrBufOutput request_part = new cdrBufOutput(); + BufferedCdrOutput request_part = new BufferedCdrOutput(); request_part.setOrb(orb()); @@ -288,7 +288,7 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, request_part.create_input_stream(); // Ensure the servant (handler) has a delegate set. - servantDelegate sd = null; + ServantDelegateImpl sd = null; Delegate d = null; @@ -300,19 +300,19 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, { // In some cases exception is thrown if the delegate is not set. } - if (d instanceof servantDelegate) + if (d instanceof ServantDelegateImpl) { // If the delegate is already set, try to reuse the existing // instance. - sd = (servantDelegate) d; + sd = (ServantDelegateImpl) d; if (sd.object != object) { - sd = new servantDelegate(servant, poa, Id); + sd = new ServantDelegateImpl(servant, poa, Id); } } else { - sd = new servantDelegate(servant, poa, Id); + sd = new ServantDelegateImpl(servant, poa, Id); } servant._set_delegate(sd); @@ -368,13 +368,13 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, { // Failed due any reason, insert without // helper. - a.insert_Streamable(new streamReadyHolder( + a.insert_Streamable(new StreamHolder( buf.create_input_stream() ) ); - recordTypeCode r = - new recordTypeCode(TCKind.tk_except); + RecordTypeCode r = + new RecordTypeCode(TCKind.tk_except); r.setId(uex_idl); r.setName(ObjectCreator.getDefaultName(uex_idl)); } @@ -531,9 +531,9 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, { InvokeHandler handler = object.getHandler(operation(), cookie, false); - if (handler instanceof dynImpHandler) + if (handler instanceof DynamicImpHandler) { - DynamicImplementation dyn = ((dynImpHandler) handler).servant; + DynamicImplementation dyn = ((DynamicImpHandler) handler).servant; if (serverRequest == null) { serverRequest = new LocalServerRequest(this); @@ -589,7 +589,7 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, // Prepare an Any that will hold the exception. gnuAny exc = new gnuAny(); - exc.insert_Streamable(new streamReadyHolder(input)); + exc.insert_Streamable(new StreamHolder(input)); UnknownUserException unuex = new UnknownUserException(exc); m_environment.exception(unuex); @@ -637,7 +637,7 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, * * @return the CDR output stream, containing the written output. */ - cdrBufOutput getBuffer() + BufferedCdrOutput getBuffer() { return buffer; } @@ -656,7 +656,7 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, */ private void prepareStream() { - buffer = new cdrBufOutput(); + buffer = new BufferedCdrOutput(); buffer.setOrb(orb()); } @@ -664,9 +664,9 @@ public class LocalRequest extends gnuRequest implements ResponseHandler, * Get the parameter stream, where the invocation arguments should be written * if they are written into the stream directly. */ - public streamRequest getParameterStream() + public StreamBasedRequest getParameterStream() { - m_parameter_buffer = new streamRequest(); + m_parameter_buffer = new StreamBasedRequest(); m_parameter_buffer.request = this; m_parameter_buffer.setOrb(poa.orb()); return m_parameter_buffer; diff --git a/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java b/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java index d95bf2b..bb00aab 100644 --- a/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java +++ b/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java @@ -38,7 +38,7 @@ exception statement from your version. */ package gnu.CORBA.Poa; -import gnu.CORBA.Functional_ORB; +import gnu.CORBA.OrbFunctional; import gnu.CORBA.IOR; import gnu.CORBA.Connected_objects.cObject; import gnu.CORBA.DynAn.gnuDynAnyFactory; @@ -53,11 +53,13 @@ import org.omg.CORBA.Any; import org.omg.CORBA.BAD_OPERATION; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.ORB; import org.omg.CORBA.Policy; import org.omg.CORBA.PolicyError; import org.omg.CORBA.portable.ObjectImpl; import org.omg.PortableInterceptor.PolicyFactory; -import org.omg.PortableServer.POA; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.POAManagerPackage.State; import org.omg.PortableServer.POAPackage.InvalidPolicy; import java.applet.Applet; @@ -69,7 +71,7 @@ import java.util.Properties; * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ public class ORB_1_4 - extends Functional_ORB + extends OrbFunctional { /** * The root POA. @@ -100,7 +102,7 @@ public class ORB_1_4 super(); try { - rootPOA = new gnuPOA(null, "RootPOA", null, policySets.rootPoa(), this); + rootPOA = new gnuPOA(null, "RootPOA", null, StandardPolicies.rootPoa(), this); } catch (InvalidPolicy ex) { @@ -130,7 +132,7 @@ public class ORB_1_4 { try { - activeObjectMap.Obj exists = rootPOA.findObject(forObject); + AOM.Obj exists = rootPOA.findObject(forObject); if (exists == null) throw new OBJECT_NOT_EXIST(forObject == null ? "null" : forObject.toString()); @@ -201,9 +203,9 @@ public class ORB_1_4 IOR ior = super.createIOR(ref); if (iIor != null) { - activeObjectMap.Obj obj = rootPOA.findIorKey(ior.key); + AOM.Obj obj = rootPOA.findIorKey(ior.key); - POA poa; + gnuPOA poa; // Null means that the object was connected to the ORB directly. if (obj == null) @@ -215,6 +217,7 @@ public class ORB_1_4 // This may modify the ior. iIor.establish_components(info); + iIor.components_established(info); } return ior; } @@ -252,5 +255,39 @@ public class ORB_1_4 super.set_parameters(para, props); registerInterceptors(props, para); } + + /** + * This method is called by RMI-IIOP {@link javax.rmi.Tie#orb(ORB)}, passing + * this as parameter. The ORB will try to connect that tie as + * one of its objects, if it is not already connected. If the wrapper is an + * instance of Servant this method also activates the root poa (if not already + * active). + */ + public void set_delegate(java.lang.Object wrapper) + { + if (wrapper instanceof org.omg.CORBA.Object) + { + org.omg.CORBA.Object object = (org.omg.CORBA.Object) wrapper; + if (connected_objects.getKey(object) == null) + connect(object); + } + else if (wrapper instanceof Servant) + { + Servant s = (Servant) wrapper; + if (rootPOA.findServant(s) == null) + try + { + rootPOA.servant_to_reference(s); + if (rootPOA.the_POAManager().get_state().value() == State._HOLDING) + rootPOA.the_POAManager().activate(); + } + catch (Exception e) + { + BAD_OPERATION bad = new BAD_OPERATION("Unable to connect " + + wrapper + " to " + this); + throw bad; + } + } + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/ServantDelegateImpl.java b/libjava/classpath/gnu/CORBA/Poa/ServantDelegateImpl.java new file mode 100644 index 0000000..e65214d --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/ServantDelegateImpl.java @@ -0,0 +1,232 @@ +/* ServantDelegateImpl.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.Poa; + +import gnu.CORBA.Unexpected; + +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.Object; +import org.omg.PortableServer.CurrentPackage.NoContext; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAHelper; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.portable.Delegate; + +/** + * The implementation of the servant delegate for the locally existing + * servant.The associated servant that must also implement the + * {@link InvokeHandler} interface. Each servant requires a separate + * instance of this delegate and can serve a single object only. + * Hence the fields are final, but the delegate is typically reused + * unless the same servant is connected to different objects. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class ServantDelegateImpl + implements Delegate +{ + /** + * The servant, associated with this object. + */ + final Servant servant; + + /** + * The servant (not object) id. + */ + final byte[] servant_id; + + /** + * The POA, where the servant is connected. + */ + final gnuPOA poa; + + /** + * The object, exposed as an object, served by this servant. + */ + final gnuServantObject object; + + /** + * Create the delegat for the servant that will be connected to the + * given poa. The method is normally called from inside of gnuPOA. + * The constructor sets the newly created delegate as the delegate to this + * servant by calling Servant._set_delegate. + * + * @param a_poa the poa. + * @param a_servant the servant. + * @param a_servant_id the servant id. + */ + public ServantDelegateImpl(Servant a_servant, gnuPOA a_poa, byte[] a_servant_id) + { + poa = a_poa; + servant = a_servant; + servant_id = a_servant_id; + servant._set_delegate(this); + object = + new gnuServantObject(servant, servant_id, (ORB_1_4) servant._orb(), a_poa); + object._set_delegate(new LocalDelegate(object, poa, a_servant_id)); + } + + /** + * Check if this object could be named by the given repository id. + * @param idl_id the repository id to check. + * + * @return true if it is one of the possible repository ids of this + * object. + */ + public boolean is_a(Servant a_servant, String idl_id) + { + same(a_servant); + + String[] maybe = object.repository_ids; + if (maybe == null) + maybe = servant._all_interfaces(poa, object.Id); + for (int i = 0; i < maybe.length; i++) + { + if (maybe [ i ].equals(idl_id)) + return true; + } + return false; + } + + /** + * Return the ORB's default POA. + */ + public POA default_POA(Servant a_servant) + { + same(a_servant); + try + { + return POAHelper.narrow(orb(a_servant).resolve_initial_references("RootPOA")); + } + catch (InvalidName ex) + { + throw new Unexpected(ex); + } + } + + /** + * Get ORB. + */ + public ORB orb(Servant a_servant) + { + same(a_servant); + return poa.orb(); + } + + /** + * Get the object, exposing the servant. + */ + public Object this_object(Servant a_servant) + { + same(a_servant); + try + { + return poa.aom.get(poa.m_orb.currents.get_object_id()).object; + } + catch (NoContext ex) + { + return object; + } + } + + /** + * Not supported. + * + * @specnote Same as for Sun up till 1.5 inclusive. + */ + public Object get_interface_def(Servant a_servant) + { + same(a_servant); + throw new NO_IMPLEMENT(); + } + + /** + * Get the Id of the object being currently served. + */ + public byte[] object_id(Servant a_servant) + { + same(a_servant); + try + { + byte[] id = poa.m_orb.currents.get_object_id(); + return id; + } + catch (NoContext ex) + { + return object.Id; + } + } + + /** + * Always returns false; + */ + public boolean non_existent(Servant a_servant) + { + same(a_servant); + return false; + } + + /** + * Return the associated POA. + */ + public POA poa(Servant a_servant) + { + same(a_servant); + try + { + return poa.m_orb.currents.get_POA(); + } + catch (NoContext ex) + { + return poa; + } + } + + /** + * Checks if the passed servant is the same as the servant, associated with + * this delegate. This class requires a single servant per delegate. + */ + void same(Servant some_servant) + { + if (servant != some_servant) + throw new InternalError("Only one servant per delegate is supported."); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/StandardPolicies.java b/libjava/classpath/gnu/CORBA/Poa/StandardPolicies.java new file mode 100644 index 0000000..b2edc40 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/StandardPolicies.java @@ -0,0 +1,128 @@ +/* StandardPolicies.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.Poa; + +import org.omg.CORBA.Policy; +import org.omg.PortableServer.IdAssignmentPolicyValue; +import org.omg.PortableServer.IdUniquenessPolicyValue; +import org.omg.PortableServer.ImplicitActivationPolicyValue; +import org.omg.PortableServer.LifespanPolicyValue; +import org.omg.PortableServer.RequestProcessingPolicyValue; +import org.omg.PortableServer.ServantRetentionPolicyValue; +import org.omg.PortableServer.ThreadPolicyValue; + +import java.util.ArrayList; + +/** + * Contains the frequently uset POA policy sets. The policy + * arrays are package private for security reasons, the cloned + * copies are returned. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class StandardPolicies +{ + /** + * The default policy set, as defined in OMG specs. This is also + * the policy set for the root POA. + */ + private static final AccessiblePolicy[] rootPOASet = + new AccessiblePolicy[] + { + new gnuThreadPolicy(ThreadPolicyValue.ORB_CTRL_MODEL), + new gnuLifespanPolicy(LifespanPolicyValue.TRANSIENT), + new gnuIdUniquenessPolicy(IdUniquenessPolicyValue.UNIQUE_ID), + new gnuIdAssignmentPolicy(IdAssignmentPolicyValue.SYSTEM_ID), + new gnuServantRetentionPolicy(ServantRetentionPolicyValue.RETAIN), + new gnuRequestProcessingPolicy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY), + new gnuImplicitActivationPolicy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) + }; + + /** + * Return the policy set, applicable for the root POA, as defined + * in OMG specs. + */ + public static Policy[] rootPoa() + { + Policy[] p = new Policy[ rootPOASet.length ]; + System.arraycopy(rootPOASet, 0, p, 0, p.length); + return p; + } + + /** + * Convert the potentially incomplete policy array into array, containing + * the complete policy set. + * + * @param policies the policy list, may be incomplete (even zero size). + * + * @return the complete policy array. The missing, but needed policies + * are added with they default values. + */ + public static Policy[] withDefault(Policy[] policies) + { + ArrayList current = new ArrayList(rootPOASet.length); + Policy p_default; + boolean specified; + + for (int i = 0; i < rootPOASet.length; i++) + { + p_default = rootPOASet [ i ]; + specified = false; + ForThis: + for (int j = 0; j < policies.length; j++) + { + if (policies [ j ].policy_type() == p_default.policy_type()) + { + specified = true; + current.add(policies [ j ]); + break ForThis; + } + } + if (!specified) + current.add(p_default.copy()); + } + + Policy[] complete = new Policy[ current.size() ]; + for (int i = 0; i < complete.length; i++) + { + complete [ i ] = (Policy) current.get(i); + } + return complete; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/activeObjectMap.java b/libjava/classpath/gnu/CORBA/Poa/activeObjectMap.java deleted file mode 100644 index 1354ba9..0000000 --- a/libjava/classpath/gnu/CORBA/Poa/activeObjectMap.java +++ /dev/null @@ -1,394 +0,0 @@ -/* activeObjectMap.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.Poa; - -import gnu.CORBA.ByteArrayComparator; - -import org.omg.PortableServer.POA; -import org.omg.PortableServer.Servant; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - * Implements the conception of the Active Object Map. - * If the POA supports the RETAIN policy, it maintains an Active - * Object Map, that associates Object Ids with active servants. - * Each association constitutes an active object. We use a single map - * for all POAs on the given orb. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class activeObjectMap -{ - /** - * The reference data about the object, placed on the AOM. - */ - public class Obj - { - /** - * Create an initialised instance. - */ - Obj(org.omg.CORBA.Object _object, byte[] _key, Servant _servant, POA _poa) - { - object = _object; - key = _key; - servant = _servant; - poa = _poa; - } - - /** - * The object. - */ - public final org.omg.CORBA.Object object; - - /** - * The servant, serving the given object. - */ - public Servant servant; - - /** - * The local servant that once served this object. - * This field is used by {@link ForwardedServant} when it discovers that - * the forwarding chaing returns back to the original location. - * It should not be used anywhere else. - */ - Servant primary_servant; - - /** - * The POA, where the object is connected. - */ - public final POA poa; - - /** - * The object key. - */ - public final byte[] key; - - /** - * If true, this entry is deactivated. - */ - public boolean deactivated; - - /** - * Set the servant value, preserving any non null - * value as the primary servant. - */ - public void setServant(Servant s) - { - if (primary_servant == null) - primary_servant = s; - servant = s; - } - - /** - * Get the servant. - */ - public Servant getServant() - { - return servant; - } - - /** - * Get the deactivation state. - */ - public boolean isDeactiveted() - { - return deactivated; - } - - /** - * Set the deactivation state. - */ - public void setDeactivated(boolean state) - { - deactivated = state; - } - - public boolean equals(java.lang.Object other) - { - if (other instanceof Obj) - { - Obj o = (Obj) other; - return o.object.equals(object); - } - else - return false; - } - } - - /** - * The free number to give for the next instance. - * This field is incremented each time the - * new collection of the connected objects is created. - * Each collection has its own unique instance number. - */ - private static long free_id; - - /** - * The map of the all connected objects, maps the object key to the - * object. - */ - Map objects = new TreeMap(new ByteArrayComparator()); - - /** - * Get the record of the stored object. If the object is mapped - * several times under the different keys, one of the mappings - * is used. - * - * @param object the stored object - * - * @return the record about the stored object, null if - * this object is not stored here. - */ - public Obj findObject(org.omg.CORBA.Object stored_object) - { - if (stored_object == null) - return null; - - Map.Entry item; - Iterator iter = objects.entrySet().iterator(); - Obj ref; - - while (iter.hasNext()) - { - item = (Map.Entry) iter.next(); - ref = (Obj) item.getValue(); - if (stored_object.equals(ref.object)) - return ref; - } - return null; - } - - /** - * Find the reference info for the given servant. - * If the servant is mapped to several objects, this - * returns the first found occurence. - * - * @param servant a servant to find. - * - * @return the servant/object/POA binding or null if no such found. - */ - public Obj findServant(Servant servant) - { - if (servant == null) - return null; - - Map.Entry item; - Iterator iter = objects.entrySet().iterator(); - Obj ref; - - while (iter.hasNext()) - { - item = (Map.Entry) iter.next(); - ref = (Obj) item.getValue(); - if (servant.equals(ref.servant)) - return ref; - } - return null; - } - - /** - * Find the reference info for the given servant. - * If the servant is mapped to several objects, this - * returns the first found occurence. - * - * @param servant a servant to find. - * @param speficies if to search for the inactive (true) or active - * (false) servant. A servant with unmatching activity is ignored - * by this method. - * - * @return the servant/object/POA binding or null if no such found. - */ - public Obj findServant(Servant servant, boolean inactive) - { - if (servant == null) - return null; - - Map.Entry item; - Iterator iter = objects.entrySet().iterator(); - Obj ref; - - while (iter.hasNext()) - { - item = (Map.Entry) iter.next(); - ref = (Obj) item.getValue(); - if (ref.deactivated == inactive) - if (ref.servant != null) - if (servant.equals(ref.servant)) - return ref; - } - return null; - } - - /** - * Add the new object to the repository. The object key is - * generated automatically. - * - * @param object the object to add. - * @param servant a servant, serving the given object. - * @param poa the poa, where the object is connected. - * - * @return the newly created object record. - */ - public Obj add(org.omg.CORBA.Object object, Servant servant, POA poa) - { - return add(generateObjectKey(object), object, servant, poa); - } - - /** - * Add the new object to the repository. - * - * @param key the object key. - * @param object the object to add. - * @param servant a servant, serving the given object. - * @param poa the POA, where the object is connected. - */ - public Obj add(byte[] key, org.omg.CORBA.Object object, Servant servant, - POA poa - ) - { - Obj rec = new Obj(object, key, servant, poa); - objects.put(key, rec); - return rec; - } - - /** - * Add the new object to the repository. - * - * @param delegate the delegate, providing data about the servant, key, POA - * and object. - * @param port the port that this object would take. - */ - public Obj add(servantDelegate delegate) - { - Obj rec = - new Obj(delegate.object, delegate.servant_id, delegate.servant, - delegate.poa - ); - objects.put(delegate.servant_id, rec); - return rec; - } - - /** - * Put back the definition structure that has probably been removed earlier. - */ - public void put(Obj obj) - { - objects.put(obj.key, obj); - } - - /** - * Get the stored object. - * - * @param key the key (in the byte array form). - * - * @return the matching object, null if none is matching. - */ - public Obj get(byte[] key) - { - return (Obj) objects.get(key); - } - - /** - * Get the map key set. - */ - public Set keySet() - { - return objects.keySet(); - } - - /** - * Remove the given object, indiciating it by the key. - * - * @param object the object to remove. - */ - public void remove(byte[] key) - { - objects.remove(key); - } - - /** - * Generate the object key, unique in the currently - * running java virtual machine. The passed object - * parameter is currently not in use. - * - * @return the generated key. - */ - protected byte[] generateObjectKey(org.omg.CORBA.Object object) - { - byte[] key; - - // The repetetive keys cannot be generated, but theoretically - // the same keys can be passed when calling add(byte[]...). - // Hence we check if the key is not already in the map and, - // if it is, use the subsequent value. - do - { - key = getFreeId(); - } - while (objects.containsKey(key)); - return key; - } - - /** - * Get the next free 8 byte id, surely unique between calls of this - * method for the currently running virtual machine. - */ - public static synchronized byte[] getFreeId() - { - byte[] r = new byte[ 8 ]; - - // Start from the faster-changing. - r [ 0 ] = ((byte) (0xff & free_id)); - r [ 1 ] = ((byte) (0xff & (free_id >> 8))); - r [ 2 ] = ((byte) (0xff & (free_id >> 16))); - r [ 3 ] = ((byte) (0xff & (free_id >> 24))); - r [ 4 ] = ((byte) (0xff & (free_id >> 32))); - r [ 5 ] = ((byte) (0xff & (free_id >> 40))); - r [ 6 ] = ((byte) (0xff & (free_id >> 48))); - r [ 7 ] = ((byte) (0xff & (free_id >> 56))); - - free_id++; - - return r; - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java b/libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java deleted file mode 100644 index 1cc3e13..0000000 --- a/libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -/* dynImpHandler.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.Poa; - -import org.omg.CORBA.BAD_OPERATION; -import org.omg.CORBA.portable.InputStream; -import org.omg.CORBA.portable.InvokeHandler; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.ResponseHandler; -import org.omg.PortableServer.DynamicImplementation; - -/** - * The InvokeHandler, indicating, that the target is a dynamic - * implementation rather than an invoke handler. These two - * types are not substitutable, but in some methods have possibility - * just to handle them differently. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class dynImpHandler - implements InvokeHandler -{ - /** - * The servant that is a dynamic implementation rather than - * invoke handler. - */ - public final DynamicImplementation servant; - - /** - * Create a new instance, wrapping some dyn implementation. - * @param _servant - */ - public dynImpHandler(DynamicImplementation _servant) - { - servant = _servant; - } - - /** - * We cannot invoke properly without having parameter info. - * - * @throws BAD_OPERATION, always. - */ - public OutputStream _invoke(String method, InputStream input, - ResponseHandler handler - ) - { - throw new BAD_OPERATION(servant + " is not an InvokeHandler."); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuAdapterActivator.java b/libjava/classpath/gnu/CORBA/Poa/gnuAdapterActivator.java index 3019a2a..17d5a0f 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuAdapterActivator.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuAdapterActivator.java @@ -69,7 +69,7 @@ public class gnuAdapterActivator { try { - POA n = parent.create_POA(child_name, null, policySets.rootPoa()); + POA n = parent.create_POA(child_name, null, StandardPolicies.rootPoa()); n.the_POAManager().activate(); } catch (Exception ex) diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java index a404486..9153190 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.IdAssignmentPolicyValue; */ public class gnuIdAssignmentPolicy extends _PolicyImplBase - implements IdAssignmentPolicy, vPolicy + implements IdAssignmentPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java index 2abd1f4..0b5fa14 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.IdUniquenessPolicyValue; */ public class gnuIdUniquenessPolicy extends _PolicyImplBase - implements IdUniquenessPolicy, vPolicy + implements IdUniquenessPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java index 1e539a2..f1721be 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.ImplicitActivationPolicyValue; */ public class gnuImplicitActivationPolicy extends _PolicyImplBase - implements ImplicitActivationPolicy, vPolicy + implements ImplicitActivationPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java index 97b3f2d..f26596c 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.LifespanPolicyValue; */ public class gnuLifespanPolicy extends _PolicyImplBase - implements LifespanPolicy, vPolicy + implements LifespanPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuPOA.java b/libjava/classpath/gnu/CORBA/Poa/gnuPOA.java index 1d9e838..6f2a019 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuPOA.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuPOA.java @@ -49,10 +49,15 @@ import org.omg.CORBA.LocalObject; import org.omg.CORBA.NO_IMPLEMENT; import org.omg.CORBA.OBJ_ADAPTER; import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; import org.omg.CORBA.Policy; import org.omg.CORBA.SetOverrideType; import org.omg.CORBA.TRANSIENT; import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableInterceptor.NON_EXISTENT; +import org.omg.PortableInterceptor.ObjectReferenceFactory; +import org.omg.PortableInterceptor.ObjectReferenceTemplate; +import org.omg.PortableInterceptor.ObjectReferenceTemplateHelper; import org.omg.PortableServer.AdapterActivator; import org.omg.PortableServer.ForwardRequest; import org.omg.PortableServer.IdAssignmentPolicy; @@ -87,8 +92,10 @@ import org.omg.PortableServer.POAPackage.ServantAlreadyActive; import org.omg.PortableServer.POAPackage.ServantNotActive; import org.omg.PortableServer.POAPackage.WrongAdapter; import org.omg.PortableServer.POAPackage.WrongPolicy; -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; + +import gnu.CORBA.OrbFunctional; +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; /** * Our POA implementation. @@ -97,12 +104,108 @@ import gnu.CORBA.CDR.cdrBufOutput; */ public class gnuPOA extends LocalObject - implements POA + implements POA, ObjectReferenceFactory { /** + * The object reference template, associated with this POA. + * + * @since 1.5 + */ + class RefTemplate implements ObjectReferenceTemplate + { + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + RefTemplate() + { + // The adapter name is computed once. + ArrayList names = new ArrayList(); + names.add(the_name()); + + POA poa = the_parent(); + while (poa != null) + { + names.add(poa.the_name()); + poa = poa.the_parent(); + } + + // Fill in the string array in reverse (more natural) order, + // root POA first. + m_adapter_name = new String[names.size()]; + + for (int i = 0; i < m_adapter_name.length; i++) + m_adapter_name[i] = (String) names.get(m_adapter_name.length - i - 1); + } + + /** + * The adapter name + */ + final String[] m_adapter_name; + + /** + * Get the name of this POA. + */ + public String[] adapter_name() + { + return (String[]) m_adapter_name.clone(); + } + + /** + * Get the ORB id. + */ + public String orb_id() + { + return m_orb.orb_id; + } + + /** + * Get the server id. + */ + public String server_id() + { + return OrbFunctional.server_id; + } + + /** + * Create the object. + */ + public Object make_object(String repositoryId, byte[] objectId) + { + return create_reference_with_id(objectId, repositoryId); + } + + /** + * Get the array of truncatible repository ids. + */ + public String[] _truncatable_ids() + { + return ref_template_ids; + } + } + + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The adapter reference template. + */ + ObjectReferenceTemplate refTemplate; + + /** + * The reference template repository ids. Defined outside the class as it + * cannot have static members. + */ + final static String[] ref_template_ids = + new String[] { ObjectReferenceTemplateHelper.id() }; + + /** * The active object map, mapping between object keys, objects and servants. */ - public final activeObjectMap aom = new activeObjectMap(); + public final AOM aom = new AOM(); /** * The children of this POA. @@ -182,6 +285,12 @@ public class gnuPOA * necessity of the frequent checks. */ public final boolean retain_servant; + + /** + * The object reference factory, used to create the new object + * references. + */ + ObjectReferenceFactory m_object_factory = this; /** * Create a new abstract POA. @@ -199,7 +308,7 @@ public class gnuPOA throws InvalidPolicy { // Add default policies. - Policy[] all_policies = policySets.withDefault(a_policies); + Policy[] all_policies = StandardPolicies.withDefault(a_policies); name = a_name; parent = a_parent; @@ -222,12 +331,14 @@ public class gnuPOA for (int i = 0; i < s_policies.length; i++) { s_policies [ i ] = all_policies [ i ].copy(); - m_policies.add(((vPolicy) s_policies [ i ]).getValue()); + m_policies.add(((AccessiblePolicy) s_policies [ i ]).getValue()); } retain_servant = applies(ServantRetentionPolicyValue.RETAIN); validatePolicies(a_policies); + + refTemplate = new RefTemplate(); } /** @@ -281,7 +392,7 @@ public class gnuPOA keys.addAll(aom.keySet()); byte[] key; - activeObjectMap.Obj obj; + AOM.Obj obj; boolean last; for (int i = 0; i < keys.size(); i++) { @@ -422,30 +533,30 @@ public class gnuPOA } /** - * Generate the Object Id for the given servant and add the servant to - * the Active Object Map using this Id a a key. If the servant - * activator is set, its incarnate method will be called. - * - * @param a_servant a servant that would serve the object with the - * returned Object Id. If null is passed, under apporoprate policies the - * servant activator is invoked. - * + * Generate the Object Id for the given servant and add the servant to the + * Active Object Map using this Id a a key. If the servant activator is set, + * its incarnate method will be called. + * + * @param a_servant a servant that would serve the object with the returned + * Object Id. If null is passed, under apporoprate policies the servant + * activator is invoked. + * * @return the generated objert Id for the given servant. - * - * @throws ServantAlreadyActive if this servant is already in the - * Active Object Map and the UNIQUE_ID policy applies. - * - * @throws WrongPolicy if the required policies SYSTEM_ID and RETAIN - * do not apply to this POA. + * + * @throws ServantAlreadyActive if this servant is already in the Active + * Object Map and the UNIQUE_ID policy applies. + * + * @throws WrongPolicy if the required policies SYSTEM_ID and RETAIN do not + * apply to this POA. */ public byte[] activate_object(Servant a_servant) - throws ServantAlreadyActive, WrongPolicy + throws ServantAlreadyActive, WrongPolicy { checkDiscarding(); required(ServantRetentionPolicyValue.RETAIN); required(IdAssignmentPolicyValue.SYSTEM_ID); - activeObjectMap.Obj exists = aom.findServant(a_servant); + AOM.Obj exists = aom.findServant(a_servant); if (exists != null) { @@ -464,28 +575,30 @@ public class gnuPOA // activations. } - byte[] object_key = activeObjectMap.getFreeId(); - servantDelegate delegate = new servantDelegate(a_servant, this, object_key); - connectDelegate(object_key, delegate); + byte[] object_key = AOM.getFreeId(); + ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this, + object_key); + create_and_connect(object_key, + a_servant._all_interfaces(this, object_key)[0], delegate); return object_key; } /** - * Add the given servant to the Active Object Map as a servant for the - * object with the provided Object Id. If the servant activator is - * set, its incarnate method will be called. - * + * Add the given servant to the Active Object Map as a servant for the object + * with the provided Object Id. If the servant activator is set, its incarnate + * method will be called. + * * @param an_Object_Id an object id for the given object. - * @param a_servant a servant that will serve the object with the given - * Object Id. If null is passed, under apporoprate policies the - * servant activator is invoked. - * - * @throws ObjectAlreadyActive if the given object id is already in the - * Active Object Map. - * @throws ServantAlreadyActive if the UNIQUE_ID policy applies and - * this servant is already in use. - * @throws WrongPolicy if the required RETAIN policy does not apply to - * this POA. + * @param a_servant a servant that will serve the object with the given Object + * Id. If null is passed, under apporoprate policies the servant activator is + * invoked. + * + * @throws ObjectAlreadyActive if the given object id is already in the Active + * Object Map. + * @throws ServantAlreadyActive if the UNIQUE_ID policy applies and this + * servant is already in use. + * @throws WrongPolicy if the required RETAIN policy does not apply to this + * POA. * @throws BAD_PARAM if the passed object id is invalid due any reason. */ public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant) @@ -496,16 +609,14 @@ public class gnuPOA } /** - * Same as activate_object_with_id, but permits gnuForwardRequest - * forwarding exception. This is used when the activation is called - * from the remote invocation context and we have possibility - * to return the forwarding message. + * Same as activate_object_with_id, but permits gnuForwardRequest forwarding + * exception. This is used when the activation is called from the remote + * invocation context and we have possibility to return the forwarding + * message. */ public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant, - boolean use_forwarding - ) - throws ServantAlreadyActive, ObjectAlreadyActive, - WrongPolicy + boolean use_forwarding) + throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy { checkDiscarding(); required(ServantRetentionPolicyValue.RETAIN); @@ -514,12 +625,12 @@ public class gnuPOA // already active. if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) { - activeObjectMap.Obj sx = aom.findServant(a_servant, false); + AOM.Obj sx = aom.findServant(a_servant, false); if (sx != null) throw new ServantAlreadyActive(); } - activeObjectMap.Obj exists = aom.get(an_Object_Id); + AOM.Obj exists = aom.get(an_Object_Id); if (exists != null) { if (exists.servant == null) @@ -537,26 +648,27 @@ public class gnuPOA } else { - servantDelegate delegate = - new servantDelegate(a_servant, this, an_Object_Id); - connectDelegate(an_Object_Id, delegate); + ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this, + an_Object_Id); + create_and_connect(an_Object_Id, a_servant._all_interfaces(this, + an_Object_Id)[0], delegate); } } /** * Locate the servant for this object Id and connect it to ORB. - * + * * @param an_Object_Id the object id. * @param a_servant the servant (may be null). * @param exists an existing active object map entry. - * @param use_forwarding allow to throw the gnuForwardRequest - * if the activator throws ForwardRequest. - * - * @throws OBJ_ADAPTER minor 4 if the servant cannot be located - * (the required servant manager may be missing). + * @param use_forwarding allow to throw the gnuForwardRequest if the activator + * throws ForwardRequest. + * + * @throws OBJ_ADAPTER minor 4 if the servant cannot be located (the required + * servant manager may be missing). */ private void locateServant(byte[] an_Object_Id, Servant a_servant, - activeObjectMap.Obj exists, boolean use_forwarding + AOM.Obj exists, boolean use_forwarding ) throws InternalError { @@ -582,8 +694,8 @@ public class gnuPOA throw new OBJ_ADAPTER("no servant", 4, CompletionStatus.COMPLETED_NO); } - servantDelegate delegate = - new servantDelegate(exists.servant, this, an_Object_Id); + ServantDelegateImpl delegate = + new ServantDelegateImpl(exists.servant, this, an_Object_Id); exists.servant._set_delegate(delegate); object.setServant(exists.servant); connect_to_orb(an_Object_Id, delegate.object); @@ -605,7 +717,7 @@ public class gnuPOA { required(ServantRetentionPolicyValue.RETAIN); - activeObjectMap.Obj exists = aom.get(the_Object_Id); + AOM.Obj exists = aom.get(the_Object_Id); if (exists == null || exists.isDeactiveted()) throw new ObjectNotActive(); @@ -615,7 +727,7 @@ public class gnuPOA // Check if this servant is serving something else. aom.remove(the_Object_Id); - activeObjectMap.Obj other = aom.findServant(exists.servant, false); + AOM.Obj other = aom.findServant(exists.servant, false); boolean remaining = other != null; @@ -643,7 +755,7 @@ public class gnuPOA throws WrongPolicy { required(IdAssignmentPolicyValue.SYSTEM_ID); - return create_reference_with_id(activeObjectMap.getFreeId(), a_repository_id); + return create_reference_with_id(AOM.getFreeId(), a_repository_id); } /** @@ -662,8 +774,8 @@ public class gnuPOA * servant. */ public org.omg.CORBA.Object create_reference_with_id(byte[] an_object_id, - String a_repository_id - ) + String a_repository_id + ) { String[] ids; if (a_repository_id == null) @@ -672,7 +784,7 @@ public class gnuPOA ids = new String[] { a_repository_id }; // Check maybe such object is already activated. - activeObjectMap.Obj e = aom.get(an_object_id); + AOM.Obj e = aom.get(an_object_id); Servant servant; if (e == null) @@ -847,7 +959,7 @@ public class gnuPOA return m_poa_id; else { - cdrBufOutput buffer = new cdrBufOutput(); + BufferedCdrOutput buffer = new BufferedCdrOutput(); POA p = this; while (p != null) { @@ -874,7 +986,7 @@ public class gnuPOA { required(ServantRetentionPolicyValue.RETAIN); - activeObjectMap.Obj ref = aom.get(the_Object_Id); + AOM.Obj ref = aom.get(the_Object_Id); if (ref == null) throw new ObjectNotActive(); else @@ -897,7 +1009,7 @@ public class gnuPOA { if (applies(ServantRetentionPolicyValue.RETAIN)) { - activeObjectMap.Obj ref = aom.get(the_Object_Id); + AOM.Obj ref = aom.get(the_Object_Id); if (ref == null || ref.isDeactiveted()) { if (default_servant != null) @@ -932,7 +1044,7 @@ public class gnuPOA public byte[] reference_to_id(org.omg.CORBA.Object the_Object) throws WrongAdapter, WrongPolicy { - activeObjectMap.Obj ref = aom.findObject(the_Object); + AOM.Obj ref = aom.findObject(the_Object); if (ref == null) throw new WrongAdapter(); return ref.key; @@ -958,7 +1070,7 @@ public class gnuPOA { if (applies(ServantRetentionPolicyValue.RETAIN)) { - activeObjectMap.Obj ref = aom.findObject(the_Object); + AOM.Obj ref = aom.findObject(the_Object); if (ref == null) throw new WrongAdapter(); else if (ref.isDeactiveted() || ref.servant == null) @@ -1017,7 +1129,7 @@ public class gnuPOA ) ) { - activeObjectMap.Obj ref = null; + AOM.Obj ref = null; if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID)) ref = aom.findServant(the_Servant); if (ref == null && @@ -1047,31 +1159,31 @@ public class gnuPOA } /** - *

Converts the given servant to the object reference. - * The servant will serve all methods, invoked on the returned object. - * The returned object reference can be passed to the remote client, - * enabling remote invocations. - *

- * If the specified servant is active, it is returned. Otherwise, - * if the POA has the IMPLICIT_ACTIVATION policy the method activates - * the servant. In this case, if the servant activator is set, - * the {@link ServantActivatorOperations#incarnate} method will be called. + *

+ * Converts the given servant to the object reference. The servant will serve + * all methods, invoked on the returned object. The returned object reference + * can be passed to the remote client, enabling remote invocations. *

- * + *

+ * If the specified servant is active, it is returned. Otherwise, if the POA + * has the IMPLICIT_ACTIVATION policy the method activates the servant. In + * this case, if the servant activator is set, the + * {@link ServantActivatorOperations#incarnate} method will be called. + *

+ * * @throws ServantNotActive if the servant is inactive and no * IMPLICIT_ACTIVATION policy applies. * @throws WrongPolicy This method needs the RETAIN policy and either the * UNIQUE_ID or IMPLICIT_ACTIVATION policies. - * + * * @return the object, exposing the given servant in the context of this POA. */ public org.omg.CORBA.Object servant_to_reference(Servant the_Servant) - throws ServantNotActive, - WrongPolicy + throws ServantNotActive, WrongPolicy { required(ServantRetentionPolicyValue.RETAIN); - activeObjectMap.Obj exists = null; + AOM.Obj exists = null; if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID)) exists = aom.findServant(the_Servant); @@ -1092,17 +1204,17 @@ public class gnuPOA else return exists.object; } - if (exists == null && - applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) - ) + if (exists == null + && applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)) { checkDiscarding(); - byte[] object_key = activeObjectMap.getFreeId(); + byte[] object_key = AOM.getFreeId(); - servantDelegate delegate = - new servantDelegate(the_Servant, this, object_key); - connectDelegate(object_key, delegate); + ServantDelegateImpl delegate = new ServantDelegateImpl(the_Servant, + this, object_key); + create_and_connect(object_key, the_Servant._all_interfaces(this, + object_key)[0], delegate); return delegate.object; } @@ -1111,22 +1223,22 @@ public class gnuPOA } /** - * Incarnate in cases when request forwarding is not expected - * because the servant must be provided by the servant activator. - * - * @param x the aom entry, where the object is replaced by - * value, returned by servant activator (if not null). - * + * Incarnate in cases when request forwarding is not expected because the + * servant must be provided by the servant activator. + * + * @param x the aom entry, where the object is replaced by value, returned by + * servant activator (if not null). + * * @param key the object key. - * + * * @param a_servant the servant that was passed as a parameter in the * activation method. - * - * @param use_forwarding if true, the gnuForwardRequest is throw - * under the forwarding exception (for remote client). Otherwise, the - * request is internally redirected (for local invocation). + * + * @param use_forwarding if true, the gnuForwardRequest is throw under the + * forwarding exception (for remote client). Otherwise, the request is + * internally redirected (for local invocation). */ - private Servant incarnate(activeObjectMap.Obj x, byte[] object_key, + private Servant incarnate(AOM.Obj x, byte[] object_key, Servant a_servant, boolean use_forwarding ) { @@ -1281,34 +1393,46 @@ public class gnuPOA } /** - *

Destroy this POA and all descendant POAs. The destroyed POAs can be - * later re-created via {@link AdapterActivator} or by invoking - * {@link #create_POA}. - * This differs from {@link PoaManagerOperations#deactivate} that does - * not allow recreation of the deactivated POAs. After deactivation, - * recreation is only possible if the POAs were later destroyed. - *

- * The remote invocation on the target, belonging to the POA that is - * currently destroyed return the remote exception ({@link TRANSIENT}, - * minor code 4). + *

+ * Destroy this POA and all descendant POAs. The destroyed POAs can be later + * re-created via {@link AdapterActivator} or by invoking {@link #create_POA}. + * This differs from {@link PoaManagerOperations#deactivate} that does not + * allow recreation of the deactivated POAs. After deactivation, recreation is + * only possible if the POAs were later destroyed. *

+ *

+ * The remote invocation on the target, belonging to the POA that is currently + * destroyed return the remote exception ({@link TRANSIENT}, minor code 4). + *

+ * * @param etherealize_objects if true, and POA has RETAIN policy, and the * servant manager is available, the servant manager method - * {@link ServantActivatorOperations#etherealize} is called for each - * active object in the Active Object Map. This method should not - * try to access POA being destroyed. If destroy is called - * multiple times before the destruction completes, - * the etherialization should be invoked only once. - * + * {@link ServantActivatorOperations#etherealize} is called for each active + * object in the Active Object Map. This method should not try to access POA + * being destroyed. If destroy is called multiple times before + * the destruction completes, the etherialization should be invoked only once. + * * @param wait_for_completion if true, the method waits till the POA being - * destroyed completes all current requests and etherialization. If false, - * the method returns immediately. + * destroyed completes all current requests and etherialization. If false, the + * method returns immediately. */ public void destroy(boolean etherealize_objects, boolean wait_for_completion) { + // Notify the IOR interceptors about that the POA is destroyed. + if (m_orb.iIor != null) + m_orb.iIor.adapter_state_changed( + new ObjectReferenceTemplate[] { getReferenceTemplate() }, + NON_EXISTENT.value); + if (wait_for_completion) waitWhileRunning(); + // Nofify the IOR interceptors that the POA is destroyed. + if (m_manager instanceof gnuPOAManager) + { + ((gnuPOAManager) m_manager).poaDestroyed(this); + } + // Put the brake instead of manager, preventing the subsequent // requests. gnuPOAManager g = new gnuPOAManager(); @@ -1328,7 +1452,7 @@ public class gnuPOA keys.addAll(aom.keySet()); byte[] key; - activeObjectMap.Obj obj; + AOM.Obj obj; for (int i = 0; i < keys.size(); i++) { key = (byte[]) keys.get(i); @@ -1348,7 +1472,7 @@ public class gnuPOA POA[] ch = the_children(); for (int i = 0; i < ch.length; i++) { - ch [ i ].destroy(etherealize_objects, wait_for_completion); + ch[i].destroy(etherealize_objects, wait_for_completion); } } @@ -1430,13 +1554,14 @@ public class gnuPOA } /** - * Connect the given delegate under the given key, also calling - * incarnate. + * Connect the given delegate under the given key, also calling incarnate. */ - private void connectDelegate(byte[] object_key, servantDelegate delegate) + private void create_and_connect(byte[] object_key, String repository_id, + ServantDelegateImpl delegate) { aom.add(delegate); - connect_to_orb(object_key, delegate.object); + connect_to_orb(object_key, getReferenceFactory().make_object(repository_id, + object_key)); if (servant_activator != null) incarnate(null, object_key, delegate.servant, false); } @@ -1517,9 +1642,9 @@ public class gnuPOA /** * Recursively searches for the given object in the POA tree. */ - public activeObjectMap.Obj findObject(org.omg.CORBA.Object object) + public AOM.Obj findObject(org.omg.CORBA.Object object) { - activeObjectMap.Obj h = aom.findObject(object); + AOM.Obj h = aom.findObject(object); if (h != null) return h; else @@ -1533,16 +1658,16 @@ public class gnuPOA } return h; } - + /** * Recursively searches for the given key in the POA tree. * @param ior_key the key, ecapsulating both object * and poa ids. * @return */ - public activeObjectMap.Obj findKey(byte[] object_id, byte[] poa_id) + public AOM.Obj findKey(byte[] object_id, byte[] poa_id) { - activeObjectMap.Obj h = null; + AOM.Obj h = null; if (Arrays.equals(poa_id, id())) h = aom.get(object_id); if (h != null) @@ -1563,9 +1688,9 @@ public class gnuPOA * Parses the given key, extracts poa and object id and searches * for such reference. */ - public activeObjectMap.Obj findIorKey(byte[] ior_key) + public AOM.Obj findIorKey(byte[] ior_key) { - cdrBufInput in = new cdrBufInput(ior_key); + BufferredCdrInput in = new BufferredCdrInput(ior_key); int signature = in.read_long(); if (signature != SIGNATURE) return null; @@ -1582,7 +1707,7 @@ public class gnuPOA */ public byte[] toIORKey(byte[] object_id) { - cdrBufOutput buffer = new cdrBufOutput(); + BufferedCdrOutput buffer = new BufferedCdrOutput(); buffer.write_long(SIGNATURE); buffer.write_sequence(object_id); buffer.write_sequence(id()); @@ -1600,7 +1725,7 @@ public class gnuPOA */ public byte[] idFormIor(byte[] ior_key) { - cdrBufInput in = new cdrBufInput(ior_key); + BufferredCdrInput in = new BufferredCdrInput(ior_key); int signature = in.read_long(); if (signature != SIGNATURE) return null; @@ -1612,4 +1737,70 @@ public class gnuPOA else return null; } + + /** + * Recursively searches for the given servant in the POA tree. + */ + public AOM.Obj findServant(Servant servant) + { + AOM.Obj h = aom.findServant(servant); + if (h != null) + return h; + else + { + for (int i = 0; i < children.size(); i++) + { + h = ((gnuPOA) children.get(i)).findServant(servant); + if (h != null) + return h; + } + } + return h; + } + + /** + * Get the object reference template of this POA. + * Instantiate a singleton instance, if required. + */ + public ObjectReferenceTemplate getReferenceTemplate() + { + if (refTemplate == null) + refTemplate = new RefTemplate(); + + return refTemplate; + } + + public ObjectReferenceFactory getReferenceFactory() + { + return m_object_factory; + } + + public void setReferenceFactory(ObjectReferenceFactory factory) + { + m_object_factory = factory; + } + + /** + * Create the object (needed by the factory interface). + */ + public Object make_object(String a_repository_id, byte[] an_object_id) + { + AOM.Obj existing = aom.get(an_object_id); + // The object may already exist. In this case, it is just returned. + if (existing != null && existing.object != null) + return existing.object; + else + { + return new gnuServantObject(new String[] { a_repository_id }, + an_object_id, this, m_orb); + } + } + + /** + * Required by object reference factory ops. + */ + public String[] _truncatable_ids() + { + return ref_template_ids; + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java b/libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java index 6c1b564..7710306 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java @@ -40,6 +40,8 @@ package gnu.CORBA.Poa; import org.omg.CORBA.BAD_INV_ORDER; import org.omg.CORBA.LocalObject; +import org.omg.PortableInterceptor.NON_EXISTENT; +import org.omg.PortableInterceptor.ObjectReferenceTemplate; import org.omg.PortableServer.POAManager; import org.omg.PortableServer.POAManagerPackage.AdapterInactive; import org.omg.PortableServer.POAManagerPackage.State; @@ -59,18 +61,22 @@ public class gnuPOAManager extends LocalObject implements POAManager { + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + /** - * The POAs, controlled by this manager. The members must be instances of - * the gnuAbstractPOA. + * The POAs, controlled by this manager. */ - HashSet POAs = new HashSet(); + private HashSet POAs = new HashSet(); /** * The state of the manager. The newly created manager is always * in the holding state. */ State state = State.HOLDING; - + /** * Get the state of the POA manager. */ @@ -94,6 +100,8 @@ public class gnuPOAManager state = State.ACTIVE; else throw new AdapterInactive(); + + notifyInterceptors(state.value()); } /** @@ -113,6 +121,9 @@ public class gnuPOAManager state = State.HOLDING; else throw new AdapterInactive(); + + notifyInterceptors(state.value()); + if (wait_for_completion) waitForIdle(); } @@ -144,6 +155,9 @@ public class gnuPOAManager if (state == State.INACTIVE) throw new AdapterInactive("Repetetive inactivation"); state = State.INACTIVE; + + notifyInterceptors(state.value()); + if (wait_for_completion) waitForIdle(); @@ -178,6 +192,9 @@ public class gnuPOAManager state = State.DISCARDING; else throw new AdapterInactive(); + + notifyInterceptors(state.value()); + if (wait_for_completion) waitForIdle(); } @@ -193,11 +210,13 @@ public class gnuPOAManager { if (state == State.ACTIVE) throw new BAD_INV_ORDER("The state is active"); - + + gnuPOA poa; Iterator iter = POAs.iterator(); + while (iter.hasNext()) { - gnuPOA poa = (gnuPOA) iter.next(); + poa = (gnuPOA) iter.next(); poa.waitWhileRunning(); } } @@ -222,4 +241,33 @@ public class gnuPOAManager { POAs.remove(poa); } + + /** + * This method is called when POA is destryed. The interceptors are + * notified. + */ + public void poaDestroyed(gnuPOA poa) + { + notifyInterceptors(NON_EXISTENT.value); + } + + /** + * Notify CORBA 3.0 interceptors about the status change. + */ + public synchronized void notifyInterceptors(int new_state) + { + gnuPOA poa; + Iterator iter = POAs.iterator(); + + // The System.identityHashCode is also called in gnuIorInfo. + while (iter.hasNext()) + { + poa = (gnuPOA) iter.next(); + if (poa.m_orb.iIor != null) + { + poa.m_orb.iIor.adapter_manager_state_changed( + System.identityHashCode(this), (short) new_state); + } + } + } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java index 5bbcd13..2f77639c 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.RequestProcessingPolicyValue; */ public class gnuRequestProcessingPolicy extends _PolicyImplBase - implements RequestProcessingPolicy, vPolicy + implements RequestProcessingPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java b/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java index 1ad98d1..020897a 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java @@ -39,14 +39,17 @@ exception statement from your version. */ package gnu.CORBA.Poa; import gnu.CORBA.GIOP.ReplyHeader; -import gnu.CORBA.IOR_Delegate; -import gnu.CORBA.IOR_contructed_object; +import gnu.CORBA.IorDelegate; +import gnu.CORBA.IorObject; import gnu.CORBA.Interceptor.gnuServerRequestInfo; +import gnu.CORBA.typecodes.RecordTypeCode; +import gnu.CORBA.IOR; +import gnu.CORBA.IorProvider; +import gnu.CORBA.Minor; import gnu.CORBA.ObjectCreator; import gnu.CORBA.Unexpected; -import gnu.CORBA.bufferedResponseHandler; -import gnu.CORBA.recordTypeCode; -import gnu.CORBA.streamReadyHolder; +import gnu.CORBA.ResponseHandlerImpl; +import gnu.CORBA.StreamHolder; import org.omg.CORBA.Any; import org.omg.CORBA.BAD_OPERATION; @@ -90,7 +93,8 @@ import java.util.Arrays; public class gnuServantObject extends ObjectImpl implements org.omg.CORBA.Object, InvokeHandler, - CurrentOperations + CurrentOperations, + IorProvider { /** * The associated servant that must also implement the {@link InvokeHandler} @@ -144,6 +148,14 @@ public class gnuServantObject extends ObjectImpl poa = a_poa; orb = an_orb; } + + /** + * Get the IOR as it would be for this object. + */ + public IOR getIor() + { + return orb.getLocalIor(this); + } /** * Create a servant object, associated with the passed servant. @@ -257,10 +269,8 @@ public class gnuServantObject extends ObjectImpl } catch (Exception ex) { - ex.printStackTrace(); - BAD_OPERATION bad = - new BAD_OPERATION("Unable to activate", 0x5004, + new BAD_OPERATION("Unable to activate", Minor.Activation, CompletionStatus.COMPLETED_NO ); bad.initCause(ex); @@ -276,7 +286,7 @@ public class gnuServantObject extends ObjectImpl // No servant and no servant manager - throw exception. else { - throw new BAD_OPERATION("Unable to activate", 0x5002, + throw new BAD_OPERATION("Unable to activate", Minor.Activation, CompletionStatus.COMPLETED_NO ); } @@ -294,7 +304,7 @@ public class gnuServantObject extends ObjectImpl } else if (a_servant instanceof DynamicImplementation) { - return new dynImpHandler((DynamicImplementation) a_servant); + return new DynamicImpHandler((DynamicImplementation) a_servant); } else { @@ -402,17 +412,17 @@ public class gnuServantObject extends ObjectImpl boolean intercept = false; ServerRequestInterceptorOperations interceptor = null; gnuServerRequestInfo info = null; - bufferedResponseHandler i_handler = null; + ResponseHandlerImpl i_handler = null; try { if (orb.iServer != null && - r_handler instanceof bufferedResponseHandler + r_handler instanceof ResponseHandlerImpl ) { interceptor = orb.iServer; - i_handler = (bufferedResponseHandler) r_handler; + i_handler = (ResponseHandlerImpl) r_handler; info = new gnuServerRequestInfo(this, i_handler.request_header, @@ -426,7 +436,7 @@ public class gnuServantObject extends ObjectImpl try { CookieHolder cookie = null; - activeObjectMap.Obj self = poa.aom.get(Id); + AOM.Obj self = poa.aom.get(Id); if (poa.servant_locator != null) { @@ -467,18 +477,18 @@ public class gnuServantObject extends ObjectImpl { // In some cases exception is thrown if the delegate is not set. } - if (d instanceof servantDelegate) + if (d instanceof ServantDelegateImpl) { // If the delegate is already set, check maybe we can // reuse the existing instance. - if (((servantDelegate) d).object != this) + if (((ServantDelegateImpl) d).object != this) { - servant._set_delegate(new servantDelegate(servant, poa, Id)); + servant._set_delegate(new ServantDelegateImpl(servant, poa, Id)); } } else { - servant._set_delegate(new servantDelegate(servant, poa, Id)); + servant._set_delegate(new ServantDelegateImpl(servant, poa, Id)); } try @@ -536,13 +546,13 @@ public class gnuServantObject extends ObjectImpl { // Failed due any reason, insert without // helper. - a.insert_Streamable(new streamReadyHolder( + a.insert_Streamable(new StreamHolder( buf.create_input_stream() ) ); - recordTypeCode r = - new recordTypeCode(TCKind.tk_except); + RecordTypeCode r = + new RecordTypeCode(TCKind.tk_except); r.setId(uex_idl); r.setName(ObjectCreator.getDefaultName( uex_idl @@ -774,12 +784,12 @@ public class gnuServantObject extends ObjectImpl gnuServantObject g = (gnuServantObject) other; return orb == g.orb && poa == g.poa && Arrays.equals(Id, g.Id); } - else if (other instanceof IOR_contructed_object) + else if (other instanceof IorObject) { - IOR_contructed_object ir = ((IOR_contructed_object) other); + IorObject ir = ((IorObject) other); try { - IOR_Delegate ird = (IOR_Delegate) ir._get_delegate(); + IorDelegate ird = (IorDelegate) ir._get_delegate(); byte[] ior_id = poa.idFormIor(ird.getIor().key); if (ior_id != null && Arrays.equals(ior_id, Id)) { diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuServantRetentionPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuServantRetentionPolicy.java index 009e70e..9fb61ab 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuServantRetentionPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuServantRetentionPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.ServantRetentionPolicyValue; */ public class gnuServantRetentionPolicy extends _PolicyImplBase - implements ServantRetentionPolicy, vPolicy + implements ServantRetentionPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java index f42ebef..1de94a1 100644 --- a/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java +++ b/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java @@ -51,7 +51,7 @@ import org.omg.PortableServer.ThreadPolicyValue; */ public class gnuThreadPolicy extends _PolicyImplBase - implements ThreadPolicy, vPolicy + implements ThreadPolicy, AccessiblePolicy { /** * Use serialVersionUID for interoperability. diff --git a/libjava/classpath/gnu/CORBA/Poa/policySets.java b/libjava/classpath/gnu/CORBA/Poa/policySets.java deleted file mode 100644 index eb68846..0000000 --- a/libjava/classpath/gnu/CORBA/Poa/policySets.java +++ /dev/null @@ -1,128 +0,0 @@ -/* policySets.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.Poa; - -import org.omg.CORBA.Policy; -import org.omg.PortableServer.IdAssignmentPolicyValue; -import org.omg.PortableServer.IdUniquenessPolicyValue; -import org.omg.PortableServer.ImplicitActivationPolicyValue; -import org.omg.PortableServer.LifespanPolicyValue; -import org.omg.PortableServer.RequestProcessingPolicyValue; -import org.omg.PortableServer.ServantRetentionPolicyValue; -import org.omg.PortableServer.ThreadPolicyValue; - -import java.util.ArrayList; - -/** - * Contains the frequently uset POA policy sets. The policy - * arrays are package private for security reasons, the cloned - * copies are returned. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class policySets -{ - /** - * The default policy set, as defined in OMG specs. This is also - * the policy set for the root POA. - */ - private static final vPolicy[] rootPOASet = - new vPolicy[] - { - new gnuThreadPolicy(ThreadPolicyValue.ORB_CTRL_MODEL), - new gnuLifespanPolicy(LifespanPolicyValue.TRANSIENT), - new gnuIdUniquenessPolicy(IdUniquenessPolicyValue.UNIQUE_ID), - new gnuIdAssignmentPolicy(IdAssignmentPolicyValue.SYSTEM_ID), - new gnuServantRetentionPolicy(ServantRetentionPolicyValue.RETAIN), - new gnuRequestProcessingPolicy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY), - new gnuImplicitActivationPolicy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) - }; - - /** - * Return the policy set, applicable for the root POA, as defined - * in OMG specs. - */ - public static Policy[] rootPoa() - { - Policy[] p = new Policy[ rootPOASet.length ]; - System.arraycopy(rootPOASet, 0, p, 0, p.length); - return p; - } - - /** - * Convert the potentially incomplete policy array into array, containing - * the complete policy set. - * - * @param policies the policy list, may be incomplete (even zero size). - * - * @return the complete policy array. The missing, but needed policies - * are added with they default values. - */ - public static Policy[] withDefault(Policy[] policies) - { - ArrayList current = new ArrayList(rootPOASet.length); - Policy p_default; - boolean specified; - - for (int i = 0; i < rootPOASet.length; i++) - { - p_default = rootPOASet [ i ]; - specified = false; - ForThis: - for (int j = 0; j < policies.length; j++) - { - if (policies [ j ].policy_type() == p_default.policy_type()) - { - specified = true; - current.add(policies [ j ]); - break ForThis; - } - } - if (!specified) - current.add(p_default.copy()); - } - - Policy[] complete = new Policy[ current.size() ]; - for (int i = 0; i < complete.length; i++) - { - complete [ i ] = (Policy) current.get(i); - } - return complete; - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/servantDelegate.java b/libjava/classpath/gnu/CORBA/Poa/servantDelegate.java deleted file mode 100644 index f59c01c..0000000 --- a/libjava/classpath/gnu/CORBA/Poa/servantDelegate.java +++ /dev/null @@ -1,232 +0,0 @@ -/* servantDelegate.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.Poa; - -import gnu.CORBA.Unexpected; - -import org.omg.CORBA.NO_IMPLEMENT; -import org.omg.CORBA.ORB; -import org.omg.CORBA.ORBPackage.InvalidName; -import org.omg.CORBA.Object; -import org.omg.PortableServer.CurrentPackage.NoContext; -import org.omg.PortableServer.POA; -import org.omg.PortableServer.POAHelper; -import org.omg.PortableServer.Servant; -import org.omg.PortableServer.portable.Delegate; - -/** - * The implementation of the servant delegate for the locally existing - * servant.The associated servant that must also implement the - * {@link InvokeHandler} interface. Each servant requires a separate - * instance of this delegate and can serve a single object only. - * Hence the fields are final, but the delegate is typically reused - * unless the same servant is connected to different objects. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class servantDelegate - implements Delegate -{ - /** - * The servant, associated with this object. - */ - final Servant servant; - - /** - * The servant (not object) id. - */ - final byte[] servant_id; - - /** - * The POA, where the servant is connected. - */ - final gnuPOA poa; - - /** - * The object, exposed as an object, served by this servant. - */ - final gnuServantObject object; - - /** - * Create the delegat for the servant that will be connected to the - * given poa. The method is normally called from inside of gnuPOA. - * The constructor sets the newly created delegate as the delegate to this - * servant by calling Servant._set_delegate. - * - * @param a_poa the poa. - * @param a_servant the servant. - * @param a_servant_id the servant id. - */ - public servantDelegate(Servant a_servant, gnuPOA a_poa, byte[] a_servant_id) - { - poa = a_poa; - servant = a_servant; - servant_id = a_servant_id; - servant._set_delegate(this); - object = - new gnuServantObject(servant, servant_id, (ORB_1_4) servant._orb(), a_poa); - object._set_delegate(new LocalDelegate(object, poa, a_servant_id)); - } - - /** - * Check if this object could be named by the given repository id. - * @param idl_id the repository id to check. - * - * @return true if it is one of the possible repository ids of this - * object. - */ - public boolean is_a(Servant a_servant, String idl_id) - { - same(a_servant); - - String[] maybe = object.repository_ids; - if (maybe == null) - maybe = servant._all_interfaces(poa, object.Id); - for (int i = 0; i < maybe.length; i++) - { - if (maybe [ i ].equals(idl_id)) - return true; - } - return false; - } - - /** - * Return the ORB's default POA. - */ - public POA default_POA(Servant a_servant) - { - same(a_servant); - try - { - return POAHelper.narrow(orb(a_servant).resolve_initial_references("RootPOA")); - } - catch (InvalidName ex) - { - throw new Unexpected(ex); - } - } - - /** - * Get ORB. - */ - public ORB orb(Servant a_servant) - { - same(a_servant); - return poa.orb(); - } - - /** - * Get the object, exposing the servant. - */ - public Object this_object(Servant a_servant) - { - same(a_servant); - try - { - return poa.aom.get(poa.m_orb.currents.get_object_id()).object; - } - catch (NoContext ex) - { - return object; - } - } - - /** - * Not supported. - * - * @specnote Same as for Sun up till 1.5 inclusive. - */ - public Object get_interface_def(Servant a_servant) - { - same(a_servant); - throw new NO_IMPLEMENT(); - } - - /** - * Get the Id of the object being currently served. - */ - public byte[] object_id(Servant a_servant) - { - same(a_servant); - try - { - byte[] id = poa.m_orb.currents.get_object_id(); - return id; - } - catch (NoContext ex) - { - return object.Id; - } - } - - /** - * Always returns false; - */ - public boolean non_existent(Servant a_servant) - { - same(a_servant); - return false; - } - - /** - * Return the associated POA. - */ - public POA poa(Servant a_servant) - { - same(a_servant); - try - { - return poa.m_orb.currents.get_POA(); - } - catch (NoContext ex) - { - return poa; - } - } - - /** - * Checks if the passed servant is the same as the servant, associated with - * this delegate. This class requires a single servant per delegate. - */ - void same(Servant some_servant) - { - if (servant != some_servant) - throw new InternalError("Only one servant per delegate is supported."); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/vPolicy.java b/libjava/classpath/gnu/CORBA/Poa/vPolicy.java deleted file mode 100644 index 9e45b56..0000000 --- a/libjava/classpath/gnu/CORBA/Poa/vPolicy.java +++ /dev/null @@ -1,62 +0,0 @@ -/* vPolicy.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA.Poa; - -import org.omg.CORBA.Policy; - -/** - * The Classpath implementation of the policy, providing the policy - * value and the code of the policy type. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public interface vPolicy - extends Policy -{ - /** - * Get the value of this policy - */ - java.lang.Object getValue(); - - /** - * Get the integer code of this policy value. - */ - int getCode(); - -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/RawReply.java b/libjava/classpath/gnu/CORBA/RawReply.java new file mode 100644 index 0000000..a36f4b4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/RawReply.java @@ -0,0 +1,95 @@ +/* RawReply.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.GIOP.MessageHeader; + +import org.omg.CORBA.ORB; + +/** + * The remote object reply in the binary form, holding + * the message header and the following binary data. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +class RawReply +{ + /** + * The message header. + */ + final MessageHeader header; + + /** + * The associated orb. + */ + final ORB orb; + + /** + * The message data. + */ + final byte[] data; + + /** + * Create the binary reply. + * + * @param an_header the message header + * @param a_data the message data. + */ + RawReply(ORB an_orb, MessageHeader an_header, byte[] a_data) + { + orb = an_orb; + header = an_header; + data = a_data; + } + + /** + * Get the CDR input stream with the correctly set alignment. + * + * @return the CDR stream to read the message data. + */ + BufferredCdrInput getStream() + { + BufferredCdrInput in = new BufferredCdrInput(data); + in.setOffset(header.getHeaderSize()); + in.setVersion(header.version); + in.setOrb(orb); + in.setBigEndian(header.isBigEndian()); + return in; + } +} diff --git a/libjava/classpath/gnu/CORBA/ResponseHandlerImpl.java b/libjava/classpath/gnu/CORBA/ResponseHandlerImpl.java new file mode 100644 index 0000000..4d509cc --- /dev/null +++ b/libjava/classpath/gnu/CORBA/ResponseHandlerImpl.java @@ -0,0 +1,189 @@ +/* ResponseHandlerImpl.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferedCdrOutput; +import gnu.CORBA.GIOP.MessageHeader; +import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.GIOP.RequestHeader; +import gnu.CORBA.GIOP.CodeSetServiceContext; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; + +/** + * Provides the CDR output streams for writing the response to the given buffer. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ResponseHandlerImpl + implements ResponseHandler +{ + /** + * The message header. This field is used to compute the size and alignments. + * It is, however, never directly written to the buffer stream. + */ + public final MessageHeader message_header; + + /** + * The associated orb. + */ + public final ORB orb; + + /** + * The reply header. + */ + public final ReplyHeader reply_header; + + /** + * The request header. + */ + public final RequestHeader request_header; + + /** + * True if the stream was obtained by invoking {@link #createExceptionReply()}, + * false otherwise. + */ + private boolean exceptionReply; + + /** + * The buffer to write into. + */ + private BufferedCdrOutput buffer; + + /** + * Create a new buffered response handler that uses the given message headers. + * The headers are used to compute sizes and check the versions. They are not + * written into a stream inside this class. + * + * @param m_header a message header. + * @param r_header a reply header. + */ + ResponseHandlerImpl(ORB an_orb, MessageHeader m_header, + ReplyHeader r_header, RequestHeader rq_header) + { + message_header = m_header; + reply_header = r_header; + request_header = rq_header; + orb = an_orb; + prepareStream(); + } + + /** + * Get an output stream for providing details about the exception. Before + * returning the stream, the handler automatically writes the message header + * and the reply about exception header, but not the message header. + * + * @return the stream to write exception details into. + */ + public OutputStream createExceptionReply() + { + exceptionReply = true; + prepareStream(); + return buffer; + } + + /** + * Get an output stream for writing a regular reply (not an exception). + * + * Before returning the stream, the handler automatically writes the regular + * reply header, but not the message header. + * + * @return the output stream for writing a regular reply. + */ + public OutputStream createReply() + { + exceptionReply = false; + prepareStream(); + reply_header.reply_status = ReplyHeader.NO_EXCEPTION; + return buffer; + } + + /** + * Get the buffer, normally containing the written reply. The reply includes + * the reply header (or the exception header) but does not include the message + * header. + * + * The stream buffer can also be empty if no data have been written into + * streams, returned by {@link #createReply()} or + * {@link #createExceptionReply()}. + * + * @return the CDR output stream, containing the written output. + */ + public BufferedCdrOutput getBuffer() + { + return buffer; + } + + /** + * True if the stream was obtained by invoking {@link #createExceptionReply()}, + * false otherwise (usually no-exception reply). + */ + public boolean isExceptionReply() + { + return exceptionReply; + } + + /** + * Compute the header offset, set the correct version number and codeset. + */ + private void prepareStream() + { + buffer = new BufferedCdrOutput(); + buffer.setOrb(orb); + buffer.setVersion(message_header.version); + buffer.setCodeSet(CodeSetServiceContext.find(reply_header.service_context)); + + // Since 1.2, the data section is always aligned on the 8 byte boundary. + // In older versions, it is necessary to set the offset correctly. + if (message_header.version.until_inclusive(1, 1)) + { + buffer.setOffset(message_header.getHeaderSize()); + + // Get the position after the reply header would be written. + reply_header.write(buffer); + + int new_offset = message_header.getHeaderSize() + buffer.buffer.size(); + + buffer.buffer.reset(); + buffer.setOffset(new_offset); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/Restricted_ORB.java b/libjava/classpath/gnu/CORBA/Restricted_ORB.java deleted file mode 100644 index 247cd20..0000000 --- a/libjava/classpath/gnu/CORBA/Restricted_ORB.java +++ /dev/null @@ -1,524 +0,0 @@ -/* RestrictedORB.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufOutput; - -import org.omg.CORBA.Any; -import org.omg.CORBA.BAD_PARAM; -import org.omg.CORBA.ContextList; -import org.omg.CORBA.Environment; -import org.omg.CORBA.ExceptionList; -import org.omg.CORBA.NO_IMPLEMENT; -import org.omg.CORBA.NVList; -import org.omg.CORBA.NamedValue; -import org.omg.CORBA.ORB; -import org.omg.CORBA.ORBPackage.InvalidName; -import org.omg.CORBA.Request; -import org.omg.CORBA.StructMember; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; -import org.omg.CORBA.UnionMember; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.ValueFactory; -import org.omg.PortableInterceptor.ClientRequestInterceptorOperations; -import org.omg.PortableInterceptor.IORInterceptorOperations; -import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; - -import java.applet.Applet; - -import java.util.Hashtable; -import java.util.Properties; - -/** - * This class implements so-called Singleton ORB, a highly restricted version - * that cannot communicate over network. This ORB is provided for the - * potentially malicious applets with heavy security restrictions. It, however, - * supports some basic features that might be needed even when the network - * access is not granted. - * - * This ORB can only create typecodes, {@link Any}, {@link ContextList}, - * {@link NVList} and {@link org.omg.CORBA.portable.OutputStream} that writes to - * an internal buffer. - * - * All other methods throw the {@link NO_IMPLEMENT} exception. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class Restricted_ORB extends org.omg.CORBA_2_3.ORB -{ - /** - * The singleton instance of this ORB. - */ - public static final ORB Singleton = new Restricted_ORB(); - - /** - * The cumulated listener for all IOR interceptors. Interceptors are used by - * {@link gnu.CORBA.Poa.ORB_1_4}. - */ - public IORInterceptorOperations iIor; - - /** - * The cumulated listener for all server request interceptors. Interceptors - * are used by {@link gnu.CORBA.Poa.ORB_1_4}. - */ - public ServerRequestInterceptorOperations iServer; - - /** - * The cumulated listener for all client request interceptros. Interceptors - * are used by {@link gnu.CORBA.Poa.ORB_1_4}. - */ - public ClientRequestInterceptorOperations iClient; - - /** - * The required size of the interceptor slot array. - */ - public int icSlotSize = 0; - - /** - * The value factories. - */ - protected Hashtable factories = new Hashtable(); - - /** - * The policy factories. - */ - protected Hashtable policyFactories = new Hashtable(); - - /** - * Create a new instance of the RestrictedORB. This is used in derived classes - * only. - */ - protected Restricted_ORB() - { - } - - /** {@inheritDoc} */ - public TypeCode create_alias_tc(String id, String name, TypeCode typecode) - { - return new aliasTypeCode(typecode, id, name); - } - - /** {@inheritDoc} */ - public Any create_any() - { - gnuAny any = new gnuAny(); - any.setOrb(this); - return any; - } - - /** {@inheritDoc} */ - public TypeCode create_array_tc(int length, TypeCode element_type) - { - primitiveArrayTypeCode p = - new primitiveArrayTypeCode(TCKind.tk_array, element_type); - p.setLength(length); - return p; - } - - /** {@inheritDoc} */ - public ContextList create_context_list() - { - return new gnuContextList(); - } - - /** {@inheritDoc} */ - public TypeCode create_enum_tc(String id, String name, String[] values) - { - recordTypeCode r = new recordTypeCode(TCKind.tk_enum); - for (int i = 0; i < values.length; i++) - { - r.field().name = values [ i ]; - } - - r.setId(id); - r.setName(name); - - return r; - } - - /** {@inheritDoc} */ - public Environment create_environment() - { - return new gnuEnvironment(); - } - - /** {@inheritDoc} */ - public ExceptionList create_exception_list() - { - return new gnuExceptionList(); - } - - /** {@inheritDoc} */ - public TypeCode create_exception_tc(String id, String name, - StructMember[] members - ) - { - recordTypeCode r = new recordTypeCode(TCKind.tk_except); - r.setId(id); - r.setName(name); - - for (int i = 0; i < members.length; i++) - { - r.add(members [ i ]); - } - - return r; - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public TypeCode create_interface_tc(String id, String name) - { - no(); - return null; - } - - /** {@inheritDoc} */ - public NVList create_list(int count) - { - return new gnuNVList(count); - } - - /** {@inheritDoc} */ - public NamedValue create_named_value(String s, Any any, int flags) - { - return new gnuNamedValue(); - } - - /** {@inheritDoc} */ - public OutputStream create_output_stream() - { - cdrBufOutput stream = new cdrBufOutput(); - stream.setOrb(this); - return stream; - } - - /** {@inheritDoc} */ - public TypeCode create_sequence_tc(int bound, TypeCode element_type) - { - primitiveArrayTypeCode p = - new primitiveArrayTypeCode(TCKind.tk_sequence, element_type); - p.setLength(bound); - return p; - } - - /** {@inheritDoc} */ - public TypeCode create_string_tc(int bound) - { - stringTypeCode p = new stringTypeCode(TCKind.tk_string); - p.setLength(bound); - return p; - } - - /** {@inheritDoc} */ - public TypeCode create_struct_tc(String id, String name, - StructMember[] members - ) - { - recordTypeCode r = new recordTypeCode(TCKind.tk_struct); - r.setId(id); - r.setName(name); - - for (int i = 0; i < members.length; i++) - { - r.add(members [ i ]); - } - - return r; - } - - /** {@inheritDoc} */ - public TypeCode create_union_tc(String id, String name, - TypeCode discriminator_type, UnionMember[] members - ) - { - recordTypeCode r = new recordTypeCode(TCKind.tk_union); - r.setId(id); - r.setName(name); - r.setDiscriminator_type(discriminator_type); - r.setDefaultIndex(0); - - for (int i = 0; i < members.length; i++) - { - r.add(members [ i ]); - } - - return r; - } - - /** {@inheritDoc} */ - public TypeCode create_wstring_tc(int bound) - { - stringTypeCode p = new stringTypeCode(TCKind.tk_wstring); - p.setLength(bound); - return p; - } - - /** {@inheritDoc} */ - public TypeCode get_primitive_tc(TCKind tcKind) - { - try - { - return typeNamer.getPrimitveTC(tcKind); - } - catch (BadKind ex) - { - throw new BAD_PARAM("This is not a primitive type code: " + - tcKind.value() - ); - } - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public String[] list_initial_services() - { - no(); - throw new InternalError(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public String object_to_string(org.omg.CORBA.Object forObject) - { - no(); - throw new InternalError(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws InvalidName never in this class, but it is thrown in the derived - * classes. - * - * @throws NO_IMPLEMENT, always. - */ - public org.omg.CORBA.Object resolve_initial_references(String name) - throws InvalidName - { - no(); - throw new InternalError(); - } - - /** - * Shutdown the ORB server. - * - * For RestrictedORB, returns witout action. - */ - public void run() - { - } - - /** - * Shutdown the ORB server. - * - * For RestrictedORB, returns witout action. - */ - public void shutdown(boolean wait_for_completion) - { - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public org.omg.CORBA.Object string_to_object(String IOR) - { - no(); - throw new InternalError(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - protected void set_parameters(Applet app, Properties props) - { - no(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - protected void set_parameters(String[] args, Properties props) - { - no(); - } - - /** - * Throws an exception, stating that the given method is not supported by the - * Restricted ORB. - */ - private final void no() - { - // Apart the programming errors, this can only happen if the - // malicious code is trying to do that it is not allowed. - throw new NO_IMPLEMENT("Use init(args, props) for the functional version."); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public Request get_next_response() throws org.omg.CORBA.WrongTransaction - { - no(); - throw new InternalError(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public boolean poll_next_response() - { - no(); - throw new InternalError(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public void send_multiple_requests_deferred(Request[] requests) - { - no(); - } - - /** - * This method is not allowed for a RestrictedORB. - * - * @throws NO_IMPLEMENT, always. - */ - public void send_multiple_requests_oneway(Request[] requests) - { - no(); - } - - /** - * Register the value factory under the given repository id. - */ - public ValueFactory register_value_factory(String repository_id, - ValueFactory factory - ) - { - factories.put(repository_id, factory); - return factory; - } - - /** - * Unregister the value factroy. - */ - public void unregister_value_factory(String id) - { - factories.remove(id); - } - - /** - * Look for the value factory for the value, having the given repository id. - * The implementation checks for the registered value factories first. If none - * found, it tries to load and instantiate the class, mathing the given naming - * convention. If this faild, null is returned. - * - * @param repository_id a repository id. - * - * @return a found value factory, null if none. - */ - public ValueFactory lookup_value_factory(String repository_id) - { - ValueFactory f = (ValueFactory) factories.get(repository_id); - if (f != null) - { - return f; - } - - f = (ValueFactory) ObjectCreator.createObject(repository_id, - "DefaultFactory" - ); - if (f != null) - { - factories.put(repository_id, f); - } - return f; - } - - /** - * Destroy the interceptors, if they are present. - */ - public void destroy() - { - if (iIor != null) - { - iIor.destroy(); - iIor = null; - } - - if (iServer != null) - { - iServer.destroy(); - iServer = null; - } - - if (iClient != null) - { - iClient.destroy(); - iClient = null; - } - - super.destroy(); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java b/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java index 7f40fc8..a6f7aa5 100644 --- a/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java +++ b/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java @@ -38,7 +38,7 @@ exception statement from your version. */ package gnu.CORBA; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.BufferedCdrOutput; import org.omg.CORBA.ARG_IN; import org.omg.CORBA.ARG_INOUT; @@ -67,7 +67,7 @@ public class ServiceRequestAdapter /** * A buffer for writing the response. */ - cdrBufOutput reply = new cdrBufOutput(); + BufferedCdrOutput reply = new BufferedCdrOutput(); /** * If set to true, an exception has been thrown during the invocation. @@ -105,7 +105,7 @@ public class ServiceRequestAdapter int OUT = ARG_OUT.value; // Write all arguments to the buffer output stream. - cdrBufOutput buffer = new cdrBufOutput(); + BufferedCdrOutput buffer = new BufferedCdrOutput(); gnuNVList args = new gnuNVList(); request.arguments(args); @@ -127,7 +127,7 @@ public class ServiceRequestAdapter { // Write the exception information gnuAny exc = new gnuAny(); - universalHolder uku = new universalHolder(h.reply); + GeneralHolder uku = new GeneralHolder(h.reply); exc.insert_Streamable(uku); request.set_exception(exc); } @@ -146,7 +146,7 @@ public class ServiceRequestAdapter { // Use the universal holder otherwise. gnuAny r = new gnuAny(); - r.insert_Streamable(new streamReadyHolder(in)); + r.insert_Streamable(new StreamHolder(in)); } // Unpack the arguments diff --git a/libjava/classpath/gnu/CORBA/SimpleDelegate.java b/libjava/classpath/gnu/CORBA/SimpleDelegate.java new file mode 100644 index 0000000..c6e20e1 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/SimpleDelegate.java @@ -0,0 +1,294 @@ +/* Local_delegate.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * The delegate, implementing the basic functionality only. This delegate + * is set in {@link ORG.connect(org.omg.CORBA.Object)} if ORB + * determines that the object is an instance of the + * {@link org.omg.CORBA.portable.ObjectImpl} and no other delegate is set. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class SimpleDelegate + extends Delegate + implements IorProvider +{ + /** + * The orb. + */ + protected final ORB orb; + + /** + * The ior. + */ + protected IOR ior; + + public SimpleDelegate(ORB an_orb, IOR an_ior) + { + orb = an_orb; + ior = an_ior; + } + + /** + * Set the IOR of this object. The IOR must be newly set if + * the server reports that the object has permanently moved to a new + * location. + * + * @param an_ior the new IOR. + */ + public void setIor(IOR an_ior) + { + this.ior = an_ior; + } + + /** + * Get the IOR of this object. + */ + public IOR getIor() + { + return ior; + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, + NamedValue returns + ) + { + throw new NO_IMPLEMENT(); + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, + NamedValue returns, ExceptionList exceptions, + ContextList ctx_list + ) + { + throw new NO_IMPLEMENT(); + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target) + { + throw new NO_IMPLEMENT(); + } + + /** + * Performs direct comparison ('=='). + */ + public boolean equals(org.omg.CORBA.Object self, org.omg.CORBA.Object other) + { + return self == other; + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target) + { + throw new NO_IMPLEMENT(); + } + + /** + * Return the hashcode (0 <= hashcode < maximum). + */ + public int hash(org.omg.CORBA.Object target, int maximum) + { + return target == null ? 0 : target.hashCode() % maximum; + } + + /** + * Delegates functionality to java.lang.Object.hashCode(); + */ + public int hashCode(org.omg.CORBA.Object target) + { + return target == null ? 0 : target.hashCode(); + } + + /** + * Check if this object can be referenced by the given repository id. + * + * @param target the CORBA object, must be an instance of + * {@link org.omg.CORBA.portable.ObjectImpl}. + * + * @param repositoryIdentifer the repository id. + * + * @return true if the passed parameter is a repository id of this + * CORBA object. + */ + public boolean is_a(org.omg.CORBA.Object target, String repositoryIdentifer) + { + if (!(target instanceof ObjectImpl)) + throw new NO_IMPLEMENT("Supported only for org.omg.CORBA.portable.ObjectImpl"); + + ObjectImpl imp = (ObjectImpl) target; + String[] ids = imp._ids(); + + for (int i = 0; i < ids.length; i++) + { + if (ids [ i ].equals(repositoryIdentifer)) + return true; + } + return false; + } + + /** + * Returns true if the objects are the same or have the same delegate set. All + * objects in this implementation have a separate delegate. + */ + public boolean is_equivalent(org.omg.CORBA.Object target, + org.omg.CORBA.Object other) + { + if (target == other) + return true; + if ((target instanceof ObjectImpl) && other instanceof ObjectImpl) + { + try + { + org.omg.CORBA.portable.Delegate a = ((ObjectImpl) target)._get_delegate(); + org.omg.CORBA.portable.Delegate b = ((ObjectImpl) other)._get_delegate(); + if (a == b) + { + return true; + } + else + { + // We compere the IOR's in this case. + if (a instanceof IorProvider && b instanceof IorProvider) + { + IOR ia = ((IorProvider) a).getIor(); + IOR ib = ((IorProvider) b).getIor(); + + if (ia != null && ib != null) + return (ia.equals(ib)); + else + return ia == ib; + } + } + if (a != null && b != null) + { + return a.equals(b); + } + } + catch (Exception ex) + { + // Unable to get one of the delegates. + return false; + } + } + return false; + } + + /** + * Returns true by default. + */ + public boolean is_local(org.omg.CORBA.Object self) + { + return true; + } + + /** + * Returns true if the target is null. + */ + public boolean non_existent(org.omg.CORBA.Object target) + { + return target == null; + } + + /** + * Returns the ORB, passed in constructor, + * regardless of the argument. This class requires a single instance + * per each object. + */ + public ORB orb(org.omg.CORBA.Object target) + { + return orb; + } + + /** + * Returns without action. + */ + public void release(org.omg.CORBA.Object target) + { + } + + /** + * This method assumes that the target is local and connected to the ORB. + */ + public Request request(org.omg.CORBA.Object target, String operation) + { + if (orb instanceof OrbFunctional) + { + ((OrbFunctional) orb).ensureRunning(); + } + gnuRequest g = new gnuRequest(); + g.setORB(orb); + g.setOperation(operation); + g.setIor(ior); + g.m_target = target; + return g; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Simple_delegate.java b/libjava/classpath/gnu/CORBA/Simple_delegate.java deleted file mode 100644 index 5eabc7d..0000000 --- a/libjava/classpath/gnu/CORBA/Simple_delegate.java +++ /dev/null @@ -1,276 +0,0 @@ -/* Local_delegate.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.Context; -import org.omg.CORBA.ContextList; -import org.omg.CORBA.ExceptionList; -import org.omg.CORBA.NO_IMPLEMENT; -import org.omg.CORBA.NVList; -import org.omg.CORBA.NamedValue; -import org.omg.CORBA.ORB; -import org.omg.CORBA.Request; -import org.omg.CORBA.portable.Delegate; -import org.omg.CORBA.portable.ObjectImpl; - -/** - * The delegate, implementing the basic functionality only. This delegate - * is set in {@link ORG.connect(org.omg.CORBA.Object)} if ORB - * determines that the object is an instance of the - * {@link org.omg.CORBA.portable.ObjectImpl} and no other delegate is set. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class Simple_delegate - extends Delegate -{ - /** - * The orb. - */ - protected final ORB orb; - - /** - * The ior. - */ - protected IOR ior; - - public Simple_delegate(ORB an_orb, IOR an_ior) - { - orb = an_orb; - ior = an_ior; - } - - /** - * Set the IOR of this object. The IOR must be newly set if - * the server reports that the object has permanently moved to a new - * location. - * - * @param an_ior the new IOR. - */ - public void setIor(IOR an_ior) - { - this.ior = an_ior; - } - - /** - * Get the IOR of this object. - */ - public IOR getIor() - { - return ior; - } - - /** - * Not implemented. - * - * @throws NO_IMPLEMENT, always. - */ - public Request create_request(org.omg.CORBA.Object target, Context context, - String operation, NVList parameters, - NamedValue returns - ) - { - throw new NO_IMPLEMENT(); - } - - /** - * Not implemented. - * - * @throws NO_IMPLEMENT, always. - */ - public Request create_request(org.omg.CORBA.Object target, Context context, - String operation, NVList parameters, - NamedValue returns, ExceptionList exceptions, - ContextList ctx_list - ) - { - throw new NO_IMPLEMENT(); - } - - /** - * Not implemented. - * - * @throws NO_IMPLEMENT, always. - */ - public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target) - { - throw new NO_IMPLEMENT(); - } - - /** - * Performs direct comparison ('=='). - */ - public boolean equals(org.omg.CORBA.Object self, org.omg.CORBA.Object other) - { - return self == other; - } - - /** - * Not implemented. - * - * @throws NO_IMPLEMENT, always. - */ - public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target) - { - throw new NO_IMPLEMENT(); - } - - /** - * Return the hashcode (0 <= hashcode < maximum). - */ - public int hash(org.omg.CORBA.Object target, int maximum) - { - return target == null ? 0 : target.hashCode() % maximum; - } - - /** - * Delegates functionality to java.lang.Object.hashCode(); - */ - public int hashCode(org.omg.CORBA.Object target) - { - return target == null ? 0 : target.hashCode(); - } - - /** - * Check if this object can be referenced by the given repository id. - * - * @param target the CORBA object, must be an instance of - * {@link org.omg.CORBA.portable.ObjectImpl}. - * - * @param repositoryIdentifer the repository id. - * - * @return true if the passed parameter is a repository id of this - * CORBA object. - */ - public boolean is_a(org.omg.CORBA.Object target, String repositoryIdentifer) - { - if (!(target instanceof ObjectImpl)) - throw new NO_IMPLEMENT("Supported only for org.omg.CORBA.portable.ObjectImpl"); - - ObjectImpl imp = (ObjectImpl) target; - String[] ids = imp._ids(); - - for (int i = 0; i < ids.length; i++) - { - if (ids [ i ].equals(repositoryIdentifer)) - return true; - } - return false; - } - - /** - * Returns true if the objects are the same of have - * the same delegate set. All objects in this implementation - * have a separate delegate. - */ - public boolean is_equivalent(org.omg.CORBA.Object target, - org.omg.CORBA.Object other - ) - { - if (target == other) - return true; - if ((target instanceof ObjectImpl) && other instanceof ObjectImpl) - { - try - { - org.omg.CORBA.portable.Delegate a = - ((ObjectImpl) target)._get_delegate(); - org.omg.CORBA.portable.Delegate b = - ((ObjectImpl) other)._get_delegate(); - if (a == b) - { - return true; - } - if (a != null && b != null) - { - return a.equals(b); - } - } - catch (Exception ex) - { - // Unable to get one of the delegates. - return false; - } - } - return false; - } - - /** - * Returns true by default. - */ - public boolean is_local(org.omg.CORBA.Object self) - { - return true; - } - - /** - * Returns true if the target is null. - */ - public boolean non_existent(org.omg.CORBA.Object target) - { - return target == null; - } - - /** - * Returns the ORB, passed in constructor, - * regardless of the argument. This class requires a single instance - * per each object. - */ - public ORB orb(org.omg.CORBA.Object target) - { - return orb; - } - - /** - * Returns without action. - */ - public void release(org.omg.CORBA.Object target) - { - } - - /** - * This should never be called this type delegate. - * - * @throws InternalError, always. - */ - public Request request(org.omg.CORBA.Object target, String operation) - { - throw new InternalError(); - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/SocketRepository.java b/libjava/classpath/gnu/CORBA/SocketRepository.java index a6b9920..e48a9a5 100644 --- a/libjava/classpath/gnu/CORBA/SocketRepository.java +++ b/libjava/classpath/gnu/CORBA/SocketRepository.java @@ -40,8 +40,9 @@ package gnu.CORBA; import java.net.Socket; import java.net.SocketException; - import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; /** * This class caches the opened sockets that are reused during the @@ -56,9 +57,10 @@ public class SocketRepository * The socket map. */ private static HashMap sockets = new HashMap(); - + /** - * Put a socket. + * Put a socket. This method also discards all not reusable sockets from + * the map. * * @param key as socket key. * @@ -66,7 +68,41 @@ public class SocketRepository */ public static void put_socket(Object key, Socket s) { - sockets.put(key, s); + synchronized (sockets) + { + sockets.put(key, s); + gc(); + } + } + + /** + * Removes all non reusable sockets. As it is private, + * we know we call from the synchronized code already. + */ + private static void gc() + { + Iterator iter = sockets.entrySet().iterator(); + + Map.Entry e; + Socket sx; + + while (iter.hasNext()) + { + e = (Map.Entry) iter.next(); + sx = (Socket) e.getValue(); + + if (not_reusable(sx)) + iter.remove(); + } + } + + /** + * Return true if the socket is no longer reusable. + */ + static boolean not_reusable(Socket s) + { + return (s.isClosed() || !s.isBound() || !s.isConnected() || + s.isInputShutdown() || s.isOutputShutdown()); } /** @@ -75,31 +111,41 @@ public class SocketRepository * @param key a socket key. * * @return an opened socket for reuse, null if no such available or it is - * closed. + * closed, its input or output has been shutown or otherwise the socket is not + * reuseable. */ public static Socket get_socket(Object key) { - Socket s = (Socket) sockets.get(key); - if (s == null) + if (true) return null; - else if (s.isClosed()) - { - sockets.remove(key); - return null; - } - else + + synchronized (sockets) { - sockets.remove(key); - try + Socket s = (Socket) sockets.get(key); + if (s == null) + return null; + + // Ensure that the socket is fully reusable. + else if (not_reusable(s)) { - // Set one minute time out that will be changed later. - s.setSoTimeout(60*1000); + sockets.remove(key); + return null; } - catch (SocketException e) + else { - s = null; + try + { + // Set one minute time out that will be changed later. + s.setSoTimeout(60 * 1000); + } + catch (SocketException e) + { + s = null; + } + + sockets.remove(key); + return s; } - return s; } } } \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/StreamBasedRequest.java b/libjava/classpath/gnu/CORBA/StreamBasedRequest.java new file mode 100644 index 0000000..66796d6 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/StreamBasedRequest.java @@ -0,0 +1,60 @@ +/* gnuStreamRequest.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.BufferedCdrOutput; + +/** + * A stream, additionally holding the gnu request. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class StreamBasedRequest + extends BufferedCdrOutput +{ + /** + * The enclosed request. + */ + public gnuRequest request; + + /** + * True if the response is expected. + */ + public boolean response_expected = true; +} diff --git a/libjava/classpath/gnu/CORBA/StreamHolder.java b/libjava/classpath/gnu/CORBA/StreamHolder.java new file mode 100644 index 0000000..de2fda0 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/StreamHolder.java @@ -0,0 +1,123 @@ +/* StreamHolder.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.CORBA; + +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; + +/** + * A holder that stores the input stream, from that the holder data + * can be read. There is no way to write the data into this holder. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class StreamHolder + implements Streamable +{ + /** + * The stream, holding the data for this holder. + */ + protected final InputStream stream; + + /** + * Create a holder that will read from the given stream. + * + * @param a_stream a stream. + */ + public StreamHolder(InputStream a_stream) + { + stream = a_stream; + } + + /** + * This method is not in use, should never be called. + */ + public TypeCode _type() + { + throw new NO_IMPLEMENT(); + } + + /** + * Writes the data from the stored stream into the provided + * output stream till the end of the input stream is reached. + * + * @throws MARSHAL if the IOException is thrown during operation. + */ + public void _write(OutputStream output) + { + try + { + int d = stream.read(); + + while (d >= 0) + { + output.write(d); + d = stream.read(); + } + } + catch (IOException ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + m.minor = Minor.CDR; + throw m; + } + } + + /** + * This method is not in use, should never be called. + */ + public void _read(InputStream input) + { + throw new NO_IMPLEMENT(); + } + + /** + * Get the input stream that has been passed in constructor. + */ + InputStream getInputStream() + { + return stream; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/StubLocator.java b/libjava/classpath/gnu/CORBA/StubLocator.java new file mode 100644 index 0000000..d9e5ee4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/StubLocator.java @@ -0,0 +1,110 @@ +/* StubLocator.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * Finds a stub class like "_HelloStub" that can be instantiated + * from IOR reference. The returned object can be casted to the + * used type like "Hello" without using the helper .narrow method, + * and the object is not unnsecessarily re - instantiated if + * the .narrow method is used anyway. If no stub, matching the naming + * conventions, is available, the returned stub replacement can still be used + * to get the valid request, add parameter and invoke the method by name. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class StubLocator +{ + /** + * Search for the possibly available default stub. + * + * @param orb the current ORB. It is not required to find the binding + * classes, but is needed to instantiate the default implementation + * if no binding classes are found. + * + * @param ior the IOR, possibly containing the information about the + * correct implementation class. + */ + public static ObjectImpl search(ORB orb, IOR ior) + { + try + { + int a = ior.Id.indexOf(':'); + int b = ior.Id.lastIndexOf(':'); + + String s = ior.Id.substring(a + 1, b).replace('/', '.'); + + String path; + + b = s.lastIndexOf('.'); + if (b > 0) + path = s.substring(0, b + 1); + else + path = ""; + + String stub = "_" + s.substring(b + 1) + "Stub"; + + Class stubClass = ObjectCreator.forName(path + stub); + + return (ObjectImpl) stubClass.newInstance(); + } + catch (Exception failed) + { + // Various exceptions can be thrown if the Id cannot be parsed, + // the class is missing, cannot be instantiated or is not an + // instance of the ObjectImpl. + return createDefaultStub(orb, ior); + } + } + + /** + * Return the default stub for the case when the client binding classes + * are not locally available. The returned stub can still be used + * to get the valid request, add parameter and invoke the method by name. + * + * @return the default implementation. + */ + protected static ObjectImpl createDefaultStub(ORB orb, IOR ior) + { + return new IorObject(orb, ior); + } +} diff --git a/libjava/classpath/gnu/CORBA/TypeCodeHelper.java b/libjava/classpath/gnu/CORBA/TypeCodeHelper.java index c742275..4ffb0b7 100644 --- a/libjava/classpath/gnu/CORBA/TypeCodeHelper.java +++ b/libjava/classpath/gnu/CORBA/TypeCodeHelper.java @@ -38,6 +38,13 @@ exception statement from your version. */ package gnu.CORBA; +import gnu.CORBA.typecodes.FixedTypeCode; +import gnu.CORBA.typecodes.GeneralTypeCode; +import gnu.CORBA.typecodes.ArrayTypeCode; +import gnu.CORBA.typecodes.PrimitiveTypeCode; +import gnu.CORBA.typecodes.RecordTypeCode; +import gnu.CORBA.typecodes.StringTypeCode; + import org.omg.CORBA.TCKind; import org.omg.CORBA.TypeCode; import org.omg.CORBA.TypeCodePackage.BadKind; @@ -62,10 +69,10 @@ public class TypeCodeHelper { TCKind kind = TCKind.from_int(in.read_long()); TypeCode rt; - generalTypeCode g; - recordTypeCode r; - recordTypeCode.Field f; - stringTypeCode s; + GeneralTypeCode g; + RecordTypeCode r; + RecordTypeCode.Field f; + StringTypeCode s; int n; switch (kind.value()) @@ -73,21 +80,21 @@ public class TypeCodeHelper case TCKind._tk_sequence : case TCKind._tk_array : - primitiveArrayTypeCode p = new primitiveArrayTypeCode(kind); + ArrayTypeCode p = new ArrayTypeCode(kind); p.setLength(in.read_long()); rt = p; break; case TCKind._tk_string : case TCKind._tk_wstring : - s = new stringTypeCode(kind); + s = new StringTypeCode(kind); s.setLength(in.read_long()); rt = s; break; case TCKind._tk_fixed : - fixedTypeCode fx = new fixedTypeCode(); + FixedTypeCode fx = new FixedTypeCode(); fx.setDigits(in.read_short()); fx.setScale(in.read_short()); rt = fx; @@ -96,7 +103,7 @@ public class TypeCodeHelper case TCKind._tk_objref : case TCKind._tk_native : case TCKind._tk_abstract_interface : - g = new generalTypeCode(kind); + g = new GeneralTypeCode(kind); g.setId(in.read_string()); g.setName(in.read_string()); rt = g; @@ -104,7 +111,7 @@ public class TypeCodeHelper case TCKind._tk_alias : case TCKind._tk_value_box : - g = new generalTypeCode(kind); + g = new GeneralTypeCode(kind); g.setId(in.read_string()); g.setName(in.read_string()); g.setContentType(in.read_TypeCode()); @@ -113,7 +120,7 @@ public class TypeCodeHelper case TCKind._tk_struct : case TCKind._tk_except : - r = new recordTypeCode(kind); + r = new RecordTypeCode(kind); r.setId(in.read_string()); r.setName(in.read_string()); @@ -129,7 +136,7 @@ public class TypeCodeHelper break; case TCKind._tk_enum : - r = new recordTypeCode(kind); + r = new RecordTypeCode(kind); r.setId(in.read_string()); r.setName(in.read_string()); @@ -144,7 +151,7 @@ public class TypeCodeHelper break; case TCKind._tk_union : - r = new recordTypeCode(kind); + r = new RecordTypeCode(kind); r.setId(in.read_string()); r.setName(in.read_string()); r.setDiscriminator_type(in.read_TypeCode()); @@ -164,7 +171,7 @@ public class TypeCodeHelper break; case TCKind._tk_value : - r = new recordTypeCode(kind); + r = new RecordTypeCode(kind); r.setId(in.read_string()); r.setName(in.read_string()); r.setTypeModifier(in.read_short()); @@ -183,7 +190,7 @@ public class TypeCodeHelper break; default : - rt = new primitiveTypeCode(kind); + rt = new PrimitiveTypeCode(kind); } return rt; } diff --git a/libjava/classpath/gnu/CORBA/TypeKindNamer.java b/libjava/classpath/gnu/CORBA/TypeKindNamer.java new file mode 100644 index 0000000..3296db3 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/TypeKindNamer.java @@ -0,0 +1,183 @@ +/* primitiveTypes.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.typecodes.PrimitiveTypeCode; +import gnu.CORBA.typecodes.RecordTypeCode; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A conveniency method for naming the built-in types. + * This is used in error reporting that is part of the user interface. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class TypeKindNamer +{ + /** + * Names of the primitve types. + */ + protected static final String[] tk = + new String[] + { + "null", "void", "short", "long", "ushort", "ulong", "float", "double", + "boolean", "char", "octet", "any", "TypeCode", "Principal", "objref", + "struct", "union", "enum", "string", "sequence", "array", "alias", + "exception", "longlong", "ulonglong", "longdouble", "wchar", "wstring", + "fixed", "value", "value_box", "native", "abstract_interface" + }; + + /** + * Primitve TypeCodes. + */ + protected static final TypeCode[] primitveCodes = + new TypeCode[] + { + new PrimitiveTypeCode(TCKind.tk_null), + new PrimitiveTypeCode(TCKind.tk_void), + new PrimitiveTypeCode(TCKind.tk_short), + new PrimitiveTypeCode(TCKind.tk_long), + new PrimitiveTypeCode(TCKind.tk_ushort), + new PrimitiveTypeCode(TCKind.tk_ulong), + new PrimitiveTypeCode(TCKind.tk_float), + new PrimitiveTypeCode(TCKind.tk_double), + new PrimitiveTypeCode(TCKind.tk_boolean), + new PrimitiveTypeCode(TCKind.tk_char), + new PrimitiveTypeCode(TCKind.tk_octet), + new PrimitiveTypeCode(TCKind.tk_any), + new PrimitiveTypeCode(TCKind.tk_TypeCode), + new PrimitiveTypeCode(TCKind.tk_Principal), + new RecordTypeCode(TCKind.tk_objref), + new PrimitiveTypeCode(TCKind.tk_struct), + new PrimitiveTypeCode(TCKind.tk_union), + new PrimitiveTypeCode(TCKind.tk_enum), + new PrimitiveTypeCode(TCKind.tk_string), + new PrimitiveTypeCode(TCKind.tk_sequence), + new PrimitiveTypeCode(TCKind.tk_array), + new PrimitiveTypeCode(TCKind.tk_alias), + new PrimitiveTypeCode(TCKind.tk_except), + new PrimitiveTypeCode(TCKind.tk_longlong), + new PrimitiveTypeCode(TCKind.tk_ulonglong), + new PrimitiveTypeCode(TCKind.tk_longdouble), + new PrimitiveTypeCode(TCKind.tk_wchar), + new PrimitiveTypeCode(TCKind.tk_wstring), + new PrimitiveTypeCode(TCKind.tk_fixed), + new PrimitiveTypeCode(TCKind.tk_value), + new PrimitiveTypeCode(TCKind.tk_value_box), + new PrimitiveTypeCode(TCKind.tk_native), + new PrimitiveTypeCode(TCKind.tk_abstract_interface) + }; + + static + { + // The Id of the "abstract object" is defined as empty string. + RecordTypeCode object = + (RecordTypeCode) primitveCodes [ TCKind._tk_objref ]; + object.setId(""); + object.setName("Object"); + } + + /** + * Get the primitive type code. + * + * @return the primitve type code, corresponding the passed value. + * + * @throws BadKind if this is not a primitive type code. + */ + public static TypeCode getPrimitveTC(TCKind tc) + throws BadKind + { + try + { + return primitveCodes [ tc.value() ]; + } + catch (ArrayIndexOutOfBoundsException ex) + { + throw new BadKind(tc.value() + " is not a primitve type."); + } + } + + /** + * Get the string name of the passed primitive type. + * + * @param kind the kind of the primitive type the must be defined + * in {@link omg.org.CORBA.TCKind}. + * + * @return the short string name, used in error reporting, etc. + */ + public static String nameIt(int kind) + { + try + { + return tk [ kind ]; + } + catch (ArrayIndexOutOfBoundsException ex) + { + return "type of kind '" + kind + "'"; + } + } + + /** + * Get the string name of the passed primitive type. + * + * @param kind the kind of the primitive type the must be defined + * in {@link omg.org.CORBA.TCKind}. + * + * @return the short string name, used in error reporting, etc. + */ + public static String nameIt(TypeCode type) + { + try + { + if (type.kind().value() == TCKind._tk_array) + return "array of " + nameIt(type.content_type()); + else if (type.kind().value() == TCKind._tk_sequence) + return "sequence of " + nameIt(type.content_type()); + else + return nameIt(type.kind().value()); + } + catch (Exception ex) + { + return "type of kind '" + type.kind().value() + "'"; + } + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Version.java b/libjava/classpath/gnu/CORBA/Version.java index 84f40bf..efc27c2 100644 --- a/libjava/classpath/gnu/CORBA/Version.java +++ b/libjava/classpath/gnu/CORBA/Version.java @@ -70,8 +70,8 @@ public class Version /** * Create the version with the given version numbers. * - * @param major major number (0..255) - * @param minor minor number (0..255) + * @param _major major number (0..255) + * @param _minor minor number (0..255) */ public Version(int _major, int _minor) { @@ -99,6 +99,15 @@ public class Version Version that = (Version) other; return same(that); } + + /** + * Get the hashcode, higher 8 bits being the major version and lower 8 bits + * the minor version. + */ + public int hashCode() + { + return major << 8 | minor; + } /** * Read from the input stream, major number first. @@ -114,7 +123,10 @@ public class Version } catch (IOException ex) { - throw new MARSHAL("IOException while reading message header"); + MARSHAL m = new MARSHAL("IOException while reading message header"); + m.initCause(ex); + m.minor = Minor.Header; + throw m; } } @@ -166,7 +178,7 @@ public class Version * Returs true if the given version is lower or equal to the * version, specified by the provided minor and major version * number. This means, the version, specified by these two numbers, - * should be supported by teh current version. + * should be supported by the current version. * * @param a_major a major version number. * @param a_minor a minor version number. @@ -200,7 +212,11 @@ public class Version } catch (IOException ex) { - throw new MARSHAL("IOException while writing message header"); + MARSHAL m = new MARSHAL("IOException while writing message header"); + m.minor = Minor.Header; + m.initCause(ex); + throw m; } } + } diff --git a/libjava/classpath/gnu/CORBA/WCharHolder.java b/libjava/classpath/gnu/CORBA/WCharHolder.java index 23f0ad1..3c6a87f 100644 --- a/libjava/classpath/gnu/CORBA/WCharHolder.java +++ b/libjava/classpath/gnu/CORBA/WCharHolder.java @@ -38,6 +38,8 @@ exception statement from your version. */ package gnu.CORBA; +import gnu.CORBA.typecodes.PrimitiveTypeCode; + import org.omg.CORBA.TCKind; import org.omg.CORBA.TypeCode; import org.omg.CORBA.portable.InputStream; @@ -61,7 +63,7 @@ public final class WCharHolder /** * The default type code for this holder. */ - private static final TypeCode t_char = new primitiveTypeCode(TCKind.tk_wchar); + private static final TypeCode t_char = new PrimitiveTypeCode(TCKind.tk_wchar); /** * The char (CORBA wchar) value, diff --git a/libjava/classpath/gnu/CORBA/WStringHolder.java b/libjava/classpath/gnu/CORBA/WStringHolder.java index c9e8e33..7f18791 100644 --- a/libjava/classpath/gnu/CORBA/WStringHolder.java +++ b/libjava/classpath/gnu/CORBA/WStringHolder.java @@ -38,6 +38,8 @@ exception statement from your version. */ package gnu.CORBA; +import gnu.CORBA.typecodes.StringTypeCode; + import org.omg.CORBA.TCKind; import org.omg.CORBA.TypeCode; import org.omg.CORBA.portable.InputStream; @@ -62,8 +64,8 @@ public class WStringHolder /** * The default type code for this holder. */ - private static final stringTypeCode t_string = - new stringTypeCode(TCKind.tk_wstring); + private static final StringTypeCode t_string = + new StringTypeCode(TCKind.tk_wstring); /** * The String (CORBA string) value, diff --git a/libjava/classpath/gnu/CORBA/_PolicyImplBase.java b/libjava/classpath/gnu/CORBA/_PolicyImplBase.java index d9ff9d6..17a5f4a 100644 --- a/libjava/classpath/gnu/CORBA/_PolicyImplBase.java +++ b/libjava/classpath/gnu/CORBA/_PolicyImplBase.java @@ -165,7 +165,8 @@ public abstract class _PolicyImplBase output.write_long(policyCode); } else - throw new BAD_OPERATION(method, 0, CompletionStatus.COMPLETED_MAYBE); + throw new BAD_OPERATION(method, Minor.Method, + CompletionStatus.COMPLETED_MAYBE); return output; } diff --git a/libjava/classpath/gnu/CORBA/aliasTypeCode.java b/libjava/classpath/gnu/CORBA/aliasTypeCode.java deleted file mode 100644 index 8846631..0000000 --- a/libjava/classpath/gnu/CORBA/aliasTypeCode.java +++ /dev/null @@ -1,142 +0,0 @@ -/* aliasTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; - -/** - * The type code that is an alias of another type code. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class aliasTypeCode - extends primitiveTypeCode -{ - /** - * The typecode repository id. - */ - protected final String id; - - /** - * The typecode name. - */ - protected final String name; - - /** - * The type code for that this typecode is an alias. - */ - protected final TypeCode aliasFor; - - /** - * Create the typecode, specifying for that typecode it is an - * alias and the id and name of the newly created typecode. - * - * @param an_aliasFor the typecode, for that this typecode is an - * alias. - * - * @param an_id the repository id fo the newly created typecode. - * - * @param a_name the name of the newly created typecode. - */ - public aliasTypeCode(TypeCode an_aliasFor, String an_id, String a_name) - { - super(TCKind.tk_alias); - aliasFor = an_aliasFor; - id = an_id; - name = a_name; - } - - /** - * Get the typecode, for that this typecode is an alias. - */ - public TypeCode content_type() - { - return aliasFor; - } - - /** - * The objects are assumed to be equal if they repository - * ids are both equal or both unavailable and the - * kind values are equal. - * - * @param other the other typecode to compare. - */ - public boolean equal(TypeCode other) - { - if (super.equal(other)) - return true; - try - { - return id.equals(other.id()); - } - catch (BadKind ex) - { - return false; - } - } - - /** - * Return true if the given typecode is equal for - * either this typecode of the alias typecode. - * - * @param other the typecode to compare. - */ - public boolean equivalent(TypeCode other) - { - return other.equal(this) || other.equal(aliasFor); - } - - /** - * Get the repository id of this typecode. - */ - public String id() - { - return id; - } - - /** - * Get the name of this typecode. - */ - public String name() - { - return name; - } -} diff --git a/libjava/classpath/gnu/CORBA/binaryReply.java b/libjava/classpath/gnu/CORBA/binaryReply.java deleted file mode 100644 index 71afa37..0000000 --- a/libjava/classpath/gnu/CORBA/binaryReply.java +++ /dev/null @@ -1,95 +0,0 @@ -/* binaryReply.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.GIOP.MessageHeader; - -import org.omg.CORBA.ORB; - -/** - * The remote object reply in the binary form, holding - * the message header and the following binary data. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -class binaryReply -{ - /** - * The message header. - */ - final MessageHeader header; - - /** - * The associated orb. - */ - final ORB orb; - - /** - * The message data. - */ - final byte[] data; - - /** - * Create the binary reply. - * - * @param an_header the message header - * @param a_data the message data. - */ - binaryReply(ORB an_orb, MessageHeader an_header, byte[] a_data) - { - orb = an_orb; - header = an_header; - data = a_data; - } - - /** - * Get the CDR input stream with the correctly set alignment. - * - * @return the CDR stream to read the message data. - */ - cdrBufInput getStream() - { - cdrBufInput in = new cdrBufInput(data); - in.setOffset(header.getHeaderSize()); - in.setVersion(header.version); - in.setOrb(orb); - in.setBigEndian(header.isBigEndian()); - return in; - } -} diff --git a/libjava/classpath/gnu/CORBA/bufferedResponseHandler.java b/libjava/classpath/gnu/CORBA/bufferedResponseHandler.java deleted file mode 100644 index 0fe945c..0000000 --- a/libjava/classpath/gnu/CORBA/bufferedResponseHandler.java +++ /dev/null @@ -1,189 +0,0 @@ -/* bufferedResponseHandler.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufOutput; -import gnu.CORBA.GIOP.MessageHeader; -import gnu.CORBA.GIOP.ReplyHeader; -import gnu.CORBA.GIOP.RequestHeader; -import gnu.CORBA.GIOP.cxCodeSet; - -import org.omg.CORBA.ORB; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.ResponseHandler; - -/** - * Provides the CDR output streams for writing the response to the given buffer. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class bufferedResponseHandler - implements ResponseHandler -{ - /** - * The message header. This field is used to compute the size and alignments. - * It is, however, never directly written to the buffer stream. - */ - public final MessageHeader message_header; - - /** - * The associated orb. - */ - public final ORB orb; - - /** - * The reply header. - */ - public final ReplyHeader reply_header; - - /** - * The request header. - */ - public final RequestHeader request_header; - - /** - * True if the stream was obtained by invoking {@link #createExceptionReply()}, - * false otherwise. - */ - private boolean exceptionReply; - - /** - * The buffer to write into. - */ - private cdrBufOutput buffer; - - /** - * Create a new buffered response handler that uses the given message headers. - * The headers are used to compute sizes and check the versions. They are not - * written into a stream inside this class. - * - * @param m_header a message header. - * @param r_header a reply header. - */ - bufferedResponseHandler(ORB an_orb, MessageHeader m_header, - ReplyHeader r_header, RequestHeader rq_header) - { - message_header = m_header; - reply_header = r_header; - request_header = rq_header; - orb = an_orb; - prepareStream(); - } - - /** - * Get an output stream for providing details about the exception. Before - * returning the stream, the handler automatically writes the message header - * and the reply about exception header, but not the message header. - * - * @return the stream to write exception details into. - */ - public OutputStream createExceptionReply() - { - exceptionReply = true; - prepareStream(); - return buffer; - } - - /** - * Get an output stream for writing a regular reply (not an exception). - * - * Before returning the stream, the handler automatically writes the regular - * reply header, but not the message header. - * - * @return the output stream for writing a regular reply. - */ - public OutputStream createReply() - { - exceptionReply = false; - prepareStream(); - reply_header.reply_status = ReplyHeader.NO_EXCEPTION; - return buffer; - } - - /** - * Get the buffer, normally containing the written reply. The reply includes - * the reply header (or the exception header) but does not include the message - * header. - * - * The stream buffer can also be empty if no data have been written into - * streams, returned by {@link #createReply()} or - * {@link #createExceptionReply()}. - * - * @return the CDR output stream, containing the written output. - */ - public cdrBufOutput getBuffer() - { - return buffer; - } - - /** - * True if the stream was obtained by invoking {@link #createExceptionReply()}, - * false otherwise (usually no-exception reply). - */ - public boolean isExceptionReply() - { - return exceptionReply; - } - - /** - * Compute the header offset, set the correct version number and codeset. - */ - private void prepareStream() - { - buffer = new cdrBufOutput(); - buffer.setOrb(orb); - buffer.setVersion(message_header.version); - buffer.setCodeSet(cxCodeSet.find(reply_header.service_context)); - - // Since 1.2, the data section is always aligned on the 8 byte boundary. - // In older versions, it is necessary to set the offset correctly. - if (message_header.version.until_inclusive(1, 1)) - { - buffer.setOffset(message_header.getHeaderSize()); - - // Get the position after the reply header would be written. - reply_header.write(buffer); - - int new_offset = message_header.getHeaderSize() + buffer.buffer.size(); - - buffer.buffer.reset(); - buffer.setOffset(new_offset); - } - } -} diff --git a/libjava/classpath/gnu/CORBA/cdrEncapsCodec.java b/libjava/classpath/gnu/CORBA/cdrEncapsCodec.java deleted file mode 100644 index 699c6f7..0000000 --- a/libjava/classpath/gnu/CORBA/cdrEncapsCodec.java +++ /dev/null @@ -1,356 +0,0 @@ -/* cdrEncapsCodec.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; -import gnu.CORBA.CDR.cdrOutput; - -import org.omg.CORBA.Any; -import org.omg.CORBA.LocalObject; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.ORB; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.UserException; -import org.omg.IOP.Codec; -import org.omg.IOP.CodecPackage.FormatMismatch; -import org.omg.IOP.CodecPackage.InvalidTypeForEncoding; -import org.omg.IOP.CodecPackage.TypeMismatch; - -/** - * The local {@link Codec} implementation for ENCODING_CDR_ENCAPS - * encoding. This is a local implementation; the remote side should - * have its own Codec of this kind. - * - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class cdrEncapsCodec - extends LocalObject - implements Codec -{ - /** - * The default version of encoding, used in parameterless constructor. - */ - private static final Version DEFAULT_VERSION = new Version(1, 2); - - /** - * If set to true, no wide string or wide character is allowed (GIOP 1.0). - */ - private final boolean noWide; - - /** - * The version of this encoding. - */ - private final Version version; - - /** - * The associated ORB. - */ - protected final ORB orb; - - /** - * If true, this Codec writes the record length (as int) in the beginning - * of the record. This indicator is part of the formal OMG standard, but it is - * missing in Sun's implementation. Both Suns's and this Codec detects - * the indicator, if present, but can also decode data where this information - * is missing. If the length indicator is missing, the first four bytes in - * Suns encoding are equal to 0 (Big Endian marker). - */ - private boolean lengthIndicator = true; - - /** - * Create an instance of this Codec, encoding following the given version. - */ - public cdrEncapsCodec(ORB _orb, Version _version) - { - orb = _orb; - version = _version; - noWide = version.until_inclusive(1, 0); - } - - /** - * Return the array of repository ids for this object. - * - * @return { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }, always. - */ - public String[] _ids() - { - return new String[] { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }; - } - - /** - * Decode the contents of the byte array into Any. - * The byte array may have the optional four byte length indicator - * in the beginning. If these four bytes are zero, it is assumed, - * that no length indicator is present. - */ - public Any decode(byte[] them) - throws FormatMismatch - { - cdrBufInput input = createInput(them); - cdrBufInput encapsulation = createEncapsulation(them, input); - - TypeCode type = encapsulation.read_TypeCode(); - - try - { - checkTypePossibility("", type); - } - catch (InvalidTypeForEncoding ex) - { - throw new FormatMismatch(ex.getMessage()); - } - - return readAny(type, encapsulation); - } - - private cdrBufInput createEncapsulation(byte[] them, cdrBufInput input) - { - cdrBufInput encapsulation; - - if ((them [ 0 ] | them [ 1 ] | them [ 2 ] | them [ 3 ]) == 0) - { - // Skip that appears to be the always present Big Endian marker. - encapsulation = input; - input.read_short(); - } - else - encapsulation = input.read_encapsulation(); - return encapsulation; - } - - /** {@inheritDoc} */ - public byte[] encode(Any that) - throws InvalidTypeForEncoding - { - checkTypePossibility("", that.type()); - - cdrBufOutput output = createOutput(that); - - // cdrBufOutput has internal support for this encoding. - cdrOutput encapsulation = output.createEncapsulation(); - - try - { - TypeCodeHelper.write(encapsulation, that.type()); - that.write_value(encapsulation); - - encapsulation.close(); - output.close(); - } - catch (Exception ex) - { - MARSHAL m = new MARSHAL(); - m.initCause(ex); - throw m; - } - return output.buffer.toByteArray(); - } - - /** - * Decode the value, stored in the byte array, into Any, assuming, - * that the byte array holds the data structure, defined by the - * given typecode. - * - * The byte array may have the optional four byte length indicator - * in the beginning. If these four bytes are zero, it is assumed, - * that no length indicator is present. - */ - public Any decode_value(byte[] them, TypeCode type) - throws FormatMismatch, TypeMismatch - { - try - { - checkTypePossibility("", type); - } - catch (InvalidTypeForEncoding ex) - { - throw new TypeMismatch(ex.getMessage()); - } - - cdrBufInput input = createInput(them); - cdrBufInput encapsulation = createEncapsulation(them, input); - return readAny(type, encapsulation); - } - - /** - * Read an Any from the given stream. - * - * @param type a type of the Any to read. - * @param input the encapsulation stream. - */ - private Any readAny(TypeCode type, cdrBufInput encapsulation) - throws MARSHAL - { - gnuAny a = new gnuAny(); - a.setOrb(orb); - - // cdrBufInput has internal support for this encoding. - a.read_value(encapsulation, type); - return a; - } - - /** {@inheritDoc} */ - public byte[] encode_value(Any that) - throws InvalidTypeForEncoding - { - checkTypePossibility("", that.type()); - - cdrBufOutput output = createOutput(that); - - cdrOutput encapsulation = output.createEncapsulation(); - - try - { - that.write_value(encapsulation); - - encapsulation.close(); - output.close(); - } - catch (Exception ex) - { - MARSHAL m = new MARSHAL(); - m.initCause(ex); - throw m; - } - return output.buffer.toByteArray(); - } - - /** - * Create the CDR output stream for writing the given Any. - * The cdrBufOutput has internal support for encapsulation encodings. - * - * @param that the Any that will be written. - * - * @return the stream. - * - * @throws InvalidTypeForEncoding if that Any cannot be written under the - * given version. - */ - private cdrBufOutput createOutput(Any that) - throws InvalidTypeForEncoding - { - cdrBufOutput output = new cdrBufOutput(); - output.setOrb(orb); - output.setVersion(version); - return output; - } - - /** - * Checks if the given type can be encoded. Currently only checks for wide - * strings and wide chars for GIOP 1.0. - * - * @param t a typecode to chek. - * - * @throws InvalidTypeForEncoding if the typecode is not valid for the given - * version. - */ - private void checkTypePossibility(String name, TypeCode t) - throws InvalidTypeForEncoding - { - if (noWide) - { - try - { - int kind = t.kind().value(); - - if (kind == TCKind._tk_wchar || kind == TCKind._tk_wstring) - throw new InvalidTypeForEncoding(name + " wide char in " + - version - ); - else if (kind == TCKind._tk_alias || kind == TCKind._tk_array || - kind == TCKind._tk_sequence - ) - checkTypePossibility("Array member", t.content_type()); - - else if (kind == TCKind._tk_struct || kind == TCKind._tk_union) - { - for (int i = 0; i < t.member_count(); i++) - { - checkTypePossibility(t.member_name(i), t.member_type(i)); - } - } - } - catch (UserException ex) - { - InternalError ierr = new InternalError(); - ierr.initCause(ex); - throw ierr; - } - } - } - - /** - * Create the CDR input stream for reading the given byte array. - * - * @param them a byte array to read. - * - * @return the stream. - */ - private cdrBufInput createInput(byte[] them) - { - cdrBufInput input = new cdrBufInput(them); - input.setOrb(orb); - input.setVersion(version); - return input; - } - - /** - * Check if the Codec writes the length indicator. - */ - public boolean hasLengthIndicator() - { - return lengthIndicator; - } - - /** - * Sets if the Codec must write the record length in the beginning of the - * array. Encodings both with and without that indicator are understood - * both by Suns and this codec, but the OMG specification seems requiring - * it. The default behavior is to use the length indicator. - * - * @param use_lengthIndicator - */ - public void setUseLengthIndicator(boolean use_lengthIndicator) - { - lengthIndicator = use_lengthIndicator; - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/corbaArrayList.java b/libjava/classpath/gnu/CORBA/corbaArrayList.java deleted file mode 100644 index 1690f05..0000000 --- a/libjava/classpath/gnu/CORBA/corbaArrayList.java +++ /dev/null @@ -1,115 +0,0 @@ -/* corbaArrayList.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import java.io.Serializable; - -import java.util.ArrayList; - -import org.omg.CORBA.Bounds; - -/** - * This class is used to store array lists. Differently from - * the java.util lists, - * it throws {@link org.omg.CORBA.Bounds} rather than - * {@link IndexOutOfBoundsException}. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class corbaArrayList - extends ArrayList - implements Serializable -{ - /** - * Use serialVersionUID for interoperability. - */ - private static final long serialVersionUID = 1; - - /** - * Creates the list with the given initial size. - */ - public corbaArrayList(int initial_size) - { - super(initial_size); - } - - /** - * Creates the list with the default size. - */ - public corbaArrayList() - { - } - - /** - * Remove the item at the given index. - * @param at the index - * @throws org.omg.CORBA.Bounds if the index is out of bounds. - */ - public void drop(int at) - throws Bounds - { - try - { - super.remove(at); - } - catch (IndexOutOfBoundsException ex) - { - throw new Bounds("[" + at + "], valid [0.." + size() + "]"); - } - } - - /** - * Get the item at the given index. - * @param at the index - * @return the item at the index - * @throws org.omg.CORBA.Bounds if the index is out of bounds. - */ - public Object item(int at) - throws Bounds - { - try - { - return super.get(at); - } - catch (IndexOutOfBoundsException ex) - { - throw new Bounds("[" + at + "], valid [0.." + size() + "]"); - } - } -} diff --git a/libjava/classpath/gnu/CORBA/fixedTypeCode.java b/libjava/classpath/gnu/CORBA/fixedTypeCode.java deleted file mode 100644 index eb61041..0000000 --- a/libjava/classpath/gnu/CORBA/fixedTypeCode.java +++ /dev/null @@ -1,145 +0,0 @@ -/* fixedTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import java.math.BigDecimal; - -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; - -/** - * A typecode for CORBA fixed - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class fixedTypeCode - extends primitiveTypeCode -{ - /** - * The number of the used digits. - */ - private short digits; - - /** - * The number of the digits after the decimal point. - */ - private short scale; - - /** - * Creates the instance of the fixed type code. - */ - public fixedTypeCode() - { - super(TCKind.tk_fixed); - } - - /** - * Creates the instance of the fixed type code, - * setting the digits and scale by example. - */ - public fixedTypeCode(BigDecimal example) - { - super(TCKind.tk_fixed); - if (example != null) - { - setScale(example.scale()); - setDigits(countDigits(example)); - } - } - - /** - * Set the number of digits. - */ - public void setDigits(int a_digits) - { - this.digits = (short) a_digits; - } - - /** - * Set the number of digits after the decimal point. - */ - public void setScale(int a_scale) - { - this.scale = (short) a_scale; - } - - /** - * Get the number of digits in thid BigDecimal - * - * @param x a BigDecimal to check. - */ - public static int countDigits(BigDecimal number) - { - return number.unscaledValue().abs().toString().length(); - } - - /** - * Compare with other type code for equality. - */ - public boolean equal(TypeCode other) - { - if (other == this) return true; - try - { - TypeCode that = (TypeCode) other; - return kind() == that.kind() && digits == that.fixed_digits() && - scale == that.fixed_scale(); - } - catch (BadKind ex) - { - return false; - } - } - - /** - * Get the number of digits. - */ - public short fixed_digits() - { - return digits; - } - - /** - * Get the number of digits after the decimal point. - */ - public short fixed_scale() - { - return scale; - } -} diff --git a/libjava/classpath/gnu/CORBA/generalTypeCode.java b/libjava/classpath/gnu/CORBA/generalTypeCode.java deleted file mode 100644 index 3b79148..0000000 --- a/libjava/classpath/gnu/CORBA/generalTypeCode.java +++ /dev/null @@ -1,243 +0,0 @@ -/* generalTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufOutput; - -import java.util.Arrays; -import java.util.BitSet; - -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; - -/** - * A typecode for types, requiring to provide various additional - * properties but still not requiring to store the - * members of the structure. The property can be retrieved - * by the corresponding method if it has been previously assigned. - * Otherwise, a {@link BadKind} is thrown. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class generalTypeCode - extends primitiveTypeCode -{ - /** - * Indicates that the field value has not been previously set. - */ - protected static int UNSET = Integer.MIN_VALUE; - - /** - * The kinds for that the length() must return 0 even if it - * has not been previously set. - */ - private static final BitSet lengthAllowed = new BitSet(); - - static - { - lengthAllowed.set(TCKind._tk_array); - lengthAllowed.set(TCKind._tk_sequence); - lengthAllowed.set(TCKind._tk_string); - lengthAllowed.set(TCKind._tk_wstring); - } - - private String id; - private String name; - private TypeCode concrete_base_type; - private TypeCode content_type; - private int len; - private int type_modifier = UNSET; - - /** - * Create a new instance, setting kind to the given kind. - * @param kind - */ - public generalTypeCode(TCKind kind) - { - super(kind); - if (!lengthAllowed.get(kind.value())) - len = UNSET; - } - - /** - * Set this property. - */ - public void setConcreteBase_type(TypeCode concrete_base_type) - { - this.concrete_base_type = concrete_base_type; - } - - /** - * Set the component content type. - */ - public void setContentType(TypeCode a_content_type) - { - this.content_type = a_content_type; - } - - /** - * Set this property. - */ - public void setId(String id) - { - this.id = id; - } - - /** - * Set the length property. - * @param l - */ - public void setLength(int l) - { - len = l; - } - - /** - * Set this property. - */ - public void setName(String name) - { - this.name = name; - } - - /** - * Set the type modifier. - */ - public void setTypeModifier(int a_type_modifier) - { - this.type_modifier = a_type_modifier; - } - - /** {@inheritDoc} */ - public TypeCode concrete_base_type() - throws BadKind - { - if (concrete_base_type != null) - return concrete_base_type; - throw new BadKind("concrete_base_type"); - } - - /** - * Returns the content type that must be explicitly set - * for this class. - * - * @throws BadKind if the content type has not been set. - */ - public TypeCode content_type() - throws BadKind - { - if (content_type != null) - return content_type; - throw new BadKind("content_type"); - } - - /** - * Returns true if both typecodes, if written into CDR - * stream, would result the same stream content. - */ - public boolean equal(TypeCode other) - { - if (this == other) - return true; - if (kind() != other.kind()) - return false; - - cdrBufOutput a = new cdrBufOutput(16); - cdrBufOutput b = new cdrBufOutput(16); - - a.write_TypeCode(this); - b.write_TypeCode(other); - - return Arrays.equals(a.buffer.toByteArray(), b.buffer.toByteArray()); - } - - /** - * Delegates functionality to {@link #equal}. - */ - public boolean equivalent(TypeCode other) - { - return equal(other); - } - - /** {@inheritDoc} */ - public String id() - throws BadKind - { - if (id != null) - return id; - throw new BadKind("id"); - } - - /** - * Get the length. For sequences, arrays, strings and wstrings - * this method returns 0 rather than throwing a BadKind even - * if {@link setLength(int)} has not been previously called. - * - * @return the length of string, array or sequence. - * - * @throws BadKind if the method cannot be invoked for the - * given kind of typecode. - */ - public int length() - throws BadKind - { - if (len != UNSET) - return len; - throw new BadKind("length"); - } - - /** {@inheritDoc} */ - public String name() - throws BadKind - { - if (name != null) - return name; - throw new BadKind("name"); - } - - /** {@inheritDoc} */ - public short type_modifier() - throws BadKind - { - if (type_modifier != UNSET) - return (short) type_modifier; - throw new BadKind("type_modifier"); - } -} diff --git a/libjava/classpath/gnu/CORBA/gnuAny.java b/libjava/classpath/gnu/CORBA/gnuAny.java index 7e5ef33..729386d 100644 --- a/libjava/classpath/gnu/CORBA/gnuAny.java +++ b/libjava/classpath/gnu/CORBA/gnuAny.java @@ -39,8 +39,10 @@ exception statement from your version. */ package gnu.CORBA; import gnu.CORBA.CDR.Vio; -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; +import gnu.CORBA.typecodes.PrimitiveTypeCode; +import gnu.CORBA.typecodes.StringTypeCode; import org.omg.CORBA.Any; import org.omg.CORBA.AnyHolder; @@ -62,19 +64,14 @@ import org.omg.CORBA.StringHolder; import org.omg.CORBA.TCKind; import org.omg.CORBA.TypeCode; import org.omg.CORBA.TypeCodeHolder; -import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.ValueBaseHolder; -import org.omg.CORBA.portable.BoxedValueHelper; import org.omg.CORBA.portable.Streamable; -import java.io.IOException; import java.io.Serializable; - import java.lang.reflect.Field; - import java.math.BigDecimal; - import java.util.Arrays; +import java.util.zip.Adler32; /** * The implementation of {@link Any}. @@ -93,12 +90,17 @@ import java.util.Arrays; public class gnuAny extends Any { + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + /** * The value, returned by {@link #type()} if the value has been * not intialized. */ protected static final TypeCode nullType = - new primitiveTypeCode(TCKind.tk_null); + new PrimitiveTypeCode(TCKind.tk_null); /** * The Streamable, representing the value, held by this gnuAny. @@ -137,11 +139,11 @@ public class gnuAny */ public gnuAny Clone() { - cdrBufOutput out = new cdrBufOutput(); + BufferedCdrOutput out = new BufferedCdrOutput(); out.setOrb(orb); out.write_any(this); - cdrBufInput in = new cdrBufInput(out.buffer.toByteArray()); + BufferredCdrInput in = new BufferredCdrInput(out.buffer.toByteArray()); in.setOrb(orb); return (gnuAny) in.read_any(); } @@ -152,18 +154,18 @@ public class gnuAny */ public org.omg.CORBA.portable.InputStream create_input_stream() { - if (has instanceof universalHolder) + if (has instanceof GeneralHolder) { - universalHolder u = (universalHolder) has; + GeneralHolder u = (GeneralHolder) has; return u.getInputStream(); } else { - cdrBufOutput out = new cdrBufOutput(); + BufferedCdrOutput out = new BufferedCdrOutput(); out.setOrb(orb); write_value(out); - cdrBufInput in = new cdrBufInput(out.buffer.toByteArray()); + BufferredCdrInput in = new BufferredCdrInput(out.buffer.toByteArray()); in.setOrb(orb); return in; } @@ -174,7 +176,7 @@ public class gnuAny */ public org.omg.CORBA.portable.OutputStream create_output_stream() { - cdrBufOutput stream = new cdrBufOutput(); + BufferedCdrOutput stream = new BufferedCdrOutput(); stream.setOrb(orb); return stream; } @@ -194,11 +196,11 @@ public class gnuAny if (has.equals(((gnuAny) other).has)) return true; - cdrBufOutput a = new cdrBufOutput(); + BufferedCdrOutput a = new BufferedCdrOutput(); a.setOrb(orb); write_value(a); - cdrBufOutput b = new cdrBufOutput(); + BufferedCdrOutput b = new BufferedCdrOutput(); b.setOrb(orb); other.write_value(b); @@ -207,6 +209,28 @@ public class gnuAny return Arrays.equals(ba, bb); } + + /** + * Get the content - dependent hashcode. + */ + public int hashCode() + { + if (has == null) + return type().kind().value(); + else + { + Adler32 adler = new Adler32(); + + BufferedCdrOutput a = new BufferedCdrOutput(); + a.setOrb(orb); + write_value(a); + + adler.update(a.buffer.toByteArray()); + adler.update(type().kind().value()); + + return (int) adler.getValue() & Integer.MAX_VALUE; + } + } /** * Delegates functionality to {@link #equal(Any)}. @@ -232,7 +256,10 @@ public class gnuAny } catch (ClassCastException ex) { - throw new BAD_OPERATION(); + BAD_OPERATION bad = new BAD_OPERATION(); + bad.initCause(ex); + bad.minor = Minor.Any; + throw bad; } } @@ -297,7 +324,10 @@ public class gnuAny } catch (Exception ex) { - return new BAD_OPERATION("Value type expected"); + BAD_OPERATION bad = new BAD_OPERATION("Value type expected"); + bad.minor = Minor.Any; + bad.initCause(ex); + throw bad; } } @@ -664,7 +694,7 @@ public class gnuAny else has = new StringHolder(x); - typecode = new stringTypeCode(TCKind.tk_string); + typecode = new StringTypeCode(TCKind.tk_string); } /** {@inheritDoc} */ @@ -751,40 +781,27 @@ public class gnuAny } else { - has = holderFactory.createHolder(a_type); + has = HolderLocator.createHolder(a_type); if (has == null) { // Use the Universal Holder that reads till the end of stream. // This works with the extract/insert pair of the typical // Helper. - cdrBufOutput buffer = new cdrBufOutput(); + BufferedCdrOutput buffer = new BufferedCdrOutput(); buffer.setOrb(orb); - has = new universalHolder(buffer); + has = new GeneralHolder(buffer); } } type(a_type); - if (!(has instanceof universalHolder) && + if (!(has instanceof GeneralHolder) && (kind == TCKind._tk_value_box)) { // The streamable only contains operations for // reading the value, not the value header. Field vField = has.getClass().getField("value"); - BoxedValueHelper helper; - - try - { - Class helperClass = - Class.forName(ObjectCreator.toHelperName(a_type.id())); - helper = (BoxedValueHelper) helperClass.newInstance(); - } - catch (Exception ex) - { - helper = null; - } - - Object content = Vio.read(input, helper); + Object content = Vio.read(input, a_type.id()); vField.set(has, content); } else @@ -793,6 +810,7 @@ public class gnuAny catch (Exception ex) { MARSHAL m = new MARSHAL(); + m.minor = Minor.Any; m.initCause(ex); throw m; } @@ -805,7 +823,7 @@ public class gnuAny return typecode; else if (xKind >= 0) { - typecode = new primitiveTypeCode(TCKind.from_int(xKind)); + typecode = new PrimitiveTypeCode(TCKind.from_int(xKind)); return typecode; } else @@ -838,38 +856,43 @@ public class gnuAny /** * Check if the current value if the value of the given kind. + * * @param kind a kind to check. * @throws BAD_OPERATION if the value is not set of is different kind. */ protected void check(int kind) - throws BAD_OPERATION + throws BAD_OPERATION { if (has == null) - throw new BAD_OPERATION("value not set"); + { + BAD_OPERATION bad = new BAD_OPERATION("value not set"); + bad.minor = Minor.Any; + throw bad; + } if (xKind >= 0) { if (xKind != kind) - if (!( - xKind == TCKind._tk_alias && - has._type().kind().value() == kind - ) - ) - throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + - " when stored " + typeNamer.nameIt(xKind) - ); + if (!(xKind == TCKind._tk_alias && has._type().kind().value() == kind)) + { + BAD_OPERATION bad = new BAD_OPERATION("Extracting " + + TypeKindNamer.nameIt(kind) + " when stored " + + TypeKindNamer.nameIt(xKind)); + bad.minor = Minor.Any; + throw bad; + } } else { if (type().kind().value() != kind) - if (!( - type().kind().value() == TCKind._tk_alias && - has._type().kind().value() == kind - ) - ) - throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + - " stored " + typeNamer.nameIt(type()) - ); + if (!(type().kind().value() == TCKind._tk_alias && has._type().kind().value() == kind)) + { + BAD_OPERATION bad = new BAD_OPERATION("Extracting " + + TypeKindNamer.nameIt(kind) + " stored " + + TypeKindNamer.nameIt(type())); + bad.minor = Minor.Any; + throw bad; + } } } diff --git a/libjava/classpath/gnu/CORBA/gnuCodecFactory.java b/libjava/classpath/gnu/CORBA/gnuCodecFactory.java index 067de49..8cf9ccf 100644 --- a/libjava/classpath/gnu/CORBA/gnuCodecFactory.java +++ b/libjava/classpath/gnu/CORBA/gnuCodecFactory.java @@ -83,7 +83,7 @@ public class gnuCodecFactory extends LocalObject implements CodecFactory "supported by this factory." ); - return new cdrEncapsCodec(orb, + return new CdrEncapsCodecImpl(orb, new Version(for_encoding.major_version, for_encoding.minor_version) ); } diff --git a/libjava/classpath/gnu/CORBA/gnuContextList.java b/libjava/classpath/gnu/CORBA/gnuContextList.java index 2a26437..68584c3 100644 --- a/libjava/classpath/gnu/CORBA/gnuContextList.java +++ b/libjava/classpath/gnu/CORBA/gnuContextList.java @@ -53,7 +53,7 @@ public class gnuContextList /** * The collection, holding the actual list of strings. */ - corbaArrayList strings = new corbaArrayList(); + CorbaList strings = new CorbaList(); /** {@inheritDoc} */ public void add(String name) diff --git a/libjava/classpath/gnu/CORBA/gnuExceptionList.java b/libjava/classpath/gnu/CORBA/gnuExceptionList.java index b684ec9..5f0c0c9 100644 --- a/libjava/classpath/gnu/CORBA/gnuExceptionList.java +++ b/libjava/classpath/gnu/CORBA/gnuExceptionList.java @@ -54,7 +54,7 @@ public class gnuExceptionList /** * A list to store the objects. */ - protected corbaArrayList list = new corbaArrayList(); + protected CorbaList list = new CorbaList(); /** {@inheritDoc} */ public void add(TypeCode an_exception) diff --git a/libjava/classpath/gnu/CORBA/gnuNVList.java b/libjava/classpath/gnu/CORBA/gnuNVList.java index e436c33..3645a3e 100644 --- a/libjava/classpath/gnu/CORBA/gnuNVList.java +++ b/libjava/classpath/gnu/CORBA/gnuNVList.java @@ -53,14 +53,14 @@ public class gnuNVList /** * The list of the named values. */ - protected corbaArrayList list; + protected CorbaList list; /** * Creates the list with the default initial size. */ public gnuNVList() { - list = new corbaArrayList(); + list = new CorbaList(); } /** @@ -68,7 +68,7 @@ public class gnuNVList */ public gnuNVList(int initial_size) { - list = new corbaArrayList(initial_size); + list = new CorbaList(initial_size); } /** {@inheritDoc} */ diff --git a/libjava/classpath/gnu/CORBA/gnuRequest.java b/libjava/classpath/gnu/CORBA/gnuRequest.java index 7d756ed..5adf741 100644 --- a/libjava/classpath/gnu/CORBA/gnuRequest.java +++ b/libjava/classpath/gnu/CORBA/gnuRequest.java @@ -38,12 +38,12 @@ exception statement from your version. */ package gnu.CORBA; -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; import gnu.CORBA.GIOP.MessageHeader; import gnu.CORBA.GIOP.ReplyHeader; import gnu.CORBA.GIOP.RequestHeader; -import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.GIOP.CodeSetServiceContext; import gnu.CORBA.Interceptor.gnuClientRequestInfo; import gnu.CORBA.Poa.ORB_1_4; @@ -54,6 +54,7 @@ import org.omg.CORBA.Any; import org.omg.CORBA.BAD_INV_ORDER; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.Bounds; +import org.omg.CORBA.COMM_FAILURE; import org.omg.CORBA.CompletionStatus; import org.omg.CORBA.Context; import org.omg.CORBA.ContextList; @@ -134,8 +135,8 @@ public class gnuRequest extends Request implements Cloneable /** * The empty byte array. */ - private static final binaryReply EMPTY = - new binaryReply(null, new MessageHeader(), new byte[ 0 ]); + private static final RawReply EMPTY = + new RawReply(null, new MessageHeader(), new byte[ 0 ]); /** * The context holder for methods ctx(Context) and ctx(). @@ -222,7 +223,7 @@ public class gnuRequest extends Request implements Cloneable * The request arguments in the case when they are directly written into the * parameter buffer. */ - protected streamRequest m_parameter_buffer; + protected StreamBasedRequest m_parameter_buffer; /** * The array of slots. @@ -294,8 +295,8 @@ public class gnuRequest extends Request implements Cloneable orb = an_orb; // Take the interceptor from the ORB. - if (orb instanceof Restricted_ORB) - m_interceptor = ((Restricted_ORB) orb).iClient; + if (orb instanceof OrbRestricted) + m_interceptor = ((OrbRestricted) orb).iClient; if (m_interceptor != null && orb instanceof ORB_1_4) { @@ -332,12 +333,12 @@ public class gnuRequest extends Request implements Cloneable * Get the parameter stream, where the invocation arguments should be written * if they are written into the stream directly. */ - public streamRequest getParameterStream() + public StreamBasedRequest getParameterStream() { - m_parameter_buffer = new streamRequest(); + m_parameter_buffer = new StreamBasedRequest(); m_parameter_buffer.request = this; m_parameter_buffer.setVersion(ior.Internet.version); - m_parameter_buffer.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets)); + m_parameter_buffer.setCodeSet(CodeSetServiceContext.negotiate(ior.Internet.CodeSets)); m_parameter_buffer.setOrb(orb); m_parameter_buffer.setBigEndian(Big_endian); @@ -345,7 +346,7 @@ public class gnuRequest extends Request implements Cloneable // correctly. if (ior.Internet.version.until_inclusive(1, 1)) { - cdrBufOutput measure = new cdrBufOutput(); + BufferedCdrOutput measure = new BufferedCdrOutput(); measure.setOffset(12); if (m_rqh == null) m_rqh = new gnu.CORBA.GIOP.v1_0.RequestHeader(); @@ -513,8 +514,8 @@ public class gnuRequest extends Request implements Cloneable try { ObjectImpl impl = (ObjectImpl) e.forward; - Simple_delegate delegate = - (Simple_delegate) impl._get_delegate(); + SimpleDelegate delegate = + (SimpleDelegate) impl._get_delegate(); ior = delegate.getIor(); } catch (Exception ex) @@ -714,14 +715,15 @@ public class gnuRequest extends Request implements Cloneable /** * Do the actual invocation. This implementation requires to set the IOR * property ({@link #setIOR(IOR)} before calling this method. - * + * * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been previously set * or if the direct argument addition is mixed with the direct argument * writing into the output stream. - * + * * @return the server response in binary form. */ - public synchronized binaryReply submit() throws ForwardRequest + public synchronized RawReply submit() + throws ForwardRequest { gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader(); @@ -742,26 +744,25 @@ public class gnuRequest extends Request implements Cloneable m_interceptor.send_request(m_info); // Prepare the submission. - cdrBufOutput request_part = new cdrBufOutput(); + BufferedCdrOutput request_part = new BufferedCdrOutput(); request_part.setOffset(header.getHeaderSize()); request_part.setVersion(header.version); - request_part.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets)); + request_part.setCodeSet(CodeSetServiceContext.negotiate(ior.Internet.CodeSets)); request_part.setOrb(orb); request_part.setBigEndian(header.isBigEndian()); // This also sets the stream encoding to the encoding, specified // in the header. rh.write(request_part); - + if (m_args != null && m_args.count() > 0) { write_parameters(header, request_part); if (m_parameter_buffer != null) - throw new BAD_INV_ORDER("Please either add parameters or " + - "write them into stream, but not both " + "at once." - ); + throw new BAD_INV_ORDER("Please either add parameters or " + + "write them into stream, but not both " + "at once."); } if (m_parameter_buffer != null) @@ -789,12 +790,15 @@ public class gnuRequest extends Request implements Cloneable { // The BindException may be thrown under very heavy parallel // load. For some time, just wait, exceptiong the socket to free. - Open: - for (int i = 0; i < PAUSE_STEPS; i++) + Open: for (int i = 0; i < PAUSE_STEPS; i++) { try { - socket = new Socket(ior.Internet.host, ior.Internet.port); + if (orb instanceof OrbFunctional) + socket = ((OrbFunctional) orb).socketFactory.createClientSocket( + ior.Internet.host, ior.Internet.port); + else + socket = new Socket(ior.Internet.host, ior.Internet.port); break Open; } catch (BindException ex) @@ -816,9 +820,8 @@ public class gnuRequest extends Request implements Cloneable } if (socket == null) - throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port + - " in use" - ); + throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port + + " in use"); socket.setKeepAlive(true); OutputStream socketOutput = socket.getOutputStream(); @@ -836,25 +839,26 @@ public class gnuRequest extends Request implements Cloneable InputStream socketInput = socket.getInputStream(); response_header.read(socketInput); - byte[] r = new byte[ response_header.message_size ]; - int n = 0; - reading: - while (n < r.length) + byte[] r; + if (orb instanceof OrbFunctional) { - n += socketInput.read(r, n, r.length - n); + OrbFunctional fo = (OrbFunctional) orb; + r = response_header.readMessage(socketInput, socket, + fo.TOUT_WHILE_READING, fo.TOUT_AFTER_RECEIVING); } - return new binaryReply(orb, response_header, r); + else + r = response_header.readMessage(socketInput, null, 0, 0); + + return new RawReply(orb, response_header, r); } else return EMPTY; } catch (IOException io_ex) { - MARSHAL m = - new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" + - ior.Internet.port, 10000 + ior.Internet.port, - CompletionStatus.COMPLETED_NO - ); + COMM_FAILURE m = new COMM_FAILURE("Unable to open a socket at " + + ior.Internet.host + ":" + ior.Internet.port, 0xC9, + CompletionStatus.COMPLETED_NO); m.initCause(io_ex); throw m; } @@ -864,7 +868,7 @@ public class gnuRequest extends Request implements Cloneable { if (socket != null && !socket.isClosed()) { - socket.setSoTimeout(Functional_ORB.TANDEM_REQUESTS); + socket.setSoTimeout(OrbFunctional.TANDEM_REQUESTS); SocketRepository.put_socket(key, socket); } } @@ -929,14 +933,15 @@ public class gnuRequest extends Request implements Cloneable * Do actual invocation. This method recursively calls itself if the * redirection is detected. */ - private void p_invoke() throws SystemException, ForwardRequest + private void p_invoke() + throws SystemException, ForwardRequest { - binaryReply response = submit(); + RawReply response = submit(); if (m_rph == null) m_rph = response.header.create_reply_header(); - cdrBufInput input = response.getStream(); + BufferredCdrInput input = response.getStream(); input.setOrb(orb); m_rph.read(input); @@ -946,7 +951,7 @@ public class gnuRequest extends Request implements Cloneable switch (m_rph.reply_status) { - case ReplyHeader.NO_EXCEPTION : + case ReplyHeader.NO_EXCEPTION: NamedValue arg; @@ -992,7 +997,7 @@ public class gnuRequest extends Request implements Cloneable break; - case ReplyHeader.SYSTEM_EXCEPTION : + case ReplyHeader.SYSTEM_EXCEPTION: if (align) { input.align(8); @@ -1000,7 +1005,8 @@ public class gnuRequest extends Request implements Cloneable } readExceptionId(input); - m_sys_ex = ObjectCreator.readSystemException(input); + m_sys_ex = ObjectCreator.readSystemException(input, + m_rph.service_context); m_environment.exception(m_sys_ex); if (m_interceptor != null) @@ -1008,7 +1014,7 @@ public class gnuRequest extends Request implements Cloneable throw m_sys_ex; - case ReplyHeader.USER_EXCEPTION : + case ReplyHeader.USER_EXCEPTION: if (align) { input.align(8); @@ -1020,7 +1026,7 @@ public class gnuRequest extends Request implements Cloneable gnuAny exc = new gnuAny(); exc.setOrb(orb); - exc.insert_Streamable(new streamReadyHolder(input)); + exc.insert_Streamable(new StreamHolder(input)); UnknownUserException unuex = new UnknownUserException(exc); m_environment.exception(unuex); @@ -1030,8 +1036,8 @@ public class gnuRequest extends Request implements Cloneable break; - case ReplyHeader.LOCATION_FORWARD_PERM : - case ReplyHeader.LOCATION_FORWARD : + case ReplyHeader.LOCATION_FORWARD_PERM: + case ReplyHeader.LOCATION_FORWARD: if (response.header.version.since_inclusive(1, 2)) input.align(8); @@ -1043,8 +1049,7 @@ public class gnuRequest extends Request implements Cloneable catch (IOException ex) { new MARSHAL("Cant read forwarding info", 5103, - CompletionStatus.COMPLETED_NO - ); + CompletionStatus.COMPLETED_NO); } setIor(forwarded); @@ -1058,17 +1063,16 @@ public class gnuRequest extends Request implements Cloneable p_invoke(); return; - default : + default: throw new MARSHAL("Unknow reply status", 8100 + m_rph.reply_status, - CompletionStatus.COMPLETED_NO - ); + CompletionStatus.COMPLETED_NO); } } /** * Read exception id without changing the stream pointer position. */ - void readExceptionId(cdrBufInput input) + void readExceptionId(BufferredCdrInput input) { input.mark(2048); m_exception_id = input.read_string(); @@ -1084,7 +1088,7 @@ public class gnuRequest extends Request implements Cloneable * @throws MARSHAL if the attempt to write the parameters has failde. */ protected void write_parameter_buffer(MessageHeader header, - cdrBufOutput request_part + BufferedCdrOutput request_part ) throws MARSHAL { try @@ -1097,7 +1101,9 @@ public class gnuRequest extends Request implements Cloneable } catch (IOException ex) { - throw new MARSHAL("Unable to write method arguments to CDR output."); + MARSHAL m = new MARSHAL("Unable to write method arguments to CDR output."); + m.minor = Minor.CDR; + throw m; } } @@ -1110,7 +1116,7 @@ public class gnuRequest extends Request implements Cloneable * @throws MARSHAL if the attempt to write the parameters has failde. */ protected void write_parameters(MessageHeader header, - cdrBufOutput request_part + BufferedCdrOutput request_part ) throws MARSHAL { // Align after 1.2, but only once. @@ -1161,7 +1167,7 @@ public class gnuRequest extends Request implements Cloneable */ public TaggedProfile effective_profile() { - cdrBufOutput buf = new cdrBufOutput(512); + BufferedCdrOutput buf = new BufferedCdrOutput(512); buf.setOrb(orb); ior.Internet.write(buf); @@ -1176,7 +1182,7 @@ public class gnuRequest extends Request implements Cloneable */ public org.omg.CORBA.Object effective_target() { - return new IOR_contructed_object(orb, ior); + return new IorObject(orb, ior); } /** @@ -1188,7 +1194,7 @@ public class gnuRequest extends Request implements Cloneable if (id == TAG_CODE_SETS.value) { // Codesets are encoded separately. - cdrBufOutput buf = new cdrBufOutput(512); + BufferedCdrOutput buf = new BufferedCdrOutput(512); buf.setOrb(orb); ior.Internet.CodeSets.write(buf); @@ -1289,7 +1295,7 @@ public class gnuRequest extends Request implements Cloneable return m_forwarding_target; if (m_forward_ior != null) - return new IOR_contructed_object(orb, m_forward_ior); + return new IorObject(orb, m_forward_ior); else return null; } diff --git a/libjava/classpath/gnu/CORBA/gnuValueHolder.java b/libjava/classpath/gnu/CORBA/gnuValueHolder.java index 0b38264..8263113 100644 --- a/libjava/classpath/gnu/CORBA/gnuValueHolder.java +++ b/libjava/classpath/gnu/CORBA/gnuValueHolder.java @@ -123,7 +123,7 @@ public class gnuValueHolder try { Class helperClass = - Class.forName(ObjectCreator.toHelperName(type.id())); + ObjectCreator.forName(ObjectCreator.toHelperName(type.id())); helper = (BoxedValueHelper) helperClass.newInstance(); } diff --git a/libjava/classpath/gnu/CORBA/holderFactory.java b/libjava/classpath/gnu/CORBA/holderFactory.java deleted file mode 100644 index 159d223..0000000 --- a/libjava/classpath/gnu/CORBA/holderFactory.java +++ /dev/null @@ -1,184 +0,0 @@ -/* holderFactory.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.AnyHolder; -import org.omg.CORBA.AnySeqHolder; -import org.omg.CORBA.BooleanHolder; -import org.omg.CORBA.BooleanSeqHolder; -import org.omg.CORBA.CharHolder; -import org.omg.CORBA.CharSeqHolder; -import org.omg.CORBA.DoubleHolder; -import org.omg.CORBA.DoubleSeqHolder; -import org.omg.CORBA.FixedHolder; -import org.omg.CORBA.FloatHolder; -import org.omg.CORBA.FloatSeqHolder; -import org.omg.CORBA.IntHolder; -import org.omg.CORBA.LongHolder; -import org.omg.CORBA.LongLongSeqHolder; -import org.omg.CORBA.LongSeqHolder; -import org.omg.CORBA.OctetSeqHolder; -import org.omg.CORBA.PrincipalHolder; -import org.omg.CORBA.ShortHolder; -import org.omg.CORBA.ShortSeqHolder; -import org.omg.CORBA.StringHolder; -import org.omg.CORBA.StringSeqHolder; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodeHolder; -import org.omg.CORBA.ULongLongSeqHolder; -import org.omg.CORBA.ULongSeqHolder; -import org.omg.CORBA.UShortSeqHolder; -import org.omg.CORBA.WCharSeqHolder; -import org.omg.CORBA.WStringSeqHolder; -import org.omg.CORBA.portable.Streamable; -import org.omg.CORBA.ObjectHolder; - -/** - * Creates the suitable holder for storing the value of the given final_type. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class holderFactory -{ - /** - * The array, sufficiently large to use any {@link TCKind}._tk* constant as - * an index. - */ - private static final Class[] holders; - - private static final Class[] seqHolders; - - static - { - holders = new Class[32]; - holders[TCKind._tk_Principal] = PrincipalHolder.class; - holders[TCKind._tk_TypeCode] = TypeCodeHolder.class; - holders[TCKind._tk_any] = AnyHolder.class; - holders[TCKind._tk_boolean] = BooleanHolder.class; - holders[TCKind._tk_char] = CharHolder.class; - holders[TCKind._tk_double] = DoubleHolder.class; - holders[TCKind._tk_float] = FloatHolder.class; - holders[TCKind._tk_fixed] = FixedHolder.class; - holders[TCKind._tk_long] = IntHolder.class; - holders[TCKind._tk_longdouble] = DoubleHolder.class; - holders[TCKind._tk_longlong] = LongHolder.class; - holders[TCKind._tk_octet] = OctetHolder.class; - holders[TCKind._tk_short] = ShortHolder.class; - holders[TCKind._tk_string] = StringHolder.class; - holders[TCKind._tk_ulong] = IntHolder.class; - holders[TCKind._tk_ulonglong] = LongHolder.class; - holders[TCKind._tk_ushort] = ShortHolder.class; - holders[TCKind._tk_wchar] = WCharHolder.class; - holders[TCKind._tk_wstring] = WStringHolder.class; - holders[TCKind._tk_objref] = ObjectHolder.class; - - seqHolders = new Class[32]; - - seqHolders[TCKind._tk_ulonglong] = ULongLongSeqHolder.class; - seqHolders[TCKind._tk_short] = ShortSeqHolder.class; - seqHolders[TCKind._tk_octet] = OctetSeqHolder.class; - seqHolders[TCKind._tk_any] = AnySeqHolder.class; - seqHolders[TCKind._tk_long] = LongSeqHolder.class; - seqHolders[TCKind._tk_longlong] = LongLongSeqHolder.class; - seqHolders[TCKind._tk_float] = FloatSeqHolder.class; - seqHolders[TCKind._tk_double] = DoubleSeqHolder.class; - seqHolders[TCKind._tk_char] = CharSeqHolder.class; - seqHolders[TCKind._tk_boolean] = BooleanSeqHolder.class; - seqHolders[TCKind._tk_wchar] = WCharSeqHolder.class; - seqHolders[TCKind._tk_ushort] = UShortSeqHolder.class; - seqHolders[TCKind._tk_ulong] = ULongSeqHolder.class; - seqHolders[TCKind._tk_string] = StringSeqHolder.class; - seqHolders[TCKind._tk_wstring] = WStringSeqHolder.class; - } - - /** - * Create a holder for storing the value of the given built-in final_type. This - * function returns the defined holders for the built-in primitive types and - * they sequences. - * - * @param t the typecode - * - * @return an instance of the corresponding built-in holder of null if no such - * is defined for this final_type. The holder is created with a parameterless - * constructor. - */ - public static Streamable createHolder(TypeCode t) - { - try - { - int kind = t.kind().value(); - int componentKind; - - Streamable holder = null; - - if (kind < holders.length && holders[kind] != null) - holder = (Streamable) holders[kind].newInstance(); - - if (holder != null) - return holder; - - switch (kind) - { - case TCKind._tk_sequence: - componentKind = t.content_type().kind().value(); - if (componentKind < seqHolders.length) - return (Streamable) seqHolders[componentKind].newInstance(); - break; - - default: - break; - } - } - catch (Exception ex) - { - throw new Unexpected(ex); - } - - try - { - Object ox = ObjectCreator.createObject(t.id(), "Holder"); - return (Streamable) ox; - } - catch (Exception ex) - { - return null; - } - } -} diff --git a/libjava/classpath/gnu/CORBA/interfaces/SocketFactory.java b/libjava/classpath/gnu/CORBA/interfaces/SocketFactory.java new file mode 100644 index 0000000..7797dcb --- /dev/null +++ b/libjava/classpath/gnu/CORBA/interfaces/SocketFactory.java @@ -0,0 +1,95 @@ +/* SocketFactory.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.interfaces; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * This class produces sockets for serving and submitting CORBA requests. The + * socket factory can be set using {@link gnuOrb.setSocketFactory()} for + * producting all sockets for that ORB. This is needed for using secure sockets, + * for implementing the desired timeout policies, for HTTP tunnels and in some + * other similar cases. While such functionality is provided by near all + * existing CORBA implementations, no standard mechanism is defined. + * + * The socket factory may need to put additional information to the IORs of the + * objects, released by the ORB. Because of this reason, this interface extends + * IORInterceptorOperations. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface SocketFactory +{ + /** + * The name of the ORB property that forces the ORB to use the socket + * factory class, the name of that (String) is the value of this property. + */ + final String PROPERTY = "gnu.CORBA.SocketFactory"; + + /** + * Create a server socket that should serve remote invocations on the given + * port. The ORB may use this socket to serve either one or more objects. + * + * @param port the port, on that the socket should be listening for requests. + * The port policy can be controlled by {@link gnuPortManager}. + * + * @throws IOException if the socket cannot be created on the given port due + * any reasons. The ORB may try to open the socket on another port, calling + * this method with the different parameter. + */ + ServerSocket createServerSocket(int port) + throws IOException; + + /** + * Create a client socket that should send a request to the remote side. When + * returned, the socket should be opened and ready to communicate. + * + * @param port the port, on that the socket should be openend. The port is + * usually part of the internet profile. + * + * @throws IOException if the socket cannot be created on the given port due + * any reasons. The ORB may try to open the socket on another port, calling + * this method with the different parameter. + */ + Socket createClientSocket(String host, int port) + throws IOException; + +} diff --git a/libjava/classpath/gnu/CORBA/interfaces/package.html b/libjava/classpath/gnu/CORBA/interfaces/package.html new file mode 100644 index 0000000..101475b --- /dev/null +++ b/libjava/classpath/gnu/CORBA/interfaces/package.html @@ -0,0 +1,49 @@ + + + + +GNU Classpath - gnu.CORBA.interfaces + + +

This package contains Classpath specific interfaces that +the user program may be forced to use in cases when no +other, better solution of the problem is available. The +existing classes and methods in this package should not +be removed without the real need

+ + diff --git a/libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java b/libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java deleted file mode 100644 index fc020be..0000000 --- a/libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java +++ /dev/null @@ -1,265 +0,0 @@ -/* primitiveArrayTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; - -/** - * A TypeCode for arrays. - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class primitiveArrayTypeCode - extends primitiveTypeCode -{ - /** - * The array components. - */ - TypeCode of; - - /** - * The length of the array, must be updated when setting - * a new value. - */ - private int length; - - /** - * Create a primitive array type code, defining the sequence - * {@link TCKind.tk_sequence)} with - * the given member type. - * - * @param array_of the sequence member type. - */ - public primitiveArrayTypeCode(TCKind array_of) - { - super(TCKind.tk_sequence); - of = new primitiveTypeCode(array_of); - } - - /** - * Create a primitive array type code, defining the array, sequence - * or other type with the given member type. - * - * @param this_type the type of this type (normally either - * sequence of array). - * @param array_of the sequence member type. - */ - public primitiveArrayTypeCode(TCKind this_type, TypeCode array_of) - { - super(this_type); - of = array_of; - } - - /** - * Return the array component type. - * @return the array component type - * @throws org.omg.CORBA.TypeCodePackage.BadKind - */ - public TypeCode content_type() - throws org.omg.CORBA.TypeCodePackage.BadKind - { - return of; - } - - /** - * Return true if the other TypeCode defines the array, having elements - * of the same type. The sizes of arrays are not taken into - * consideration. - * - * @param other the other TypeCode - * @return true if other is an array with the same - * component type. - */ - public boolean equal(TypeCode other) - { - try - { - return kind() == other.kind() && - content_type() == other.content_type(); - } - catch (BadKind ex) - { - // Should not be thrown. - return false; - } - } - - /** - * Returns the agreed Id in the form of - * IDL:omg.org/CORBA/ {type name} Seq:1.0. - * - * @return the Id of this TypeCode. - * - * @throws org.omg.CORBA.TypeCodePackage.BadKind if the content type - * is not one of the constants, defined in {@link TCKind}. - * This package class should not be used as TypeCode for the arrays, - * holding the user defined components. - */ - public String id() - throws org.omg.CORBA.TypeCodePackage.BadKind - { - switch (content_type().kind().value()) - { - case TCKind._tk_null : - return "IDL:omg.org/CORBA/NullSeq:1.0"; - - case TCKind._tk_void : - return "IDL:omg.org/CORBA/VoidSeq:1.0"; - - case TCKind._tk_short : - return "IDL:omg.org/CORBA/ShortSeq:1.0"; - - case TCKind._tk_long : - return "IDL:omg.org/CORBA/LongSeq:1.0"; - - case TCKind._tk_ushort : - return "IDL:omg.org/CORBA/UShortSeq:1.0"; - - case TCKind._tk_ulong : - return "IDL:omg.org/CORBA/ULongSeq:1.0"; - - case TCKind._tk_float : - return "IDL:omg.org/CORBA/FloatSeq:1.0"; - - case TCKind._tk_double : - return "IDL:omg.org/CORBA/DoubleSeq:1.0"; - - case TCKind._tk_boolean : - return "IDL:omg.org/CORBA/BooleanSeq:1.0"; - - case TCKind._tk_char : - return "IDL:omg.org/CORBA/CharSeq:1.0"; - - case TCKind._tk_octet : - return "IDL:omg.org/CORBA/OctetSeq:1.0"; - - case TCKind._tk_any : - return "IDL:omg.org/CORBA/AnySeq:1.0"; - - case TCKind._tk_TypeCode : - return "IDL:omg.org/CORBA/TypeCodeSeq:1.0"; - - case TCKind._tk_Principal : - return "IDL:omg.org/CORBA/PrincipalSeq:1.0"; - - case TCKind._tk_objref : - return "IDL:omg.org/CORBA/ObjrefSeq:1.0"; - - case TCKind._tk_struct : - return "IDL:omg.org/CORBA/StructSeq:1.0"; - - case TCKind._tk_union : - return "IDL:omg.org/CORBA/UnionSeq:1.0"; - - case TCKind._tk_enum : - return "IDL:omg.org/CORBA/EnumSeq:1.0"; - - case TCKind._tk_string : - return "IDL:omg.org/CORBA/StringSeq:1.0"; - - case TCKind._tk_sequence : - return "IDL:omg.org/CORBA/SequenceSeq:1.0"; - - case TCKind._tk_array : - return "IDL:omg.org/CORBA/ArraySeq:1.0"; - - case TCKind._tk_alias : - return "IDL:omg.org/CORBA/AliasSeq:1.0"; - - case TCKind._tk_except : - return "IDL:omg.org/CORBA/ExceptSeq:1.0"; - - case TCKind._tk_longlong : - return "IDL:omg.org/CORBA/LongLongSeq:1.0"; - - case TCKind._tk_ulonglong : - return "IDL:omg.org/CORBA/ULongLongSeq:1.0"; - - case TCKind._tk_longdouble : - return "IDL:omg.org/CORBA/LongDoubleSeq:1.0"; - - case TCKind._tk_wchar : - return "IDL:omg.org/CORBA/WCharSeq:1.0"; - - case TCKind._tk_wstring : - return "IDL:omg.org/CORBA/WStringSeq:1.0"; - - case TCKind._tk_fixed : - return "IDL:omg.org/CORBA/FixedSeq:1.0"; - - case TCKind._tk_value : - return "IDL:omg.org/CORBA/ValueSeq:1.0"; - - case TCKind._tk_value_box : - return "IDL:omg.org/CORBA/Value_boxSeq:1.0"; - - case TCKind._tk_native : - return "IDL:omg.org/CORBA/NativeSeq:1.0"; - - case TCKind._tk_abstract_interface : - return "IDL:omg.org/CORBA/Abstract_interfaceSeq:1.0"; - - default : - throw new BadKind(); - } - } - - /** - * Return the array length. - * @return the length of the array. - * @throws org.omg.CORBA.TypeCodePackage.BadKind - */ - public int length() - throws org.omg.CORBA.TypeCodePackage.BadKind - { - return length; - } - - /** - * Sets the array length to the supplied value. - * - * @param l the new length. - */ - public void setLength(int l) - { - this.length = l; - } - -} diff --git a/libjava/classpath/gnu/CORBA/primitiveTypeCode.java b/libjava/classpath/gnu/CORBA/primitiveTypeCode.java deleted file mode 100644 index 4bf97d0..0000000 --- a/libjava/classpath/gnu/CORBA/primitiveTypeCode.java +++ /dev/null @@ -1,196 +0,0 @@ -/* primitiveTypeCode.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - - 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.CORBA; - -import java.io.Serializable; - -import org.omg.CORBA.Any; -import org.omg.CORBA.IDLEntity; -import org.omg.CORBA.NO_IMPLEMENT; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; -import org.omg.CORBA.TypeCodePackage.Bounds; - -/** - * An information about a primitive CORBA data type - * (boolean, char, wchar, octet and also signed or unsigned short, long, - * long long, float and double). - * This class only implements the methods {@link #kind() } - * and {@link equal() } that are valid for - * all TypeCode kinds. Other methods are implemented in derived - * subclasses. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class primitiveTypeCode - extends TypeCode - implements IDLEntity, Serializable -{ - /** - * The kind of this TypeCode. - */ - protected final TCKind kind; - - public primitiveTypeCode(TCKind a_kind) - { - kind = a_kind; - } - - public TypeCode concrete_base_type() - throws BadKind - { - throw new BadKind(); - } - - public TypeCode content_type() - throws BadKind - { - throw new BadKind(); - } - - public int default_index() - throws BadKind - { - throw new BadKind(); - } - - public TypeCode discriminator_type() - throws BadKind - { - throw new BadKind(); - } - - /** - * Test two types for equality. The default implementation - * returs true of the types of the same kind. - * @param other the other type to compere with - * @return true if the types are interchangeable. - */ - public boolean equal(TypeCode other) - { - return kind() == other.kind(); - } - - public boolean equivalent(TypeCode parm1) - { - throw new NO_IMPLEMENT(); - } - - public short fixed_digits() - throws BadKind - { - throw new BadKind("fixed_digits"); - } - - public short fixed_scale() - throws BadKind - { - throw new BadKind("fixed_scale"); - } - - public TypeCode get_compact_typecode() - { - throw new NO_IMPLEMENT(); - } - - public String id() - throws BadKind - { - throw new BadKind("id"); - } - - /** - * Return the kind of this type code object. - * @return one of the TCKind.t_.. fields. - */ - public TCKind kind() - { - return kind; - } - - public int length() - throws BadKind - { - throw new BadKind("length"); - } - - public int member_count() - throws BadKind - { - throw new BadKind("member_count"); - } - - public Any member_label(int index) - throws BadKind, Bounds - { - throw new BadKind("member_label"); - } - - public String member_name(int index) - throws BadKind, Bounds - { - throw new BadKind("member_name"); - } - - public TypeCode member_type(int index) - throws BadKind, Bounds - { - throw new BadKind("member_type"); - } - - public short member_visibility(int index) - throws BadKind, Bounds - { - throw new BadKind("member_visibility"); - } - - public String name() - throws BadKind - { - throw new BadKind("name"); - } - - public short type_modifier() - throws BadKind - { - throw new BadKind("type_modifier"); - } -} diff --git a/libjava/classpath/gnu/CORBA/recordTypeCode.java b/libjava/classpath/gnu/CORBA/recordTypeCode.java deleted file mode 100644 index 8f2ecde..0000000 --- a/libjava/classpath/gnu/CORBA/recordTypeCode.java +++ /dev/null @@ -1,245 +0,0 @@ -/* recordTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.Any; -import org.omg.CORBA.StructMember; -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; -import org.omg.CORBA.TypeCodePackage.Bounds; -import org.omg.CORBA.UnionMember; -import org.omg.CORBA.ValueMember; - -/** - * The type code that also has the member property getters - * supported. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class recordTypeCode - extends generalTypeCode -{ - /** - * The individual field of the record. - */ - public static class Field - { - /** - * The record label. - */ - public Any label; - - /** - * The record name. - */ - public String name; - - /** - * The record type. - */ - public TypeCode type; - - /** - * The record visibility. - */ - public int visibility = UNSET; - } - - /** - * The members of this data structure. - */ - protected corbaArrayList members = new corbaArrayList(); - private TypeCode discriminator_type; - private int default_index = UNSET; - - /** - * Creates the type code of the given kind. - */ - public recordTypeCode(TCKind kind) - { - super(kind); - } - - /** - * Set the default index. - */ - public void setDefaultIndex(int a_default_index) - { - this.default_index = a_default_index; - } - - /** - * Set the discriminator type. - */ - public void setDiscriminator_type(TypeCode a_discriminator_type) - { - this.discriminator_type = a_discriminator_type; - } - - public Field getField(int p) - { - return (Field) members.get(p); - } - - public void add(Field field) - { - members.add(field); - } - - /** - * Adds a new field, taking values from the passed - * {@link StructMember}. - */ - public void add(StructMember m) - { - Field f = field(); - f.name = m.name; - f.type = m.type; - } - - /** - * Adds a new field, taking values from the passed - * {@link ValueMember}. - */ - public void add(ValueMember m) - { - Field f = field(); - f.name = m.name; - f.type = m.type; - f.visibility = m.access; - - } - - /** - * Adds a new field, taking values from the passed - * {@link UnionMember}. - */ - public void add(UnionMember m) - { - Field f = field(); - f.name = m.name; - f.type = m.type; - f.label = m.label; - } - - public int default_index() - throws BadKind - { - if (default_index != UNSET) - return default_index; - throw new BadKind(); - } - - public TypeCode discriminator_type() - throws BadKind - { - if (discriminator_type != null) - return discriminator_type; - throw new BadKind(); - } - - /** - * Creates, adds and returns new field. - */ - public Field field() - { - Field f = new Field(); - members.add(f); - return f; - } - - /** {@inheritDoc} */ - public int member_count() - { - return members.size(); - } - - /** {@inheritDoc} */ - public Any member_label(int index) - throws BadKind, Bounds - { - Field f = getField(index); - if (f.label != null) - { - return f.label; - } - else - throw new BadKind(); - } - - /** {@inheritDoc} */ - public String member_name(int index) - throws BadKind - { - Field f = getField(index); - if (f.name != null) - { - return f.name; - } - else - throw new BadKind(); - } - - /** {@inheritDoc} */ - public TypeCode member_type(int index) - throws BadKind, Bounds - { - Field f = getField(index); - if (f.type != null) - { - return f.type; - } - else - throw new BadKind(); - } - - /** {@inheritDoc} */ - public short member_visibility(int index) - throws BadKind, Bounds - { - Field f = getField(index); - if (f.visibility != UNSET) - { - return (short) f.visibility; - } - else - throw new BadKind(); - } -} diff --git a/libjava/classpath/gnu/CORBA/recursiveTypeCode.java b/libjava/classpath/gnu/CORBA/recursiveTypeCode.java deleted file mode 100644 index 6bc672e..0000000 --- a/libjava/classpath/gnu/CORBA/recursiveTypeCode.java +++ /dev/null @@ -1,78 +0,0 @@ -/* recursiveTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.TCKind; - -/** - * The typecode, serving as a placeholder in defining - * typecodes, containing recursion. - */ -public class recursiveTypeCode - extends primitiveTypeCode -{ - /** - * The id of the type for that this type serves as a - * placeholder. - */ - private final String the_id; - - /** - * Create a typecode that serves as a placeholder for - * the typecode with the given id. - * - * @param id the Id of the type for that this type serves as a - * placeholder. - */ - public recursiveTypeCode(String an_id) - { - super(TCKind.tk_null); - the_id = an_id; - } - - /** - * Get the id of the type for that this type serves as a - * placeholder. - */ - public String id() - throws org.omg.CORBA.TypeCodePackage.BadKind - { - return the_id; - } -} diff --git a/libjava/classpath/gnu/CORBA/streamReadyHolder.java b/libjava/classpath/gnu/CORBA/streamReadyHolder.java deleted file mode 100644 index a777bd5..0000000 --- a/libjava/classpath/gnu/CORBA/streamReadyHolder.java +++ /dev/null @@ -1,120 +0,0 @@ -/* streamReadyHolder.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.CORBA; - -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.NO_IMPLEMENT; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.portable.InputStream; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.Streamable; - -import java.io.IOException; - -/** - * A holder that stores the input stream, from that the holder data - * can be read. There is no way to write the data into this holder. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class streamReadyHolder - implements Streamable -{ - /** - * The stream, holding the data for this holder. - */ - protected final InputStream stream; - - /** - * Create a holder that will read from the given stream. - * - * @param a_stream a stream. - */ - public streamReadyHolder(InputStream a_stream) - { - stream = a_stream; - } - - /** - * This method is not in use, should never be called. - */ - public TypeCode _type() - { - throw new NO_IMPLEMENT(); - } - - /** - * Writes the data from the stored stream into the provided - * output stream till the end of the input stream is reached. - * - * @throws MARSHAL if the IOException is thrown during operation. - */ - public void _write(OutputStream output) - { - try - { - int d = stream.read(); - - while (d >= 0) - { - output.write(d); - d = stream.read(); - } - } - catch (IOException ex) - { - throw new MARSHAL(ex + ":" + ex.getMessage()); - } - } - - /** - * This method is not in use, should never be called. - */ - public void _read(InputStream input) - { - throw new NO_IMPLEMENT(); - } - - /** - * Get the input stream that has been passed in constructor. - */ - InputStream getInputStream() - { - return stream; - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/streamRequest.java b/libjava/classpath/gnu/CORBA/streamRequest.java deleted file mode 100644 index a0f7eb0..0000000 --- a/libjava/classpath/gnu/CORBA/streamRequest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* gnuStreamRequest.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufOutput; - -/** - * A stream, additionally holding the gnu request. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class streamRequest - extends cdrBufOutput -{ - /** - * The enclosed request. - */ - public gnuRequest request; - - /** - * True if the response is expected. - */ - public boolean response_expected = true; -} diff --git a/libjava/classpath/gnu/CORBA/stringTypeCode.java b/libjava/classpath/gnu/CORBA/stringTypeCode.java deleted file mode 100644 index 27aa119..0000000 --- a/libjava/classpath/gnu/CORBA/stringTypeCode.java +++ /dev/null @@ -1,83 +0,0 @@ -/* stringTypeCode.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.TCKind; - -/** - * The typecode for string and wide string. - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class stringTypeCode - extends primitiveTypeCode -{ - private int len = 0; - - /** - * Create a new instance of the string type code. - * - * @param a_kind a kind of this typecode, normally - * either tk_string or tk_wstring. - */ - public stringTypeCode(TCKind a_kind) - { - super(a_kind); - } - - /** - * Set the length property. - * - * @param a_length a length. - */ - public void setLength(int a_length) - { - len = a_length; - } - - /** - * Get the length of the string. This method returns 0 - * (unbounded) if the property has not been set. - * - * @return the length (bound) of the string. - */ - public int length() - { - return len; - } -} diff --git a/libjava/classpath/gnu/CORBA/stubFinder.java b/libjava/classpath/gnu/CORBA/stubFinder.java deleted file mode 100644 index 77efd00..0000000 --- a/libjava/classpath/gnu/CORBA/stubFinder.java +++ /dev/null @@ -1,110 +0,0 @@ -/* stubFinder.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.ORB; -import org.omg.CORBA.portable.ObjectImpl; - -/** - * Finds a stub class like "_HelloStub" that can be instantiated - * from IOR reference. The returned object can be casted to the - * used type like "Hello" without using the helper .narrow method, - * and the object is not unnsecessarily re - instantiated if - * the .narrow method is used anyway. If no stub, matching the naming - * conventions, is available, the returned stub replacement can still be used - * to get the valid request, add parameter and invoke the method by name. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class stubFinder -{ - /** - * Search for the possibly available default stub. - * - * @param orb the current ORB. It is not required to find the binding - * classes, but is needed to instantiate the default implementation - * if no binding classes are found. - * - * @param ior the IOR, possibly containing the information about the - * correct implementation class. - */ - public static ObjectImpl search(ORB orb, IOR ior) - { - try - { - int a = ior.Id.indexOf(':'); - int b = ior.Id.lastIndexOf(':'); - - String s = ior.Id.substring(a + 1, b).replace('/', '.'); - - String path; - - b = s.lastIndexOf('.'); - if (b > 0) - path = s.substring(0, b + 1); - else - path = ""; - - String stub = "_" + s.substring(b + 1) + "Stub"; - - Class stubClass = Class.forName(path + stub); - - return (ObjectImpl) stubClass.newInstance(); - } - catch (Exception failed) - { - // Various exceptions can be thrown if the Id cannot be parsed, - // the class is missing, cannot be instantiated or is not an - // instance of the ObjectImpl. - return createDefaultStub(orb, ior); - } - } - - /** - * Return the default stub for the case when the client binding classes - * are not locally available. The returned stub can still be used - * to get the valid request, add parameter and invoke the method by name. - * - * @return the default implementation. - */ - protected static ObjectImpl createDefaultStub(ORB orb, IOR ior) - { - return new IOR_contructed_object(orb, ior); - } -} diff --git a/libjava/classpath/gnu/CORBA/typeNamer.java b/libjava/classpath/gnu/CORBA/typeNamer.java deleted file mode 100644 index f790dc9..0000000 --- a/libjava/classpath/gnu/CORBA/typeNamer.java +++ /dev/null @@ -1,180 +0,0 @@ -/* primitiveTypes.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import org.omg.CORBA.TCKind; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.TypeCodePackage.BadKind; - -/** - * A conveniency method for naming the built-in types. - * This is used in error reporting that is part of the user interface. - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class typeNamer -{ - /** - * Names of the primitve types. - */ - protected static final String[] tk = - new String[] - { - "null", "void", "short", "long", "ushort", "ulong", "float", "double", - "boolean", "char", "octet", "any", "TypeCode", "Principal", "objref", - "struct", "union", "enum", "string", "sequence", "array", "alias", - "exception", "longlong", "ulonglong", "longdouble", "wchar", "wstring", - "fixed", "value", "value_box", "native", "abstract_interface" - }; - - /** - * Primitve TypeCodes. - */ - protected static final TypeCode[] primitveCodes = - new TypeCode[] - { - new primitiveTypeCode(TCKind.tk_null), - new primitiveTypeCode(TCKind.tk_void), - new primitiveTypeCode(TCKind.tk_short), - new primitiveTypeCode(TCKind.tk_long), - new primitiveTypeCode(TCKind.tk_ushort), - new primitiveTypeCode(TCKind.tk_ulong), - new primitiveTypeCode(TCKind.tk_float), - new primitiveTypeCode(TCKind.tk_double), - new primitiveTypeCode(TCKind.tk_boolean), - new primitiveTypeCode(TCKind.tk_char), - new primitiveTypeCode(TCKind.tk_octet), - new primitiveTypeCode(TCKind.tk_any), - new primitiveTypeCode(TCKind.tk_TypeCode), - new primitiveTypeCode(TCKind.tk_Principal), - new recordTypeCode(TCKind.tk_objref), - new primitiveTypeCode(TCKind.tk_struct), - new primitiveTypeCode(TCKind.tk_union), - new primitiveTypeCode(TCKind.tk_enum), - new primitiveTypeCode(TCKind.tk_string), - new primitiveTypeCode(TCKind.tk_sequence), - new primitiveTypeCode(TCKind.tk_array), - new primitiveTypeCode(TCKind.tk_alias), - new primitiveTypeCode(TCKind.tk_except), - new primitiveTypeCode(TCKind.tk_longlong), - new primitiveTypeCode(TCKind.tk_ulonglong), - new primitiveTypeCode(TCKind.tk_longdouble), - new primitiveTypeCode(TCKind.tk_wchar), - new primitiveTypeCode(TCKind.tk_wstring), - new primitiveTypeCode(TCKind.tk_fixed), - new primitiveTypeCode(TCKind.tk_value), - new primitiveTypeCode(TCKind.tk_value_box), - new primitiveTypeCode(TCKind.tk_native), - new primitiveTypeCode(TCKind.tk_abstract_interface) - }; - - static - { - // The Id of the "abstract object" is defined as empty string. - recordTypeCode object = - (recordTypeCode) primitveCodes [ TCKind._tk_objref ]; - object.setId(""); - object.setName("Object"); - } - - /** - * Get the primitive type code. - * - * @return the primitve type code, corresponding the passed value. - * - * @throws BadKind if this is not a primitive type code. - */ - public static TypeCode getPrimitveTC(TCKind tc) - throws BadKind - { - try - { - return primitveCodes [ tc.value() ]; - } - catch (ArrayIndexOutOfBoundsException ex) - { - throw new BadKind(tc.value() + " is not a primitve type."); - } - } - - /** - * Get the string name of the passed primitive type. - * - * @param kind the kind of the primitive type the must be defined - * in {@link omg.org.CORBA.TCKind}. - * - * @return the short string name, used in error reporting, etc. - */ - public static String nameIt(int kind) - { - try - { - return tk [ kind ]; - } - catch (ArrayIndexOutOfBoundsException ex) - { - return "type of kind '" + kind + "'"; - } - } - - /** - * Get the string name of the passed primitive type. - * - * @param kind the kind of the primitive type the must be defined - * in {@link omg.org.CORBA.TCKind}. - * - * @return the short string name, used in error reporting, etc. - */ - public static String nameIt(TypeCode type) - { - try - { - if (type.kind().value() == TCKind._tk_array) - return "array of " + nameIt(type.content_type()); - else if (type.kind().value() == TCKind._tk_sequence) - return "sequence of " + nameIt(type.content_type()); - else - return nameIt(type.kind().value()); - } - catch (Exception ex) - { - return "type of kind '" + type.kind().value() + "'"; - } - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/typecodes/AliasTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/AliasTypeCode.java new file mode 100644 index 0000000..3cb8ebf --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/AliasTypeCode.java @@ -0,0 +1,148 @@ +/* AliasTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * The type code that is an alias of another type code. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class AliasTypeCode + extends PrimitiveTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The typecode repository id. + */ + protected final String id; + + /** + * The typecode name. + */ + protected final String name; + + /** + * The type code for that this typecode is an alias. + */ + protected final TypeCode aliasFor; + + /** + * Create the typecode, specifying for that typecode it is an + * alias and the id and name of the newly created typecode. + * + * @param an_aliasFor the typecode, for that this typecode is an + * alias. + * + * @param an_id the repository id fo the newly created typecode. + * + * @param a_name the name of the newly created typecode. + */ + public AliasTypeCode(TypeCode an_aliasFor, String an_id, String a_name) + { + super(TCKind.tk_alias); + aliasFor = an_aliasFor; + id = an_id; + name = a_name; + } + + /** + * Get the typecode, for that this typecode is an alias. + */ + public TypeCode content_type() + { + return aliasFor; + } + + /** + * The objects are assumed to be equal if they repository + * ids are both equal or both unavailable and the + * kind values are equal. + * + * @param other the other typecode to compare. + */ + public boolean equal(TypeCode other) + { + if (super.equal(other)) + return true; + try + { + return id.equals(other.id()); + } + catch (BadKind ex) + { + return false; + } + } + + /** + * Return true if the given typecode is equal for + * either this typecode of the alias typecode. + * + * @param other the typecode to compare. + */ + public boolean equivalent(TypeCode other) + { + return other.equal(this) || other.equal(aliasFor); + } + + /** + * Get the repository id of this typecode. + */ + public String id() + { + return id; + } + + /** + * Get the name of this typecode. + */ + public String name() + { + return name; + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/ArrayTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/ArrayTypeCode.java new file mode 100644 index 0000000..bb79810 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/ArrayTypeCode.java @@ -0,0 +1,272 @@ +/* ArrayTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A TypeCode for arrays. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ArrayTypeCode + extends PrimitiveTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + + /** + * The array components. + */ + TypeCode of; + + /** + * The length of the array, must be updated when setting + * a new value. + */ + private int length; + + /** + * Create a primitive array type code, defining the sequence + * {@link TCKind.tk_sequence)} with + * the given member type. + * + * @param array_of the sequence member type. + */ + public ArrayTypeCode(TCKind array_of) + { + super(TCKind.tk_sequence); + of = new PrimitiveTypeCode(array_of); + } + + /** + * Create a primitive array type code, defining the array, sequence + * or other type with the given member type. + * + * @param this_type the type of this type (normally either + * sequence of array). + * @param array_of the sequence member type. + */ + public ArrayTypeCode(TCKind this_type, TypeCode array_of) + { + super(this_type); + of = array_of; + } + + /** + * Return the array component type. + * @return the array component type + * @throws org.omg.CORBA.TypeCodePackage.BadKind + */ + public TypeCode content_type() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + return of; + } + + /** + * Return true if the other TypeCode defines the array, having elements + * of the same type. The sizes of arrays are not taken into + * consideration. + * + * @param other the other TypeCode + * @return true if other is an array with the same + * component type. + */ + public boolean equal(TypeCode other) + { + try + { + return kind() == other.kind() && + content_type() == other.content_type(); + } + catch (BadKind ex) + { + // Should not be thrown. + return false; + } + } + + /** + * Returns the agreed Id in the form of + * IDL:omg.org/CORBA/ {type name} Seq:1.0. + * + * @return the Id of this TypeCode. + * + * @throws org.omg.CORBA.TypeCodePackage.BadKind if the content type + * is not one of the constants, defined in {@link TCKind}. + * This package class should not be used as TypeCode for the arrays, + * holding the user defined components. + */ + public String id() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + switch (content_type().kind().value()) + { + case TCKind._tk_null : + return "IDL:omg.org/CORBA/NullSeq:1.0"; + + case TCKind._tk_void : + return "IDL:omg.org/CORBA/VoidSeq:1.0"; + + case TCKind._tk_short : + return "IDL:omg.org/CORBA/ShortSeq:1.0"; + + case TCKind._tk_long : + return "IDL:omg.org/CORBA/LongSeq:1.0"; + + case TCKind._tk_ushort : + return "IDL:omg.org/CORBA/UShortSeq:1.0"; + + case TCKind._tk_ulong : + return "IDL:omg.org/CORBA/ULongSeq:1.0"; + + case TCKind._tk_float : + return "IDL:omg.org/CORBA/FloatSeq:1.0"; + + case TCKind._tk_double : + return "IDL:omg.org/CORBA/DoubleSeq:1.0"; + + case TCKind._tk_boolean : + return "IDL:omg.org/CORBA/BooleanSeq:1.0"; + + case TCKind._tk_char : + return "IDL:omg.org/CORBA/CharSeq:1.0"; + + case TCKind._tk_octet : + return "IDL:omg.org/CORBA/OctetSeq:1.0"; + + case TCKind._tk_any : + return "IDL:omg.org/CORBA/AnySeq:1.0"; + + case TCKind._tk_TypeCode : + return "IDL:omg.org/CORBA/TypeCodeSeq:1.0"; + + case TCKind._tk_Principal : + return "IDL:omg.org/CORBA/PrincipalSeq:1.0"; + + case TCKind._tk_objref : + return "IDL:omg.org/CORBA/ObjrefSeq:1.0"; + + case TCKind._tk_struct : + return "IDL:omg.org/CORBA/StructSeq:1.0"; + + case TCKind._tk_union : + return "IDL:omg.org/CORBA/UnionSeq:1.0"; + + case TCKind._tk_enum : + return "IDL:omg.org/CORBA/EnumSeq:1.0"; + + case TCKind._tk_string : + return "IDL:omg.org/CORBA/StringSeq:1.0"; + + case TCKind._tk_sequence : + return "IDL:omg.org/CORBA/SequenceSeq:1.0"; + + case TCKind._tk_array : + return "IDL:omg.org/CORBA/ArraySeq:1.0"; + + case TCKind._tk_alias : + return "IDL:omg.org/CORBA/AliasSeq:1.0"; + + case TCKind._tk_except : + return "IDL:omg.org/CORBA/ExceptSeq:1.0"; + + case TCKind._tk_longlong : + return "IDL:omg.org/CORBA/LongLongSeq:1.0"; + + case TCKind._tk_ulonglong : + return "IDL:omg.org/CORBA/ULongLongSeq:1.0"; + + case TCKind._tk_longdouble : + return "IDL:omg.org/CORBA/LongDoubleSeq:1.0"; + + case TCKind._tk_wchar : + return "IDL:omg.org/CORBA/WCharSeq:1.0"; + + case TCKind._tk_wstring : + return "IDL:omg.org/CORBA/WStringSeq:1.0"; + + case TCKind._tk_fixed : + return "IDL:omg.org/CORBA/FixedSeq:1.0"; + + case TCKind._tk_value : + return "IDL:omg.org/CORBA/ValueSeq:1.0"; + + case TCKind._tk_value_box : + return "IDL:omg.org/CORBA/Value_boxSeq:1.0"; + + case TCKind._tk_native : + return "IDL:omg.org/CORBA/NativeSeq:1.0"; + + case TCKind._tk_abstract_interface : + return "IDL:omg.org/CORBA/Abstract_interfaceSeq:1.0"; + + default : + throw new BadKind(); + } + } + + /** + * Return the array length. + * @return the length of the array. + * @throws org.omg.CORBA.TypeCodePackage.BadKind + */ + public int length() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + return length; + } + + /** + * Sets the array length to the supplied value. + * + * @param l the new length. + */ + public void setLength(int l) + { + this.length = l; + } + +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/FixedTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/FixedTypeCode.java new file mode 100644 index 0000000..c5fae63 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/FixedTypeCode.java @@ -0,0 +1,152 @@ +/* FixedTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + + +import java.math.BigDecimal; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A typecode for CORBA fixed + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class FixedTypeCode + extends PrimitiveTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + + /** + * The number of the used digits. + */ + private short digits; + + /** + * The number of the digits after the decimal point. + */ + private short scale; + + /** + * Creates the instance of the fixed type code. + */ + public FixedTypeCode() + { + super(TCKind.tk_fixed); + } + + /** + * Creates the instance of the fixed type code, + * setting the digits and scale by example. + */ + public FixedTypeCode(BigDecimal example) + { + super(TCKind.tk_fixed); + if (example != null) + { + setScale(example.scale()); + setDigits(countDigits(example)); + } + } + + /** + * Set the number of digits. + */ + public void setDigits(int a_digits) + { + this.digits = (short) a_digits; + } + + /** + * Set the number of digits after the decimal point. + */ + public void setScale(int a_scale) + { + this.scale = (short) a_scale; + } + + /** + * Get the number of digits in thid BigDecimal + * + * @param x a BigDecimal to check. + */ + public static int countDigits(BigDecimal number) + { + return number.unscaledValue().abs().toString().length(); + } + + /** + * Compare with other type code for equality. + */ + public boolean equal(TypeCode other) + { + if (other == this) return true; + try + { + TypeCode that = (TypeCode) other; + return kind() == that.kind() && digits == that.fixed_digits() && + scale == that.fixed_scale(); + } + catch (BadKind ex) + { + return false; + } + } + + /** + * Get the number of digits. + */ + public short fixed_digits() + { + return digits; + } + + /** + * Get the number of digits after the decimal point. + */ + public short fixed_scale() + { + return scale; + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/GeneralTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/GeneralTypeCode.java new file mode 100644 index 0000000..0a90784 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/GeneralTypeCode.java @@ -0,0 +1,249 @@ +/* GeneralTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + +import gnu.CORBA.CDR.BufferedCdrOutput; + +import java.util.Arrays; +import java.util.BitSet; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A typecode for types, requiring to provide various additional + * properties but still not requiring to store the + * members of the structure. The property can be retrieved + * by the corresponding method if it has been previously assigned. + * Otherwise, a {@link BadKind} is thrown. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class GeneralTypeCode + extends PrimitiveTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + + /** + * Indicates that the field value has not been previously set. + */ + protected static int UNSET = Integer.MIN_VALUE; + + /** + * The kinds for that the length() must return 0 even if it + * has not been previously set. + */ + private static final BitSet lengthAllowed = new BitSet(); + + static + { + lengthAllowed.set(TCKind._tk_array); + lengthAllowed.set(TCKind._tk_sequence); + lengthAllowed.set(TCKind._tk_string); + lengthAllowed.set(TCKind._tk_wstring); + } + + private String id; + private String name; + private TypeCode concrete_base_type; + private TypeCode content_type; + private int len; + private int type_modifier = UNSET; + + /** + * Create a new instance, setting kind to the given kind. + * @param a_kind the kind of the typecode being created. + */ + public GeneralTypeCode(TCKind a_kind) + { + super(a_kind); + if (!lengthAllowed.get(a_kind.value())) + len = UNSET; + } + + /** + * Set this property. + */ + public void setConcreteBase_type(TypeCode a_concrete_base_type) + { + this.concrete_base_type = a_concrete_base_type; + } + + /** + * Set the component content type. + */ + public void setContentType(TypeCode a_content_type) + { + this.content_type = a_content_type; + } + + /** + * Set this property. + */ + public void setId(String an_id) + { + this.id = an_id; + } + + /** + * Set the length property. + * @param l + */ + public void setLength(int l) + { + len = l; + } + + /** + * Set this property. + */ + public void setName(String a_name) + { + this.name = a_name; + } + + /** + * Set the type modifier. + */ + public void setTypeModifier(int a_type_modifier) + { + this.type_modifier = a_type_modifier; + } + + /** {@inheritDoc} */ + public TypeCode concrete_base_type() + throws BadKind + { + if (concrete_base_type != null) + return concrete_base_type; + throw new BadKind("concrete_base_type"); + } + + /** + * Returns the content type that must be explicitly set + * for this class. + * + * @throws BadKind if the content type has not been set. + */ + public TypeCode content_type() + throws BadKind + { + if (content_type != null) + return content_type; + throw new BadKind("content_type"); + } + + /** + * Returns true if both typecodes, if written into CDR + * stream, would result the same stream content. + */ + public boolean equal(TypeCode other) + { + if (this == other) + return true; + if (kind() != other.kind()) + return false; + + BufferedCdrOutput a = new BufferedCdrOutput(16); + BufferedCdrOutput b = new BufferedCdrOutput(16); + + a.write_TypeCode(this); + b.write_TypeCode(other); + + return Arrays.equals(a.buffer.toByteArray(), b.buffer.toByteArray()); + } + + /** + * Delegates functionality to {@link #equal}. + */ + public boolean equivalent(TypeCode other) + { + return equal(other); + } + + /** {@inheritDoc} */ + public String id() + throws BadKind + { + if (id != null) + return id; + throw new BadKind("id"); + } + + /** + * Get the length. For sequences, arrays, strings and wstrings + * this method returns 0 rather than throwing a BadKind even + * if {@link setLength(int)} has not been previously called. + * + * @return the length of string, array or sequence. + * + * @throws BadKind if the method cannot be invoked for the + * given kind of typecode. + */ + public int length() + throws BadKind + { + if (len != UNSET) + return len; + throw new BadKind("length"); + } + + /** {@inheritDoc} */ + public String name() + throws BadKind + { + if (name != null) + return name; + throw new BadKind("name"); + } + + /** {@inheritDoc} */ + public short type_modifier() + throws BadKind + { + if (type_modifier != UNSET) + return (short) type_modifier; + throw new BadKind("type_modifier"); + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/PrimitiveTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/PrimitiveTypeCode.java new file mode 100644 index 0000000..22d39a8 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/PrimitiveTypeCode.java @@ -0,0 +1,201 @@ +/* PrimitiveTypeCode.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.CORBA.typecodes; + +import java.io.Serializable; + +import org.omg.CORBA.Any; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.portable.IDLEntity; + +/** + * An information about a primitive CORBA data type + * (boolean, char, wchar, octet and also signed or unsigned short, long, + * long long, float and double). + * This class only implements the methods {@link #kind() } + * and {@link equal() } that are valid for + * all TypeCode kinds. Other methods are implemented in derived + * subclasses. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class PrimitiveTypeCode + extends TypeCode + implements IDLEntity, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The kind of this TypeCode. + */ + protected final TCKind kind; + + public PrimitiveTypeCode(TCKind a_kind) + { + kind = a_kind; + } + + public TypeCode concrete_base_type() + throws BadKind + { + throw new BadKind(); + } + + public TypeCode content_type() + throws BadKind + { + throw new BadKind(); + } + + public int default_index() + throws BadKind + { + throw new BadKind(); + } + + public TypeCode discriminator_type() + throws BadKind + { + throw new BadKind(); + } + + /** + * Test two types for equality. The default implementation + * returs true of the types of the same kind. + * @param other the other type to compere with + * @return true if the types are interchangeable. + */ + public boolean equal(TypeCode other) + { + return kind() == other.kind(); + } + + public boolean equivalent(TypeCode parm1) + { + throw new NO_IMPLEMENT(); + } + + public short fixed_digits() + throws BadKind + { + throw new BadKind("fixed_digits"); + } + + public short fixed_scale() + throws BadKind + { + throw new BadKind("fixed_scale"); + } + + public TypeCode get_compact_typecode() + { + throw new NO_IMPLEMENT(); + } + + public String id() + throws BadKind + { + throw new BadKind("id"); + } + + /** + * Return the kind of this type code object. + * @return one of the TCKind.t_.. fields. + */ + public TCKind kind() + { + return kind; + } + + public int length() + throws BadKind + { + throw new BadKind("length"); + } + + public int member_count() + throws BadKind + { + throw new BadKind("member_count"); + } + + public Any member_label(int index) + throws BadKind, Bounds + { + throw new BadKind("member_label"); + } + + public String member_name(int index) + throws BadKind, Bounds + { + throw new BadKind("member_name"); + } + + public TypeCode member_type(int index) + throws BadKind, Bounds + { + throw new BadKind("member_type"); + } + + public short member_visibility(int index) + throws BadKind, Bounds + { + throw new BadKind("member_visibility"); + } + + public String name() + throws BadKind + { + throw new BadKind("name"); + } + + public short type_modifier() + throws BadKind + { + throw new BadKind("type_modifier"); + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/RecordTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/RecordTypeCode.java new file mode 100644 index 0000000..89f3425 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/RecordTypeCode.java @@ -0,0 +1,252 @@ +/* RecordTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + +import gnu.CORBA.CorbaList; + +import org.omg.CORBA.Any; +import org.omg.CORBA.StructMember; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.UnionMember; +import org.omg.CORBA.ValueMember; + +/** + * The type code that also has the member property getters + * supported. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class RecordTypeCode + extends GeneralTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The individual field of the record. + */ + public static class Field + { + /** + * The record label. + */ + public Any label; + + /** + * The record name. + */ + public String name; + + /** + * The record type. + */ + public TypeCode type; + + /** + * The record visibility. + */ + public int visibility = UNSET; + } + + /** + * The members of this data structure. + */ + protected CorbaList members = new CorbaList(); + private TypeCode discriminator_type; + private int default_index = UNSET; + + /** + * Creates the type code of the given kind. + */ + public RecordTypeCode(TCKind a_kind) + { + super(a_kind); + } + + /** + * Set the default index. + */ + public void setDefaultIndex(int a_default_index) + { + this.default_index = a_default_index; + } + + /** + * Set the discriminator type. + */ + public void setDiscriminator_type(TypeCode a_discriminator_type) + { + this.discriminator_type = a_discriminator_type; + } + + public Field getField(int p) + { + return (Field) members.get(p); + } + + public void add(Field field) + { + members.add(field); + } + + /** + * Adds a new field, taking values from the passed + * {@link StructMember}. + */ + public void add(StructMember m) + { + Field f = field(); + f.name = m.name; + f.type = m.type; + } + + /** + * Adds a new field, taking values from the passed + * {@link ValueMember}. + */ + public void add(ValueMember m) + { + Field f = field(); + f.name = m.name; + f.type = m.type; + f.visibility = m.access; + + } + + /** + * Adds a new field, taking values from the passed + * {@link UnionMember}. + */ + public void add(UnionMember m) + { + Field f = field(); + f.name = m.name; + f.type = m.type; + f.label = m.label; + } + + public int default_index() + throws BadKind + { + if (default_index != UNSET) + return default_index; + throw new BadKind(); + } + + public TypeCode discriminator_type() + throws BadKind + { + if (discriminator_type != null) + return discriminator_type; + throw new BadKind(); + } + + /** + * Creates, adds and returns new field. + */ + public Field field() + { + Field f = new Field(); + members.add(f); + return f; + } + + /** {@inheritDoc} */ + public int member_count() + { + return members.size(); + } + + /** {@inheritDoc} */ + public Any member_label(int index) + throws BadKind, Bounds + { + Field f = getField(index); + if (f.label != null) + { + return f.label; + } + else + throw new BadKind(); + } + + /** {@inheritDoc} */ + public String member_name(int index) + throws BadKind + { + Field f = getField(index); + if (f.name != null) + { + return f.name; + } + else + throw new BadKind(); + } + + /** {@inheritDoc} */ + public TypeCode member_type(int index) + throws BadKind, Bounds + { + Field f = getField(index); + if (f.type != null) + { + return f.type; + } + else + throw new BadKind(); + } + + /** {@inheritDoc} */ + public short member_visibility(int index) + throws BadKind, Bounds + { + Field f = getField(index); + if (f.visibility != UNSET) + { + return (short) f.visibility; + } + else + throw new BadKind(); + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/RecursiveTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/RecursiveTypeCode.java new file mode 100644 index 0000000..0e6ac37 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/RecursiveTypeCode.java @@ -0,0 +1,84 @@ +/* RecursiveTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + + +import org.omg.CORBA.TCKind; + +/** + * The typecode, serving as a placeholder in defining + * typecodes, containing recursion. + */ +public class RecursiveTypeCode + extends PrimitiveTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The id of the type for that this type serves as a + * placeholder. + */ + private final String the_id; + + /** + * Create a typecode that serves as a placeholder for + * the typecode with the given id. + * + * @param id the Id of the type for that this type serves as a + * placeholder. + */ + public RecursiveTypeCode(String an_id) + { + super(TCKind.tk_null); + the_id = an_id; + } + + /** + * Get the id of the type for that this type serves as a + * placeholder. + */ + public String id() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + return the_id; + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/StringTypeCode.java b/libjava/classpath/gnu/CORBA/typecodes/StringTypeCode.java new file mode 100644 index 0000000..2d1689b --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/StringTypeCode.java @@ -0,0 +1,89 @@ +/* StringTypeCode.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.typecodes; + + +import org.omg.CORBA.TCKind; + +/** + * The typecode for string and wide string. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class StringTypeCode + extends PrimitiveTypeCode +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + private int len = 0; + + /** + * Create a new instance of the string type code. + * + * @param a_kind a kind of this typecode, normally + * either tk_string or tk_wstring. + */ + public StringTypeCode(TCKind a_kind) + { + super(a_kind); + } + + /** + * Set the length property. + * + * @param a_length a length. + */ + public void setLength(int a_length) + { + len = a_length; + } + + /** + * Get the length of the string. This method returns 0 + * (unbounded) if the property has not been set. + * + * @return the length (bound) of the string. + */ + public int length() + { + return len; + } +} diff --git a/libjava/classpath/gnu/CORBA/typecodes/package.html b/libjava/classpath/gnu/CORBA/typecodes/package.html new file mode 100644 index 0000000..891b3b9 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typecodes/package.html @@ -0,0 +1,48 @@ + + + + +GNU Classpath - gnu.CORBA.typecodes + + + Contains GNU Classpath specific typecode definitions. + + @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + + + diff --git a/libjava/classpath/gnu/CORBA/universalHolder.java b/libjava/classpath/gnu/CORBA/universalHolder.java deleted file mode 100644 index c20dac44..0000000 --- a/libjava/classpath/gnu/CORBA/universalHolder.java +++ /dev/null @@ -1,174 +0,0 @@ -/* universalStreamable.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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.CORBA; - -import gnu.CORBA.CDR.cdrBufInput; -import gnu.CORBA.CDR.cdrBufOutput; - -import org.omg.CORBA.BAD_OPERATION; -import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.TypeCode; -import org.omg.CORBA.portable.InputStream; -import org.omg.CORBA.portable.OutputStream; -import org.omg.CORBA.portable.Streamable; - -import java.io.IOException; - -/** - * This class holds the abstract binary data array of the Streamable - * being stored. It is used to insert and extract into {@link Any} objects - * that have no holder, but have the helper classes. - * Encoding/decoding then must be performed by the helper. This class is - * defined as package private because it is not idiot proof and - * must be used with care. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class universalHolder - implements Streamable -{ - /** - * The binary data, stored inside this holder. - */ - private cdrBufOutput value = new cdrBufOutput(); - - /** - * Create the universal holder that uses the given buffer to store the data. - */ - public universalHolder(cdrBufOutput buffer) - { - value = buffer; - } - - /** - * Reads into the internal buffer till the end of stream is - * reached. No alignment operations are performed. This operation - * normally reads from the stream, where the single value, - * stored using {@link #_write}, is written. - * - * @throws MARSHALL, if the IOException is thrown during the - * stream operation. - */ - public void _read(InputStream input) - { - try - { - if (input instanceof cdrBufInput) - { - cdrBufInput b = (cdrBufInput) input; - value.write(b.buffer.getBuffer()); - } - else - { - int c; - - do - { - c = input.read(); - if (c >= 0) - value.write(c); - } - while (c >= 0); - } - } - catch (IOException ex) - { - MARSHAL t = new MARSHAL(); - t.initCause(ex); - throw t; - } - } - - /** - * The type is not known and cannot be returned. - * - * @throws BAD_OPERATION, always. - */ - public TypeCode _type() - { - throw new BAD_OPERATION(); - } - - /** - * Writes the binary data being stored into the given output - * stream. This operation supposes that the current stream - * position is 0 or satisfies the required alignments anyway. - * - * @throws MARSHAL if the IOExeption is thrown when writing the - * byte array. - */ - public void _write(OutputStream output) - { - try - { - value.buffer.writeTo(output); - } - catch (IOException ex) - { - MARSHAL t = new MARSHAL(); - t.initCause(ex); - throw t; - } - } - - /** - * Get the input stream that reads the fields of the stored value. - */ - InputStream getInputStream() - { - return value.create_input_stream(); - } - - /** - * Clone. - */ - public universalHolder Clone() - { - try - { - cdrBufOutput nb = new cdrBufOutput(value.buffer.size()); - value.buffer.writeTo(nb); - return new universalHolder(nb); - } - catch (IOException ex) - { - throw new Unexpected(ex); - } - } -} \ No newline at end of file diff --git a/libjava/classpath/gnu/classpath/ByteArray.java b/libjava/classpath/gnu/classpath/ByteArray.java new file mode 100644 index 0000000..6307b8a --- /dev/null +++ b/libjava/classpath/gnu/classpath/ByteArray.java @@ -0,0 +1,109 @@ +/* ByteArray.java -- wrapper around a byte array, with nice toString output. + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath; + +import java.io.PrintWriter; +import java.io.StringWriter; + +public final class ByteArray +{ + private final byte[] value; + + public ByteArray (final byte[] value) + { + this.value = value; + } + + public byte[] getValue () + { + return value; + } + + public String toString () + { + StringWriter str = new StringWriter (); + PrintWriter out = new PrintWriter (str); + int i = 0; + int len = value.length; + while (i < len) + { + out.print (formatInt (i, 16, 8)); + out.print (" "); + int l = Math.min (16, len - i); + String s = toHexString (value, i, l, ' '); + out.print (s); + for (int j = 56 - (56 - s.length ()); j < 56; j++) + out.print (" "); + for (int j = 0; j < l; j++) + { + byte b = value[i+j]; + if ((b & 0xFF) < 0x20 || (b & 0xFF) > 0x7E) + out.print ("."); + else + out.print ((char) (b & 0xFF)); + } + out.println (); + i += 16; + } + return str.toString (); + } + + public static String toHexString (byte[] buf, int off, int len, char sep) + { + StringBuffer str = new StringBuffer(); + for (int i = 0; i < len; i++) + { + str.append (Character.forDigit (buf[i+off] >>> 4 & 0x0F, 16)); + str.append (Character.forDigit (buf[i+off] & 0x0F, 16)); + if (i < len - 1) + str.append(sep); + } + return str.toString(); + } + + public static String formatInt (int value, int radix, int len) + { + String s = Integer.toString (value, radix); + StringBuffer buf = new StringBuffer (); + for (int j = 0; j < len - s.length(); j++) + buf.append ("0"); + buf.append (s); + return buf.toString(); + } +} diff --git a/libjava/classpath/gnu/classpath/SystemProperties.java b/libjava/classpath/gnu/classpath/SystemProperties.java index 600e1a6..524f040 100644 --- a/libjava/classpath/gnu/classpath/SystemProperties.java +++ b/libjava/classpath/gnu/classpath/SystemProperties.java @@ -106,12 +106,6 @@ public class SystemProperties if (defaultProperties.get("file.encoding") == null) defaultProperties.put("file.encoding", "8859_1"); - // Default to the Swing FocusManager so that the old-style Swing API - // for FocusManager can be supported without hardcoding it in AWT. - if (defaultProperties.get("gnu.java.awt.FocusManager") == null) - defaultProperties.put("gnu.java.awt.FocusManager", - "gnu.java.awt.FocusManager"); - // XXX FIXME - Temp hack for old systems that set the wrong property if (defaultProperties.get("java.io.tmpdir") == null) defaultProperties.put("java.io.tmpdir", diff --git a/libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java b/libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java new file mode 100644 index 0000000..b0d9b65 --- /dev/null +++ b/libjava/classpath/gnu/classpath/jdwp/event/VmDeathEvent.java @@ -0,0 +1,85 @@ +/* VmDeathEvent.java -- An event specifying that the VM has terminated + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Event notifying the debugger that the virtual machine has terminated. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VmDeathEvent + extends Event +{ + /** + * Constructs a VmDeathEvent object + * + * @param thread the initial thread + */ + public VmDeathEvent () + { + super (JdwpConstants.EventKind.VM_DEATH); + } + + /** + * Returns a specific filtering parameter for this event. + * This event has no valid types. + * + * @param type the type of parameter desired + * @returns the desired parameter or null + */ + public Object getParameter (Class type) + { + return null; + } + + /** + * Writes out event-specific data + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + // no data (request ID done by VMIdManager) + } +} diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java index 75753cd..d029e61 100644 --- a/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/StepFilter.java @@ -66,7 +66,7 @@ public class StepFilter public StepFilter (ThreadId tid, int size, int depth) throws InvalidThreadException { - if (tid == null | tid.getReference().get () == null) + if (tid.getReference().get () == null) throw new InvalidThreadException (tid.getId ()); _tid = tid; diff --git a/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java b/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java index 039b437..83ad409 100644 --- a/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java +++ b/libjava/classpath/gnu/classpath/jdwp/event/filters/ThreadOnlyFilter.java @@ -66,7 +66,7 @@ public class ThreadOnlyFilter public ThreadOnlyFilter (ThreadId tid) throws InvalidThreadException { - if (tid == null | tid.getReference().get () == null) + if (tid.getReference().get () == null) throw new InvalidThreadException (tid.getId ()); _tid = tid; diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java index 2470216..a9dc6cc 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java @@ -88,7 +88,8 @@ public class ArrayReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeLength(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java index 8ae1b45..b77c3a8 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java @@ -82,7 +82,8 @@ public class ArrayTypeCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } public void executeNewInstance(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java index 4e8e23e..cc591b1 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java @@ -86,7 +86,8 @@ public class ClassLoaderReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } public void executeVisibleClasses(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java index dcafa6f..cfec20b 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java @@ -79,7 +79,8 @@ public class ClassObjectReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } public void executeReflectedType(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java index ff6010e..f60da7b 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java @@ -95,7 +95,8 @@ public class ClassTypeCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeSuperclass(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java index 389b2d3..e4b1b60 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/EventRequestCommandSet.java @@ -102,7 +102,8 @@ public class EventRequestCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeSet(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java index b5db664..53308d7 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/MethodCommandSet.java @@ -94,7 +94,8 @@ public class MethodCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeLineTable(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java index 23a64c3..ef421ea 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java @@ -106,7 +106,8 @@ public class ObjectReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeReferenceType(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java index b9944f7..7338480 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java @@ -128,7 +128,8 @@ public class ReferenceTypeCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeSignature(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java index 480f4ca..7890a8e 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java @@ -91,7 +91,8 @@ public class StackFrameCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeGetValues(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java index 8f5bc68..13fde0a 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java @@ -84,7 +84,8 @@ public class StringReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeValue(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java index 8a11195..ba36251 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java @@ -85,7 +85,8 @@ public class ThreadGroupReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeName(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java index 73643b6..559e405 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java @@ -118,7 +118,8 @@ public class ThreadReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeName(ByteBuffer bb, DataOutputStream os) diff --git a/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java b/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java index b834068..6bdb236 100644 --- a/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java +++ b/libjava/classpath/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java @@ -67,7 +67,7 @@ public class VirtualMachineCommandSet public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) throws JdwpException { - boolean keepRunning = true; + boolean shutdown = false; try { switch (command) @@ -91,7 +91,7 @@ public class VirtualMachineCommandSet executeIDsizes(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.DISPOSE: - keepRunning = false; + shutdown = true; executeDispose(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.SUSPEND: @@ -101,7 +101,7 @@ public class VirtualMachineCommandSet executeResume(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.EXIT: - keepRunning = false; + shutdown = true; executeExit(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CREATE_STRING: @@ -145,7 +145,8 @@ public class VirtualMachineCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return keepRunning; + + return shutdown; } private void executeVersion(ByteBuffer bb, DataOutputStream os) @@ -164,8 +165,8 @@ public class VirtualMachineCommandSet String vmVersion = props.getProperty("java.version"); String vmName = props.getProperty("java.vm.name"); JdwpString.writeString(os, description); - os.write(jdwpMajor); - os.write(jdwpMinor); + os.writeInt(jdwpMajor); + os.writeInt(jdwpMinor); JdwpString.writeString(os, vmName); JdwpString.writeString(os, vmVersion); } diff --git a/libjava/classpath/gnu/java/awt/AWTUtilities.java b/libjava/classpath/gnu/java/awt/AWTUtilities.java index af1fc13..ca7b551 100644 --- a/libjava/classpath/gnu/java/awt/AWTUtilities.java +++ b/libjava/classpath/gnu/java/awt/AWTUtilities.java @@ -592,9 +592,12 @@ public class AWTUtilities if (destination == null) destination = getRoot(source); - - convertPointToScreen(pt, source); - convertPointFromScreen(pt, destination); + + if (source.isShowing() && destination.isShowing()) + { + convertPointToScreen(pt, source); + convertPointFromScreen(pt, destination); + } return pt; } diff --git a/libjava/classpath/gnu/java/awt/EmbeddedWindow.java b/libjava/classpath/gnu/java/awt/EmbeddedWindow.java index 08b2140..99f90c9 100644 --- a/libjava/classpath/gnu/java/awt/EmbeddedWindow.java +++ b/libjava/classpath/gnu/java/awt/EmbeddedWindow.java @@ -98,13 +98,11 @@ public class EmbeddedWindow extends Frame } catch (IllegalAccessException e) { - throw new RuntimeException - ("couldn't set java.awt.Component.peer field"); + throw new AssertionError (e); } catch (NoSuchFieldException e) { - throw new RuntimeException - ("couldn't set java.awt.Component.peer field"); + throw new AssertionError (e); } super.addNotify(); diff --git a/libjava/classpath/gnu/java/awt/FocusManager.java b/libjava/classpath/gnu/java/awt/FocusManager.java deleted file mode 100644 index 49b40bf..0000000 --- a/libjava/classpath/gnu/java/awt/FocusManager.java +++ /dev/null @@ -1,52 +0,0 @@ -/* FocusManager.java -- Provide Swing FocusManager API compatibility - 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 modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt; - -/** - * This is a subclass of the otherwise abstract class - * {@link javax.swing.FocusManager}. Its sole purpose is to make the Swing - * FocusManager usable as a FocusManager in AWT, so that we can provide both - * the new (1.4) KeyboardFocusManager API and still support the older - * Swing FocusManager. - * - * @author Roman Kennke - */ -public class FocusManager - extends javax.swing.FocusManager -{ -} diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontMetrics.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontMetrics.java index 7a439e8..c79f403 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontMetrics.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkFontMetrics.java @@ -1,5 +1,5 @@ /* GdkFontMetrics.java - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -62,15 +62,28 @@ public class GdkFontMetrics extends FontMetrics static final int TEXT_METRICS_HEIGHT = 3; static final int TEXT_METRICS_X_ADVANCE = 4; static final int TEXT_METRICS_Y_ADVANCE = 5; - - + + /** + * Makes sure to return a Font based on the given Font that has as + * peer a GdkFontPeer. Used in the initializer. + */ + private static Font initFont(Font font) + { + if (font == null) + return new Font("Dialog", Font.PLAIN, 12); + else if (font.getPeer() instanceof GdkFontPeer) + return font; + else + { + ClasspathToolkit toolkit; + toolkit = (ClasspathToolkit) Toolkit.getDefaultToolkit(); + return toolkit.getFont(font.getName(), font.getAttributes()); + } + } + public GdkFontMetrics (Font font) { - super (font.getPeer() instanceof GdkFontPeer - ? font - : ((ClasspathToolkit)(Toolkit.getDefaultToolkit ())) - .getFont (font.getName(), font.getAttributes ())); - + super(initFont(font)); peer = (GdkFontPeer) this.font.getPeer(); font_metrics = new int[5]; diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java index 160602b..d80306c 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java @@ -68,7 +68,7 @@ public class GdkGraphics extends Graphics Color color, xorColor; GtkComponentPeer component; - Font font; + Font font = new Font ("Dialog", Font.PLAIN, 12); Rectangle clip; GtkImage image; @@ -88,6 +88,8 @@ public class GdkGraphics extends Graphics color = g.color; xorColor = g.xorColor; font = g.font; + if (font == null) + font = new Font ("Dialog", Font.PLAIN, 12); clip = new Rectangle (g.clip); component = g.component; @@ -115,7 +117,6 @@ public class GdkGraphics extends Graphics GdkGraphics (GtkComponentPeer component) { this.component = component; - font = component.awtComponent.getFont (); color = Color.black; if (component.isRealized ()) @@ -128,6 +129,8 @@ public class GdkGraphics extends Graphics { initState (component); color = component.awtComponent.getForeground (); + if (color == null) + color = Color.BLACK; Dimension d = component.awtComponent.getSize (); clip = new Rectangle (0, 0, d.width, d.height); } @@ -137,6 +140,8 @@ public class GdkGraphics extends Graphics { initStateUnlocked (component); color = component.awtComponent.getForeground (); + if (color == null) + color = Color.BLACK; Dimension d = component.awtComponent.getSize (); clip = new Rectangle (0, 0, d.width, d.height); } @@ -378,7 +383,8 @@ public class GdkGraphics extends Graphics public void setFont (Font font) { - this.font = font; + if (font != null) + this.font = font; } native void setFunction (int gdk_func); diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java index 6d9aabf..c9ed301 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -101,7 +101,7 @@ public class GdkGraphics2D extends Graphics2D static { if (! Configuration.GTK_CAIRO_ENABLED) - throw new Error("Grahics2D not implemented. " + throw new Error("Graphics2D not implemented. " + "Cairo was not found or disabled at configure time"); if (Configuration.INIT_LOAD_LIBRARY) @@ -154,11 +154,22 @@ public class GdkGraphics2D extends Graphics2D public Graphics create(int x, int y, int width, int height) { - return new GdkGraphics2D(width, height); + return new GdkGraphics2D(this, x, y, width, height); + } + + private void fail_g2d () + { + System.err.println ("Attempted to instantiate GdkGraphics2D" + + " but Graphics2D not enabled. Try again with" + + " -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D"); + System.exit (1); } GdkGraphics2D(GdkGraphics2D g) { + if (!GtkToolkit.useGraphics2D ()) + fail_g2d (); + paint = g.paint; stroke = g.stroke; setRenderingHints(g.hints); @@ -198,8 +209,18 @@ public class GdkGraphics2D extends Graphics2D stateStack = new Stack(); } + GdkGraphics2D(GdkGraphics2D g, int x, int y, int widht, int height) + { + this(g); + translate(x, y); + clipRect(0, 0, widht, height); + } + GdkGraphics2D(int width, int height) { + if (!GtkToolkit.useGraphics2D ()) + fail_g2d (); + initState(width, height); setColor(Color.black); @@ -215,6 +236,9 @@ public class GdkGraphics2D extends Graphics2D GdkGraphics2D(GtkComponentPeer component) { + if (!GtkToolkit.useGraphics2D ()) + fail_g2d (); + this.component = component; if (component.isRealized()) @@ -949,7 +973,10 @@ public class GdkGraphics2D extends Graphics2D public Shape getClip() { - return clip.getBounds2D(); //getClipInDevSpace(); + if (clip == null) + return null; + else + return clip.getBounds2D(); //getClipInDevSpace(); } public Rectangle getClipBounds() @@ -992,8 +1019,11 @@ public class GdkGraphics2D extends Graphics2D if (clip == null) { // Reset clipping. - Dimension d = component.awtComponent.getSize(); - setClip(0, 0, d.width, d.height); + if (component != null) + { + Dimension d = component.awtComponent.getSize(); + setClip(0, 0, d.width, d.height); + } } else { @@ -1045,8 +1075,9 @@ public class GdkGraphics2D extends Graphics2D public void clearRect(int x, int y, int width, int height) { - cairoSetRGBAColor(bg.getRed() / 255.0, bg.getGreen() / 255.0, - bg.getBlue() / 255.0, 1.0); + if (bg != null) + cairoSetRGBAColor(bg.getRed() / 255.0, bg.getGreen() / 255.0, + bg.getBlue() / 255.0, 1.0); cairoNewPath(); cairoRectangle(x, y, width, height); cairoFill(); @@ -1371,7 +1402,8 @@ public class GdkGraphics2D extends Graphics2D public void copyArea(int x, int y, int width, int height, int dx, int dy) { - throw new java.lang.UnsupportedOperationException(); + GdkGraphics2D g = (GdkGraphics2D) create(x, y, width, height); + gdkDrawDrawable(g, x + dx, y + dy); } public void drawArc(int x, int y, int width, int height, int startAngle, @@ -1604,6 +1636,11 @@ public class GdkGraphics2D extends Graphics2D public void setFont(Font f) { + // Sun's JDK does not throw NPEs, instead it leaves the current setting + // unchanged. So do we. + if (f == null) + return; + if (f.getPeer() instanceof GdkFontPeer) font = f; else diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java index ff51745..c3ae581 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java @@ -388,10 +388,7 @@ public class GdkTextLayout throw new Error("not implemented"); } - public Shape getOutline (AffineTransform tx) - { - throw new Error("not implemented"); - } + public native Shape getOutline (AffineTransform tx); public Shape getVisualHighlightShape (TextHitInfo firstEndpoint, TextHitInfo secondEndpoint, diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java index c140744..ed7dc74 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java @@ -131,9 +131,6 @@ public class GtkChoicePeer extends GtkComponentPeer protected void postChoiceItemEvent (String label, int stateChange) { - // Must set our state before notifying listeners - if (stateChange == ItemEvent.SELECTED) - ((Choice) awtComponent).select (label); postItemEvent (label, stateChange); } } diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java index 60e8371..fe0dae7 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java @@ -71,6 +71,7 @@ import java.awt.image.ImageProducer; import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; +import java.awt.peer.WindowPeer; import java.util.Timer; import java.util.TimerTask; @@ -98,6 +99,7 @@ public class GtkComponentPeer extends GtkGenericPeer native int[] gtkWidgetGetBackground (); native void gtkWidgetGetDimensions (int[] dim); native void gtkWidgetGetPreferredDimensions (int[] dim); + native void gtkWindowGetLocationOnScreen (int[] point); native void gtkWidgetGetLocationOnScreen (int[] point); native void gtkWidgetSetCursor (int type); native void gtkWidgetSetCursorUnlocked (int type); @@ -270,7 +272,10 @@ public class GtkComponentPeer extends GtkGenericPeer public Point getLocationOnScreen () { int point[] = new int[2]; - gtkWidgetGetLocationOnScreen (point); + if( this instanceof WindowPeer ) + gtkWindowGetLocationOnScreen (point); + else + gtkWidgetGetLocationOnScreen (point); return new Point (point[0], point[1]); } diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java index c2cbc37..f5ba3ad 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java @@ -44,6 +44,10 @@ import java.awt.Rectangle; import java.awt.event.PaintEvent; import java.awt.peer.DialogPeer; +import javax.swing.JDialog; +import javax.swing.JPopupMenu; +import javax.swing.JToolTip; + public class GtkDialogPeer extends GtkWindowPeer implements DialogPeer { @@ -82,10 +86,28 @@ public class GtkDialogPeer extends GtkWindowPeer void create () { - // Create a decorated dialog window. - create (GDK_WINDOW_TYPE_HINT_DIALOG, true); - Dialog dialog = (Dialog) awtComponent; + int type = GDK_WINDOW_TYPE_HINT_DIALOG; + + if (dialog instanceof JDialog) + { + Class heavyWeightClass; + try + { + heavyWeightClass = Class.forName("javax.swing.Popup$JWindowPopup"); + } + catch (ClassNotFoundException e) + { + throw new AssertionError(e); + } + + if (dialog.getClass() == heavyWeightClass + || ((JDialog) dialog).getContentPane() instanceof JToolTip) + type = GDK_WINDOW_TYPE_HINT_MENU; + } + + // Create a decorated dialog window. + create (type, !((Dialog) awtComponent).isUndecorated ()); gtkWindowSetModal (dialog.isModal ()); setTitle (dialog.getTitle ()); diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java index 6eb90ff..99cca0c 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkFramePeer.java @@ -168,7 +168,8 @@ public class GtkFramePeer extends GtkWindowPeer void create () { // Create a normal decorated window. - create (GDK_WINDOW_TYPE_HINT_NORMAL, true); + create (GDK_WINDOW_TYPE_HINT_NORMAL, + !((Frame) awtComponent).isUndecorated ()); Frame frame = (Frame) awtComponent; diff --git a/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java b/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java index 54f4888..591b528 100644 --- a/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java +++ b/libjava/classpath/gnu/java/awt/peer/qt/QtToolkit.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.java.awt.peer.qt; +import gnu.classpath.Configuration; import gnu.java.awt.EmbeddedWindow; import gnu.java.awt.peer.ClasspathFontPeer; import gnu.java.awt.peer.EmbeddedWindowPeer; @@ -135,7 +136,8 @@ public class QtToolkit extends ClasspathToolkit { eventQueue = new EventQueue(); repaintThread = new QtRepaintThread(); - System.loadLibrary("qtpeer"); + if (Configuration.INIT_LOAD_LIBRARY) + System.loadLibrary("qtpeer"); String theme = null; try diff --git a/libjava/classpath/gnu/java/beans/DummyAppletContext.java b/libjava/classpath/gnu/java/beans/DummyAppletContext.java index 4facb47..583d2f5 100644 --- a/libjava/classpath/gnu/java/beans/DummyAppletContext.java +++ b/libjava/classpath/gnu/java/beans/DummyAppletContext.java @@ -63,7 +63,6 @@ import java.util.Iterator; class DummyAppletContext implements AppletContext { private static final Enumeration EMPTY_ENUMERATION = Collections.enumeration(Collections.EMPTY_SET); - private static final AudioClip DUMMY_CLIP = new DummyAudioClip(); DummyAppletContext() { @@ -80,14 +79,7 @@ class DummyAppletContext implements AppletContext */ public AudioClip getAudioClip(URL url) { - try - { - return (url.openConnection() != null ? DUMMY_CLIP : null); - } - catch (IOException ioe) - { - return null; - } + return Applet.newAudioClip(url); } /** Loads the Image instance by delegating to @@ -170,31 +162,4 @@ class DummyAppletContext implements AppletContext { return Collections.EMPTY_SET.iterator(); } - - /** Dummy AudioClip implementation that does nothing but - * preventing NullPointerExceptionS being thrown in programs - * that expect a valid AudioClip instance to be returned by - * their Applet. - * - * @author Robert Schuster - */ - static class DummyAudioClip implements AudioClip - { - public void play() - { - } - - public void stop() - { - } - - public void loop() - { - } - - public String toString() - { - return "DummyAudioClip never plays anything - implement javax.sound and make us happy :)"; - } - } } diff --git a/libjava/classpath/gnu/java/beans/decoder/BooleanHandler.java b/libjava/classpath/gnu/java/beans/decoder/BooleanHandler.java index a34fe34..a675e8c 100644 --- a/libjava/classpath/gnu/java/beans/decoder/BooleanHandler.java +++ b/libjava/classpath/gnu/java/beans/decoder/BooleanHandler.java @@ -57,10 +57,10 @@ class BooleanHandler extends SimpleHandler protected Object parse(String number) throws AssemblyException { if (number.equals("true")) - return new Boolean(true); + return Boolean.TRUE; if (number.equals("false")) - return new Boolean(false); + return Boolean.FALSE; throw new AssemblyException(new IllegalArgumentException("Element contained no valid boolean value.")); } diff --git a/libjava/classpath/gnu/java/io/PlatformHelper.java b/libjava/classpath/gnu/java/io/PlatformHelper.java index d2c6012..79ce6e8 100644 --- a/libjava/classpath/gnu/java/io/PlatformHelper.java +++ b/libjava/classpath/gnu/java/io/PlatformHelper.java @@ -109,11 +109,6 @@ public class PlatformHelper String tmppath = path.replace('/', separatorChar); StringBuffer canonpath; - // We found it'll be more efficient and easy to handle to - // return a lowercased canonical path - if(isWindows) - tmppath = tmppath.toLowerCase(); - int i; if ((i = beginWithRootPathPrefix(tmppath)) == 0 ) diff --git a/libjava/classpath/gnu/java/net/LineInputStream.java b/libjava/classpath/gnu/java/net/LineInputStream.java index 5ca0686..81a3c7d 100644 --- a/libjava/classpath/gnu/java/net/LineInputStream.java +++ b/libjava/classpath/gnu/java/net/LineInputStream.java @@ -1,5 +1,5 @@ /* LineInputStream.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.net; +import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.FilterInputStream; import java.io.IOException; @@ -91,7 +92,8 @@ public class LineInputStream buf = new ByteArrayOutputStream(); this.encoding = encoding; eof = false; - blockReads = in.markSupported(); + // If it is already buffered, additional buffering gains nothing. + blockReads = !(in instanceof BufferedInputStream) && in.markSupported(); } /** @@ -109,11 +111,12 @@ public class LineInputStream if (blockReads) { // Use mark and reset to read chunks of bytes - final int MIN_LENGTH = 1024; + final int MAX_LENGTH = 1024; int len, pos; - + len = in.available(); - len = (len < MIN_LENGTH) ? MIN_LENGTH : len; + if (len == 0 || len > MAX_LENGTH) + len = MAX_LENGTH; byte[] b = new byte[len]; in.mark(len); // Read into buffer b diff --git a/libjava/classpath/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java b/libjava/classpath/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java deleted file mode 100644 index 680e45d..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java +++ /dev/null @@ -1,123 +0,0 @@ -/* Authenticator.java --ByteArrayResponseBodyReader.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Simple response body reader that stores content in a byte array. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class ByteArrayResponseBodyReader - implements ResponseBodyReader -{ - - /** - * The content. - */ - protected byte[] content; - - /** - * The position in the content at which the next write will occur. - */ - protected int pos; - - /** - * The length of the buffer. - */ - protected int len; - - /** - * Constructs a new byte array response body reader. - */ - public ByteArrayResponseBodyReader() - { - this(4096); - } - - /** - * Constructs a new byte array response body reader with the specified - * initial buffer size. - * @param size the initial buffer size - */ - public ByteArrayResponseBodyReader(int size) - { - content = new byte[size]; - pos = len = 0; - } - - /** - * This reader accepts all responses. - */ - public boolean accept(Request request, Response response) - { - return true; - } - - public void read(byte[] buffer, int offset, int length) - { - int l = length - offset; - if (pos + l > content.length) - { - byte[] tmp = new byte[content.length * 2]; - System.arraycopy(content, 0, tmp, 0, pos); - content = tmp; - } - System.arraycopy(buffer, offset, content, pos, l); - pos += l; - len = pos; - } - - public void close() - { - pos = 0; - } - - /** - * Retrieves the content of this reader as a byte array. - * The size of the returned array is the number of bytes read. - */ - public byte[] toByteArray() - { - byte[] ret = new byte[len]; - System.arraycopy(content, 0, ret, 0, len); - return ret; - } - -} - diff --git a/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java b/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java index c0706b7..a4487d1 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java +++ b/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java @@ -110,7 +110,7 @@ public class ChunkedInputStream // Read chunk header int c, last = 0; boolean seenSemi = false; - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); do { c = in.read(); diff --git a/libjava/classpath/gnu/java/net/protocol/http/Cookie.java b/libjava/classpath/gnu/java/net/protocol/http/Cookie.java index 45e2f73..0be7a09 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/Cookie.java +++ b/libjava/classpath/gnu/java/net/protocol/http/Cookie.java @@ -139,7 +139,7 @@ public class Cookie public String toString(boolean showPath, boolean showDomain) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(name); buf.append('='); buf.append(value); diff --git a/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java b/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java index 6d9f447..573a791 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java +++ b/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java @@ -41,10 +41,6 @@ package gnu.java.net.protocol.http; import gnu.classpath.Configuration; import gnu.classpath.SystemProperties; import gnu.java.net.EmptyX509TrustManager; -import gnu.java.net.protocol.http.event.ConnectionEvent; -import gnu.java.net.protocol.http.event.ConnectionListener; -import gnu.java.net.protocol.http.event.RequestEvent; -import gnu.java.net.protocol.http.event.RequestListener; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -57,6 +53,7 @@ import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -131,8 +128,6 @@ public class HTTPConnection */ protected int minorVersion; - private final List connectionListeners; - private final List requestListeners; private final List handshakeCompletedListeners; /** @@ -165,6 +160,12 @@ public class HTTPConnection */ protected CookieManager cookieManager; + + /** + * The pool that this connection is a member of (if any). + */ + private LinkedHashMap pool; + /** * Creates a new HTTP connection. * @param hostname the name of the host to connect to @@ -236,8 +237,6 @@ public class HTTPConnection this.connectionTimeout = connectionTimeout; this.timeout = timeout; majorVersion = minorVersion = 1; - connectionListeners = new ArrayList(4); - requestListeners = new ArrayList(4); handshakeCompletedListeners = new ArrayList(2); } @@ -332,6 +331,73 @@ public class HTTPConnection } /** + * The number of times this HTTPConnection has be used via keep-alive. + */ + int useCount; + + /** + * Generates a key for connections in the connection pool. + * + * @param h the host name. + * @param p the port. + * @param sec true if using https. + * + * @return the key. + */ + static Object getPoolKey(String h, int p, boolean sec) + { + StringBuilder buf = new StringBuilder(sec ? "https://" : "http://"); + buf.append(h); + buf.append(':'); + buf.append(p); + return buf.toString(); + } + + /** + * Set the connection pool that this HTTPConnection is a member of. + * If left unset or set to null, it will not be a member of any pool + * and will not be a candidate for reuse. + * + * @param p the pool. + */ + void setPool(LinkedHashMap p) + { + pool = p; + } + + /** + * Signal that this HTTPConnection is no longer needed and can be + * returned to the connection pool. + * + */ + void release() + { + if (pool != null) + { + synchronized (pool) + { + useCount++; + Object key = HTTPConnection.getPoolKey(hostname, port, secure); + pool.put(key, this); + while (pool.size() >= HTTPURLConnection.maxConnections) + { + // maxConnections must always be >= 1 + Object lru = pool.keySet().iterator().next(); + HTTPConnection c = (HTTPConnection)pool.remove(lru); + try + { + c.closeConnection(); + } + catch (IOException ioe) + { + // Ignore it. We are just cleaning up. + } + } + } + } + } + + /** * Creates a new request using this connection. * @param method the HTTP method to invoke * @param path the URI-escaped RFC2396 abs_path with @@ -367,7 +433,7 @@ public class HTTPConnection Cookie[] cookies = cookieManager.getCookies(hostname, secure, path); if (cookies != null && cookies.length > 0) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append("$Version=1"); for (int i = 0; i < cookies.length; i++) { @@ -378,7 +444,6 @@ public class HTTPConnection ret.setHeader("Cookie", buf.toString()); } } - fireRequestEvent(RequestEvent.REQUEST_CREATED, ret); return ret; } @@ -388,14 +453,7 @@ public class HTTPConnection public void close() throws IOException { - try - { - closeConnection(); - } - finally - { - fireConnectionEvent(ConnectionEvent.CONNECTION_CLOSED); - } + closeConnection(); } /** @@ -534,7 +592,7 @@ public class HTTPConnection */ protected String getURI() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(secure ? "https://" : "http://"); buf.append(hostname); if (secure) @@ -584,84 +642,6 @@ public class HTTPConnection // -- Events -- - public void addConnectionListener(ConnectionListener l) - { - synchronized (connectionListeners) - { - connectionListeners.add(l); - } - } - - public void removeConnectionListener(ConnectionListener l) - { - synchronized (connectionListeners) - { - connectionListeners.remove(l); - } - } - - protected void fireConnectionEvent(int type) - { - ConnectionEvent event = new ConnectionEvent(this, type); - ConnectionListener[] l = null; - synchronized (connectionListeners) - { - l = new ConnectionListener[connectionListeners.size()]; - connectionListeners.toArray(l); - } - for (int i = 0; i < l.length; i++) - { - switch (type) - { - case ConnectionEvent.CONNECTION_CLOSED: - l[i].connectionClosed(event); - break; - } - } - } - - public void addRequestListener(RequestListener l) - { - synchronized (requestListeners) - { - requestListeners.add(l); - } - } - - public void removeRequestListener(RequestListener l) - { - synchronized (requestListeners) - { - requestListeners.remove(l); - } - } - - protected void fireRequestEvent(int type, Request request) - { - RequestEvent event = new RequestEvent(this, type, request); - RequestListener[] l = null; - synchronized (requestListeners) - { - l = new RequestListener[requestListeners.size()]; - requestListeners.toArray(l); - } - for (int i = 0; i < l.length; i++) - { - switch (type) - { - case RequestEvent.REQUEST_CREATED: - l[i].requestCreated(event); - break; - case RequestEvent.REQUEST_SENDING: - l[i].requestSent(event); - break; - case RequestEvent.REQUEST_SENT: - l[i].requestSent(event); - break; - } - } - } - void addHandshakeCompletedListener(HandshakeCompletedListener l) { synchronized (handshakeCompletedListeners) diff --git a/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java b/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java index 9f2055f..d5da7d6 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java +++ b/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java @@ -38,7 +38,6 @@ exception statement from your version. */ package gnu.java.net.protocol.http; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -75,7 +74,8 @@ public class HTTPURLConnection /** * Pool of reusable connections, used if keepAlive is true. */ - private static final Map connectionPool = new LinkedHashMap(); + private static final LinkedHashMap connectionPool = new LinkedHashMap(); + static int maxConnections; /* * The underlying connection. @@ -87,7 +87,6 @@ public class HTTPURLConnection int proxyPort; String agent; boolean keepAlive; - int maxConnections; private Request request; private Headers requestHeaders; @@ -95,8 +94,8 @@ public class HTTPURLConnection private boolean requestMethodSetExplicitly; private Response response; - private ByteArrayInputStream responseSink; - private ByteArrayInputStream errorSink; + private InputStream responseSink; + private InputStream errorSink; private HandshakeCompletedEvent handshakeEvent; @@ -202,34 +201,59 @@ public class HTTPURLConnection } connection.setProxy(proxyHostname, proxyPort); } - request = connection.newRequest(method, file); - if (!keepAlive) - { - request.setHeader("Connection", "close"); - } - if (agent != null) - { - request.setHeader("User-Agent", agent); - } - request.getHeaders().putAll(requestHeaders); - if (requestSink != null) + try { - byte[] content = requestSink.toByteArray(); - RequestBodyWriter writer = new ByteArrayRequestBodyWriter(content); - request.setRequestBodyWriter(writer); + request = connection.newRequest(method, file); + if (!keepAlive) + { + request.setHeader("Connection", "close"); + } + if (agent != null) + { + request.setHeader("User-Agent", agent); + } + request.getHeaders().putAll(requestHeaders); + if (requestSink != null) + { + byte[] content = requestSink.toByteArray(); + RequestBodyWriter writer = new ByteArrayRequestBodyWriter(content); + request.setRequestBodyWriter(writer); + } + if (creds != null) + { + request.setAuthenticator(new Authenticator() { + public Credentials getCredentials(String realm, int attempts) + { + return (attempts < 2) ? creds : null; + } + }); + } + response = request.dispatch(); } - ByteArrayResponseBodyReader reader = new ByteArrayResponseBodyReader(); - request.setResponseBodyReader(reader); - if (creds != null) + catch (IOException ioe) { - request.setAuthenticator(new Authenticator() { - public Credentials getCredentials(String realm, int attempts) + if (connection.useCount > 0) + { + // Connection re-use failed: Try a new connection. + try + { + connection.close(); + } + catch (IOException _) + { + // Ignore. + } + connection = null; + retry = true; + continue; + } + else { - return (attempts < 2) ? creds : null; + // First time the connection was used: Hard failure. + throw ioe; } - }); } - response = request.dispatch(); + if (response.getCodeClass() == 3 && getInstanceFollowRedirects()) { // Follow redirect @@ -307,7 +331,8 @@ public class HTTPURLConnection } else { - responseSink = new ByteArrayInputStream(reader.toByteArray ()); + responseSink = response.getBody(); + if (response.getCode() == 404) { errorSink = responseSink; @@ -328,27 +353,14 @@ public class HTTPURLConnection HTTPConnection connection; if (keepAlive) { - StringBuffer buf = new StringBuffer(secure ? "https://" : "http://"); - buf.append(Thread.currentThread().hashCode()); - buf.append('@'); - buf.append(host); - buf.append(':'); - buf.append(port); - String key = buf.toString(); + Object key = HTTPConnection.getPoolKey(host, port, secure); synchronized (connectionPool) { - connection = (HTTPConnection) connectionPool.get(key); + connection = (HTTPConnection) connectionPool.remove(key); if (connection == null) { connection = new HTTPConnection(host, port, secure); - // Good housekeeping - if (connectionPool.size() == maxConnections) - { - // maxConnections must always be >= 1 - Object lru = connectionPool.keySet().iterator().next(); - connectionPool.remove(lru); - } - connectionPool.put(key, connection); + connection.setPool(connectionPool); } } } @@ -502,9 +514,9 @@ public class HTTPURLConnection return null; } } - Map headers = response.getHeaders(); - Map ret = new LinkedHashMap(); - ret.put("", Collections.singletonList(getStatusLine(response))); + Headers headers = response.getHeaders(); + LinkedHashMap ret = new LinkedHashMap(); + ret.put(null, Collections.singletonList(getStatusLine(response))); for (Iterator i = headers.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); @@ -512,7 +524,7 @@ public class HTTPURLConnection String value = (String) entry.getValue(); ret.put(key, Collections.singletonList(value)); } - return ret; + return Collections.unmodifiableMap(ret); } String getStatusLine(Response response) diff --git a/libjava/classpath/gnu/java/net/protocol/http/Headers.java b/libjava/classpath/gnu/java/net/protocol/http/Headers.java index 847ebef..9306fc4 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/Headers.java +++ b/libjava/classpath/gnu/java/net/protocol/http/Headers.java @@ -60,7 +60,7 @@ import java.util.Set; * @author Chris Burdess (dog@gnu.org) */ public class Headers - implements Map + extends LinkedHashMap { static final DateFormat dateFormat = new HTTPDateFormat(); @@ -143,36 +143,18 @@ public class Headers } - private LinkedHashMap headers; - public Headers() { - headers = new LinkedHashMap(); - } - - public int size() - { - return headers.size(); - } - - public boolean isEmpty() - { - return headers.isEmpty(); } public boolean containsKey(Object key) { - return headers.containsKey(new Header((String) key)); - } - - public boolean containsValue(Object value) - { - return headers.containsValue(value); + return super.containsKey(new Header((String) key)); } public Object get(Object key) { - return headers.get(new Header((String) key)); + return super.get(new Header((String) key)); } /** @@ -180,7 +162,7 @@ public class Headers */ public String getValue(String header) { - return (String) headers.get(new Header(header)); + return (String) super.get(new Header(header)); } /** @@ -205,6 +187,27 @@ public class Headers } /** + * Returns the value of the specified header as a long, or -1 if the + * header is not present or cannot be parsed as a long. + */ + public long getLongValue(String header) + { + String val = getValue(header); + if (val == null) + { + return -1; + } + try + { + return Long.parseLong(val); + } + catch (NumberFormatException e) + { + } + return -1; + } + + /** * Returns the value of the specified header as a date, * or null if the header is not present or not a date. */ @@ -227,12 +230,12 @@ public class Headers public Object put(Object key, Object value) { - return headers.put(new Header((String) key), value); + return super.put(new Header((String) key), value); } public Object remove(Object key) { - return headers.remove(new Header((String) key)); + return super.remove(new Header((String) key)); } public void putAll(Map t) @@ -241,18 +244,13 @@ public class Headers { String key = (String) i.next(); String value = (String) t.get(key); - headers.put(new Header(key), value); + put(key, value); } } - public void clear() - { - headers.clear(); - } - public Set keySet() { - Set keys = headers.keySet(); + Set keys = super.keySet(); Set ret = new LinkedHashSet(); for (Iterator i = keys.iterator(); i.hasNext(); ) { @@ -261,14 +259,9 @@ public class Headers return ret; } - public Collection values() - { - return headers.values(); - } - public Set entrySet() { - Set entries = headers.entrySet(); + Set entries = super.entrySet(); Set ret = new LinkedHashSet(); for (Iterator i = entries.iterator(); i.hasNext(); ) { @@ -278,16 +271,6 @@ public class Headers return ret; } - public boolean equals(Object other) - { - return headers.equals(other); - } - - public int hashCode() - { - return headers.hashCode(); - } - /** * Parse the specified input stream, adding headers to this collection. */ @@ -298,7 +281,7 @@ public class Headers (LineInputStream) in : new LineInputStream(in); String name = null; - StringBuffer value = new StringBuffer(); + StringBuilder value = new StringBuilder(); while (true) { String line = lin.readLine(); @@ -354,14 +337,14 @@ public class Headers private void addValue(String name, String value) { Header key = new Header(name); - String old = (String) headers.get(key); + String old = (String) super.get(key); if (old == null) { - headers.put(key, value); + super.put(key, value); } else { - headers.put(key, old + ", " + value); + super.put(key, old + ", " + value); } } diff --git a/libjava/classpath/gnu/java/net/protocol/http/LimitedLengthInputStream.java b/libjava/classpath/gnu/java/net/protocol/http/LimitedLengthInputStream.java new file mode 100644 index 0000000..16cf56a --- /dev/null +++ b/libjava/classpath/gnu/java/net/protocol/http/LimitedLengthInputStream.java @@ -0,0 +1,220 @@ +/* LimitedLengthInputStream.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.net.protocol.http; + +import java.io.IOException; +import java.io.InputStream; + +/** + * InputStream that limits the total number of bytes that can be read + * from an underlying stream. In addition to limiting the number of + * bytes read, close() is not propagated to the underlying stream. + * + * @author David Daney (ddaney@avtrex.com) + */ +class LimitedLengthInputStream + extends InputStream +{ + private long remainingLen; + private boolean restrictLen; + private HTTPConnection connection; + private boolean eof; + private InputStream in; + private boolean doClose; + + + private void handleClose() + throws IOException + { + eof = true; + if (doClose) + { + in.close(); + } + else + { + connection.release(); + } + in = null; + connection = null; + } + + /** + * Constructor. + * + * @param in the underlying stream + * + * @param maxLen the maximum number of bytes to read + * + * @param restrictLen if true the number of bytes that can be read + * from this stream will be limited to maxLen, otherwise the number + * of bytes is not restricted. + * + * @param con the HTTPConnection associated with this stream + * + * @param doClose if true con will be closed when finished reading, + * else it will be placed back in the connection pool. + * + */ + LimitedLengthInputStream(InputStream in, + long maxLen, + boolean restrictLen, + HTTPConnection con, + boolean doClose) + throws IOException + + { + this.in = in; + this.remainingLen = maxLen; + this.restrictLen = restrictLen; + this.connection = con; + this.doClose = doClose; + + if (restrictLen) + { + if (maxLen < 0) + throw new IllegalArgumentException(); + else if (maxLen == 0) + handleClose(); // Nothing to do, release the connection. + } + } + + public synchronized int read() + throws IOException + { + if (eof) + return -1; // EOF + + int r; + + if (restrictLen) + { + r = in.read(); + if (-1 != r) + remainingLen--; + + if (0 == remainingLen) + handleClose(); + } + else + { + r = in.read(); + if (r == -1) + handleClose(); + } + + return r; + } + + public int read(byte[] buffer) + throws IOException + { + return read(buffer, 0, buffer.length); + } + + public synchronized int read(byte[] buffer, int offset, int length) + throws IOException + { + if (eof) + return -1; // EOF + + if (restrictLen && length > remainingLen) + length = (int) remainingLen; + + int r = in.read(buffer, offset, length); + + if (-1 == r) + handleClose(); + + if (restrictLen && r > 0) + { + remainingLen -= r; + if (0 == remainingLen) + handleClose(); + } + return r; + } + + public synchronized long skip(long n) + throws IOException + { + + if (eof) + return 0; + + if (restrictLen && n > remainingLen) + n = remainingLen; + + long r = in.skip(n); + + if (restrictLen) + { + remainingLen -= r; + if (0 == remainingLen) + handleClose(); + } + return r; + } + + public synchronized int available() + throws IOException + { + if (eof) + return 0; + + int a = in.available(); + if (restrictLen && a > remainingLen) + a = (int)remainingLen; + return a; + } + + public synchronized void close() + throws IOException + { + if (eof) + return; + + // If we get to here, the stream was not fully read. Just throw + // it away. + + doClose = true; + + handleClose(); + } +} diff --git a/libjava/classpath/gnu/java/net/protocol/http/Request.java b/libjava/classpath/gnu/java/net/protocol/http/Request.java index 21205e6..b9441b3 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/Request.java +++ b/libjava/classpath/gnu/java/net/protocol/http/Request.java @@ -1,5 +1,5 @@ /* Request.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,7 +40,6 @@ package gnu.java.net.protocol.http; import gnu.java.net.BASE64; import gnu.java.net.LineInputStream; -import gnu.java.net.protocol.http.event.RequestEvent; import java.io.IOException; import java.io.InputStream; @@ -100,11 +99,6 @@ public class Request protected int requestBodyNegotiationThreshold; /** - * The response body reader. - */ - protected ResponseBodyReader responseBodyReader; - - /** * Map of response header handlers. */ protected Map responseHeaderHandlers; @@ -236,16 +230,6 @@ public class Request } /** - * Sets the response body reader. - * @param responseBodyReader the handler to receive notifications of - * response body content - */ - public void setResponseBodyReader(ResponseBodyReader responseBodyReader) - { - this.responseBodyReader = responseBodyReader; - } - - /** * Sets a callback handler to be invoked for the specified header name. * @param name the header name * @param handler the handler to receive the value for the header @@ -324,13 +308,10 @@ public class Request do { retry = false; - // Send request - connection.fireRequestEvent(RequestEvent.REQUEST_SENDING, this); // Get socket output and input streams OutputStream out = connection.getOutputStream(); - LineInputStream in = - new LineInputStream(connection.getInputStream()); + // Request line String requestUri = path; if (connection.isUsingProxy() && @@ -369,28 +350,42 @@ public class Request count += len; } while (len > -1 && count < contentLength); - out.write(CRLF.getBytes(US_ASCII)); } out.flush(); - // Sent event - connection.fireRequestEvent(RequestEvent.REQUEST_SENT, this); // Get response - response = readResponse(in); - int sc = response.getCode(); - if (sc == 401 && authenticator != null) - { - if (authenticate(response, attempts++)) - { - retry = true; - } - } - else if (sc == 100 && expectingContinue) - { - requestHeaders.remove("Expect"); - setHeader("Content-Length", Integer.toString(contentLength)); - expectingContinue = false; - retry = true; - } + while(true) + { + response = readResponse(connection.getInputStream()); + int sc = response.getCode(); + if (sc == 401 && authenticator != null) + { + if (authenticate(response, attempts++)) + { + retry = true; + } + } + else if (sc == 100) + { + if (expectingContinue) + { + requestHeaders.remove("Expect"); + setHeader("Content-Length", + Integer.toString(contentLength)); + expectingContinue = false; + retry = true; + } + else + { + // A conforming server can send an unsoliceted + // Continue response but *should* not (RFC 2616 + // sec 8.2.3). Ignore the bogus Continue + // response and get the real response that + // should follow + continue; + } + } + break; + } } while (retry); } @@ -402,14 +397,16 @@ public class Request return response; } - Response readResponse(LineInputStream in) + Response readResponse(InputStream in) throws IOException { String line; int len; // Read response status line - line = in.readLine(); + LineInputStream lis = new LineInputStream(in); + + line = lis.readLine(); if (line == null) { throw new ProtocolException("Peer closed connection"); @@ -438,30 +435,25 @@ public class Request String message = line.substring(end + 1, len - 1); // Read response headers Headers responseHeaders = new Headers(); - responseHeaders.parse(in); + responseHeaders.parse(lis); notifyHeaderHandlers(responseHeaders); - // Construct response - int codeClass = code / 100; - Response ret = new Response(majorVersion, minorVersion, code, - codeClass, message, responseHeaders); + InputStream body = null; + switch (code) { + case 100: case 204: case 205: case 304: break; default: - // Does response body reader want body? - boolean notify = (responseBodyReader != null); - if (notify) - { - if (!responseBodyReader.accept(this, ret)) - { - notify = false; - } - } - readResponseBody(ret, in, notify); + body = createResponseBodyStream(responseHeaders, majorVersion, + minorVersion, in); } + + // Construct response + Response ret = new Response(majorVersion, minorVersion, code, + message, responseHeaders, body); return ret; } @@ -487,25 +479,40 @@ public class Request } } - void readResponseBody(Response response, InputStream in, - boolean notify) + private InputStream createResponseBodyStream(Headers responseHeaders, + int majorVersion, + int minorVersion, + InputStream in) throws IOException { - byte[] buffer = new byte[4096]; - int contentLength = -1; + long contentLength = -1; Headers trailer = null; - String transferCoding = response.getHeader("Transfer-Encoding"); + // Persistent connections are the default in HTTP/1.1 + boolean doClose = "close".equalsIgnoreCase(getHeader("Connection")) || + "close".equalsIgnoreCase(responseHeaders.getValue("Connection")) || + (connection.majorVersion == 1 && connection.minorVersion == 0) || + (majorVersion == 1 && minorVersion == 0); + + String transferCoding = responseHeaders.getValue("Transfer-Encoding"); if ("chunked".equalsIgnoreCase(transferCoding)) { - trailer = new Headers(); - in = new ChunkedInputStream(in, trailer); + in = new LimitedLengthInputStream(in, -1, false, connection, doClose); + + in = new ChunkedInputStream(in, responseHeaders); } else { - contentLength = response.getIntHeader("Content-Length"); + contentLength = responseHeaders.getLongValue("Content-Length"); + + if (contentLength < 0) + doClose = true; // No Content-Length, must close. + + in = new LimitedLengthInputStream(in, contentLength, + contentLength >= 0, + connection, doClose); } - String contentCoding = response.getHeader("Content-Encoding"); + String contentCoding = responseHeaders.getValue("Content-Encoding"); if (contentCoding != null && !"identity".equals(contentCoding)) { if ("gzip".equals(contentCoding)) @@ -522,51 +529,7 @@ public class Request contentCoding); } } - - // Persistent connections are the default in HTTP/1.1 - boolean doClose = "close".equalsIgnoreCase(getHeader("Connection")) || - "close".equalsIgnoreCase(response.getHeader("Connection")) || - (connection.majorVersion == 1 && connection.minorVersion == 0) || - (response.majorVersion == 1 && response.minorVersion == 0); - - int count = contentLength; - int len = (count > -1) ? count : buffer.length; - len = (len > buffer.length) ? buffer.length : len; - while (len > -1) - { - len = in.read(buffer, 0, len); - if (len < 0) - { - // EOF - connection.closeConnection(); - break; - } - if (notify) - { - responseBodyReader.read(buffer, 0, len); - } - if (count > -1) - { - count -= len; - if (count < 1) - { - if (doClose) - { - connection.closeConnection(); - } - break; - } - } - } - if (notify) - { - responseBodyReader.close(); - } - if (trailer != null) - { - response.getHeaders().putAll(trailer); - notifyHeaderHandlers(trailer); - } + return in; } boolean authenticate(Response response, int attempts) @@ -686,7 +649,7 @@ public class Request { int len = text.length(); String key = null; - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); Properties ret = new Properties(); boolean inQuote = false; for (int i = 0; i < len; i++) @@ -739,7 +702,7 @@ public class Request { int nc = connection.getNonceCount(nonce); String hex = Integer.toHexString(nc); - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (int i = 8 - hex.length(); i > 0; i--) { buf.append('0'); @@ -810,7 +773,7 @@ public class Request int len = text.length(); String attr = null; - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); boolean inQuote = false; for (int i = 0; i <= len; i++) { diff --git a/libjava/classpath/gnu/java/net/protocol/http/Response.java b/libjava/classpath/gnu/java/net/protocol/http/Response.java index 29dc28b..58d7454 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/Response.java +++ b/libjava/classpath/gnu/java/net/protocol/http/Response.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.net.protocol.http; +import java.io.InputStream; import java.util.Date; /** @@ -64,19 +65,6 @@ public class Response protected final int code; /** - * The class of the response. This is the most significant digit of the - * status code. - *
- *
1xx
Informational response
- *
2xx
Success
- *
3xx
Redirection
- *
4xx
Client error
- *
5xx
Server error
- *
- */ - protected final int codeClass; - - /** * Human-readable text of the response. */ protected final String message; @@ -87,18 +75,22 @@ public class Response protected final Headers headers; /** + * An InputStream that returns the body of the response. + */ + protected final InputStream body; + + /** * Constructs a new response with the specified parameters. */ protected Response(int majorVersion, int minorVersion, int code, - int codeClass, String message, - Headers headers) + String message, Headers headers, InputStream body) { this.majorVersion = majorVersion; this.minorVersion = minorVersion; this.code = code; - this.codeClass = codeClass; this.message = message; this.headers = headers; + this.body = body; } /** @@ -129,12 +121,19 @@ public class Response } /** - * Returns the class of the response. - * @see #codeClass + * Returns the class of the response. This is the most significant + * digit of the status code. + *
+ *
1xx
Informational response
+ *
2xx
Success
+ *
3xx
Redirection
+ *
4xx
Client error
+ *
5xx
Server error
+ *
*/ public int getCodeClass() { - return codeClass; + return code / 100; } /** @@ -173,6 +172,15 @@ public class Response } /** + * Returns the header value for the specified name as a long. + * @param name the header name + */ + public long getLongHeader(String name) + { + return headers.getLongValue(name); + } + + /** * Returns the header value for the specified name as a date. * @param name the header name */ @@ -181,5 +189,14 @@ public class Response return headers.getDateValue(name); } + /** + * Returns an InputStream that returns the body of the response. + * + * @return the body of the response + */ + public InputStream getBody() + { + return body; + } } diff --git a/libjava/classpath/gnu/java/net/protocol/http/ResponseBodyReader.java b/libjava/classpath/gnu/java/net/protocol/http/ResponseBodyReader.java deleted file mode 100644 index 49e1b37..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/ResponseBodyReader.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ResponseBodyReader.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Callback interface for receiving notification of response body content. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface ResponseBodyReader -{ - - /** - * Indicate whether this reader is interested in the specified response. - * If it returns false, it will not receive body content notifications for - * that response. - */ - boolean accept(Request request, Response response); - - /** - * Receive notification of body content. - * @param buffer the content buffer - * @param offset the offset within the buffer that content starts - * @param length the length of the content - */ - void read(byte[] buffer, int offset, int length); - - /** - * Notifies the reader that the end of the content was reached. - */ - void close(); - -} - diff --git a/libjava/classpath/gnu/java/net/protocol/http/event/ConnectionEvent.java b/libjava/classpath/gnu/java/net/protocol/http/event/ConnectionEvent.java deleted file mode 100644 index 3f6f545..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/event/ConnectionEvent.java +++ /dev/null @@ -1,81 +0,0 @@ -/* ConnectionEvent.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import java.util.EventObject; - -/** - * A connection event. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class ConnectionEvent - extends EventObject -{ - - /** - * The connection closed event type. - */ - public static final int CONNECTION_CLOSED = 0; - - /** - * The type of this event. - */ - protected int type; - - /** - * Constructs a connection event with the specified source and type. - */ - public ConnectionEvent(Object source, int type) - { - super(source); - this.type = type; - } - - /** - * Returns the type of this event. - * @see #type - */ - public int getType() - { - return type; - } - -} - diff --git a/libjava/classpath/gnu/java/net/protocol/http/event/ConnectionListener.java b/libjava/classpath/gnu/java/net/protocol/http/event/ConnectionListener.java deleted file mode 100644 index 073e89d..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/event/ConnectionListener.java +++ /dev/null @@ -1,58 +0,0 @@ -/* ConnectionListener.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import java.util.EventListener; - -/** - * A connection listener. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface ConnectionListener - extends EventListener -{ - - /** - * Callback invoked when the associated connection is closed. - */ - void connectionClosed(ConnectionEvent event); - -} - diff --git a/libjava/classpath/gnu/java/net/protocol/http/event/RequestEvent.java b/libjava/classpath/gnu/java/net/protocol/http/event/RequestEvent.java deleted file mode 100644 index 281c621..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/event/RequestEvent.java +++ /dev/null @@ -1,107 +0,0 @@ -/* RequestEvent.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import gnu.java.net.protocol.http.Request; - -import java.util.EventObject; - -/** - * A request event. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class RequestEvent - extends EventObject -{ - - /** - * The request created event type. - */ - public static final int REQUEST_CREATED = 0; - - /** - * The request sending event type. - */ - public static final int REQUEST_SENDING = 1; - - /** - * The request sent event type. - */ - public static final int REQUEST_SENT = 2; - - /** - * The type of this event. - */ - protected int type; - - /** - * The request associated with this event. - */ - protected Request request; - - /** - * Constructs a request event with the specified source, type, and request. - */ - public RequestEvent(Object source, int type, Request request) - { - super(source); - this.type = type; - this.request = request; - } - - /** - * Returns the type of this event. - * @see #type - */ - public int getType() - { - return type; - } - - /** - * Returns the request associated with this event. - */ - public Request getRequest() - { - return request; - } - -} - diff --git a/libjava/classpath/gnu/java/net/protocol/http/event/RequestListener.java b/libjava/classpath/gnu/java/net/protocol/http/event/RequestListener.java deleted file mode 100644 index c880fbc..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/event/RequestListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* RequestListener.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import java.util.EventListener; - -/** - * A request listener. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface RequestListener - extends EventListener -{ - - /** - * Callback invoked when a request is created from the associated - * connection. - */ - void requestCreated(RequestEvent event); - - /** - * Callback invoked when the request has been initialised with all data - * and before sending this data to the server. - */ - void requestSending(RequestEvent event); - - /** - * Callback invoked after all request data has been sent to the server. - */ - void requestSent(RequestEvent event); - -} - diff --git a/libjava/classpath/gnu/java/net/protocol/http/event/package.html b/libjava/classpath/gnu/java/net/protocol/http/event/package.html deleted file mode 100644 index 6aed0fc..0000000 --- a/libjava/classpath/gnu/java/net/protocol/http/event/package.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - -GNU Classpath - gnu.java.net.protocol.http.event - - -

- - - diff --git a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java index bd7a80d..e8548742 100644 --- a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java +++ b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java @@ -69,13 +69,17 @@ public final class Connection extends JarURLConnection private static Hashtable cache = new Hashtable(); private static final int READBUFSIZE = 4*1024; - public static synchronized JarFile get (URL url) throws IOException + public static synchronized JarFile get (URL url, boolean useCaches) + throws IOException { - JarFile jf = (JarFile) cache.get (url); + JarFile jf; + if (useCaches) + { + jf = (JarFile) cache.get (url); + if (jf != null) + return jf; + } - if (jf != null) - return jf; - if ("file".equals (url.getProtocol())) { File f = new File (url.getFile()); @@ -100,9 +104,10 @@ public final class Connection extends JarURLConnection jf = new JarFile (f, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); } - - cache.put (url, jf); - + + if (useCaches) + cache.put (url, jf); + return jf; } } @@ -120,7 +125,7 @@ public final class Connection extends JarURLConnection return; jar_url = getJarFileURL(); - jar_file = JarFileCache.get (jar_url); + jar_file = JarFileCache.get (jar_url, useCaches); String entry_name = getEntryName(); if (entry_name != null diff --git a/libjava/classpath/gnu/java/nio/SocketChannelImpl.java b/libjava/classpath/gnu/java/nio/SocketChannelImpl.java index 9fb71c1..fcddbd6 100644 --- a/libjava/classpath/gnu/java/nio/SocketChannelImpl.java +++ b/libjava/classpath/gnu/java/nio/SocketChannelImpl.java @@ -258,7 +258,7 @@ public final class SocketChannelImpl extends SocketChannel } else { - dst.put (data, offset, len); + dst.put (data, offset, readBytes); } return readBytes; diff --git a/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java b/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java index 0ee5d3f..466f3dd 100644 --- a/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java +++ b/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java @@ -175,7 +175,8 @@ public final class FileChannelImpl extends FileChannel */ protected void finalize() throws IOException { - this.close(); + if (fd != -1) + close(); } public int read (ByteBuffer dst) throws IOException diff --git a/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java b/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java index e3927d9..fa1dbc4 100644 --- a/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java +++ b/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java @@ -54,6 +54,8 @@ final class UTF_16Decoder extends CharsetDecoder static final int BIG_ENDIAN = 0; static final int LITTLE_ENDIAN = 1; static final int UNKNOWN_ENDIAN = 2; + static final int MAYBE_BIG_ENDIAN = 3; + static final int MAYBE_LITTLE_ENDIAN = 4; private static final char BYTE_ORDER_MARK = 0xFEFF; private static final char REVERSED_BYTE_ORDER_MARK = 0xFFFE; @@ -81,26 +83,37 @@ final class UTF_16Decoder extends CharsetDecoder byte b2 = in.get (); // handle byte order mark - if (byteOrder == UNKNOWN_ENDIAN) + if (byteOrder == UNKNOWN_ENDIAN || + byteOrder == MAYBE_BIG_ENDIAN || + byteOrder == MAYBE_LITTLE_ENDIAN) { char c = (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF)); if (c == BYTE_ORDER_MARK) { + if (byteOrder == MAYBE_LITTLE_ENDIAN) + { + return CoderResult.malformedForLength (2); + } byteOrder = BIG_ENDIAN; inPos += 2; continue; } else if (c == REVERSED_BYTE_ORDER_MARK) { + if (byteOrder == MAYBE_BIG_ENDIAN) + { + return CoderResult.malformedForLength (2); + } byteOrder = LITTLE_ENDIAN; inPos += 2; continue; } else { - // assume big endian, do not consume bytes, + // assume big or little endian, do not consume bytes, // continue with normal processing - byteOrder = BIG_ENDIAN; + byteOrder = (byteOrder == MAYBE_LITTLE_ENDIAN ? + LITTLE_ENDIAN : BIG_ENDIAN); } } diff --git a/libjava/classpath/gnu/java/nio/charset/UnicodeLittle.java b/libjava/classpath/gnu/java/nio/charset/UnicodeLittle.java index d354e04..63f2855 100644 --- a/libjava/classpath/gnu/java/nio/charset/UnicodeLittle.java +++ b/libjava/classpath/gnu/java/nio/charset/UnicodeLittle.java @@ -64,7 +64,7 @@ final class UnicodeLittle extends Charset public CharsetDecoder newDecoder () { - return new UTF_16Decoder (this, UTF_16Decoder.UNKNOWN_ENDIAN); + return new UTF_16Decoder (this, UTF_16Decoder.MAYBE_LITTLE_ENDIAN); } public CharsetEncoder newEncoder () diff --git a/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java b/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java index 58eaa85..873e9ec 100644 --- a/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java +++ b/libjava/classpath/gnu/java/nio/charset/iconv/IconvProvider.java @@ -62,7 +62,11 @@ public final class IconvProvider extends CharsetProvider } } - private IconvProvider() + // Declaring the construtor public may violate the use of singleton. + // But it must be public so that an instance of this class can be + // created by Class.newInstance(), which is the case when this provider is + // defined in META-INF/services/java.nio.charset.spi.CharsetProvider. + public IconvProvider() { IconvMetaData.setup(); } diff --git a/libjava/classpath/gnu/java/rmi/dgc/DGCImpl_Stub.java b/libjava/classpath/gnu/java/rmi/dgc/DGCImpl_Stub.java index b1e086a..9f18d12 100644 --- a/libjava/classpath/gnu/java/rmi/dgc/DGCImpl_Stub.java +++ b/libjava/classpath/gnu/java/rmi/dgc/DGCImpl_Stub.java @@ -81,7 +81,7 @@ public final class DGCImpl_Stub public void clean(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.VMID $param_2, boolean $param_3) throws java.rmi.RemoteException { try { if (useNewInvoke) { - ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, new java.lang.Boolean($param_3)}, -5803803475088455571L); + ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, Boolean.valueOf($param_3)}, -5803803475088455571L); } else { java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash); diff --git a/libjava/classpath/gnu/java/rmi/server/RMIClassLoaderImpl.java b/libjava/classpath/gnu/java/rmi/server/RMIClassLoaderImpl.java new file mode 100644 index 0000000..2e1e780 --- /dev/null +++ b/libjava/classpath/gnu/java/rmi/server/RMIClassLoaderImpl.java @@ -0,0 +1,350 @@ +/* RMIClassLoaderImpl.java -- FIXME: briefly describe file purpose + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.rmi.server; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.rmi.server.RMIClassLoaderSpi; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * The default implementation of {@link java.rmi.server.RMIClassLoaderSpi}. + * + * @author Roman Kennke (kennke@aicas.com) + */ +public class RMIClassLoaderImpl extends RMIClassLoaderSpi +{ + private static class MyClassLoader extends URLClassLoader + { + // Package-private to avoid a trampoline constructor. + MyClassLoader (URL[] urls, ClassLoader parent, String annotation) + { + super (urls, parent); + this.annotation = annotation; + } + + private MyClassLoader (URL[] urls, ClassLoader parent) + { + super (urls, parent); + this.annotation = urlToAnnotation (urls); + } + + public static String urlToAnnotation (URL[] urls) + { + if (urls.length == 0) + return null; + + StringBuffer annotation = new StringBuffer (64 * urls.length); + + for (int i = 0; i < urls.length; i++) + { + annotation.append (urls [i].toExternalForm()); + annotation.append (' '); + } + + return annotation.toString(); + } + + public final String getClassAnnotation() + { + return annotation; + } + + private final String annotation; + } + + /** + * This class is used to identify a cached classloader by its codebase and + * the context classloader that is its parent. + */ + private static class CacheKey + { + private String mCodeBase; + private ClassLoader mContextClassLoader; + + public CacheKey (String theCodebase, ClassLoader theContextClassLoader) + { + mCodeBase = theCodebase; + mContextClassLoader = theContextClassLoader; + } + + /** + * @return true if the codebase and the context classloader are equal + */ + public boolean equals (Object theOther) + { + if (theOther instanceof CacheKey) + { + CacheKey key = (CacheKey) theOther; + + return (equals (this.mCodeBase,key.mCodeBase) + && equals (this.mContextClassLoader, key.mContextClassLoader)); + } + return false; + } + + /** + * Test if the two objects are equal or both null. + * @param theOne + * @param theOther + * @return + */ + private boolean equals (Object theOne, Object theOther) + { + return theOne != null ? theOne.equals (theOther) : theOther == null; + } + + /** + * @return hashCode + */ + public int hashCode() + { + return ((mCodeBase != null ? mCodeBase.hashCode() : 0) + ^(mContextClassLoader != null ? mContextClassLoader.hashCode() : -1)); + } + + public String toString() + { + return "[" + mCodeBase + "," + mContextClassLoader + "]"; + } + + } + + private static RMIClassLoaderImpl instance = null; + + private static Map cacheLoaders; //map annotations to loaders + private static Map cacheAnnotations; //map loaders to annotations + //class loader for defaultAnnotation + private static MyClassLoader defaultClassLoader; + + //defaultAnnotation is got from system property + // "java.rmi.server.defaultAnnotation" + private static String defaultAnnotation; + + //URL object for defaultAnnotation + private static URL defaultCodebase; + + static + { + // 89 is a nice prime number for Hashtable initial capacity + cacheLoaders = new Hashtable (89); + cacheAnnotations = new Hashtable (89); + + defaultAnnotation = System.getProperty ("java.rmi.server.defaultAnnotation"); + + try + { + if (defaultAnnotation != null) + defaultCodebase = new URL (defaultAnnotation); + } + catch (Exception _) + { + defaultCodebase = null; + } + + if (defaultCodebase != null) + { + defaultClassLoader = new MyClassLoader (new URL[] { defaultCodebase }, null, + defaultAnnotation); + cacheLoaders.put (new CacheKey (defaultAnnotation, + Thread.currentThread().getContextClassLoader()), + defaultClassLoader); + } + } + + /** + * This is a singleton class and may only be instantiated once from within + * the {@link #getInstance} method. + */ + private RMIClassLoaderImpl() + { + } + + /** + * Returns an instance of RMIClassLoaderImpl. + * + * @return an instance of RMIClassLoaderImpl + */ + public static RMIClassLoaderSpi getInstance() + { + if (instance == null) + instance = new RMIClassLoaderImpl(); + return instance; + } + + public Class loadClass(String codeBase, String name, + ClassLoader defaultLoader) + throws MalformedURLException, ClassNotFoundException + { + ClassLoader loader; + if (defaultLoader == null) + loader = Thread.currentThread().getContextClassLoader(); + else + loader = defaultLoader; + + //try context class loader first + try + { + return Class.forName(name, false, loader); + } + catch (ClassNotFoundException e) + { + // class not found in the local classpath + } + + if (codeBase.length() == 0) //=="" + { + loader = defaultClassLoader; + } + else + { + loader = getClassLoader(codeBase); + } + + if (loader == null) + { + //do not throw NullPointerException + throw new ClassNotFoundException ("Could not find class (" + name + + ") at codebase (" + codeBase + ")"); + } + + return Class.forName(name, false, loader); + } + + public Class loadProxyClass(String codeBase, String[] interfaces, + ClassLoader defaultLoader) + throws MalformedURLException, ClassNotFoundException + { + // FIXME: Implement this. + return null; + } + + /** + * Gets a classloader for the given codebase and with the current + * context classloader as parent. + * + * @param codebase + * + * @return a classloader for the given codebase + * + * @throws MalformedURLException if the codebase contains a malformed URL + */ + public ClassLoader getClassLoader(String codebase) + throws MalformedURLException + { + ClassLoader loader; + CacheKey loaderKey = new CacheKey + (codebase, Thread.currentThread().getContextClassLoader()); + loader = (ClassLoader) cacheLoaders.get (loaderKey); + + if (loader == null) + { + //create an entry in cacheLoaders mapping a loader to codebases. + // codebases are separated by " " + StringTokenizer tok = new StringTokenizer (codebase, " "); + ArrayList urls = new ArrayList(); + + while (tok.hasMoreTokens()) + urls.add (new URL(tok.nextToken())); + + loader = new MyClassLoader((URL[]) urls.toArray(new URL [urls.size()]), + Thread.currentThread().getContextClassLoader(), + codebase); + cacheLoaders.put (loaderKey, loader); + } + + return loader; + } + + /** + * Returns a string representation of the network location where a remote + * endpoint can get the class-definition of the given class. + * + * @param cl + * + * @return a space seperated list of URLs where the class-definition + * of cl may be found + */ + public String getClassAnnotation(Class cl) + { + ClassLoader loader = cl.getClassLoader(); + + if (loader == null + || loader == ClassLoader.getSystemClassLoader()) + { + return System.getProperty ("java.rmi.server.codebase"); + } + + if (loader instanceof MyClassLoader) + { + return ((MyClassLoader) loader).getClassAnnotation(); + } + + String s = (String) cacheAnnotations.get (loader); + + if (s != null) + return s; + + if (loader instanceof URLClassLoader) + { + URL[] urls = ((URLClassLoader) loader).getURLs(); + + if (urls.length == 0) + return null; + + StringBuffer annotation = new StringBuffer (64 * urls.length); + + for (int i = 0; i < urls.length; i++) + { + annotation.append (urls [i].toExternalForm()); + annotation.append (' '); + } + + s = annotation.toString(); + cacheAnnotations.put (loader, s); + return s; + } + + return System.getProperty ("java.rmi.server.codebase"); + } +} diff --git a/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java b/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java index 888b30b..587d57f 100644 --- a/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java +++ b/libjava/classpath/gnu/java/rmi/server/RMIObjectInputStream.java @@ -102,7 +102,7 @@ protected Class resolveProxyClass(String intfs[]) protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException { if(valueClass.isPrimitive()){ if(valueClass == Boolean.TYPE) - return new Boolean(readBoolean()); + return Boolean.valueOf(readBoolean()); if(valueClass == Byte.TYPE) return new Byte(readByte()); if(valueClass == Character.TYPE) diff --git a/libjava/classpath/gnu/java/rmi/server/UnicastServer.java b/libjava/classpath/gnu/java/rmi/server/UnicastServer.java index 065ef8c..a8da725 100644 --- a/libjava/classpath/gnu/java/rmi/server/UnicastServer.java +++ b/libjava/classpath/gnu/java/rmi/server/UnicastServer.java @@ -51,13 +51,16 @@ import java.rmi.RemoteException; import java.rmi.ServerError; import java.rmi.server.ObjID; import java.rmi.server.UID; +import java.util.Collections; +import java.util.Map; import java.util.Hashtable; +import java.util.IdentityHashMap; public class UnicastServer implements ProtocolConstants { static private Hashtable objects = new Hashtable(); //mapping OBJID to server ref -static private Hashtable refcache = new Hashtable(); //mapping obj itself to server ref +static private Map refcache = Collections.synchronizedMap(new IdentityHashMap()); //mapping obj itself to server ref static private DGCImpl dgc; public static void exportObject(UnicastServerRef obj) { diff --git a/libjava/classpath/gnu/java/security/PolicyFile.java b/libjava/classpath/gnu/java/security/PolicyFile.java index c6a3061..3064f04 100644 --- a/libjava/classpath/gnu/java/security/PolicyFile.java +++ b/libjava/classpath/gnu/java/security/PolicyFile.java @@ -533,7 +533,7 @@ public final class PolicyFile extends Policy if (clazz == null) { currentPerms.add(new UnresolvedPermission(className, - null, null, (Certificate[]) currentCerts.toArray(new Certificate[0]))); + null, null, (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]))); continue; } try @@ -555,7 +555,7 @@ public final class PolicyFile extends Policy if (clazz == null) { currentPerms.add(new UnresolvedPermission(className, - target, null, (Certificate[]) currentCerts.toArray(new Certificate[0]))); + target, null, (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]))); continue; } try @@ -598,7 +598,7 @@ public final class PolicyFile extends Policy if (clazz == null) { currentPerms.add(new UnresolvedPermission(className, - target, action, (Certificate[]) currentCerts.toArray(new Certificate[0]))); + target, action, (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]))); continue; } else diff --git a/libjava/classpath/gnu/java/security/der/BitString.java b/libjava/classpath/gnu/java/security/der/BitString.java index b88b145..02b1c03 100644 --- a/libjava/classpath/gnu/java/security/der/BitString.java +++ b/libjava/classpath/gnu/java/security/der/BitString.java @@ -286,6 +286,19 @@ public class BitString implements Cloneable, Comparable return 0; // not reached. } + public int hashCode() + { + int result = 0; + for (int i = 0; i < bytes.length - 1; ++i) + result = result * 31 + bytes[i]; + if (bytes.length > 0) + { + int lastByte = bytes[bytes.length - 1] & ~ ((1 << ignoredBits) - 1); + result = result * 31 + lastByte; + } + return result; + } + public boolean equals(Object o) { if (!(o instanceof BitString)) diff --git a/libjava/classpath/gnu/java/security/der/DERReader.java b/libjava/classpath/gnu/java/security/der/DERReader.java index cb07f14..09ec1e2 100644 --- a/libjava/classpath/gnu/java/security/der/DERReader.java +++ b/libjava/classpath/gnu/java/security/der/DERReader.java @@ -389,7 +389,7 @@ public class DERReader implements DER Integer.parseInt(str.substring( 4, 6)), // day Integer.parseInt(str.substring( 6, 8)), // hour Integer.parseInt(str.substring( 8, 10))); // minute - if (date.length() == 12); + if (date.length() == 12) calendar.set(Calendar.SECOND, Integer.parseInt(str.substring(10, 12))); } diff --git a/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java b/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java new file mode 100644 index 0000000..591fc68 --- /dev/null +++ b/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyFactoryImpl.java @@ -0,0 +1,123 @@ +/* DiffieHellmanKeyFactoryImpl.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.provider; + +import gnu.javax.crypto.GnuDHPrivateKey; + +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.KeyFactorySpi; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; + +import javax.crypto.spec.DHParameterSpec; +import javax.crypto.spec.DHPrivateKeySpec; +import javax.crypto.spec.DHPublicKeySpec; + +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.interfaces.DHPublicKey; + +public class DiffieHellmanKeyFactoryImpl extends KeyFactorySpi +{ + protected PrivateKey engineGeneratePrivate (final KeySpec spec) + throws InvalidKeySpecException + { + if (spec instanceof DHPrivateKeySpec) + { + DHPrivateKeySpec dh = (DHPrivateKeySpec) spec; + return new GnuDHPrivateKey (dh.getX (), + new DHParameterSpec (dh.getP (), dh.getG ())); + } + throw new InvalidKeySpecException (); + } + + protected PublicKey engineGeneratePublic (final KeySpec spec) + throws InvalidKeySpecException + { + if (spec instanceof DHPublicKeySpec) + { + DHPublicKeySpec dh = (DHPublicKeySpec) spec; + return new GnuDHPublicKey (new DHParameterSpec (dh.getP (), dh.getG ()), + dh.getY(), null); + } + throw new InvalidKeySpecException (); + } + + protected KeySpec engineGetKeySpec (final Key key, final Class specClass) + throws InvalidKeySpecException + { + if (key instanceof DHPrivateKey) + { + if (DHPrivateKeySpec.class.isAssignableFrom (specClass)) + { + DHParameterSpec params = ((DHPrivateKey) key).getParams (); + return new DHPrivateKeySpec (((DHPrivateKey) key).getX (), + params.getP (), params.getG ()); + } + } + if (key instanceof DHPublicKey) + { + if (DHPublicKeySpec.class.isAssignableFrom (specClass)) + { + DHParameterSpec params = ((DHPublicKey) key).getParams (); + return new DHPublicKeySpec (((DHPublicKey) key).getY (), + params.getP (), params.getG ()); + } + } + throw new InvalidKeySpecException (); + } + + protected Key engineTranslateKey (final Key key) + throws InvalidKeyException + { + if (key instanceof DHPrivateKey) + { + return new GnuDHPrivateKey (((DHPrivateKey) key).getX (), + ((DHPrivateKey) key).getParams ()); + } + if (key instanceof DHPublicKey) + { + return new GnuDHPublicKey (((DHPublicKey) key).getParams (), + ((DHPublicKey) key).getY (), null); + } + throw new InvalidKeyException (); + } +} diff --git a/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java b/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java new file mode 100644 index 0000000..1b68d27 --- /dev/null +++ b/libjava/classpath/gnu/java/security/provider/DiffieHellmanKeyPairGeneratorImpl.java @@ -0,0 +1,86 @@ +/* DiffieHellmanKeyPairGeneratorImpl.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.security.provider; + +import gnu.javax.crypto.GnuDHPrivateKey; + +import java.math.BigInteger; + +import java.security.KeyPair; +import java.security.KeyPairGeneratorSpi; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.spec.DHParameterSpec; + +public class DiffieHellmanKeyPairGeneratorImpl extends KeyPairGeneratorSpi +{ + private SecureRandom random; + private DHParameterSpec params; + + public KeyPair generateKeyPair () + { + if (params == null || random == null) + throw new IllegalStateException ("not initialized"); + byte[] buf = new byte[(params.getP ().bitLength() >>> 3)]; + random.nextBytes (buf); + BigInteger x = new BigInteger (1, buf); + BigInteger y = params.getG ().modPow (x, params.getP ()); + GnuDHPublicKey pub = new GnuDHPublicKey (params, y, null); + GnuDHPrivateKey priv = new GnuDHPrivateKey (x, params); + + return new KeyPair (pub, priv); + } + + public void initialize (final int keysize, final SecureRandom random) + { + throw new UnsupportedOperationException ("key generation without parameters not supported"); + } + + public void initialize (final AlgorithmParameterSpec params, + final SecureRandom random) + { + if (!(params instanceof DHParameterSpec)) + throw new IllegalArgumentException ("expecting Diffie-Hellman parameters"); + this.params = (DHParameterSpec) params; + this.random = random; + if (this.random == null) + this.random = new SecureRandom (); + } +} diff --git a/libjava/classpath/gnu/java/security/provider/Gnu.java b/libjava/classpath/gnu/java/security/provider/Gnu.java index 849f63c..e553bbc 100644 --- a/libjava/classpath/gnu/java/security/provider/Gnu.java +++ b/libjava/classpath/gnu/java/security/provider/Gnu.java @@ -46,7 +46,7 @@ public final class Gnu extends Provider { public Gnu() { - super("GNU", 1.0, "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 Certificates and CRLs, PKIX certificate path validators, Collection cert stores"); + super("GNU", 1.0, "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 Certificates and CRLs, PKIX certificate path validators, Collection cert stores, Diffie-Hellman key agreement and key pair generator"); AccessController.doPrivileged (new PrivilegedAction() { @@ -100,10 +100,12 @@ public final class Gnu extends Provider // Key Pair Generator put("KeyPairGenerator.DSA", gnu.java.security.provider.DSAKeyPairGenerator.class.getName()); + put("KeyPairGenerator.DiffieHellman", DiffieHellmanKeyPairGeneratorImpl.class.getName ()); put("Alg.Alias.KeyPairGenerator.OID.1.2.840.10040.4.1", "DSA"); put("Alg.Alias.KeyPairGenerator.1.2.840.10040.4.1", "DSA"); put("Alg.Alias.KeyPairGenerator.1.3.14.3.2.12", "DSA"); + put("Alg.Alias.KeyPairGenerator.DH", "DiffieHellman"); // Key Factory put("KeyFactory.DSA", @@ -122,6 +124,9 @@ public final class Gnu extends Provider put("Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSA"); put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA"); + put("KeyFactory.DiffieHellman", DiffieHellmanKeyFactoryImpl.class.getName()); + put("Alg.Alias.KeyFactory.DH", "DiffieHellman"); + // Message Digests put("MessageDigest.SHA", gnu.java.security.provider.SHA.class.getName()); put("MessageDigest.MD5", gnu.java.security.provider.MD5.class.getName()); @@ -161,6 +166,14 @@ public final class Gnu extends Provider // CertStore put("CertStore.Collection", CollectionCertStoreImpl.class.getName()); + // KeyAgreement + put("KeyAgreement.DiffieHellman", gnu.javax.crypto.DiffieHellmanImpl.class.getName()); + put("Alg.Alias.KeyAgreement.DH", "DiffieHellman"); + + // Cipher + put("Cipher.RSAES-PKCS1-v1_5", gnu.javax.crypto.RSACipherImpl.class.getName()); + put("Alg.Alias.Cipher.RSA", "RSAES-PKCS1-v1_5"); + return null; } }); diff --git a/libjava/classpath/gnu/java/security/x509/ext/BasicConstraints.java b/libjava/classpath/gnu/java/security/x509/ext/BasicConstraints.java index 00f7a6e..d8f5c61 100644 --- a/libjava/classpath/gnu/java/security/x509/ext/BasicConstraints.java +++ b/libjava/classpath/gnu/java/security/x509/ext/BasicConstraints.java @@ -112,7 +112,7 @@ public class BasicConstraints extends Extension.Value if (encoded == null) { List bc = new ArrayList (2); - bc.add (new DERValue (DER.BOOLEAN, new Boolean (ca))); + bc.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (ca))); if (pathLenConstraint >= 0) bc.add (new DERValue (DER.INTEGER, BigInteger.valueOf ((long) pathLenConstraint))); diff --git a/libjava/classpath/gnu/java/security/x509/ext/Extension.java b/libjava/classpath/gnu/java/security/x509/ext/Extension.java index 5ca9ac3..97097a2 100644 --- a/libjava/classpath/gnu/java/security/x509/ext/Extension.java +++ b/libjava/classpath/gnu/java/security/x509/ext/Extension.java @@ -232,7 +232,7 @@ public class Extension { List ext = new ArrayList (3); ext.add (new DERValue (DER.OBJECT_IDENTIFIER, oid)); - ext.add (new DERValue (DER.BOOLEAN, new Boolean (critical))); + ext.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (critical))); ext.add (new DERValue (DER.OCTET_STRING, value.getEncoded())); return new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, ext); } @@ -274,6 +274,14 @@ public class Extension return (byte[]) encoded; } + public int hashCode() + { + int result = 0; + for (int i = 0; i < encoded.length; ++i) + result = result * 31 + encoded[i]; + return result; + } + public boolean equals(Object o) { if (!(o instanceof Value)) diff --git a/libjava/classpath/gnu/java/text/BaseBreakIterator.java b/libjava/classpath/gnu/java/text/BaseBreakIterator.java index c28a208..4afd8ae 100644 --- a/libjava/classpath/gnu/java/text/BaseBreakIterator.java +++ b/libjava/classpath/gnu/java/text/BaseBreakIterator.java @@ -68,12 +68,15 @@ public abstract class BaseBreakIterator extends BreakIterator return iter.getBeginIndex(); } + /** + * Return the first boundary after pos. + * This has the side effect of setting the index of the + * CharacterIterator. + */ public int following (int pos) { - int save = iter.getIndex(); iter.setIndex(pos); int r = next (); - iter.setIndex(save); return r; } diff --git a/libjava/classpath/gnu/javax/crypto/DiffieHellmanImpl.java b/libjava/classpath/gnu/javax/crypto/DiffieHellmanImpl.java new file mode 100644 index 0000000..4797af7 --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/DiffieHellmanImpl.java @@ -0,0 +1,159 @@ +/* DiffieHellmanImpl.java -- implementation of the Diffie-Hellman key agreement. + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto; + +import gnu.java.security.provider.GnuDHPublicKey; + +import java.math.BigInteger; + +import java.security.Key; +import java.security.InvalidKeyException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.KeyAgreementSpi; +import javax.crypto.SecretKey; +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.interfaces.DHPublicKey; +import javax.crypto.spec.DHParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * The Diffie-Hellman key agreement. + * + * @author Casey Marshall (csm@gnu.org) + */ +public final class DiffieHellmanImpl extends KeyAgreementSpi +{ + + /** The private key being used for this agreement. */ + private DHPrivateKey key; + + /** The current result. */ + private BigInteger result; + + /** True if the caller told us we are done. */ + private boolean last_phase_done; + + /** Trivial default constructor. */ + public DiffieHellmanImpl () + { + key = null; + result = null; + last_phase_done = false; + } + + // KeyAgreementSpi methods. + + protected Key engineDoPhase (final Key incoming, final boolean lastPhase) + throws InvalidKeyException + { + if (key == null) + throw new IllegalStateException ("not initialized"); + if (last_phase_done) + throw new IllegalStateException ("last phase already done"); + + if (!(incoming instanceof DHPublicKey)) + throw new InvalidKeyException ("expecting javax.crypto.interfaces.DHPublicKey"); + DHPublicKey pub = (DHPublicKey) incoming; + DHParameterSpec s1 = key.getParams(); + DHParameterSpec s2 = pub.getParams(); + if (!s1.getG().equals (s2.getG()) + || !s1.getP().equals (s2.getP()) + || s1.getL() != s2.getL()) + throw new InvalidKeyException ("supplied key is not compatible"); + + result = pub.getY().modPow (key.getX(), s1.getP()); + if (lastPhase) + { + last_phase_done = true; + return null; + } + + throw new IllegalArgumentException ("only supports two-party Diffie Hellman"); + } + + protected byte[] engineGenerateSecret () + { + if (result == null || !last_phase_done) + throw new IllegalStateException ("not finished"); + + byte[] buf = result.toByteArray (); + if (buf[0] == 0x00) + { + byte[] buf2 = new byte[buf.length - 1]; + System.arraycopy (buf, 1, buf2, 0, buf2.length); + buf = buf2; + } + return buf; + } + + protected int engineGenerateSecret (final byte[] secret, final int offset) + { + byte[] s = engineGenerateSecret(); + System.arraycopy (s, 0, secret, offset, s.length); + return s.length; + } + + protected SecretKey engineGenerateSecret (final String algorithm) + throws InvalidKeyException + { + byte[] s = engineGenerateSecret(); + return new SecretKeySpec (s, algorithm); + } + + protected void engineInit (final Key key, final SecureRandom random) + throws InvalidKeyException + { + if (!(key instanceof DHPrivateKey)) + throw new InvalidKeyException ("not a javax.crypto.interfaces.DHPrivateKey"); + this.key = (DHPrivateKey) key; + result = null; + last_phase_done = false; + } + + protected void engineInit (final Key key, final AlgorithmParameterSpec params, + final SecureRandom random) + throws InvalidKeyException + { + engineInit (key, random); + } +} diff --git a/libjava/classpath/gnu/javax/crypto/GnuDHPrivateKey.java b/libjava/classpath/gnu/javax/crypto/GnuDHPrivateKey.java new file mode 100644 index 0000000..f70cd7d --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/GnuDHPrivateKey.java @@ -0,0 +1,90 @@ +/* GnuDHPrivateKey.java -- a Diffie-Hellman private key. + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto; + +import java.math.BigInteger; + +import javax.crypto.interfaces.DHKey; +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.spec.DHParameterSpec; + +/** + * A Diffie-Hellman private key. + * + * @author Casey Marshall (csm@gnu.org) + */ +public class GnuDHPrivateKey implements DHPrivateKey +{ + + private final BigInteger x; + private final DHParameterSpec params; + + public GnuDHPrivateKey (final BigInteger x, final DHParameterSpec params) + { + x.getClass (); + params.getClass (); + this.x = x; + this.params = params; + } + + public DHParameterSpec getParams() + { + return params; + } + + public String getAlgorithm() + { + return "DiffieHellman"; + } + + public String getFormat () + { + return "NONE"; + } + + public byte[] getEncoded () + { + return null; + } + + public BigInteger getX () + { + return x; + } +} diff --git a/libjava/classpath/gnu/javax/crypto/RSACipherImpl.java b/libjava/classpath/gnu/javax/crypto/RSACipherImpl.java new file mode 100644 index 0000000..0a4c29d --- /dev/null +++ b/libjava/classpath/gnu/javax/crypto/RSACipherImpl.java @@ -0,0 +1,311 @@ +/* DiffieHellmanImpl.java -- implementation of the Diffie-Hellman key agreement. + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto; + +import gnu.classpath.ByteArray; +import gnu.classpath.debug.Component; +import gnu.classpath.debug.SystemLogger; + +import java.math.BigInteger; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import java.security.interfaces.RSAKey; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPrivateCrtKey; +import java.security.interfaces.RSAPublicKey; + +import java.security.spec.AlgorithmParameterSpec; + +import java.util.logging.Logger; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.CipherSpi; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.ShortBufferException; + +public class RSACipherImpl extends CipherSpi +{ + private static final Logger logger = SystemLogger.SYSTEM; + + private static final byte[] EMPTY = new byte[0]; + private int opmode = -1; + private RSAPrivateKey decipherKey = null; + private RSAPublicKey blindingKey = null; + private RSAPublicKey encipherKey = null; + private SecureRandom random = null; + private byte[] dataBuffer = null; + private int pos = 0; + + protected void engineSetMode (String mode) throws NoSuchAlgorithmException + { + throw new NoSuchAlgorithmException ("only one mode available"); + } + + protected void engineSetPadding (String pad) throws NoSuchPaddingException + { + throw new NoSuchPaddingException ("only one padding available"); + } + + protected int engineGetBlockSize () + { + return 1; + } + + protected int engineGetOutputSize (int inputLen) + { + int outputLen = 0; + if (decipherKey != null) + { + outputLen = (decipherKey.getModulus ().bitLength () + 7) / 8; + } + else if (encipherKey != null) + { + outputLen = (encipherKey.getModulus ().bitLength () + 7) / 8; + } + else + throw new IllegalStateException ("not initialized"); + if (inputLen > outputLen) + throw new IllegalArgumentException ("not configured to encode " + inputLen + + "bytes; at most " + outputLen); + return outputLen; + } + + protected int engineGetKeySize (final Key key) throws InvalidKeyException + { + if (!(key instanceof RSAKey)) + throw new InvalidKeyException ("not an RSA key"); + return ((RSAKey) key).getModulus ().bitLength (); + } + + protected byte[] engineGetIV () + { + return null; + } + + protected AlgorithmParameters engineGetParameters() + { + return null; + } + + protected void engineInit (int opmode, Key key, SecureRandom random) + throws InvalidKeyException + { + int outputLen = 0; + if (opmode == Cipher.ENCRYPT_MODE) + { + if (!(key instanceof RSAPublicKey)) + throw new InvalidKeyException ("expecting a RSAPublicKey"); + encipherKey = (RSAPublicKey) key; + decipherKey = null; + blindingKey = null; + outputLen = (encipherKey.getModulus ().bitLength () + 7) / 8; + } + else if (opmode == Cipher.DECRYPT_MODE) + { + if (key instanceof RSAPrivateKey) + { + decipherKey = (RSAPrivateKey) key; + encipherKey = null; + blindingKey = null; + outputLen = (decipherKey.getModulus ().bitLength () + 7) / 8; + } + else if (key instanceof RSAPublicKey) + { + if (decipherKey == null) + throw new IllegalStateException ("must configure decryption key first"); + if (!decipherKey.getModulus ().equals (((RSAPublicKey) key).getModulus ())) + throw new InvalidKeyException ("blinding key is not compatible"); + blindingKey = (RSAPublicKey) key; + return; + } + else + throw new InvalidKeyException ("expecting either an RSAPrivateKey or an RSAPublicKey (for blinding)"); + } + else + throw new IllegalArgumentException ("only encryption and decryption supported"); + this.random = random; + this.opmode = opmode; + pos = 0; + dataBuffer = new byte[outputLen]; + } + + protected void engineInit (int opmode, Key key, AlgorithmParameterSpec spec, SecureRandom random) + throws InvalidKeyException + { + engineInit (opmode, key, random); + } + + protected void engineInit (int opmode, Key key, AlgorithmParameters params, SecureRandom random) + throws InvalidKeyException + { + engineInit (opmode, key, random); + } + + protected byte[] engineUpdate (byte[] in, int offset, int length) + { + if (opmode != Cipher.ENCRYPT_MODE && opmode != Cipher.DECRYPT_MODE) + throw new IllegalStateException ("not initialized"); + System.arraycopy (in, offset, dataBuffer, pos, length); + pos += length; + return EMPTY; + } + + protected int engineUpdate (byte[] in, int offset, int length, byte[] out, int outOffset) + { + engineUpdate (in, offset, length); + return 0; + } + + protected byte[] engineDoFinal (byte[] in, int offset, int length) + throws IllegalBlockSizeException, BadPaddingException + { + engineUpdate (in, offset, length); + if (opmode == Cipher.DECRYPT_MODE) + { + if (pos < dataBuffer.length) + throw new IllegalBlockSizeException ("expecting exactly " + dataBuffer.length + " bytes"); + BigInteger enc = new BigInteger (1, dataBuffer); + byte[] dec = rsaDecrypt (enc); + logger.log (Component.CRYPTO, "RSA: decryption produced\n{0}", + new ByteArray (dec)); + if (dec[0] != 0x02) + throw new BadPaddingException ("expected padding type 2"); + int i; + for (i = 1; i < dec.length && dec[i] != 0x00; i++); + int len = dec.length - i; + byte[] result = new byte[len]; + System.arraycopy (dec, i, result, 0, len); + pos = 0; + return result; + } + else + { + offset = dataBuffer.length - pos; + if (offset < 3) + throw new IllegalBlockSizeException ("input is too large to encrypt"); + byte[] dec = new byte[dataBuffer.length]; + dec[0] = 0x02; + if (random == null) + random = new SecureRandom (); + byte[] pad = new byte[offset - 2]; + random.nextBytes (pad); + for (int i = 0; i < pad.length; i++) + if (pad[i] == 0) + pad[i] = 1; + System.arraycopy (pad, 0, dec, 1, pad.length); + dec[dec.length - pos] = 0x00; + System.arraycopy (dataBuffer, 0, dec, offset, pos); + logger.log (Component.CRYPTO, "RSA: produced padded plaintext\n{0}", + new ByteArray (dec)); + BigInteger x = new BigInteger (1, dec); + BigInteger y = x.modPow (encipherKey.getPublicExponent (), + encipherKey.getModulus ()); + byte[] enc = y.toByteArray (); + if (enc[0] == 0x00) + { + byte[] tmp = new byte[enc.length - 1]; + System.arraycopy (enc, 1, tmp, 0, tmp.length); + enc = tmp; + } + pos = 0; + return enc; + } + } + + protected int engineDoFinal (byte[] out, int offset) + throws ShortBufferException, IllegalBlockSizeException, BadPaddingException + { + byte[] result = engineDoFinal (EMPTY, 0, 0); + if (out.length - offset < result.length) + throw new ShortBufferException ("need " + result.length + ", have " + + (out.length - offset)); + System.arraycopy (result, 0, out, offset, result.length); + return result.length; + } + + protected int engineDoFinal (final byte[] input, final int offset, final int length, + final byte[] output, final int outputOffset) + throws ShortBufferException, IllegalBlockSizeException, BadPaddingException + { + byte[] result = engineDoFinal (input, offset, length); + if (output.length - outputOffset < result.length) + throw new ShortBufferException ("need " + result.length + ", have " + + (output.length - outputOffset)); + System.arraycopy (result, 0, output, outputOffset, result.length); + return result.length; + } + + /** + * Decrypts the ciphertext, employing RSA blinding if possible. + */ + private byte[] rsaDecrypt (BigInteger enc) + { + if (random == null) + random = new SecureRandom (); + BigInteger n = decipherKey.getModulus (); + BigInteger r = null; + BigInteger pubExp = null; + if (blindingKey != null) + pubExp = blindingKey.getPublicExponent (); + if (pubExp != null && (decipherKey instanceof RSAPrivateCrtKey)) + pubExp = ((RSAPrivateCrtKey) decipherKey).getPublicExponent (); + if (pubExp != null) + { + r = new BigInteger (n.bitLength () - 1, random); + enc = r.modPow (pubExp, n).multiply (enc).mod (n); + } + + BigInteger dec = enc.modPow (decipherKey.getPrivateExponent (), n); + + if (pubExp != null) + { + dec = dec.multiply (r.modInverse (n)).mod (n); + } + + return dec.toByteArray (); + } +} diff --git a/libjava/classpath/gnu/javax/imageio/bmp/BMPDecoder.java b/libjava/classpath/gnu/javax/imageio/bmp/BMPDecoder.java new file mode 100644 index 0000000..c4a582b --- /dev/null +++ b/libjava/classpath/gnu/javax/imageio/bmp/BMPDecoder.java @@ -0,0 +1,169 @@ +/* BMPDecoder.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.javax.imageio.bmp; + +import java.io.IOException; +import javax.imageio.stream.ImageInputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.awt.image.ColorModel; +import java.awt.image.IndexColorModel; +import java.awt.image.BufferedImage; + +public abstract class BMPDecoder { + + protected BMPInfoHeader infoHeader; + protected BMPFileHeader fileHeader; + protected long offset; + + public BMPDecoder(BMPFileHeader fh, BMPInfoHeader ih){ + fileHeader = fh; + infoHeader = ih; + offset = BMPFileHeader.SIZE + BMPInfoHeader.SIZE; + } + + /** + * Determines the coding type of the bitmap and returns the corresponding + * decoder. + */ + public static BMPDecoder getDecoder(BMPFileHeader fh, BMPInfoHeader ih){ + switch(ih.getCompression()){ + case BMPInfoHeader.BI_RGB: // uncompressed RGB + switch(ih.getBitCount()){ + case 32: + return new DecodeBF32(fh, ih, true); + + case 24: + return new DecodeRGB24(fh, ih); + + case 16: + return new DecodeBF16(fh, ih, true); + + case 8: + return new DecodeRGB8(fh, ih); + + case 4: + return new DecodeRGB4(fh, ih); + + case 1: + return new DecodeRGB1(fh, ih); + + default: + return null; + } + + case BMPInfoHeader.BI_RLE8: + return new DecodeRLE8(fh, ih); + + case BMPInfoHeader.BI_RLE4: + return new DecodeRLE4(fh, ih); + + case BMPInfoHeader.BI_BITFIELDS: + switch(ih.getBitCount()){ + case 16: + return new DecodeBF16(fh, ih, false); + + case 32: + return new DecodeBF32(fh, ih, false); + + default: + return null; + } + + default: + return null; + } + } + + /** + * The image decoder. + */ + public abstract BufferedImage decode(ImageInputStream in) + throws IOException, BMPException; + + /** + * Reads r,g,b bit masks from an inputstream + */ + protected int[] readBitMasks(ImageInputStream in) throws IOException { + int[] bitmasks = new int[3]; + byte[] temp = new byte[12]; + if(in.read(temp) != 12) + throw new IOException("Couldn't read bit masks."); + offset += 12; + + ByteBuffer buf = ByteBuffer.wrap(temp); + buf.order(ByteOrder.LITTLE_ENDIAN); + bitmasks[0] = buf.getInt(); + bitmasks[1] = buf.getInt(); + bitmasks[2] = buf.getInt(); + return bitmasks; + } + + /** + * Reads an N-color palette from an inputstream in RGBQUAD format and + * returns an equivalent ColorModel object + */ + protected IndexColorModel readPalette(ImageInputStream in) throws IOException { + int N = infoHeader.getNumberOfPaletteEntries(); + byte[] r = new byte[N]; + byte[] g = new byte[N]; + byte[] b = new byte[N]; + for(int i=0;i=0;y--){ + byte[] scanline = new byte[scansize]; + if(in.read(scanline) != scansize) + throw new IOException("Couldn't read image data."); + + for(int x=0;x=0;y--){ + byte[] scanline = new byte[scansize]; + if(in.read(scanline) != scansize) + throw new IOException("Couldn't read image data."); + + for(int x=0;x>3; + + int scansize = w>>3; + byte[] data = new byte[size]; + + for(int y=h-1;y>=0;y--){ + // Scanlines are padded to dword boundries + int readsize = scansize; + if((readsize & 3) != 0) readsize += (4 - (scansize & 3)); + + byte[] scanline = new byte[readsize]; + if(in.read(scanline) != readsize) + throw new IOException("Couldn't read image data."); + + for(int x=0;x=0;y--){ + byte[] scanline = new byte[scansize]; + if(in.read(scanline) != scansize) + throw new IOException("Couldn't read image data."); + + for(int x=0;x> 1; + + // Scanline padded to dword offsets + int wbytes = (w + (w & 1)) >> 1; + int scansize = ((wbytes & 3) != 0)? (wbytes + 4 - (wbytes&3)) : wbytes; + + byte[] data = new byte[wbytes*h]; + + for(int y=h-1;y>=0;y--){ + byte[] scanline = new byte[scansize]; + if(in.read(scanline) != scansize) + throw new IOException("Couldn't read image data."); + + for(int x=0;x=0;y--){ + byte[] scanline = new byte[scansize]; + if(in.read(scanline) != scansize) + throw new IOException("Couldn't read image data."); + + for(int x=0;x>1]; + int offIn = 0; + int x=0,y=0; + + // width in bytes + w += (w&1); + w = w >> 1; + + try { + while(((x>>1) + y*w) < w*h){ + if(in.read(cmd) != 2) + throw new IOException("Error reading compressed data."); + + if(cmd[0] == ESCAPE){ + switch(cmd[1]){ + case EOB: // end of bitmap + return data; + case EOL: // end of line + x = 0; + y++; + break; + case DELTA: // delta + if(in.read(cmd) != 2) + throw new IOException("Error reading compressed data."); + int dx = cmd[0] & (0xFF); + int dy = cmd[1] & (0xFF); + x += dx; + y += dy; + break; + + default: + // decode a literal run + int length = cmd[1] & (0xFF); + + // size of run, which is word aligned. + int bytesize = length; + bytesize += (bytesize & 1); + bytesize >>= 1; + bytesize += (bytesize & 1); + + byte[] run = new byte[bytesize]; + if(in.read(run) != bytesize) + throw new IOException("Error reading compressed data."); + + if((x&1) == 0){ + length += (length&1); + length >>= 1; + System.arraycopy(run, 0, data, ((x>>1) + w*(h-y-1)), + length); + } else { + for(int i=0;i>1) + w*(h-y-1)] + |= ((run[i>>1]&0xF0) >> 4); + else // copy low to high + data[((x+i)>>1) + w*(h-y-1)] + |= ((run[i>>1]&0x0F) << 4); + } + } + x += cmd[1] & (0xFF); + break; + } + } else { + // decode a byte run + int length = cmd[0] & (0xFF); + if((x&1) == 0){ + length += (length&1); + length >>= 1; + for(int i=0;i> 1)] = cmd[1]; + } else { + for(int i=0;i>1) + w*(h-y-1)] + |= ((cmd[1]&0xF0) >> 4); + else // copy low to high + data[((x+i)>>1) + w*(h-y-1)] + |= ((cmd[1]&0x0F) << 4); + } + } + x += cmd[0] & (0xFF); + } + } + return data; + } catch(ArrayIndexOutOfBoundsException e){ + throw new BMPException("Invalid RLE data."); + } + } +} + diff --git a/libjava/classpath/gnu/javax/imageio/bmp/DecodeRLE8.java b/libjava/classpath/gnu/javax/imageio/bmp/DecodeRLE8.java new file mode 100644 index 0000000..1d00e67 --- /dev/null +++ b/libjava/classpath/gnu/javax/imageio/bmp/DecodeRLE8.java @@ -0,0 +1,143 @@ +/* DecodeRLE8.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.javax.imageio.bmp; + +import java.io.IOException; +import javax.imageio.stream.ImageInputStream; +import java.awt.image.BufferedImage; +import java.awt.image.IndexColorModel; +import java.awt.image.Raster; +import java.awt.image.WritableRaster; +import java.awt.image.DataBuffer; +import java.awt.image.DataBufferByte; +import java.awt.image.SinglePixelPackedSampleModel; +import java.awt.image.SampleModel; +import java.awt.Dimension; + +public class DecodeRLE8 extends BMPDecoder { + + public DecodeRLE8(BMPFileHeader fh, BMPInfoHeader ih){ + super(fh, ih); + } + + /** + * RLE control codes + */ + private static final byte ESCAPE = (byte)0; + private static final byte EOL = (byte)0; // end of line + private static final byte EOB = (byte)1; // end of bitmap + private static final byte DELTA = (byte)2; // delta + + public BufferedImage decode(ImageInputStream in) throws IOException, BMPException { + IndexColorModel palette = readPalette(in); + skipToImage(in); + + Dimension d = infoHeader.getSize(); + int h = (int)d.getHeight(); + int w = (int)d.getWidth(); + + byte[] data = uncompress(w, h, in); + SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, + w, h, + new int[] {0xFF}); + DataBuffer db = new DataBufferByte(data, w*h, 0); + WritableRaster raster = Raster.createWritableRaster(sm, db, null); + + return new BufferedImage(palette, raster, false, null); + } + + private byte[] uncompress(int w, int h, ImageInputStream in) + throws BMPException, IOException { + byte[] cmd = new byte[2]; + byte[] data = new byte[w*h]; + int offIn = 0; + int x=0,y=0; + + try { + while((x + y*w) < w*h){ + if(in.read(cmd) != 2) + throw new IOException("Error reading compressed data."); + + if(cmd[0] == ESCAPE){ + switch(cmd[1]){ + case EOB: // end of bitmap + return data; + case EOL: // end of line + x = 0; + y++; + break; + case DELTA: // delta + if(in.read(cmd) != 2) + throw new IOException("Error reading compressed data."); + int dx = cmd[0] & (0xFF); + int dy = cmd[1] & (0xFF); + x += dx; + y += dy; + break; + + default: + // decode a literal run + int length = cmd[1] & (0xFF); + int copylength = length; + + // absolute mode must be word-aligned + length += (length & 1); + + byte[] run = new byte[length]; + if(in.read(run) != length) + throw new IOException("Error reading compressed data."); + + System.arraycopy(run, 0, data, (x+w*(h-y-1)), + copylength); + x += copylength; + break; + } + } else { + // decode a byte run + int length = cmd[0] & (0xFF); + for(int i=0;i + * Makes the remote object a_target ready for remote + * communication using the same communications runtime as for the passed + * a_source parameter. The a_target is connected to the same + * ORB (and, if applicable, to the same POA) as the a_source. + * + * @param a_target the target to connect to ORB, must be an instance of either + * {@link ObjectImpl} (Stubs and old-style ties) or {@link Servant} (POA-bases + * ties). + * + * @param a_source the object, providing the connection information, must be + * an instance of either {@link ObjectImpl} (Stubs and old-style ties) or + * {@link Servant} (POA-bases ties). + * + * @throws RemoteException if the target is already connected to another ORB. + */ + public void connect(Remote a_target, Remote a_source) throws RemoteException { - throw new Error("Not implemented for PortableRemoteObjectDelegateImpl"); - } - - public void exportObject(Remote obj) - throws RemoteException - { - PortableServer.exportObject(obj); + ORB orb = null; + POA poa = null; + boolean ok = false; + + try + { + if (a_source instanceof Servant) + { + Servant s = (Servant) a_source; + orb = s._orb(); + poa = s._poa(); + ok = true; + } + + if (!ok && a_source instanceof ObjectImpl) + { + ObjectImpl o = (ObjectImpl) a_source; + orb = o._orb(); + ok = true; + try + { + if (orb instanceof ORB_1_4) + { + // POA information available. + ORB_1_4 xorb = (ORB_1_4) orb; + Delegate d = o._get_delegate(); + + if (d instanceof LocalDelegate) + { + LocalDelegate l = (LocalDelegate) d; + poa = l.poa; + } + else if (d instanceof SimpleDelegate) + { + byte[] ior_key = ((SimpleDelegate) d).getIor().key; + AOM.Obj ref = xorb.rootPOA.findIorKey(ior_key); + if (ref != null) + poa = ref.poa; + } + } + } + catch (Exception ex) + { + // OK, POA info is not available, but as ORB is available, we + // will connect in a default way. + } + } + } + catch (Exception ex) + { + RuntimeException rex = new RuntimeException("Unable to get info from " + + a_source); + rex.initCause(ex); + throw rex; + } + + if (!ok && a_source instanceof Tie) + { + Tie t = (Tie) a_source; + orb = t.orb(); + poa = null; + ok = true; + } + + if (orb == null) + throw new RemoteException("Unable to determine ORB from " + a_source); + + if (a_target instanceof Stub) + { + StubDelegateImpl.connect((Stub) a_target, orb, poa); + } + else if (a_target instanceof Servant) + { + try + { + if (poa == null) + { + poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); + // Activate if not active. + if (poa.the_POAManager().get_state().value() == State._HOLDING) + poa.the_POAManager().activate(); + } + poa.servant_to_reference((Servant) a_target); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + else if (a_target instanceof org.omg.CORBA.Object) + { + // Connect as object. + orb.connect((org.omg.CORBA.Object) a_target); + } + else if (a_target instanceof Tie) + { + // We avoid calling this because it will aways connect to the root poa. + ((Tie) a_target).orb(orb); + } } + /** + * Narrow the given object to the instance of the given class. The currently + * supported narrowing types are: + * + * 1. Simple widening conversion.
+ * 2. ObjectImpl -> RMI interface.
+ * 3. ObjectImpl -> ObjectImpl.
+ * 4. Tie -> Remote (implementation)
+ * 5. Remote (implementation) -> Tie.
+ * + * The narrowing has sense only for derived classes. + */ public Object narrow(Object narrowFrom, Class narrowTo) throws ClassCastException { if (narrowTo == null) throw new ClassCastException("Can't narrow to null class"); - if (narrowFrom == null) + else if (narrowFrom == null) return null; + else + // Simple narrowing case. + if (narrowTo.isAssignableFrom(narrowFrom.getClass())) + return narrowFrom; + else if (narrowTo.isInterface() || narrowFrom instanceof ObjectImpl) + { + // Narrow CORBA object to passed interface. + + String interf = narrowTo.getName(); + String stubClassName; - Class fromClass = narrowFrom.getClass(); - Object result = null; - + stubClassName = getStubClassName(interf); + + try + { + // Replace the interface class by the stub class. + narrowTo = Util.loadClass(stubClassName, null, + narrowTo.getClassLoader()); + } + catch (ClassNotFoundException e) + { + ClassCastException cex = new ClassCastException("Class not found: " + + stubClassName); + cex.initCause(e); + throw cex; + } + } + else if (narrowFrom instanceof Tie) + { + // Try to substitute the return tie target as a return value. + Remote target = ((Tie) narrowFrom).getTarget(); + if (target != null && narrowTo.isAssignableFrom(target.getClass())) + return target; + } + + Object narrowed; try { - if (narrowTo.isAssignableFrom(fromClass)) - result = narrowFrom; - else - { - System.out.println("We still haven't implement this case: narrow " - + narrowFrom + " of type " + fromClass + " to " - + narrowTo); - Class[] cs = fromClass.getInterfaces(); - for (int i = 0; i < cs.length; i++) - System.out.println(cs[i]); - Exception e1 = new Exception(); - try - { - throw e1; - } - catch(Exception ee) - { - ee.printStackTrace(); - } - System.exit(2); - //throw new Error("We still haven't implement this case: narrow " - // + narrowFrom + " of type " + fromClass + " to " - // + narrowTo); - /* - ObjectImpl objimpl = (ObjectImpl)narrowFrom; - if(objimpl._is_a(PortableServer.getTypeName(narrowTo))) - result = PortableServer.getStubFromObjectImpl(objimpl, narrowTo); - */ - } - } - catch(Exception e) - { - result = null; - } - - if (result == null) - throw new ClassCastException("Can't narrow from " - + fromClass + " to " + narrowTo); - - return result; + narrowed = narrowTo.newInstance(); + } + catch (Exception e) + { + ClassCastException cex = new ClassCastException("Cannot instantiate " + + narrowTo.getName()); + cex.initCause(e); + throw cex; + } + + if (narrowed instanceof ObjectImpl) + { + // This also works for the instances of the Stub. + ObjectImpl target = (ObjectImpl) narrowed; + // Set the delegate, as is done in *Helper.narrow(..). + target._set_delegate(((ObjectImpl) narrowFrom)._get_delegate()); + } + else if (narrowed instanceof Tie && narrowFrom instanceof Remote) + { + // Try to set the narrowing object as a target for the Tie. + ((Tie) narrowed).setTarget((Remote) narrowFrom); + } + else + throw new ClassCastException("Narrowing of " + narrowFrom.getClass() + + " to " + narrowTo + " is either not possible or not implemented."); + + return narrowed; } - - public Remote toStub(Remote obj) + + /** + * Get the Stub class name for the name, representing the given interface. + */ + static String getStubClassName(String interf) + { + String stubClassName; + int p = interf.lastIndexOf('.'); + + if (p < 0) + // The interface is defined in the default package. + stubClassName = "_" + interf + "_Stub"; + else + stubClassName = interf.substring(0, p + 1) + "_" + + interf.substring(p + 1) + "_Stub"; + return stubClassName; + } + + /** + * Get stub for the given implementation, searching by class name pattern. The + * found stub must implement Remote for this method to succeed. + */ + public Remote toStub(Remote ObjImpl) throws NoSuchObjectException { - return PortableServer.toStub(obj); + String icn = ObjImpl.getClass().getName(); + if (!icn.endsWith("Impl")) + throw new BAD_PARAM("Invalid class name '" + icn + + "', must end with 'Impl'"); + + String sn = "_" + icn.substring(0, icn.length() - "Impl".length()) + + "_Stub"; + + Class stubClass; + Object o_stub; + + try + { + stubClass = RMIClassLoader.loadClass(sn); + o_stub = stubClass.newInstance(); + } + catch (Exception e) + { + NoSuchObjectException n = new NoSuchObjectException(sn); + n.initCause(e); + throw n; + } + + if (!Remote.class.isAssignableFrom(stubClass)) + throw new ClassCastException(stubClass.getName() + + " exists but cannot be returned as it does not inherit from " + + Remote.class.getName()); + + return (Remote) o_stub; } + /** + * If the object tie is no longer in use, disconnet it from the orb. + */ public void unexportObject(Remote obj) throws NoSuchObjectException { - PortableServer.unexportObject(obj); + Util.unexportObject(obj); + } + + /** + * Find or create a tie for this target and mark it as being used by the given + * object. + */ + public void exportObject(Remote obj) + throws RemoteException + { + if (obj instanceof Stub) + Util.registerTarget(StubDelegateImpl.getTieFromStub((Stub) obj), obj); + else if (obj instanceof Tie) + { + Tie t = (Tie) obj; + Util.registerTarget(t, null); + } } } diff --git a/libjava/classpath/gnu/javax/rmi/CORBA/RmiUtilities.java b/libjava/classpath/gnu/javax/rmi/CORBA/RmiUtilities.java new file mode 100644 index 0000000..91bfa37 --- /dev/null +++ b/libjava/classpath/gnu/javax/rmi/CORBA/RmiUtilities.java @@ -0,0 +1,946 @@ +/* RmiUtilities.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import gnu.CORBA.OrbFunctional; +import gnu.CORBA.Minor; +import gnu.CORBA.Unexpected; +import gnu.CORBA.CDR.Vio; +import gnu.CORBA.CDR.gnuRuntime; +import gnu.CORBA.CDR.gnuValueStream; +import gnu.CORBA.CDR.HeadlessInput; + +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.StringValueHelper; +import org.omg.CORBA.WStringValueHelper; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ValueBase; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAHelper; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.POAManagerPackage.State; +import org.omg.SendingContext.RunTime; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.rmi.Remote; +import java.security.MessageDigest; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Iterator; +import java.util.TreeSet; +import java.util.WeakHashMap; + +import javax.rmi.PortableRemoteObject; +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.Tie; +import javax.rmi.CORBA.Util; + +/** + * Defines methods that must be accessible in several derived classes. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class RmiUtilities +{ + /** + * The currently used RMI-IIOP version format. + */ + public static byte VERSION = 1; + + /** + * The non - writable class fields. + */ + static final int NON_WRITABLE = Modifier.STATIC | Modifier.TRANSIENT; + + /** + * The standard String repository Id. + */ + public static final String RMI_STRING_ID = StringValueHelper.id(); + + /** + * The standard Class repository Id. + */ + public static final String RMI_CLASS_ID = "RMI:javax.rmi.CORBA.ClassDesc:2BABDA04587ADCCC:CFBF02CF5294176B"; + + /** + * The standard string array repository Id. + */ + public static final String RMI_STRING_ARRAY_ID = "RMI:[Ljava.lang.String;:071DA8BE7F971128:A0F0A4387A3BB342"; + + /** + * An instance of the wide string value helper for writing strings. + */ + static WStringValueHelper wStringValueHelper = new WStringValueHelper(); + + /** + * Set of serializable classes that have .writeObject and .readObject defined. + * Contains weak references to ensure that the classes will be unloadable. + */ + WeakHashMap io_format = new WeakHashMap(); + + /** + * The standard IO format with no .writeObject and .readObject defined. + */ + static final Object STANDARD = new Object(); + + /** + * The custom IO format with .writeObject and .readObject defined, + * defaultWriteObject called. + */ + static final Object CUSTOM_DWO = new Object(); + + /** + * The custom IO format with .writeObject and .readObject defined, + * defaultWriteObject has not been called. + */ + static final Object CUSTOM_NO_DWO = new Object(); + + /** + * The arguments for readObject. + */ + static final Class[] READ_OBJECT_ARGS = new Class[] { ObjectInputStream.class }; + + /** + * The arguments for writeObject. + */ + static final Class[] WRITE_OBJECT_ARGS = new Class[] { ObjectOutputStream.class }; + + /** + * The undocumented field that is heading the Sun's object data, written with + * writeObject. + */ + static final int S_X = 16908034; + + /** + * Write all fields of the passed value. + */ + void writeFields(OutputStream an_output, Serializable object) + { + org.omg.CORBA_2_3.portable.OutputStream output = (org.omg.CORBA_2_3.portable.OutputStream) an_output; + try + { + Class o_class = object.getClass(); + Field[] fields = getWritableFields(o_class); + Field f; + + Class fc; + + for (int i = 0; i < fields.length; i++) + { + f = fields[i]; + fc = f.getType(); + Object v = f.get(object); + + if (fc == String.class) + { + output.write_value((Serializable) v, wStringValueHelper); + } + else if (fc == int.class) + output.write_long(((Integer) v).intValue()); + else if (fc == long.class) + output.write_longlong(((Number) v).longValue()); + else if (fc == double.class) + output.write_double(((Number) v).doubleValue()); + else if (fc == float.class) + output.write_float(((Number) v).floatValue()); + else if (fc == boolean.class) + output.write_boolean(((Boolean) v).booleanValue()); + else if (fc == short.class) + output.write_short(((Number) v).shortValue()); + else if (fc == byte.class) + output.write_octet(((Number) v).byteValue()); + else if (fc == char.class) + output.write_wchar(((Character) v).charValue()); + else + { + if (!fc.isInterface() && Remote.class.isAssignableFrom(fc)) + fc = getExportedInterface(fc); + writeMember(output, v, fc); + } + } + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("Cannot write " + object); + m.minor = Minor.ValueFields; + m.initCause(ex); + throw m; + } + } + + /** + * Write a memeber (field) of the data structure. + */ + void writeMember(org.omg.CORBA_2_3.portable.OutputStream output, + Object object, Class xClass) + { + if (output instanceof gnuValueStream) + { + gnuRuntime g = ((gnuValueStream) output).getRunTime(); + // Reset the target as we are already beyond the critical point + // where is must have the value being written. + if (g != null) + g.target = null; + } + if (Serializable.class.isAssignableFrom(xClass) + || Remote.class.isAssignableFrom(xClass)) + { + // Object handles null reference on its own. + if (org.omg.CORBA.Object.class.isAssignableFrom(xClass) + || Remote.class.isAssignableFrom(xClass)) + { + if (object == null) + output.write_Object(null); + else if (isTieRequired(object)) + exportTie(output, object, xClass); + else + writeValue(output, (Serializable) object); + } + else + output.write_value((Serializable) object, xClass); + } + else + { + MARSHAL m = new MARSHAL(xClass + " is not Serializable"); + m.minor = Minor.NonSerializable; + throw m; + } + } + + /** + * Check if the object must be wrapped into Tie, connected to the ORB and then + * the corresponding Stub be written. + */ + public boolean isTieRequired(Object object) + { + return object instanceof Remote && !(object instanceof Stub); + } + + /** + * Get the interface under that the class of this object must be exposed. The + * interface must be derived from Remote. + */ + Class getExportedInterface(Object object) + throws MARSHAL + { + Class fc = null; + Class[] interfaces = object.getClass().getInterfaces(); + for (int i = 0; i < interfaces.length; i++) + { + if (!Remote.class.equals(interfaces[i])) + if (Remote.class.isAssignableFrom(interfaces[i])) + { + if (fc == null) + fc = interfaces[i]; + else + { + MARSHAL m = new MARSHAL("Both " + fc + " and " + interfaces[i] + + " extends Remote"); + m.minor = Minor.TargetConversion; + throw m; + } + } + } + if (fc == null) + { + MARSHAL m = new MARSHAL(object.getClass() + + " does not implement any interface, derived from Remote"); + m.minor = Minor.TargetConversion; + throw m; + } + return fc; + } + + /** + * Get the persistent hash code for the given class, as defined by OMG + * standard. The inheritance, field names and types (but not the visibility) + * are taken into consideration as well as the presence of the writeObject + * method are taken into consideration. The class name and methods, if any, + * are not taken into consideration. + */ + public static long getHashCode(Class c) + { + Class of = c.isArray() ? c.getComponentType() : null; + if (c.isArray() + && ((!Serializable.class.isAssignableFrom(of) || of.isPrimitive() || Remote.class.isAssignableFrom(of)))) + return 0; + if (!Serializable.class.isAssignableFrom(c)) + return 0; + try + { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(bout); + + Class superClass = c.getSuperclass(); + if (superClass != null) + out.writeLong(getHashCode(superClass)); + + int writeObjectPresentCode; + try + { + c.getDeclaredMethod("writeObject", + new Class[] { ObjectOutputStream.class }); + writeObjectPresentCode = 2; // Exists. + } + catch (NoSuchMethodException e) + { + writeObjectPresentCode = 1; // Missing. + } + out.writeInt(writeObjectPresentCode); + + Field[] fields = c.getDeclaredFields(); + + Arrays.sort(fields, new Comparator() + { + public int compare(Object a, Object b) + { + Field fa = (Field) a; + Field fb = (Field) b; + return fa.getName().compareTo(fb.getName()); + } + }); + + Field f; + for (int i = 0; i < fields.length; i++) + { + f = fields[i]; + if ((f.getModifiers() & NON_WRITABLE) == 0) + { + out.writeUTF(f.getName()); + out.writeUTF(getDescriptor(f.getType())); + } + } + + out.flush(); + out.close(); + MessageDigest shaDigest; + try + { + shaDigest = MessageDigest.getInstance("SHA"); + } + catch (Exception ex) + { + throw new InternalError("SHA digesting algorithm is not available"); + } + + // Return the digest value to the calling + // method as an array of bytes. + byte[] sha = shaDigest.digest(bout.toByteArray()); + + long hash = 0; + for (int i = 0; i < Math.min(8, sha.length); i++) + { + hash += (long) (sha[i] & 255) << (i * 8); + } + return hash; + } + catch (IOException ioex) + { + throw new Unexpected(ioex); + } + } + + /** + * Converts to hexadecimal string, supplementing leading zeros. + */ + public static String toHex(long l) + { + StringBuffer b = new StringBuffer(); + b.append(Long.toHexString(l).toUpperCase()); + while (b.length() < 16) + b.insert(0, '0'); + return b.toString(); + } + + /** + * Returns a String representing the type-encoding of a class. + */ + static String getDescriptor(Class type) + { + if (type.equals(boolean.class)) + return "Z"; + if (type.equals(byte.class)) + return "B"; + if (type.equals(short.class)) + return "S"; + if (type.equals(char.class)) + return "C"; + if (type.equals(int.class)) + return "I"; + if (type.equals(long.class)) + return "J"; + if (type.equals(float.class)) + return "F"; + if (type.equals(double.class)) + return "D"; + if (type.equals(void.class)) + return "V"; + else if (type.isArray()) + { + StringBuffer l = new StringBuffer("["); + Class component = type.getComponentType(); + + while (component.isArray()) + { + l.append('['); + component = component.getComponentType(); + } + + l.append('L'); + l.append(component.getName().replace('.', '/')); + l.append(';'); + return l.toString(); + } + else + return "L" + type.getName().replace('.', '/') + ';'; + } + + public static Field[] getWritableFields(Class c) + { + TreeSet set = new TreeSet(new Comparator() + { + public int compare(Object a, Object b) + { + return ((Field) a).getName().compareTo(((Field) b).getName()); + } + }); + + while (!c.equals(Object.class)) + { + Field[] f = c.getDeclaredFields(); + for (int i = 0; i < f.length; i++) + { + if ((f[i].getModifiers() & NON_WRITABLE) == 0) + { + f[i].setAccessible(true); + set.add(f[i]); + } + } + c = c.getSuperclass(); + } + + Field[] r = new Field[set.size()]; + int p = 0; + Iterator it = set.iterator(); + while (it.hasNext()) + { + r[p++] = (Field) it.next(); + } + return r; + } + + /** + * The method is called for Remotes that are not Stubs. It is assumed, that + * the Remote is an implementation. The method searches for the suitable tie + * and, if found, exports it by creating and connecting the stub. Such export + * is supported since jdk 1.5. + */ + void exportTie(org.omg.CORBA_2_3.portable.OutputStream output, + Object implementation, Class interfaceClass) + { + try + { + // Remote, but non - stub class (implementation) + // must be replaced by stub. + Tie t = Util.getTie((Remote) implementation); + if (t instanceof Servant) + { + POA rootPoa = POAHelper.narrow(output.orb().resolve_initial_references( + "RootPOA")); + org.omg.CORBA.Object co = rootPoa.servant_to_reference((Servant) t); + Stub stub = (Stub) PortableRemoteObject.narrow(co, interfaceClass); + writeRemoteObject(output, stub); + + if (rootPoa.the_POAManager().get_state().value() == State._HOLDING) + rootPoa.the_POAManager().activate(); + } + else if (t instanceof org.omg.CORBA.Object) + { + org.omg.CORBA.Object co = (org.omg.CORBA.Object) t; + output.orb().connect(co); + + Stub stub = (Stub) PortableRemoteObject.narrow(co, interfaceClass); + writeRemoteObject(output, stub); + } + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("Unable to export " + implementation); + m.minor = Minor.TargetConversion; + m.initCause(ex); + throw m; + } + } + + /** + * Start the ORB, if it is not already runnning. + */ + void ensureOrbRunning(org.omg.CORBA_2_3.portable.OutputStream output) + { + // Ensure ORB is running. + if (output.orb() instanceof OrbFunctional) + { + ((OrbFunctional) output.orb()).ensureRunning(); + } + } + + /** + * Write data to the CORBA output stream. Writes the object contents only; the + * header must be already written. For object, containing objects, may be + * called recursively. + * + * @param an_output a stream to write to, must be + * org.omg.CORBA_2_3.portable.OutputStream + * @param object an object to write. + */ + public void writeRemoteObject(OutputStream an_output, Object object) + { + org.omg.CORBA_2_3.portable.OutputStream output = (org.omg.CORBA_2_3.portable.OutputStream) an_output; + + if (isTieRequired(object)) + { + // Find the interface that is implemented by the object and extends + // Remote. + Class fc = getExportedInterface(object); + exportTie(output, object, fc); + } + else if (object instanceof org.omg.CORBA.Object) + { + ensureOrbRunning(output); + an_output.write_Object((org.omg.CORBA.Object) object); + } + else if (object != null && object instanceof Serializable) + writeFields(an_output, (Serializable) object); + } + + /** + * Write data to the CORBA output stream. Writes the object contents only; the + * header must be already written. For object, containing objects, may be + * called recursively. + * + * @param an_output a stream to write to, must be + * org.omg.CORBA_2_3.portable.OutputStream + * @param object an object to write. + */ + public void writeValue(OutputStream an_output, Serializable object) + { + org.omg.CORBA_2_3.portable.OutputStream output = (org.omg.CORBA_2_3.portable.OutputStream) an_output; + + if (isTieRequired(object)) + { + // Find the interface that is implemented by the object and extends + // Remote. + Class fc = getExportedInterface(object); + exportTie(output, object, fc); + } + else if (object instanceof org.omg.CORBA.Object) + { + ensureOrbRunning(output); + an_output.write_Object((org.omg.CORBA.Object) object); + } + else if (object instanceof Externalizable) + { + try + { + ObjectOutputStream stream = new CorbaOutput(output, object, + this); + stream.write(VERSION); + ((Externalizable) object).writeExternal(stream); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("writeExternal failed"); + m.minor = Minor.Value; + m.initCause(ex); + throw m; + } + } + else if (object instanceof Serializable) + { + Object mode = null; + synchronized (io_format) + { + mode = io_format.get(object.getClass()); + if (mode == STANDARD) + { + writeFields(an_output, (Serializable) object); + return; + } + } + try + { + Method m = object.getClass().getDeclaredMethod("writeObject", + WRITE_OBJECT_ARGS); + m.setAccessible(true); // May be private. + + try + { + ObjectOutputStream stream = new CorbaOutput(output, + object, this); + + // Write version. + stream.write(VERSION); + + if (mode == CUSTOM_DWO) + // Write true, supposing that the defaultWriteObject + // has been called. + stream.write(1); + else if (mode == CUSTOM_NO_DWO) + // Write false (has not been called) + stream.write(0); + else + { + // Measure. + DefaultWriteObjectTester tester = new DefaultWriteObjectTester(object); + m.invoke(object, new Object[] { tester }); + + synchronized (io_format) + { + io_format.put(object.getClass(), + tester.dwo_called ? CUSTOM_DWO : CUSTOM_NO_DWO); + stream.write(tester.dwo_called ? 1 : 0); + } + } + + m.invoke(object, new Object[] { stream }); + stream.flush(); + } + catch (Exception ex) + { + MARSHAL mx = new MARSHAL(object.getClass().getName() + + ".writeObject failed"); + mx.initCause(ex); + throw mx; + } + } + catch (NoSuchMethodException e) + { + // Write in a standard way. + writeFields(an_output, (Serializable) object); + synchronized (io_format) + { + io_format.put(object.getClass(), STANDARD); + } + } + } + } + + /** + * Read data from the CDR input stream. Reads the object contents only; the + * header must be already read (the repository id or ids ara passed). For + * object, containing objects, may be called recursively. + * + * @param an_input the stream to read from, must be + * org.omg.CORBA_2_3.portable.InputStream + * @param object the instance of the object being read. + * @param id the repository Id from the stream in the case when single id was + * specified. + * @param ids the repository Ids from the stream in the case when multiple ids + * were specified. + * @param codebase the codebase, if it was included in the header of the value + * type. Null if not codebase was included. + * + * @return the object, extracted from the stream. + */ + /** + * Read value from the input stream in the case when the value is not + * Streamable or CustomMarshalled. + */ + public Serializable readValue(InputStream in, int offset, Class clz, + String repositoryID, RunTime sender) + { + if (in instanceof HeadlessInput) + ((HeadlessInput) in).subsequentCalls = true; + + gnuRuntime g; + Serializable object = null; + + try + { + g = (gnuRuntime) sender; + object = g.target; + } + catch (ClassCastException e) + { + // Working with the other CORBA implementation. + g = null; + } + + org.omg.CORBA_2_3.portable.InputStream input = (org.omg.CORBA_2_3.portable.InputStream) in; + + if (Remote.class.isAssignableFrom(clz) + || ValueBase.class.isAssignableFrom(clz)) + { + // Interface is narrowed into Stub. + if (clz.isInterface()) + try + { + clz = Util.loadClass( + PortableRemoteObjectDelegateImpl.getStubClassName(clz.getName()), + null, clz.getClassLoader()); + } + catch (ClassNotFoundException e) + { + MARSHAL m = new MARSHAL("Cannot get stub from interface " + + clz.getClass().getName()); + m.minor = Minor.TargetConversion; + m.initCause(e); + throw m; + } + + // Remote needs special handling. + if (ObjectImpl.class.isAssignableFrom(clz)) + { + // First read CORBA object reference. + Object ro = input.read_Object(); + + ObjectImpl obj = (ObjectImpl) ro; + if (obj == null) + return null; + + Delegate delegate = obj._get_delegate(); + object = instantiate(offset, clz, g); + ((ObjectImpl) object)._set_delegate(delegate); + } + // The object - specific data follows. + } + else if (org.omg.CORBA.Object.class.isAssignableFrom(clz)) + object = (Serializable) input.read_Object(); + + if (object == null) + object = instantiate(offset, clz, g); + + // The sentence below prevents attempt to read the internal fields of the + // ObjectImpl (or RMI Stub) that might follow the object definition. + // Sun's jre 1.5 does not write this information. The stubs, generated + // by rmic, does not contain such fields. + if (object instanceof ObjectImpl) + return object; + + if (object instanceof Externalizable) + { + try + { + CorbaInput stream = new CorbaInput(input, object, this, + offset, repositoryID, g); + + byte version = stream.readByte(); + if (version != 1) + throw new MARSHAL("Unsuported RMI-IIOP version " + version); + + ((Externalizable) object).readExternal(stream); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("readExternal failed"); + m.initCause(ex); + throw m; + } + } + else + { + Object mode = null; + synchronized (io_format) + { + mode = io_format.get(object.getClass()); + } + + if (mode == STANDARD) + { + readFields(offset, repositoryID, object, input, g); + } + else + { + try + { + Method m = object.getClass().getDeclaredMethod("readObject", + READ_OBJECT_ARGS); + try + { + m.setAccessible(true); // May be private. + + CorbaInput stream = new CorbaInput(input, + object, this, offset, repositoryID, g); + + byte version = stream.readByte(); + if (version != 1) + throw new MARSHAL("Unsuported RMI-IIOP version " + + version); + + // This would indicate is defaultWriteObject has been + // called, + // but the readObject method normally takes care about this. + boolean dwo = stream.readByte() != 0; + + m.invoke(object, new Object[] { stream }); + synchronized (io_format) + { + io_format.put(object.getClass(), dwo ? CUSTOM_DWO + : CUSTOM_NO_DWO); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + MARSHAL mx = new MARSHAL(object.getClass().getName() + + ".readObject failed"); + mx.initCause(ex); + throw mx; + } + } + catch (NoSuchMethodException e) + { + // Read in a standard way. + synchronized (io_format) + { + io_format.put(object.getClass(), STANDARD); + readFields(offset, repositoryID, object, input, g); + } + } + } + } + return object; + } + + /** + * Create an instance. + */ + Serializable instantiate(int offset, Class clz, gnuRuntime g) + throws MARSHAL + { + Serializable object; + try + { + object = (Serializable) Vio.instantiateAnyWay(clz); + g.objectWritten(object, offset); + } + catch (Exception e) + { + MARSHAL m = new MARSHAL("Unable to instantiate " + clz); + m.minor = Minor.Instantiation; + m.initCause(e); + throw m; + } + return object; + } + + /** + * Read fields of the object. + */ + void readFields(int offset, String repositoryID, Serializable object, + org.omg.CORBA_2_3.portable.InputStream input, gnuRuntime r) + throws MARSHAL + { + Field f = null; + Class o_class = object.getClass(); + + try + { + // The returned field array must already be in canonical order. + Field[] fields = getWritableFields(o_class); + + Class fc; + + for (int i = 0; i < fields.length; i++) + { + // Full value type header expected ahead. + if (input instanceof HeadlessInput) + ((HeadlessInput) input).subsequentCalls = true; + + f = fields[i]; + fc = f.getType(); + + Object v; + + if (fc == String.class) + { + v = input.read_value(wStringValueHelper); + } + else if (fc == int.class) + v = new Integer(input.read_long()); + else if (fc == long.class) + v = new Long(input.read_longlong()); + else if (fc == double.class) + v = new Double(input.read_double()); + else if (fc == float.class) + v = new Float(input.read_float()); + else if (fc == boolean.class) + v = input.read_boolean() ? Boolean.TRUE : Boolean.FALSE; + else if (fc == short.class) + v = new Short(input.read_short()); + else if (fc == byte.class) + v = new Byte(input.read_octet()); + else if (fc == char.class) + v = new Character(input.read_char()); + else if (org.omg.CORBA.Object.class.isAssignableFrom(fc) + || Remote.class.isAssignableFrom(fc)) + { + v = readValue(input, offset, fc, null, r); + } + else + { + v = Vio.read(input, fc); + } + + f.set(object, v); + } + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("Cannot read " + o_class.getName() + " field " + + f); + m.initCause(ex); + m.minor = Minor.ValueFields; + throw m; + } + } + +} diff --git a/libjava/classpath/gnu/javax/rmi/CORBA/StubDelegateImpl.java b/libjava/classpath/gnu/javax/rmi/CORBA/StubDelegateImpl.java index 998d59e..afc254d 100644 --- a/libjava/classpath/gnu/javax/rmi/CORBA/StubDelegateImpl.java +++ b/libjava/classpath/gnu/javax/rmi/CORBA/StubDelegateImpl.java @@ -1,5 +1,5 @@ -/* StubDelegateImpl.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. +/* StubDelegateImpl.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,67 +38,273 @@ exception statement from your version. */ package gnu.javax.rmi.CORBA; +import gnu.CORBA.ObjectCreator; +import gnu.CORBA.Unexpected; +import gnu.CORBA.CDR.BufferredCdrInput; +import gnu.CORBA.CDR.BufferedCdrOutput; + import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.rmi.Remote; import java.rmi.RemoteException; + +import javax.rmi.PortableRemoteObject; import javax.rmi.CORBA.Stub; import javax.rmi.CORBA.StubDelegate; +import javax.rmi.CORBA.Tie; +import javax.rmi.CORBA.Util; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAHelper; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.POAManagerPackage.State; + +/** + * The default stub delegate. + * + * @author Wu Gansha (gansha.wu@intel.com) (stub) + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) (implementation) + */ public class StubDelegateImpl implements StubDelegate { - - private int hashCode; - - public StubDelegateImpl(){ - hashCode = 0; + /** + *

+ * Finds the suitable {@link Tie} for this Stub and connects it to the given + * ORB. The tie is found by the name pattern. If the found tie is derived from + * {@link org.omg.CORBA.PortableServer.Servant}, it is connected to the root + * POA, also activating it (if not already active). + *

+ *

+ * This method does not allow to specify, to which POA the found Tie must be + * connected and requires to use the deprecated method {@link ORB#connect}. + * Many useful POA features remain unaccessible. A better alternative it might + * be to generate a {@link org.omg.CORBA.PortableServer.Servant} - derived Tie + * (-poa key in rmic) and connect it to POA in one of the many ways, listed in + * the description of the {@link orb.omg.PortableServer} package). The + * obtained CORBA object can be narrowed into stub using + * {@link PortableRemoteObject#narrow}. + *

+ * + * @param orb the ORB where the Stub must be connected. + * + * @throws RemoteException if the stub is already connected to some other ORB. + * If the stub is already connected to the ORB that was passed as parameter, + * the method returns without action. + * + * @throws BAD_PARAM if the name of this stub does not match the stub name + * pattern, "_*_Stub" or if the Tie class, "_*Impl_Tie", does not exists or an + * instance of this class cannot be instantiated. + */ + public void connect(Stub self, ORB orb) + throws RemoteException + { + connect(self, orb, null); } - // XXX javax.rmi.ORB -> org.omg.CORBA.ORB - public void connect(Stub self, javax.rmi.ORB orb) + + /** + * Connect when the POA is specified. + */ + public static void connect(Stub self, ORB orb, POA poa) throws RemoteException { - throw new Error("Not implemented for StubDelegate"); + ORB oorb = null; + try + { + Delegate d = self._get_delegate(); + if (d != null) + oorb = d.orb(self); + } + catch (Exception e) + { + // Failed to get Delegate or ORB. + // (possible ony for user-written Stubs). + } + + if (oorb != null) + { + if (!oorb.equals(orb)) + throw new RemoteException("Stub " + self + + " is connected to another ORB, " + orb); + else + return; + } + + Tie t = null; + if (self instanceof Remote) + t = Util.getTie((Remote) self); + + // Find by name pattern. + if (t == null) + t = getTieFromStub(self); + + Delegate delegate; + + if (t instanceof Servant) + { + try + { + if (poa == null) + { + poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); + // Activate if not active. + if (poa.the_POAManager().get_state().value() == State._HOLDING) + poa.the_POAManager().activate(); + } + + ObjectImpl obj = (ObjectImpl) poa.servant_to_reference((Servant) t); + delegate = obj._get_delegate(); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + else if (t instanceof ObjectImpl) + { + ObjectImpl o = (ObjectImpl) t; + orb.connect(o); + delegate = o._get_delegate(); + } + else + throw new BAD_PARAM("The Tie must be either Servant or ObjectImpl"); + + self._set_delegate(delegate); } - public boolean equals(Stub self, Object obj) + /** + * Locate a tie class, appropriate to the given stub class, by the name + * pattern. + */ + public static Tie getTieFromStub(java.lang.Object self) { - if(self == null || obj == null) - return self == obj; - if(!(obj instanceof Stub)) - return false; - return self.hashCode() == ((Stub)obj).hashCode(); + Tie t; + String sn = self.getClass().getName(); + if (!sn.endsWith("_Stub")) + throw new BAD_PARAM("The stub name, " + sn + + ", does not match _*_Stub pattern"); + + String tn = sn.substring(0, sn.length() - "_Stub".length()) + "Impl_Tie"; + Class tieClass = null; + + try + { + tieClass = ObjectCreator.forName(tn); + t = (Tie) tieClass.newInstance(); + if (self instanceof Remote) + Util.registerTarget(t, (Remote) self); + } + catch (Exception e) + { + BAD_PARAM bad = new BAD_PARAM("Unable to instantiate '" + tn + "'"); + bad.initCause(e); + throw bad; + } + return t; + } + + /** + * Compare two stubs for equality. + */ + public boolean equals(Stub self, java.lang.Object obj) + { + if (obj instanceof ObjectImpl) + { + ObjectImpl other = (ObjectImpl) obj; + Delegate d1 = other._get_delegate(); + Delegate d2 = self._get_delegate(); + if (d1 == null || d2 == null) + return d1 == d2; + else + return d1.equals(d2); + } + else return false; } + /** + * Get the hash code (from IOR reference). + */ public int hashCode(Stub self) { - //FIX ME - return hashCode; + Delegate d = self._get_delegate(); + return d==null?0:d.hashCode(); } + /** + * Returns the IOR reference of the connected ORB. + * + * @see ORB#object_to_string(org.omg.CORBA.Object); + */ public String toString(Stub self) { try { - return self._orb().object_to_string(self); + return self._orb().object_to_string(self); } - // XXX javax.rmi.BAD_OPERATION -> org.omg.CORBA.BAD_OPERATION - catch(javax.rmi.BAD_OPERATION bad_operation) + catch (Exception ex) { - return null; + return null; } } - public void readObject(Stub self, ObjectInputStream s) + /** + * This should never be called. The ORB must be supplied. + * + * @see #connect + */ + public void readObject(Stub self, ObjectInputStream input) throws IOException, ClassNotFoundException { - throw new Error("Not implemented for StubDelegate"); + readObject(self, input, null); } - public void writeObject(Stub self, ObjectOutputStream s) + /** + * Read as CORBA object when the ORB is known. The ORB must be set under the + * previous call of Stub.connect. The Stub is automatically registered with + * this ORB. + */ + public void readObject(Stub self, ObjectInputStream input, ORB orb) + throws IOException, ClassNotFoundException + { + byte[] b = (byte[]) input.readObject(); + BufferredCdrInput in = new BufferredCdrInput(b); + + if (orb != null) + in.setOrb(orb); + + ObjectImpl r = (ObjectImpl) in.read_Object(); + + self._set_delegate(r._get_delegate()); + } + + /** + * Write as CORBA object. The ORB is taken from the + * org.omg.CORBA.portable.Delegate. The Stub is automatically registered with + * this ORB (if not already done). + */ + public void writeObject(Stub self, ObjectOutputStream output) + throws IOException + { + writeObject(self, output, null); + } + + /** + * Write as CORBA object. The ORB must be either set under the previous call + * of Stub.connect or it is taken from the org.omg.CORBA.portable.Delegate. + * The Stub is automatically registered with this ORB (if not already done). + */ + public void writeObject(Stub self, ObjectOutputStream output, ORB orb) throws IOException { - throw new Error("Not implemented for StubDelegate"); + BufferedCdrOutput out = new BufferedCdrOutput(); + out.setOrb(orb == null ? self._orb() : orb); + out.write_Object(self); + + output.writeObject(out.buffer.toByteArray()); } - -} +} \ No newline at end of file diff --git a/libjava/classpath/gnu/javax/rmi/CORBA/TieTargetRecord.java b/libjava/classpath/gnu/javax/rmi/CORBA/TieTargetRecord.java new file mode 100644 index 0000000..70e751a --- /dev/null +++ b/libjava/classpath/gnu/javax/rmi/CORBA/TieTargetRecord.java @@ -0,0 +1,93 @@ +/* TieTargetRecord.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.util.HashSet; + +import javax.rmi.CORBA.Tie; + +/** + * Represents a Tie, connected to possibly multiple invocation targets. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class TieTargetRecord +{ + /** + * The associated Tie. + */ + public final Tie tie; + + /** + * The objects, exposing the tie. + */ + public HashSet targets = new HashSet(); + + /** + * Create a new record. + */ + public TieTargetRecord(Tie a_tie) + { + tie = a_tie; + } + + /** + * Add a target. + */ + public void add(Object target) + { + targets.add(target); + } + + /** + * Remove target. + */ + public void remove(Object target) + { + targets.remove(target); + } + + /** + * Return true if the tie has no associated invocation targets. + */ + public boolean unused() + { + return targets.size() == 0; + } +} diff --git a/libjava/classpath/gnu/javax/rmi/CORBA/UtilDelegateImpl.java b/libjava/classpath/gnu/javax/rmi/CORBA/UtilDelegateImpl.java index 7bed2aa..66a4e24 100644 --- a/libjava/classpath/gnu/javax/rmi/CORBA/UtilDelegateImpl.java +++ b/libjava/classpath/gnu/javax/rmi/CORBA/UtilDelegateImpl.java @@ -1,5 +1,5 @@ -/* UtilDelegateImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* UtilDelegateImpl.java -- + Copyright (C) 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,115 +38,717 @@ exception statement from your version. */ package gnu.javax.rmi.CORBA; +import gnu.CORBA.Minor; +import gnu.CORBA.ObjectCreator; +import gnu.CORBA.Poa.ORB_1_4; +import gnu.CORBA.Poa.AOM; +import gnu.CORBA.Poa.gnuPOA; +import gnu.CORBA.typecodes.GeneralTypeCode; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.COMM_FAILURE; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.INVALID_TRANSACTION; +import org.omg.CORBA.INV_OBJREF; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_PERMISSION; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.OMGVMCID; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TRANSACTION_REQUIRED; +import org.omg.CORBA.TRANSACTION_ROLLEDBACK; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.rmi.AccessException; +import java.rmi.MarshalException; +import java.rmi.NoSuchObjectException; import java.rmi.Remote; import java.rmi.RemoteException; +import java.rmi.ServerError; +import java.rmi.ServerException; +import java.rmi.UnexpectedException; import java.rmi.server.RMIClassLoader; -import java.net.MalformedURLException; -import java.io.*; -//import org.omg.CORBA.ORB; -//import org.omg.CORBA.SystemException; -//import org.omg.CORBA.portable.InputStream; -//import org.omg.CORBA.portable.OutputStream; -import javax.rmi.CORBA.*; +import java.util.Hashtable; + +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.Tie; +import javax.rmi.CORBA.Util; +import javax.rmi.CORBA.UtilDelegate; +import javax.rmi.CORBA.ValueHandler; +import javax.transaction.InvalidTransactionException; +import javax.transaction.TransactionRequiredException; +import javax.transaction.TransactionRolledbackException; +/** + * The implementation of UtilDelegate. + * + * @author Wu Gansha (gansha.wu@intel.com) (stub) + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) (implementation) + */ public class UtilDelegateImpl + extends RmiUtilities implements UtilDelegate { - // XXX javax.rmi.ORB -> org.omg.CORBA.ORB - public Object copyObject(Object obj, javax.rmi.ORB orb) + /** + * The instance of the value handler, requested once. + */ + static ValueHandler m_ValueHandler; + + /** + * The global map of all ties to they records. + */ + static Hashtable m_Ties = new Hashtable(); + + /** + * The global map of all targets to they records. + */ + static Hashtable m_Targets = new Hashtable(); + + /** + * The standard package for that the exception names are omitted. + */ + static final String m_StandardPackage = "org.omg.CORBA."; + + /** + * Make a deep copy of the object. + */ + public Object copyObject(Object obj, ORB orb) throws RemoteException { - throw new Error("Not implemented for UtilDelegate"); + // Strings are immutable, can be shared. + if (obj instanceof String) + return obj; + else if (obj == null) + return null; + else if (obj instanceof String[] || obj instanceof String[][] + || obj instanceof String[][][]) + { + // String arrays can be just cloned. + return ((Object[]) obj).clone(); + } + else if (obj instanceof Serializable) + { + try + { + ByteArrayOutputStream a = new ByteArrayOutputStream(); + ObjectOutputStream ou = new ObjectOutputStream(a); + ou.writeObject(obj); + ou.close(); + ObjectInputStream input = new ObjectInputStream( + new ByteArrayInputStream(a.toByteArray())); + return input.readObject(); + } + catch (Exception ex) + { + RemoteException rex = new RemoteException("Cannot copy " + obj); + throw rex; + } + } + else + return obj; } - // XXX javax.rmi.ORB -> org.omg.CORBA.ORB - public Object[] copyObjects(Object obj[], javax.rmi.ORB orb) + /** + * Make a deep copy of the object array. + */ + public Object[] copyObjects(Object[] obj, ORB orb) throws RemoteException { - throw new Error("Not implemented for UtilDelegate"); + return (Object[]) copyObject(obj, orb); } public ValueHandler createValueHandler() { - throw new Error("Not implemented for UtilDelegate"); + if (m_ValueHandler == null) + m_ValueHandler = (ValueHandler) DelegateFactory.getInstance(DelegateFactory.VALUEHANDLER); + return m_ValueHandler; } - + + /** + * Returns the codebase of the given class. + */ public String getCodebase(Class clz) { - throw new Error("Not implemented for UtilDelegate"); + return RMIClassLoader.getClassAnnotation(clz); } - + + /** + * Get the Tie that handles invocations on the given target. If the target/Tie + * pair has not been previously registered using {@link #registerTarget}, + * this method tries to locate a tie class by the name pattern. If this + * succeeds, the tie-target pair is also registered. + * + * @return the Tie. + */ public Tie getTie(Remote target) { - throw new Error("Not implemented for UtilDelegate"); + synchronized (m_Targets) + { + Tie tie; + TieTargetRecord r = ((TieTargetRecord) m_Targets.get(target)); + if (r == null) + { + if (target instanceof Stub) + { + tie = StubDelegateImpl.getTieFromStub(target); + registerTarget(tie, target); + } + else + { + // Treat this as implementation. + String tieClassName = getTieClassName(target.getClass().getName()); + try + { + Class tieClass = Util.loadClass(tieClassName, null, + target.getClass().getClassLoader()); + tie = (Tie) tieClass.newInstance(); + } + catch (Exception e) + { + MARSHAL m = new MARSHAL("Unable to instantiate " + + tieClassName); + m.minor = Minor.TargetConversion; + m.initCause(e); + throw m; + } + tie.setTarget(target); + registerTarget(tie, target); + } + } + else + tie = r.tie; + return tie; + } + } + + /** + * Get the Stub class name for the name, representing the given interface. + */ + private String getTieClassName(String interf) + { + String stubClassName; + int p = interf.lastIndexOf('.'); + + if (p < 0) + // The interface is defined in the default package. + stubClassName = "_" + interf + "_Tie"; + else + stubClassName = interf.substring(0, p + 1) + "_" + + interf.substring(p + 1) + "_Tie"; + return stubClassName; } - + + /** + * Register the Tie-target pair. As the Tie is a Servant, it can potentially + * be connected to several objects and hence may be registered with several + * targets. + */ + public void registerTarget(Tie tie, Remote target) + { + synchronized (m_Ties) + { + synchronized (m_Targets) + { + TieTargetRecord r = (TieTargetRecord) m_Ties.get(tie); + if (r == null) + { + // First registration for this Tie. + r = new TieTargetRecord(tie); + m_Ties.put(tie, r); + } + if (target != null) + { + r.add(target); + m_Targets.put(target, r); + } + } + } + } + + /** + * Deactivate the associated Tie, if it is found and is not connected to other + * registered targets. Independing from the POA policies, the transparent + * reactivation will not be possible. + */ + public void unexportObject(Remote target) + throws NoSuchObjectException + { + synchronized (m_Ties) + { + synchronized (m_Targets) + { + TieTargetRecord r = ((TieTargetRecord) m_Targets.get(target)); + if (r != null) + { + if (target instanceof org.omg.CORBA.Object) + r.tie.orb().disconnect((org.omg.CORBA.Object) target); + + if (r.unused()) + { + m_Targets.remove(target); + m_Ties.remove(r.tie); + r.tie.deactivate(); + + if (r.tie.orb() instanceof ORB_1_4) + { + // Standard case, when more deep cleanup is possible. + // Independing from the POA policies, the object will + // not be activable transparently. + ORB_1_4 orb = (ORB_1_4) r.tie.orb(); + + if (target instanceof org.omg.CORBA.Object) + { + AOM.Obj record = orb.rootPOA.findObject((org.omg.CORBA.Object) target); + + if (record != null && record.servant == r.tie + && record.poa instanceof gnuPOA) + { + ((gnuPOA) record.poa).aom.remove(record.key); + record.deactivated = true; + record.servant = null; + } + } + } + } + } + } + } + } + + /** + * Checks if the given stub is local. + * + * @param stub a stub to check. + * @return true if the stub is local, false otherwise. + */ public boolean isLocal(Stub stub) throws RemoteException { - throw new Error("Not implemented for UtilDelegate"); + try + { + return stub._is_local(); + } + catch (SystemException e) + { + RemoteException rex = new RemoteException(); + rex.initCause(e); + throw rex; + } } + /** + * Load the class. The method uses class loaders from the call stact first. If + * this fails, the further behaviour depends on the System Property + * "java.rmi.server.useCodebaseOnly" with default value "false". + * + *
    + *
  • Try the current thread context class loader first.
  • + *
  • If remoteCodebase is non-null and useCodebaseOnly is "false" then call + * java.rmi.server.RMIClassLoader.loadClass (remoteCodebase, className)
  • + *
  • If remoteCodebase is null or useCodebaseOnly is true then call + * java.rmi.server.RMIClassLoader.loadClass(className)
  • + *
  • If a class is still not successfully loaded and the loader != null + * then try Class.forName(className, false, loader).
  • + *
+ * + * @param className the name of the class. + * @param remoteCodebase the codebase. + * @param loader the class loader. + * @return the loaded class. + * + * @throws ClassNotFoundException of the class cannot be loaded. + */ public Class loadClass(String className, String remoteCodebase, - ClassLoader loader) + ClassLoader loader) throws ClassNotFoundException { - try{ - if (remoteCodebase == null) - return RMIClassLoader.loadClass(className); - else - return RMIClassLoader.loadClass(remoteCodebase, className); - } - catch (MalformedURLException e1) + if (loader == null) + loader = Thread.currentThread().getContextClassLoader(); + + String p_useCodebaseOnly = System.getProperty("java.rmi.server.useCodebaseOnly"); + + boolean useCodebaseOnly = p_useCodebaseOnly != null + && p_useCodebaseOnly.trim().equalsIgnoreCase("true"); + + try { - throw new ClassNotFoundException(className, e1); + if (remoteCodebase != null && !useCodebaseOnly) + return RMIClassLoader.loadClass(remoteCodebase, className); } - catch(ClassNotFoundException e2) + catch (Exception e) { - if(loader != null) - return loader.loadClass(className); - else - return null; + // This failed but try others. } + + try + { + if (remoteCodebase == null || useCodebaseOnly) + return RMIClassLoader.loadClass(remoteCodebase, className); + } + catch (Exception e) + { + // This failed but try others. + } + + if (loader != null) + return Class.forName(className, true, loader); + + throw new ClassNotFoundException(className + " at " + remoteCodebase); } + /** + * Converts CORBA {@link SystemException} into RMI {@link RemoteException}. + * The exception is converted as defined in the following table: + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
CORBA ExceptionRMI Exception
{@link COMM_FAILURE}{@link MarshalException}
{@link INV_OBJREF}{@link NoSuchObjectException}
{@link NO_PERMISSION}{@link AccessException}
{@link MARSHAL}{@link MarshalException}
{@link BAD_PARAM} (all other cases){@link MarshalException}
{@link OBJECT_NOT_EXIST}{@link NoSuchObjectException}
{@link TRANSACTION_REQUIRED}{@link TransactionRequiredException}
{@link TRANSACTION_ROLLEDBACK}{@link TransactionRolledbackException}
{@link INVALID_TRANSACTION}{@link InvalidTransactionException}
Any other {@link SystemException}{@link RemoteException}
+ *

+ *

+ * The exception detailed message always consists of + *

    + *
  1. the string "CORBA "
  2. + *
  3. the CORBA name of the system exception
  4. + *
  5. single space
  6. + *
  7. the hexadecimal value of the system exception's minor code, preceeded + * by 0x (higher bits contain {@link OMGVMCID}).
  8. + *
  9. single space
  10. + *
  11. the {@link CompletionStatus} of the exception: "Yes", "No" or "Maybe".
  12. + *
+ *

+ * For instance, if the Internet connection was refused: + *

+ *

+ *

+   * CORBA COMM_FAILURE 0x535500C9 No
+   * 

+ *

+ * The original CORBA exception is set as the cause of the RemoteException + * being created. + *

+ */ public RemoteException mapSystemException(SystemException ex) { - throw new Error("Not implemented for UtilDelegate"); + RemoteException rex; + + String status; + + switch (ex.completed.value()) + { + case CompletionStatus._COMPLETED_MAYBE: + status = "Maybe"; + break; + + case CompletionStatus._COMPLETED_NO: + status = "No"; + break; + + case CompletionStatus._COMPLETED_YES: + status = "Yes"; + break; + + default: + status = "Unexpected completion status " + ex.completed.value(); + } + + String name = ex.getClass().getName(); + + if (name.startsWith(m_StandardPackage)) + name = name.substring(m_StandardPackage.length()); + + String message = "CORBA " + name + " 0x" + Integer.toHexString(ex.minor) + + " " + status; + + if (ex instanceof COMM_FAILURE) + rex = new MarshalException(message, ex); + else if (ex instanceof INV_OBJREF) + { + rex = new NoSuchObjectException(message); + rex.detail = ex; + } + else if (ex instanceof NO_PERMISSION) + rex = new AccessException(message, ex); + else if (ex instanceof MARSHAL) + rex = new MarshalException(message, ex); + else if (ex instanceof BAD_PARAM) + rex = new MarshalException(message, ex); + else if (ex instanceof OBJECT_NOT_EXIST) + { + rex = new NoSuchObjectException(message); + rex.detail = ex; + } + else if (ex instanceof TRANSACTION_REQUIRED) + { + rex = new TransactionRequiredException(message); + rex.detail = ex; + } + else if (ex instanceof TRANSACTION_ROLLEDBACK) + { + rex = new TransactionRolledbackException(message); + rex.detail = ex; + } + else if (ex instanceof INVALID_TRANSACTION) + { + rex = new InvalidTransactionException(message); + rex.detail = ex; + } + else if (ex instanceof UNKNOWN) + rex = wrapException(ex.getCause()); + else + rex = new RemoteException(message, ex); + + return rex; } - public Object readAny(InputStream in) + /** + * Converts the exception that was thrown by the implementation method on a + * server side into RemoteException that can be transferred and re-thrown on a + * client side. The method converts exceptions as defined in the following + * table: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Exception to map (or subclass)Maps into
{@link Error}{@link ServerError}
{@link RemoteException}{@link ServerException}
{@link SystemException}wrapException({@link #mapSystemException})
{@link RuntimeException}rethrows
Any other exception{@link UnexpectedException}
+ * + * @param ex an exception that was thrown on a server side implementation. + * + * @return the corresponding RemoteException unless it is a RuntimeException. + * + * @throws RuntimeException the passed exception if it is an instance of + * RuntimeException. + * + * @specnote It is the same behavior, as in Suns implementations 1.4.0-1.5.0. + */ + public RemoteException wrapException(Throwable ex) + throws RuntimeException { - throw new Error("Not implemented for UtilDelegate"); + if (ex instanceof RuntimeException) + throw (RuntimeException) ex; + else if (ex instanceof Error) + return new ServerError(ex.getMessage(), (Error) ex); + else if (ex instanceof RemoteException) + return new ServerException(ex.getMessage(), (Exception) ex); + else if (ex instanceof SystemException) + return wrapException(mapSystemException((SystemException) ex)); + else + return new UnexpectedException("Unexpected", (Exception) ex); } - public void registerTarget(Tie tie, Remote target) + /** + * Write abstract interface to the CORBA output stream. The write format is + * matching CORBA abstract interface. Remotes and CORBA objects are written as + * objects, other classes are supposed to be value types and are written as + * such. {@link Remote}s are processed as defined in + * {@link #writeRemoteObject}. The written data contains discriminator, + * defining, that was written. Another method that writes the same content is + * {@link org.omg.CORBA_2_3.portable.OutputStream#write_abstract_interface(java.lang.Object)}. + * + * @param output a stream to write to, must be + * {@link org.omg.CORBA_2_3.portable.OutputStream}. + * + * @param object an object to write, must be CORBA object, Remote + */ + public void writeAbstractObject(OutputStream output, Object object) { - throw new Error("Not implemented for UtilDelegate"); + ((org.omg.CORBA_2_3.portable.OutputStream) output).write_abstract_interface(object); } - - public void unexportObject(Remote target) + + /** + * Write the passed java object to the output stream in the form of the CORBA + * {@link Any}. This includes creating an writing the object {@link TypeCode} + * first. Such Any can be later read by a non-RMI-IIOP CORBA implementation + * and manipulated, for instance, by means, provided in + * {@link org.omg.DynamicAny.DynAny}. Depending from the passed value, this + * method writes CORBA object, value type or value box. For value types Null + * is written with the abstract interface, its typecode having repository id + * "IDL:omg.org/CORBA/AbstractBase:1.0" and the empty string name. + * + * @param output the object to write. + * @param object the java object that must be written in the form of the CORBA + * {@link Any}. + */ + public void writeAny(OutputStream output, Object object) { - throw new Error("Not implemented for UtilDelegate"); + Any any = output.orb().create_any(); + if (object == null) + { + GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_abstract_interface); + t.setId("IDL:omg.org/CORBA/AbstractBase:1.0"); + t.setName(""); + any.type(t); + output.write_any(any); + return; + } + else if (object instanceof org.omg.CORBA.Object + && !(object instanceof Remote)) + { + // Write as value type. + boolean inserted = ObjectCreator.insertWithHelper(any, object); + if (inserted) + { + output.write_any(any); + return; + } + } + + if (object instanceof org.omg.CORBA.Object) + writeAnyAsRemote(output, object); + else if (object instanceof Serializable) + { + any.insert_Value((Serializable) object); + output.write_any(any); + } + else + { + MARSHAL m = new MARSHAL(object.getClass().getName() + + " must be CORBA Object, Remote or Serializable"); + m.minor = Minor.NonSerializable; + throw m; + } } - - public RemoteException wrapException(Throwable orig) + + /** + * Write Any as for remote object. + */ + void writeAnyAsRemote(OutputStream output, Object object) { - throw new Error("Not implemented for UtilDelegate"); + GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_objref); + t.setId(m_ValueHandler.getRMIRepositoryID(object.getClass())); + t.setName(object.getClass().getName()); + + // Writing Any (typecode, followed by value). + output.write_TypeCode(t); + writeRemoteObject(output, object); } - - public void writeAbstractObject(OutputStream out, Object obj) + + /** + * Get the class name excluding the package name. + */ + String getName(String n) { - throw new Error("Not implemented for UtilDelegate"); + int p = n.lastIndexOf('.'); + if (p < 0) + return n; + else + return n.substring(p + 1); } - - public void writeAny(OutputStream out, Object obj) + + /** + * Read Any from the input stream. + */ + public Object readAny(InputStream input) { - throw new Error("Not implemented for UtilDelegate"); + return input.read_any(); } - public void writeRemoteObject(OutputStream out, Object obj) + /** + * Write the passed parameter to the output stream as CORBA object. If the + * parameter is an instance of Remote and not an instance of Stub, the method + * instantiates a suitable Tie, connects the parameter to this Tie and then + * connects that Tie to the ORB that is requested from the output stream. Then + * the object reference is written to the stream, making remote invocations + * possible. This method is used in write_value(..) method group in + * {@link org.omg.CORBA_2_3.portable.OutputStream} and also may be called + * directly from generated Stubs and Ties. + * + * @param output a stream to write to, must be + * org.omg.CORBA_2_3.portable.OutputStream + * @param object an object to write. + */ + public void writeRemoteObject(OutputStream an_output, Object object) { - throw new Error("Not implemented for UtilDelegate"); + org.omg.CORBA_2_3.portable.OutputStream output = (org.omg.CORBA_2_3.portable.OutputStream) an_output; + if (object == null) + an_output.write_Object(null); + else if (isTieRequired(object)) + { + // Find the interface that is implemented by the object and extends + // Remote. + Class fc = getExportedInterface(object); + exportTie(output, object, fc); + } + else if (object instanceof org.omg.CORBA.Object) + { + ensureOrbRunning(output); + an_output.write_Object((org.omg.CORBA.Object) object); + } + else if (object != null && object instanceof Serializable) + writeFields(an_output, (Serializable) object); } -} + +} \ No newline at end of file diff --git a/libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerDelegateImpl.java b/libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerDelegateImpl.java new file mode 100644 index 0000000..dc3b3cd --- /dev/null +++ b/libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerDelegateImpl.java @@ -0,0 +1,163 @@ +/* ValueHandlerDelegateImpl.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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import gnu.CORBA.CDR.gnuRuntime; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CustomMarshal; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.SendingContext.RunTime; + +import java.io.Externalizable; +import java.io.ObjectStreamClass; +import java.io.Serializable; +import java.rmi.Remote; + +import javax.rmi.CORBA.ValueHandler; +import javax.rmi.CORBA.ValueHandlerMultiFormat; + +/** + * Implementation of the ValueHandler. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) (implementation) + */ +public class ValueHandlerDelegateImpl + extends RmiUtilities + implements ValueHandler, ValueHandlerMultiFormat +{ + /** + * Return the maximal supported stream format version. We currently + * support the version 1. + * + * TODO Support the version 2. + */ + public byte getMaximumStreamFormatVersion() + { + return 1; + } + + /** + * Write value using the given stream format version. + */ + public void writeValue(OutputStream output, Serializable value, byte version) + { + if (version!=1) + throw new BAD_PARAM("Unsupported stream format version "+version); + else + writeValue(output, value); + } + + /** + * This implementation associates RunTime with stream rather than with the + * value handler and this method is not used in the implementation. It is + * implemented just for the sake of compatibility. + */ + public RunTime getRunTimeCodeBase() + { + return new gnuRuntime(null, null); + } + + /** + * Checks if an instance of this class can write its fields itself. + */ + public boolean isCustomMarshaled(Class clz) + { + return CustomMarshal.class.isAssignableFrom(clz) + || Streamable.class.isAssignableFrom(clz); + } + + /** + * No replacement, returns the passed parameter. + */ + public Serializable writeReplace(Serializable value) + { + return value; + } + + /** + * Compute the repository id in the RMI hashed format. + */ + public String getRMIRepositoryID(final Class cx) + { + long hash = 0; + Class of = cx.isArray() ? cx.getComponentType() : null; + + if (cx.equals(String[].class)) + return RMI_STRING_ARRAY_ID; + else if (cx.equals(String.class)) + return RMI_STRING_ID; + else if (cx.equals(Class.class)) + return RMI_CLASS_ID; + else if (Remote.class.isAssignableFrom(cx) + || !Serializable.class.isAssignableFrom(cx) + || cx.isInterface() + || (cx.isArray() && (!Serializable.class.isAssignableFrom(of) + || of.isPrimitive() || Remote.class.isAssignableFrom(of))) + + ) + // Some classes that have zero hash code and serial no version id + // included. + return "RMI:" + cx.getName() + ":" + toHex(hash); + else if (cx.isArray()) + // Arrays have the same hashcode and uid as they components. + return "RMI:" + cx.getName() + ":" + toHex(getHashCode(of)) + ":" + + toHex(getSid(of)); + else + { + if (Externalizable.class.isAssignableFrom(cx)) + hash = 1; + else + hash = getHashCode(cx); + + return "RMI:" + cx.getName() + ":" + toHex(hash) + ":" + + toHex(getSid(cx)); + } + } + + /** + * Get the class serial version UID. + */ + long getSid(Class cx) + { + ObjectStreamClass osc = ObjectStreamClass.lookup(cx); + return osc.getSerialVersionUID(); + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerImpl.java b/libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerImpl.java deleted file mode 100644 index 906381f..0000000 --- a/libjava/classpath/gnu/javax/rmi/CORBA/ValueHandlerImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* ValueHandlerImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.rmi.CORBA; - -import java.io.*; -//import org.omg.CORBA.portable.InputStream; -//import org.omg.CORBA.portable.OutputStream; -//import org.omg.SendingContext.RunTime; -import javax.rmi.CORBA.ValueHandler; - -public class ValueHandlerImpl - implements ValueHandler -{ - - public String getRMIRepositoryID(Class clz) - { - throw new Error("Not implemented for ValueHandler"); - } - - // XXX - Runtime -> RunTime - public Runtime getRunTimeCodeBase() - { - throw new Error("Not implemented for ValueHandler"); - } - - public boolean isCustomMarshaled(Class clz) - { - throw new Error("Not implemented for ValueHandler"); - } - - // XXX - Runtime -> RunTime - public Serializable readValue(InputStream in, int offset, Class clz, String repositoryID, Runtime sender) - { - throw new Error("Not implemented for ValueHandler"); - } - - public Serializable writeReplace(Serializable value) - { - throw new Error("Not implemented for ValueHandler"); - } - - public void writeValue(OutputStream out, Serializable value) - { - throw new Error("Not implemented for ValueHandler"); - } -} diff --git a/libjava/classpath/gnu/javax/rmi/PortableServer.java b/libjava/classpath/gnu/javax/rmi/PortableServer.java deleted file mode 100644 index 4a84138..0000000 --- a/libjava/classpath/gnu/javax/rmi/PortableServer.java +++ /dev/null @@ -1,141 +0,0 @@ -/* PortableServer.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the 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, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.rmi; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.NoSuchObjectException; -import java.rmi.server.UnicastRemoteObject; -import java.rmi.server.RemoteStub; -import java.util.Hashtable; - -import javax.rmi.CORBA.*; - -/** - * The relationship of PortableRemoteObjectImpl with PortableServer - * is like that of UnicastRemoteObject with UnicastServer - */ -public class PortableServer -{ - static private Hashtable tieCache = new Hashtable(); - static private Object NO_TIE = new Object(); - - public static final synchronized void exportObject(Remote obj) - throws RemoteException - { - if(Util.getTie(obj) != null) - return; - - Tie tie = getTieFromRemote(obj); - if (tie != null) - Util.registerTarget(tie, obj); - else - UnicastRemoteObject.exportObject(obj); - } - - public static final void unexportObject(Remote obj) - { - if (Util.getTie(obj) != null) - Util.unexportObject(obj); - if (tieCache.get(obj) != null) //?? - tieCache.remove(obj); - } - - public static final Remote toStub(Remote obj) - throws NoSuchObjectException - { - if (obj instanceof Stub || obj instanceof RemoteStub) - return obj; - - Tie tie = Util.getTie(obj); - Remote stub; - if (tie != null) - stub = getStubFromTie(tie); - else - throw new NoSuchObjectException("Can't toStub an unexported object"); - return stub; - } - - static synchronized Tie getTieFromRemote(Remote obj) - { - Object tie = tieCache.get(obj); - if (tie == null) - { - tie = getTieFromClass(obj.getClass()); - if(tie == null) - tieCache.put(obj, NO_TIE); - else - tieCache.put(obj, tie); - } - else - if(tie != NO_TIE) - { - try - { - tie = obj.getClass().newInstance(); - } - catch(Exception _) - { - tie = null; - } - } - else //NO_TIE - tie = null; - - return (Tie)tie; - } - - static synchronized Tie getTieFromClass(Class clz) - { - //FIX ME - return null; - } - - public static Remote getStubFromTie(Tie tie) - { - //FIX ME - return null; - } - - public static Remote getStubFromObjectImpl(ObjectImpl objimpl, Class toClass) - { - //FIX ME - return null; - } -} diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java new file mode 100644 index 0000000..fb9e684 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java @@ -0,0 +1,130 @@ +/* AlsaInputPortDevice.java -- ALSA MIDI In Port + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.alsa; + +import javax.sound.midi.MidiUnavailableException; +import javax.sound.midi.Receiver; +import javax.sound.midi.Transmitter; +import gnu.javax.sound.midi.alsa.AlsaMidiDeviceProvider.AlsaPortInfo; + +/** + * ALSA MIDI In Port. + * + * @author Anthony Green (green@redhat.com) + * + */ +public class AlsaInputPortDevice extends AlsaPortDevice +{ + + AlsaInputPortDevice (AlsaPortInfo info) + { + super(info); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#open() + */ + public void open() throws MidiUnavailableException + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#close() + */ + public void close() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#isOpen() + */ + public boolean isOpen() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMicrosecondPosition() + */ + public long getMicrosecondPosition() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMaxReceivers() + */ + public int getMaxReceivers() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMaxTransmitters() + */ + public int getMaxTransmitters() + { + // TODO Auto-generated method stub + return 1; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getReceiver() + */ + public Receiver getReceiver() throws MidiUnavailableException + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getTransmitter() + */ + public Transmitter getTransmitter() throws MidiUnavailableException + { + return new AlsaTransmitter(); + } +} diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java new file mode 100644 index 0000000..4951be6 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java @@ -0,0 +1,216 @@ +/* AlsaMidiDeviceProvider.java -- The ALSA MIDI Device Provider + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.alsa; + +import gnu.classpath.Configuration; + +import javax.sound.midi.MidiDevice; +import javax.sound.midi.MidiDevice.Info; +import javax.sound.midi.spi.MidiDeviceProvider; + +/** + * Provide ALSA MIDI devices. + * + * @author Anthony Green (green@redhat.com) + * + */ +public class AlsaMidiDeviceProvider extends MidiDeviceProvider +{ + /** + * Abstract base for ALSA specific MIDI device info. + * + * @author Anthony Green (green@redhat.com) + * + */ + private static abstract class AlsaInfo extends Info + { + /** + * Create an ALSA specific MIDI device info object. + * + * @param name the device name + * @param description the device description + */ + public AlsaInfo(String name, String description) + { + super(name, "Alsa", description, "0.0"); + } + + abstract MidiDevice getDevice (); + } + + /** + * ALSA MIDI Port. + * + * @author Anthony Green (green@redhat.com) + * + */ + public static abstract class AlsaPortInfo extends AlsaInfo + { + long client; + long port; + + /** + * Create ALSA MIDI In Port. + * + * @param name the device name + * @param description the device description + * @param client the client ID + * @param port the port ID + */ + public AlsaPortInfo(String name, String description, long client, long port) + { + super(name, description); + this.client = client; + this.port = port; + } + } + + /** + * ALSA Sequencer specific info. + * + * @author Anthony Green (green@redhat.com) + * + */ + private static class AlsaSequencerInfo extends AlsaInfo + { + public AlsaSequencerInfo(String name, String description) + { + super(name, description); + } + + MidiDevice getDevice() + { + return AlsaMidiSequencerDevice.getInstance(); + } + } + + /** + * ALSA MIDI In Port. + * + * @author Anthony Green (green@redhat.com) + * + */ + private static class AlsaInputPortInfo extends AlsaPortInfo + { + public AlsaInputPortInfo(String name, String description, long client, long port) + { + super(name, description, client, port); + } + + MidiDevice getDevice() + { + return new AlsaInputPortDevice(this); + } + } + + /** + * ALSA MIDI Out Port. + * + * @author Anthony Green (green@redhat.com) + * + */ + private static class AlsaOutputPortInfo extends AlsaPortInfo + { + public AlsaOutputPortInfo(String name, String description, long client, long port) + { + super(name, description, client, port); + } + + MidiDevice getDevice() + { + return new AlsaOutputPortDevice(this); + } + } + + private static AlsaInfo[] infos; + + private static native AlsaInfo[] getInputDeviceInfo_(); + private static native AlsaInfo[] getOutputDeviceInfo_(); + + /** + * Initialize the ALSA system + */ + private static native void init_(); + + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("gjsmalsa"); + } + + init_(); + + AlsaInfo inputs[] = getInputDeviceInfo_(); + AlsaInfo outputs[] = getOutputDeviceInfo_(); + + infos = new AlsaInfo[inputs.length + outputs.length + 1]; + infos[0] = new AlsaSequencerInfo ("/dev/snd/seq", "ALSA Sequencer"); + System.arraycopy(inputs, 0, infos, 1, inputs.length); + System.arraycopy(outputs, 0, infos, 1 + inputs.length, outputs.length); + } + + public AlsaMidiDeviceProvider() + { + // Nothing. + } + + /* (non-Javadoc) + * @see javax.sound.midi.spi.MidiDeviceProvider#getDeviceInfo() + */ + public Info[] getDeviceInfo() + { + return infos; + } + + /* (non-Javadoc) + * @see javax.sound.midi.spi.MidiDeviceProvider#getDevice(javax.sound.midi.MidiDevice.Info) + */ + public MidiDevice getDevice(Info info) + { + for (int i = 0; i < infos.length; i++) + { + if (info.equals(infos[i])) + { + return infos[i].getDevice(); + } + } + throw new IllegalArgumentException("Don't recognize MIDI device " + info); + } +} diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java new file mode 100644 index 0000000..c91f1e3 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java @@ -0,0 +1,519 @@ +/* AlsaMidiSequencerDevice.java -- The ALSA MIDI sequencer device + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.alsa; + +import java.io.IOException; +import java.io.InputStream; + +import javax.sound.midi.ControllerEventListener; +import javax.sound.midi.InvalidMidiDataException; +import javax.sound.midi.MetaEventListener; +import javax.sound.midi.MidiUnavailableException; +import javax.sound.midi.Receiver; +import javax.sound.midi.Sequence; +import javax.sound.midi.Sequencer; +import javax.sound.midi.Track; +import javax.sound.midi.Transmitter; + +// FIXME: These next two imports are only required by gcj it seems. +import javax.sound.midi.MidiDevice.Info; +import javax.sound.midi.Sequencer.SyncMode; + +/** + * The ALSA MIDI sequencer device. This is a singleton device. + * + * @author green@redhat.com + * + */ +public class AlsaMidiSequencerDevice implements Sequencer +{ + // The singleton instance. + public final static AlsaMidiSequencerDevice instance = new AlsaMidiSequencerDevice(); + + // A pointer to a native chunk of memory + private long nativeState; + + // The sequence to process + private Sequence sequence; + + /** + * A private constructor. There should only be one instance of this + * device. + */ + private AlsaMidiSequencerDevice() + { + super(); + } + + /** + * Return the sequencer singleton. + * + * @return the sequencer singleton + */ + public static AlsaMidiSequencerDevice getInstance() + { + return instance; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setSequence(javax.sound.midi.Sequence) + */ + public void setSequence(Sequence seq) throws InvalidMidiDataException + { + sequence = seq; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setSequence(java.io.InputStream) + */ + public void setSequence(InputStream istream) throws IOException, + InvalidMidiDataException + { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getSequence() + */ + public Sequence getSequence() + { + return sequence; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#start() + */ + public void start() + { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#stop() + */ + public void stop() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#isRunning() + */ + public boolean isRunning() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#startRecording() + */ + public void startRecording() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#stopRecording() + */ + public void stopRecording() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#isRecording() + */ + public boolean isRecording() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#recordEnable(javax.sound.midi.Track, int) + */ + public void recordEnable(Track track, int channel) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#recordDisable(javax.sound.midi.Track) + */ + public void recordDisable(Track track) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTempoInBPM() + */ + public float getTempoInBPM() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setTempoInBPM(float) + */ + public void setTempoInBPM(float bpm) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTempoInMPQ() + */ + public float getTempoInMPQ() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setTempoInMPQ(float) + */ + public void setTempoInMPQ(float mpq) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setTempoFactor(float) + */ + public void setTempoFactor(float factor) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTempoFactor() + */ + public float getTempoFactor() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTickLength() + */ + public long getTickLength() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTickPosition() + */ + public long getTickPosition() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setTickPosition(long) + */ + public void setTickPosition(long tick) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getMicrosecondLength() + */ + public long getMicrosecondLength() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getMicrosecondPosition() + */ + public long getMicrosecondPosition() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setMicrosecondPosition(long) + */ + public void setMicrosecondPosition(long microsecond) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setMasterSyncMode(javax.sound.midi.Sequencer.SyncMode) + */ + public void setMasterSyncMode(SyncMode sync) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getMasterSyncMode() + */ + public SyncMode getMasterSyncMode() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getMasterSyncModes() + */ + public SyncMode[] getMasterSyncModes() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setSlaveSyncMode(javax.sound.midi.Sequencer.SyncMode) + */ + public void setSlaveSyncMode(SyncMode sync) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getSlaveSyncMode() + */ + public SyncMode getSlaveSyncMode() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getSlaveSyncModes() + */ + public SyncMode[] getSlaveSyncModes() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setTrackMute(int, boolean) + */ + public void setTrackMute(int track, boolean mute) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTrackMute(int) + */ + public boolean getTrackMute(int track) + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#setTrackSolo(int, boolean) + */ + public void setTrackSolo(int track, boolean solo) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#getTrackSolo(int) + */ + public boolean getTrackSolo(int track) + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#addMetaEventListener(javax.sound.midi.MetaEventListener) + */ + public boolean addMetaEventListener(MetaEventListener listener) + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#removeMetaEventListener(javax.sound.midi.MetaEventListener) + */ + public void removeMetaEventListener(MetaEventListener listener) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#addControllerEventListener(javax.sound.midi.ControllerEventListener, int[]) + */ + public int[] addControllerEventListener(ControllerEventListener listener, + int[] controllers) + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Sequencer#removeControllerEventListener(javax.sound.midi.ControllerEventListener, int[]) + */ + public int[] removeControllerEventListener(ControllerEventListener listener, + int[] controllers) + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getDeviceInfo() + */ + public Info getDeviceInfo() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#open() + */ + public void open() throws MidiUnavailableException + { + synchronized(this) + { + // Check to see if we're open already. + if (nativeState != 0) + return; + + nativeState = open_(); + } + } + + /** + * Allocate the native state object, and open the sequencer. + * + * @return a long representation of a pointer to the nativeState. + */ + private native long open_(); + + /** + * Close the sequencer and free the native state object. + */ + private native void close_(long nativeState); + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#close() + */ + public void close() + { + synchronized(this) + { + close_(nativeState); + nativeState = 0; + } + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#isOpen() + */ + public boolean isOpen() + { + synchronized(this) + { + return (nativeState != 0); + } + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMaxReceivers() + */ + public int getMaxReceivers() + { + return -1; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMaxTransmitters() + */ + public int getMaxTransmitters() + { + return -1; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getReceiver() + */ + public Receiver getReceiver() throws MidiUnavailableException + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getTransmitter() + */ + public Transmitter getTransmitter() throws MidiUnavailableException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java new file mode 100644 index 0000000..bc5a5593 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java @@ -0,0 +1,131 @@ +/* AlsaOutputPortDevice.java -- ALSA MIDI Output Port Device + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.alsa; + +import gnu.javax.sound.midi.alsa.AlsaMidiDeviceProvider.AlsaPortInfo; + +import javax.sound.midi.MidiUnavailableException; +import javax.sound.midi.Receiver; +import javax.sound.midi.Transmitter; + +/** + * ALSA MIDI Out Device + * + * @author Anthony Green (green@redhat.com) + * + */ +public class AlsaOutputPortDevice extends AlsaPortDevice +{ + AlsaOutputPortDevice (AlsaPortInfo info) + { + super(info); + } + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#open() + */ + public void open() throws MidiUnavailableException + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#close() + */ + public void close() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#isOpen() + */ + public boolean isOpen() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMicrosecondPosition() + */ + public long getMicrosecondPosition() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMaxReceivers() + */ + public int getMaxReceivers() + { + // TODO Auto-generated method stub + return 1; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMaxTransmitters() + */ + public int getMaxTransmitters() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getReceiver() + */ + public Receiver getReceiver() throws MidiUnavailableException + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getTransmitter() + */ + public Transmitter getTransmitter() throws MidiUnavailableException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java new file mode 100644 index 0000000..d666be1 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java @@ -0,0 +1,153 @@ +/* AlsaPortDevice.java -- ALSA MIDI Port Devices + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.alsa; + +import javax.sound.midi.MidiDevice; +import javax.sound.midi.MidiMessage; +import javax.sound.midi.Receiver; +import javax.sound.midi.Transmitter; + +// FIXME: This next import is only rquired for gcj it seems. +import javax.sound.midi.MidiDevice.Info; + +import gnu.javax.sound.midi.alsa.AlsaMidiDeviceProvider.AlsaPortInfo; + +/** + * ALSA Port Device + * + * @author Anthony Green (green@redhat.com) + * + */ +public abstract class AlsaPortDevice implements MidiDevice +{ + /** + * The ALSA Receiver class. + * + * @author Anthony Green (green@redhat.com) + * + */ + public class AlsaReceiver implements Receiver + { + /* (non-Javadoc) + * @see javax.sound.midi.Receiver#send(javax.sound.midi.MidiMessage, long) + */ + public void send(MidiMessage message, long timeStamp) + throws IllegalStateException + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Receiver#close() + */ + public void close() + { + // TODO Auto-generated method stub + + } + } + + AlsaMidiDeviceProvider.AlsaPortInfo info; + + public AlsaPortDevice (AlsaPortInfo info) + { + this.info = info; + } + + public Info getDeviceInfo() + { + return info; + } + + native void run_receiver_thread_ (long client, long port, Receiver receiver); + + /** + * The ALSA Transmitter class. + * + * @author Anthony Green (green@redhat.com) + * + */ + protected class AlsaTransmitter implements Transmitter, Runnable + { + private Receiver receiver; + + public void run() + { + run_receiver_thread_ (info.client, info.port, receiver); + } + + /* (non-Javadoc) + * @see javax.sound.midi.Transmitter#setReceiver(javax.sound.midi.Receiver) + */ + public void setReceiver(Receiver receiver) + { + synchronized (this) + { + this.receiver = receiver; + } + + // Create the processing thread + new Thread(this).start(); + } + + /* (non-Javadoc) + * @see javax.sound.midi.Transmitter#getReceiver() + */ + public Receiver getReceiver() + { + synchronized (this) + { + return receiver; + } + } + + /* (non-Javadoc) + * @see javax.sound.midi.Transmitter#close() + */ + public void close() + { + synchronized (this) + { + receiver.close(); + receiver = null; + } + } + } +} diff --git a/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java new file mode 100644 index 0000000..baf6173 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java @@ -0,0 +1,173 @@ +/* DSSIMidiDeviceProvider.java -- DSSI Device Provider + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.dssi; + +import java.util.ArrayList; +import java.util.List; +import java.io.File; +import java.io.FilenameFilter; + +import gnu.classpath.Configuration; +import gnu.javax.sound.midi.alsa.AlsaMidiSequencerDevice; + +import javax.sound.midi.MidiDevice; +import javax.sound.midi.MidiDevice.Info; +import javax.sound.midi.spi.MidiDeviceProvider; + +/** + * A DSSI MIDI device provider. + * + * DSSI (pronounced "dizzy") is an API for audio plugins, with particular + * application for software synthesis plugins with native user interfaces. + * + * Read about DSSI at http://dssi.sourceforge.net + * + * @author Anthony Green (green@redhat.com) + * + */ +public class DSSIMidiDeviceProvider extends MidiDeviceProvider +{ + /** + * The MidiDevice.Info specialized for DSSI synthesizers. + * + * @author Anthony Green (green@redhat.com) + * + */ + private static class DSSIInfo extends Info + { + String soname; + long index; + + public DSSIInfo(String name, String vendor, String description, + String version, String soname, long index) + { + super(name, vendor, description, version); + this.soname = soname; + this.index = index; + } + } + + static native long dlopen_(String soname); + static native void dlclose_(long sohandle); + static native long getDSSIHandle_(long sohandle, long index); + static native String getDSSIName_(long handle); + static native String getDSSICopyright_(long handle); + static native String getDSSIVendor_(long handle); + static native String getDSSILabel_(long handle); + + private static List examineLibrary(String soname) + { + List list = new ArrayList(); + long index = 0; + long handle; + + long sohandle = dlopen_(soname); + if (sohandle == 0) + return list; + do + { + handle = getDSSIHandle_(sohandle, index); + if (handle == 0) + break; + String name = getDSSILabel_(handle); + String copyright = getDSSICopyright_(handle); + String label = getDSSIName_(handle); + String vendor = getDSSIVendor_(handle); + list.add(new DSSIInfo(name, vendor, label, + "DSSI-1", soname, index)); + index++; + } while (true); + + // Close the library and free memory + dlclose_(sohandle); + + return list; + } + + private static DSSIInfo[] infos; + + static + { + if (Configuration.INIT_LOAD_LIBRARY) + System.loadLibrary("gjsmdssi"); + + File dssidir = new File("/usr/lib/dssi/"); + String sofiles[] = dssidir.list(new FilenameFilter() + { + public boolean accept(File dir, String n) + { + return n.endsWith(".so"); + } + }); + List ilist = new ArrayList(); + for (int i = 0; i < sofiles.length; i++) + ilist.addAll(examineLibrary(new File(dssidir, sofiles[i]).getAbsolutePath())); + infos = (DSSIInfo[]) ilist.toArray(new DSSIInfo[ilist.size()]); + } + + public DSSIMidiDeviceProvider() + { + // Empty. + } + + /* Return the Info array. + * @see javax.sound.midi.spi.MidiDeviceProvider#getDeviceInfo() + */ + public Info[] getDeviceInfo() + { + return infos; + } + + /* Get a MIDI Device for info. + * @see javax.sound.midi.spi.MidiDeviceProvider#getDevice(javax.sound.midi.MidiDevice.Info) + */ + public MidiDevice getDevice(Info info) + { + for (int i = 0; i < infos.length; i++) + { + if (info.equals(infos[i])) + { + return new DSSISynthesizer(infos[i], + infos[i].soname, + infos[i].index); + } + } + throw new IllegalArgumentException("Don't recognize MIDI device " + info); + } +} diff --git a/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java new file mode 100644 index 0000000..ca09b30 --- /dev/null +++ b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java @@ -0,0 +1,745 @@ +/* DSSISynthesizer.java -- DSSI Synthesizer Provider + 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 modify +it under the terms of the GNU General Public License as published by +the 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, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.sound.midi.dssi; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.sound.midi.Instrument; +import javax.sound.midi.MidiChannel; +import javax.sound.midi.MidiMessage; +import javax.sound.midi.MidiUnavailableException; +import javax.sound.midi.Patch; +import javax.sound.midi.Receiver; +import javax.sound.midi.ShortMessage; +import javax.sound.midi.Soundbank; +import javax.sound.midi.SoundbankResource; +import javax.sound.midi.Synthesizer; +import javax.sound.midi.Transmitter; +import javax.sound.midi.VoiceStatus; + +// FIXME: This import in only required for gcj it seems. +import javax.sound.midi.MidiDevice.Info; + +/** + * DSSI soft-synth support. + * + * All DSSI soft-synths are expected to be installed in /usr/lib/dssi. + * + * @author Anthony Green (green@redhat.com) + * + */ +public class DSSISynthesizer implements Synthesizer +{ + /** + * The DSSI Instrument class. + * + * @author Anthony Green (green@redhat.com) + * + */ + class DSSIInstrument extends Instrument + { + DSSIInstrument (Soundbank soundbank, Patch patch, String name) + { + super (soundbank, patch, name, null); + } + + /* @see javax.sound.midi.SoundbankResource#getData() + */ + public Object getData() + { + return null; + } + + } + +/** + * DSSISoundbank holds all instruments. + * + * @author Anthony Green (green@redhat.com) + * + */ + class DSSISoundbank implements Soundbank + { + private String name; + private String description; + private List instruments = new ArrayList(); + private List resources = new ArrayList(); + private String vendor; + private String version; + + public DSSISoundbank(String name, String description, String vendor, String version) + { + this.name = name; + this.description = description; + this.vendor = vendor; + this.version = version; + } + + void add(Instrument instrument) + { + instruments.add(instrument); + } + + /* @see javax.sound.midi.Soundbank#getName() + */ + public String getName() + { + return name; + } + + /* @see javax.sound.midi.Soundbank#getVersion() + */ + public String getVersion() + { + return version; + } + + /* @see javax.sound.midi.Soundbank#getVendor() + */ + public String getVendor() + { + return vendor; + } + + /* @see javax.sound.midi.Soundbank#getDescription() + */ + public String getDescription() + { + return description; + } + + /* @see javax.sound.midi.Soundbank#getResources() + */ + public SoundbankResource[] getResources() + { + return (SoundbankResource[]) + resources.toArray(new SoundbankResource[resources.size()]); + } + + /* @see javax.sound.midi.Soundbank#getInstruments() + */ + public Instrument[] getInstruments() + { + return (Instrument[]) + instruments.toArray(new Instrument[instruments.size()]); + } + + /* @see javax.sound.midi.Soundbank#getInstrument(javax.sound.midi.Patch) + */ + public Instrument getInstrument(Patch patch) + { + Iterator itr = instruments.iterator(); + + while (itr.hasNext()) + { + Instrument i = (Instrument) itr.next(); + if (i.getPatch().equals(patch)) + return i; + } + + return null; + } + } + +/** + * The Receiver class receives all MIDI messages from a connected + * Transmitter. + * + * @author Anthony Green (green@redhat.com) + * + */ + class DSSIReceiver implements Receiver + { + /* (non-Javadoc) + * @see javax.sound.midi.Receiver#send(javax.sound.midi.MidiMessage, long) + */ + public void send(MidiMessage message, long timeStamp) + throws IllegalStateException + { + if (message instanceof ShortMessage) + { + ShortMessage smessage = (ShortMessage) message; + + switch (message.getStatus()) + { + case ShortMessage.NOTE_ON: + int velocity = smessage.getData2(); + if (velocity > 0) + channels[smessage.getChannel()].noteOn(smessage.getData1(), + smessage.getData2()); + else + channels[smessage.getChannel()].noteOff(smessage.getData1()); + break; + case ShortMessage.CONTROL_CHANGE: + channels[smessage.getChannel()].controlChange(smessage.getData1(), + smessage.getData2()); + break; + default: + System.out.println ("Unhandled message: " + message.getStatus()); + break; + } + } + } + + /* (non-Javadoc) + * @see javax.sound.midi.Receiver#close() + */ + public void close() + { + // TODO Auto-generated method stub + } + + } + + static native void noteOn_(long handle, int channel, int noteNumber, int velocity); + static native void noteOff_(long handle, int channel, int noteNumber, int velocity); + static native void setPolyPressure_(long handle, int channel, int noteNumber, int pressure); + static native int getPolyPressure_(long handle, int channel, int noteNumber); + static native void controlChange_(long handle, int channel, int control, int value); + static native void open_(long handle); + static native void close_(long handle); + static native String getProgramName_(long handle, int index); + static native int getProgramBank_(long handle, int index); + static native int getProgramProgram_(long handle, int index); + static native void selectProgram_(long handle, int bank, int program); + + /** + * @author Anthony Green (green@redhat.com) + * + */ + public class DSSIMidiChannel implements MidiChannel + { + int channel = 0; + + /** + * Default contructor. + */ + public DSSIMidiChannel(int channel) + { + super(); + this.channel = channel; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#noteOn(int, int) + */ + public void noteOn(int noteNumber, int velocity) + { + noteOn_(sohandle, channel, noteNumber, velocity); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#noteOff(int, int) + */ + public void noteOff(int noteNumber, int velocity) + { + noteOff_(sohandle, channel, noteNumber, velocity); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#noteOff(int) + */ + public void noteOff(int noteNumber) + { + noteOff_(sohandle, channel, noteNumber, -1); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setPolyPressure(int, int) + */ + public void setPolyPressure(int noteNumber, int pressure) + { + setPolyPressure_(sohandle, channel, noteNumber, pressure); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getPolyPressure(int) + */ + public int getPolyPressure(int noteNumber) + { + return getPolyPressure_(sohandle, channel, noteNumber); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setChannelPressure(int) + */ + public void setChannelPressure(int pressure) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getChannelPressure() + */ + public int getChannelPressure() + { + // TODO Auto-generated method stub + return 0; + } + + /* @see javax.sound.midi.MidiChannel#controlChange(int, int) */ + public void controlChange(int controller, int value) + { + controlChange_(sohandle, channel, controller, value); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getController(int) + */ + public int getController(int controller) + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#programChange(int) + */ + public void programChange(int program) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#programChange(int, int) + */ + public void programChange(int bank, int program) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getProgram() + */ + public int getProgram() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setPitchBend(int) + */ + public void setPitchBend(int bend) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getPitchBend() + */ + public int getPitchBend() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#resetAllControllers() + */ + public void resetAllControllers() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#allNotesOff() + */ + public void allNotesOff() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#allSoundOff() + */ + public void allSoundOff() + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#localControl(boolean) + */ + public boolean localControl(boolean on) + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setMono(boolean) + */ + public void setMono(boolean on) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getMono() + */ + public boolean getMono() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setOmni(boolean) + */ + public void setOmni(boolean on) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getOmni() + */ + public boolean getOmni() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setMute(boolean) + */ + public void setMute(boolean mute) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getMute() + */ + public boolean getMute() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#setSolo(boolean) + */ + public void setSolo(boolean solo) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiChannel#getSolo() + */ + public boolean getSolo() + { + // TODO Auto-generated method stub + return false; + } + + } + + long sohandle; + long handle; + private Info info; + + MidiChannel channels[] = new MidiChannel[16]; + + // The list of known soundbanks, and the default one. + List soundbanks = new ArrayList(); + DSSISoundbank defaultSoundbank; + + /** + * Create a DSSI Synthesizer. + * + * @param info the DSSIInfo for this soft-synth + * @param soname the name of the .so file for this DSSI synth + * @param index the DSSI index for this soft-synth + */ + public DSSISynthesizer(Info info, String soname, long index) + { + super(); + this.info = info; + sohandle = DSSIMidiDeviceProvider.dlopen_(soname); + handle = DSSIMidiDeviceProvider.getDSSIHandle_(sohandle, index); + channels[0] = new DSSIMidiChannel(0); + defaultSoundbank = new DSSISoundbank("name", "description", + "vendor", "version"); + soundbanks.add(defaultSoundbank); + + int i = 0; + String name; + do + { + name = getProgramName_(sohandle, i); + if (name != null) + { + defaultSoundbank. + add(new DSSIInstrument(defaultSoundbank, + new Patch(getProgramBank_(sohandle, i), + getProgramProgram_(sohandle, i)), + name)); + i++; + } + } while (name != null); + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#getMaxPolyphony() + */ + public int getMaxPolyphony() + { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#getLatency() + */ + public long getLatency() + { + // DSSI and LADSPA provide no way to determine the latency. + // Let's just return 0 for now. + return 0; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#getChannels() + */ + public MidiChannel[] getChannels() + { + return channels; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#getVoiceStatus() + */ + public VoiceStatus[] getVoiceStatus() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#isSoundbankSupported(javax.sound.midi.Soundbank) + */ + public boolean isSoundbankSupported(Soundbank soundbank) + { + // TODO Auto-generated method stub + return false; + } + + /* @see javax.sound.midi.Synthesizer#loadInstrument(javax.sound.midi.Instrument) + */ + public boolean loadInstrument(Instrument instrument) + { + // FIXME: perhaps this isn't quite right. It can probably + // be in any soundbank. + if (instrument.getSoundbank() != defaultSoundbank) + throw new IllegalArgumentException ("Synthesizer doesn't support this instrument's soundbank"); + + Patch patch = instrument.getPatch(); + selectProgram_(sohandle, patch.getBank(), patch.getProgram()); + return true; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#unloadInstrument(javax.sound.midi.Instrument) + */ + public void unloadInstrument(Instrument instrument) + { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#remapInstrument(javax.sound.midi.Instrument, javax.sound.midi.Instrument) + */ + public boolean remapInstrument(Instrument from, Instrument to) + { + // TODO Auto-generated method stub + return false; + } + + /* @see javax.sound.midi.Synthesizer#getDefaultSoundbank() + */ + public Soundbank getDefaultSoundbank() + { + return defaultSoundbank; + } + + /* @see javax.sound.midi.Synthesizer#getAvailableInstruments() + */ + public Instrument[] getAvailableInstruments() + { + List instruments = new ArrayList(); + Iterator itr = soundbanks.iterator(); + while (itr.hasNext()) + { + Soundbank sb = (Soundbank) itr.next(); + Instrument ins[] = sb.getInstruments(); + for (int i = 0; i < ins.length; i++) + instruments.add(ins[i]); + } + return (Instrument[]) + instruments.toArray(new Instrument[instruments.size()]); + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#getLoadedInstruments() + */ + public Instrument[] getLoadedInstruments() + { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#loadAllInstruments(javax.sound.midi.Soundbank) + */ + public boolean loadAllInstruments(Soundbank soundbank) + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#unloadAllInstruments(javax.sound.midi.Soundbank) + */ + public void unloadAllInstruments(Soundbank soundbank) + { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[]) + */ + public boolean loadInstruments(Soundbank soundbank, Patch[] patchList) + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.Synthesizer#unloadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[]) + */ + public void unloadInstruments(Soundbank soundbank, Patch[] patchList) + { + // TODO Auto-generated method stub + + } + + /* @see javax.sound.midi.MidiDevice#getDeviceInfo() + */ + public Info getDeviceInfo() + { + return info; + } + + /* @see javax.sound.midi.MidiDevice#open() + */ + public void open() throws MidiUnavailableException + { + open_(sohandle); + } + + /* @see javax.sound.midi.MidiDevice#close() + */ + public void close() + { + close_(sohandle); + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#isOpen() + */ + public boolean isOpen() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see javax.sound.midi.MidiDevice#getMicrosecondPosition() + */ + public long getMicrosecondPosition() + { + // TODO Auto-generated method stub + return 0; + } + + /* @see javax.sound.midi.MidiDevice#getMaxReceivers() + */ + public int getMaxReceivers() + { + return 1; + } + + /* @see javax.sound.midi.MidiDevice#getMaxTransmitters() + */ + public int getMaxTransmitters() + { + return 0; + } + + /* @see javax.sound.midi.MidiDevice#getReceiver() + */ + public Receiver getReceiver() throws MidiUnavailableException + { + return new DSSIReceiver(); + } + + /* @see javax.sound.midi.MidiDevice#getTransmitter() + */ + public Transmitter getTransmitter() throws MidiUnavailableException + { + return null; + } +} diff --git a/libjava/classpath/gnu/xml/aelfred2/JAXPFactory.java b/libjava/classpath/gnu/xml/aelfred2/JAXPFactory.java index 37e8cc9..011ca3c 100644 --- a/libjava/classpath/gnu/xml/aelfred2/JAXPFactory.java +++ b/libjava/classpath/gnu/xml/aelfred2/JAXPFactory.java @@ -109,7 +109,7 @@ public final class JAXPFactory // (flags can't necessarily be set before parsing) new JaxpParser().getXMLReader().setFeature(name, value); - flags.put(name, new Boolean(value)); + flags.put(name, Boolean.valueOf(value)); } catch (SAXNotRecognizedException e) { diff --git a/libjava/classpath/gnu/xml/aelfred2/SAXDriver.java b/libjava/classpath/gnu/xml/aelfred2/SAXDriver.java index 7e950ce..6864ff6 100644 --- a/libjava/classpath/gnu/xml/aelfred2/SAXDriver.java +++ b/libjava/classpath/gnu/xml/aelfred2/SAXDriver.java @@ -717,7 +717,9 @@ final public class SAXDriver } else { - in.setSystemId(absolutize(baseURI, in.getSystemId(), false)); + in.setSystemId(absolutize(baseURI, + in.getSystemId(), + entityResolver != base)); source = entityResolver.resolveEntity(in.getPublicId(), in.getSystemId()); if (source == null) diff --git a/libjava/classpath/gnu/xml/dom/DomDocument.java b/libjava/classpath/gnu/xml/dom/DomDocument.java index dc476b5..29b8dc7 100644 --- a/libjava/classpath/gnu/xml/dom/DomDocument.java +++ b/libjava/classpath/gnu/xml/dom/DomDocument.java @@ -210,13 +210,15 @@ public class DomDocument */ public Element getElementById(String id) { - DomDoctype doctype = (DomDoctype) getDoctype(); - - if (doctype == null || !doctype.hasIds() - || id == null || id.length() == 0) + if (id == null || id.length() == 0) { return null; } + DomDoctype doctype = (DomDoctype) getDoctype(); + if (doctype != null && !doctype.hasIds()) + { + doctype = null; + } // yes, this is linear in size of document. // it'd be easy enough to maintain a hashtable. @@ -233,25 +235,39 @@ public class DomDocument if (current.getNodeType() == ELEMENT_NODE) { DomElement element = (DomElement) current; - DTDElementTypeInfo info = - doctype.getElementTypeInfo(current.getNodeName()); - if (info != null && - id.equals(element.getAttribute(info.idAttrName))) - { - return element; - } - else if (element.userIdAttrs != null) + if (doctype != null) { - for (Iterator i = element.userIdAttrs.iterator(); - i.hasNext(); ) + DTDElementTypeInfo info = + doctype.getElementTypeInfo(current.getNodeName()); + if (info != null && + id.equals(element.getAttribute(info.idAttrName))) { - Node idAttr = (Node) i.next(); - if (id.equals(idAttr.getNodeValue())) + return element; + } + else if (element.userIdAttrs != null) + { + for (Iterator i = element.userIdAttrs.iterator(); + i.hasNext(); ) { - return element; + Node idAttr = (Node) i.next(); + if (id.equals(idAttr.getNodeValue())) + { + return element; + } } } } + // xml:id + String xmlId = element.getAttribute("xml:id"); + if (xmlId == null) + { + xmlId = element.getAttributeNS(XMLConstants.XML_NS_URI, + "id"); + } + if (id.equals(xmlId)) + { + return element; + } } // descend? diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java index 3706fba..03420c4 100644 --- a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java +++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java @@ -376,31 +376,31 @@ public class GnomeDocument name = name.toLowerCase(); if ("canonical-form".equals(name)) { - return new Boolean(canonicalForm); + return Boolean.valueOf(canonicalForm); } else if ("cdata-sections".equals(name)) { - return new Boolean(cdataSections); + return Boolean.valueOf(cdataSections); } else if ("check-character-normalization".equals(name)) { - return new Boolean(checkCharacterNormalization); + return Boolean.valueOf(checkCharacterNormalization); } else if ("comments".equals(name)) { - return new Boolean(comments); + return Boolean.valueOf(comments); } else if ("datatype-normalization".equals(name)) { - return new Boolean(datatypeNormalization); + return Boolean.valueOf(datatypeNormalization); } else if ("element-content-whitespace".equals(name)) { - return new Boolean(elementContentWhitespace); + return Boolean.valueOf(elementContentWhitespace); } else if ("entities".equals(name)) { - return new Boolean(entities); + return Boolean.valueOf(entities); } else if ("error-handler".equals(name)) { @@ -408,43 +408,43 @@ public class GnomeDocument } else if ("infoset".equals(name)) { - return new Boolean(!validateIfSchema && - !entities && - !datatypeNormalization && - !cdataSections && - namespaceDeclarations && - wellFormed && - elementContentWhitespace && - comments && - namespaces); + return Boolean.valueOf(!validateIfSchema && + !entities && + !datatypeNormalization && + !cdataSections && + namespaceDeclarations && + wellFormed && + elementContentWhitespace && + comments && + namespaces); } else if ("namespaces".equals(name)) { - return new Boolean(namespaces); + return Boolean.valueOf(namespaces); } else if ("namespace-declarations".equals(name)) { - return new Boolean(namespaceDeclarations); + return Boolean.valueOf(namespaceDeclarations); } else if ("normalize-characters".equals(name)) { - return new Boolean(normalizeCharacters); + return Boolean.valueOf(normalizeCharacters); } else if ("split-cdata-sections".equals(name)) { - return new Boolean(splitCdataSections); + return Boolean.valueOf(splitCdataSections); } else if ("validate".equals(name)) { - return new Boolean(validate); + return Boolean.valueOf(validate); } else if ("validate-if-schema".equals(name)) { - return new Boolean(validateIfSchema); + return Boolean.valueOf(validateIfSchema); } else if ("well-formed".equals(name)) { - return new Boolean(wellFormed); + return Boolean.valueOf(wellFormed); } else { @@ -497,7 +497,7 @@ public class GnomeDocument } else if (value instanceof String) { - return new Boolean ((String) value).booleanValue(); + return Boolean.valueOf ((String) value).booleanValue(); } return false; } diff --git a/libjava/classpath/gnu/xml/pipeline/ValidationConsumer.java b/libjava/classpath/gnu/xml/pipeline/ValidationConsumer.java index 0fbfa9264..8391767 100644 --- a/libjava/classpath/gnu/xml/pipeline/ValidationConsumer.java +++ b/libjava/classpath/gnu/xml/pipeline/ValidationConsumer.java @@ -1607,7 +1607,7 @@ public final class ValidationConsumer extends EventFilter throw new RuntimeException ("patchNext"); } - if (table != null && (flags | F_LOOPHEAD) != 0) + if (table != null && (flags & F_LOOPHEAD) != 0) table.put (this, this); } diff --git a/libjava/classpath/gnu/xml/stream/XMLOutputFactoryImpl.java b/libjava/classpath/gnu/xml/stream/XMLOutputFactoryImpl.java index 25f5204..05b6d6c 100644 --- a/libjava/classpath/gnu/xml/stream/XMLOutputFactoryImpl.java +++ b/libjava/classpath/gnu/xml/stream/XMLOutputFactoryImpl.java @@ -121,7 +121,8 @@ public class XMLOutputFactoryImpl { if (IS_PREFIX_DEFAULTING.equals(name)) prefixDefaulting = ((Boolean) value).booleanValue(); - throw new IllegalArgumentException(name); + else + throw new IllegalArgumentException(name); } public Object getProperty(String name) diff --git a/libjava/classpath/gnu/xml/stream/XMLStreamWriterImpl.java b/libjava/classpath/gnu/xml/stream/XMLStreamWriterImpl.java index 9ac0abe..d677048 100644 --- a/libjava/classpath/gnu/xml/stream/XMLStreamWriterImpl.java +++ b/libjava/classpath/gnu/xml/stream/XMLStreamWriterImpl.java @@ -39,7 +39,10 @@ package gnu.xml.stream; import java.io.IOException; import java.io.Writer; +import java.util.Enumeration; +import java.util.HashSet; import java.util.LinkedList; +import java.util.Set; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; @@ -57,16 +60,56 @@ public class XMLStreamWriterImpl implements XMLStreamWriter { + /** + * The underlying character stream to write to. + */ protected final Writer writer; + + /** + * The encoding being used. + * Note that this must match the encoding of the character stream. + */ protected final String encoding; + + /** + * Whether prefix defaulting is being used. + * If true and a prefix has not been defined for a namespace specified on + * an element or an attribute, a new prefix and namespace declaration will + * be created. + */ protected final boolean prefixDefaulting; + + /** + * The namespace context used to determine the namespace-prefix mappings + * in scope. + */ protected NamespaceContext namespaceContext; + /** + * The stack of elements in scope. + * Used to close the remaining elements. + */ private LinkedList elements; + + /** + * Whether a start element has been opened but not yet closed. + */ private boolean inStartElement; + + /** + * Whether we are in an empty element. + */ private boolean emptyElement; + private NamespaceSupport namespaces; - + private int count = 0; + + /** + * Constructor. + * @see #writer + * @see #encoding + * @see #prefixDefaulting + */ protected XMLStreamWriterImpl(Writer writer, String encoding, boolean prefixDefaulting) { @@ -77,6 +120,10 @@ public class XMLStreamWriterImpl namespaces = new NamespaceSupport(); } + /** + * Write the end of a start-element event. + * This will close the element if it was defined to be an empty element. + */ private void endStartElement() throws IOException { @@ -128,7 +175,7 @@ public class XMLStreamWriterImpl if (!isDeclared) { if (prefixDefaulting) - prefix = XMLConstants.DEFAULT_NS_PREFIX; + prefix = createPrefix(namespaceURI); else throw new XMLStreamException("namespace " + namespaceURI + " has not been declared"); @@ -140,13 +187,13 @@ public class XMLStreamWriterImpl writer.write(':'); } writer.write(localName); - if (prefixDefaulting && !isDeclared) + inStartElement = true; + if (!isDeclared) { writeNamespace(prefix, namespaceURI); } elements.addLast(new String[] { prefix, localName }); - inStartElement = true; } catch (IOException e) { @@ -156,6 +203,26 @@ public class XMLStreamWriterImpl } } + /** + * Creates a new unique prefix in the document. + * Subclasses may override this method to provide a suitably unique prefix + * for the given namespace. + * @param namespaceURI the namespace URI + */ + protected String createPrefix(String namespaceURI) + { + Set prefixes = new HashSet(); + for (Enumeration e = namespaces.getPrefixes(); e.hasMoreElements(); ) + prefixes.add(e.nextElement()); + String ret; + do + { + ret = "ns" + (count++); + } + while (prefixes.contains(ret)); + return ret; + } + public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException @@ -656,6 +723,12 @@ public class XMLStreamWriterImpl throw new IllegalArgumentException(name); } + /** + * Write the specified text, ensuring that the content is suitably encoded + * for XML. + * @param text the text to write + * @param inAttr whether we are in an attribute value + */ private void writeEncoded(String text, boolean inAttr) throws IOException { diff --git a/libjava/classpath/gnu/xml/transform/StreamSerializer.java b/libjava/classpath/gnu/xml/transform/StreamSerializer.java index eb04539..74b1005 100644 --- a/libjava/classpath/gnu/xml/transform/StreamSerializer.java +++ b/libjava/classpath/gnu/xml/transform/StreamSerializer.java @@ -694,7 +694,11 @@ public class StreamSerializer { buf = new StringBuffer(text.substring(0, i)); } - buf.append("'"); + if (mode == Stylesheet.OUTPUT_HTML) + // HTML does not define ', use character entity ref + buf.append("'"); + else + buf.append("'"); } else if (c == '"' && inAttr) { diff --git a/libjava/classpath/gnu/xml/transform/TransformerImpl.java b/libjava/classpath/gnu/xml/transform/TransformerImpl.java index a36aa61..cf40488 100644 --- a/libjava/classpath/gnu/xml/transform/TransformerImpl.java +++ b/libjava/classpath/gnu/xml/transform/TransformerImpl.java @@ -1,5 +1,5 @@ /* TransformerImpl.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -505,6 +505,12 @@ class TransformerImpl { URL url = new URL(systemId); URLConnection connection = url.openConnection(); + // We need to call setDoInput(false), because our + // implementation of the file protocol allows writing + // (unlike Sun), but it will fail with a FileNotFoundException + // if we also open the connection for input and the output + // file doesn't yet exist. + connection.setDoInput(false); connection.setDoOutput(true); out = connection.getOutputStream(); } -- cgit v1.1