e.g.
MyException
MyExceptionHelper |
// VB
Imports System
Namespace demo.grid.MyServerPackage
'
' Exception definition : MyException
'
' @author TomORB VB Native Compiler 1.0rc1
'
<Serializable()> _
Public NotInheritable Class MyException
Inherits Org.Omg.CORBA.UserException
'
' Exception member why
'
Public why As String
'
' Default constructor
'
Public Sub New
MyBase.New(MyExceptionHelper.Id())
End Sub
'
' Constructor with fields initialization
' @param why why exception member
'
Public Sub New(why As String)
MyBase.New(MyExceptionHelper.Id())
Me.why = why
End Sub
'
' Full constructor with fields initialization
' @param why why exception member
'
Public Sub New(orb_reason As String, why As String)
MyBase.New(MyExceptionHelper.Id() +" " + orb_reason)
Me.why = why
End Sub
End Class
End Namespace
Namespace demo.grid.MyServerPackage
'
' Helper class for : MyException
'
' @author TomORB VB Native Compiler 1.0rc1
'
Public Class MyExceptionHelper
'
' Insert MyException into an any
' param name="a" an any
' param name="t" MyException value
'
Public Shared Sub Insert(a As Org.Omg.CORBA.Any,
t As demo.grid.MyServerPackage.MyException)
a.Type(Type())
Write(a.Create_Output_Stream(),t)
End Sub
'
' Extract MyException from an any
' @param a an any
' @return the extracted MyException value
'
Public Shared Function Extract(a As Org.Omg.CORBA.Any)
As demo.grid.MyServerPackage.MyException
If Not(a.Type().Equal(Type())) Then
Throw New Org.Omg.CORBA.MARSHAL()
End If
Return Read(a.Create_Input_Stream())
End Function
'
' Internal TypeCode value
'
Private Shared _tc As Org.Omg.CORBA.TypeCode = Nothing
Private Shared _working As Boolean = false
'
' Return the MyException TypeCode
' @return a TypeCode
'
Public Shared Function Type() As Org.Omg.CORBA.TypeCode
If _tc Is Nothing Then
SyncLock (GetType(Org.Omg.CORBA.TypeCode))
If Not(_tc Is Nothing) Then
Return _tc
End If
If _working Then
Return Org.Omg.CORBA.ORB.Init().Create_Recursive_TC(Id())
End If
_working = True
Dim orb As Org.Omg.CORBA.ORB = Org.Omg.CORBA.ORB.Init()
Dim _members() As Org.Omg.CORBA.StructMember =
New Org.Omg.CORBA.StructMember(0){}
_members(0) = New Org.Omg.CORBA.StructMember()
_members(0).name = "why"
_members(0).type = orb.Get_Primitive_TC(Org.Omg.CORBA.TCKind.tk_string)
_tc = orb.Create_Exception_TC(Id(),"MyException",_members)
_working = False
End SyncLock
End If
Return _tc
End Function
'
' Return the MyException IDL ID
' @return an ID
'
Public Shared Function Id() As String
Return _id
End Function
Private Shared _id As String = "IDL:demo/grid/MyServer/MyException:1.0"
'
' Read MyException from a marshalled stream
' @param istream the input stream
' @return the readed MyException value
'
Public Shared Function Read(istream As Org.Omg.CORBA.Portable.InputStream)
As demo.grid.MyServerPackage.MyException
Dim new_one As demo.grid.MyServerPackage.MyException =
New demo.grid.MyServerPackage.MyException()
If Not(istream.Read_String().Equals(Id()) ) Then
Throw New Org.Omg.CORBA.MARSHAL()
End if
new_one.why = istream.Read_String()
Return new_one
End Function
'
' Write MyException into a marshalled stream
' @param ostream the output stream
' @param value MyException value
'
Public Shared Sub Write(ostream As Org.Omg.CORBA.Portable.OutputStream,
value As demo.grid.MyServerPackage.MyException)
ostream.Write_String(Id())
ostream.Write_String(value.why)
End Sub
End Class
End Namespace
|