Source Code Cross Referenced for ModelFieldTypeReader.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » entity » model » 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 » ERP CRM Financial » ofbiz » org.ofbiz.entity.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.entity.model;
019:
020:        import java.io.Serializable;
021:        import java.util.Collection;
022:        import java.util.HashMap;
023:        import java.util.Map;
024:
025:        import org.ofbiz.base.config.GenericConfigException;
026:        import org.ofbiz.base.config.MainResourceHandler;
027:        import org.ofbiz.base.config.ResourceHandler;
028:        import org.ofbiz.base.util.Debug;
029:        import org.ofbiz.base.util.UtilTimer;
030:        import org.ofbiz.base.util.UtilXml;
031:        import org.ofbiz.base.util.cache.UtilCache;
032:        import org.ofbiz.entity.config.DatasourceInfo;
033:        import org.ofbiz.entity.config.EntityConfigUtil;
034:        import org.ofbiz.entity.config.FieldTypeInfo;
035:        import org.w3c.dom.Document;
036:        import org.w3c.dom.Element;
037:        import org.w3c.dom.Node;
038:
039:        /**
040:         * Generic Entity - Field Type Definition Reader
041:         *
042:         */
043:        public class ModelFieldTypeReader implements  Serializable {
044:
045:            public static final String module = ModelFieldTypeReader.class
046:                    .getName();
047:            public static UtilCache readers = new UtilCache(
048:                    "entity.ModelFieldTypeReader", 0, 0);
049:
050:            public Map fieldTypeCache = null;
051:
052:            public int numEntities = 0;
053:            public int numFields = 0;
054:            public int numRelations = 0;
055:
056:            public String modelName;
057:            public ResourceHandler fieldTypeResourceHandler;
058:            public String entityFileName;
059:
060:            public static ModelFieldTypeReader getModelFieldTypeReader(
061:                    String helperName) {
062:                DatasourceInfo datasourceInfo = EntityConfigUtil
063:                        .getDatasourceInfo(helperName);
064:                if (datasourceInfo == null) {
065:                    throw new IllegalArgumentException(
066:                            "Could not find a datasource/helper with the name "
067:                                    + helperName);
068:                }
069:
070:                String tempModelName = datasourceInfo.fieldTypeName;
071:                ModelFieldTypeReader reader = (ModelFieldTypeReader) readers
072:                        .get(tempModelName);
073:
074:                if (reader == null) // don't want to block here
075:                {
076:                    synchronized (ModelFieldTypeReader.class) {
077:                        // must check if null again as one of the blocked threads can still enter
078:                        reader = (ModelFieldTypeReader) readers
079:                                .get(tempModelName);
080:                        if (reader == null) {
081:                            reader = new ModelFieldTypeReader(tempModelName);
082:                            readers.put(tempModelName, reader);
083:                        }
084:                    }
085:                }
086:                return reader;
087:            }
088:
089:            public ModelFieldTypeReader(String modelName) {
090:                this .modelName = modelName;
091:                FieldTypeInfo fieldTypeInfo = EntityConfigUtil
092:                        .getFieldTypeInfo(modelName);
093:
094:                if (fieldTypeInfo == null) {
095:                    throw new IllegalStateException(
096:                            "Could not find a field-type definition with name \""
097:                                    + modelName + "\"");
098:                }
099:                fieldTypeResourceHandler = new MainResourceHandler(
100:                        EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME,
101:                        fieldTypeInfo.resourceElement);
102:
103:                // preload caches...
104:                getFieldTypeCache();
105:            }
106:
107:            public Map getFieldTypeCache() {
108:                if (fieldTypeCache == null) // don't want to block here
109:                {
110:                    synchronized (ModelFieldTypeReader.class) {
111:                        // must check if null again as one of the blocked threads can still enter
112:                        if (fieldTypeCache == null) // now it's safe
113:                        {
114:                            fieldTypeCache = new HashMap();
115:
116:                            UtilTimer utilTimer = new UtilTimer();
117:                            // utilTimer.timerString("Before getDocument");
118:
119:                            Document document = null;
120:
121:                            try {
122:                                document = fieldTypeResourceHandler
123:                                        .getDocument();
124:                            } catch (GenericConfigException e) {
125:                                Debug
126:                                        .logError(
127:                                                e,
128:                                                "Error loading field type file",
129:                                                module);
130:                            }
131:                            if (document == null) {
132:                                fieldTypeCache = null;
133:                                return null;
134:                            }
135:
136:                            // utilTimer.timerString("Before getDocumentElement");
137:                            Element docElement = document.getDocumentElement();
138:
139:                            if (docElement == null) {
140:                                fieldTypeCache = null;
141:                                return null;
142:                            }
143:                            docElement.normalize();
144:
145:                            Node curChild = docElement.getFirstChild();
146:
147:                            int i = 0;
148:
149:                            if (curChild != null) {
150:                                utilTimer
151:                                        .timerString("Before start of field type loop");
152:                                do {
153:                                    if (curChild.getNodeType() == Node.ELEMENT_NODE
154:                                            && "field-type-def".equals(curChild
155:                                                    .getNodeName())) {
156:                                        i++;
157:                                        // utilTimer.timerString("Start loop -- " + i + " --");
158:                                        Element curFieldType = (Element) curChild;
159:                                        String fieldTypeName = UtilXml
160:                                                .checkEmpty(curFieldType
161:                                                        .getAttribute("type"),
162:                                                        "[No type name]");
163:                                        // utilTimer.timerString("  After fieldTypeName -- " + i + " --");
164:                                        ModelFieldType fieldType = createModelFieldType(
165:                                                curFieldType, docElement, null);
166:
167:                                        // utilTimer.timerString("  After createModelFieldType -- " + i + " --");
168:                                        if (fieldType != null) {
169:                                            fieldTypeCache.put(fieldTypeName,
170:                                                    fieldType);
171:                                            // utilTimer.timerString("  After fieldTypeCache.put -- " + i + " --");
172:                                            if (Debug.verboseOn())
173:                                                Debug
174:                                                        .logVerbose(
175:                                                                "-- getModelFieldType: #"
176:                                                                        + i
177:                                                                        + " Created fieldType: "
178:                                                                        + fieldTypeName,
179:                                                                module);
180:                                        } else {
181:                                            Debug
182:                                                    .logWarning(
183:                                                            "-- -- ENTITYGEN ERROR:getModelFieldType: Could not create fieldType for fieldTypeName: "
184:                                                                    + fieldTypeName,
185:                                                            module);
186:                                        }
187:
188:                                    }
189:                                } while ((curChild = curChild.getNextSibling()) != null);
190:                            } else
191:                                Debug.logWarning("No child nodes found.",
192:                                        module);
193:                            utilTimer
194:                                    .timerString("FINISHED - Total Field Types: "
195:                                            + i + " FINISHED");
196:                        }
197:                    }
198:                }
199:                return fieldTypeCache;
200:            }
201:
202:            /** Creates a Collection with all of the ModelFieldType names
203:             * @return A Collection of ModelFieldType names
204:             */
205:            public Collection getFieldTypeNames() {
206:                Map ftc = getFieldTypeCache();
207:
208:                return ftc.keySet();
209:            }
210:
211:            /** Creates a Collection with all of the ModelFieldTypes
212:             * @return A Collection of ModelFieldTypes
213:             */
214:            public Collection getFieldTypes() {
215:                Map ftc = getFieldTypeCache();
216:
217:                return ftc.values();
218:            }
219:
220:            /** Gets an FieldType object based on a definition from the specified XML FieldType descriptor file.
221:             * @param fieldTypeName The fieldTypeName of the FieldType definition to use.
222:             * @return An FieldType object describing the specified fieldType of the specified descriptor file.
223:             */
224:            public ModelFieldType getModelFieldType(String fieldTypeName) {
225:                Map ftc = getFieldTypeCache();
226:
227:                if (ftc != null)
228:                    return (ModelFieldType) ftc.get(fieldTypeName);
229:                else
230:                    return null;
231:            }
232:
233:            ModelFieldType createModelFieldType(Element fieldTypeElement,
234:                    Element docElement, UtilTimer utilTimer) {
235:                if (fieldTypeElement == null)
236:                    return null;
237:
238:                ModelFieldType field = new ModelFieldType(fieldTypeElement);
239:
240:                return field;
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.