Source Code Cross Referenced for VirtualBuilder.java in  » Database-ORM » MMBase » org » mmbase » module » core » 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.module.core 
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.module.core;
011:
012:        import java.util.*;
013:        import org.mmbase.bridge.Field;
014:        import org.mmbase.datatypes.*;
015:        import org.mmbase.core.CoreField;
016:        import org.mmbase.core.util.Fields;
017:        import org.mmbase.util.logging.Logger;
018:        import org.mmbase.util.logging.Logging;
019:
020:        /**
021:         * VirtualBuilder is a builder which creates 'virtual' nodes.
022:         * This class is intended to facilitate practical creation of virtual
023:         * builders by capturing events that migth otherwise lead to unexpected or
024:         * faulty behavior.
025:         *
026:         * @author Pierre van Rooden
027:         * @version $Id: VirtualBuilder.java,v 1.25 2008/02/03 17:33:57 nklasens Exp $
028:         */
029:        public class VirtualBuilder extends MMObjectBuilder {
030:            private static final Logger log = Logging
031:                    .getLoggerInstance(VirtualBuilder.class);
032:
033:            private static int counter = 0;
034:
035:            /**
036:             * Creates an instance of a Virtual builder.
037:             * A builder instantiated with this constrcutor is not registered in MMBase
038:             * and should only be used as a temporary parent for virtual nodes which
039:             * do not have a long life span.
040:             * @param m the MMbase cloud creating the node
041:             */
042:            public VirtualBuilder(MMBase m) {
043:                this .mmb = m;
044:                this .tableName = "virtualnodes_" + counter++;
045:                this .description = "";
046:                virtual = true;
047:            }
048:
049:            /**
050:             * Creates an instance of a Virtual builder and registers it in MMBase.
051:             * @param m the MMbase cloud creating the node
052:             * @param tableName the name of the builder as known in the MMbase system
053:             */
054:            protected VirtualBuilder(MMBase m, String tableName) {
055:                this .mmb = m;
056:                this .tableName = tableName;
057:                this .description = "";
058:                virtual = true;
059:                if (m.addBuilder(tableName, this ) != null) {
060:                    log.debug("Replaced virtual builder '" + tableName + "'");
061:                } else {
062:                    log.debug("Created virtual builder '" + tableName + "'");
063:                }
064:            }
065:
066:            /**
067:             * Initializes this builder.
068:             * No specifici cation is performed.
069:             * This method overrides the default emthod in MMObhjectBuilder, which
070:             * would otherwise attempt to access the database.
071:             * @return Always true.
072:             * @see #create
073:             */
074:            public boolean init() {
075:                return true;
076:            }
077:
078:            /**
079:             * Creates a new builder table in the current database.
080:             * This method does not perform any action in a virtual builder, as there is
081:             * no actual table associated with it.
082:             */
083:            public boolean create() {
084:                return true;
085:            }
086:
087:            /**
088:             * Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided).
089:             * This method does not perform any action in a virtual builder.
090:             * @param owner The administrator creating the node
091:             * @param node The object to insert
092:             * @return -1 (the insert failed)
093:             */
094:            public int insert(String owner, MMObjectNode node) {
095:                // no insert allowed on this builder, so signal -1
096:                return -1;
097:            }
098:
099:            /**
100:             * Get a new node, using this builder as its parent.
101:             * The new node is a virtual node.
102:             * @param owner The administrator creating the new node.
103:             * @return A newly initialized <code>VirtualNode</code>.
104:             */
105:            public MMObjectNode getNewNode(String owner) {
106:                VirtualNode node = new VirtualNode(this );
107:                node.setValue("number", -1);
108:                node.setValue("owner", owner);
109:                node.setValue("otype", oType);
110:                setDefaults(node);
111:                return node;
112:            }
113:
114:            /**
115:             * {@inheritDoc}
116:             * The default behavior of a virtual node is to display the content of
117:             * the 'name' field (if present).
118:             * XXX: should be changed to something better
119:             * @param node The node to display
120:             * @return either the name field of the node or "no info"
121:             */
122:            public String getGUIIndicator(MMObjectNode node) {
123:                String s = node.getStringValue("name");
124:                if (s != null) {
125:                    return s;
126:                } else {
127:                    return GUI_INDICATOR;
128:                }
129:            }
130:
131:            /**
132:             * Return a field's database state.
133:             * The default behavior for a virtual node is to return <code>DBSTATE_VIRTUAL</code>.
134:             * @param fieldName the requested field's name
135:             * @return <code>DBSTATE_VIRTUAL</code>
136:             */
137:            public int getDBState(String fieldName) {
138:                return Field.STATE_VIRTUAL;
139:            }
140:
141:            /**
142:             * {@inheritDoc}
143:             * Since virtual builders are generally not associated with a database,
144:             * this method returns null.
145:             * @param fieldName name of the field
146:             * @param node
147:             * @return <code>null</code>
148:             */
149:            protected String getShortedText(String fieldName, MMObjectNode node) {
150:                return null;
151:            }
152:
153:            /**
154:             * {@inheritDoc}
155:             * Since virtual builders are generally not associated with a database,
156:             * this method returns null.
157:             * @param fieldName name of the field
158:             * @param node
159:             * @return <code>null</code>
160:             */
161:            protected byte[] getShortedByte(String fieldName, MMObjectNode node) {
162:                return null;
163:            }
164:
165:            /**
166:             * Get text from a blob field from a database.
167:             * @since MMBase-1.8
168:             */
169:            public Map<String, CoreField> getFields(MMObjectNode node) {
170:                Map<String, CoreField> res = new HashMap<String, CoreField>();
171:                // determine fields and field types
172:                Map<String, Object> values = node.getValues();
173:                synchronized (values) {
174:                    Iterator<Map.Entry<String, Object>> i = values.entrySet()
175:                            .iterator();
176:                    while (i.hasNext()) {
177:                        Map.Entry<String, Object> entry = i.next();
178:                        String fieldName = entry.getKey();
179:                        Object value = entry.getValue();
180:                        if (value == null)
181:                            value = new Object();
182:                        DataType<? extends Object> fieldDataType = DataTypes
183:                                .createDataType("field", value.getClass());
184:                        int type = Fields.classToType(value.getClass());
185:                        CoreField fd = Fields.createField(fieldName, type,
186:                                Field.TYPE_UNKNOWN, Field.STATE_VIRTUAL,
187:                                fieldDataType);
188:                        fd.finish();
189:                        res.put(fieldName, fd);
190:                    }
191:                }
192:                return res;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.