01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * 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:
22: package org.jacorb.orb;
23:
24: import java.lang.reflect.InvocationTargetException;
25: import java.lang.reflect.Method;
26:
27: import org.jacorb.ir.RepositoryID;
28: import org.jacorb.util.ObjectUtil;
29: import org.omg.CORBA.portable.ApplicationException;
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.17 2006/06/28 12:39:20 alphonse.bendt Exp $
37: */
38: public class ApplicationExceptionHelper {
39: /**
40: * Private constructor to prevent instantiation
41: */
42: private ApplicationExceptionHelper() {
43: // utility class
44: }
45:
46: /**
47: * This method tries to insert the given ApplicationException into the
48: * given any by deriving the helper name from object id. <br>
49: * All exceptions are propagated upward to be handled there.
50: */
51:
52: public static void insert(org.omg.CORBA.Any any,
53: ApplicationException exception)
54: throws ClassNotFoundException, NoSuchMethodException,
55: IllegalAccessException, InvocationTargetException {
56: java.lang.Object userEx;
57:
58: // Get exception and helper names
59:
60: String name = RepositoryID.className(exception.getId(), null);
61: String helperName = name + "Helper";
62:
63: // Get various required classes
64:
65: Class exClass = ObjectUtil.classForName(name);
66: Class helperClass = ObjectUtil.classForName(helperName);
67: Class anyClass = org.omg.CORBA.Any.class;
68: Class isClass = org.omg.CORBA.portable.InputStream.class;
69:
70: // Get various required methods
71:
72: Method readMeth = helperClass.getMethod("read",
73: new Class[] { isClass });
74: Method insertMeth = helperClass.getMethod("insert",
75: new Class[] { anyClass, exClass });
76:
77: // Do equivalent of:
78: //
79: // userEx = UserExHelper.read (s.getInputStream ());
80: // UserExHelper.insert (any, userEx);
81: //
82:
83: userEx = readMeth.invoke(null,
84: new java.lang.Object[] { exception.getInputStream() });
85: insertMeth.invoke(null, new java.lang.Object[] { any, userEx });
86: }
87: }
|