KickJava   Java API By Example, From Geeks To Geeks.

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


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.FlowControl;
25 import org.netbeans.modules.websvc.wsitmodelext.rm.MaxReceiveBufferSize;
26 import org.netbeans.modules.websvc.wsitmodelext.rm.RMMSQName;
27 import org.netbeans.modules.xml.wsdl.model.Binding;
28 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory;
29 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
30 import org.netbeans.modules.xml.xam.Model;
31
32 import java.io.IOException JavaDoc;
33 import org.openide.ErrorManager;
34
35 /**
36  *
37  * @author Martin Grebac
38  */

39 public class RMMSModelHelper {
40     
41     /**
42      * Creates a new instance of RMMSModelHelper
43      */

44     public RMMSModelHelper() {
45     }
46     
47     // enables FlowControl in the config wsdl on specified binding
48
public static void enableFlowControl(Binding b) {
49         All a = PolicyModelHelper.createPolicy(b);
50         PolicyModelHelper.createElement(a, RMMSQName.RMFLOWCONTROL.getQName(), FlowControl.class, false);
51     }
52
53     // disables RM in the config wsdl on specified binding
54
public static void disableFlowControl(Binding b) {
55         WSDLModel model = b.getModel();
56         Policy p = PolicyModelHelper.getPolicyForElement(b);
57         FlowControl fc = getFlowControl(p);
58         if (fc != null) {
59             PolicyModelHelper.removeElement(fc.getParent(), FlowControl.class, false);
60         }
61         PolicyModelHelper.cleanPolicies(b);
62     }
63
64     // checks if Flow Control is enabled in the config wsdl on specified binding
65
public static boolean isFlowControlEnabled(Binding b) {
66         Policy p = PolicyModelHelper.getPolicyForElement(b);
67         if (p != null) {
68             FlowControl fc = getFlowControl(p);
69             return (fc != null);
70         }
71         return false;
72     }
73     
74     public static FlowControl getFlowControl(Binding b) {
75         Policy p = PolicyModelHelper.getPolicyForElement(b);
76         return getFlowControl(p);
77     }
78
79     public static FlowControl getFlowControl(Policy p) {
80         return (FlowControl) PolicyModelHelper.getTopLevelElement(p, FlowControl.class);
81     }
82
83     public static void setMaxReceiveBufferSize(Binding b, String JavaDoc value) {
84         WSDLModel model = b.getModel();
85         FlowControl fc = getFlowControl(b);
86         setMaxReceiveBufferSize(fc, value);
87     }
88     
89     public static String JavaDoc getMaxReceiveBufferSize(Binding b) {
90         WSDLModel model = b.getModel();
91         FlowControl fc = getFlowControl(b);
92         return getMaxReceiveBufferSize(fc);
93     }
94     
95     public static String JavaDoc getMaxReceiveBufferSize(FlowControl fc) {
96         String JavaDoc max = null;
97         if (fc != null) {
98             MaxReceiveBufferSize maxBuf = fc.getMaxReceiveBufferSize();
99             if (maxBuf!=null) {
100                 max = maxBuf.getMaxReceiveBufferSize();
101             }
102         }
103         return max;
104     }
105
106     public static void setMaxReceiveBufferSize(FlowControl fc, String JavaDoc value) {
107         if (fc != null) {
108             Model model = fc.getModel();
109             boolean isTransaction = model.isIntransaction();
110             if (!isTransaction) {
111                 model.startTransaction();
112             }
113             try {
114                 MaxReceiveBufferSize maxBufSize = fc.getMaxReceiveBufferSize();
115                 if (maxBufSize == null) {
116                     if (value != null) { // if is null, then there's no element and we want to remove it -> do nothing
117
WSDLComponentFactory wcf = fc.getModel().getFactory();
118                         MaxReceiveBufferSize maxBuf = (MaxReceiveBufferSize)wcf.create(fc,
119                                 RMMSQName.MAXRECEIVEBUFFERSIZE.getQName()
120                                 );
121                         maxBuf.setMaxReceiveBufferSize(value);
122                         fc.addExtensibilityElement(maxBuf);
123                     }
124                 } else {
125                     if (value == null) {
126                         fc.removeMaxReceiveBufferSize(maxBufSize);
127                     } else {
128                         maxBufSize.setMaxReceiveBufferSize(value);
129                     }
130                 }
131             } finally {
132                 if (!isTransaction) {
133                     model.endTransaction();
134                 }
135             }
136         }
137     }
138     
139 }
140
Popular Tags