Source Code Cross Referenced for NameSpaceKeyWrapper.java in  » Search-Engine » Jofti » com » jofti » cache » adapter » 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 » Search Engine » Jofti » com.jofti.cache.adapter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 11-May-2005
003:         *
004:         */
005:        package com.jofti.cache.adapter;
006:
007:        import com.jofti.api.NameSpaceKey;
008:
009:        /**
010:         *
011:         *
012:         *Used in the JBossCacheAdapter index. The wrapper provides comparableness and ordering for 
013:         *the JBoss Fqn key. Specifically, the namespace object is checked first. If they are of the same type and equal then the key is checked. 
014:         * Otherwise if both objects are of the same type and comparable then natual ordering occurs on these objects. However, if they are not the same type 
015:         * then ordering of the toString() method is taken (while this may not provide consistency 
016:         * across time, we do not care as this is reasonable to provide key ordering in the index - which is not visible to the caller).
017:         * <p>
018:         * Key Comparison is done in a similar manner.<p>
019:         * 
020:         *  @author Steve Woodcock
021:         */
022:        public class NameSpaceKeyWrapper implements  Comparable, NameSpaceKey {
023:
024:            /**
025:             * @return Returns the key.
026:             */
027:            public Object getKey() {
028:                return key;
029:            }
030:
031:            private static String KEY_DEFAULT = "KEY";
032:
033:            protected Object nameSpace = null;
034:
035:            protected Class nameSpaceClass;
036:
037:            protected Object key = null;
038:            protected Class keyClass = null;
039:            int hashCode = 0;
040:
041:            private String nameSpaceCompareString = null;
042:
043:            /**
044:             * Constructs a wrapper for a namespace and key object. Null keys are given the String 
045:             * value "KEY".
046:             * @param nameSpace
047:             * @param key
048:             */
049:            public NameSpaceKeyWrapper(Object nameSpace, Object key) {
050:                this .nameSpace = nameSpace;
051:                nameSpaceClass = this .nameSpace.getClass();
052:                if (key != null) {
053:                    this .key = key;
054:                    keyClass = key.getClass();
055:                } else {
056:                    key = KEY_DEFAULT;
057:                    keyClass = this .key.getClass();
058:                }
059:                this .nameSpaceCompareString = nameSpace.toString() + "." + key;
060:                hashCode = nameSpace.hashCode() + key.hashCode();
061:            }
062:
063:            public NameSpaceKeyWrapper(Object nameSpace) {
064:                this (nameSpace, KEY_DEFAULT);
065:            }
066:
067:            public int compareTo(Object o) {
068:
069:                try {
070:
071:                    NameSpaceKeyWrapper temp = (NameSpaceKeyWrapper) o;
072:
073:                    // if the namespaces are the same type & comparable
074:                    if (nameSpaceClass.equals(temp.nameSpaceClass)
075:                            && nameSpace.equals(temp.nameSpace)) {
076:                        // the name spaces are equal
077:                        // compare the keys if they are comparable
078:                        if (keyClass.equals(temp.keyClass)
079:                                && key instanceof  Comparable) {
080:                            return ((Comparable) key).compareTo(temp.key);
081:                        }
082:                        // otherwise we have mismatched key types - so devolve to String
083:                        return key.toString().compareTo(temp.key.toString());
084:
085:                    } else {
086:                        // do a compare to on String
087:                        if (nameSpaceClass.equals(temp.nameSpaceClass)
088:                                && nameSpace instanceof  Comparable) {
089:                            return ((Comparable) nameSpace)
090:                                    .compareTo((Comparable) temp.nameSpace);
091:                        } else {
092:                            return nameSpace.toString().compareTo(
093:                                    temp.nameSpace.toString());
094:                        }
095:
096:                    }
097:                } catch (Throwable t) {
098:
099:                }
100:                return -1;
101:            }
102:
103:            public boolean equals(Object o) {
104:                try {
105:                    NameSpaceKeyWrapper temp = (NameSpaceKeyWrapper) o;
106:                    // see if name spaces equal
107:                    if (nameSpaceClass.equals(temp.nameSpaceClass)) {
108:                        // name spaces are equal
109:                        if (nameSpace.equals(temp.nameSpace)) {
110:                            // see if keys are equals
111:                            if (keyClass.equals(temp.keyClass)) {
112:                                return key.equals(temp.key);
113:                            }
114:                        }
115:                    }
116:                } catch (Exception e) {
117:
118:                }
119:                return false;
120:            }
121:
122:            public int hashCode() {
123:                return hashCode;
124:            }
125:
126:            public String toString() {
127:                return nameSpaceCompareString;
128:            }
129:
130:            /* (non-Javadoc)
131:             * @see com.jofti.core.NameSpaceKey#getNameSpace()
132:             */
133:            public Object getNameSpace() {
134:                // TODO Auto-generated method stub
135:                return nameSpace;
136:            }
137:
138:            protected void setNameSpace(Object nameSpace) {
139:                this .nameSpace = nameSpace;
140:                this .nameSpaceClass = nameSpace.getClass();
141:                this .nameSpaceCompareString = nameSpace.toString() + "." + key;
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.