KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > wsdlmodelext > RMSunModelHelper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext;
21
22 import org.netbeans.modules.websvc.wsitmodelext.policy.All;
23 import org.netbeans.modules.websvc.wsitmodelext.policy.Policy;
24 import org.netbeans.modules.websvc.wsitmodelext.rm.AckRequestInterval;
25 import org.netbeans.modules.websvc.wsitmodelext.rm.CloseTimeout;
26 import org.netbeans.modules.websvc.wsitmodelext.rm.Ordered;
27 import org.netbeans.modules.websvc.wsitmodelext.rm.RMSunClientQName;
28 import org.netbeans.modules.websvc.wsitmodelext.rm.RMSunQName;
29 import org.netbeans.modules.websvc.wsitmodelext.rm.ResendInterval;
30 import org.netbeans.modules.xml.wsdl.model.Binding;
31 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
32
33 /**
34  *
35  * @author Martin Grebac
36  */

37 public class RMSunModelHelper {
38     
39     /**
40      * Creates a new instance of RMSunModelHelper
41      */

42     public RMSunModelHelper() {
43     }
44     
45     // enables Ordered delivery in the config wsdl on specified binding
46
public static void enableOrdered(Binding b) {
47         All a = PolicyModelHelper.createPolicy(b);
48         PolicyModelHelper.createElement(a, RMSunQName.ORDERED.getQName(), Ordered.class, false);
49     }
50
51     // disables Ordered delivery in the config wsdl on specified binding
52
public static void disableOrdered(Binding b) {
53         WSDLModel model = b.getModel();
54         Policy p = PolicyModelHelper.getPolicyForElement(b);
55         Ordered ord = getOrdered(p);
56         if (ord != null) {
57             PolicyModelHelper.removeElement(ord.getParent(), Ordered.class, false);
58         }
59         PolicyModelHelper.cleanPolicies(b);
60     }
61
62     // checks if Flow Control is enabled in the config wsdl on specified binding
63
public static boolean isOrderedEnabled(Binding b) {
64         WSDLModel model = b.getModel();
65         Policy p = PolicyModelHelper.getPolicyForElement(b);
66         if (p != null) {
67             Ordered ord = getOrdered(p);
68             return (ord != null);
69         }
70         return false;
71     }
72     
73     public static Ordered getOrdered(Policy p) {
74         return (Ordered) PolicyModelHelper.getTopLevelElement(p, Ordered.class);
75     }
76
77     public static String JavaDoc getResendInterval(Binding b) {
78         WSDLModel model = b.getModel();
79         Policy p = PolicyModelHelper.getPolicyForElement(b);
80         ResendInterval ri = (ResendInterval) PolicyModelHelper.getTopLevelElement(p, ResendInterval.class);
81         if (ri != null) {
82             return ri.getResendInterval();
83         }
84         return null;
85     }
86     
87     public static void setResendInterval(Binding b, String JavaDoc value) {
88         WSDLModel model = b.getModel();
89         All all = PolicyModelHelper.createPolicy(b);
90         ResendInterval ri = PolicyModelHelper.createElement(all,
91                 RMSunClientQName.RESENDINTERVAL.getQName(), ResendInterval.class, false);
92         boolean isTransaction = model.isIntransaction();
93         if (!isTransaction) {
94             model.startTransaction();
95         }
96         try {
97             if ((value == null) && (ri != null)) {
98                 PolicyModelHelper.removeElement(ri);
99             } else {
100                 ri.setResendInterval(value);
101             }
102         } finally {
103             if (!isTransaction) {
104                 model.endTransaction();
105             }
106         }
107     }
108
109     public static String JavaDoc getCloseTimeout(Binding b) {
110         WSDLModel model = b.getModel();
111         Policy p = PolicyModelHelper.getPolicyForElement(b);
112         CloseTimeout ct = (CloseTimeout) PolicyModelHelper.getTopLevelElement(p, CloseTimeout.class);
113         if (ct != null) {
114             return ct.getCloseTimeout();
115         }
116         return null;
117     }
118     
119     public static void setCloseTimeout(Binding b, String JavaDoc value) {
120         WSDLModel model = b.getModel();
121         All all = PolicyModelHelper.createPolicy(b);
122         CloseTimeout ct = PolicyModelHelper.createElement(all,
123                 RMSunClientQName.CLOSETIMEOUT.getQName(), CloseTimeout.class, false);
124         boolean isTransaction = model.isIntransaction();
125         if (!isTransaction) {
126             model.startTransaction();
127         }
128         try {
129             if ((value == null) && (ct != null)) {
130                 PolicyModelHelper.removeElement(ct);
131             } else {
132                 ct.setCloseTimeout(value);
133             }
134         } finally {
135             if (!isTransaction) {
136                 model.endTransaction();
137             }
138         }
139     }
140     
141     public static String JavaDoc getAckRequestInterval(Binding b) {
142         WSDLModel model = b.getModel();
143         Policy p = PolicyModelHelper.getPolicyForElement(b);
144         AckRequestInterval ri = PolicyModelHelper.getTopLevelElement(p, AckRequestInterval.class);
145         if (ri != null) {
146             return ri.getAckRequestInterval();
147         }
148         return null;
149     }
150     
151     public static void setAckRequestInterval(Binding b, String JavaDoc value) {
152         WSDLModel model = b.getModel();
153         All all = PolicyModelHelper.createPolicy(b);
154         AckRequestInterval ri = PolicyModelHelper.createElement(all,
155                 RMSunClientQName.ACKREQUESTINTERVAL.getQName(), AckRequestInterval.class, false);
156         boolean isTransaction = model.isIntransaction();
157         if (!isTransaction) {
158             model.startTransaction();
159         }
160         try {
161             if ((value == null) && (ri != null)) {
162                 PolicyModelHelper.removeElement(ri);
163             } else {
164                 ri.setAckRequestInterval(value);
165             }
166         } finally {
167             if (!isTransaction) {
168                 model.endTransaction();
169             }
170         }
171     }
172     
173 }
174
Popular Tags