001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.feature.type;
017:
018: import org.geotools.resources.Utilities;
019:
020: /**
021: * Simple implementation of TypeName.
022: *
023: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
024: *
025: */
026: public class TypeName implements org.opengis.feature.type.TypeName {
027: /** namespace / scope */
028: protected String namespace;
029:
030: /** local part */
031: protected String local;
032:
033: /**
034: * Constructs an instance with the local part set. Namespace / scope is
035: * set to null.
036: *
037: * @param local The local part of the name.
038: */
039: public TypeName(String local) {
040: this (null, local);
041: }
042:
043: /**
044: * Constructs an instance with the local part and namespace set.
045: *
046: * @param namespace The namespace or scope of the name.
047: * @param local The local part of the name.
048: *
049: */
050: public TypeName(String namespace, String local) {
051: this .namespace = namespace;
052: this .local = local;
053: }
054:
055: public boolean isGlobal() {
056: return getNamespaceURI() == null;
057: }
058:
059: public String getNamespaceURI() {
060: return namespace;
061: }
062:
063: public String getLocalPart() {
064: return local;
065: }
066:
067: public String getURI() {
068: if ((namespace == null) && (local == null)) {
069: return null;
070: }
071:
072: if (namespace == null) {
073: return local;
074: }
075:
076: if (local == null) {
077: return namespace;
078: }
079:
080: return new StringBuffer(namespace).append(':').append(local)
081: .toString();
082: }
083:
084: /**
085: * value object with equality based on name and namespace.
086: */
087: public int hashCode() {
088: String uri = getURI();
089:
090: return (uri != null) ? uri.hashCode() : 0;
091: }
092:
093: /**
094: * value object with equality based on name and namespace.
095: */
096: public boolean equals(Object obj) {
097: if (obj instanceof TypeName) {
098: TypeName other = (TypeName) obj;
099:
100: return Utilities.equals(getURI(), other.getURI());
101: }
102:
103: return false;
104: }
105:
106: /** name or namespace:name */
107: public String toString() {
108: return getURI();
109: }
110: }
|