001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2001 The Apache Software Foundation.
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.validators.schema.identity;
059:
060: /**
061: * Base class of Schema identity constraint.
062: *
063: * @author Andy Clark, IBM
064: * @version $Id: IdentityConstraint.java,v 1.4 2001/05/17 20:58:59 neilg Exp $
065: */
066: public abstract class IdentityConstraint {
067:
068: //
069: // Constants
070: //
071:
072: /** Type: unique. */
073: public static final short UNIQUE = 0;
074:
075: /** Type: key. */
076: public static final short KEY = 1;
077:
078: /** Type: key reference. */
079: public static final short KEYREF = 2;
080:
081: //
082: // Data
083: //
084:
085: /** Identity constraint name. */
086: protected String fIdentityConstraintName;
087:
088: /** Element name. */
089: protected String fElementName;
090:
091: /** Selector. */
092: protected Selector fSelector;
093:
094: /** Field count. */
095: protected int fFieldCount;
096:
097: /** Fields. */
098: protected Field[] fFields;
099:
100: //
101: // Constructors
102: //
103:
104: /** Default constructor. */
105: protected IdentityConstraint(String identityConstraintName,
106: String elementName) {
107: fIdentityConstraintName = identityConstraintName;
108: fElementName = elementName;
109: } // <init>(String,String)
110:
111: //
112: // Public methods
113: //
114:
115: /** Returns the identity constraint type. */
116: public abstract short getType();
117:
118: /** Returns the identity constraint name. */
119: public String getIdentityConstraintName() {
120: return fIdentityConstraintName;
121: } // getIdentityConstraintName():String
122:
123: /** Returns the element name. */
124: public String getElementName() {
125: return fElementName;
126: } // getElementName():String
127:
128: /** Sets the selector. */
129: public void setSelector(Selector selector) {
130: fSelector = selector;
131: } // setSelector(Selector)
132:
133: /** Returns the selector. */
134: public Selector getSelector() {
135: return fSelector;
136: } // getSelector():Selector
137:
138: /** Adds a field. */
139: public void addField(Field field) {
140: try {
141: fFields[fFieldCount] = null;
142: } catch (NullPointerException e) {
143: fFields = new Field[4];
144: } catch (ArrayIndexOutOfBoundsException e) {
145: Field[] newfields = new Field[fFields.length * 2];
146: System.arraycopy(fFields, 0, newfields, 0, fFields.length);
147: fFields = newfields;
148: }
149: fFields[fFieldCount++] = field;
150: } // addField(Field)
151:
152: /** Returns the field count. */
153: public int getFieldCount() {
154: return fFieldCount;
155: } // getFieldCount():int
156:
157: /** Returns the field at the specified index. */
158: public Field getFieldAt(int index) {
159: return fFields[index];
160: } // getFieldAt(int):Field
161:
162: //
163: // Object methods
164: //
165:
166: /** Returns a string representation of this object. */
167: public String toString() {
168: String s = super .toString();
169: int index1 = s.lastIndexOf('$');
170: if (index1 != -1) {
171: return s.substring(index1 + 1);
172: }
173: int index2 = s.lastIndexOf('.');
174: if (index2 != -1) {
175: return s.substring(index2 + 1);
176: }
177: return s;
178: } // toString():String
179:
180: // equals: returns true if and only if the String
181: // representations of all members of both objects (except for
182: // the elenemtName field) are equal.
183: public boolean equals(IdentityConstraint id) {
184: boolean areEqual = fIdentityConstraintName
185: .equals(id.fIdentityConstraintName);
186: if (!areEqual)
187: return false;
188: areEqual = fSelector.toString().equals(id.fSelector.toString());
189: if (!areEqual)
190: return false;
191: areEqual = (fFieldCount == id.fFieldCount);
192: if (!areEqual)
193: return false;
194: for (int i = 0; i < fFieldCount; i++)
195: if (!fFields[i].toString().equals(id.fFields[i].toString()))
196: return false;
197: return true;
198: } // equals
199:
200: } // class IdentityConstraint
|