Source Code Cross Referenced for FixedElementParser.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » parser » 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.runtime.parser 
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 it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * 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 MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id: FixedElementParser.java 3622 2006-12-12 03:04:08Z lzheng $
023:         */
024:        package com.bostechcorp.cbesb.runtime.parser;
025:
026:        import java.io.ByteArrayInputStream;
027:        import java.io.IOException;
028:        import java.io.InputStream;
029:        import java.io.InputStreamReader;
030:        import java.io.UnsupportedEncodingException;
031:
032:        import org.w3c.dom.Element;
033:
034:        import com.bostechcorp.cbesb.common.i18n.Message;
035:        import com.bostechcorp.cbesb.common.i18n.Messages;
036:        import com.bostechcorp.cbesb.common.mdl.IContentElement;
037:        import com.bostechcorp.cbesb.common.mdl.IContentGroup;
038:        import com.bostechcorp.cbesb.common.mdl.IContentNode;
039:        import com.bostechcorp.cbesb.common.mdl.IElementDefinition;
040:        import com.bostechcorp.cbesb.common.mdl.IFixedChildAttributes;
041:        import com.bostechcorp.cbesb.common.util.ErrorUtil;
042:        import com.bostechcorp.cbesb.runtime.parser.impl.LegacyDataParser;
043:
044:        /**
045:         * The FixedElementParser class implements ElementParser. It is used to parse
046:         * elements defined as fixed format. 
047:         * Basic flow of the parse method: 
048:         * 1. Create a new Element with the name and namespace provided in the ElementDefinition. 
049:         * 2. Loop over all of the child ContentElement nodes defined in the ElementDefinition. 
050:         * 	  For each child, do the following: 
051:         * 	  a. Get the length of the data for the child 
052:         *    b. Read that many characters from the InputStream into a buffer. 
053:         *    c. Using the justification and fill character settings, trim the buffer 
054:         *    to contain only meaningful data. 
055:         *    d. Create a new InputStream containing this data only. 
056:         *    e. Get the ElementDefinition from the ContentElement that defines the child. 
057:         *    f. Get an instance of ElementParser from ElementParserFactory using the 
058:         *    child ElementDefinition as input. 
059:         *    g. Call the parse method of this ElementParser passing in the new InputStream and
060:         *    child ElementDefinition. 
061:         *    h. Append the returned DOM Element to the Element created in step 1.
062:         * 
063:         */
064:        public class FixedElementParser implements  IElementParser {
065:
066:            /* (non-Javadoc)
067:             * @see com.bostechcorp.cbesb.runtime.component.parser.IElementParser#parse(java.io.InputStream, com.bostechcorp.cbesb.common.mdl.IElementDefinition)
068:             */
069:            public Element parse(InputStream is,
070:                    IElementDefinition elementDefinition)
071:                    throws ParserException {
072:
073:                try {
074:                    InputStreamReader isReader = new InputStreamReader(is,
075:                            "utf-8");
076:                    Element element = LegacyDataParser.getDocument()
077:                            .createElementNS(
078:                                    elementDefinition.getNamespaceURI(),
079:                                    elementDefinition.getName());
080:
081:                    //Loop through the elements under content node
082:                    for (int i = 0; i < elementDefinition.getChildCount(); i++) {
083:                        IContentNode contentNode = elementDefinition
084:                                .getChildAtIndex(i);
085:                        if (contentNode instanceof  IContentElement) {
086:                            //Get discription for this fixed contentNode
087:                            IFixedChildAttributes fixedChildAttributes = (IFixedChildAttributes) ((IContentElement) contentNode)
088:                                    .getFormatChildAttributes();
089:                            //Descript fixed data
090:                            String childData = scanFixedData(
091:                                    fixedChildAttributes, isReader);
092:
093:                            IElementDefinition childElementDefinition = ((IContentElement) contentNode)
094:                                    .getResolvedElementDef();
095:
096:                            IElementParser childParser = ElementParserFactory
097:                                    .instance().getElementParser(
098:                                            childElementDefinition);
099:
100:                            //		            //Check if name of chileElementDefinition is empty mean reference
101:                            //		            if (childElementDefinition.getName().equals("")) {
102:                            //		            	childElementDefinition.setName(((IContentElement)contentNode).getRef());
103:                            //		            }
104:                            //	            	System.out.println("");
105:                            Element child = childParser.parse(
106:                                    new ByteArrayInputStream(childData
107:                                            .getBytes("utf-8")),
108:                                    childElementDefinition);
109:                            element.appendChild(child);
110:                        } else if (contentNode instanceof  IContentGroup) {
111:                            // TODO LU  can we skip here?
112:                            //See if Fixed type could have group node
113:                        }
114:                    }
115:
116:                    return element;
117:
118:                } catch (UnsupportedEncodingException e) {
119:                    //			ErrorUtil.printError("Exception in parse()",e);
120:                    //			throw new ParserException(new Message(Messages.SCAN_FIXED_DATA, e.getMessage()).getMessage());
121:                    throw new ParserException(
122:                            "IOExceptection caught when converting string to UTF-8 in parsing element '"
123:                                    + elementDefinition.getNamespaceURI() + ":"
124:                                    + elementDefinition.getName() + "'", e);
125:                }
126:            }
127:
128:            private String scanFixedData(IFixedChildAttributes fixedAttr,
129:                    InputStreamReader reader) throws ParserException {
130:
131:                String retValue = "";
132:
133:                int length = fixedAttr.getLength();
134:                char[] charbuffer = new char[length];
135:                StringBuffer strBuf = new StringBuffer();
136:                int charsRead = 0;
137:
138:                try {
139:                    charsRead = reader.read(charbuffer, 0, length);
140:                } catch (IOException ioe) {
141:                    ErrorUtil.printError("Exception in scanFixedData() ", ioe);
142:                    throw new ParserException(new Message(
143:                            Messages.SCAN_FIXED_DATA, ioe.getMessage())
144:                            .getMessage());
145:                }
146:
147:                if (charsRead > -1) {
148:                    strBuf.append(charbuffer, 0, charsRead);
149:                }
150:
151:                char fillChar = fixedAttr.getFillChar();
152:                if (fillChar != 0) {
153:                    if (fixedAttr.getJustification() == IFixedChildAttributes.JUSTIFICATION_LEFT) {
154:                        for (int i = strBuf.length() - 1; i >= 0; i--) {
155:                            if (strBuf.charAt(i) != fillChar) {
156:                                retValue = strBuf.substring(0, i + 1);
157:                                break;
158:                            }
159:                        }
160:                    } else {
161:                        for (int i = 0; i < strBuf.length(); i++) {
162:                            if (strBuf.charAt(i) != fillChar) {
163:                                retValue = strBuf.substring(i);
164:                                break;
165:                            }
166:                        }
167:                    }
168:                } else {
169:                    retValue = strBuf.toString();
170:                }
171:
172:                //System.out.println(retValue);
173:
174:                return retValue;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.