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


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.datatypes;
011:
012:        import java.util.Collection;
013:        import org.mmbase.util.Casting;
014:        import org.mmbase.util.LocalizedString;
015:        import org.mmbase.bridge.*;
016:        import org.mmbase.util.logging.*;
017:
018:        /**
019:         * The Node data type describes a data type which is based on an MMBase 'node' field. So the value
020:         * is an MMBase node, which can normally be described by a foreign key.
021:         *
022:         * @author Pierre van Rooden
023:         * @author Michiel Meeuwissen
024:         * @version $Id: NodeDataType.java,v 1.33 2007/06/21 07:32:31 pierre Exp $
025:         * @since MMBase-1.8
026:         */
027:        public class NodeDataType extends BasicDataType<Node> {
028:
029:            private static final Logger log = Logging
030:                    .getLoggerInstance(NodeDataType.class);
031:
032:            private static final long serialVersionUID = 1L; // increase this if object serialization changes (which we shouldn't do!)
033:
034:            protected MustExistRestriction mustExistRestriction = new MustExistRestriction();
035:
036:            /**
037:             * Constructor for node field.
038:             */
039:            public NodeDataType(String name) {
040:                super (name, Node.class);
041:            }
042:
043:            protected void inheritRestrictions(BasicDataType origin) {
044:                super .inheritRestrictions(origin);
045:                if (origin instanceof  NodeDataType) {
046:                    mustExistRestriction
047:                            .inherit(((NodeDataType) origin).mustExistRestriction);
048:                }
049:            }
050:
051:            protected void cloneRestrictions(BasicDataType origin) {
052:                super .cloneRestrictions(origin);
053:                if (origin instanceof  NodeDataType) {
054:                    mustExistRestriction = new MustExistRestriction(
055:                            ((NodeDataType) origin).mustExistRestriction);
056:                }
057:            }
058:
059:            protected Object castToValidate(Object value, Node node, Field field)
060:                    throws CastException {
061:                if (value == null)
062:                    return null;
063:                Object preCast = preCast(value, node, field); // resolves enumerations
064:                if (preCast instanceof  Node) {
065:                    return preCast;
066:                } else {
067:                    Object res = Casting.toType(Node.class, getCloud(node,
068:                            field), preCast);
069:                    if (res == null) {
070:                        if (Casting.toString(value).equals("-1")) {
071:                            return null;
072:                        }
073:                        throw new CastException("No such node " + preCast);
074:                    } else {
075:                        return res;
076:                    }
077:                }
078:            }
079:
080:            /**
081:             * Whether the Node of the value must exist
082:             *
083:             * XXX MM: How can you have a non-existing node? I don't really get it. AFAIK all nodes exist.
084:             *              especially since a node field is essentially a foreign key.
085:             */
086:            public boolean mustExist() {
087:                return mustExistRestriction.getValue().equals(Boolean.TRUE);
088:            }
089:
090:            public MustExistRestriction getMustExistRestriction() {
091:                mustExistRestriction.setFixed(true);
092:                return mustExistRestriction;
093:            }
094:
095:            public int getEnforceStrength() {
096:                return Math.max(super .getEnforceStrength(),
097:                        mustExistRestriction.getEnforceStrength());
098:            }
099:
100:            protected Collection<LocalizedString> validateCastValue(
101:                    Collection<LocalizedString> errors, Object castValue,
102:                    Object value, Node node, Field field) {
103:                errors = super .validateCastValue(errors, castValue, value,
104:                        node, field);
105:                errors = mustExistRestriction.validate(errors, value, node,
106:                        field);
107:                return errors;
108:            }
109:
110:            private class MustExistRestriction extends
111:                    AbstractRestriction<Boolean> {
112:                MustExistRestriction(MustExistRestriction me) {
113:                    super (me);
114:                    enforceStrength = DataType.ENFORCE_ONCHANGE;
115:                }
116:
117:                MustExistRestriction() {
118:                    super ("mustExist", Boolean.TRUE);
119:                    enforceStrength = DataType.ENFORCE_ONCHANGE;
120:                }
121:
122:                protected Cloud getCloud(Node node, Field field) {
123:                    Cloud cloud = node != null ? node.getCloud() : null;
124:                    if (cloud == null)
125:                        cloud = field != null ? field.getNodeManager()
126:                                .getCloud() : null;
127:                    if (cloud == null) {
128:                        cloud = ContextProvider.getDefaultCloudContext()
129:                                .getCloud("mmbase", "class", null);
130:                    }
131:                    return cloud;
132:                }
133:
134:                protected boolean simpleValid(Object v, Node node, Field field) {
135:                    if (getValue().equals(Boolean.TRUE)) {
136:                        if (v != null) {
137:                            if (v instanceof  String) {
138:                                Cloud cloud = getCloud(node, field);
139:                                return cloud != null
140:                                        && cloud.hasNode((String) v);
141:                            } else if (v instanceof  Number) {
142:                                int num = ((Number) v).intValue();
143:                                if (num < 0)
144:                                    return false;
145:                                Cloud cloud = getCloud(node, field);
146:                                return cloud != null && cloud.hasNode(num);
147:                            } else if (v instanceof  Node) {
148:                                return true;
149:                            } else {
150:                                //log.info("Not valid because node value is a " + v.getClass());
151:                                return false;
152:                            }
153:                        }
154:                    }
155:                    return true;
156:                }
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.