Source Code Cross Referenced for PolicyUtils.java in  » Web-Services-apache-cxf-2.0.1 » ws-rm » org » apache » cxf » ws » rm » policy » 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 apache cxf 2.0.1 » ws rm » org.apache.cxf.ws.rm.policy 
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:         */package org.apache.cxf.ws.rm.policy;
019:
020:        import java.math.BigInteger;
021:        import java.util.Collection;
022:
023:        import org.apache.cxf.message.Message;
024:        import org.apache.cxf.ws.policy.AssertionInfo;
025:        import org.apache.cxf.ws.policy.AssertionInfoMap;
026:        import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
027:        import org.apache.cxf.ws.rm.RMConstants;
028:        import org.apache.cxf.ws.rm.policy.RMAssertion.AcknowledgementInterval;
029:        import org.apache.cxf.ws.rm.policy.RMAssertion.BaseRetransmissionInterval;
030:        import org.apache.cxf.ws.rm.policy.RMAssertion.InactivityTimeout;
031:
032:        /**
033:         * 
034:         */
035:        public final class PolicyUtils {
036:
037:            /**
038:             * Prevents instantiation.
039:             *
040:             */
041:            private PolicyUtils() {
042:            }
043:
044:            /**
045:             * Returns an RMAssertion that is compatible with the default value
046:             * and all RMAssertions pertaining to the message (can never be null).
047:             * 
048:             * @param rma the default value
049:             * @param message the message
050:             * @return the compatible RMAssertion
051:             */
052:            public static RMAssertion getRMAssertion(RMAssertion defaultValue,
053:                    Message message) {
054:                RMAssertion compatible = defaultValue;
055:                AssertionInfoMap amap = message.get(AssertionInfoMap.class);
056:                if (null != amap) {
057:                    Collection<AssertionInfo> ais = amap.get(RMConstants
058:                            .getRMAssertionQName());
059:                    if (null != ais) {
060:
061:                        for (AssertionInfo ai : ais) {
062:                            JaxbAssertion<RMAssertion> ja = getAssertion(ai);
063:                            RMAssertion rma = ja.getData();
064:                            compatible = null == defaultValue ? rma
065:                                    : intersect(compatible, rma);
066:                        }
067:                    }
068:                }
069:                return compatible;
070:            }
071:
072:            public static RMAssertion intersect(RMAssertion a, RMAssertion b) {
073:                if (equals(a, b)) {
074:                    return a;
075:                }
076:                RMAssertion compatible = new RMAssertion();
077:
078:                // use maximum of inactivity timeout
079:
080:                BigInteger aval = null;
081:                if (null != a.getInactivityTimeout()) {
082:                    aval = a.getInactivityTimeout().getMilliseconds();
083:                }
084:                BigInteger bval = null;
085:                if (null != b.getInactivityTimeout()) {
086:                    bval = b.getInactivityTimeout().getMilliseconds();
087:                }
088:                if (null != aval || null != bval) {
089:                    InactivityTimeout ia = new RMAssertion.InactivityTimeout();
090:                    if (null != aval && null != bval) {
091:                        ia.setMilliseconds(aval.max(bval));
092:                    } else {
093:                        ia.setMilliseconds(aval != null ? aval : bval);
094:                    }
095:                    compatible.setInactivityTimeout(ia);
096:                }
097:
098:                // use minimum of base retransmission interval
099:
100:                aval = null;
101:                if (null != a.getBaseRetransmissionInterval()) {
102:                    aval = a.getBaseRetransmissionInterval().getMilliseconds();
103:                }
104:                bval = null;
105:                if (null != b.getBaseRetransmissionInterval()) {
106:                    bval = b.getBaseRetransmissionInterval().getMilliseconds();
107:                }
108:                if (null != aval || null != bval) {
109:                    BaseRetransmissionInterval bri = new RMAssertion.BaseRetransmissionInterval();
110:                    if (null != aval && null != bval) {
111:                        bri.setMilliseconds(aval.min(bval));
112:                    } else {
113:                        bri.setMilliseconds(aval != null ? aval : bval);
114:                    }
115:                    compatible.setBaseRetransmissionInterval(bri);
116:                }
117:
118:                // use minimum of acknowledgement interval
119:
120:                aval = null;
121:                if (null != a.getAcknowledgementInterval()) {
122:                    aval = a.getAcknowledgementInterval().getMilliseconds();
123:                }
124:                bval = null;
125:                if (null != b.getAcknowledgementInterval()) {
126:                    bval = b.getAcknowledgementInterval().getMilliseconds();
127:                }
128:                if (null != aval || null != bval) {
129:                    AcknowledgementInterval ai = new RMAssertion.AcknowledgementInterval();
130:                    if (null != aval && null != bval) {
131:                        ai.setMilliseconds(aval.min(bval));
132:                    } else {
133:                        ai.setMilliseconds(aval != null ? aval : bval);
134:                    }
135:                    compatible.setAcknowledgementInterval(ai);
136:                }
137:
138:                // backoff parameter
139:                if (null != a.getExponentialBackoff()
140:                        || null != b.getExponentialBackoff()) {
141:                    compatible
142:                            .setExponentialBackoff(new RMAssertion.ExponentialBackoff());
143:                }
144:                return compatible;
145:            }
146:
147:            public static boolean equals(RMAssertion a, RMAssertion b) {
148:                if (a == b) {
149:                    return true;
150:                }
151:
152:                BigInteger aval = null;
153:                if (null != a.getInactivityTimeout()) {
154:                    aval = a.getInactivityTimeout().getMilliseconds();
155:                }
156:                BigInteger bval = null;
157:                if (null != b.getInactivityTimeout()) {
158:                    bval = b.getInactivityTimeout().getMilliseconds();
159:                }
160:                if (!equals(aval, bval)) {
161:                    return false;
162:                }
163:
164:                aval = null;
165:                if (null != a.getBaseRetransmissionInterval()) {
166:                    aval = a.getBaseRetransmissionInterval().getMilliseconds();
167:                }
168:                bval = null;
169:                if (null != b.getBaseRetransmissionInterval()) {
170:                    bval = b.getBaseRetransmissionInterval().getMilliseconds();
171:                }
172:                if (!equals(aval, bval)) {
173:                    return false;
174:                }
175:
176:                aval = null;
177:                if (null != a.getAcknowledgementInterval()) {
178:                    aval = a.getAcknowledgementInterval().getMilliseconds();
179:                }
180:                bval = null;
181:                if (null != b.getAcknowledgementInterval()) {
182:                    bval = b.getAcknowledgementInterval().getMilliseconds();
183:                }
184:                if (!equals(aval, bval)) {
185:                    return false;
186:                }
187:
188:                return null == a.getExponentialBackoff() ? null == b
189:                        .getExponentialBackoff() : null != b
190:                        .getExponentialBackoff();
191:            }
192:
193:            private static boolean equals(BigInteger aval, BigInteger bval) {
194:                if (null != aval) {
195:                    if (null != bval) {
196:                        if (!aval.equals(bval)) {
197:                            return false;
198:                        }
199:                    } else {
200:                        return false;
201:                    }
202:                } else {
203:                    if (null != bval) {
204:                        return false;
205:                    }
206:                    return true;
207:                }
208:                return true;
209:            }
210:
211:            @SuppressWarnings("unchecked")
212:            private static JaxbAssertion<RMAssertion> getAssertion(
213:                    AssertionInfo ai) {
214:                return (JaxbAssertion<RMAssertion>) ai.getAssertion();
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.