| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.instruct.Actor; |
| 11 |
import net.sf.saxon.expr.instruct.AttributeSet; |
| 12 |
import net.sf.saxon.expr.instruct.GlobalVariable; |
| 13 |
import net.sf.saxon.expr.instruct.NamedTemplate; |
| 14 |
import net.sf.saxon.om.Function; |
| 15 |
import net.sf.saxon.om.StandardNames; |
| 16 |
import net.sf.saxon.style.StylesheetPackage; |
| 17 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 18 |
import net.sf.saxon.trans.Mode; |
| 19 |
import net.sf.saxon.trans.Visibility; |
| 20 |
import net.sf.saxon.trans.VisibilityProvenance; |
| 21 |
import net.sf.saxon.trans.XPathException; |
| 22 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 23 |
|
| 24 |
import java.util.ArrayList; |
| 25 |
import java.util.List; |
| 26 |
import java.util.Map; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class Component { |
| 34 |
|
| 35 |
protected Actor actor; |
| 36 |
private Visibility visibility; |
| 37 |
private List<ComponentBinding> bindings = new ArrayList<ComponentBinding>(); |
| 38 |
private StylesheetPackage containingPackage; |
| 39 |
private StylesheetPackage declaringPackage; |
| 40 |
private VisibilityProvenance provenance; |
| 41 |
private Component baseComponent; |
| 42 |
|
| 43 |
|
| 44 |
private Component() {} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public static Component makeComponent( |
| 56 |
Actor actor, Visibility visibility, VisibilityProvenance provenance, StylesheetPackage containingPackage, StylesheetPackage declaringPackage) { |
| 57 |
Component c; |
| 58 |
if (actor instanceof Mode) { |
| 59 |
c = new M(); |
| 60 |
} else { |
| 61 |
c = new Component(); |
| 62 |
} |
| 63 |
c.actor = actor; |
| 64 |
c.visibility = visibility; |
| 65 |
c.provenance = provenance; |
| 66 |
c.containingPackage = containingPackage; |
| 67 |
c.declaringPackage = declaringPackage; |
| 68 |
return c; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public List<ComponentBinding> getComponentBindings() { |
| 80 |
return bindings; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public void setComponentBindings(List<ComponentBinding> bindings) { |
| 92 |
this.bindings = bindings; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public void setVisibility(Visibility visibility, VisibilityProvenance provenance) { |
| 102 |
this.visibility = visibility; |
| 103 |
this.provenance = provenance; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public Visibility getVisibility() { |
| 115 |
return visibility; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public VisibilityProvenance getVisibilityProvenance() { |
| 126 |
return provenance; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public boolean isHiddenAbstractComponent() { |
| 136 |
return visibility == Visibility.HIDDEN && baseComponent != null && |
| 137 |
baseComponent.getVisibility() == Visibility.ABSTRACT; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public Actor getActor() { |
| 148 |
return actor; |
| 149 |
} |
| 150 |
|
| 151 |
public int getComponentKind() { |
| 152 |
if (actor instanceof NamedTemplate) { |
| 153 |
return StandardNames.XSL_TEMPLATE; |
| 154 |
} else if (actor instanceof GlobalVariable) { |
| 155 |
return StandardNames.XSL_VARIABLE; |
| 156 |
} else if (actor instanceof Function) { |
| 157 |
return StandardNames.XSL_FUNCTION; |
| 158 |
} else if (actor instanceof AttributeSet) { |
| 159 |
return StandardNames.XSL_ATTRIBUTE_SET; |
| 160 |
} else if (actor instanceof Mode) { |
| 161 |
return StandardNames.XSL_MODE; |
| 162 |
} else { |
| 163 |
return -1; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
public StylesheetPackage getDeclaringPackage() { |
| 174 |
return declaringPackage; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public StylesheetPackage getContainingPackage() { |
| 184 |
return containingPackage; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public Component getBaseComponent() { |
| 197 |
return baseComponent; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public void setBaseComponent(Component original) { |
| 211 |
baseComponent = original; |
| 212 |
} |
| 213 |
|
| 214 |
public void export(ExpressionPresenter out, Map<Component, Integer> componentIdMap, |
| 215 |
Map<StylesheetPackage, Integer> packageIdMap) throws XPathException { |
| 216 |
out.startElement("co"); |
| 217 |
int id = obtainComponentId(this, componentIdMap); |
| 218 |
out.emitAttribute("id", ""+id); |
| 219 |
if (getVisibilityProvenance() != VisibilityProvenance.DEFAULTED) { |
| 220 |
out.emitAttribute("vis", getVisibility().toString()); |
| 221 |
} |
| 222 |
String refs = listComponentReferences(componentIdMap); |
| 223 |
out.emitAttribute("binds", refs); |
| 224 |
if (baseComponent != null && getActor() == baseComponent.getActor()) { |
| 225 |
int baseId = obtainComponentId(baseComponent, componentIdMap); |
| 226 |
out.emitAttribute("base", ""+baseId); |
| 227 |
out.emitAttribute("dpack", packageIdMap.get(declaringPackage)+""); |
| 228 |
} else { |
| 229 |
actor.export(out); |
| 230 |
} |
| 231 |
out.endElement(); |
| 232 |
} |
| 233 |
|
| 234 |
public String listComponentReferences(Map<Component, Integer> componentIdMap) { |
| 235 |
FastStringBuffer fsb = new FastStringBuffer(128); |
| 236 |
for (ComponentBinding ref : getComponentBindings()) { |
| 237 |
Component target = ref.getTarget(); |
| 238 |
int targetId = obtainComponentId(target, componentIdMap); |
| 239 |
if (fsb.length() != 0) { |
| 240 |
fsb.append(" "); |
| 241 |
} |
| 242 |
fsb.append("" + targetId); |
| 243 |
} |
| 244 |
return fsb.toString(); |
| 245 |
} |
| 246 |
|
| 247 |
private int obtainComponentId(Component component, Map<Component, Integer> componentIdMap) { |
| 248 |
Integer id = componentIdMap.get(component); |
| 249 |
if (id == null) { |
| 250 |
id = componentIdMap.size(); |
| 251 |
componentIdMap.put(component, id); |
| 252 |
} |
| 253 |
return id; |
| 254 |
} |
| 255 |
|
| 256 |
public static class M extends Component { |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
@Override |
| 265 |
public Mode getActor() { |
| 266 |
return (Mode)super.getActor(); |
| 267 |
} |
| 268 |
|
| 269 |
public void setActor(Mode m) { |
| 270 |
this.actor = m; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
} |
| 275 |
|