Source Code Cross Referenced for HandlerChainDocument.java in  » ESB » celtix-1.0 » org » objectweb » celtix » bus » handlers » 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 » celtix 1.0 » org.objectweb.celtix.bus.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.bus.handlers;
002:
003:        import java.io.InputStream;
004:        import java.util.ArrayList;
005:        import java.util.List;
006:
007:        import javax.xml.namespace.QName;
008:        import javax.xml.parsers.DocumentBuilder;
009:        import javax.xml.parsers.DocumentBuilderFactory;
010:        import javax.xml.ws.WebServiceException;
011:
012:        import org.w3c.dom.Document;
013:        import org.w3c.dom.Element;
014:        import org.w3c.dom.Node;
015:        import org.w3c.dom.NodeList;
016:
017:        import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType;
018:        import org.objectweb.celtix.configuration.ConfigurationItemMetadata;
019:        import org.objectweb.celtix.configuration.impl.TypeSchema;
020:        import org.objectweb.celtix.configuration.impl.TypeSchemaHelper;
021:
022:        public class HandlerChainDocument {
023:            private static final String HANDLER_CHAIN_TYPE_NAME = "handlerChainType";
024:            private static final String HANDLER_CONFIG_ELEM_NAME = "handler-config";
025:            private static final String HANDLER_CHAIN_ELEM_NAME = "handler-chain";
026:            private static final String HANDLER_CHAIN_NAME_ELEM_NAME = "handler-chain-name";
027:            private static final String HANDLER_ELEM_NAME = "handler";
028:            private static final String HANDLER_NAME_ELEM_NAME = "handler-name";
029:            private static final String HANDLER_CLASS_ELEM_NAME = "handler-class";
030:            private static final String INIT_PARAM_ELEM_NAME = "init=param";
031:            private static final String PARAM_NAME_ELEM_NAME = "param-name";
032:            private static final String PARAM_VALUE_ELEM_NAME = "param-value";
033:            private static final String JAXWS_TYPES_URI = "http://celtix.objectweb.org/bus/jaxws/configuration/types";
034:
035:            private List<HandlerChainType> chains;
036:
037:            HandlerChainDocument(InputStream is, boolean doValidate) {
038:                chains = new ArrayList<HandlerChainType>();
039:                try {
040:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
041:                            .newInstance();
042:                    dbf.setNamespaceAware(false);
043:                    DocumentBuilder builder = dbf.newDocumentBuilder();
044:                    Document srcDoc = builder.parse(is);
045:                    dbf.setNamespaceAware(true);
046:                    Document destDoc = builder.newDocument();
047:                    transform(srcDoc, destDoc);
048:
049:                    NodeList chainNodes = destDoc.getFirstChild()
050:                            .getChildNodes();
051:                    for (int i = 0; i < chainNodes.getLength(); i++) {
052:                        Node node = chainNodes.item(i);
053:                        if (Node.ELEMENT_NODE == node.getNodeType()
054:                                && HANDLER_CHAIN_ELEM_NAME
055:                                        .equals(getNodeName(node))) {
056:
057:                            String location = "schemas/configuration/jaxws-types.xsd";
058:                            TypeSchema ts = new TypeSchemaHelper(true).get(
059:                                    JAXWS_TYPES_URI, null, location);
060:
061:                            ConfigurationItemMetadata mdi = new ConfigurationItemMetadata() {
062:                                public Object getDefaultValue() {
063:                                    return null;
064:                                }
065:
066:                                public LifecyclePolicy getLifecyclePolicy() {
067:                                    return LifecyclePolicy.STATIC;
068:                                }
069:
070:                                public String getName() {
071:                                    return "handlerChain";
072:                                }
073:
074:                                public QName getType() {
075:                                    return new QName(JAXWS_TYPES_URI,
076:                                            HANDLER_CHAIN_TYPE_NAME);
077:                                }
078:
079:                            };
080:
081:                            Object obj = ts.unmarshalDefaultValue(mdi,
082:                                    (Element) node, doValidate);
083:                            chains.add((HandlerChainType) obj);
084:                        }
085:                    }
086:                } catch (Exception ex) {
087:                    if (ex instanceof  WebServiceException) {
088:                        throw (WebServiceException) ex;
089:                    }
090:                    throw new WebServiceException(ex);
091:                }
092:            }
093:
094:            HandlerChainType getChain(String name) {
095:                if (null == name || "".equals(name)) {
096:                    return chains.size() > 0 ? chains.get(0) : null;
097:                }
098:                for (HandlerChainType hc : chains) {
099:                    if (name.equals(hc.getHandlerChainName())) {
100:                        return hc;
101:                    }
102:                }
103:                return null;
104:            }
105:
106:            private String getNodeName(Node node) {
107:                String name = node.getNodeName();
108:                if (name.contains(":")) {
109:                    name = name.substring(name.indexOf(":") + 1);
110:                }
111:                return name;
112:            }
113:
114:            private void transform(Document src, Document dest) {
115:                Node destNode = dest.createElement(HANDLER_CONFIG_ELEM_NAME);
116:                dest.appendChild(destNode);
117:                Node srcNode = src.getFirstChild();
118:                createChainNodes(src, srcNode, dest, destNode);
119:            }
120:
121:            private void createChainNodes(Document src, Node srcNode,
122:                    Document dest, Node destNode) {
123:                NodeList nodes = srcNode.getChildNodes();
124:                for (int i = 0; i < nodes.getLength(); i++) {
125:                    Node node = nodes.item(i);
126:                    if (Node.ELEMENT_NODE == node.getNodeType()
127:                            && HANDLER_CHAIN_ELEM_NAME
128:                                    .equals(getNodeName(node))) {
129:                        Element el = dest.createElementNS(JAXWS_TYPES_URI,
130:                                HANDLER_CHAIN_ELEM_NAME);
131:                        destNode.appendChild(el);
132:                        createLeafNode(src, node, dest, el,
133:                                HANDLER_CHAIN_NAME_ELEM_NAME);
134:                        createHandlerNodes(src, node, dest, el);
135:                    }
136:                }
137:            }
138:
139:            private void createLeafNode(Document src, Node srcNode,
140:                    Document dest, Node destNode, String type) {
141:                NodeList nodes = srcNode.getChildNodes();
142:                for (int i = 0; i < nodes.getLength(); i++) {
143:                    Node node = nodes.item(i);
144:                    if (Node.ELEMENT_NODE == node.getNodeType()
145:                            && type.equals(getNodeName(node))) {
146:                        Element el = dest
147:                                .createElementNS(JAXWS_TYPES_URI, type);
148:                        el.setTextContent(node.getTextContent());
149:                        destNode.appendChild(el);
150:                        break;
151:                    }
152:                }
153:            }
154:
155:            private void createHandlerNodes(Document src, Node srcNode,
156:                    Document dest, Node destNode) {
157:                NodeList nodes = srcNode.getChildNodes();
158:                for (int i = 0; i < nodes.getLength(); i++) {
159:                    Node node = nodes.item(i);
160:                    if (Node.ELEMENT_NODE == node.getNodeType()
161:                            && HANDLER_ELEM_NAME.equals(getNodeName(node))) {
162:                        Element el = dest.createElementNS(JAXWS_TYPES_URI,
163:                                HANDLER_ELEM_NAME);
164:                        destNode.appendChild(el);
165:                        createLeafNode(src, node, dest, el,
166:                                HANDLER_NAME_ELEM_NAME);
167:                        createLeafNode(src, node, dest, el,
168:                                HANDLER_CLASS_ELEM_NAME);
169:                        createInitParamNodes(src, node, dest, el);
170:                    }
171:                }
172:            }
173:
174:            private void createInitParamNodes(Document src, Node srcNode,
175:                    Document dest, Node destNode) {
176:                NodeList nodes = srcNode.getChildNodes();
177:                for (int i = 0; i < nodes.getLength(); i++) {
178:                    Node node = nodes.item(i);
179:                    if (Node.ELEMENT_NODE == node.getNodeType()
180:                            && INIT_PARAM_ELEM_NAME.equals(getNodeName(node))) {
181:                        Element el = dest.createElementNS(JAXWS_TYPES_URI,
182:                                INIT_PARAM_ELEM_NAME);
183:                        destNode.appendChild(el);
184:                        createLeafNode(src, node, dest, el,
185:                                PARAM_NAME_ELEM_NAME);
186:                        createLeafNode(src, node, dest, el,
187:                                PARAM_VALUE_ELEM_NAME);
188:                    }
189:                }
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.