corba/src/share/classes/com/sun/corba/se/spi/orb/OperationFactory.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 7059 79caba0caf4f
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
package com.sun.corba.se.spi.orb ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
import java.util.StringTokenizer ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Array ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.net.URL ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.net.MalformedURLException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.impl.orbutil.ORBClassLoader ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import com.sun.corba.se.impl.orbutil.ObjectUtility ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
/** This is a static factory class for commonly used operations
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
* for property parsing.  The following operations are supported:
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
* <ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
* <li>maskErrorAction( Operation op ) executes op and returns the result.  If op throws an
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
* exception, the result is null.
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
* <li>indexAction( int arg ) returns the [arg] element of value, which must be an Object[]</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
* <li>identityAction() return the value</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
* <li>booleanAction() return a Boolean representing true or false values of the String value</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
* <li>integerAction() returns an Integer for the String value, which must be a decimal integer</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
* <li>stringAction() returns the String value</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
* <li>classAction() returns a class for the String value, as loaded by the ORB classloader</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
* <li>setFlagAction() always return Boolean.TRUE</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
* <li>URLAction() returns a java.net.URL for the String value, which must be a valid URL</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
* <li>integerRangeAction( int min, int max ) returns an Integer for the String value, which must be a
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
* decimal integer in the range min to max inclusive</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
* <li>listAction( String sep, Operation ) tokenizes the String value with sep as separator, then
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
* applies the Operation to each token, and returns an array of the result</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
* <li>sequenceAction( String, Operation[] ) tokenizes the String value with sep as separator, then
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
* applies each Operation in the Operation array to successive tokens, and returns an array of the results</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
* <li>compose( Operation op1, Operation op2 ) is the operation that applies op2 to the result of applying
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
* op1 to the value</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
* <li>mapAction( Operation ) applies the Operation to each element of an array of objects, and returns
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
* an array of the results</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
* <li>mapSequenceAction( Operation[] ) applies the corresponding element of the Operation array to an
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
* element of the Object[] value, and returns an array of the results</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
* <li>convertIntegerToShort coerces an Integer into a Short.</li>
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
* </ul>
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
* Other operations can be directly defined, and combined using these basic operations.
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
*/
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
public abstract class OperationFactory {
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    private OperationFactory() {}
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    private static String getString( Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        if (obj instanceof String)
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
            return (String)obj ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
            throw new Error( "String expected" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    private static Object[] getObjectArray( Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        if (obj instanceof Object[])
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
            return (Object[])obj ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
            throw new Error( "Object[] expected" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    private static StringPair getStringPair( Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        if (obj instanceof StringPair)
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
            return (StringPair)obj ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            throw new Error( "StringPair expected" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    private static abstract class OperationBase implements Operation{
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        public boolean equals( Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            if (this==obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
                return true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            if (!(obj instanceof OperationBase))
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
                return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            OperationBase other = (OperationBase)obj ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
            return toString().equals( other.toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        public int hashCode()
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
            return toString().hashCode() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    private static class MaskErrorAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        private Operation op ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        public MaskErrorAction( Operation op )
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
            this.op = op ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        public Object operate( Object arg )
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                return op.operate( arg ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            } catch (java.lang.Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
                return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        public String toString()
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
            return "maskErrorAction(" + op + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    public static Operation maskErrorAction( Operation op )
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        return new MaskErrorAction( op ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    private static class IndexAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        private int index ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        public IndexAction( int index )
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
            this.index = index ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
            return getObjectArray( value )[ index ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        public String toString()
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
            return "indexAction(" + index + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    public static Operation indexAction( int index )
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        return new IndexAction( index ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    private static class SuffixAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            return getStringPair( value ).getFirst() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        public String toString() { return "suffixAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    private static Operation suffixActionImpl = new SuffixAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    private static class ValueAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
            return getStringPair( value ).getSecond() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
        public String toString() { return "valueAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    private static Operation valueActionImpl = new ValueAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
    private static class IdentityAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
            return value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        public String toString() { return "identityAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    private static Operation identityActionImpl = new IdentityAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    private static class BooleanAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
            return new Boolean( getString( value ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        public String toString() { return "booleanAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    private static Operation booleanActionImpl = new BooleanAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    private static class IntegerAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
            return new Integer( getString( value ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        public String toString() { return "integerAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    private static Operation integerActionImpl = new IntegerAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
    private static class StringAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
            return value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        public String toString() { return "stringAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    private static Operation stringActionImpl = new StringAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    private static class ClassAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            String className = getString( value ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                Class result = ORBClassLoader.loadClass( className ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
            } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
                ORBUtilSystemException wrapper = ORBUtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
                    CORBALogDomains.ORB_LIFECYCLE ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
                throw wrapper.couldNotLoadClass( exc, className ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        public String toString() { return "classAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    private static Operation classActionImpl = new ClassAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    private static class SetFlagAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
            return Boolean.TRUE ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        public String toString() { return "setFlagAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    private static Operation setFlagActionImpl = new SetFlagAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    private static class URLAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
            String val = (String)value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
                return new URL( val ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
            } catch (MalformedURLException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
                ORBUtilSystemException wrapper = ORBUtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
                    CORBALogDomains.ORB_LIFECYCLE ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
                throw wrapper.badUrl( exc, val ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        public String toString() { return "URLAction" ; }
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    private static Operation URLActionImpl = new URLAction() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    public static Operation identityAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        return identityActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    public static Operation suffixAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
        return suffixActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    public static Operation valueAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
        return valueActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
    public static Operation booleanAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        return booleanActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    public static Operation integerAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        return integerActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    public static Operation stringAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
        return stringActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    public static Operation classAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        return classActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
    public static Operation setFlagAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        return setFlagActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    public static Operation URLAction()
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        return URLActionImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
    private static class IntegerRangeAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
        private int min ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        private int max ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        IntegerRangeAction( int min, int max )
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            this.min = min ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
            this.max = max ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
            int result = Integer.parseInt( getString( value ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
            if ((result >= min) && (result <= max))
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
                return new Integer( result ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
                throw new IllegalArgumentException(
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                    "Property value " + result + " is not in the range " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
                    min + " to " + max ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            return "integerRangeAction(" + min + "," + max + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    public static Operation integerRangeAction( int min, int max )
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
        return new IntegerRangeAction( min, max ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    private static class ListAction extends OperationBase {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        private String sep ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
        private Operation act ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        ListAction( String sep, Operation act )
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
            this.sep = sep ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
            this.act = act ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        // Note that this method carefully constructs an array of the type
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
        // of the first result, rather than just using Object[], which is
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        // not convertible into the correct type.  Also note that no tokens
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        // results in a null result.
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
            StringTokenizer st = new StringTokenizer( getString( value ),
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
                sep ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
            int length = st.countTokens() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
            Object result = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
            int ctr = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
            while (st.hasMoreTokens()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
                String next = st.nextToken() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
                Object val = act.operate( next ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
                if (result == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
                    result = Array.newInstance( val.getClass(), length ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
                Array.set( result, ctr++, val ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
            return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
            return "listAction(separator=\"" + sep +
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
                "\",action=" + act + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
    public static Operation listAction( String sep, Operation act )
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
        return new ListAction( sep, act ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
    private static class SequenceAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        private String sep ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        private Operation[] actions ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        SequenceAction( String sep, Operation[] actions )
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
            this.sep = sep ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
            this.actions = actions ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
            StringTokenizer st = new StringTokenizer( getString( value ),
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
                sep ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
            int numTokens = st.countTokens() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
            if (numTokens != actions.length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
                throw new Error(
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                    "Number of tokens and number of actions do not match" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
            int ctr = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
            Object[] result = new Object[ numTokens ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
            while (st.hasMoreTokens()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
                Operation act = actions[ctr] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                String next = st.nextToken() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
                result[ctr++] = act.operate( next ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
            return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
            return "sequenceAction(separator=\"" + sep +
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
                "\",actions=" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                ObjectUtility.compactObjectToString(actions) + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    public static Operation sequenceAction( String sep,
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
        Operation[] actions )
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
        return new SequenceAction( sep, actions ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
    private static class ComposeAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
        private Operation op1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
        private Operation op2 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
        ComposeAction( Operation op1, Operation op2 )
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
            this.op1 = op1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
            this.op2 = op2 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            return op2.operate( op1.operate( value ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            return "composition(" + op1 + "," + op2 + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
    public static Operation compose( Operation op1, Operation op2 )
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        return new ComposeAction( op1, op2 ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    private static class MapAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
        Operation op ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
        MapAction( Operation op )
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
            this.op = op ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
            Object[] values = (Object[])value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
            Object[] result = new Object[ values.length ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
            for (int ctr=0; ctr<values.length; ctr++ )
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
                result[ctr] = op.operate( values[ctr] ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
            return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
            return "mapAction(" + op + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
    public static Operation mapAction( Operation op )
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
        return new MapAction( op ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
    private static class MapSequenceAction extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        private Operation[] op ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        public MapSequenceAction( Operation[] op )
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
            this.op = op ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
        // XXX Does this correctly handle array types?  It seems
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        // that hetereogeneous arrays work this way, while
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
        // homogeneous arrays need to use Array.newInstance tricks.
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
            Object[] values = (Object[])value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
            Object[] result = new Object[ values.length ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
            for (int ctr=0; ctr<values.length; ctr++ )
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
                result[ctr] = op[ctr].operate( values[ctr] ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
            return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            return "mapSequenceAction(" +
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                ObjectUtility.compactObjectToString(op) + ")" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    public static Operation mapSequenceAction( Operation[] op )
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
        return new MapSequenceAction( op ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
    private static class ConvertIntegerToShort extends OperationBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
        public Object operate( Object value )
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
            Integer val = (Integer)value ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
            return new Short( val.shortValue() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
            return "ConvertIntegerToShort" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
    private static Operation convertIntegerToShortImpl = new ConvertIntegerToShort() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
    public static Operation convertIntegerToShort()
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
        return convertIntegerToShortImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
}