Source Code Cross Referenced for ServiceInformationImpl.java in  » IDE-Netbeans » web.core » org » netbeans » modules » websvc » wsdl » config » 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.wsdl.config 
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:        /*
042:         * ServiceInformationImpl.java
043:         *
044:         * Created on April 26, 2006, 10:11 AM
045:         *
046:         * To change this template, choose Tools | Template Manager
047:         * and open the template in the editor.
048:         */
049:
050:        package org.netbeans.modules.websvc.wsdl.config;
051:
052:        import java.io.FileNotFoundException;
053:        import java.io.IOException;
054:        import java.lang.ref.WeakReference;
055:        import java.util.Collections;
056:        import java.util.List;
057:        import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
058:        import org.netbeans.modules.websvc.jaxrpc.PortInformation;
059:        import org.netbeans.modules.websvc.jaxrpc.ServiceInformation;
060:        import org.netbeans.modules.websvc.jaxrpc.nodes.WsCompileConfigCookie;
061:        import org.openide.filesystems.FileObject;
062:        import org.openide.loaders.DataObject;
063:        import org.openide.loaders.DataObjectNotFoundException;
064:
065:        /**
066:         *
067:         * @author rico
068:         * Refactored methods from the WsdlDataObject
069:         */
070:        public class ServiceInformationImpl implements  ServiceInformation {
071:
072:            private WeakReference portInformationHandlerRef = null;
073:            private DataObject wsdlDataObj;
074:
075:            // If isClientWsdl is true, the WSDL file is in the WSDL folder of a web service
076:            // client enabled module and thus will have operations and UI exposed that affect
077:            // the service as it exists within the project.  E.g. deleting such a file will
078:            // actually remove the service from the project, not just delete the file on disk.
079:            private boolean clientResolved, isClientWsdl;
080:
081:            /** Typical data object constructor.
082:             */
083:            public ServiceInformationImpl(DataObject dobj) {
084:                wsdlDataObj = dobj;
085:            }
086:
087:            public boolean isClientWsdl() {
088:                if (!clientResolved) {
089:                    initClientWsdl();
090:                    clientResolved = true;
091:                }
092:                return isClientWsdl;
093:            }
094:
095:            private void initClientWsdl() {
096:                isClientWsdl = false;
097:                FileObject wsdlFO = wsdlDataObj.getPrimaryFile();
098:
099:                // Check to make sure it has a non-null parent (can't be in WSDL folder if it does).
100:                FileObject parentFO = wsdlFO.getParent();
101:                if (parentFO != null) {
102:                    // Does this module support web service clients?
103:                    WebServicesClientSupport clientSupport = WebServicesClientSupport
104:                            .getWebServicesClientSupport(wsdlFO);
105:                    if (clientSupport != null) {
106:                        // Is this file object in the WSDL folder of the client?
107:                        FileObject wsdlFolder = clientSupport.getWsdlFolder();
108:                        if (wsdlFolder != null && wsdlFolder.equals(parentFO)) {
109:                            // If we get here, the following conditions should be true:
110:                            //   The WSDL file is in a code module that supports webservice clients.
111:                            //   The WSDL file is in the proper WSDL folder of that module.
112:                            isClientWsdl = true;
113:
114:                            // With the addition of "Create service from wsdl" feature,
115:                            // wsdl files in this folder could also be services (if the project
116:                            // in question supports service at least) so we need additional
117:                            // heuristics for this case.
118:                            //                    WebServicesSupport serviceSupport = WebServicesSupport.getWebServicesSupport(wsdlFO);
119:                            //                    if(serviceSupport != null) {
120:                            //                        List serviceList = serviceSupport.getServices();
121:                            //                    }
122:
123:                            // for now, just check and see if there is a mapping file in the web-inf/meta-inf folder (parent)
124:                            FileObject ddFolder = wsdlFolder.getParent();
125:                            if (ddFolder != null) {
126:                                FileObject mappingFile = ddFolder
127:                                        .getFileObject(wsdlDataObj.getName()
128:                                                + "-mapping", "xml"); // NOI18N
129:                                if (mappingFile != null) {
130:                                    isClientWsdl = false;
131:                                }
132:                            }
133:                        }
134:                    }
135:                }
136:            }
137:
138:            public String getServicePackageName() {
139:                // locate config object and use cookie on that to get package name
140:                String packageName = "unknown"; // NOI18N default to unknown package name
141:
142:                FileObject configFO = null;
143:                FileObject wsdlFO = wsdlDataObj.getPrimaryFile();
144:                FileObject parentFO = wsdlFO.getParent();
145:                if (parentFO != null && parentFO.isFolder()) {
146:                    configFO = parentFO
147:                            .getFileObject(
148:                                    wsdlFO.getName()
149:                                            + WsCompileConfigDataObject.WSCOMPILE_CONFIG_FILENAME_SUFFIX,
150:                                    "xml");
151:                }
152:
153:                if (configFO != null) {
154:                    WsCompileConfigCookie configCookie = null;
155:                    try {
156:                        DataObject dobj = DataObject.find(configFO);
157:                        if (dobj instanceof  WsCompileConfigCookie)
158:                            configCookie = (WsCompileConfigCookie) dobj;
159:                    } catch (DataObjectNotFoundException ex) {
160:                        // Shouldn't happen, but it it does, we're screwed.
161:                        // !PW FIXME log this.
162:                    }
163:
164:                    if (configCookie != null) {
165:                        packageName = configCookie.getServicePackageName();
166:                    }
167:                }
168:
169:                return packageName;
170:
171:                // !PW FIXME rewrite this to use the DD provider API implemented for config files.
172:                //        // If it's cached, use that.
173:                //        synchronized (this) {
174:                //            if(packageHandlerRef != null) {
175:                //                PackageHandler handler = (PackageHandler) packageHandlerRef.get();
176:                //                if(handler != null) {
177:                //                    return handler.getPackageName();
178:                //                }
179:                //            }
180:                //        }
181:                //
182:                //        String result = null;
183:                //        FileObject configFO = null;
184:                //
185:                //        // Locate the -config file for this service client.
186:                //        Set extraFiles = secondaryEntries();
187:                //        if(extraFiles.size() >= 1) {
188:                //            // !PW This section is a holdover from EA1 where config files are secondary entries in the loader.
189:                //            //     It is probably obsolete.  Remove just before or after EA2.
190:                //            FileEntry fe = (FileEntry) extraFiles.iterator().next();
191:                //            configFO = fe.getFile();
192:                //        } else {
193:                //            FileObject wsdlFO = getPrimaryFile();
194:                //            FileObject parentFO = wsdlFO.getParent();
195:                //            if(parentFO != null && parentFO.isFolder()) {
196:                //                configFO = parentFO.getFileObject(wsdlFO.getName() + WsCompileConfigDataObject.WSCOMPILE_CONFIG_FILENAME_SUFFIX, WSCOMPILE_CONFIG_EXTENSION);
197:                //            }
198:                //        }
199:                //
200:                //        if(configFO != null) {
201:                //            // Invoke SAX parser on the WSDL config file to extract the package name
202:                //            PackageHandler handler = new PackageHandler();
203:                //
204:                //            try {
205:                //                javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
206:                //                javax.xml.parsers.SAXParser saxParser = factory.newSAXParser();
207:                //                saxParser.parse(configFO.getInputStream(), handler);
208:                //
209:                //                synchronized (this) {
210:                //                    packageHandlerRef = new WeakReference(handler);
211:                //                }
212:                //
213:                //                result = handler.getPackageName();
214:                //            } catch(javax.xml.parsers.ParserConfigurationException ex) {
215:                //                // !PW FIXME
216:                //            } catch(org.xml.sax.SAXException ex) {
217:                //                // !PW FIXME
218:                //            } catch(FileNotFoundException ex) {
219:                //                // !PW Should never happen.
220:                //            } catch(IOException ex) {
221:                //                // !PW FIXME
222:                //            }
223:                //        }
224:                //
225:                //        return result;
226:            }
227:
228:            public PortInformation getPortInformation() {
229:                return parseWsdl();
230:            }
231:
232:            public List getServicePorts(String serviceName) {
233:                List portList;
234:                PortInformationHandler handler = parseWsdl();
235:
236:                if (handler != null) {
237:                    PortInformation.ServiceInfo serviceInfo = handler
238:                            .getServiceInfo(serviceName);
239:                    portList = serviceInfo.getPorts();
240:                } else {
241:                    portList = Collections.EMPTY_LIST;
242:                }
243:
244:                return portList;
245:            }
246:
247:            public String[] getServiceNames() {
248:                String[] result;
249:                PortInformationHandler handler = parseWsdl();
250:
251:                if (handler != null) {
252:                    result = handler.getServiceNames();
253:                } else {
254:                    result = new String[0];
255:                }
256:
257:                return result;
258:            }
259:
260:            public String getTargetNamespace() {
261:                String result;
262:                PortInformationHandler handler = parseWsdl();
263:
264:                if (handler != null) {
265:                    result = handler.getTargetNamespace();
266:                } else {
267:                    result = null; // !PW Should this be the default?
268:                }
269:
270:                return result;
271:            }
272:
273:            private PortInformationHandler parseWsdl() {
274:                PortInformationHandler handler = null;
275:
276:                // If it's cached, use that.
277:                synchronized (this ) {
278:                    if (portInformationHandlerRef != null) {
279:                        handler = (PortInformationHandler) portInformationHandlerRef
280:                                .get();
281:                        if (handler != null) {
282:                            return handler;
283:                        }
284:                    }
285:                }
286:
287:                List result = Collections.EMPTY_LIST;
288:                FileObject primaryFile = wsdlDataObj.getPrimaryFile();
289:                // Invoke SAX parser on the WSDL to extract list of port bindings
290:                handler = new PortInformationHandler();
291:
292:                try {
293:                    org.xml.sax.XMLReader xmlReader = org.openide.xml.XMLUtil
294:                            .createXMLReader(false, true);
295:                    xmlReader.setContentHandler(handler);
296:                    xmlReader.parse(new org.xml.sax.InputSource(primaryFile
297:                            .getInputStream()));
298:                    // Extract service names and porttypes
299:                    synchronized (this ) {
300:                        portInformationHandlerRef = new WeakReference(handler);
301:                    }
302:                } catch (org.xml.sax.SAXException ex) {
303:                    // !PW FIXME
304:                    handler = null;
305:                } catch (FileNotFoundException ex) {
306:                    // !PW Should never happen.
307:                    handler = null;
308:                } catch (IOException ex) {
309:                    // !PW FIXME
310:                    handler = null;
311:                }
312:
313:                return handler;
314:            }
315:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.