001    /* ParameterMode.java --
002       Copyright (C) 2005, 2006 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    package org.omg.CORBA;
039    
040    import org.omg.CORBA.portable.IDLEntity;
041    
042    import java.io.Serializable;
043    
044    /**
045     * Defines the parameter modes (the ways in that a method parameter
046     * is used during invocation).
047     *
048     * In CORBA, a method parameter can pass the value (PARAM_IN),
049     * be used as a placeholder to return the value (PARAM_OUT) or
050     * both pass the data and be used as a placeholder to return the
051     * changed value (PARAM_INOUT).
052     *
053     * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
054     */
055    public class ParameterMode
056      implements Serializable, IDLEntity
057    {
058      /**
059       * Use serialVersionUID (v1.4) for interoperability.
060       */
061      private static final long serialVersionUID = 1521598391932998229L;
062    
063      /**
064       * This value means that the parameter is an IN parameter.
065       */
066      public static final int _PARAM_IN = 0;
067    
068      /**
069       * This value means that the parameter is an OUT parameter.
070       */
071      public static final int _PARAM_OUT = 1;
072    
073      /**
074       * This value means that the parameter is an INOUT parameter.
075       */
076      public static final int _PARAM_INOUT = 2;
077    
078      /**
079       * This value means that the parameter is an IN parameter.
080       */
081      public static final ParameterMode PARAM_IN = new ParameterMode(_PARAM_IN);
082    
083      /**
084       * This value means that the parameter is an OUT parameter.
085       */
086      public static final ParameterMode PARAM_OUT = new ParameterMode(_PARAM_OUT);
087    
088      /**
089       * This value means that the parameter is an INOUT parameter.
090       */
091      public static final ParameterMode PARAM_INOUT = new ParameterMode(_PARAM_INOUT);
092    
093      /**
094       * The value of this parameter mode instance.
095       */
096      private final int value;
097    
098      /**
099       * The conversion table.
100       */
101      private static final ParameterMode[] table =
102        new ParameterMode[] { PARAM_IN, PARAM_OUT, PARAM_INOUT };
103    
104      /**
105       * Create an instance of the parameter mode with the given value.
106       */
107      protected ParameterMode(int a_value)
108      {
109        value = a_value;
110      }
111    
112      /**
113       * Return the integer value code for the given parameter mode.
114       *
115       * @return 0 for PARAM_IN, 1 for PARAM_OUT, 3 for PARAM_INOUT.
116       */
117      public int value()
118      {
119        return value;
120      }
121    
122      /**
123       * Get a parameter mode instance for the integer parameter mode code.
124       *
125       * @param p_mode a parameter mode (0..2).
126       *
127       * @return a corresponding parameter mode instance.
128       *
129       * @throws BAD_PARAM for the invalid parameter mode code.
130       */
131      public static ParameterMode from_int(int p_mode)
132      {
133        try
134          {
135            return table [ p_mode ];
136          }
137        catch (ArrayIndexOutOfBoundsException ex)
138          {
139            throw new BAD_PARAM("Invalid parameter mode: " + p_mode);
140          }
141      }
142    }