1 23 24 package org.objectweb.medor.expression.lib; 25 26 import org.objectweb.jorm.type.api.PType; 27 import org.objectweb.medor.expression.api.Operand; 28 import org.objectweb.medor.expression.api.ExpressionException; 29 import org.objectweb.medor.expression.api.ParameterOperand; 30 31 35 public class BasicParameterOperand 36 extends BasicVariableOperand 37 implements ParameterOperand { 38 39 protected String name = null; 40 41 public BasicParameterOperand() { 42 super(); 43 } 44 45 public BasicParameterOperand(BasicParameterOperand po) { 46 super(po); 47 this.name = po.getName(); 48 } 49 50 public BasicParameterOperand(PType type, String name) { 51 super(type); 52 this.name = name; 53 } 54 55 public BasicParameterOperand(PType type, String name, Object value) { 56 super(type); 57 this.name = name; 58 objectValue = value; 59 } 60 61 public BasicParameterOperand(PType type, String name, String value) { 62 super(type); 63 this.name = name; 64 objectValue = value; 65 } 66 67 public BasicParameterOperand(PType type, String name, boolean value) { 68 super(type); 69 this.name = name; 70 longValue = (value ? 1 : 0); 71 } 72 73 public BasicParameterOperand(PType type, String name, long value) { 74 super(type); 75 this.name = name; 76 longValue = value; 77 } 78 79 public BasicParameterOperand(PType type, String name, double value) { 80 super(type); 81 this.name = name; 82 doubleValue = value; 83 } 84 85 public Object clone(Object clone, java.util.Map obj2clone) throws CloneNotSupportedException { 86 clone = super.clone(clone, obj2clone); 87 ((BasicParameterOperand) clone).name = name; 88 return clone; 89 } 90 91 public String getName() { 92 return name; 93 } 94 95 public void setName(String n) { 96 name = n; 97 } 98 99 public Operand evaluate(ParameterOperand[] pos, Object o) 100 throws ExpressionException { 101 int i = 0; 102 while (i < pos.length 103 && pos[i].getType().getTypeCode() != type.getTypeCode() 104 && !pos[i].getName().equalsIgnoreCase(name)) { 105 i++; 106 } 107 if (i < pos.length) { 108 switch (type.getTypeCode()) { 109 case PType.TYPECODE_BOOLEAN: 110 setValue(pos[i].getBoolean()); 111 break; 112 case PType.TYPECODE_BYTE: 113 setValue(pos[i].getByte()); 114 break; 115 case PType.TYPECODE_CHAR: 116 setValue(pos[i].getChar()); 117 break; 118 case PType.TYPECODE_DATE: 119 setValue(pos[i].getDate()); 120 break; 121 case PType.TYPECODE_DOUBLE: 122 setValue(pos[i].getDouble()); 123 break; 124 case PType.TYPECODE_FLOAT: 125 setValue(pos[i].getFloat()); 126 break; 127 case PType.TYPECODE_INT: 128 setValue(pos[i].getInt()); 129 break; 130 case PType.TYPECODE_LONG: 131 setValue(pos[i].getLong()); 132 break; 133 case PType.TYPECODE_SHORT: 134 setValue(pos[i].getShort()); 135 break; 136 case PType.TYPECODE_STRING: 137 setValue(pos[i].getString()); 138 break; 139 case PType.TYPECODE_OBJBOOLEAN: 140 case PType.TYPECODE_OBJBYTE: 141 case PType.TYPECODE_OBJCHAR: 142 case PType.TYPECODE_OBJDOUBLE: 143 case PType.TYPECODE_OBJFLOAT: 144 case PType.TYPECODE_OBJINT: 145 case PType.TYPECODE_OBJLONG: 146 case PType.TYPECODE_OBJSHORT: 147 default: 148 objectValue = pos[i].getObject(); 149 break; 150 } 151 } 152 else 153 throw new ExpressionException("Parameter without value: " + this.getName()); 154 return this; 155 } 156 } 157 | Popular Tags |