1 23 package org.objectweb.medor.expression.lib; 24 25 import org.objectweb.jorm.type.api.PType; 26 import org.objectweb.jorm.type.api.PTypeSpace; 27 import org.objectweb.medor.expression.api.TypingException; 28 import org.objectweb.medor.expression.api.VariableOperand; 29 30 import java.util.Date ; 31 32 public class BasicVariableOperand 33 extends BasicOperand 34 implements VariableOperand { 35 36 public BasicVariableOperand() { 37 super(); 38 } 39 public BasicVariableOperand(BasicOperand p) { 40 super(p); 41 } 42 public BasicVariableOperand(PType p) { 43 super(p); 44 } 45 46 public BasicVariableOperand(boolean b) { 47 super(b); 48 } 49 50 public BasicVariableOperand(char p) { 51 super(p); 52 } 53 54 public BasicVariableOperand(byte p) { 55 super(p); 56 } 57 58 public BasicVariableOperand(short p) { 59 super(p); 60 } 61 62 public BasicVariableOperand(int p) { 63 super(p); 64 } 65 66 public BasicVariableOperand(long p) { 67 super(p); 68 } 69 70 public BasicVariableOperand(float p) { 71 super(p); 72 } 73 74 public BasicVariableOperand(double p) { 75 super(p); 76 } 77 78 public BasicVariableOperand(String p) { 79 super(p); 80 } 81 82 public BasicVariableOperand(Date p) { 83 super(p); 84 } 85 86 public void setType(PType type) { 87 longValue = 0; 88 doubleValue = 0; 89 objectValue = null; 90 this.type = type; 91 } 92 93 public void setValue(boolean p) throws TypingException { 94 if (PTypeSpace.BOOLEAN.isa(type)) { 95 longValue = (p ? 1 : 0); 96 doubleValue = (p ? 1 : 0); 97 } else 98 throw new TypingException("This Operand can not store a boolean value"); 99 } 100 101 public void setValue(int p) throws TypingException { 102 if (PTypeSpace.INT.isa(type)) { 103 longValue = p; 104 doubleValue = p; 105 } else 106 throw new TypingException("This Operand can not store an integer value " + type.getTypeCode()); 107 } 108 109 public void setValue(byte p) throws TypingException { 110 if (PTypeSpace.BYTE.isa(type)) { 111 longValue = p; 112 doubleValue = p; 113 } else 114 throw new TypingException("This Operand can not store a byte value"); 115 } 116 117 118 public void setValue(short p) throws TypingException { 119 if (PTypeSpace.SHORT.isa(type)) { 120 longValue = p; 121 doubleValue = p; 122 } else 123 throw new TypingException("This Operand can not store a short value"); 124 } 125 126 127 public void setValue(long p) throws TypingException { 128 if (PTypeSpace.LONG.isa(type)) { 129 longValue = p; 130 doubleValue = p; 131 } else 132 throw new TypingException("This Operand can not store a long value"); 133 } 134 135 public void setValue(float p) throws TypingException { 136 if (PTypeSpace.FLOAT.isa(type)) { 137 doubleValue = p; 138 } else 139 throw new TypingException("This Operand can not store a float value"); 140 } 141 142 public void setValue(double p) throws TypingException { 143 if (PTypeSpace.DOUBLE.isa(type)) { 144 doubleValue = p; 145 } else 146 throw new TypingException("This Operand can not store a double value"); 147 } 148 149 public void setValue(char p) throws TypingException { 150 if (PTypeSpace.CHAR.isa(type)) { 151 doubleValue = p; 152 longValue = p; 153 } else 154 throw new TypingException("This Operand can not store a CHAR value"); 155 } 156 157 public void setValue(String p) throws TypingException { 158 if (PTypeSpace.STRING.isa(type)) { 159 objectValue = p; 160 } else 161 throw new TypingException("This Operand can not store a string value " + type.getJavaName()); 162 } 163 164 public void setValue(Date p) throws TypingException { 165 objectValue = p; 166 } 167 168 169 public void setValue(Object p) throws TypingException { 170 objectValue = p; 171 switch(type.getTypeCode()) { 172 case PType.TYPECODE_BOOLEAN: 173 longValue = ((Boolean ) p).booleanValue() ? 1 : 0; 174 doubleValue = longValue; 175 break; 176 case PType.TYPECODE_BYTE: 177 longValue = ((Byte ) p).byteValue(); 178 doubleValue = longValue; 179 break; 180 case PType.TYPECODE_CHAR: 181 longValue = ((Character ) p).charValue(); 182 doubleValue = longValue; 183 break; 184 case PType.TYPECODE_SHORT: 185 longValue = ((Short ) p).shortValue(); 186 doubleValue = longValue; 187 break; 188 case PType.TYPECODE_INT: 189 longValue = ((Integer ) p).intValue(); 190 doubleValue = longValue; 191 break; 192 case PType.TYPECODE_LONG: 193 longValue = ((Long ) p).longValue(); 194 doubleValue = longValue; 195 break; 196 case PType.TYPECODE_FLOAT: 197 doubleValue = ((Float ) p).floatValue(); 198 break; 199 case PType.TYPECODE_DOUBLE: 200 doubleValue = ((Double ) p).doubleValue(); 201 break; 202 } 203 } 204 } 205 | Popular Tags |