KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > expression > lib > BasicOperator


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, S. Chassande-Barrioz, A. Lefebvre
22  */

23 package org.objectweb.medor.expression.lib;
24
25 import org.objectweb.jorm.type.api.PType;
26 import org.objectweb.medor.expression.api.Expression;
27 import org.objectweb.medor.expression.api.Operator;
28 import org.objectweb.medor.expression.api.VariableOperand;
29 import org.objectweb.util.monolog.api.BasicLevel;
30
31 /**
32  * @author A. Lefebvre
33  */

34 public abstract class BasicOperator extends BasicExpression implements Operator {
35
36     protected VariableOperand result = null;
37     protected boolean verified = false;
38     protected Expression[] expressions;
39
40     public BasicOperator() {
41     }
42
43     public BasicOperator(Expression[] expressions) {
44         this.expressions = expressions;
45     }
46
47     public BasicOperator(PType type) {
48         super(type);
49     }
50
51     public BasicOperator(PType type, Expression[] expressions) {
52         super(type);
53         this.expressions = expressions;
54     }
55
56     public Object JavaDoc clone(Object JavaDoc clone, java.util.Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
57         clone = super.clone(clone, obj2clone);
58         BasicOperator bo = (BasicOperator) clone;
59         bo.result = (VariableOperand) getClone(result, obj2clone);
60         bo.verified = verified;
61         if (expressions != null) {
62             bo.expressions = new Expression[expressions.length];
63             //when cloning an array, the elements are not cloned
64
for(int i=0; i<expressions.length; i++) {
65                 if (expressions[i] != null) {
66                     bo.expressions[i] =(Expression) getClone(expressions[i], obj2clone);
67                 }
68             }
69         }
70         return clone;
71     }
72
73     // IMPLEMENTATION OF THE Expression INTERFACE //
74
//--------------------------------------------//
75

76     public Expression getExpression(int i) {
77         if (expressions == null) {
78             logger.log(BasicLevel.FATAL, "Operand of the operaor "
79                 + getOperatorString(), new NullPointerException JavaDoc());
80         }
81         return expressions[i];
82     }
83
84     public synchronized void setExpression(int idx, Expression e) {
85         if (expressions == null) {
86             expressions = new Expression[idx + 1];
87             logger.log(BasicLevel.WARN,
88                 "Allocation of the operand array (" + idx + ") for the operator "
89                 + getOperatorString());
90         } else if (idx >= expressions.length){
91             Expression[] neo = new Expression[idx + 1];
92             System.arraycopy(expressions, 0, neo, 0, expressions.length);
93             expressions = neo;
94             logger.log(BasicLevel.WARN,
95                 "Reallocation " + expressions.length + " to " + idx
96                 + "of the operand array for the operator "
97                 + getOperatorString());
98         }
99         expressions[idx] = e;
100     }
101
102     public int getOperandNumber() {
103         return expressions.length;
104     }
105 }
106
Popular Tags