Source Code Cross Referenced for Adapter4Rules.java in  » Rule-Engine » Mandarax » org » mandarax » zkb » framework » 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 » Mandarax » org.mandarax.zkb.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.mandarax.zkb.framework;
002:
003:        /**
004:         *  Copyright (C) 1999-2004  Jens Dietrich (mailto:mandarax@jbdietrich.com)
005:         *
006:         *  This library 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 library 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:
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Vector;
024:
025:        import org.jdom.Element;
026:        import org.mandarax.kernel.Fact;
027:        import org.mandarax.kernel.LogicFactory;
028:        import org.mandarax.kernel.Prerequisite;
029:        import org.mandarax.kernel.Rule;
030:        import org.mandarax.zkb.ObjectPersistencyService;
031:        import org.mandarax.zkb.ZKBException;
032:
033:        /**
034:         * An adapter class for rules.
035:         * @see org.mandarax.kernel.Rule
036:         * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
037:         * @version 3.4 <7 March 05>
038:         * @since 2.2
039:         */
040:
041:        public class Adapter4Rules extends AbstractAdapter {
042:
043:            /**
044:             * Export an object, i.e., convert it to an element in the DOM.
045:             * @param obj an object
046:             * @param driver the generic driver
047:             * @param ops the object persistency service
048:             * @exception a ZKBException is thrown if export fails
049:             */
050:            public Element exportObject(Object obj, GenericDriver driver,
051:                    ObjectPersistencyService ops) throws ZKBException {
052:                check(obj, Rule.class);
053:                Rule rule = (Rule) obj;
054:                Element e = new Element(RULE);
055:                Element eConn = new Element(rule.isBodyOrConnected() ? OR : AND);
056:                Element eBody = new Element(BODY);
057:                eBody.addContent(eConn);
058:                e.addContent(eBody);
059:                for (Iterator it = rule.getBody().iterator(); it.hasNext();) {
060:                    Element el = exportObject(it.next(), PREREQUISITE, driver,
061:                            ops);
062:                    eConn.addContent(el);
063:                }
064:                Element eHead = new Element(HEAD);
065:                e.addContent(eHead);
066:                Element el = exportObject(rule.getHead(),
067:                        TagAndAttributeNames.FACT, driver, ops);
068:                eHead.addContent(el);
069:                exportProperties(e, rule);
070:                return e;
071:            }
072:
073:            /**
074:             * Build an object from an XML element.
075:             * @param e an element
076:             * @param driver the generic driver
077:             * @param ops the object persistency service
078:             * @param lfactory the logic factory used to create objects
079:             * @exception a ZKBException is thrown if import fails
080:             */
081:            public Object importObject(Element e, GenericDriver driver,
082:                    ObjectPersistencyService ops, LogicFactory lfactory)
083:                    throws ZKBException {
084:                // get  body
085:                Element eBody = e.getChild(BODY);
086:                Element eConn = (Element) eBody.getChildren().get(0);
087:                boolean isOrConnected = OR.equals(eConn.getName());
088:                List body = new Vector();
089:                Adapter adapter4Prereq = driver.getAdapter(PREREQUISITE);
090:                List children = eConn.getChildren();
091:                for (Iterator it = children.iterator(); it.hasNext();) {
092:                    Element eFact = (Element) it.next();
093:                    Prerequisite premisse = (Prerequisite) adapter4Prereq
094:                            .importObject(eFact, driver, ops, lfactory);
095:                    body.add(premisse);
096:                }
097:                // get head
098:                Element eHead = e.getChild(HEAD);
099:                Fact head = (Fact) importChild(eHead, FACT, driver, ops,
100:                        lfactory);
101:
102:                // build rule
103:                Rule rule = lfactory.createRule(body, head, isOrConnected);
104:                importProperties(e, rule);
105:                return rule;
106:            }
107:
108:            /**
109:             * Get the name of the associated tag (element).
110:             * @return a string
111:             */
112:            public String getTagName() {
113:                return RULE;
114:            }
115:
116:            /**
117:             * Print the DTD associated with this adapter on a string buffer.
118:             * @param out the buffer to print on. 
119:             */
120:            public void printDTD(StringBuffer out) {
121:                // warning : properties are declared here and only here
122:                // this is sensitive w.r.t. the order in which adapters are registered
123:                // here we assume that this is the first adapter registered that needs property support
124:                out.append("<!ELEMENT rule (_body,_head,properties?)>\n");
125:                out.append("<!ELEMENT _body (or|and|atom*)>\n");
126:                out.append("<!ELEMENT or (prereq*)>\n");
127:                out.append("<!ELEMENT and (prereq*)>\n");
128:                out.append("<!ELEMENT _head (atom)>\n");
129:                out.append("<!ELEMENT properties (property*)>\n");
130:                out.append("<!ELEMENT property EMPTY>\n");
131:                out.append("<!ATTLIST property key CDATA #REQUIRED>\n");
132:                out.append("<!ATTLIST property value CDATA #REQUIRED>\n");
133:            }
134:
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.