Source Code Cross Referenced for JaxWsChildren.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.io.File;
044:        import java.io.IOException;
045:        import java.net.URI;
046:        import java.net.URISyntaxException;
047:        import java.net.URL;
048:        import java.net.UnknownHostException;
049:        import java.util.ArrayList;
050:        import java.util.Collections;
051:        import java.util.List;
052:        import java.util.Map.Entry;
053:        import java.util.Set;
054:        import java.util.StringTokenizer;
055:        import javax.lang.model.element.AnnotationMirror;
056:        import javax.lang.model.element.AnnotationValue;
057:        import javax.lang.model.element.Element;
058:        import javax.lang.model.element.ExecutableElement;
059:        import javax.lang.model.element.Modifier;
060:        import javax.lang.model.element.TypeElement;
061:        import javax.lang.model.element.VariableElement;
062:        import javax.lang.model.type.DeclaredType;
063:        import javax.lang.model.type.TypeKind;
064:        import javax.lang.model.type.TypeMirror;
065:        import javax.lang.model.util.ElementFilter;
066:        import javax.swing.SwingUtilities;
067:        import javax.xml.parsers.ParserConfigurationException;
068:        import javax.xml.transform.stream.StreamSource;
069:        import org.apache.tools.ant.module.api.support.ActionUtils;
070:        import org.netbeans.api.java.source.CancellableTask;
071:        import org.netbeans.api.java.source.CompilationController;
072:        import org.netbeans.api.java.source.JavaSource;
073:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlChangeListener;
074:        import org.netbeans.modules.websvc.api.support.java.SourceUtils;
075:        import org.openide.filesystems.FileChangeAdapter;
076:        import org.openide.filesystems.FileChangeListener;
077:        import org.openide.filesystems.FileEvent;
078:        import org.openide.nodes.AbstractNode;
079:        import static org.netbeans.api.java.source.JavaSource.Phase;
080:        import org.netbeans.api.project.FileOwnerQuery;
081:        import org.netbeans.api.project.Project;
082:        import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper;
083:        import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
084:        import org.netbeans.modules.websvc.core.JaxWsUtils;
085:        import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
086:        import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
087:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModel;
088:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelListener;
089:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModeler;
090:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelerFactory;
091:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlOperation;
092:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlPort;
093:        import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlService;
094:        import org.netbeans.modules.websvc.api.jaxws.project.WSUtils;
095:        import org.netbeans.modules.websvc.jaxws.api.WsdlWrapperGenerator;
096:        import org.netbeans.modules.websvc.jaxws.api.WsdlWrapperHandler;
097:        import org.openide.DialogDisplayer;
098:        import org.openide.ErrorManager;
099:        import org.openide.execution.ExecutorTask;
100:        import org.openide.filesystems.FileLock;
101:        import org.openide.filesystems.FileObject;
102:        import org.openide.filesystems.FileStateInvalidException;
103:        import org.openide.filesystems.FileUtil;
104:        import org.openide.nodes.Children;
105:        import org.openide.nodes.Node;
106:        import org.openide.util.NbBundle;
107:        import org.netbeans.modules.websvc.api.jaxws.project.config.Binding;
108:        import org.xml.sax.SAXException;
109:
110:        /*
111:         *  Children of the web service node, namely,
112:         *  the operations of the webservice
113:         */
114:        public class JaxWsChildren extends Children.Keys/* implements  MDRChangeListener  */{
115:            private java.awt.Image cachedIcon;
116:            private static final String OPERATION_ICON = "org/netbeans/modules/websvc/core/webservices/ui/resources/wsoperation.png"; //NOI18N
117:
118:            private FileObject implClass;
119:            private Service service;
120:            private FileObject srcRoot;
121:
122:            private WsdlModel wsdlModel;
123:            private WsdlModeler wsdlModeler;
124:            private boolean modelGenerationFinished;
125:
126:            private WsdlChangeListener wsdlChangeListener;
127:
128:            private FileChangeListener fcl;
129:
130:            public JaxWsChildren(Service service, FileObject srcRoot,
131:                    FileObject implClass) {
132:                super ();
133:                this .service = service;
134:                this .srcRoot = srcRoot;
135:                this .implClass = implClass;
136:            }
137:
138:            // Retouche
139:            //    public ComponentMethodViewStrategy createViewStrategy() {
140:            //        WSComponentMethodViewStrategy strategy = WSComponentMethodViewStrategy.instance();
141:            //        return strategy;
142:            //    }
143:            //    
144:
145:            private List<ExecutableElement> getPublicMethods(
146:                    CompilationController controller, TypeElement classElement)
147:                    throws IOException {
148:                List<? extends Element> members = classElement
149:                        .getEnclosedElements();
150:                List<ExecutableElement> methods = ElementFilter
151:                        .methodsIn(members);
152:                List<ExecutableElement> publicMethods = new ArrayList<ExecutableElement>();
153:                for (ExecutableElement method : methods) {
154:                    Set<Modifier> modifiers = method.getModifiers();
155:                    if (modifiers.contains(Modifier.PUBLIC)) {
156:                        publicMethods.add(method);
157:                    }
158:                }
159:                return publicMethods;
160:            }
161:
162:            @Override
163:            protected void addNotify() {
164:                if (isFromWsdl()) {
165:                    try {
166:                        FileObject localWsdlFolder = getJAXWSSupport()
167:                                .getLocalWsdlFolderForService(
168:                                        service.getName(), false);
169:                        assert localWsdlFolder != null : "Cannot find folder for local wsdl file"; //NOI18N
170:                        FileObject wsdlFo = localWsdlFolder
171:                                .getFileObject(service.getLocalWsdlFile());
172:                        if (wsdlFo == null)
173:                            return;
174:                        if (wsdlModeler == null) {
175:                            wsdlModeler = WsdlModelerFactory.getDefault()
176:                                    .getWsdlModeler(wsdlFo.getURL());
177:                        }
178:                        if (wsdlModeler != null) {
179:                            wsdlChangeListener = new WsdlChangeListener() {
180:                                public void wsdlModelChanged(
181:                                        WsdlModel oldWsdlModel,
182:                                        WsdlModel newWsdlModel) {
183:                                    wsdlModel = newWsdlModel;
184:                                    ((JaxWsNode) getNode()).changeIcon();
185:                                    updateKeys();
186:                                }
187:                            };
188:                            wsdlModeler
189:                                    .addWsdlChangeListener(wsdlChangeListener);
190:                        }
191:                        String packageName = service.getPackageName();
192:                        if (packageName != null
193:                                && service.isPackageNameForceReplace()) {
194:                            // set the package name for the modeler
195:                            wsdlModeler.setPackageName(packageName);
196:                        } else {
197:                            wsdlModeler.setPackageName(null);
198:                        }
199:                        JAXWSSupport support = getJAXWSSupport();
200:                        wsdlModeler.setCatalog(support.getCatalog());
201:                        setBindings(support, wsdlModeler, service);
202:                        modelGenerationFinished = false;
203:                        ((JaxWsNode) getNode()).changeIcon();
204:                        wsdlModeler.generateWsdlModel(new WsdlModelListener() {
205:                            public void modelCreated(WsdlModel model) {
206:                                modelGenerationFinished = true;
207:                                if (model == null) {
208:                                    DialogDisplayer
209:                                            .getDefault()
210:                                            .notify(
211:                                                    new JaxWsUtils.WsImportServiceFailedMessage(
212:                                                            wsdlModeler
213:                                                                    .getCreationException()));
214:                                }
215:                            }
216:                        });
217:                    } catch (FileStateInvalidException ex) {
218:                        ErrorManager.getDefault().log(ex.getLocalizedMessage());
219:                        updateKeys();
220:                    }
221:                } else {
222:                    assert (implClass != null);
223:                    if (fcl == null) {
224:                        fcl = new FileChangeAdapter() {
225:                            @Override
226:                            public void fileChanged(FileEvent fe) {
227:                                updateKeys();
228:                            }
229:                        };
230:                        implClass.addFileChangeListener(fcl);
231:                    }
232:
233:                    updateKeys();
234:                }
235:            }
236:
237:            @Override
238:            protected void removeNotify() {
239:                if (wsdlModeler != null) {
240:                    wsdlModeler.removeWsdlChangeListener(wsdlChangeListener);
241:                }
242:                if (fcl != null) {
243:                    implClass.removeFileChangeListener(fcl);
244:                    fcl = null;
245:                }
246:                setKeys(Collections.EMPTY_SET);
247:            }
248:
249:            private void updateKeys() {
250:                if (isFromWsdl()) {
251:                    List<WsdlOperation> keys = new ArrayList<WsdlOperation>();
252:                    if (wsdlModel != null) {
253:                        WsdlService wsdlService = wsdlModel
254:                                .getServiceByName(service.getServiceName());
255:                        if (wsdlService != null) {
256:                            WsdlPort wsdlPort = wsdlService
257:                                    .getPortByName(service.getPortName());
258:                            if (wsdlPort != null)
259:                                keys = wsdlPort.getOperations();
260:                        }
261:                    }
262:                    setKeys(keys);
263:                } else {
264:                    SwingUtilities.invokeLater(new Runnable() {
265:                        public void run() {
266:                            final List<WebOperationInfo>[] keys = new List[] { new ArrayList<WebOperationInfo>() };
267:                            if (implClass != null) {
268:                                JavaSource javaSource = JavaSource
269:                                        .forFileObject(implClass);
270:                                if (javaSource != null) {
271:                                    CancellableTask<CompilationController> task = new CancellableTask<CompilationController>() {
272:                                        public void run(
273:                                                CompilationController controller)
274:                                                throws IOException {
275:                                            controller
276:                                                    .toPhase(Phase.ELEMENTS_RESOLVED);
277:                                            TypeElement typeElement = SourceUtils
278:                                                    .getPublicTopLevelElement(controller);
279:                                            if (typeElement != null) {
280:                                                // find WS operations
281:                                                // either annotated (@WebMethod) public mathods 
282:                                                // or all public methods
283:                                                List<ExecutableElement> publicMethods = getPublicMethods(
284:                                                        controller, typeElement);
285:                                                List<ExecutableElement> webMethods = new ArrayList<ExecutableElement>();
286:                                                List<WebOperationInfo> webOperations = new ArrayList<WebOperationInfo>();
287:                                                TypeElement webMethodEl = controller
288:                                                        .getElements()
289:                                                        .getTypeElement(
290:                                                                "javax.jws.WebMethod"); //NOI18N
291:                                                if (webMethodEl != null) {
292:                                                    boolean foundWebMethodAnnotation = false;
293:                                                    for (ExecutableElement method : publicMethods) {
294:                                                        List<? extends AnnotationMirror> annotations = method
295:                                                                .getAnnotationMirrors();
296:                                                        boolean hasWebMethodAnnotation = false;
297:                                                        for (AnnotationMirror an : annotations) {
298:                                                            if (controller
299:                                                                    .getTypes()
300:                                                                    .isSameType(
301:                                                                            webMethodEl
302:                                                                                    .asType(),
303:                                                                            an
304:                                                                                    .getAnnotationType())) {
305:                                                                hasWebMethodAnnotation = true;
306:                                                                break;
307:                                                            }
308:                                                        }
309:                                                        if (hasWebMethodAnnotation) {
310:                                                            if (!foundWebMethodAnnotation) {
311:                                                                foundWebMethodAnnotation = true;
312:                                                                // remove all methods added before
313:                                                                // because only annotated methods should be added
314:                                                                if (webMethods
315:                                                                        .size() > 0)
316:                                                                    webMethods
317:                                                                            .clear();
318:                                                            }
319:                                                            webMethods
320:                                                                    .add(method);
321:                                                        } else if (!foundWebMethodAnnotation) {
322:                                                            // there are only non-annotated methods present until now
323:                                                            webMethods
324:                                                                    .add(method);
325:                                                        }
326:                                                    } // for
327:
328:                                                    // create list of operations;                                      
329:                                                    for (ExecutableElement webMethod : webMethods) {
330:                                                        // web operation name
331:                                                        WebOperationInfo webOperation = new WebOperationInfo();
332:                                                        List<? extends AnnotationMirror> annotations = webMethod
333:                                                                .getAnnotationMirrors();
334:                                                        for (AnnotationMirror an : annotations) {
335:                                                            if (controller
336:                                                                    .getTypes()
337:                                                                    .isSameType(
338:                                                                            webMethodEl
339:                                                                                    .asType(),
340:                                                                            an
341:                                                                                    .getAnnotationType())) {
342:                                                                java.util.Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = an
343:                                                                        .getElementValues();
344:                                                                for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : expressions
345:                                                                        .entrySet()) {
346:                                                                    if (entry
347:                                                                            .getKey()
348:                                                                            .getSimpleName()
349:                                                                            .contentEquals(
350:                                                                                    "operationName")) { //NOI18N
351:                                                                        webOperation
352:                                                                                .setOperationName((String) expressions
353:                                                                                        .get(
354:                                                                                                entry
355:                                                                                                        .getKey())
356:                                                                                        .getValue());
357:                                                                    }
358:                                                                }
359:                                                            }
360:                                                        }
361:                                                        if (webOperation
362:                                                                .getOperationName() == null) {
363:                                                            webOperation
364:                                                                    .setOperationName(webMethod
365:                                                                            .getSimpleName()
366:                                                                            .toString());
367:                                                        }
368:
369:                                                        // return type
370:                                                        TypeMirror returnType = webMethod
371:                                                                .getReturnType();
372:                                                        if (returnType
373:                                                                .getKind() == TypeKind.DECLARED) {
374:                                                            TypeElement element = (TypeElement) ((DeclaredType) returnType)
375:                                                                    .asElement();
376:                                                            webOperation
377:                                                                    .setReturnType(element
378:                                                                            .getQualifiedName()
379:                                                                            .toString());
380:                                                        } else { // for primitive type
381:                                                            webOperation
382:                                                                    .setReturnType(returnType
383:                                                                            .toString());
384:                                                        }
385:
386:                                                        // parameter types
387:                                                        List<? extends VariableElement> params = webMethod
388:                                                                .getParameters();
389:                                                        List<String> paramTypes = new ArrayList<String>();
390:                                                        for (VariableElement param : params) {
391:                                                            TypeMirror type = param
392:                                                                    .asType();
393:                                                            if (type.getKind() == TypeKind.DECLARED) {
394:                                                                TypeElement element = (TypeElement) ((DeclaredType) type)
395:                                                                        .asElement();
396:                                                                paramTypes
397:                                                                        .add(element
398:                                                                                .getQualifiedName()
399:                                                                                .toString());
400:                                                            } else { // for primitive type
401:                                                                paramTypes
402:                                                                        .add(type
403:                                                                                .toString());
404:                                                            }
405:                                                        }
406:                                                        webOperation
407:                                                                .setParamTypes(paramTypes);
408:
409:                                                        webOperations
410:                                                                .add(webOperation);
411:                                                    }
412:                                                }
413:                                                keys[0] = webOperations;
414:                                            }
415:                                        }
416:
417:                                        public void cancel() {
418:                                        }
419:                                    };
420:                                    try {
421:                                        javaSource
422:                                                .runUserActionTask(task, true);
423:                                    } catch (IOException ex) {
424:                                        ErrorManager.getDefault().notify(ex);
425:                                    }
426:                                }
427:                            }
428:                            setKeys(keys[0]);
429:                        }
430:                    });
431:                }
432:            }
433:
434:            protected Node[] createNodes(Object key) {
435:                if (key instanceof  WsdlOperation) {
436:                    return new Node[] { new OperationNode((WsdlOperation) key) };
437:                } else if (key instanceof  WebOperationInfo) {
438:                    final WebOperationInfo method = (WebOperationInfo) key;
439:                    Node n = new AbstractNode(Children.LEAF) {
440:
441:                        @java.lang.Override
442:                        public java.awt.Image getIcon(int type) {
443:                            if (cachedIcon == null) {
444:                                cachedIcon = org.openide.util.Utilities
445:                                        .loadImage(OPERATION_ICON);
446:                            }
447:                            return cachedIcon;
448:                        }
449:
450:                        @Override
451:                        public String getDisplayName() {
452:                            return method.getOperationName() + ": "
453:                                    + getClassName(method.getReturnType()); //NOI18N
454:                        }
455:                    };
456:                    StringBuffer buf = new StringBuffer();
457:                    for (String paramType : method.getParamTypes()) {
458:                        buf.append(buf.length() == 0 ? paramType : ", "
459:                                + paramType);
460:                    }
461:                    n.setShortDescription(NbBundle.getMessage(
462:                            JaxWsClientChildren.class, "TXT_operationDesc",
463:                            method.getReturnType(), method.getOperationName(),
464:                            buf.toString()));
465:                    return new Node[] { n };
466:                }
467:                return new Node[0];
468:            }
469:
470:            private boolean isFromWsdl() {
471:                return service.getWsdlUrl() != null;
472:            }
473:
474:            private JAXWSSupport getJAXWSSupport() {
475:                return JAXWSSupport.getJAXWSSupport(srcRoot);
476:            }
477:
478:            private String getClassName(String fullClassName) {
479:                StringTokenizer tok = new StringTokenizer(fullClassName, "."); //NOI18N
480:                String token = "";
481:                while (tok.hasMoreTokens()) {
482:                    token = tok.nextToken();
483:                }
484:                return token;
485:            }
486:
487:            private void setBindings(JAXWSSupport support,
488:                    WsdlModeler wsdlModeler, Service service) {
489:                Binding[] extbindings = service.getBindings();
490:                if (extbindings == null || extbindings.length == 0) {
491:                    wsdlModeler.setJAXBBindings(null);
492:                    return;
493:                }
494:                String[] bindingFiles = new String[extbindings.length];
495:                for (int i = 0; i < extbindings.length; i++) {
496:                    bindingFiles[i] = extbindings[i].getFileName();
497:                }
498:
499:                FileObject bindingsFolder = support
500:                        .getBindingsFolderForService(getNode().getName(), true);
501:                List<URL> list = new ArrayList<URL>();
502:                for (int i = 0; i < bindingFiles.length; i++) {
503:                    FileObject fo = bindingsFolder
504:                            .getFileObject(bindingFiles[i]);
505:                    try {
506:                        list.add(fo.getURL());
507:                    } catch (FileStateInvalidException ex) {
508:                        // if there is problem no bindings will be added
509:                    }
510:                }
511:                URL[] bindings = new URL[list.size()];
512:                list.<URL> toArray(bindings);
513:                wsdlModeler.setJAXBBindings(bindings);
514:            }
515:
516:            void refreshKeys(boolean downloadWsdl,
517:                    final boolean refreshImplClass, String newWsdlUrl) {
518:                if (!isFromWsdl())
519:                    return;
520:                super .addNotify();
521:                try {
522:                    // copy to local wsdl first
523:                    JAXWSSupport support = getJAXWSSupport();
524:
525:                    if (downloadWsdl) {
526:                        String serviceName = getNode().getName();
527:                        FileObject xmlResorcesFo = support
528:                                .getLocalWsdlFolderForService(serviceName, true);
529:                        FileObject localWsdl = null;
530:                        try {
531:                            String oldWsdlUrl = service.getWsdlUrl();
532:                            boolean jaxWsModelChanged = false;
533:                            if (newWsdlUrl.length() > 0
534:                                    && !oldWsdlUrl.equals(newWsdlUrl)) {
535:                                localWsdl = WSUtils.retrieveResource(
536:                                        xmlResorcesFo, new URI(newWsdlUrl));
537:                                jaxWsModelChanged = true;
538:                            } else {
539:                                localWsdl = WSUtils.retrieveResource(
540:                                        xmlResorcesFo, new URI(oldWsdlUrl));
541:                            }
542:                            if (jaxWsModelChanged) {
543:                                service.setWsdlUrl(newWsdlUrl);
544:                                FileObject xmlResourcesFo = support
545:                                        .getLocalWsdlFolderForService(
546:                                                serviceName, false);
547:                                if (xmlResourcesFo != null) {
548:                                    String localWsdlUrl = FileUtil
549:                                            .getRelativePath(xmlResourcesFo,
550:                                                    localWsdl);
551:                                    service.setLocalWsdlFile(localWsdlUrl);
552:                                }
553:                                Project project = FileOwnerQuery
554:                                        .getOwner(srcRoot);
555:                                JaxWsModel jaxWsModel = (JaxWsModel) project
556:                                        .getLookup().lookup(JaxWsModel.class);
557:                                if (jaxWsModel != null)
558:                                    jaxWsModel.write();
559:                            }
560:                            // copy resources to WEB-INF/wsdl/${serviceName}
561:                            FileObject wsdlFolder = getWsdlFolderForService(
562:                                    support, serviceName);
563:                            WSUtils.copyFiles(xmlResorcesFo, wsdlFolder);
564:                        } catch (URISyntaxException ex) {
565:                            ErrorManager.getDefault().notify(ex);
566:                        } catch (UnknownHostException ex) {
567:                            ErrorManager.getDefault().annotate(
568:                                    ex,
569:                                    NbBundle.getMessage(
570:                                            JaxWsClientChildren.class,
571:                                            "MSG_ConnectionProblem"));
572:                            return;
573:                        } catch (IOException ex) {
574:                            ErrorManager.getDefault().annotate(
575:                                    ex,
576:                                    NbBundle.getMessage(
577:                                            JaxWsClientChildren.class,
578:                                            "MSG_ConnectionProblem"));
579:                            return;
580:                        }
581:
582:                        // re-generate also wrapper wsdl file if necessary
583:                        if (localWsdl != null) {
584:                            WsdlWrapperHandler handler = null;
585:                            try {
586:                                handler = WsdlWrapperGenerator.parse(localWsdl
587:                                        .getURL().toExternalForm());
588:                            } catch (ParserConfigurationException ex) {
589:                                ErrorManager.getDefault().notify(
590:                                        ErrorManager.INFORMATIONAL, ex);
591:                            } catch (SAXException ex) {
592:                                ErrorManager.getDefault().notify(
593:                                        ErrorManager.INFORMATIONAL, ex);
594:                            } catch (IOException ex) {
595:                                ErrorManager.getDefault().notify(
596:                                        ErrorManager.INFORMATIONAL, ex);
597:                            }
598:                            if (!handler.isServiceElement()) {
599:                                StreamSource source = new StreamSource(
600:                                        localWsdl.getURL().toExternalForm());
601:                                try {
602:                                    File wrapperWsdlFile = new File(FileUtil
603:                                            .toFile(localWsdl.getParent()),
604:                                            WsdlWrapperGenerator
605:                                                    .getWrapperName(localWsdl
606:                                                            .getURL())); //NOI18N
607:
608:                                    if (!wrapperWsdlFile.exists()) {
609:                                        try {
610:                                            wrapperWsdlFile.createNewFile();
611:                                        } catch (IOException ex) {
612:                                            ErrorManager.getDefault().notify(
613:                                                    ErrorManager.EXCEPTION, ex);
614:                                        }
615:                                    }
616:                                    if (wrapperWsdlFile.exists()) {
617:                                        WsdlWrapperGenerator
618:                                                .generateWrapperWSDLContent(
619:                                                        wrapperWsdlFile,
620:                                                        source,
621:                                                        handler
622:                                                                .getTargetNsPrefix(),
623:                                                        localWsdl.getNameExt());
624:                                    }
625:                                } catch (IOException ex) {
626:                                    ErrorManager.getDefault().notify(
627:                                            ErrorManager.INFORMATIONAL, ex);
628:                                }
629:                            }
630:                        }
631:                    }
632:                    FileObject wsdlFo = getJAXWSSupport()
633:                            .getLocalWsdlFolderForService(service.getName(),
634:                                    false).getFileObject(
635:                                    service.getLocalWsdlFile());
636:                    wsdlModeler = WsdlModelerFactory.getDefault()
637:                            .getWsdlModeler(wsdlFo.getURL());
638:                    String packageName = service.getPackageName();
639:                    if (packageName != null
640:                            && service.isPackageNameForceReplace()) {
641:                        // set the package name for the modeler
642:                        wsdlModeler.setPackageName(packageName);
643:                    } else {
644:                        wsdlModeler.setPackageName(null);
645:                    }
646:                    wsdlModeler.setCatalog(support.getCatalog());
647:                    setBindings(support, wsdlModeler, service);
648:
649:                    // re-generate java artifacts
650:                    regenerateJavaArtifacts();
651:                    // update nodes and implementation class
652:
653:                    modelGenerationFinished = false;
654:                    ((JaxWsNode) getNode()).changeIcon();
655:                    wsdlModeler.generateWsdlModel(new WsdlModelListener() {
656:                        public void modelCreated(WsdlModel model) {
657:                            wsdlModel = model;
658:                            modelGenerationFinished = true;
659:                            ((JaxWsNode) getNode()).changeIcon();
660:                            if (model == null) {
661:                                DialogDisplayer
662:                                        .getDefault()
663:                                        .notify(
664:                                                new JaxWsUtils.WsImportServiceFailedMessage(
665:                                                        wsdlModeler
666:                                                                .getCreationException()));
667:                            }
668:                            if (model != null) {
669:                                try {
670:                                    // test if serviceName, portName are the same, change if necessary
671:                                    String serviceName = service
672:                                            .getServiceName();
673:                                    String portName = service.getPortName();
674:                                    WsdlService wsdlService = model
675:                                            .getServiceByName(serviceName);
676:                                    boolean jaxWsModelChanged = false;
677:                                    if (wsdlService == null) {
678:                                        wsdlService = (WsdlService) model
679:                                                .getServices().get(0);
680:                                        service.setServiceName(wsdlService
681:                                                .getName());
682:                                        jaxWsModelChanged = true;
683:                                    }
684:                                    WsdlPort wsdlPort = wsdlService
685:                                            .getPortByName(portName);
686:                                    if (wsdlPort == null) {
687:                                        wsdlPort = (WsdlPort) wsdlService
688:                                                .getPorts().get(0);
689:                                        service.setPortName(wsdlPort.getName());
690:                                        jaxWsModelChanged = true;
691:                                    }
692:
693:                                    // test if package name for java artifacts hasn't changed
694:                                    String oldPkgName = service
695:                                            .getPackageName();
696:                                    if (wsdlService != null
697:                                            && oldPkgName != null
698:                                            && !service
699:                                                    .isPackageNameForceReplace()) {
700:                                        String javaName = wsdlService
701:                                                .getJavaName();
702:                                        int dotPosition = javaName
703:                                                .lastIndexOf(".");
704:                                        if (dotPosition >= 0) {
705:                                            String newPkgName = javaName
706:                                                    .substring(0, dotPosition);
707:                                            if (!oldPkgName.equals(newPkgName)) {
708:                                                service
709:                                                        .setPackageName(newPkgName);
710:                                                jaxWsModelChanged = true;
711:                                            }
712:                                        }
713:                                    }
714:
715:                                    // save jax-ws model
716:                                    if (jaxWsModelChanged) {
717:                                        Project project = FileOwnerQuery
718:                                                .getOwner(srcRoot);
719:                                        if (project != null) {
720:                                            JaxWsModel jaxWsModel = (JaxWsModel) project
721:                                                    .getLookup().lookup(
722:                                                            JaxWsModel.class);
723:                                            if (jaxWsModel != null)
724:                                                jaxWsModel.write();
725:                                        }
726:
727:                                    }
728:                                    if (refreshImplClass) {
729:                                        // re-generate implementation class
730:                                        String implClass = service
731:                                                .getImplementationClass();
732:                                        FileObject oldImplClass = srcRoot
733:                                                .getFileObject(implClass
734:                                                        .replace('.', '/')
735:                                                        + ".java"); //NOI18N
736:                                        FileObject oldCopy = srcRoot
737:                                                .getFileObject(implClass
738:                                                        .replace('.', '/')
739:                                                        + ".java.old"); //NOI18N
740:                                        int index = implClass.lastIndexOf(".");
741:                                        FileObject folder = index > 0 ? srcRoot
742:                                                .getFileObject(implClass
743:                                                        .substring(0, index)
744:                                                        .replace('.', '/'))
745:                                                : srcRoot;
746:                                        if (folder != null) {
747:                                            String name = (index >= 0 ? implClass
748:                                                    .substring(index + 1)
749:                                                    : implClass);
750:                                            if (oldImplClass != null) {
751:                                                if (oldCopy != null)
752:                                                    oldCopy.delete();
753:                                                FileUtil.copyFile(oldImplClass,
754:                                                        folder, name + ".java",
755:                                                        "old"); //NOI18N
756:                                                oldImplClass.delete();
757:                                            }
758:                                            // close the editor representing old impl bean
759:                                            JaxWsNode parent = (JaxWsNode) getNode();
760:                                            JaxWsUtils
761:                                                    .generateJaxWsImplementationClass(
762:                                                            FileOwnerQuery
763:                                                                    .getOwner(srcRoot),
764:                                                            folder, name,
765:                                                            model, service);
766:                                            FileObject newImplClass = srcRoot
767:                                                    .getFileObject(implClass
768:                                                            .replace('.', '/')
769:                                                            + ".java"); //NOI18N
770:                                            if (newImplClass != null) {
771:                                                JaxWsChildren.this .implClass = newImplClass;
772:                                            }
773:                                            parent.refreshImplClass();
774:                                        }
775:                                    }
776:                                } catch (Exception ex) {
777:                                    ErrorManager.getDefault().notify(
778:                                            ErrorManager.ERROR, ex);
779:                                }
780:                            }
781:                        }
782:                    });
783:                } catch (FileStateInvalidException ex) {
784:                    ErrorManager.getDefault().log(ex.getLocalizedMessage());
785:                }
786:            }
787:
788:            private void regenerateJavaArtifacts() {
789:                Project project = FileOwnerQuery.getOwner(srcRoot);
790:                if (project != null) {
791:                    FileObject buildImplFo = project.getProjectDirectory()
792:                            .getFileObject(
793:                                    GeneratedFilesHelper.BUILD_IMPL_XML_PATH);
794:                    try {
795:                        String name = service.getName();
796:                        ExecutorTask wsimportTask = ActionUtils.runTarget(
797:                                buildImplFo, new String[] {
798:                                        "wsimport-service-clean-" + name,
799:                                        "wsimport-service-" + name }, null); //NOI18N
800:                        wsimportTask.waitFinished();
801:                    } catch (IOException ex) {
802:                        ErrorManager.getDefault().log(ex.getLocalizedMessage());
803:                    } catch (IllegalArgumentException ex) {
804:                        ErrorManager.getDefault().log(ex.getLocalizedMessage());
805:                    }
806:                }
807:            }
808:
809:            private FileObject getWsdlFolderForService(JAXWSSupport support,
810:                    String name) throws IOException {
811:                FileObject globalWsdlFolder = support.getWsdlFolder(true);
812:                FileObject oldWsdlFolder = globalWsdlFolder.getFileObject(name);
813:                if (oldWsdlFolder != null) {
814:                    FileLock lock = oldWsdlFolder.lock();
815:                    try {
816:                        oldWsdlFolder.delete(lock);
817:                    } finally {
818:                        lock.releaseLock();
819:                    }
820:                }
821:                return globalWsdlFolder.createFolder(name);
822:            }
823:
824:            WsdlModeler getWsdlModeler() {
825:                return wsdlModeler;
826:            }
827:
828:            boolean isModelGenerationFinished() {
829:                return modelGenerationFinished;
830:            }
831:
832:            private class WebOperationInfo {
833:                private String operationName;
834:                private List<String> paramTypes;
835:                private String returnType;
836:
837:                String getOperationName() {
838:                    return operationName;
839:                }
840:
841:                void setOperationName(String operationName) {
842:                    this .operationName = operationName;
843:                }
844:
845:                List<String> getParamTypes() {
846:                    return paramTypes;
847:                }
848:
849:                void setParamTypes(List<String> paramTypes) {
850:                    this .paramTypes = paramTypes;
851:                }
852:
853:                String getReturnType() {
854:                    return returnType;
855:                }
856:
857:                void setReturnType(String returnType) {
858:                    this.returnType = returnType;
859:                }
860:            }
861:
862:        }
w_w___w__.___j_a__v_a___2__s___.___c___o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.