KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > api > WSITConfigProvider


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 package org.netbeans.modules.websvc.wsitconf.api;
20
21 import java.util.Collection JavaDoc;
22 import javax.swing.JComponent JavaDoc;
23 import javax.swing.undo.UndoManager JavaDoc;
24 import org.netbeans.api.project.FileOwnerQuery;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
27 import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
28 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
29 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
30 import org.netbeans.modules.websvc.wsitconf.*;
31 import org.netbeans.modules.websvc.wsitconf.ui.service.ServiceTopComponent;
32 import org.netbeans.modules.websvc.wsitconf.util.Util;
33 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityPolicyModelHelper;
34 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.WSITModelSupport;
35 import org.netbeans.modules.xml.wsdl.model.Binding;
36 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
37 import org.openide.ErrorManager;
38 import org.openide.nodes.Node;
39
40 /**
41  *
42  * @author Martin Grebac
43  */

44 public final class WSITConfigProvider extends Object JavaDoc {
45
46     private static WSITConfigProvider instance;
47   
48     private WSITConfigProvider() { }
49
50     public static synchronized WSITConfigProvider getDefault() {
51         if (instance == null) {
52             instance = new WSITConfigProvider();
53         }
54         return instance;
55     }
56     
57     /**
58      * Returns a WSIT configuration editor, then you may call same methods as WS Attributes editor api does,
59      * which means WSEditor.createWSEditorComponent(Node node, JaxWsModel jaxWsModel). This call returns JComponent
60      * with WSIT config UI.
61      * This method only returns dialog - there are no OK/Cancel buttons provided - thus it's required that a
62      * caller of this method makes sure appropriate actions are taken on wsdlModel and undomanager for Cancel/Save actions
63      */

64     public final JComponent JavaDoc getWSITServiceConfig(WSDLModel wsdlModel, UndoManager JavaDoc undoManager, Collection JavaDoc<Binding> bindings) {
65         final ServiceTopComponent stc = new ServiceTopComponent(wsdlModel, undoManager, bindings);
66         return stc;
67     }
68     
69     /**
70      * Should be invoked with same parameters as WSEditor calls are invoked. Returns false if WSIT is not supported,
71      * is switched off, an error happened, or WSIT security features are switched off.
72      * Is here to enable other parties (e.g. AccessManager) to detect if WSIT is configured, because combinations
73      * don't work well together.
74      */

75     public final boolean isWsitSecurityEnabled(Node node, JaxWsModel jaxWsModel) {
76         
77         //is it a client node?
78
Client client = (Client)node.getLookup().lookup(Client.class);
79         //is it a service node?
80
Service service = (Service)node.getLookup().lookup(Service.class);
81         
82         Project p = null;
83         if (jaxWsModel != null) {
84             p = FileOwnerQuery.getOwner(jaxWsModel.getJaxWsFile());
85         }
86
87         if (p != null) {
88             if (Util.isWsitSupported(p)) {
89                 try {
90                     WSDLModel wsdlModel = WSITModelSupport.getModel(node, jaxWsModel, null, false, null);
91                     if (wsdlModel != null) {
92                         if (client != null) { //it's a client
93
JAXWSClientSupport wscs = JAXWSClientSupport.getJaxWsClientSupport(p.getProjectDirectory());
94                             if (wscs != null) {
95                                 WSDLModel serviceWsdlModel = WSITModelSupport.getServiceModelForClient(wscs, client);
96                                 Collection JavaDoc<Binding> bindings = serviceWsdlModel.getDefinitions().getBindings();
97                                 for (Binding b : bindings) {
98                                     if (SecurityPolicyModelHelper.isSecurityEnabled(b)) {
99                                         return true;
100                                     }
101                                 }
102                             }
103                         } else if (service != null) {
104                             Collection JavaDoc<Binding> bindings = wsdlModel.getDefinitions().getBindings();
105                             for (Binding b : bindings) {
106                                 if (SecurityPolicyModelHelper.isSecurityEnabled(b)) {
107                                     return true;
108                                 }
109                             }
110                         }
111                     }
112                 } catch(Exception JavaDoc e) {
113                     ErrorManager.getDefault().notify(e);
114                 }
115             }
116         }
117         return false;
118     }
119
120     /**
121      * Should be invoked with same parameters as WSEditor calls are invoked. Returns false if WSIT is not supported,
122      * is switched off, or an error happened.
123      * Is here to enable other parties (e.g. AccessManager) to detect if WSIT is configured, because combinations
124      * don't work well together.
125      */

126     public final boolean isWsitEnabled(Node node, JaxWsModel jaxWsModel) {
127         
128         Project p = null;
129         if (jaxWsModel != null) {
130             p = FileOwnerQuery.getOwner(jaxWsModel.getJaxWsFile());
131         }
132
133         if (p != null) {
134             if (Util.isWsitSupported(p)) {
135                 try {
136                     WSDLModel wsdlModel = WSITModelSupport.getModel(node, jaxWsModel, null, false, null);
137                     if (wsdlModel != null) {
138                         return true;
139                     }
140                 } catch(Exception JavaDoc e) {
141                     ErrorManager.getDefault().notify(e);
142                 }
143             }
144         }
145         return false;
146     }
147     
148 }
149
Popular Tags