Source Code Cross Referenced for Lookup.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » masterindex » plugin » datamodel » 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 » IDE Netbeans » etl.project » org.netbeans.modules.masterindex.plugin.datamodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.masterindex.plugin.datamodel;
042:
043:        import java.io.FileInputStream;
044:        import java.io.FileNotFoundException;
045:        import java.io.InputStream;
046:        import java.util.ArrayList;
047:        import java.util.HashMap;
048:        import java.util.Iterator;
049:        import net.java.hulp.i18n.Logger;
050:        import org.netbeans.modules.etl.logger.Localizer;
051:        import org.netbeans.modules.etl.logger.LogUtil;
052:
053:        /**
054:         * @author Sujit Biswas
055:         * @author Manish Bharani
056:         */
057:        public class Lookup {
058:
059:            private static transient final Logger mLogger = LogUtil
060:                    .getLogger(Lookup.class.getName());
061:            private static transient final Localizer mLoc = Localizer.get();
062:            private HashMap<String, HashMap<String, Integer>> lookupMap = new HashMap<String, HashMap<String, Integer>>();
063:            private HashMap<String, Integer> childIndex = new HashMap<String, Integer>();
064:            private transient ObjectDefinition objectdef;
065:
066:            /**
067:             * @param objectdef
068:             */
069:            private Lookup(ObjectDefinition objectdef) {
070:                this .objectdef = objectdef;
071:                createLookup();
072:            }
073:
074:            /**
075:             *
076:             * @param objectDefinition
077:             */
078:            private Lookup(InputStream objectDefinition) {
079:                ObjectDefinitionBuilder b = new ObjectDefinitionBuilder();
080:                this .objectdef = b.parse(objectDefinition);
081:                createLookup();
082:            }
083:
084:            /**
085:             * populate the lookupMap and the childIndex
086:             *
087:             */
088:            private void createLookup() {
089:                createLooupMap(lookupMap, objectdef, objectdef.getName());
090:                createChildIndex(childIndex, objectdef, objectdef.getName());
091:
092:            }
093:
094:            /**
095:             * populate the childIndex
096:             *
097:             */
098:            private void createChildIndex(
099:                    HashMap<String, Integer> childTypeIndex,
100:                    ObjectDefinition context, String prefix) {
101:                for (int i = 0; i < context.getChildren().size(); i++) {
102:
103:                    ObjectDefinition child = context.getChildren().get(i);
104:                    String cname = child.getName();
105:                    String key = prefix + "." + cname;
106:                    childTypeIndex.put(key, i);
107:                    createChildIndex(childTypeIndex, child, key);
108:                }
109:
110:            }
111:
112:            /**
113:             * populate the lookupMap
114:             *
115:             */
116:            private void createLooupMap(
117:                    HashMap<String, HashMap<String, Integer>> lmap,
118:                    ObjectDefinition context, String prefix) {
119:
120:                lmap.put(prefix, createFieldMap(context));
121:
122:                for (int i = 0; i < context.getChildren().size(); i++) {
123:
124:                    ObjectDefinition child = context.getChildren().get(i);
125:                    String cname = child.getName();
126:                    String key = prefix + "." + cname;
127:                    createLooupMap(lmap, child, key);
128:                }
129:
130:            }
131:
132:            /**
133:             * create the field map for a given ObjectDefinition
134:             *
135:             * @param context
136:             * @return
137:             */
138:            private HashMap<String, Integer> createFieldMap(
139:                    ObjectDefinition context) {
140:
141:                HashMap<String, Integer> map = new HashMap<String, Integer>();
142:
143:                ArrayList<Field> fields = context.getFields();
144:
145:                for (int i = 0; i < fields.size(); i++) {
146:                    map.put(fields.get(i).getName(), i);
147:                }
148:                return map;
149:            }
150:
151:            /**
152:             * utility method to create Lookup from objectDefinition InputStream
153:             *
154:             * @param objectDefinition
155:             * @return
156:             */
157:            public static Lookup createLookup(InputStream objectDefinition) {
158:
159:                Lookup l = new Lookup(objectDefinition);
160:                return l;
161:
162:            }
163:
164:            /**
165:             * utility method to create Lookup from objectDefinition Object
166:             *
167:             * @param objectDefinition
168:             * @return
169:             */
170:            public static Lookup createLookup(ObjectDefinition objectDefinition) {
171:                Lookup l = new Lookup(objectDefinition);
172:                return l;
173:
174:            }
175:
176:            /**
177:             * returns the field index for a given fieldName and prefix where given an
178:             * ePath Person.Address.city , fieldName=city and prefix=Person.Address,
179:             * will return -1 if the field does not exist in the object definition
180:             *
181:             * @param fieldName
182:             * @param prefix
183:             * @return
184:             */
185:            public int getFieldIndex(String fieldName, String prefix) {
186:
187:                if (lookupMap.get(prefix) == null) {
188:                    return -1;
189:                }
190:
191:                Integer i = lookupMap.get(prefix).get(fieldName);
192:
193:                if (i == null) {
194:                    return -1;
195:                } else {
196:                    return i.intValue();
197:                }
198:
199:            }
200:
201:            /**
202:             * returns the child index for a given prefix can be Person.Address
203:             *
204:             * @param prefix
205:             * @return
206:             */
207:            public int getChildTypeIndex(String prefix) {
208:                Integer i = childIndex.get(prefix);
209:
210:                if (i == null) {
211:                    return -1;
212:                } else {
213:                    return i.intValue();
214:                }
215:            }
216:
217:            public String getChildTypeName(int j) {
218:                Iterator i = childIndex.keySet().iterator();
219:                while (i.hasNext()) {
220:                    String key = (String) i.next();
221:                    if ((int) childIndex.get(key) == j) {
222:                        return key.substring(key.indexOf(".") + 1);
223:                    }
224:                }
225:                return null;
226:            }
227:
228:            public HashMap getChildIndexMap() {
229:                return this .childIndex;
230:            }
231:
232:            public HashMap getLookupMap() {
233:                return this .lookupMap;
234:            }
235:
236:            public ArrayList getFields(String tablename) {
237:                // Look out for parent fields
238:                if (this .objectdef.getName().equals(tablename)) {
239:                    return objectdef.getFields();
240:                } else {
241:                    // Look out for children fields
242:                    for (int i = 0; i < objectdef.getChildren().size(); i++) {
243:                        ObjectDefinition odef = (ObjectDefinition) this .objectdef
244:                                .getchild(i);
245:                        if (odef.getName().equals(tablename)) {
246:                            return odef.getFields();
247:                        }
248:                    }
249:                }
250:
251:                mLogger
252:                        .infoNoloc(mLoc
253:                                .t(
254:                                        "PRSR014: Fields for table [{0} cannot be found in the data model",
255:                                        tablename));
256:                return null;
257:            }
258:
259:            public String getRootName() {
260:                return this .objectdef.getName();
261:            }
262:
263:            /**
264:             * @param args
265:             */
266:            public static void main(String[] args) {
267:
268:                try {
269:                    //FileInputStream fis = new FileInputStream("D:/temp/eviewconfig/objectdef.xml");
270:                    FileInputStream fis = new FileInputStream(
271:                            "D:/temp/forMANISH/objectdef.xml");
272:                    Lookup l = createLookup(fis);
273:                } catch (FileNotFoundException e) {
274:                    // TODO Auto-generated catch block
275:                    e.printStackTrace();
276:                }
277:
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.