Source Code Cross Referenced for Name.java in  » Collaboration » JacORB » org » jacorb » naming » 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 » Collaboration » JacORB » org.jacorb.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jacorb.naming;
002:
003:        /*
004:         *        JacORB - a free Java ORB
005:         *
006:         *   Copyright (C) 1997-2004 Gerald Brose.
007:         *
008:         *   This library is free software; you can redistribute it and/or
009:         *   modify it under the terms of the GNU Library General Public
010:         *   License as published by the Free Software Foundation; either
011:         *   version 2 of the License, or (at your option) any later version.
012:         *
013:         *   This library is distributed in the hope that it will be useful,
014:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         *   Library General Public License for more details.
017:         *
018:         *   You should have received a copy of the GNU Library General Public
019:         *   License along with this library; if not, write to the Free
020:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         */
022:
023:        import java.util.*;
024:
025:        import org.omg.CORBA.INTERNAL;
026:        import org.omg.CosNaming.*;
027:        import org.omg.CosNaming.NamingContextPackage.*;
028:
029:        /**
030:         * A convenience class for names and converting
031:         * between Names and their string representation
032:         *
033:         * @author Gerald Brose, FU Berlin
034:         * @version $Id: Name.java,v 1.14 2006/06/14 11:56:28 alphonse.bendt Exp $
035:         */
036:
037:        public class Name implements  java.io.Serializable {
038:            private NameComponent[] fullName;
039:            private NameComponent baseName;
040:
041:            /** context part of this Name */
042:            private NameComponent[] ctxName;
043:
044:            public Name() {
045:                fullName = null;
046:                baseName = null;
047:                ctxName = null;
048:            }
049:
050:            /**
051:             *	create a name from an array of NameComponents
052:             */
053:
054:            public Name(NameComponent[] n) throws InvalidName {
055:                if (n == null || n.length == 0)
056:                    throw new InvalidName();
057:
058:                fullName = n;
059:                baseName = n[n.length - 1];
060:                if (n.length > 1) {
061:                    ctxName = new NameComponent[n.length - 1];
062:                    for (int i = 0; i < n.length - 1; i++)
063:                        ctxName[i] = n[i];
064:                } else
065:                    ctxName = null;
066:            }
067:
068:            /**
069:             *	create a name from a stringified name
070:             */
071:
072:            public Name(String string_name)
073:                    throws org.omg.CosNaming.NamingContextPackage.InvalidName {
074:                this (toName(string_name));
075:            }
076:
077:            /**
078:             *	create a name from a singleNameComponent
079:             */
080:
081:            public Name(org.omg.CosNaming.NameComponent n)
082:                    throws org.omg.CosNaming.NamingContextPackage.InvalidName {
083:                if (n == null)
084:                    throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
085:                baseName = n;
086:                fullName = new org.omg.CosNaming.NameComponent[1];
087:                fullName[0] = n;
088:                ctxName = null;
089:            }
090:
091:            /**
092:             *	@return a NameComponent object representing the unstructured
093:             *	base name of this structured name
094:             */
095:
096:            public org.omg.CosNaming.NameComponent baseNameComponent() {
097:                return baseName;
098:            }
099:
100:            public String kind() {
101:                return baseName.kind;
102:            }
103:
104:            /**
105:             *	@return this name as an array of org.omg.CosNaming.NameComponent,
106:             *	neccessary for a number of operations on naming context
107:             */
108:
109:            public org.omg.CosNaming.NameComponent[] components() {
110:                return fullName;
111:            }
112:
113:            /**
114:             *	@return a Name object representing the name of the enclosing context
115:             */
116:
117:            public Name ctxName() {
118:                // null if no further context
119:                if (ctxName != null) {
120:                    try {
121:                        return new Name(ctxName);
122:                    } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
123:                        throw new INTERNAL(e.toString());
124:                    }
125:                }
126:                return null;
127:            }
128:
129:            public boolean equals(Object obj) {
130:                if (obj == null)
131:                    return false;
132:                if (!(obj instanceof  Name))
133:                    return false;
134:                return (toString().equals(obj.toString()));
135:            }
136:
137:            public Name fullName()
138:                    throws org.omg.CosNaming.NamingContextPackage.InvalidName {
139:                return new Name(fullName);
140:            }
141:
142:            public int hashCode() {
143:                return toString().hashCode();
144:            }
145:
146:            /**
147:             * @return  the string representation of this name
148:             */
149:
150:            public String toString() {
151:                try {
152:                    return toString(fullName);
153:                } catch (InvalidName in) {
154:                    return "<invalid>";
155:                }
156:            }
157:
158:            /**
159:             * @return a single NameComponent, parsed from sn
160:             */
161:
162:            private static org.omg.CosNaming.NameComponent getComponent(
163:                    String sn)
164:                    throws org.omg.CosNaming.NamingContextPackage.InvalidName {
165:                char ch;
166:                int len = sn.length();
167:                boolean inKind = false;
168:                StringBuffer id = new StringBuffer();
169:                StringBuffer kind = new StringBuffer();
170:
171:                for (int i = 0; i < len; i++) {
172:                    ch = sn.charAt(i);
173:
174:                    if (ch == '\\') {
175:                        // Escaped character
176:
177:                        i++;
178:                        if (i >= len) {
179:                            throw new InvalidName();
180:                        }
181:                        ch = sn.charAt(i);
182:                    } else if (ch == '.') {
183:                        // id/kind separator character
184:
185:                        if (inKind) {
186:                            throw new InvalidName();
187:                        }
188:                        inKind = true;
189:                        continue;
190:                    }
191:                    if (inKind) {
192:                        kind.append(ch);
193:                    } else {
194:                        id.append(ch);
195:                    }
196:                }
197:
198:                return (new org.omg.CosNaming.NameComponent(id.toString(), kind
199:                        .toString()));
200:            }
201:
202:            /**
203:             *
204:             * @return an a array of NameComponents
205:             * @throws org.omg.CosNaming.NamingContextPackage.InvalidName
206:             */
207:
208:            public static org.omg.CosNaming.NameComponent[] toName(String sn)
209:                    throws org.omg.CosNaming.NamingContextPackage.InvalidName {
210:                if (sn == null || sn.length() == 0 || sn.startsWith("/"))
211:                    throw new InvalidName();
212:
213:                Vector v = new Vector();
214:
215:                int start = 0;
216:                int i = 0;
217:                for (; i < sn.length(); i++) {
218:                    if (sn.charAt(i) == '/' && sn.charAt(i - 1) != '\\') {
219:                        if (i - start == 0)
220:                            throw new InvalidName();
221:                        v.addElement(getComponent(sn.substring(start, i)));
222:                        start = i + 1;
223:                    }
224:                }
225:                if (start < i)
226:                    v.addElement(getComponent(sn.substring(start, i)));
227:
228:                org.omg.CosNaming.NameComponent[] result = new org.omg.CosNaming.NameComponent[v
229:                        .size()];
230:
231:                for (int j = 0; j < result.length; j++) {
232:                    result[j] = (org.omg.CosNaming.NameComponent) v
233:                            .elementAt(j);
234:                }
235:                return result;
236:            }
237:
238:            /**
239:             * @return the string representation of this NameComponent array
240:             */
241:
242:            public static String toString(org.omg.CosNaming.NameComponent[] n)
243:                    throws org.omg.CosNaming.NamingContextPackage.InvalidName {
244:                if (n == null || n.length == 0)
245:                    throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
246:
247:                StringBuffer b = new StringBuffer();
248:                for (int i = 0; i < n.length; i++) {
249:                    if (i > 0)
250:                        b.append("/");
251:
252:                    if (n[i].id.length() > 0)
253:                        b.append(escape(n[i].id));
254:
255:                    if (n[i].kind.length() > 0 || n[i].id.length() == 0)
256:                        b.append(".");
257:
258:                    if (n[i].kind.length() > 0)
259:                        b.append(escape(n[i].kind));
260:                }
261:                return b.toString();
262:            }
263:
264:            /**
265:             * escape any occurrence of "/", "." and "\"
266:             */
267:
268:            private static String escape(String s) {
269:                StringBuffer sb = new StringBuffer(s);
270:                for (int i = 0; i < sb.length(); i++) {
271:                    if (sb.charAt(i) == '/' || sb.charAt(i) == '\\'
272:                            || sb.charAt(i) == '.') {
273:                        sb.insert(i, '\\');
274:                        i++;
275:                    }
276:                }
277:                return sb.toString();
278:            }
279:
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.