Source Code Cross Referenced for ClientHandlerButtonListener.java in  » IDE-Netbeans » web.core » org » netbeans » modules » websvc » core » jaxws » nodes » 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 » IDE Netbeans » web.core » org.netbeans.modules.websvc.core.jaxws.nodes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.websvc.core.jaxws.nodes;
042:
043:        import java.awt.event.ActionEvent;
044:        import java.awt.event.ActionListener;
045:        import java.io.BufferedReader;
046:        import java.io.BufferedWriter;
047:        import java.io.File;
048:        import java.io.IOException;
049:        import java.io.InputStream;
050:        import java.io.InputStreamReader;
051:        import java.io.OutputStream;
052:        import java.io.OutputStreamWriter;
053:        import java.net.URI;
054:        import java.util.Collection;
055:        import javax.swing.table.TableModel;
056:        import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
057:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsComponentFactory;
058:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandler;
059:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerChain;
060:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerChains;
061:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerClass;
062:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsModel;
063:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsModelFactory;
064:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.DefinitionsBindings;
065:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.GlobalBindings;
066:        import org.netbeans.modules.websvc.core.webservices.ui.panels.MessageHandlerPanel;
067:        import org.netbeans.modules.websvc.api.jaxws.project.config.Binding;
068:        import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
069:        import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
070:        import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerName;
071:        import org.netbeans.modules.xml.xam.ModelSource;
072:        import org.netbeans.modules.xml.retriever.catalog.Utilities;
073:        import org.openide.ErrorManager;
074:        import org.openide.NotifyDescriptor;
075:        import org.openide.cookies.SaveCookie;
076:        import org.openide.filesystems.FileLock;
077:        import org.openide.filesystems.FileObject;
078:        import org.openide.filesystems.FileSystem;
079:        import org.openide.filesystems.FileUtil;
080:        import org.openide.filesystems.Repository;
081:        import org.openide.loaders.DataObject;
082:        import org.openide.nodes.Node;
083:
084:        /**
085:         *
086:         * @author Roderico Cruz
087:         */
088:        public class ClientHandlerButtonListener implements  ActionListener {
089:
090:            private MessageHandlerPanel panel;
091:            private BindingsModel bindingsModel;
092:            private Client client;
093:            private Node node;
094:            private JaxWsModel jaxWsModel;
095:            //private FileObject bindingHandlerFO;
096:            private String bindingsHandlerFile;
097:
098:            public ClientHandlerButtonListener(MessageHandlerPanel panel,
099:                    BindingsModel bindingsModel, Client client, Node node,
100:                    JaxWsModel jaxWsModel) {
101:
102:                this .panel = panel;
103:                this .bindingsModel = bindingsModel;
104:                this .client = client;
105:                this .node = node;
106:                this .jaxWsModel = jaxWsModel;
107:            }
108:
109:            public void actionPerformed(ActionEvent evt) {
110:
111:                if (evt.getSource() == NotifyDescriptor.OK_OPTION) {
112:                    if (!panel.isChanged()) {
113:                        return;
114:                    }
115:                    try {
116:                        FileObject srcRoot = (FileObject) node.getLookup()
117:                                .lookup(FileObject.class);
118:                        JAXWSClientSupport support = JAXWSClientSupport
119:                                .getJaxWsClientSupport(srcRoot);
120:                        final FileObject bindingsFolder = support
121:                                .getBindingsFolderForClient(node.getName(),
122:                                        true);
123:                        Client client = (Client) node.getLookup().lookup(
124:                                Client.class);
125:                        assert client != null;
126:                        bindingsHandlerFile = client.getHandlerBindingFile();
127:                        if (bindingsHandlerFile == null) {
128:                            String baseBindingsHandlerFile = node.getName()
129:                                    + "_handler";
130:                            bindingsHandlerFile = FileUtil.findFreeFileName(
131:                                    bindingsFolder, baseBindingsHandlerFile,
132:                                    "xml")
133:                                    + ".xml";
134:                            client.setHandlerBindingFile(bindingsHandlerFile);
135:                        }
136:                        final FileObject bindingHandlerFO = FileUtil
137:                                .createData(bindingsFolder, bindingsHandlerFile);
138:                        //if bindingsModel is null, create it
139:                        if (bindingsModel == null) {
140:                            InputStream is = Repository
141:                                    .getDefault()
142:                                    .getDefaultFileSystem()
143:                                    .findResource(
144:                                            "jax-ws/default-binding-handler.xml")
145:                                    .getInputStream();
146:                            final String bindingsContent = readResource(is); //NOI18N
147:                            is.close();
148:
149:                            bindingsFolder.getFileSystem().runAtomicAction(
150:                                    new FileSystem.AtomicAction() {
151:
152:                                        public void run() throws IOException {
153:                                            //bindingHandlerFO =
154:                                            //        FileUtil.createData(bindingsFolder, bindingsHandlerFile);//NOI18N
155:                                            BufferedWriter bw = null;
156:                                            OutputStream os = null;
157:                                            OutputStreamWriter osw = null;
158:                                            FileLock lock = bindingHandlerFO
159:                                                    .lock();
160:                                            try {
161:                                                os = bindingHandlerFO
162:                                                        .getOutputStream(lock);
163:                                                osw = new OutputStreamWriter(os);
164:                                                bw = new BufferedWriter(osw);
165:                                                bw.write(bindingsContent);
166:                                            } finally {
167:                                                try {
168:                                                    if (bw != null) {
169:                                                        bw.close();
170:                                                    }
171:                                                    if (os != null) {
172:                                                        os.close();
173:                                                    }
174:                                                    if (osw != null) {
175:                                                        osw.close();
176:                                                    }
177:                                                } catch (IOException e) {
178:                                                    ErrorManager.getDefault()
179:                                                            .notify(e);
180:                                                }
181:
182:                                                if (lock != null) {
183:                                                    lock.releaseLock();
184:                                                }
185:                                            }
186:                                        }
187:                                    });
188:
189:                            //now load the model and add the entry
190:                            ModelSource ms = Utilities.getModelSource(
191:                                    bindingHandlerFO, true);
192:                            bindingsModel = BindingsModelFactory.getDefault()
193:                                    .getModel(ms);
194:                            //get the relative path of the wsdl
195:                            FileObject localWsdlFile = support
196:                                    .getLocalWsdlFolderForClient(
197:                                            client.getName(), false)
198:                                    .getFileObject(client.getLocalWsdlFile());
199:                            File f = FileUtil.toFile(bindingHandlerFO);
200:                            String relativePath = Utilities.relativize(f
201:                                    .toURI(), new URI(localWsdlFile.getURL()
202:                                    .toExternalForm()));
203:                            GlobalBindings gb = bindingsModel
204:                                    .getGlobalBindings();
205:                            try {
206:                                bindingsModel.startTransaction();
207:                                gb.setWsdlLocation(relativePath);
208:                            } finally {
209:                                bindingsModel.endTransaction(); //becomes locked here
210:                            }
211:
212:                            //hack
213:                            DataObject dobj = DataObject.find(bindingHandlerFO);
214:                            if (dobj.isModified()) {
215:                                SaveCookie saveCookie = dobj
216:                                        .getCookie(SaveCookie.class);
217:                                saveCookie.save(); //becomes false here
218:                            }
219:                            //end hack
220:
221:                        }//end if bindingsModel == null
222:
223:                        //get handler chain
224:                        TableModel tableModel = panel.getHandlerTableModel();
225:                        GlobalBindings gb = bindingsModel.getGlobalBindings();
226:                        DefinitionsBindings db = gb.getDefinitionsBindings();
227:                        BindingsHandlerChains bhc = db.getHandlerChains();
228:                        BindingsHandlerChain chain = bhc.getHandlerChains()
229:                                .iterator().next();
230:
231:                        //refresh handlers
232:                        try {
233:                            bindingsModel.startTransaction();
234:                            Collection<BindingsHandler> handlers = chain
235:                                    .getHandlers();
236:                            for (BindingsHandler handler : handlers) {
237:                                chain.removeHandler(handler);
238:                            }
239:
240:                            if (tableModel.getRowCount() > 0) {
241:                                BindingsComponentFactory factory = bindingsModel
242:                                        .getFactory();
243:                                for (int i = 0; i < tableModel.getRowCount(); i++) {
244:                                    String className = (String) tableModel
245:                                            .getValueAt(i, 0);
246:                                    BindingsHandler handler = factory
247:                                            .createHandler();
248:
249:                                    String handlerName = className
250:                                            .substring(className.indexOf(".") + 1);
251:                                    BindingsHandlerName name = factory
252:                                            .createHandlerName();
253:                                    name.setHandlerName(handlerName);
254:                                    handler.setHandlerName(name);
255:
256:                                    BindingsHandlerClass handlerClass = factory
257:                                            .createHandlerClass();
258:                                    handlerClass.setClassName(className);
259:                                    handler.setHandlerClass(handlerClass);
260:
261:                                    chain.addHandler(handler);
262:                                }
263:                            }
264:                        } finally {
265:                            bindingsModel.endTransaction();
266:                        }
267:
268:                        //save bindingshandler file
269:                        DataObject dobj = DataObject.find(bindingHandlerFO);
270:                        if (dobj.isModified()) {
271:                            SaveCookie saveCookie = dobj
272:                                    .getCookie(SaveCookie.class);
273:                            saveCookie.save(); //becomes false here
274:                        }
275:
276:                        if (tableModel.getRowCount() > 0) {
277:                            Binding binding = client
278:                                    .getBindingByFileName(bindingsHandlerFile);
279:                            if (binding == null) {
280:                                binding = client.newBinding();
281:                                binding.setFileName(bindingsHandlerFile);
282:                                client.addBinding(binding);
283:                            }
284:                        } else {
285:                            Binding binding = client
286:                                    .getBindingByFileName(bindingsHandlerFile);
287:                            if (binding != null) {
288:                                client.removeBinding(binding);
289:                            }
290:                        }
291:                        //save the jaxws model
292:                        jaxWsModel.write();
293:                        boolean l = bindingHandlerFO.isLocked();
294:                        ErrorManager.getDefault().log(ErrorManager.ERROR,
295:                                "isLocked: " + l);
296:                        System.out.println("isLocked: "
297:                                + bindingHandlerFO.isLocked());
298:                    } catch (Exception e) {
299:                        ErrorManager.getDefault().notify(e);
300:                    }
301:                }
302:            }
303:
304:            //TODO: close all streams properly
305:            private static String readResource(InputStream is)
306:                    throws IOException {
307:                // read the config from resource first
308:                BufferedReader br = null;
309:                InputStreamReader isr = null;
310:                StringBuilder sb = new StringBuilder();
311:                try {
312:
313:                    String lineSep = System.getProperty("line.separator");//NOI18N
314:                    isr = new InputStreamReader(is);
315:                    br = new BufferedReader(isr);
316:
317:                    String line = br.readLine();
318:                    while (line != null) {
319:                        sb.append(line);
320:                        sb.append(lineSep);
321:                        line = br.readLine();
322:                    }
323:                } finally {
324:                    isr.close();
325:                    br.close();
326:                    is.close();
327:                }
328:                return sb.toString();
329:            }
330:        }
ww_w__.___j__a___v_a___2_s___.__co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.