1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import oracle.toplink.essentials.expressions.*; 25 26 33 public class TrimNode extends StringFunctionNode { 34 35 private Node trimChar; 36 private boolean leading; 37 private boolean trailing; 38 private boolean both; 39 40 43 public TrimNode() { 44 super(); 45 } 46 47 51 public void validate(ParseTreeContext context) { 52 TypeHelper typeHelper = context.getTypeHelper(); 53 if (left != null) { 54 left.validate(context); 55 left.validateParameter(context, typeHelper.getStringType()); 56 } 57 if (trimChar != null) { 58 trimChar.validate(context); 59 trimChar.validateParameter(context, typeHelper.getCharType()); 60 } 61 setType(typeHelper.getStringType()); 62 } 63 64 68 public Expression generateExpression(GenerationContext context) { 69 Expression whereClause = getLeft().generateExpression(context); 70 if (leading) { 71 if (trimChar != null) { 73 Expression trimCharExpr = trimChar.generateExpression(context); 74 whereClause = whereClause.leftTrim(trimCharExpr); 75 } else { 76 whereClause = whereClause.leftTrim(); 77 } 78 } else if (trailing) { 79 if (trimChar != null) { 80 Expression trimCharExpr = trimChar.generateExpression(context); 81 whereClause = whereClause.rightTrim(trimCharExpr); 82 } else { 83 whereClause = whereClause.rightTrim(); 84 } 85 } else { 86 if (trimChar != null) { 87 Expression trimCharExpr = trimChar.generateExpression(context); 88 whereClause = whereClause.leftTrim(trimCharExpr).rightTrim(trimCharExpr); 89 } else { 90 whereClause = whereClause.leftTrim().rightTrim(); 91 } 92 } 93 return whereClause; 94 } 95 96 97 public void setTrimChar(Node trimChar) { 98 this.trimChar = trimChar; 99 } 100 101 102 public boolean isLeading() { 103 return leading; 104 } 105 106 107 public void setLeading(boolean newLeading) { 108 this.leading = newLeading; 109 } 110 111 112 public boolean isTrailing() { 113 return trailing; 114 } 115 116 117 public void setTrailing(boolean newTrailing) { 118 this.trailing = newTrailing; 119 } 120 121 122 public boolean isBoth() { 123 return both; 124 } 125 126 127 public void setBoth(boolean newBoth) { 128 this.both = newBoth; 129 } 130 131 } 132 | Popular Tags |