KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ant > jonasbase > wsdl > WsdlPublish


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: WsdlPublish.java,v 1.1 2005/06/07 13:48:06 pelletib Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.ant.jonasbase.wsdl;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 import org.objectweb.jonas.ant.JOnASBaseTask;
35 import org.objectweb.jonas.ant.jonasbase.BaseTaskItf;
36 import org.objectweb.jonas.ant.jonasbase.JReplace;
37 import org.objectweb.jonas.ant.jonasbase.JTask;
38
39 /**
40  * Generates files for WSDL publish
41  * @author Florent Benoit
42  */

43 public class WsdlPublish extends JTask implements BaseTaskItf {
44
45     /**
46      * Info for the logger
47      */

48     private static final String JavaDoc INFO = "[WSDL-Publish] ";
49
50     /**
51      * Property for WSDL Handler
52      */

53     private static final String JavaDoc WSDL_HANDLER_PROPERTY = "jonas.service.ws.wsdlhandlers";
54
55     /**
56      * Default property for WSDL handlers
57      */

58     private static final String JavaDoc TOKEN_WSDLHANDLER = WSDL_HANDLER_PROPERTY + " file1";
59
60     /**
61      * List of files (WSDL publish)
62      */

63     private List JavaDoc files = new ArrayList JavaDoc();
64
65     /**
66      * List of uddi (WSDL publish)
67      */

68     private List JavaDoc uddis = new ArrayList JavaDoc();
69
70     /**
71      * Add file (wsdl publish)
72      * @param file properties file
73      */

74     public void addConfiguredFile(File file) {
75         files.add(file);
76     }
77
78     /**
79      * Add UDDI (wsdl publish)
80      * @param uddi properties file
81      */

82     public void addConfiguredUddi(Uddi uddi) {
83         uddis.add(uddi);
84     }
85
86     /**
87      * set files (wsdl publish)
88      * @param files list of properties file
89      */

90     public void setFiles(List JavaDoc files) {
91         this.files = files;
92     }
93
94     /**
95      * set uddis (wsdl publish)
96      * @param uddis list of properties uddi file
97      */

98     public void setUddis(List JavaDoc uddis) {
99         this.uddis = uddis;
100     }
101
102     /**
103      * Execute this task
104      */

105     public void execute() {
106
107         String JavaDoc fileNameList = "";
108
109         java.io.File JavaDoc jonasBaseConfDir = new java.io.File JavaDoc(getDestDir().getPath() + java.io.File.separator + "conf");
110
111         // Write file Handler
112
for (Iterator JavaDoc it = files.iterator(); it.hasNext();) {
113             File f = (File) it.next();
114
115             String JavaDoc dir = f.getDir();
116             String JavaDoc encoding = f.getEncoding();
117             String JavaDoc name = f.getName();
118
119             // Add file to handler list
120
if (fileNameList.length() == 0) {
121                 fileNameList = name;
122             } else {
123                 fileNameList += "," + name;
124             }
125
126             String JavaDoc fileName = name + ".properties";
127
128             // Build properties file and write it
129
Properties JavaDoc props = new Properties JavaDoc();
130             props.put("jonas.service.wsdl.class", File.FILEWSDLHANDLER_CLASS);
131             props.put("jonas.service.publish.file.directory", dir);
132             props.put("jonas.service.publish.file.encoding", encoding);
133             java.io.File JavaDoc writeFile = new java.io.File JavaDoc(jonasBaseConfDir, fileName);
134             log(INFO + "Generating a WSDL publish file with name '" + name + "', dir '" + dir + "' and encoding '"
135                     + encoding + "' in file '" + writeFile + "'...");
136             writePropsToFile(INFO, props, writeFile);
137         }
138
139         // Write Uddi Handler
140
for (Iterator JavaDoc it = uddis.iterator(); it.hasNext();) {
141             Uddi uddi = (Uddi) it.next();
142
143             String JavaDoc name = uddi.getName();
144             String JavaDoc username = uddi.getUserName();
145             String JavaDoc password = uddi.getPassword();
146             String JavaDoc orgName = uddi.getOrgName();
147             String JavaDoc orgDesc = uddi.getOrgDesc();
148             String JavaDoc orgPersonName = uddi.getOrgPersonName();
149             String JavaDoc lifecyclemanagerURL = uddi.getLifecyclemanagerURL();
150             String JavaDoc queryManagerURL = uddi.getQueryManagerURL();
151
152             // Add file to handler list
153
if (fileNameList.length() == 0) {
154                 fileNameList = name;
155             } else {
156                 fileNameList += "," + name;
157             }
158
159             String JavaDoc fileName = name + ".properties";
160
161             // Build properties file and write it
162
Properties JavaDoc props = new Properties JavaDoc();
163             props.put("jonas.service.wsdl.class", Uddi.REGISTRYWSDLHANDLER_CLASS);
164             props.put("jonas.service.publish.uddi.username", username);
165             props.put("jonas.service.publish.uddi.password", password);
166             props.put("jonas.service.publish.uddi.organization.name", orgName);
167             props.put("jonas.service.publish.uddi.organization.desc", orgDesc);
168             props.put("jonas.service.publish.uddi.organization.person_name", orgPersonName);
169             props.put("javax.xml.registry.lifeCycleManagerURL", lifecyclemanagerURL);
170             props.put("javax.xml.registry.queryManagerURL", queryManagerURL);
171             java.io.File JavaDoc writeFile = new java.io.File JavaDoc(jonasBaseConfDir, fileName);
172             log(INFO + "Generating a WSDL publish UDDI with name '" + name + "' in file '" + writeFile + "'...");
173             writePropsToFile(INFO, props, writeFile);
174         }
175
176         // Now set the handlers to the existing list for the property
177
JReplace propertyReplace = new JReplace();
178         propertyReplace.setProject(getProject());
179         propertyReplace.setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
180         propertyReplace.setDestDir(new java.io.File JavaDoc(getDestDir().getPath()));
181         propertyReplace.setToken(TOKEN_WSDLHANDLER);
182         propertyReplace.setValue(WSDL_HANDLER_PROPERTY + SEPARATORS + fileNameList);
183         log(INFO + "Adding WSDL handlers '" + fileNameList + "' in " + JOnASBaseTask.JONAS_CONF_FILE + " file.");
184         propertyReplace.execute();
185
186     }
187 }
Popular Tags