001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: WsdlPublish.java 6899 2005-06-07 13:48:06Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant.jonasbase.wsdl;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Properties;
031:
032: import org.objectweb.jonas.ant.JOnASBaseTask;
033: import org.objectweb.jonas.ant.jonasbase.BaseTaskItf;
034: import org.objectweb.jonas.ant.jonasbase.JReplace;
035: import org.objectweb.jonas.ant.jonasbase.JTask;
036:
037: /**
038: * Generates files for WSDL publish
039: * @author Florent Benoit
040: */
041: public class WsdlPublish extends JTask implements BaseTaskItf {
042:
043: /**
044: * Info for the logger
045: */
046: private static final String INFO = "[WSDL-Publish] ";
047:
048: /**
049: * Property for WSDL Handler
050: */
051: private static final String WSDL_HANDLER_PROPERTY = "jonas.service.ws.wsdlhandlers";
052:
053: /**
054: * Default property for WSDL handlers
055: */
056: private static final String TOKEN_WSDLHANDLER = WSDL_HANDLER_PROPERTY
057: + " file1";
058:
059: /**
060: * List of files (WSDL publish)
061: */
062: private List files = new ArrayList();
063:
064: /**
065: * List of uddi (WSDL publish)
066: */
067: private List uddis = new ArrayList();
068:
069: /**
070: * Add file (wsdl publish)
071: * @param file properties file
072: */
073: public void addConfiguredFile(File file) {
074: files.add(file);
075: }
076:
077: /**
078: * Add UDDI (wsdl publish)
079: * @param uddi properties file
080: */
081: public void addConfiguredUddi(Uddi uddi) {
082: uddis.add(uddi);
083: }
084:
085: /**
086: * set files (wsdl publish)
087: * @param files list of properties file
088: */
089: public void setFiles(List files) {
090: this .files = files;
091: }
092:
093: /**
094: * set uddis (wsdl publish)
095: * @param uddis list of properties uddi file
096: */
097: public void setUddis(List uddis) {
098: this .uddis = uddis;
099: }
100:
101: /**
102: * Execute this task
103: */
104: public void execute() {
105:
106: String fileNameList = "";
107:
108: java.io.File jonasBaseConfDir = new java.io.File(getDestDir()
109: .getPath()
110: + java.io.File.separator + "conf");
111:
112: // Write file Handler
113: for (Iterator it = files.iterator(); it.hasNext();) {
114: File f = (File) it.next();
115:
116: String dir = f.getDir();
117: String encoding = f.getEncoding();
118: String name = f.getName();
119:
120: // Add file to handler list
121: if (fileNameList.length() == 0) {
122: fileNameList = name;
123: } else {
124: fileNameList += "," + name;
125: }
126:
127: String fileName = name + ".properties";
128:
129: // Build properties file and write it
130: Properties props = new Properties();
131: props.put("jonas.service.wsdl.class",
132: File.FILEWSDLHANDLER_CLASS);
133: props.put("jonas.service.publish.file.directory", dir);
134: props.put("jonas.service.publish.file.encoding", encoding);
135: java.io.File writeFile = new java.io.File(jonasBaseConfDir,
136: fileName);
137: log(INFO + "Generating a WSDL publish file with name '"
138: + name + "', dir '" + dir + "' and encoding '"
139: + encoding + "' in file '" + writeFile + "'...");
140: writePropsToFile(INFO, props, writeFile);
141: }
142:
143: // Write Uddi Handler
144: for (Iterator it = uddis.iterator(); it.hasNext();) {
145: Uddi uddi = (Uddi) it.next();
146:
147: String name = uddi.getName();
148: String username = uddi.getUserName();
149: String password = uddi.getPassword();
150: String orgName = uddi.getOrgName();
151: String orgDesc = uddi.getOrgDesc();
152: String orgPersonName = uddi.getOrgPersonName();
153: String lifecyclemanagerURL = uddi.getLifecyclemanagerURL();
154: String queryManagerURL = uddi.getQueryManagerURL();
155:
156: // Add file to handler list
157: if (fileNameList.length() == 0) {
158: fileNameList = name;
159: } else {
160: fileNameList += "," + name;
161: }
162:
163: String fileName = name + ".properties";
164:
165: // Build properties file and write it
166: Properties props = new Properties();
167: props.put("jonas.service.wsdl.class",
168: Uddi.REGISTRYWSDLHANDLER_CLASS);
169: props.put("jonas.service.publish.uddi.username", username);
170: props.put("jonas.service.publish.uddi.password", password);
171: props.put("jonas.service.publish.uddi.organization.name",
172: orgName);
173: props.put("jonas.service.publish.uddi.organization.desc",
174: orgDesc);
175: props
176: .put(
177: "jonas.service.publish.uddi.organization.person_name",
178: orgPersonName);
179: props.put("javax.xml.registry.lifeCycleManagerURL",
180: lifecyclemanagerURL);
181: props.put("javax.xml.registry.queryManagerURL",
182: queryManagerURL);
183: java.io.File writeFile = new java.io.File(jonasBaseConfDir,
184: fileName);
185: log(INFO + "Generating a WSDL publish UDDI with name '"
186: + name + "' in file '" + writeFile + "'...");
187: writePropsToFile(INFO, props, writeFile);
188: }
189:
190: // Now set the handlers to the existing list for the property
191: JReplace propertyReplace = new JReplace();
192: propertyReplace.setProject(getProject());
193: propertyReplace
194: .setConfigurationFile(JOnASBaseTask.JONAS_CONF_FILE);
195: propertyReplace.setDestDir(new java.io.File(getDestDir()
196: .getPath()));
197: propertyReplace.setToken(TOKEN_WSDLHANDLER);
198: propertyReplace.setValue(WSDL_HANDLER_PROPERTY + SEPARATORS
199: + fileNameList);
200: log(INFO + "Adding WSDL handlers '" + fileNameList + "' in "
201: + JOnASBaseTask.JONAS_CONF_FILE + " file.");
202: propertyReplace.execute();
203:
204: }
205: }
|