Source Code Cross Referenced for IdentityHandleManager.java in  » Rule-Engine » hammurapi-rules » biz » hammurapi » rules » 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 » Rule Engine » hammurapi rules » biz.hammurapi.rules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * hammurapi-rules @mesopotamia.version@
003:         * Hammurapi rules engine. 
004:         * Copyright (C) 2005  Hammurapi Group
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * URL: http://http://www.hammurapi.biz
021:         * e-Mail: support@hammurapi.biz 
022:         */package biz.hammurapi.rules;
023:
024:        import java.io.Serializable;
025:        import java.util.ArrayList;
026:        import java.util.Collection;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.LinkedHashMap;
030:        import java.util.Map;
031:
032:        import javax.rules.Handle;
033:
034:        import biz.hammurapi.config.Component;
035:        import biz.hammurapi.config.ComponentBase;
036:        import biz.hammurapi.config.ConfigurationException;
037:
038:        /**
039:         * Handle manager implementation which keeps handles in memory. 
040:         * Objects are compared by identity, not by eqals().
041:         * @author Pavel Vlasov
042:         * @version ${Revision}
043:         */
044:        public class IdentityHandleManager extends ComponentBase implements 
045:                HandleManager, Component {
046:
047:            private Map handleMap;
048:
049:            private String storageReference;
050:
051:            /**
052:             * Path to object storage.
053:             * @param storageReference
054:             */
055:            public void setStorageReference(String storageReference) {
056:                this .storageReference = storageReference;
057:            }
058:
059:            private static class HandleImpl implements  Handle, Serializable {
060:                private static final long serialVersionUID = -6198273232968377370L;
061:                private Object master;
062:
063:                HandleImpl(Object master) {
064:                    this .master = master;
065:                }
066:
067:                public boolean equals(Object obj) {
068:                    return obj instanceof  HandleImpl
069:                            && master == ((HandleImpl) obj).master;
070:                }
071:
072:                public int hashCode() {
073:                    return master == null ? 0 : master.hashCode();
074:                }
075:
076:                public String toString() {
077:                    return getClass().getName() + " -> " + master;
078:                }
079:            }
080:
081:            synchronized public Handle addObject(Object object) {
082:                Handle newHandle = new HandleImpl(object);
083:                Handle existingHandle = (Handle) handleMap.get(newHandle);
084:                if (existingHandle == null) {
085:                    handleMap.put(newHandle, newHandle);
086:                    return newHandle;
087:                }
088:
089:                return existingHandle;
090:            }
091:
092:            synchronized public Object getObject(Handle handle) {
093:                if (handle instanceof  HandleImpl) {
094:                    return ((HandleImpl) handle).master;
095:                }
096:
097:                throw new IllegalArgumentException("Foreign handle: " + handle);
098:            }
099:
100:            public Collection getObjects() {
101:                ArrayList ret = new ArrayList();
102:                Iterator it = handleMap.keySet().iterator();
103:                while (it.hasNext()) {
104:                    ret.add(((HandleImpl) it.next()).master);
105:                }
106:                return ret;
107:            }
108:
109:            public Collection getHandles() {
110:                return handleMap.keySet();
111:            }
112:
113:            synchronized public void remove(Handle handle) {
114:                handleMap.remove(handle);
115:            }
116:
117:            public boolean contains(Handle handle) {
118:                return handleMap.containsKey(handle);
119:            }
120:
121:            synchronized public void rebind(Handle handle, Object object) {
122:                if (handle instanceof  HandleImpl) {
123:                    handleMap.remove(handle);
124:                    ((HandleImpl) handle).master = object;
125:                    handleMap.put(handle, handle);
126:                } else {
127:                    throw new IllegalArgumentException("Foreign handle: "
128:                            + handle);
129:                }
130:            }
131:
132:            public void remove(Object obj) {
133:                handleMap.remove(new HandleImpl(obj));
134:            }
135:
136:            public synchronized void clear() {
137:                handleMap.clear();
138:            }
139:
140:            public void start() throws ConfigurationException {
141:                if (storageReference == null) {
142:                    handleMap = new LinkedHashMap();
143:                } else {
144:                    handleMap = (Map) ((ObjectStorage) get(storageReference))
145:                            .get("handle-manager");
146:                    if (handleMap == null) {
147:                        handleMap = new HashMap();
148:                        ((ObjectStorage) get(storageReference)).put(
149:                                "handle-manager", handleMap);
150:                    }
151:                }
152:            }
153:
154:            public void stop() throws ConfigurationException {
155:                // Nothing
156:            }
157:
158:            public synchronized boolean isNegatedBy(Negator negator) {
159:                Iterator it = handleMap.keySet().iterator();
160:                while (it.hasNext()) {
161:                    HandleImpl handle = (HandleImpl) it.next();
162:                    if (Conclusion.object2Negator(handle.master, negator)) {
163:                        it.remove();
164:                    }
165:                }
166:
167:                return false;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.