KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > schema > SchemaComponent


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.schema;
24
25 /**
26  * Abstract class for schema component such as Declaration and Type.
27  *
28  * <p>This is the implementation of the common propertoes of Declaration,
29  * Type, and IdentityConstraint. The following properties are defined :</p>
30  * <p> 1. name : a NCName as defined by [XML-Namespaces].</p>
31  * <p> 2. target namespace : represented by a schema deinition. </p>
32  *
33  * <p>See XML Schema Part 1: Structures 3.2, 3.3, 3.4, 3.11, 3.14
34  * W3C Recommendation 2 May 2001</p>
35  *
36  * @see org.xquark.xml.schema.Declaration
37  * @see org.xquark.xml.schema.Type
38  * @see org.xquark.xml.schema.AttributeGroupDefinition
39  */

40 public abstract class SchemaComponent
41   implements SchemaConstants, SchemaVisitable {
42 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
43 private static final String JavaDoc RCSName = "$Name: $";
44   
45   protected Schema schema;
46   protected String JavaDoc name;
47
48   /**
49    * Create a new SchemaComponent.
50    *
51    * @param schema The schema which contains this component.
52    * @param name The component name, a NCName.
53    */

54   protected SchemaComponent(Schema schema, String JavaDoc name) {
55     this.schema = schema;
56     this.name = name;
57   }
58
59   public void accept(SchemaVisitor visitor) throws SchemaException {
60     visitor.visit(this);
61   }
62 /*
63   public String toString() {
64     return "#<"+getClass().getName()+" "+getNamespace()+":"+getName()+">";
65   }
66 */

67   public Schema getSchema() {
68     return schema;
69   }
70     
71   /**
72    * Return the component's name, if any.
73    *
74    * @return The component's name, or null if there is none.
75    */

76   public String JavaDoc getName() {
77     return name;
78   }
79   
80   /**
81    * Set the component's name.
82    */

83   public void setName(String JavaDoc name) { this.name = name; }
84
85   /**
86    * Return the component's name, if any.
87    *
88    * @return The component's name, or null if there is none.
89    */

90    public String JavaDoc toString() {
91     return name;
92   }
93   
94   /**
95    * Return the component's target namespace, if any.
96    *
97    * @return The target namespace, or null if the schema is null.
98    */

99   public String JavaDoc getNamespace() {
100     if (schema == null) return null;
101     return schema.getNamespace();
102   }
103
104   /**
105    * Returns the component's schema manager
106    *
107    * @return The schema manager, or null is the schema is null
108    */

109   public SchemaManager getManager() {
110     if (schema == null) return null;
111     return schema.getManager();
112   }
113
114   /**
115    * @return true if component is named and has the requested name
116    */

117   
118   public boolean hasName(String JavaDoc namespace, String JavaDoc localName) {
119     if (namespace != null && namespace.length() == 0) namespace = null;
120     return localName != null && localName.equals(getName()) &&
121       ((namespace == null && getNamespace() == null) ||
122        (namespace != null && namespace.equals(getNamespace())));
123   }
124
125 }
126
Popular Tags