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


001:        /*
002:         * Created on 13-May-2005
003:         *
004:         */
005:        package com.jofti.tree;
006:
007:        import java.util.ArrayList;
008:        import java.util.Collection;
009:        import java.util.Iterator;
010:        import java.util.LinkedHashSet;
011:        import java.util.List;
012:        import java.util.Map;
013:        import java.util.Set;
014:
015:        import org.apache.commons.logging.Log;
016:        import org.apache.commons.logging.LogFactory;
017:
018:        import com.jofti.api.NameSpaceKey;
019:        import com.jofti.btree.BTOperations;
020:        import com.jofti.btree.BTree;
021:        import com.jofti.cache.adapter.NameSpaceWrapper;
022:        import com.jofti.exception.JoftiException;
023:        import com.jofti.introspect.ClassIntrospector;
024:        import com.jofti.util.ObjectProcedureAdapter;
025:        import com.jofti.util.OpenHashMap;
026:
027:        /**
028:         * The class that the TreeIndex delegates to for operations involving NameSpace caches.<p>
029:         * 
030:         * 
031:         * @author Steve Woodcock (steve@jofti.com)
032:         *
033:         */
034:        public class NameSpaceTreeOperationAdapter extends TreeOperationAdapter {
035:
036:            public NameSpaceTreeOperationAdapter() {
037:            }
038:
039:            private static Log log = LogFactory
040:                    .getLog(NameSpaceTreeOperationAdapter.class);
041:
042:            /* (non-Javadoc)
043:             * @see com.jofti.tree.TreeOperationAdapter#contains(java.lang.Comparable, com.jofti.btree.BTree, com.jofti.introspect.ClassIntrospector)
044:             */
045:            public boolean contains(Comparable key, BTree tree,
046:                    ClassIntrospector parser) throws JoftiException {
047:                return BTOperations.contains(tree, key, parser
048:                        .getKeyDimension(((NameSpaceKey) key).getKey()
049:                                .getClass()));
050:            }
051:
052:            /* (non-Javadoc)
053:             * @see com.jofti.tree.TreeOperationAdapter#insert(java.lang.Comparable, java.lang.Object, com.jofti.btree.BTree, com.jofti.introspect.ClassIntrospector)
054:             */
055:            public void insert(Comparable key, Object value, BTree tree,
056:                    ClassIntrospector parser) throws IllegalArgumentException,
057:                    JoftiException {
058:                // first is it the right type
059:
060:                Map attributes = parser.getAttributeValues(value);
061:                if (attributes == null || attributes.isEmpty()) {
062:                    if (log.isDebugEnabled()) {
063:                        log.debug("No attributes found for '" + key
064:                                + "' ignoring in index");
065:                    }
066:                    return;
067:                }
068:
069:                List addedObjects = new ArrayList();
070:                NameSpaceKey tempKey = (NameSpaceKey) key;
071:
072:                // we index the key first
073:                if (log.isDebugEnabled()) {
074:                    log.debug("Attempting to insert name space '" + tempKey
075:                            + "'");
076:                }
077:                BTOperations.insertValue(tree, key, new NameSpaceWrapper(
078:                        tempKey.getNameSpace()), parser
079:                        .getKeyDimension(NameSpaceWrapper.class));
080:
081:                // first is it the right type
082:
083:                try {
084:
085:                    if (log.isDebugEnabled()) {
086:                        log.debug("Attempting to insert key '" + key + "'");
087:                    }
088:                    // we index the key first
089:                    BTOperations.insertKeyValue(tree, key, attributes, parser
090:                            .getKeyDimension(((NameSpaceKey) key).getClass()));
091:                    addedObjects.add(key);
092:                    if (log.isDebugEnabled()) {
093:                        log.debug("inserted key '" + key + "'");
094:                    }
095:
096:                    treeInsert(key, tree, attributes, addedObjects);
097:
098:                } catch (JoftiException e) {
099:                    log.error("Error encountered - removing indexed objects "
100:                            + addedObjects, e);
101:                    removeIndexedValues(key, addedObjects, tree, parser);
102:                }
103:
104:            }
105:
106:            /* (non-Javadoc)
107:             * @see com.jofti.tree.TreeOperationAdapter#removeByKey(java.lang.Comparable, com.jofti.btree.BTree, com.jofti.introspect.ClassIntrospector)
108:             */
109:            public void removeByKey(Comparable value, BTree tree,
110:                    ClassIntrospector parser) throws JoftiException {
111:
112:                //	Collection matchingValues = BTOperations.getKeyAttributes(tree,value,parser.getKeyDimension(((NameSpaceKey)value).getKey().getClass()));
113:                Collection matchingValues = BTOperations.getKeyAttributes(tree,
114:                        value, parser.getKeyDimension(((NameSpaceKey) value)
115:                                .getClass()));
116:
117:                if (matchingValues != null) {
118:                    if (matchingValues.size() > 0) {
119:                        for (Iterator it = matchingValues.iterator(); it
120:                                .hasNext();) {
121:                            BTOperations.removeValueObject(tree, value,
122:                                    (Comparable) it.next());
123:
124:                        }
125:                    }
126:                    if (log.isDebugEnabled()) {
127:                        log.debug("Attempting to remove key '" + value + "'");
128:                    }
129:
130:                    BTOperations.removeValue(tree, value, value, parser
131:                            .getKeyDimension(value.getClass()));
132:                    if (log.isDebugEnabled()) {
133:                        log.debug("Removed key '" + value + "'");
134:                    }
135:                    NameSpaceKey tempKey = (NameSpaceKey) value;
136:                    if (log.isDebugEnabled()) {
137:                        log.debug("Attempting to remove name space entry'"
138:                                + value + "'");
139:                    }
140:                    BTOperations.removeValue(tree, value, new NameSpaceWrapper(
141:                            tempKey.getNameSpace()), parser
142:                            .getKeyDimension(NameSpaceWrapper.class));
143:
144:                }
145:
146:            }
147:
148:            /* (non-Javadoc)
149:             * @see com.jofti.tree.TreeOperationAdapter#remove(java.lang.Comparable, java.lang.Object, com.jofti.btree.BTree, com.jofti.introspect.ClassIntrospector)
150:             */
151:            public void remove(Comparable key, Object value, BTree tree,
152:                    ClassIntrospector parser) throws IllegalArgumentException,
153:                    JoftiException {
154:                // first is it the right type
155:                try {
156:
157:                    if (log.isDebugEnabled()) {
158:                        log.debug("Attempting to remove key '" + key + "'");
159:                    }
160:
161:                    BTOperations.removeValue(tree, key, key, parser
162:                            .getKeyDimension(((NameSpaceKey) key).getKey()
163:                                    .getClass()));
164:                    if (log.isDebugEnabled()) {
165:                        log.debug("Removed key '" + key + "'");
166:                    }
167:
168:                    treeRemove(key, value, tree, parser);
169:
170:                    NameSpaceKey tempKey = (NameSpaceKey) key;
171:                    // we index the key first
172:                    if (log.isDebugEnabled()) {
173:                        log.debug("Attempting to remove name space entry'"
174:                                + tempKey + "'");
175:                    }
176:                    BTOperations.removeValue(tree, key, new NameSpaceWrapper(
177:                            tempKey.getNameSpace()), parser
178:                            .getKeyDimension(NameSpaceWrapper.class));
179:
180:                } catch (JoftiException e) {
181:                    throw e;
182:                }
183:            }
184:
185:            /**
186:             * @param key
187:             * @param added
188:             * @param tree
189:             * @param parser
190:             */
191:            private void removeIndexedValues(Object key, List added,
192:                    BTree tree, ClassIntrospector parser) {
193:                removeIndexedValues(key, added, tree);
194:                if (key instanceof  NameSpaceKey) {
195:                    NameSpaceKey tempKey = (NameSpaceKey) key;
196:                    // we index the key first
197:                    if (log.isDebugEnabled()) {
198:                        log.debug("Attempting to remove name space entry'"
199:                                + tempKey + "'");
200:                    }
201:                    try {
202:                        BTOperations.removeValue(tree, new NameSpaceWrapper(
203:                                tempKey.getNameSpace()), (Comparable) key,
204:                                parser.getKeyDimension(NameSpaceWrapper.class));
205:                    } catch (JoftiException e) {
206:                        log.warn(e);
207:                    }
208:                }
209:            }
210:
211:            /* (non-Javadoc)
212:             * @see com.jofti.tree.TreeOperationAdapter#getAllValuesForKey(java.lang.Comparable, com.jofti.btree.BTree, com.jofti.introspect.ClassIntrospector)
213:             */
214:            public Map getAllValuesForKey(Comparable key, BTree tree,
215:                    ClassIntrospector parser) throws JoftiException {
216:
217:                return BTOperations.match(tree, key, parser.getKeyDimension(key
218:                        .getClass()));
219:
220:            }
221:
222:            /**
223:             * @param tree
224:             * @param parser
225:             * @return A Collection of all the values in that dimension
226:             * @throws JoftiException
227:             */
228:            public Collection getAllValuesForDimension(BTree tree,
229:                    ClassIntrospector parser) throws JoftiException {
230:                final Set tempSet = new LinkedHashSet();
231:                Map keyDimensions = parser.getKeyDimensions();
232:
233:                for (Iterator it = keyDimensions.entrySet().iterator(); it
234:                        .hasNext();) {
235:                    Map.Entry entry = (Map.Entry) it.next();
236:                    if (!(entry.getKey() instanceof  NameSpaceWrapper)) {
237:                        OpenHashMap tempMap = (OpenHashMap) BTOperations
238:                                .getAllResultsForDimension(tree,
239:                                        ((Integer) entry.getValue()).intValue());
240:                        tempMap.forEachKey(new ObjectProcedureAdapter() {
241:                            public boolean apply(Object key) {
242:                                tempSet.add(key);
243:                                return true;
244:                            }
245:                        });
246:                        //tempSet.addAll(.keySet());
247:                    }
248:
249:                }
250:                return tempSet;
251:
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.