BooleanOr.java revision 608:7e06bf1dcb09
150477Speter/*
21598Srgrimes * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3156813Sru * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4156813Sru *
558284Speter * This code is free software; you can redistribute it and/or modify it
6156813Sru * under the terms of the GNU General Public License version 2 only, as
7116865Speter * published by the Free Software Foundation.  Oracle designates this
8129269Scognet * particular file as subject to the "Classpath" exception as provided
91598Srgrimes * by Oracle in the LICENSE file that accompanied this code.
10143145Sgrog *
11180627Smaxim * This code is distributed in the hope that it will be useful, but WITHOUT
12180627Smaxim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13171245Sbz * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14180627Smaxim * version 2 for more details (a copy is included in the LICENSE file that
15180627Smaxim * accompanied this code).
16180428Sobrien *
17180627Smaxim * You should have received a copy of the GNU General Public License version
18180428Sobrien * 2 along with this work; if not, write to the Free Software Foundation,
19180428Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20180428Sobrien *
21143145Sgrog * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22124610Sru * or visit www.oracle.com if you need additional information or have any
23143145Sgrog * questions.
2461744Sobrien */
2561744Sobrien/*
2661744Sobrien * COMPONENT_NAME: idl.parser
2761744Sobrien *
2827356Sjkh * ORIGINS: 27
2927356Sjkh *
30171245Sbz * Licensed Materials - Property of IBM
31179174Sobrien * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32179174Sobrien * RMI-IIOP v1.0
33179174Sobrien *
34143145Sgrog */
35179174Sobrien
36179174Sobrienpackage com.sun.tools.corba.se.idl.constExpr;
37179174Sobrien
38143145Sgrog// NOTES:
39179174Sobrien
40179174Sobrienimport com.sun.tools.corba.se.idl.Util;
41179174Sobrienimport java.math.BigInteger;
42171245Sbz
43179174Sobrienpublic class BooleanOr extends BinaryExpr
44143145Sgrog{
45179174Sobrien  protected BooleanOr (Expression leftOperand, Expression rightOperand)
46143145Sgrog  {
47181432Sphilip    super ("||", leftOperand, rightOperand);
48181432Sphilip  } // ctor
49181432Sphilip
50181432Sphilip  public Object evaluate () throws EvaluationException
51181432Sphilip  {
52181432Sphilip    try
53181432Sphilip    {
541598Srgrimes      Object tmpL = left ().evaluate ();
55      Object tmpR = right ().evaluate ();
56      Boolean l;
57      Boolean r;
58
59      //daz   if (tmpL instanceof Number)
60      //        l = new Boolean (((Number)tmpL).longValue () != 0);
61      //      else
62      //        l = (Boolean)tmpL;
63      if (tmpL instanceof Number)
64      {
65        if (tmpL instanceof BigInteger)
66          l = new Boolean (((BigInteger)tmpL).compareTo (zero) != 0);
67        else
68          l = new Boolean (((Number)tmpL).longValue () != 0);
69      }
70      else
71        l = (Boolean)tmpL;
72      //daz   if (tmpR instanceof Number)
73      //        r = new Boolean (((Number)tmpR).longValue () != 0);
74      //      else
75      //        r = (Boolean)tmpR;
76      if (tmpR instanceof Number)
77      {
78        if (tmpR instanceof BigInteger)
79          r = new Boolean (((BigInteger)tmpR).compareTo (BigInteger.valueOf (0)) != 0);
80        else
81          r = new Boolean (((Number)tmpR).longValue () != 0);
82      }
83      else
84        r = (Boolean)tmpR;
85      value (new Boolean (l.booleanValue () || r.booleanValue ()));
86    }
87    catch (ClassCastException e)
88    {
89      String[] parameters = {Util.getMessage ("EvaluationException.booleanOr"), left ().value ().getClass ().getName (), right ().value ().getClass ().getName ()};
90      throw new EvaluationException (Util.getMessage ("EvaluationException.1", parameters));
91    }
92    return value ();
93  } // evaluate
94} // class BooleanOr
95