1 7 8 package com.sun.corba.se.spi.servicecontext; 9 10 import org.omg.CORBA.BAD_PARAM ; 11 import org.omg.CORBA_2_3.portable.InputStream ; 12 import com.sun.corba.se.spi.servicecontext.ServiceContext ; 13 import java.lang.reflect.InvocationTargetException ; 14 import java.lang.reflect.Modifier ; 15 import java.lang.reflect.Field ; 16 import java.lang.reflect.Constructor ; 17 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 18 import com.sun.corba.se.spi.orb.ORB ; 19 import com.sun.corba.se.impl.orbutil.ORBUtility ; 20 21 23 public class ServiceContextData { 24 private void dprint( String msg ) 25 { 26 ORBUtility.dprint( this, msg ) ; 27 } 28 29 private void throwBadParam( String msg, Throwable exc ) 30 { 31 BAD_PARAM error = new BAD_PARAM ( msg ) ; 32 if (exc != null) 33 error.initCause( exc ) ; 34 throw error ; 35 } 36 37 public ServiceContextData( Class cls ) 38 { 39 if (ORB.ORBInitDebug) 40 dprint( "ServiceContextData constructor called for class " + cls ) ; 41 42 scClass = cls ; 43 44 try { 45 if (ORB.ORBInitDebug) 46 dprint( "Finding constructor for " + cls ) ; 47 48 Class [] args = new Class [2] ; 50 args[0] = InputStream .class ; 51 args[1] = GIOPVersion.class; 52 try { 53 scConstructor = cls.getConstructor( args ) ; 54 } catch (NoSuchMethodException nsme) { 55 throwBadParam( "Class does not have an InputStream constructor", nsme ) ; 56 } 57 58 if (ORB.ORBInitDebug) 59 dprint( "Finding SERVICE_CONTEXT_ID field in " + cls ) ; 60 61 Field fld = null ; 63 try { 64 fld = cls.getField( "SERVICE_CONTEXT_ID" ) ; 65 } catch (NoSuchFieldException nsfe) { 66 throwBadParam( "Class does not have a SERVICE_CONTEXT_ID member", nsfe ) ; 67 } catch (SecurityException se) { 68 throwBadParam( "Could not access SERVICE_CONTEXT_ID member", se ) ; 69 } 70 71 if (ORB.ORBInitDebug) 72 dprint( "Checking modifiers of SERVICE_CONTEXT_ID field in " + cls ) ; 73 74 int mod = fld.getModifiers() ; 75 if (!Modifier.isPublic(mod) || !Modifier.isStatic(mod) || 76 !Modifier.isFinal(mod) ) 77 throwBadParam( "SERVICE_CONTEXT_ID field is not public static final", null ) ; 78 79 if (ORB.ORBInitDebug) 80 dprint( "Getting value of SERVICE_CONTEXT_ID in " + cls ) ; 81 82 try { 83 scId = fld.getInt( null ) ; 84 } catch (IllegalArgumentException iae) { 85 throwBadParam( "SERVICE_CONTEXT_ID not convertible to int", iae ) ; 86 } catch (IllegalAccessException iae2) { 87 throwBadParam( "Could not access value of SERVICE_CONTEXT_ID", iae2 ) ; 88 } 89 } catch (BAD_PARAM nssc) { 90 if (ORB.ORBInitDebug) 91 dprint( "Exception in ServiceContextData constructor: " + nssc ) ; 92 throw nssc ; 93 } catch (Throwable thr) { 94 if (ORB.ORBInitDebug) 95 dprint( "Unexpected Exception in ServiceContextData constructor: " + 96 thr ) ; 97 } 98 99 if (ORB.ORBInitDebug) 100 dprint( "ServiceContextData constructor completed" ) ; 101 } 102 103 106 public ServiceContext makeServiceContext(InputStream is, GIOPVersion gv) 107 { 108 Object [] args = new Object [2]; 109 args[0] = is ; 110 args[1] = gv; 111 ServiceContext sc = null ; 112 113 try { 114 sc = (ServiceContext)(scConstructor.newInstance( args )) ; 115 } catch (IllegalArgumentException iae) { 116 throwBadParam( "InputStream constructor argument error", iae ) ; 117 } catch (IllegalAccessException iae2) { 118 throwBadParam( "InputStream constructor argument error", iae2 ) ; 119 } catch (InstantiationException ie) { 120 throwBadParam( "InputStream constructor called for abstract class", ie ) ; 121 } catch (InvocationTargetException ite) { 122 throwBadParam( "InputStream constructor threw exception " + 123 ite.getTargetException(), ite ) ; 124 } 125 126 return sc ; 127 } 128 129 int getId() 130 { 131 return scId ; 132 } 133 134 public String toString() 135 { 136 return "ServiceContextData[ scClass=" + scClass + " scConstructor=" + 137 scConstructor + " scId=" + scId + " ]" ; 138 } 139 140 private Class scClass ; 141 private Constructor scConstructor ; 142 private int scId ; 143 } 144 145 | Popular Tags |