Source Code Cross Referenced for Index.java in  » Database-JDBC-Connection-Pool » Space4J » org » space4j » indexing » 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 » Database JDBC Connection Pool » Space4J » org.space4j.indexing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.space4j.indexing;
002:
003:        import java.util.*;
004:        import java.io.*;
005:        import java.lang.reflect.*;
006:
007:        /**
008:         * An object representing an Index in the system.<br>
009:         * An index contains a name, a classname, and a set o attributes.<br>
010:         * Index can be simple or compound.
011:         */
012:        public class Index implements  Serializable {
013:
014:            private String name;
015:            private String classname;
016:            private String[] attributes;
017:
018:            private transient Method[] methods = null;
019:
020:            /**
021:             * Create a new Index.
022:             * @param name The name of this index.
023:             * @param klass The class of this index.
024:             * @param attributes An array of attributes.
025:             */
026:            public Index(String name, Class klass, String[] attributes) {
027:                this .name = name;
028:                this .classname = klass.getName();
029:                this .attributes = attributes;
030:            }
031:
032:            /**
033:             * Return the name of this index.
034:             * @return The name of the index.
035:             */
036:            public String getName() {
037:                return name;
038:            }
039:
040:            /**
041:             * Return the name of the class of this index.
042:             * @return The name of the class.
043:             */
044:            public String getClassName() {
045:                return classname;
046:            }
047:
048:            /**
049:             * Return the attributes of this index.
050:             * @return The attributes of the index.
051:             */
052:            public String[] getAttributes() {
053:                return attributes;
054:            }
055:
056:            /**
057:             * Check if this index contains a given attribute.
058:             * @param attribute The attribute we are looking for.
059:             * @return True if the index contains this attribute.
060:             */
061:            public boolean hasAttribute(String attribute) {
062:                for (int i = 0; i < attributes.length; i++) {
063:                    if (attributes[i].equalsIgnoreCase(attribute))
064:                        return true;
065:                }
066:                return false;
067:            }
068:
069:            private void findMethods(Class klass) {
070:
071:                // for security...
072:                if (!klass.getName().equalsIgnoreCase(this .classname))
073:                    return;
074:
075:                try {
076:                    methods = new Method[attributes.length];
077:
078:                    for (int i = 0; i < methods.length; i++) {
079:                        String name = getMethodName(attributes[i]);
080:                        methods[i] = klass.getDeclaredMethod(name, null);
081:                    }
082:                } catch (Exception e) {
083:                    e.printStackTrace();
084:                    methods = null;
085:                }
086:            }
087:
088:            private String getMethodName(String attribute) {
089:                String firstletter = attribute.substring(0, 1);
090:                StringBuffer sb = new StringBuffer("get");
091:                sb.append(firstletter.toUpperCase());
092:                sb.append(attribute.substring(1, attribute.length()));
093:                return sb.toString();
094:            }
095:
096:            /**
097:             * Get a key to be used by this index for a given object.
098:             * @param value The object from which we want a key.
099:             * @return A key for this object.
100:             */
101:            public Key getKey(Object value) {
102:
103:                // Find methods if needed...
104:                if (methods == null) {
105:                    synchronized (this ) {
106:                        if (methods == null)
107:                            findMethods(value.getClass());
108:                    }
109:                }
110:
111:                // If it is not possible to find methods return null...
112:                if (methods == null)
113:                    return null;
114:
115:                Key key = new Key();
116:
117:                try {
118:                    for (int i = 0; i < methods.length; i++) {
119:                        Object obj = methods[i].invoke(value, null);
120:                        key.add(obj);
121:                    }
122:                } catch (Exception e) {
123:                    e.printStackTrace();
124:                    return null;
125:                }
126:
127:                return key;
128:            }
129:
130:            public boolean equals(Object obj) {
131:                if (!(obj instanceof  Index))
132:                    return false;
133:                Index indx = (Index) obj;
134:                if (!indx.classname.equalsIgnoreCase(this .classname))
135:                    return false;
136:                if (indx.attributes.length != this .attributes.length)
137:                    return false;
138:                for (int i = 0; i < indx.attributes.length; i++) {
139:                    if (!indx.attributes[i]
140:                            .equalsIgnoreCase(this .attributes[i]))
141:                        return false;
142:                }
143:                return true;
144:            }
145:
146:            public int hashCode() {
147:                StringBuffer sb = new StringBuffer();
148:                sb.append(classname);
149:                for (int i = 0; i < attributes.length; i++) {
150:                    sb.append(attributes[i]);
151:                }
152:                return sb.toString().hashCode();
153:            }
154:
155:            public String toString() {
156:                StringBuffer sb = new StringBuffer();
157:                sb.append("Index: ").append(classname);
158:                sb.append(" (");
159:                for (int i = 0; i < attributes.length; i++) {
160:                    sb.append(attributes[i]).append(",");
161:                }
162:                sb.deleteCharAt(sb.length() - 1);
163:                sb.append(")");
164:                return sb.toString();
165:            }
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.