corba/src/java.corba/share/classes/com/sun/corba/se/impl/io/IIOPInputStream.java
changeset 31733 0d786ab95c1c
parent 29936 9edf96e1b418
child 33324 4d5e1be7047d
equal deleted inserted replaced
31564:9b3a9d72f07b 31733:0d786ab95c1c
  2428      * This must handle same switch logic as above.
  2428      * This must handle same switch logic as above.
  2429      */
  2429      */
  2430     private void throwAwayData(ValueMember[] fields,
  2430     private void throwAwayData(ValueMember[] fields,
  2431                                com.sun.org.omg.SendingContext.CodeBase sender)
  2431                                com.sun.org.omg.SendingContext.CodeBase sender)
  2432         throws InvalidClassException, StreamCorruptedException,
  2432         throws InvalidClassException, StreamCorruptedException,
  2433                ClassNotFoundException, IOException
  2433                ClassNotFoundException, IOException {
  2434     {
  2434 
  2435         for (int i = 0; i < fields.length; ++i) {
  2435         for (int i = 0; i < fields.length; ++i) {
  2436 
  2436 
  2437             try {
  2437             try {
  2438 
  2438 
  2439                 switch (fields[i].type.kind().value()) {
  2439                 switch (fields[i].type.kind().value()) {
  2564             }
  2564             }
  2565         }
  2565         }
  2566 
  2566 
  2567     }
  2567     }
  2568 
  2568 
  2569     private static void setObjectField(Object o, Class c, String fieldName, Object v)
  2569     private static void setObjectField(Object o, Class c, String fieldName, Object v) {
  2570     {
       
  2571         try {
  2570         try {
  2572             Field fld = c.getDeclaredField( fieldName ) ;
  2571             Field fld = c.getDeclaredField( fieldName ) ;
  2573             Class fieldCl = fld.getType();
  2572             Class fieldCl = fld.getType();
  2574             if(v != null && !fieldCl.isInstance(v)) {
  2573             if(v != null && !fieldCl.isInstance(v)) {
  2575                 throw new Exception();
  2574                 throw new Exception();
  2576             }
  2575             }
  2577             long key = bridge.objectFieldOffset( fld ) ;
  2576             long key = bridge.objectFieldOffset( fld ) ;
  2578             bridge.putObject( o, key, v ) ;
  2577             bridge.putObject( o, key, v ) ;
  2579         } catch (Exception e) {
  2578         } catch (Exception e) {
  2580             throw utilWrapper.errorSetObjectField( e, fieldName,
  2579             if (o != null) {
  2581                 o.toString(),
  2580                 throw utilWrapper.errorSetObjectField( e, fieldName,
  2582                 v.toString() ) ;
  2581                     o.toString(),
       
  2582                     v.toString() ) ;
       
  2583             } else {
       
  2584                 throw utilWrapper.errorSetObjectField( e, fieldName,
       
  2585                     "null " + c.getName() + " object",
       
  2586                     v.toString() ) ;
       
  2587             }
  2583         }
  2588         }
  2584     }
  2589     }
  2585 
  2590 
  2586     private static void setBooleanField(Object o, Class c, String fieldName, boolean v)
  2591     private static void setBooleanField(Object o, Class c, String fieldName, boolean v)
  2587     {
  2592     {
  2588         try {
  2593         try {
  2589             Field fld = c.getDeclaredField( fieldName ) ;
  2594             Field fld = c.getDeclaredField( fieldName ) ;
  2590             long key = bridge.objectFieldOffset( fld ) ;
  2595             if ((fld != null) && (fld.getType() == Boolean.TYPE)) {
  2591             bridge.putBoolean( o, key, v ) ;
  2596                 long key = bridge.objectFieldOffset( fld ) ;
       
  2597                 bridge.putBoolean( o, key, v ) ;
       
  2598             } else {
       
  2599                 throw new InvalidObjectException("Field Type mismatch");
       
  2600             }
  2592         } catch (Exception e) {
  2601         } catch (Exception e) {
       
  2602             if (o != null) {
  2593             throw utilWrapper.errorSetBooleanField( e, fieldName,
  2603             throw utilWrapper.errorSetBooleanField( e, fieldName,
  2594                 o.toString(),
  2604                 o.toString(),
  2595                 new Boolean(v) ) ;
  2605                 new Boolean(v) ) ;
       
  2606             } else {
       
  2607                 throw utilWrapper.errorSetBooleanField( e, fieldName,
       
  2608                     "null " + c.getName() + " object",
       
  2609                     new Boolean(v) ) ;
       
  2610             }
  2596         }
  2611         }
  2597     }
  2612     }
  2598 
  2613 
  2599     private static void setByteField(Object o, Class c, String fieldName, byte v)
  2614     private static void setByteField(Object o, Class c, String fieldName, byte v)
  2600     {
  2615     {
  2601         try {
  2616         try {
  2602             Field fld = c.getDeclaredField( fieldName ) ;
  2617             Field fld = c.getDeclaredField( fieldName ) ;
  2603             long key = bridge.objectFieldOffset( fld ) ;
  2618             if ((fld != null) && (fld.getType() == Byte.TYPE)) {
  2604             bridge.putByte( o, key, v ) ;
  2619                 long key = bridge.objectFieldOffset( fld ) ;
       
  2620                 bridge.putByte( o, key, v ) ;
       
  2621             } else {
       
  2622                 throw new InvalidObjectException("Field Type mismatch");
       
  2623             }
  2605         } catch (Exception e) {
  2624         } catch (Exception e) {
  2606             throw utilWrapper.errorSetByteField( e, fieldName,
  2625             if (o != null) {
  2607                 o.toString(),
  2626                 throw utilWrapper.errorSetByteField( e, fieldName,
  2608                 new Byte(v) ) ;
  2627                     o.toString(),
       
  2628                     new Byte(v) ) ;
       
  2629             } else {
       
  2630                 throw utilWrapper.errorSetByteField( e, fieldName,
       
  2631                     "null " + c.getName() + " object",
       
  2632                     new Byte(v) ) ;
       
  2633             }
  2609         }
  2634         }
  2610     }
  2635     }
  2611 
  2636 
  2612     private static void setCharField(Object o, Class c, String fieldName, char v)
  2637     private static void setCharField(Object o, Class c, String fieldName, char v)
  2613     {
  2638     {
  2614         try {
  2639         try {
  2615             Field fld = c.getDeclaredField( fieldName ) ;
  2640             Field fld = c.getDeclaredField( fieldName ) ;
  2616             long key = bridge.objectFieldOffset( fld ) ;
  2641             if ((fld != null) && (fld.getType() == Character.TYPE)) {
  2617             bridge.putChar( o, key, v ) ;
  2642                 long key = bridge.objectFieldOffset( fld ) ;
       
  2643                 bridge.putChar( o, key, v ) ;
       
  2644             } else {
       
  2645                 throw new InvalidObjectException("Field Type mismatch");
       
  2646             }
  2618         } catch (Exception e) {
  2647         } catch (Exception e) {
  2619             throw utilWrapper.errorSetCharField( e, fieldName,
  2648             if (o != null) {
  2620                 o.toString(),
  2649                 throw utilWrapper.errorSetCharField( e, fieldName,
  2621                 new Character(v) ) ;
  2650                     o.toString(),
       
  2651                     new Character(v) ) ;
       
  2652             } else {
       
  2653                 throw utilWrapper.errorSetCharField( e, fieldName,
       
  2654                     "null " + c.getName() + " object",
       
  2655                     new Character(v) ) ;
       
  2656             }
  2622         }
  2657         }
  2623     }
  2658     }
  2624 
  2659 
  2625     private static void setShortField(Object o, Class c, String fieldName, short v)
  2660     private static void setShortField(Object o, Class c, String fieldName, short v)
  2626     {
  2661     {
  2627         try {
  2662         try {
  2628             Field fld = c.getDeclaredField( fieldName ) ;
  2663             Field fld = c.getDeclaredField( fieldName ) ;
  2629             long key = bridge.objectFieldOffset( fld ) ;
  2664             if ((fld != null) && (fld.getType() == Short.TYPE)) {
  2630             bridge.putShort( o, key, v ) ;
  2665                 long key = bridge.objectFieldOffset( fld ) ;
       
  2666                 bridge.putShort( o, key, v ) ;
       
  2667             } else {
       
  2668                 throw new InvalidObjectException("Field Type mismatch");
       
  2669             }
  2631         } catch (Exception e) {
  2670         } catch (Exception e) {
       
  2671             if (o != null) {
  2632             throw utilWrapper.errorSetShortField( e, fieldName,
  2672             throw utilWrapper.errorSetShortField( e, fieldName,
  2633                 o.toString(),
  2673                 o.toString(),
  2634                 new Short(v) ) ;
  2674                 new Short(v) ) ;
       
  2675             } else {
       
  2676                 throw utilWrapper.errorSetShortField( e, fieldName,
       
  2677                     "null " + c.getName() + " object",
       
  2678                     new Short(v) ) ;
       
  2679             }
  2635         }
  2680         }
  2636     }
  2681     }
  2637 
  2682 
  2638     private static void setIntField(Object o, Class c, String fieldName, int v)
  2683     private static void setIntField(Object o, Class c, String fieldName, int v)
  2639     {
  2684     {
  2640         try {
  2685         try {
  2641             Field fld = c.getDeclaredField( fieldName ) ;
  2686             Field fld = c.getDeclaredField( fieldName ) ;
  2642             long key = bridge.objectFieldOffset( fld ) ;
  2687             if ((fld != null) && (fld.getType() == Integer.TYPE)) {
  2643             bridge.putInt( o, key, v ) ;
  2688                 long key = bridge.objectFieldOffset( fld ) ;
       
  2689                 bridge.putInt( o, key, v ) ;
       
  2690             } else {
       
  2691                 throw new InvalidObjectException("Field Type mismatch");
       
  2692             }
  2644         } catch (Exception e) {
  2693         } catch (Exception e) {
  2645             throw utilWrapper.errorSetIntField( e, fieldName,
  2694             if (o != null) {
  2646                 o.toString(),
  2695                 throw utilWrapper.errorSetIntField( e, fieldName,
  2647                 new Integer(v) ) ;
  2696                     o.toString(),
       
  2697                     new Integer(v) ) ;
       
  2698             } else {
       
  2699                 throw utilWrapper.errorSetIntField( e, fieldName,
       
  2700                     "null " + c.getName() + " object",
       
  2701                     new Integer(v) ) ;
       
  2702             }
  2648         }
  2703         }
  2649     }
  2704     }
  2650 
  2705 
  2651     private static void setLongField(Object o, Class c, String fieldName, long v)
  2706     private static void setLongField(Object o, Class c, String fieldName, long v)
  2652     {
  2707     {
  2653         try {
  2708         try {
  2654             Field fld = c.getDeclaredField( fieldName ) ;
  2709             Field fld = c.getDeclaredField( fieldName ) ;
  2655             long key = bridge.objectFieldOffset( fld ) ;
  2710             if ((fld != null) && (fld.getType() == Long.TYPE)) {
  2656             bridge.putLong( o, key, v ) ;
  2711                 long key = bridge.objectFieldOffset( fld ) ;
       
  2712                 bridge.putLong( o, key, v ) ;
       
  2713             } else {
       
  2714                 throw new InvalidObjectException("Field Type mismatch");
       
  2715             }
  2657         } catch (Exception e) {
  2716         } catch (Exception e) {
  2658             throw utilWrapper.errorSetLongField( e, fieldName,
  2717             if (o != null) {
  2659                 o.toString(),
  2718                 throw utilWrapper.errorSetLongField( e, fieldName,
  2660                 new Long(v) ) ;
  2719                     o.toString(),
       
  2720                     new Long(v) ) ;
       
  2721             } else {
       
  2722                 throw utilWrapper.errorSetLongField( e, fieldName,
       
  2723                     "null " + c.getName() + " object",
       
  2724                     new Long(v) ) ;
       
  2725             }
  2661         }
  2726         }
  2662     }
  2727     }
  2663 
  2728 
  2664     private static void setFloatField(Object o, Class c, String fieldName, float v)
  2729     private static void setFloatField(Object o, Class c, String fieldName, float v)
  2665     {
  2730     {
  2666         try {
  2731         try {
  2667             Field fld = c.getDeclaredField( fieldName ) ;
  2732             Field fld = c.getDeclaredField( fieldName ) ;
  2668             long key = bridge.objectFieldOffset( fld ) ;
  2733             if ((fld != null) && (fld.getType() == Float.TYPE)) {
  2669             bridge.putFloat( o, key, v ) ;
  2734                 long key = bridge.objectFieldOffset( fld ) ;
       
  2735                 bridge.putFloat( o, key, v ) ;
       
  2736             } else {
       
  2737                 throw new InvalidObjectException("Field Type mismatch");
       
  2738             }
  2670         } catch (Exception e) {
  2739         } catch (Exception e) {
  2671             throw utilWrapper.errorSetFloatField( e, fieldName,
  2740             if (o != null) {
  2672                 o.toString(),
  2741                 throw utilWrapper.errorSetFloatField( e, fieldName,
  2673                 new Float(v) ) ;
  2742                     o.toString(),
       
  2743                     new Float(v) ) ;
       
  2744             } else {
       
  2745                 throw utilWrapper.errorSetFloatField( e, fieldName,
       
  2746                     "null " + c.getName() + " object",
       
  2747                     new Float(v) ) ;
       
  2748             }
  2674         }
  2749         }
  2675     }
  2750     }
  2676 
  2751 
  2677     private static void setDoubleField(Object o, Class c, String fieldName, double v)
  2752     private static void setDoubleField(Object o, Class c, String fieldName, double v)
  2678     {
  2753     {
  2679         try {
  2754         try {
  2680             Field fld = c.getDeclaredField( fieldName ) ;
  2755             Field fld = c.getDeclaredField( fieldName ) ;
  2681             long key = bridge.objectFieldOffset( fld ) ;
  2756             if ((fld != null) && (fld.getType() == Double.TYPE)) {
  2682             bridge.putDouble( o, key, v ) ;
  2757                 long key = bridge.objectFieldOffset( fld ) ;
       
  2758                 bridge.putDouble( o, key, v ) ;
       
  2759             } else {
       
  2760                 throw new InvalidObjectException("Field Type mismatch");
       
  2761             }
  2683         } catch (Exception e) {
  2762         } catch (Exception e) {
  2684             throw utilWrapper.errorSetDoubleField( e, fieldName,
  2763             if (o != null) {
  2685                 o.toString(),
  2764                 throw utilWrapper.errorSetDoubleField( e, fieldName,
  2686                 new Double(v) ) ;
  2765                     o.toString(),
       
  2766                     new Double(v) ) ;
       
  2767             } else {
       
  2768                 throw utilWrapper.errorSetDoubleField( e, fieldName,
       
  2769                     "null " + c.getName() + " object",
       
  2770                     new Double(v) ) ;
       
  2771             }
  2687         }
  2772         }
  2688     }
  2773     }
  2689 
  2774 
  2690     /**
  2775     /**
  2691      * This class maintains a map of stream position to
  2776      * This class maintains a map of stream position to