1 package net.sf.saxon.instruct; 2 3 import net.sf.saxon.expr.*; 4 import net.sf.saxon.trans.XPathException; 5 import net.sf.saxon.type.ItemType; 6 import net.sf.saxon.type.SchemaType; 7 import net.sf.saxon.type.SimpleType; 8 import net.sf.saxon.om.Validation; 9 10 import java.util.Iterator ; 11 12 16 17 public abstract class ParentNodeConstructor extends Instruction { 18 19 protected Expression content; 20 private boolean lazyConstruction = false; 21 private boolean namespaceSensitiveType; 22 int validation = Validation.PRESERVE; 23 private SchemaType schemaType; 24 25 26 27 public ParentNodeConstructor() {} 28 29 33 34 public void setLazyConstruction(boolean lazy) { 35 lazyConstruction = lazy; 36 } 37 38 41 42 public final boolean isLazyConstruction() { 43 return lazyConstruction; 44 } 45 46 49 50 public void setSchemaType(SchemaType type) { 51 schemaType = type; 52 namespaceSensitiveType = (type instanceof SimpleType) && ((SimpleType)type).isNamespaceSensitive(); 53 } 54 55 58 59 public SchemaType getSchemaType() { 60 return schemaType; 61 } 62 63 66 67 public boolean isNamespaceSensitive() { 68 return namespaceSensitiveType; 69 } 70 71 75 public int getValidationAction() { 76 return validation; 77 } 78 79 82 83 public void setContentExpression(Expression content) { 84 this.content = content; 85 adoptChildExpression(content); 86 } 87 88 91 92 public Expression getContentExpression() { 93 return content; 94 } 95 96 97 104 105 public Expression simplify(StaticContext env) throws XPathException { 106 content = content.simplify(env); 107 return this; 108 } 109 110 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 111 content = content.typeCheck(env, contextItemType); 112 adoptChildExpression(content); 113 verifyLazyConstruction(); 114 return this; 115 } 116 117 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 118 content = content.optimize(opt, env, contextItemType); 119 adoptChildExpression(content); 120 return this; 121 } 122 123 124 129 130 protected void promoteInst(PromotionOffer offer) throws XPathException { 131 content = doPromotion(content, offer); 132 } 133 134 138 139 public Iterator iterateSubExpressions() { 140 return new MonoIterator(content); 141 } 142 143 147 148 public final boolean createsNewNodes() { 149 return true; 150 } 151 152 public int getCardinality() { 153 return StaticProperty.EXACTLY_ONE; 154 } 155 156 159 160 void verifyLazyConstruction() { 161 if (!isLazyConstruction()) { 162 return; 163 } 164 if ((getDependencies() & (StaticProperty.DEPENDS_ON_POSITION | StaticProperty.DEPENDS_ON_LAST)) != 0) { 167 setLazyConstruction(false); 168 } 169 if (validation == Validation.STRICT || validation == Validation.LAX 171 || schemaType != null) { 172 setLazyConstruction(false); 173 } 174 } 175 } 176 177 178 196 | Popular Tags |