KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > ApplicationExceptionHelper


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.orb;
22
23 import org.omg.CORBA.*;
24 import org.omg.CORBA.portable.*;
25
26 import java.lang.reflect.*;
27
28 import org.jacorb.ir.RepositoryID;
29 import org.jacorb.util.ObjectUtil;
30
31 /**
32  * This class provides a method for inserting an arbirtary
33  * application exception into an any.
34  *
35  * @author Nicolas Noffke
36  * @version $Id: ApplicationExceptionHelper.java,v 1.16 2004/05/06 12:40:00 nicolas Exp $
37  */

38
39 public class ApplicationExceptionHelper
40 {
41     /**
42      * This method tries to insert the given ApplicationException into the
43      * given any by deriving the helper name from object id. <br>
44      * All exceptions are propagated upward to be handled there.
45      */

46
47     public static void insert(org.omg.CORBA.Any JavaDoc any, ApplicationException s)
48         throws
49             ClassNotFoundException JavaDoc,
50             NoSuchMethodException JavaDoc,
51             IllegalAccessException JavaDoc,
52             InvocationTargetException
53     {
54         java.lang.Object JavaDoc userEx;
55
56         // Get exception and helper names
57

58         String JavaDoc name = RepositoryID.className(s.getId(), null);
59         String JavaDoc helperName = name + "Helper";
60
61         // Get various required classes
62

63         Class JavaDoc exClass = ObjectUtil.classForName(name);
64         Class JavaDoc helperClass = ObjectUtil.classForName(helperName);
65         Class JavaDoc anyClass = org.omg.CORBA.Any JavaDoc.class;
66         Class JavaDoc isClass = org.omg.CORBA.portable.InputStream JavaDoc.class;
67
68         // Get various required methods
69

70         Method readMeth =
71             helperClass.getMethod("read", new Class JavaDoc[] { isClass });
72         Method insertMeth =
73             helperClass.getMethod("insert", new Class JavaDoc[] { anyClass, exClass });
74
75         // Do equivalent of:
76
//
77
// userEx = UserExHelper.read (s.getInputStream ());
78
// UserExHelper.insert (any, userEx);
79
//
80

81         userEx =
82             readMeth.invoke(null, new java.lang.Object JavaDoc[] { s.getInputStream () });
83         insertMeth.invoke(null, new java.lang.Object JavaDoc[] {any, userEx});
84     }
85 }
86
Popular Tags