01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10: * for the specific language governing rights and limitations under the
11: * License.
12: *
13: * The Original Code is Riot.
14: *
15: * The Initial Developer of the Original Code is
16: * Neteye GmbH.
17: * Portions created by the Initial Developer are Copyright (C) 2006
18: * the Initial Developer. All Rights Reserved.
19: *
20: * Contributor(s):
21: * Felix Gnass [fgnass at neteye dot de]
22: *
23: * ***** END LICENSE BLOCK ***** */
24: package org.riotfamily.revolt.definition;
25:
26: import org.springframework.util.StringUtils;
27:
28: /**
29: * Abstract base for all classes that represent a named component within
30: * a database definition, like tables, columns and constraints.
31: *
32: * @see DefinitionUtils
33: * @author Felix Gnass [fgnass at neteye dot de]
34: */
35: public class Identifier {
36:
37: public static final String QUOTED_DELIMITER = "`";
38:
39: private String name;
40:
41: private boolean quoted;
42:
43: public Identifier() {
44: }
45:
46: public Identifier(String name) {
47: setName(name);
48: }
49:
50: public String getName() {
51: return this .name;
52: }
53:
54: public void setName(String name) {
55: if (name != null && name.startsWith(QUOTED_DELIMITER)
56: && name.endsWith(QUOTED_DELIMITER)) {
57:
58: quoted = true;
59: name = StringUtils.delete(name, QUOTED_DELIMITER);
60: }
61: this .name = name;
62: }
63:
64: public boolean isQuoted() {
65: return this .quoted;
66: }
67:
68: public void setQuoted(boolean quoted) {
69: this .quoted = quoted;
70: }
71:
72: public int hashCode() {
73: return getName() == null ? 0 : getName().toUpperCase()
74: .hashCode();
75: }
76:
77: public boolean equals(Object obj) {
78: if (this == obj) {
79: return true;
80: }
81: if (name == null) {
82: return false;
83: }
84: if (!(obj instanceof Identifier)) {
85: return false;
86: }
87: Identifier other = (Identifier) obj;
88: return name.equals(other.name)
89: || (quoted == other.quoted && name
90: .equalsIgnoreCase(other.name));
91: }
92:
93: public String toString() {
94: return name;
95: }
96:
97: }
|