1 22 23 package org.xquark.xquery.parser; 24 25 import java.util.*; 26 27 import org.xquark.xquery.typing.TypeException; 28 29 public class TypeSwitchExpression extends XQueryBinaryOperatorExpression implements Cloneable { 30 31 private static final String RCSRevision = "$Revision: 1.9 $"; 32 private static final String RCSName = "$Name: $"; 33 34 protected HashMap cases = null; 36 protected Variable defaultVariable = null; 38 39 43 public void accept(ParserVisitor visitor) throws XQueryException { 44 visitor.visit(this); 45 } 46 47 51 public TypeSwitchExpression(XQueryExpression switchExpression, HashMap cases, Variable defaultVariable, XQueryExpression defaultExpression, XQueryModule parentModule) throws TypeException, XQueryException { 52 super(switchExpression, defaultExpression); 53 setCases(cases); 54 setDefaultVariable(defaultVariable); 55 setParentModule(parentModule); 56 if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null) 57 accept(parentModule.getStaticContext().getTypeVisitor()); 58 } 59 60 64 public void setParentModule(XQueryModule parentUnit) { 65 if (parentUnit == null) 66 return; 67 this.parentModule = parentUnit; 68 super.setParentModule(parentUnit); 69 Set entries = cases.entrySet(); 70 Iterator it = entries.iterator(); 71 while (it.hasNext()) { 72 Map.Entry entry = (Map.Entry) it.next(); 73 ((QName) entry.getKey()).setParentModule(parentUnit); 74 ((XQueryExpression) entry.getValue()).setParentModule(parentUnit); 75 } 76 if (defaultVariable != null) 77 defaultVariable.setParentModule(parentUnit); 78 } 79 80 public HashMap getCases() { 81 return cases; 82 } 83 84 public void setCases(HashMap cases) throws XQueryException { 85 if (cases == null) 87 throw new XQueryException("Cases of TypeSwitchExpression cannot be null."); 88 this.cases = cases; 89 Set entries = cases.entrySet(); 90 Iterator it = entries.iterator(); 91 while (it.hasNext()) { 92 Map.Entry entry = (Map.Entry) it.next(); 93 QName qname = (QName) entry.getKey(); 94 qname.setParentModule(parentModule); 95 qname.setParentExpression(this); 96 XQueryExpression expr = (XQueryExpression) entry.getValue(); 97 expr.setParentModule(parentModule); 98 expr.setParentExpression(this); 99 } 100 } 101 102 public Variable getDefaultVariable() { 103 return defaultVariable; 104 } 105 106 public void setDefaultVariable(Variable defaultVariable) throws XQueryException { 107 this.defaultVariable = defaultVariable; 108 if (defaultVariable != null) { 109 this.defaultVariable.setParentModule(parentModule); 110 this.defaultVariable.setParentExpression(this); 111 } 112 } 113 114 public void addParentExpression(XQueryExpression parentExpression) { 118 addParentExpression(parentExpression); 119 if (defaultVariable != null) 120 defaultVariable.addParentExpression(parentExpression); 121 Set entries = cases.entrySet(); 122 Iterator it = entries.iterator(); 123 while (it.hasNext()) { 124 Map.Entry entry = (Map.Entry) it.next(); 125 ((QName) entry.getKey()).addParentExpression(parentExpression); 126 ((XQueryExpression) entry.getValue()).addParentExpression(parentExpression); 127 } 128 } 129 130 } 131 | Popular Tags |