Source Code Cross Referenced for MDLDocumentFactory.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » common » mdl » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.common.mdl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         *          Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify 
008:         * it under the terms of the GNU General Public License as published by 
009:         * the Free Software Foundation; either version 2 of the License, or 
010:         * (at your option) any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of 
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
015:         * General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License 
018:         * along with this program; if not, write to the Free Software 
019:         * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307 
020:         * USA
021:         *
022:         * $Id: MDLDocumentFactory.java 6617 2007-04-11 01:04:44Z zjin $
023:         *
024:         */
025:        package com.bostechcorp.cbesb.common.mdl;
026:
027:        import java.io.File;
028:        import java.util.HashMap;
029:
030:        import javax.xml.parsers.SAXParserFactory;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.xml.sax.InputSource;
035:
036:        import com.bostechcorp.cbesb.common.mdl.impl.MDLDocumentImpl;
037:
038:        /**
039:         * Provides methods to retrieve instances of MDLDocument from a file or creating
040:         * new empty MDLDocuments. This also allows for caching of loaded instances.
041:         * 
042:         */
043:        public class MDLDocumentFactory {
044:            protected final transient Log logger = LogFactory
045:                    .getLog(getClass());
046:
047:            private HashMap<String, IMDLDocument> cache;
048:            private boolean cacheEnabled;
049:
050:            /**
051:             * To resolver the locations of referenced MDL files.
052:             */
053:            private IDocLocationResolver docLocationResolver;
054:
055:            public MDLDocumentFactory() {
056:                cacheEnabled = true;
057:                cache = new HashMap<String, IMDLDocument>();
058:                docLocationResolver = new DefaultDocLocationResolver();
059:            }
060:
061:            public MDLDocumentFactory(IDocLocationResolver docLocationResolver) {
062:                cacheEnabled = true;
063:                cache = new HashMap<String, IMDLDocument>();
064:                this .docLocationResolver = docLocationResolver;
065:            }
066:
067:            /**
068:             * Set the cache mode.
069:             *
070:             * @param enabled boolean
071:             */
072:            public void setCacheMode(boolean enabled) {
073:                cacheEnabled = enabled;
074:            }
075:
076:            /**
077:             * purge the cache.
078:             */
079:            public void purgeCache() {
080:                cache.clear();
081:            }
082:
083:            /**
084:             * @return the docLocationResolver
085:             */
086:            public IDocLocationResolver getDocLocationResolver() {
087:                return docLocationResolver;
088:            }
089:
090:            /**
091:             * @param docLocationResolver the docLocationResolver to set
092:             */
093:            public void setDocLocationResolver(
094:                    IDocLocationResolver docLocationResolver) {
095:                this .docLocationResolver = docLocationResolver;
096:            }
097:
098:            public IMDLDocument getMDLDocumentFromFormatSpec(String formatSpec) {
099:                try {
100:                    String cacheID = docLocationResolver
101:                            .getCacheIDFromFormatSpec(formatSpec);
102:                    if (cacheEnabled && cache.containsKey(cacheID)) {
103:                        //This MDL has already been loaded and cached
104:                        return cache.get(cacheID);
105:                    } else {
106:                        //Either the MDL has not been loaded, or cache mode is disabled
107:                        InputSource inputSrc = docLocationResolver
108:                                .resolveFormatSpec(formatSpec);
109:                        IMDLDocument mdlDoc = null;
110:                        SAXParserFactory factory = SAXParserFactory
111:                                .newInstance();
112:                        factory.setNamespaceAware(true);
113:                        MDLParser mdlParser = new MDLParser(this );
114:                        File mdlFile = new File(docLocationResolver
115:                                .getAbsolutePathFromFormatSpec(formatSpec));
116:                        mdlParser.setMdlFile(mdlFile);
117:                        mdlDoc = (MDLDocumentImpl) mdlParser.parse(inputSrc);
118:                        if (cacheEnabled) {
119:                            //Add it to the cache
120:                            cache.put(cacheID, mdlDoc);
121:                        }
122:                        return mdlDoc;
123:                    }
124:                } catch (MDLException e) {
125:                    //			e.printStackTrace();
126:                    logger
127:                            .error("Exception in getMDLDocumentFromFormatSpec(): "
128:                                    + e.getMessage());
129:                    if (logger.isDebugEnabled()) {
130:                        logger.debug(
131:                                "Exception in getMDLDocumentFromFormatSpec():",
132:                                e);
133:                    }
134:                    return null;
135:                }
136:            }
137:
138:            /**
139:             * Get the MDL document.
140:             *
141:             * @param docLocation String
142:             * @return a MDL document.
143:             */
144:            public IMDLDocument getMDLDocument(String docLocation,
145:                    String currentWorkingDirectory) {
146:                try {
147:                    String cacheID = docLocationResolver
148:                            .getCacheIDFromDocLocation(docLocation,
149:                                    currentWorkingDirectory);
150:                    if (cacheEnabled && cache.containsKey(cacheID)) {
151:                        //This MDL has already been loaded and cached
152:                        return cache.get(cacheID);
153:                    } else {
154:                        //Either the MDL has not been loaded, or cache mode is disabled
155:                        InputSource inputSrc = docLocationResolver
156:                                .resolveDocLocation(docLocation,
157:                                        currentWorkingDirectory);
158:                        MDLDocumentImpl mdlDoc = null;
159:                        SAXParserFactory factory = SAXParserFactory
160:                                .newInstance();
161:                        factory.setNamespaceAware(true);
162:                        MDLParser mdlParser = new MDLParser(this );
163:                        File mdlFile = new File(docLocationResolver
164:                                .getAbsolutePathFromDocLocation(docLocation,
165:                                        currentWorkingDirectory));
166:                        mdlParser.setMdlFile(mdlFile);
167:                        mdlDoc = (MDLDocumentImpl) mdlParser.parse(inputSrc);
168:                        if (cacheEnabled) {
169:                            //Add it to the cache
170:                            cache.put(cacheID, mdlDoc);
171:                        }
172:                        return mdlDoc;
173:                    }
174:                } catch (MDLException e) {
175:                    logger.error("Exception in getMDLDocument(): "
176:                            + e.getMessage());
177:                    if (logger.isDebugEnabled()) {
178:                        logger.debug("Exception in getMDLDocument():", e);
179:                    }
180:                    return null;
181:                }
182:            }
183:
184:            /**
185:             * Get the MDL document For x12 .
186:             *
187:             * @param docLocation String
188:             * @return a MDL document.
189:             */
190:            //    public IMDLDocument getMDLDocument(String docLocation,String zipLocation) {
191:            //        File mdlFile = new File(docLocation);
192:            //        mdlDoc = new MDLDocumentImpl();
193:            //        try {
194:            //            SAXParserFactory factory = SAXParserFactory.newInstance();
195:            //            factory.setNamespaceAware(true);
196:            //
197:            //            if (mdlFile == null) {
198:            //                throw new IllegalArgumentException(new Message(Messages.FILE_IS_NULL, docLocation).getMessage());
199:            //            }
200:            //           if(zipLocation==null || zipLocation.equals(""))  mdlDoc = MDLParser.load(mdlFile,zipLocation);
201:            //           else  mdlDoc = MDLParser.load(mdlFile,zipLocation);
202:            //        } catch (MDLException mdle) {
203:            //            mdle.printStackTrace();
204:            //            return new MDLDocumentImpl();
205:            //        }
206:            //        return mdlDoc;
207:            //    }
208:            //   
209:            //    public IMDLDocument getMDLDocument(InputStream inStream,String zipLocation) {
210:            //        mdlDoc = new MDLDocumentImpl();
211:            //        try {
212:            //            SAXParserFactory factory = SAXParserFactory.newInstance();
213:            //            factory.setNamespaceAware(true);
214:            //
215:            //            if (zipLocation !=null)
216:            //            	mdlDoc = MDLParser.load(inStream,zipLocation);
217:            //            else
218:            //            	mdlDoc = MDLParser.load(inStream);
219:            //        } catch (MDLException mdle) {
220:            //            mdle.printStackTrace();
221:            //            return new MDLDocumentImpl();
222:            //        }
223:            //        return mdlDoc;
224:            //    }
225:            /**
226:             * Get a new MDL document.
227:             *
228:             * @return a MDL document.
229:             */
230:            public IMDLDocument getNewMDLDocument() {
231:                IMDLDocument mdlDoc = new MDLDocumentImpl();
232:                return mdlDoc;
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.