Source Code Cross Referenced for NameFactory.java in  » GIS » GeoTools-2.4.1 » org » geotools » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2004, Institut de Recherche pour le Développement
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.util;
018:
019:        // J2SE dependencies
020:        import java.util.ArrayList;
021:        import java.util.List;
022:        import java.util.Locale;
023:
024:        // OpenGIS dependencies
025:        import org.opengis.metadata.Identifier;
026:        import org.opengis.util.GenericName;
027:        import org.opengis.util.InternationalString;
028:
029:        // Geotools dependencies
030:        import org.geotools.resources.Utilities;
031:
032:        /**
033:         * A factory for {@link GenericName} objects.
034:         *
035:         * @since 2.1
036:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/util/NameFactory.java $
037:         * @version $Id: NameFactory.java 22443 2006-10-27 20:47:22Z desruisseaux $
038:         * @author  Martin Desruisseaux
039:         */
040:        public final class NameFactory {
041:            /**
042:             * Do not allows instantiation of instance of this class.
043:             */
044:            private NameFactory() {
045:            }
046:
047:            /**
048:             * Constructs a generic name from a fully qualified name
049:             * and the default separator character.
050:             *
051:             * @param name The fully qualified name.
052:             */
053:            public static GenericName create(final String name) {
054:                return create(name,
055:                        org.geotools.util.GenericName.DEFAULT_SEPARATOR);
056:            }
057:
058:            /**
059:             * Constructs a generic name from a fully qualified name
060:             * and the specified separator character.
061:             *
062:             * @param name The fully qualified name.
063:             * @param separator The separator character.
064:             */
065:            public static GenericName create(final String name,
066:                    final char separator) {
067:                final List names = new ArrayList();
068:                int lower = 0;
069:                while (true) {
070:                    final int upper = name.indexOf(separator, lower);
071:                    if (upper >= 0) {
072:                        names.add(name.substring(lower, upper));
073:                        lower = upper + 1;
074:                    } else {
075:                        names.add(name.substring(lower));
076:                        break;
077:                    }
078:                }
079:                return create((String[]) names
080:                        .toArray(new String[names.size()]), separator);
081:            }
082:
083:            /**
084:             * Constructs a generic name from an array of local names and the default separator character.
085:             * If any of the specified names is an {@link InternationalString}, then the
086:             * <code>{@linkplain InternationalString#toString(Locale) toString}(null)</code>
087:             * method will be used in order to fetch an unlocalized name. Otherwise, the
088:             * <code>{@linkplain CharSequence#toString toString}()</code> method will be used.
089:             *
090:             * @param names The local names as an array of strings or international strings.
091:             *              This array must contains at least one element.
092:             */
093:            public static GenericName create(final CharSequence[] names) {
094:                return create(names,
095:                        org.geotools.util.GenericName.DEFAULT_SEPARATOR);
096:            }
097:
098:            /**
099:             * Constructs a generic name from an array of local names and the specified separator character.
100:             * If any of the specified names is an {@link InternationalString}, then the
101:             * <code>{@linkplain InternationalString#toString(Locale) toString}(null)</code>
102:             * method will be used in order to fetch an unlocalized name. Otherwise, the
103:             * <code>{@linkplain CharSequence#toString toString}()</code> method will be used.
104:             *
105:             * @param names     The local names as an array of strings.
106:             *                  This array must contains at least one element.
107:             * @param separator The separator character to use.
108:             */
109:            public static GenericName create(final CharSequence[] names,
110:                    final char separator) {
111:                return create(names, names.length, separator);
112:            }
113:
114:            /**
115:             * Constructs a generic name from an array of local names
116:             * and the specified separator character.
117:             *
118:             * @param names     The local names as an array of strings.
119:             * @param length    The valid length of {@code names} array.
120:             * @param separator The separator character to use.
121:             */
122:            private static GenericName create(final CharSequence[] names,
123:                    final int length, final char separator) {
124:                if (length <= 0) {
125:                    throw new IllegalArgumentException(String.valueOf(length));
126:                }
127:                if (length == 1) {
128:                    return new LocalName(names[0]);
129:                }
130:                return new ScopedName(create(names, length - 1, separator),
131:                        separator, names[length - 1]);
132:            }
133:
134:            /**
135:             * Returns the specified name in an array. The {@code value} may be either a {@link String},
136:             * {@code String[]}, {@link GenericName} or {@code GenericName[]}. This method is used in
137:             * {@link org.geotools.referencing.AbstractIdentifiedObject} constructors.
138:             *
139:             * @param  value The object to cast into an array of generic names.
140:             * @return The generic names.
141:             * @throws ClassCastException if {@code value} can't be cast.
142:             */
143:            public static GenericName[] toArray(final Object value)
144:                    throws ClassCastException {
145:                if (value instanceof  GenericName[]) {
146:                    return (GenericName[]) value;
147:                }
148:                if (value instanceof  GenericName) {
149:                    return new GenericName[] { (GenericName) value };
150:                }
151:                if (value instanceof  CharSequence) {
152:                    return new GenericName[] { create(value.toString()) };
153:                }
154:                if (value instanceof  CharSequence[]) {
155:                    final CharSequence[] values = (CharSequence[]) value;
156:                    final GenericName[] names = new GenericName[values.length];
157:                    for (int i = 0; i < values.length; i++) {
158:                        final CharSequence v = values[i];
159:                        names[i] = (v instanceof  GenericName) ? (GenericName) v
160:                                : create(v.toString());
161:                    }
162:                    return names;
163:                }
164:                if (value instanceof  Identifier[]) {
165:                    final Identifier[] values = (Identifier[]) value;
166:                    final GenericName[] names = new GenericName[values.length];
167:                    for (int i = 0; i < values.length; i++) {
168:                        final Identifier v = values[i];
169:                        names[i] = (v instanceof  GenericName) ? (GenericName) v
170:                                : create(v.getCode());
171:                    }
172:                    return names;
173:                }
174:                // TODO: localize
175:                throw new ClassCastException("Cannot convert "
176:                        + Utilities.getShortClassName(value)
177:                        + " to GenericName[]");
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.