Source Code Cross Referenced for NodeEventHelper.java in  » Database-ORM » MMBase » org » mmbase » core » event » 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 ORM » MMBase » org.mmbase.core.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is OSI Certified Open Source Software.
003:         * OSI Certified is a certification mark of the Open Source Initiative.
004:         *
005:         * The license (Mozilla version 1.0) can be read at the MMBase site.
006:         * See http://www.MMBase.org/license
007:         */
008:        package org.mmbase.core.event;
009:
010:        import java.util.*;
011:
012:        import org.mmbase.bridge.*;
013:        import org.mmbase.module.core.*;
014:        import org.mmbase.module.corebuilders.InsRel;
015:
016:        /**
017:         * This is a utility class to create node event and relation event instances. the reason for it is
018:         * that we want to references to core classes in the NodeEvent and RelationEvent classes, to keep them bridge-friendly,
019:         * but we need a little help for easy instantiation.
020:         * @author Ernst Bunders
021:         * @since MMBase-1.8
022:         * @version $Id: NodeEventHelper.java,v 1.11 2008/02/07 16:22:34 michiel Exp $
023:
024:         */
025:        public class NodeEventHelper {
026:
027:            public static NodeEvent createNodeEventInstance(Node node,
028:                    int eventType, String machineName) {
029:                if (machineName == null)
030:                    machineName = MMBase.getMMBase().getMachineName();
031:                MMObjectNode coreNode = MMBase.getMMBase().getBuilder(
032:                        node.getNodeManager().getName()).getNode(
033:                        node.getNumber());
034:                return createNodeEventInstance(coreNode, eventType, machineName);
035:            }
036:
037:            /**
038:             * create an NodeEvent instance with an MMObjectNode
039:             * @param node
040:             * @param eventType
041:             * @param machineName or null to create a node event with local machine name
042:             * @return new instance of NodeEvent
043:             */
044:            public static NodeEvent createNodeEventInstance(MMObjectNode node,
045:                    int eventType, String machineName) {
046:                if (machineName == null)
047:                    machineName = MMBase.getMMBase().getMachineName();
048:                Map<String, Object> oldEventValues;
049:                Map<String, Object> newEventValues;
050:
051:                //fill the old and new values maps for the event
052:                switch (eventType) {
053:                case Event.TYPE_NEW:
054:                    newEventValues = removeBinaryValues(node.getValues());
055:                    oldEventValues = Collections.emptyMap();
056:                    break;
057:                case Event.TYPE_CHANGE:
058:                    oldEventValues = removeBinaryValues(node.getOldValues());
059:                    newEventValues = new HashMap<String, Object>();
060:                    Map<String, Object> values = node.getValues();
061:                    for (String key : oldEventValues.keySet()) {
062:                        newEventValues.put(key, values.get(key));
063:                    }
064:                    newEventValues = removeBinaryValues(newEventValues);
065:                    break;
066:                case Event.TYPE_DELETE:
067:                    newEventValues = Collections.emptyMap();
068:                    oldEventValues = removeBinaryValues(node.getValues());
069:                    break;
070:                default: {
071:                    oldEventValues = Collections.emptyMap();
072:                    newEventValues = Collections.emptyMap();
073:                    // err.
074:                }
075:                }
076:
077:                return new NodeEvent(machineName, node.getBuilder()
078:                        .getTableName(), node.getNumber(), oldEventValues,
079:                        newEventValues, eventType);
080:            }
081:
082:            private static Map<String, Object> removeBinaryValues(
083:                    Map<String, Object> oldEventValues) {
084:                Set<String> toremove = null;
085:                for (Map.Entry<String, Object> entry : oldEventValues
086:                        .entrySet()) {
087:                    if (entry.getValue() != null
088:                            && (entry.getValue() instanceof  byte[])) {
089:                        if (toremove == null)
090:                            toremove = new HashSet<String>();
091:                        toremove.add(entry.getKey());
092:                    }
093:                }
094:                if (toremove != null) {
095:                    Map<String, Object> newMap = new HashMap<String, Object>();
096:                    newMap.putAll(oldEventValues);
097:                    for (String k : toremove) {
098:                        newMap.remove(k);
099:                    }
100:                    return Collections.unmodifiableMap(newMap);
101:                } else {
102:                    return oldEventValues;
103:                }
104:            }
105:
106:            public static RelationEvent createRelationEventInstance(
107:                    Relation node, int eventType, String machineName) {
108:                MMObjectNode coreNode = MMBase.getMMBase().getBuilder(
109:                        node.getNodeManager().getName()).getNode(
110:                        node.getNumber());
111:                return createRelationEventInstance(coreNode, eventType,
112:                        machineName);
113:            }
114:
115:            /**
116:             * create an RelationEvent instnce with an MMObjectNode (builder should be specialization of insrel)
117:             * @param node
118:             * @param eventType
119:             * @param machineName
120:             * @return a new RelationEvetn instance
121:             * @throws IllegalArgumentException when given node's builder is not a specialization of insrel
122:             */
123:            public static RelationEvent createRelationEventInstance(
124:                    MMObjectNode node, int eventType, String machineName) {
125:                if (!(node.getBuilder() instanceof  InsRel)) {
126:                    throw new IllegalArgumentException(
127:                            "you can not create a relation changed event with this node");
128:                }
129:                MMBase mmbase = MMBase.getMMBase();
130:                if (machineName == null)
131:                    machineName = mmbase.getMachineName();
132:                MMObjectNode reldef = node.getNodeValue("rnumber");
133:
134:                int relationSourceNumber = node.getIntValue("snumber");
135:                int relationDestinationNumber = node.getIntValue("dnumber");
136:
137:                String relationSourceType = mmbase
138:                        .getBuilderNameForNode(relationSourceNumber);
139:                if (relationSourceType == null)
140:                    relationSourceType = "object";
141:                String relationDestinationType = mmbase
142:                        .getBuilderNameForNode(relationDestinationNumber);
143:                if (relationDestinationType == null)
144:                    relationDestinationType = "object";
145:                NodeEvent nodeEvent = createNodeEventInstance(node, eventType,
146:                        machineName);
147:                int role = reldef.getNumber();
148:                return new RelationEvent(nodeEvent, relationSourceNumber,
149:                        relationDestinationNumber, relationSourceType,
150:                        relationDestinationType, role);
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.