Source Code Cross Referenced for PolicyEvaluator.java in  » Web-Services-AXIS2 » codegen-wsdl2java » org » apache » axis2 » wsdl » codegen » extension » 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 » Web Services AXIS2 » codegen wsdl2java » org.apache.axis2.wsdl.codegen.extension 
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:         */
019:
020:        package org.apache.axis2.wsdl.codegen.extension;
021:
022:        import org.apache.axis2.context.ConfigurationContext;
023:        import org.apache.axis2.context.ConfigurationContextFactory;
024:        import org.apache.axis2.description.AxisModule;
025:        import org.apache.axis2.description.AxisOperation;
026:        import org.apache.axis2.description.AxisService;
027:        import org.apache.axis2.description.PolicyInclude;
028:        import org.apache.axis2.engine.AxisConfiguration;
029:        import org.apache.axis2.modules.Module;
030:        import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
031:        import org.apache.neethi.Assertion;
032:        import org.apache.neethi.Policy;
033:        import org.w3c.dom.Document;
034:        import org.w3c.dom.Element;
035:
036:        import javax.xml.namespace.QName;
037:        import javax.xml.parsers.DocumentBuilder;
038:        import javax.xml.parsers.DocumentBuilderFactory;
039:        import javax.xml.parsers.ParserConfigurationException;
040:        import java.util.ArrayList;
041:        import java.util.HashMap;
042:        import java.util.Iterator;
043:        import java.util.List;
044:        import java.util.Map;
045:
046:        public class PolicyEvaluator implements  CodeGenExtension {
047:
048:            private CodeGenConfiguration configuration;
049:
050:            /**
051:             * Init method to initialization
052:             *
053:             * @param configuration
054:             * @param namespace2ExtsMap
055:             */
056:            private void init(CodeGenConfiguration configuration,
057:                    Map namespace2ExtsMap) {
058:                this .configuration = configuration;
059:
060:                // adding default PolicyExtensions
061:                namespace2ExtsMap
062:                        .put(
063:                                "http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization",
064:                                new MTOMPolicyExtension(configuration));
065:                namespace2ExtsMap
066:                        .put(
067:                                "http://schemas.xmlsoap.org/ws/2004/09/policy/encoding",
068:                                new EncodePolicyExtension());
069:
070:                String repository = configuration.getRepositoryPath();
071:
072:                if (repository == null) {
073:                    return;
074:                }
075:
076:                try {
077:
078:                    ConfigurationContext configurationCtx = ConfigurationContextFactory
079:                            .createConfigurationContextFromFileSystem(
080:                                    repository, null);
081:                    AxisConfiguration axisConfiguration = configurationCtx
082:                            .getAxisConfiguration();
083:
084:                    for (Iterator iterator = axisConfiguration.getModules()
085:                            .values().iterator(); iterator.hasNext();) {
086:
087:                        AxisModule axisModule = (AxisModule) iterator.next();
088:                        String[] namespaces = axisModule
089:                                .getSupportedPolicyNamespaces();
090:
091:                        if (namespaces == null) {
092:                            continue;
093:                        }
094:
095:                        Module module = axisModule.getModule();
096:                        if (!(module instanceof  ModulePolicyExtension)) {
097:                            continue;
098:                        }
099:
100:                        PolicyExtension ext = ((ModulePolicyExtension) module)
101:                                .getPolicyExtension();
102:
103:                        for (int i = 0; i < namespaces.length; i++) {
104:                            namespace2ExtsMap.put(namespaces[i], ext);
105:                        }
106:                    }
107:
108:                } catch (Exception e) {
109:                    System.err
110:                            .println("cannot create repository : policy will not be supported");
111:                }
112:            }
113:
114:            public void engage(CodeGenConfiguration configuration) {
115:
116:                Map namespace2ExtMap = new HashMap();
117:                //initialize
118:                init(configuration, namespace2ExtMap);
119:
120:                Document document = getEmptyDocument();
121:                Element rootElement = document
122:                        .createElement("module-codegen-policy-extensions");
123:
124:                AxisOperation axisOperation;
125:                QName opName;
126:                PolicyInclude policyInclude;
127:                Policy policy;
128:
129:                List axisServices = configuration.getAxisServices();
130:                AxisService axisService;
131:                for (Iterator servicesIter = axisServices.iterator(); servicesIter
132:                        .hasNext();) {
133:                    axisService = (AxisService) servicesIter.next();
134:                    for (Iterator iterator = axisService.getOperations(); iterator
135:                            .hasNext();) {
136:                        axisOperation = (AxisOperation) iterator.next();
137:                        opName = axisOperation.getName();
138:
139:                        policyInclude = axisOperation.getPolicyInclude();
140:                        policy = policyInclude.getEffectivePolicy();
141:
142:                        if (policy != null) {
143:                            processPolicies(document, rootElement, policy,
144:                                    opName, namespace2ExtMap);
145:                        }
146:                    }
147:                }
148:
149:                // TODO: think about this how can we support this
150:                configuration.putProperty("module-codegen-policy-extensions",
151:                        rootElement);
152:            }
153:
154:            /**
155:             * Process policies
156:             *
157:             * @param document
158:             * @param rootElement
159:             * @param policy
160:             * @param opName
161:             */
162:            private void processPolicies(Document document,
163:                    Element rootElement, Policy policy, QName opName,
164:                    Map ns2Exts) {
165:
166:                HashMap map = new HashMap();
167:
168:                for (Iterator iterator = policy.getAlternatives(); iterator
169:                        .hasNext();) {
170:
171:                    String targetNamesapce = null;
172:                    Assertion assertion;
173:                    List assertionList;
174:
175:                    for (Iterator assertions = ((List) iterator.next())
176:                            .iterator(); assertions.hasNext();) {
177:
178:                        assertion = (Assertion) assertions.next();
179:                        targetNamesapce = assertion.getName().getNamespaceURI();
180:
181:                        if ((assertionList = (List) map.get(targetNamesapce)) == null) {
182:                            assertionList = new ArrayList();
183:                            map.put(targetNamesapce, assertionList);
184:                        }
185:
186:                        assertionList.add(assertions);
187:                    }
188:
189:                    // here we pick the first policy alternative and ignor the rest
190:                    break;
191:                }
192:
193:                for (Iterator iterator = map.keySet().iterator(); iterator
194:                        .hasNext();) {
195:                    String targetNamespace = (String) iterator.next();
196:                    PolicyExtension policyExtension = (PolicyExtension) ns2Exts
197:                            .get(targetNamespace);
198:
199:                    if (policyExtension == null) {
200:                        System.err
201:                                .println("cannot find a PolicyExtension to process "
202:                                        + targetNamespace + "type assertions");
203:                        continue;
204:                    }
205:
206:                    policyExtension.init(configuration);
207:                    policyExtension.addMethodsToStub(document, rootElement,
208:                            opName, (List) map.get(targetNamespace));
209:                }
210:            }
211:
212:            private Document getEmptyDocument() {
213:                try {
214:                    DocumentBuilder documentBuilder = DocumentBuilderFactory
215:                            .newInstance().newDocumentBuilder();
216:
217:                    return documentBuilder.newDocument();
218:                } catch (ParserConfigurationException e) {
219:                    throw new RuntimeException(e);
220:                }
221:            }
222:
223:            class MTOMPolicyExtension implements  PolicyExtension {
224:
225:                private boolean setOnce = false;
226:                private CodeGenConfiguration configuration;
227:
228:                public void init(CodeGenConfiguration configuration) {
229:                }
230:
231:                public MTOMPolicyExtension(CodeGenConfiguration configuration) {
232:                    this .configuration = configuration;
233:                }
234:
235:                public void addMethodsToStub(Document document,
236:                        Element element, QName operationName, List assertions) {
237:
238:                    // FIXME
239:
240:                    //            if (!setOnce) {
241:                    //                 Object plainBase64PropertyMap = configuration.getProperty(Constants.PLAIN_BASE_64_PROPERTY_KEY);
242:                    //                 configuration.putProperty(Constants.BASE_64_PROPERTY_KEY, plainBase64PropertyMap);
243:                    //
244:                    //                 setOnce = true;
245:                    //            }
246:                    //
247:                    //            Element optimizeContent = document.createElement("optimizeContent");
248:                    //            Element opNameElement = document.createElement("opName");
249:                    //
250:                    //            opNameElement.setAttribute("ns-url", operationName.getNamespaceURI());
251:                    //            opNameElement.setAttribute("localName", operationName.getLocalPart());
252:                    //
253:                    //            optimizeContent.appendChild(opNameElement);
254:                    //
255:                    //            element.appendChild(optimizeContent);
256:                }
257:            }
258:
259:            class EncodePolicyExtension implements  PolicyExtension {
260:
261:                public void init(CodeGenConfiguration configuration) {
262:                }
263:
264:                public void addMethodsToStub(Document document,
265:                        Element element, QName operationName, List assertions) {
266:                    // TODO implement encoding
267:                }
268:            }
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.