001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.xsom.impl;
027:
028: import com.sun.xml.internal.xsom.XSElementDecl;
029: import com.sun.xml.internal.xsom.XSIdentityConstraint;
030: import com.sun.xml.internal.xsom.XSXPath;
031: import com.sun.xml.internal.xsom.impl.parser.SchemaDocumentImpl;
032: import com.sun.xml.internal.xsom.visitor.XSFunction;
033: import com.sun.xml.internal.xsom.visitor.XSVisitor;
034: import org.xml.sax.Locator;
035:
036: import java.util.Collections;
037: import java.util.List;
038:
039: /**
040: * {@link XSIdentityConstraint} implementation.
041: *
042: * @author Kohsuke Kawaguchi
043: */
044: public class IdentityConstraintImpl extends ComponentImpl implements
045: XSIdentityConstraint, Ref.IdentityConstraint {
046:
047: private XSElementDecl parent;
048: private final short category;
049: private final String name;
050: private final XSXPath selector;
051: private final List<XSXPath> fields;
052: private final Ref.IdentityConstraint refer;
053:
054: public IdentityConstraintImpl(SchemaDocumentImpl _owner,
055: AnnotationImpl _annon, Locator _loc,
056: ForeignAttributesImpl fa, short category, String name,
057: XPathImpl selector, List<XPathImpl> fields,
058: Ref.IdentityConstraint refer) {
059:
060: super (_owner, _annon, _loc, fa);
061: this .category = category;
062: this .name = name;
063: this .selector = selector;
064: selector.setParent(this );
065: this .fields = Collections
066: .unmodifiableList((List<? extends XSXPath>) fields);
067: for (XPathImpl xp : fields)
068: xp.setParent(this );
069: this .refer = refer;
070: }
071:
072: public void visit(XSVisitor visitor) {
073: visitor.identityConstraint(this );
074: }
075:
076: public <T> T apply(XSFunction<T> function) {
077: return function.identityConstraint(this );
078: }
079:
080: public void setParent(ElementDecl parent) {
081: this .parent = parent;
082: parent.getOwnerSchema().addIdentityConstraint(this );
083: }
084:
085: public XSElementDecl getParent() {
086: return parent;
087: }
088:
089: public String getName() {
090: return name;
091: }
092:
093: public String getTargetNamespace() {
094: return getParent().getTargetNamespace();
095: }
096:
097: public short getCategory() {
098: return category;
099: }
100:
101: public XSXPath getSelector() {
102: return selector;
103: }
104:
105: public List<XSXPath> getFields() {
106: return fields;
107: }
108:
109: public XSIdentityConstraint getReferencedKey() {
110: if (category == KEYREF)
111: return refer.get();
112: else
113: throw new IllegalStateException("not a keyref");
114: }
115:
116: public XSIdentityConstraint get() {
117: return this;
118: }
119: }
|