Home » openjdk-7 » java » io » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package java.io;
   19   
   20   /**
   21    * An EmulatedFieldsForLoading is an object that represents a set of emulated
   22    * fields for an object being loaded. It is a concrete implementation for
   23    * ObjectInputStream.GetField
   24    * 
   25    * @see ObjectInputStream.GetField
   26    * @see EmulatedFieldsForDumping
   27    */
   28   class EmulatedFieldsForLoading extends ObjectInputStream.GetField {
   29   
   30       // The class descriptor with the declared fields the receiver emulates
   31       private ObjectStreamClass streamClass;
   32   
   33       // The actual representation, with a more powerful API (set&get)
   34       private EmulatedFields emulatedFields;
   35   
   36       /**
   37        * Constructs a new instance of EmulatedFieldsForDumping.
   38        * 
   39        * @param streamClass
   40        *            an ObjectStreamClass, defining the class for which to emulate
   41        *            fields.
   42        */
   43       EmulatedFieldsForLoading(ObjectStreamClass streamClass) {
   44           super();
   45           this.streamClass = streamClass;
   46           emulatedFields = new EmulatedFields(streamClass.getLoadFields(),
   47                   streamClass.fields());
   48       }
   49   
   50       /**
   51        * Return a boolean indicating if the field named <code>name</code> has
   52        * been assigned a value explicitly (false) or if it still holds a default
   53        * value for the type (true) because it hasn't been assigned to yet.
   54        * 
   55        * @param name
   56        *            A String, the name of the field to test
   57        * @return <code>true</code> if the field holds it default value,
   58        *         <code>false</code> otherwise.
   59        * 
   60        * @throws IOException
   61        *             If an IO error occurs
   62        * @throws IllegalArgumentException
   63        *             If the corresponding field can not be found.
   64        */
   65       @Override
   66       public boolean defaulted(String name) throws IOException,
   67               IllegalArgumentException {
   68           return emulatedFields.defaulted(name);
   69       }
   70   
   71       /**
   72        * Return the actual EmulatedFields instance used by the receiver. We have
   73        * the actual work in a separate class so that the code can be shared. The
   74        * receiver has to be of a subclass of GetField.
   75        * 
   76        * @return array of ObjectSlot the receiver represents.
   77        */
   78       EmulatedFields emulatedFields() {
   79           return emulatedFields;
   80       }
   81   
   82       /**
   83        * Find and return the byte value of a given field named <code>name</code>
   84        * in the receiver. If the field has not been assigned any value yet, the
   85        * default value <code>defaultValue</code> is returned instead.
   86        * 
   87        * @param name
   88        *            A String, the name of the field to find
   89        * @param defaultValue
   90        *            Return value in case the field has not been assigned to yet.
   91        * @return the value of the given field if it has been assigned, or the
   92        *         default value otherwise
   93        * 
   94        * @throws IOException
   95        *             If an IO error occurs
   96        * @throws IllegalArgumentException
   97        *             If the corresponding field can not be found.
   98        */
   99       @Override
  100       public byte get(String name, byte defaultValue) throws IOException,
  101               IllegalArgumentException {
  102           return emulatedFields.get(name, defaultValue);
  103       }
  104   
  105       /**
  106        * Find and return the char value of a given field named <code>name</code>
  107        * in the receiver. If the field has not been assigned any value yet, the
  108        * default value <code>defaultValue</code> is returned instead.
  109        * 
  110        * @param name
  111        *            A String, the name of the field to find
  112        * @param defaultValue
  113        *            Return value in case the field has not been assigned to yet.
  114        * @return the value of the given field if it has been assigned, or the
  115        *         default value otherwise
  116        * 
  117        * @throws IOException
  118        *             If an IO error occurs
  119        * @throws IllegalArgumentException
  120        *             If the corresponding field can not be found.
  121        */
  122       @Override
  123       public char get(String name, char defaultValue) throws IOException,
  124               IllegalArgumentException {
  125           return emulatedFields.get(name, defaultValue);
  126       }
  127   
  128       /**
  129        * Find and return the double value of a given field named <code>name</code>
  130        * in the receiver. If the field has not been assigned any value yet, the
  131        * default value <code>defaultValue</code> is returned instead.
  132        * 
  133        * @param name
  134        *            A String, the name of the field to find
  135        * @param defaultValue
  136        *            Return value in case the field has not been assigned to yet.
  137        * @return the value of the given field if it has been assigned, or the
  138        *         default value otherwise
  139        * 
  140        * @throws IOException
  141        *             If an IO error occurs
  142        * @throws IllegalArgumentException
  143        *             If the corresponding field can not be found.
  144        */
  145       @Override
  146       public double get(String name, double defaultValue) throws IOException,
  147               IllegalArgumentException {
  148           return emulatedFields.get(name, defaultValue);
  149       }
  150   
  151       /**
  152        * Find and return the float value of a given field named <code>name</code>
  153        * in the receiver. If the field has not been assigned any value yet, the
  154        * default value <code>defaultValue</code> is returned instead.
  155        * 
  156        * @param name
  157        *            A String, the name of the field to find
  158        * @param defaultValue
  159        *            Return value in case the field has not been assigned to yet.
  160        * @return the value of the given field if it has been assigned, or the
  161        *         default value otherwise
  162        * 
  163        * @throws IOException
  164        *             If an IO error occurs
  165        * @throws IllegalArgumentException
  166        *             If the corresponding field can not be found.
  167        */
  168       @Override
  169       public float get(String name, float defaultValue) throws IOException,
  170               IllegalArgumentException {
  171           return emulatedFields.get(name, defaultValue);
  172       }
  173   
  174       /**
  175        * Find and return the int value of a given field named <code>name</code>
  176        * in the receiver. If the field has not been assigned any value yet, the
  177        * default value <code>defaultValue</code> is returned instead.
  178        * 
  179        * @param name
  180        *            A String, the name of the field to find
  181        * @param defaultValue
  182        *            Return value in case the field has not been assigned to yet.
  183        * @return the value of the given field if it has been assigned, or the
  184        *         default value otherwise
  185        * 
  186        * @throws IOException
  187        *             If an IO error occurs
  188        * @throws IllegalArgumentException
  189        *             If the corresponding field can not be found.
  190        */
  191       @Override
  192       public int get(String name, int defaultValue) throws IOException,
  193               IllegalArgumentException {
  194           return emulatedFields.get(name, defaultValue);
  195       }
  196   
  197       /**
  198        * Find and return the long value of a given field named <code>name</code>
  199        * in the receiver. If the field has not been assigned any value yet, the
  200        * default value <code>defaultValue</code> is returned instead.
  201        * 
  202        * @param name
  203        *            A String, the name of the field to find
  204        * @param defaultValue
  205        *            Return value in case the field has not been assigned to yet.
  206        * @return the value of the given field if it has been assigned, or the
  207        *         default value otherwise
  208        * 
  209        * @throws IOException
  210        *             If an IO error occurs
  211        * @throws IllegalArgumentException
  212        *             If the corresponding field can not be found.
  213        */
  214       @Override
  215       public long get(String name, long defaultValue) throws IOException,
  216               IllegalArgumentException {
  217           return emulatedFields.get(name, defaultValue);
  218       }
  219   
  220       /**
  221        * Find and return the Object value of a given field named <code>name</code>
  222        * in the receiver. If the field has not been assigned any value yet, the
  223        * default value <code>defaultValue</code> is returned instead.
  224        * 
  225        * @param name
  226        *            A String, the name of the field to find
  227        * @param defaultValue
  228        *            Return value in case the field has not been assigned to yet.
  229        * @return the value of the given field if it has been assigned, or the
  230        *         default value otherwise
  231        * 
  232        * @throws IOException
  233        *             If an IO error occurs
  234        * @throws IllegalArgumentException
  235        *             If the corresponding field can not be found.
  236        */
  237       @Override
  238       public Object get(String name, Object defaultValue) throws IOException,
  239               IllegalArgumentException {
  240           return emulatedFields.get(name, defaultValue);
  241       }
  242   
  243       /**
  244        * Find and return the short value of a given field named <code>name</code>
  245        * in the receiver. If the field has not been assigned any value yet, the
  246        * default value <code>defaultValue</code> is returned instead.
  247        * 
  248        * @param name
  249        *            A String, the name of the field to find
  250        * @param defaultValue
  251        *            Return value in case the field has not been assigned to yet.
  252        * @return the value of the given field if it has been assigned, or the
  253        *         default value otherwise
  254        * 
  255        * @throws IOException
  256        *             If an IO error occurs
  257        * @throws IllegalArgumentException
  258        *             If the corresponding field can not be found.
  259        */
  260       @Override
  261       public short get(String name, short defaultValue) throws IOException,
  262               IllegalArgumentException {
  263           return emulatedFields.get(name, defaultValue);
  264       }
  265   
  266       /**
  267        * Find and return the boolean value of a given field named
  268        * <code>name</code> in the receiver. If the field has not been assigned
  269        * any value yet, the default value <code>defaultValue</code> is returned
  270        * instead.
  271        * 
  272        * @param name
  273        *            A String, the name of the field to find
  274        * @param defaultValue
  275        *            Return value in case the field has not been assigned to yet.
  276        * @return the value of the given field if it has been assigned, or the
  277        *         default value otherwise
  278        * 
  279        * @throws IOException
  280        *             If an IO error occurs
  281        * @throws IllegalArgumentException
  282        *             If the corresponding field can not be found.
  283        */
  284       @Override
  285       public boolean get(String name, boolean defaultValue) throws IOException,
  286               IllegalArgumentException {
  287           return emulatedFields.get(name, defaultValue);
  288       }
  289   
  290       /**
  291        * Return the class descriptor for which the emulated fields are defined.
  292        * 
  293        * @return ObjectStreamClass The class descriptor for which the emulated
  294        *         fields are defined.
  295        */
  296       @Override
  297       public ObjectStreamClass getObjectStreamClass() {
  298           return streamClass;
  299       }
  300   }

Home » openjdk-7 » java » io » [javadoc | source]