01: package com.sun.xml.xsom.impl;
02:
03: import com.sun.xml.xsom.XSElementDecl;
04: import com.sun.xml.xsom.XSIdentityConstraint;
05: import com.sun.xml.xsom.XSXPath;
06: import com.sun.xml.xsom.impl.parser.SchemaDocumentImpl;
07: import com.sun.xml.xsom.visitor.XSFunction;
08: import com.sun.xml.xsom.visitor.XSVisitor;
09: import org.xml.sax.Locator;
10:
11: import java.util.Collections;
12: import java.util.List;
13:
14: /**
15: * {@link XSIdentityConstraint} implementation.
16: *
17: * @author Kohsuke Kawaguchi
18: */
19: public class IdentityConstraintImpl extends ComponentImpl implements
20: XSIdentityConstraint, Ref.IdentityConstraint {
21:
22: private XSElementDecl parent;
23: private final short category;
24: private final String name;
25: private final XSXPath selector;
26: private final List<XSXPath> fields;
27: private final Ref.IdentityConstraint refer;
28:
29: public IdentityConstraintImpl(SchemaDocumentImpl _owner,
30: AnnotationImpl _annon, Locator _loc,
31: ForeignAttributesImpl fa, short category, String name,
32: XPathImpl selector, List<XPathImpl> fields,
33: Ref.IdentityConstraint refer) {
34:
35: super (_owner, _annon, _loc, fa);
36: this .category = category;
37: this .name = name;
38: this .selector = selector;
39: selector.setParent(this );
40: this .fields = Collections
41: .unmodifiableList((List<? extends XSXPath>) fields);
42: for (XPathImpl xp : fields)
43: xp.setParent(this );
44: this .refer = refer;
45: }
46:
47: public void visit(XSVisitor visitor) {
48: visitor.identityConstraint(this );
49: }
50:
51: public <T> T apply(XSFunction<T> function) {
52: return function.identityConstraint(this );
53: }
54:
55: public void setParent(ElementDecl parent) {
56: this .parent = parent;
57: parent.getOwnerSchema().addIdentityConstraint(this );
58: }
59:
60: public XSElementDecl getParent() {
61: return parent;
62: }
63:
64: public String getName() {
65: return name;
66: }
67:
68: public String getTargetNamespace() {
69: return getParent().getTargetNamespace();
70: }
71:
72: public short getCategory() {
73: return category;
74: }
75:
76: public XSXPath getSelector() {
77: return selector;
78: }
79:
80: public List<XSXPath> getFields() {
81: return fields;
82: }
83:
84: public XSIdentityConstraint getReferencedKey() {
85: if (category == KEYREF)
86: return refer.get();
87: else
88: throw new IllegalStateException("not a keyref");
89: }
90:
91: public XSIdentityConstraint get() {
92: return this;
93: }
94: }
|