KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > relaxng > pattern > NsNamePattern


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.relaxng.pattern;
31
32 import com.caucho.relaxng.RelaxException;
33 import com.caucho.relaxng.program.NameClassItem;
34 import com.caucho.relaxng.program.NsNameItem;
35
36 /**
37  * Relax name pattern
38  */

39 public class NsNamePattern extends NameClassPattern {
40   private String JavaDoc _name;
41   private String JavaDoc _ns;
42
43   private NameClassPattern _except;
44
45   private NsNameItem _item;
46   
47   /**
48    * Creates a new element pattern.
49    */

50   public NsNamePattern()
51   {
52   }
53
54   /**
55    * Creates a new element pattern.
56    */

57   public NsNamePattern(String JavaDoc ns)
58   {
59     _ns = ns;
60   }
61
62   /**
63    * Creates a new element pattern.
64    */

65   public NsNamePattern(String JavaDoc name, String JavaDoc ns)
66   {
67     _name = name;
68     _ns = ns;
69   }
70
71   public void setNamespace(String JavaDoc ns)
72   {
73     _ns = ns;
74   }
75
76   /**
77    * Returns the Relax schema name.
78    */

79   public String JavaDoc getTagName()
80   {
81     return "nsName";
82   }
83
84   /**
85    * Sets the except name pattern.
86    */

87   public void setExcept(NameClassPattern pattern)
88   {
89     _except = pattern;
90   }
91
92   /**
93    * Creates the program.
94    */

95   public NameClassItem createNameItem()
96     throws RelaxException
97   {
98     if (_item == null) {
99       NsNameItem item = new NsNameItem(_ns);
100
101       if (_except != null)
102     item.setExcept(_except.createNameItem());
103
104       _item = item;
105     }
106     
107     return _item;
108   }
109
110   /**
111    * Returns a string for the production.
112    */

113   public String JavaDoc toProduction()
114   {
115     if (_except == null)
116       return _ns + ":*";
117     else
118       return "(" + _ns + ":* - " + _except + ")";
119   }
120
121   public boolean equals(Object JavaDoc o)
122   {
123     if (this == o)
124       return true;
125
126     if (! (o instanceof NsNamePattern))
127       return false;
128
129     NsNamePattern pattern = (NsNamePattern) o;
130
131     if (! _ns.equals(pattern._ns))
132       return false;
133
134     if (_except == null)
135       return pattern._except == null;
136     else
137       return _except.equals(pattern._except);
138   }
139
140   /**
141    * Debugging.
142    */

143   public String JavaDoc toString()
144   {
145     return "NsName[" + _ns + "]";
146   }
147 }
148
149
Popular Tags