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: /*
043: * Jsr172Generator.java
044: *
045: * Created on August 29, 2005, 1:57 PM
046: *
047: */
048: package org.netbeans.modules.mobility.jsr172.generator;
049:
050: import java.io.BufferedOutputStream;
051: import java.io.ByteArrayOutputStream;
052: import java.io.File;
053: import java.io.IOException;
054: import java.io.OutputStream;
055: import java.text.MessageFormat;
056: import java.util.ArrayList;
057: import java.util.List;
058: import java.util.Properties;
059: import org.netbeans.api.java.project.JavaProjectConstants;
060: import org.netbeans.api.progress.ProgressHandle;
061: import org.netbeans.api.progress.ProgressHandleFactory;
062: import org.netbeans.api.project.SourceGroup;
063: import org.netbeans.api.project.Sources;
064: import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java;
065: import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2JavaFactory; //import org.netbeans.jmi.javamodel.JavaClass;
066: //import org.netbeans.jmi.javamodel.Method;
067: //import org.netbeans.jmi.javamodel.Resource;
068: //import org.netbeans.jmi.javamodel.Type;
069: import org.netbeans.modules.mobility.end2end.E2EDataObject;
070: import org.netbeans.modules.mobility.end2end.classdata.WSDLService;
071: import org.netbeans.modules.mobility.end2end.client.config.ClassDescriptor;
072: import org.netbeans.modules.mobility.end2end.client.config.ClientConfiguration; //import org.netbeans.modules.mobility.jsr172.validator.WSIValidator;
073: import org.netbeans.modules.mobility.end2end.util.Util;
074: import org.netbeans.spi.mobility.end2end.ServiceGeneratorResult; //import org.netbeans.modules.javacore.api.JavaModel;
075: import org.openide.DialogDisplayer;
076: import org.openide.ErrorManager;
077: import org.openide.NotifyDescriptor;
078: import org.openide.awt.StatusDisplayer;
079: import org.openide.filesystems.FileLock;
080: import org.openide.filesystems.FileObject;
081: import org.openide.filesystems.FileUtil;
082: import org.openide.util.NbBundle;
083:
084: /**
085: *
086: * @author suchys
087: */
088: public class Jsr172Generator {
089:
090: private Jsr172Generator() {
091: //To avoid instantiation
092: }
093:
094: public static ServiceGeneratorResult generate(
095: final E2EDataObject e2EDataObject) {
096: ServiceGeneratorResult result = null;
097:
098: final ProgressHandle ph = ProgressHandleFactory
099: .createHandle(NbBundle.getMessage(
100: Jsr172Generator.class, "MSG_GeneratingJsr172"));
101: ph.start();
102: ph.switchToIndeterminate();
103: // try {
104: final ClientConfiguration configuration = e2EDataObject
105: .getConfiguration().getClientConfiguration();
106: final ClassDescriptor cd = configuration.getClassDescriptor();
107: final WSDLService service = (WSDLService) e2EDataObject
108: .getConfiguration().getServices().get(0);
109: String file = service.getFile();
110: file = (cd.getPackageName().replace('.', '/')) + '/' + file; //NOI18N
111: final Sources sources = e2EDataObject.getClientProject()
112: .getLookup().lookup(Sources.class);
113: final SourceGroup sg = sources
114: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)[0];
115: final FileObject wsdlPosition = sg.getRootFolder()
116: .getFileObject(file);
117: if (wsdlPosition == null) {
118: DialogDisplayer.getDefault().notify(
119: new NotifyDescriptor.Message(NbBundle.getMessage(
120: Jsr172Generator.class,
121: "MSG_file_disapeared", service.getFile()),
122: NotifyDescriptor.ERROR_MESSAGE)); //NOI18N
123: return null;
124: }
125: //ask for folder otherwise MDR and FileSystems might be confused by external generator
126: final FileObject refFolder = sg.getRootFolder().getFileObject(
127: cd.getPackageName().replace('.', '/'));
128: refFolder.getChildren(true);
129: // //--
130: final File f = FileUtil.toFile(wsdlPosition);
131: final String configFileData = MessageFormat.format(
132: CONFIG_FILE_BODY, new Object[] { f.getAbsolutePath(),
133: cd.getPackageName() });
134:
135: final String wsdlUrl = f.toURI().toString();
136: // System.err.println(" - WSDL url - " + wsdlUrl );
137:
138: WSDL2Java.Configuration config = new WSDL2Java.Configuration();
139: config.setWSDLFileName(wsdlUrl);
140: config.setOutputDirectory(FileUtil.toFile(sg.getRootFolder())
141: .getAbsolutePath());
142: config.setPackageName(cd.getPackageName());
143: WSDL2Java wsdl2java = WSDL2JavaFactory.getWSDL2Java(config);
144:
145: final Properties properties = configuration.getProperties();
146: if (properties.getProperty("DataBinding") != null) {
147: config.setGenerateDataBinding(properties.getProperty(
148: "DataBinding").equals("true"));
149: }
150:
151: boolean generationResult = wsdl2java.generate();
152: if (generationResult) {
153: StatusDisplayer.getDefault().setStatusText(
154: NbBundle.getMessage(Jsr172Generator.class,
155: "MSG_Success")); //NOI18N
156:
157: // Append DataBinding library whether the data binding is enabled
158: if (config.getGenerateDataBinding()) {
159: Util.registerDataBindingLibrary(e2EDataObject
160: .getClientProject());
161: }
162: } else {
163: StatusDisplayer.getDefault().setStatusText(
164: NbBundle.getMessage(Jsr172Generator.class,
165: "MSG_Failure")); //NOI18N
166: }
167:
168: ph.finish();
169:
170: return result;
171: }
172:
173: // private static class CT extends CompileTool172 {
174: // CT(OutputStream os){
175: // super(os, "wscompile"); //NOI18N
176: // doCompilation = false;
177: // }
178: // }
179: //
180: public final static String CONFIG_FILE_BODY = "<?xml version=''1.0'' encoding=''UTF-8'' ?>\n"
181: + //NOI18N
182: "\t<configuration xmlns=''http://java.sun.com/xml/ns/jax-rpc/ri/config''>\n"
183: + //NOI18N
184: "\t\t<wsdl location=''{0}'' packageName=''{1}''>\n" + //NOI18N
185: "\t</wsdl>\n" + //NOI18N
186: "</configuration>\n"; //NOI18N
187:
188: }
|