View Javadoc
1   /**
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Intalio, Inc.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Intalio, Inc. Exolab is a registered
23   *    trademark of Intalio, Inc.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2000 (C) Intalio Inc. All Rights Reserved.
42   *
43   * $Id$
44   */
45  
46  package org.exolab.castor.xml.dtd;
47  
48  /**
49   * Implementation of DTD Notation declaration specification.
50   * @author <a href="mailto:totok@intalio.com">Alexander Totok</a>
51   * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
52   */
53  public class Notation {
54  
55     private static final short PUBLIC = 0;
56     private static final short SYSTEM = 0;
57  
58     /**
59      * Name of the notation.
60      */
61     private String name;
62  
63     /**
64      * DTD document owning this Notation.
65      */
66     private DTDdocument document;
67  
68     /**
69      * Type of the notation. Value may be the {@link #PUBLIC PUBLIC} -
70      * {@link #pubIdentifier pubIdentifier} and {@link #sysIdentifier sysIdentifier}
71      * are specified, {@link #SYSTEM SYSTEM} - the
72      * {@link #sysIdentifier sysIdentifier} only is specified, or -1
73      * if unspecified.
74      */
75     private short type = -1;
76  
77     /**
78      * <b>Public identifier</b> of the notation.
79      */
80     private String pubIdentifier = null;
81  
82     /**
83      * <b>System identifier</b> of the notation.
84      */
85     private String sysIdentifier = null;
86  
87     /**
88      * Constructor, setting name and owning DTD document of the notation.
89      * @param document must not be null.
90      * @param name must not be null or equal to empty String.
91      */
92     public Notation(DTDdocument document, String name) {
93        if (document == null) {
94           String err = "Notation constructor: document must not be null";
95           throw new IllegalArgumentException(err);
96        }
97  
98        if (name == null || name.equals("")) {
99           String err = "Notation constructor: name must not be empty.";
100          throw new IllegalArgumentException(err);
101       }
102 
103       this.name = name;
104       this.document = document;
105    } //-- Notation
106 
107    /**
108     * Returns the name of the notation.
109     */
110    public String getName() {
111       return name;
112    } //-- getName
113 
114    /**
115     * Returns DTD document owning this notation.
116     */
117    public DTDdocument getDocument() {
118       return document;
119    } //-- getDocument
120 
121    /**
122     * Sets the notation to <tt>PUBLIC</tt>.
123     * @param pubId public identifier - must not be <tt>null</tt>.
124     * @param sysId system identifier - must not be <tt>null</tt>.
125     */
126    public void setPublic(String pubId, String sysId) {
127       if (pubId == null) {
128          String err = "Notation: can not set null public ID.";
129          throw new IllegalArgumentException(err);
130       }
131 
132       if (sysId == null) {
133          String err = "Notation: can not set null system ID.";
134          throw new IllegalArgumentException(err);
135       }
136 
137       type = PUBLIC;
138       pubIdentifier = pubId;
139       sysIdentifier = sysId;
140    } //-- setPublic
141 
142    /**
143     * <b>True</b> if <tt>PUBLIC</tt> notation, <b>false</b> otherwise.
144     */
145    public boolean isPublic() {
146       return type == PUBLIC;
147    } //-- isPublic()
148 
149    /**
150     * Sets the notation to <tt>SYSTEM</tt>.
151     * @param sysId system identifier - must not be <tt>null</tt>.
152     */
153    public void setSystem(String sysId) {
154       if (sysId == null) {
155          String err = "Notation: can not set null system ID.";
156          throw new IllegalArgumentException(err);
157       }
158 
159       type = SYSTEM;
160       sysIdentifier = sysId;
161    } //-- setSystem
162 
163    /**
164     * <b>True</b> if <tt>SYSTEM</tt> notation, <b>false</b> otherwise.
165     */
166    public boolean isSystem() {
167       return type == SYSTEM;
168    } //-- isSystem
169 
170    /**
171     * Returns public identifier.
172     */
173    public String getPubIdentifier() {
174       return pubIdentifier;
175    } //-- getPubIdentifier
176 
177    /**
178     * Returns system identifier.
179     */
180    public String getSysIdentifier() {
181       return sysIdentifier;
182    } //-- getSysIdentifier
183 
184 } //-- Notation