📄 clientdelegate.java
字号:
return cachedHashValue; } public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object orig) { return orig; } public void release(org.omg.CORBA.Object obj) { // DONT clear out internal variables to release memory !! // This delegate may be pointed-to by other objrefs ! } public org.omg.CORBA.Request create_request(org.omg.CORBA.Object obj, org.omg.CORBA.Context ctx, String operation, org.omg.CORBA.NVList arg_list, org.omg.CORBA.NamedValue result) { return new RequestImpl(orb, obj, ctx, operation, arg_list, result, null, null); } public org.omg.CORBA.Request request(org.omg.CORBA.Object obj, String operation) { return new RequestImpl(orb, obj, null, operation, null, null, null, null); } public org.omg.CORBA.ORB orb(org.omg.CORBA.Object self) { return this.orb; } public org.omg.CORBA.Request create_request(org.omg.CORBA.Object obj, org.omg.CORBA.Context ctx, String operation, org.omg.CORBA.NVList arg_list, org.omg.CORBA.NamedValue result, org.omg.CORBA.ExceptionList exclist, org.omg.CORBA.ContextList ctxlist) { return new RequestImpl(orb, obj, ctx, operation, arg_list, result, exclist, ctxlist); } private static String AppExcInSpecialMethod = "ApplicationException in SpecialMethod - should not happen"; public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object obj) { InputStream is = null; try { ClientRequest os = createRequest("_interface", false); is = (InputStream) invoke((org.omg.CORBA.Object)null, (OutputStream)os); ObjectImpl objimpl = (ObjectImpl) is.read_Object(); // check if returned object is of correct type if ( !objimpl._is_a("IDL:omg.org/CORBA/InterfaceDef:1.0") ) throw new org.omg.CORBA.UNKNOWN( "InterfaceDef object of wrong type returned by server", 0, CompletionStatus.COMPLETED_MAYBE); // instantiate the stub ObjectImpl stub; try { stub = (ObjectImpl) JDKBridge.loadClass("org.omg.CORBA._InterfaceDefStub"). newInstance(); } catch (Exception ex) { throw new org.omg.CORBA.UNKNOWN( "org.omg.CORBA._InterfaceDefStub class not available", 0, CompletionStatus.COMPLETED_NO); } org.omg.CORBA.portable.Delegate del = objimpl._get_delegate(); stub._set_delegate(del); return stub; } catch (ApplicationException e) { // This cannot happen. throw new INTERNAL(AppExcInSpecialMethod); } catch (RemarshalException e) { return get_interface_def(obj); } finally { releaseReply((org.omg.CORBA.Object)null, (InputStream)is); } } public boolean is_a(org.omg.CORBA.Object obj, String dest) { // dest is the typeId of the interface to compare against. // repositoryIds is the list of typeIds that the stub knows about. // First we look for an answer using local information. String [] repositoryIds = ((ObjectImpl)obj)._ids(); String myid = ior.getTypeId(); if ( dest.equals(myid) ) { return true; } for ( int i=0; i<repositoryIds.length; i++ ) { if ( dest.equals(repositoryIds[i]) ) { return true; } } // But repositoryIds may not be complete, so it may be necessary to // go to server. InputStream is = null; try { ClientRequest os = createRequest("_is_a", false); os.write_string(dest); is = (InputStream) invoke((org.omg.CORBA.Object) null, (OutputStream)os); return is.read_boolean(); } catch (ApplicationException e) { // This cannot happen. throw new INTERNAL(AppExcInSpecialMethod); } catch (RemarshalException e) { return is_a(obj, dest); } finally { releaseReply((org.omg.CORBA.Object)null, (InputStream)is); } } public boolean non_existent(org.omg.CORBA.Object obj) { InputStream is = null; try { ClientRequest os = createRequest("_non_existent", false); is = (InputStream) invoke((org.omg.CORBA.Object)null, (OutputStream)os); return is.read_boolean(); } catch (ApplicationException e) { // This cannot happen. throw new INTERNAL(AppExcInSpecialMethod); } catch (RemarshalException e) { return non_existent(obj); } finally { releaseReply((org.omg.CORBA.Object)null, (InputStream)is); } } public OutputStream request(org.omg.CORBA.Object self, String operation, boolean responseExpected) { return (OutputStream) createRequest(operation, !responseExpected); } /** * Returns true if this object is implemented by a local servant. * We maintain a ThreadLocal to keep track of isLocal() calls to make * sure that we do not loop more than 2 times. In the first call we * set the isNextIsLocalValid to false so that the next call on the same * thread would force to return false in case servant_preinvoke() returns * null. * * @param self The object reference which delegated to this delegate. * @return true only if the servant incarnating this object is located in * this Java VM. Return false if the servant is not local or the ORB * does not support local stubs for this particular servant. The default * behavior of is_local() is to return false. */ public boolean is_local(org.omg.CORBA.Object self) { if ( ((Boolean) isNextIsLocalValid.get()).booleanValue( ) == true ) { return ior.isLocal(); } isNextIsLocalValid.set( Boolean.TRUE ); return false; } public boolean useLocalInvocation( org.omg.CORBA.Object self ) { return false ; } /** * Returns a Java reference to the servant which should be used for this * request. servant_preinvoke() is invoked by a local stub. * If a ServantObject object is returned, then its servant field * has been set to an object of the expected type (Note: the object may * or may not be the actual servant instance). The local stub may cast * the servant field to the expected type, and then invoke the operation * directly. The ServantRequest object is valid for only one invocation, * and cannot be used for more than one invocation. * * @param self The object reference which delegated to this delegate. * * @param operation a string containing the operation name. * The operation name corresponds to the operation name as it would be * encoded in a GIOP request. * * @param a Class object representing the expected type of the servant. * The expected type is the Class object associated with the operations * class of the stub's interface (e.g. A stub for an interface Foo, * would pass the Class object for the FooOperations interface). * * @return a ServantObject object. * The method may return a null value if it does not wish to support * this optimization (e.g. due to security, transactions, etc). * The method must return null if the servant is not of the expected type. */ public ServantObject servant_preinvoke(org.omg.CORBA.Object self, String operation, Class expectedType) { if (servant != null && expectedType.isAssignableFrom(servant.servant.getClass())) { // _REVISIT_ Security check? If we put a security check // on the client side of a connection (IIOPConnection.send()?) // to ensure that the client has permission, do so here as // well. Since a permission check is done when the socket // is initially opened, but not on each use, we probably // need to do the check ourselves since the call stack can // be completely different each time, and a new caller may // not have permission. return servant; } // Set it to false to disallow isLocal to be called again and again // in case of servant being null in _servant_preinvoke() call isNextIsLocalValid.set( Boolean.FALSE ); return null; } /* Returns the codebase for object reference provided. * @param self the object reference whose codebase needs to be returned. * @return the codebase as a space delimited list of url strings or * null if none. */ public String get_codebase(org.omg.CORBA.Object self) { if (ior != null) { return ior.getCodebase(); } return null; } public String toString() { return ior.stringify(); } /** * This method overrides the org.omg.CORBA.portable.Delegate.equals method, * and does the equality check based on IOR equality. */ public boolean equals(org.omg.CORBA.Object self, java.lang.Object other) { if (!(other instanceof ObjectImpl)) { return false; } ObjectImpl otherObj = (ObjectImpl) other; if (otherObj._get_delegate() instanceof ClientDelegate) { ClientDelegate otherDel = (ClientDelegate) otherObj._get_delegate(); IOR otherIor = otherDel.getIOR(); return this.ior.equals(otherIor); } else if (otherObj._get_delegate() instanceof Delegate) { return super.equals(self, other); } return false; } private void performCodeSetNegotiation(Connection conn, GIOPVersion giopVersion) { // conn.getCodeSetContext() is null when no other requests have // been made on this connection to trigger code set negotation. if (conn != null && conn.getCodeSetContext() == null && !giopVersion.equals(GIOPVersion.V1_0)) { synchronized(conn) { // Double checking. Don't let any other // threads use this connection until the // code sets are straight. if (conn.getCodeSetContext() != null) return; // This only looks at the first code set component. If // there can be multiple locations with multiple code sets, // this requires more work. IIOPProfileTemplate temp = getLocatedIOR().getProfile().getTemplate(); Iterator iter = temp.iteratorById(TAG_CODE_SETS.value); if (!iter.hasNext()) { // Didn't have a code set component. The default will // be to use ISO8859-1 for char data and throw an // exception if wchar data is used. return; } // Get the native and conversion code sets the // server specified in its IOR CodeSetComponentInfo serverCodeSets = ((CodeSetsComponent)iter.next()).getCodeSetComponentInfo(); // Perform the negotiation between this ORB's code sets and // the ones from the IOR CodeSetComponentInfo.CodeSetContext result = CodeSetConversion.impl().negotiate(conn.getORB().getCodeSetComponentInfo(), serverCodeSets); conn.setCodeSetContext(result); } } } private void addCodeSetServiceContext(Connection conn, ServiceContexts ctxs, GIOPVersion giopVersion) { // REVISIT. OMG issue 3318 concerning sending the code set // service context more than once was deemed too much for the // RTF. Here's our strategy for the moment: // // Send it on every request (necessary in cases of fragmentation // with multithreaded clients or when the first thing on a // connection is a LocateRequest). Provide an ORB property // to disable multiple sends. // // Note that the connection is null in the local case and no // service context is included. We use the ORB provided // encapsulation streams. // // Also, there will be no negotiation or service context // in GIOP 1.0. ISO8859-1 is used for char/string, and // wchar/wstring are illegal. // if (giopVersion.equals(GIOPVersion.V1_0) || conn == null) return; CodeSetComponentInfo.CodeSetContext codeSetCtx = null; if (conn.getORB().alwaysSendCodeSetServiceContext() || !conn.isPostInitialContexts()) { // Get the negotiated code sets (if any) out of the connection codeSetCtx = conn.getCodeSetContext(); } // Either we shouldn't send the code set service context, or // for some reason, the connection doesn't have its code sets. // Perhaps the server didn't include them in the IOR. Uses // ISO8859-1 for char and makes wchar/wstring illegal. if (codeSetCtx == null) return; CodeSetServiceContext cssc = new CodeSetServiceContext(codeSetCtx); try { ctxs.put(cssc); } catch (DuplicateServiceContext dsc) { // Ignore } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -