1 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 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 clone(Object clone, java.util.Map obj2clone) throws CloneNotSupportedException { 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 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 76 public Expression getExpression(int i) { 77 if (expressions == null) { 78 logger.log(BasicLevel.FATAL, "Operand of the operaor " 79 + getOperatorString(), new NullPointerException ()); 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 |