cdrinputstream_1_0.java
来自「java jdk 1.4的源码」· Java 代码 · 共 2,002 行 · 第 1/5 页
JAVA
2,002 行
if (kind == TCKind._tk_value) { return (tc.type_modifier() == org.omg.CORBA.VM_CUSTOM.value); } } catch(BadKind ex) { throw new org.omg.CORBA.MARSHAL(MinorCodes.BAD_KIND, CompletionStatus.COMPLETED_MAYBE); } return false; } // This method is actually called indirectly by // read_value(String repositoryId). // Therefore, it is not a truly independent read call that handles // header information itself. public java.io.Serializable read_value(java.io.Serializable value) { // Put into valueCache using valueIndirection if (valueCache == null) valueCache = new CacheTable(false); valueCache.put(value, valueIndirection); if (value instanceof StreamableValue) ((StreamableValue)value)._read(parent); else if (value instanceof CustomValue) ((CustomValue)value).unmarshal(parent); return value; } public java.io.Serializable read_value(java.lang.String repositoryId) { // if (inBlock) // end_block(); // Read value tag int vType = readValueTag(); if (vType == 0) return null; // value is null else if (vType == 0xffffffff) { // Indirection tag int indirection = read_long() + get_offset() - 4; if (valueCache != null && valueCache.containsVal(indirection)) { java.io.Serializable cachedValue = (java.io.Serializable)valueCache.getKey(indirection); return cachedValue; } else { throw new IndirectionException(indirection); } } else { int indirection = get_offset() - 4; // end_block(); boolean saveIsChunked = isChunked; isChunked = repIdUtil.isChunkedEncoding(vType); java.lang.Object value = null; String codebase_URL = null; if (repIdUtil.isCodeBasePresent(vType)){ codebase_URL = read_codebase_URL(); } // Read repository id String repositoryIDString = null; switch(repIdUtil.getTypeInfo(vType)){ case RepositoryIdUtility.NO_TYPE_INFO : repositoryIDString = repositoryId; break; case RepositoryIdUtility.SINGLE_REP_TYPE_INFO : repositoryIDString = read_repositoryId(); break; case RepositoryIdUtility.PARTIAL_LIST_TYPE_INFO : repositoryIDString = read_repositoryIds(); break; } ValueFactory factory = Utility.getFactory(null, codebase_URL, orb, repositoryIDString); start_block(); end_flag--; if (isChunked) chunkedValueNestingLevel--; valueIndirection = indirection; // for callback value = factory.read_value(parent); handleEndOfValue(); readEndTag(); // Put into valueCache if (valueCache == null) valueCache = new CacheTable(false); valueCache.put(value, indirection); // allow for possible continuation chunk isChunked = saveIsChunked; start_block(); return (java.io.Serializable)value; } } private Class readClass() { String codebases = null, classRepId = null; if (orb == null || ORBVersionImpl.FOREIGN.equals(orb.getORBVersion()) || ORBVersionImpl.NEWER.compareTo(orb.getORBVersion()) <= 0) { codebases = (String)read_value(java.lang.String.class); classRepId = (String)read_value(java.lang.String.class); } else { // Pre-Merlin/J2EE 1.3 ORBs wrote the repository ID // and codebase strings in the wrong order. classRepId = (String)read_value(java.lang.String.class); codebases = (String)read_value(java.lang.String.class); } if (debug) { debugPrintMessage("readClass codebases: " + codebases + " rep Id: " + classRepId); } Class cl = null; RepositoryIdInterface repositoryID = repIdStrs.getFromString(classRepId); try { cl = repositoryID.getClassFromType(codebases); } catch(ClassNotFoundException cnfe){ debugPrintThrowable(cnfe); throw new org.omg.CORBA.MARSHAL("Unable to load Class " + repositoryID.getClassName() + " : " + cnfe.getMessage(), MinorCodes.CNFE_READ_CLASS, CompletionStatus.COMPLETED_MAYBE); } catch(MalformedURLException me){ debugPrintThrowable(me); throw new org.omg.CORBA.MARSHAL("Unable to load Class " + repositoryID.getClassName() + " : " + me.getMessage(), MinorCodes.MALFORMED_URL, CompletionStatus.COMPLETED_MAYBE); } return cl; } private java.lang.Object readIDLValueWithHelper(ValueHelper helper, int indirection) { // look for two-argument static read method Method readMethod; try { Class argTypes[] = {org.omg.CORBA.portable.InputStream.class, helper.get_class()}; readMethod = helper.getClass().getDeclaredMethod(kReadMethod, argTypes); } catch(NoSuchMethodException nsme) { // must be boxed value helper java.lang.Object result = helper.read_value(parent); return result; } // found two-argument read method, so must be non-boxed value... // ...create a blank instance java.lang.Object val = null; try { val = helper.get_class().newInstance(); } catch(java.lang.InstantiationException ie){ debugPrintThrowable(ie); throw new org.omg.CORBA.MARSHAL(ie.getMessage()); } catch(IllegalAccessException iae){ // Value's constructor is protected or private // // So, use the helper to read the value. // // NOTE : This means that in this particular case a recursive ref. // would fail. return helper.read_value(parent); } // add blank instance to cache table if (valueCache == null) valueCache = new CacheTable(false); valueCache.put(val, indirection); // if custom type, call unmarshal method if (val instanceof CustomMarshal && isCustomType(helper)) { ((CustomMarshal)val).unmarshal(parent); return val; } // call two-argument read method using reflection try { java.lang.Object args[] = {parent, val}; readMethod.invoke(helper, args); return val; } catch(IllegalAccessException iae2){ debugPrintThrowable(iae2); throw new org.omg.CORBA.MARSHAL(iae2.getMessage()); } catch(InvocationTargetException ite){ debugPrintThrowable(ite); throw new org.omg.CORBA.MARSHAL(ite.getMessage()); } } private java.lang.Object readBoxedIDLEntity(Class clazz, String codebase) { try { ClassLoader clazzLoader = (clazz == null ? null : clazz.getClassLoader()); final Class helperClass = Utility.loadClassForClass(clazz.getName()+"Helper", codebase, clazzLoader, clazz, clazzLoader); final Class argTypes[] = {org.omg.CORBA.portable.InputStream.class}; // getDeclaredMethod requires RuntimePermission accessDeclaredMembers // if a different class loader is used (even though the javadoc says otherwise) Method readMethod = null; try { readMethod = (Method)AccessController.doPrivileged( new PrivilegedExceptionAction() { public java.lang.Object run() throws NoSuchMethodException { return helperClass.getDeclaredMethod(kReadMethod, argTypes); } } ); } catch (PrivilegedActionException pae) { // this gets caught below throw (NoSuchMethodException)pae.getException(); } java.lang.Object args[] = {parent}; return readMethod.invoke(null, args); } catch (ClassNotFoundException cnfe) { debugPrintThrowable(cnfe); throw new org.omg.CORBA.MARSHAL(cnfe.getMessage()); } catch(NoSuchMethodException nsme) { debugPrintThrowable(nsme); throw new org.omg.CORBA.MARSHAL(nsme.getMessage()); } catch(IllegalAccessException iae) { debugPrintThrowable(iae); throw new org.omg.CORBA.MARSHAL(iae.getMessage()); } catch(InvocationTargetException ite) { debugPrintThrowable(ite); throw new org.omg.CORBA.MARSHAL(ite.getMessage()); } } private java.lang.Object readIDLValue(int indirection, String repId, Class clazz, String codebase) { if (StreamableValue.class.isAssignableFrom(clazz) || CustomValue.class.isAssignableFrom(clazz)) { // use new-style OBV support (factory object) ValueFactory factory = Utility.getFactory(clazz, codebase, orb, repId); valueIndirection = indirection; // for callback return factory.read_value(parent); } else if (ValueBase.class.isAssignableFrom(clazz)) { // use old-style OBV support (helper object) BoxedValueHelper helper = Utility.getHelper(clazz, codebase, repId); if (helper instanceof ValueHelper) return readIDLValueWithHelper((ValueHelper)helper, indirection); else return helper.read_value(parent); } else { // must be a boxed IDLEntity, so make a reflective call to the // helper's static read method... return readBoxedIDLEntity(clazz, codebase); } } /** * End tags are only written for chunked valuetypes. * * Before Merlin, our ORBs wrote end tags which took into account * all enclosing valuetypes. This was changed by an interop resolution * (see details around chunkedValueNestingLevel) to only include * enclosing chunked types. * * ORB versioning and end tag compaction are handled here. */ private void readEndTag() { if (isChunked) { // Read the end tag int anEndTag = read_long(); // End tags should always be negative, and the outermost // enclosing chunked valuetype should have a -1 end tag. if (anEndTag >= 0) { if (anEndTag >= maxBlockLength) { // A custom marshaled valuetype left extra data // on the wire, and that data had another // nested value inside of it. We've just // read the value tag of that nested value. // // In an attempt to get by it, we'll try to call // read_value() to get the nested value off of // the wire. Afterwards, we must call handleEndOfValue // to read any further chunks that the containing // valuetype might still have after the nested // value. Finally, we make a recursive call to // readEndTag to read the end tag of the // containing value, or do this again if there // are more nested values. bbwi.index -= 4; read_value(); handleEndOfValue(); readEndTag(); return; } else { // We read something that wasn't big enough to be // a value tag. This is an error. throw new MARSHAL("Read non-negative end tag: " + anEndTag + " at " + (get_offset() - 4), MinorCodes.POSITIVE_END_TAG, CompletionStatus.COMPLETED_MAYBE); } } // If the ORB is null, or if we're sure we're talking to // a foreign ORB, Merlin, or something more recent, we // use the updated end tag computation, and are more strenuous // about the values. if (orb == null || ORBVersionImpl.FOREIGN.equals(orb.getORBVersion()) || ORBVersionImpl.NEWER.compareTo(orb.getORBVersion()) <= 0) { // If the end tag we read was less than what we were expecting, // then the sender must think it's sent more enclosing // chunked valuetypes than we have. Throw an exception. if (anEndTag < chunkedValueNestingLevel) throw new MARSHAL("Expecting fewer enclosing valuetypes. " + "Received end tag " + anEndTag + " but expected " + chunkedValueNestingLevel, MinorCodes.UNEXPECTED_ENCLOSING_VALUETYPE, CompletionStatus.COMPLETED_MAYBE); // If the end tag is bigger than what we expected, but // still negative, then the sender has done some end tag // compaction. We back up the stream 4 bytes so that the // next time readEndTag is called, it will get down here // again. Even with fragmentation, we'll always be able // to do this. if (anEndTag != chunkedValueNestingLevel) bbwi.index -= 4; } else { // When talking to Kestrel or Ladybird, we use our old // end tag rules and are less strict. If the end tag // isn't what we expected, we back up, assuming // compaction. if (anEndTag != end_flag) { bbwi.index -= 4; } } // This only keeps track of the enclosing chunked // valuetypes chunkedValueNestingLevel++; } // This keeps track of all enclosing valuetypes end_flag++; } protected int get_offset() { return bbwi.index; } private void start_block() { // if (outerValueDone) if (!isChunked) return; // if called from alignAndCheck, need to reset blockLength // to avoid an infinite recursion loop on read_long() call blockLength = maxBlockLength; blockLength = read_long();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?