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