001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.tools;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.portal.kernel.util.StringUtil;
025: import com.liferay.portal.util.PortalUtil;
026: import com.liferay.util.FileUtil;
027: import com.liferay.util.ant.Java2WsddTask;
028:
029: import java.io.File;
030: import java.io.IOException;
031:
032: import java.util.Iterator;
033: import java.util.List;
034:
035: import org.dom4j.Document;
036: import org.dom4j.Element;
037:
038: /**
039: * <a href="WSDDBuilder.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class WSDDBuilder {
045:
046: public static void main(String[] args) {
047: if (args.length == 2) {
048: new WSDDBuilder(args[0], args[1]);
049: } else {
050: throw new IllegalArgumentException();
051: }
052: }
053:
054: public WSDDBuilder(String fileName, String serverConfigFileName) {
055: try {
056: _serverConfigFileName = serverConfigFileName;
057:
058: Document doc = PortalUtil.readDocumentFromFile(new File(
059: fileName), true);
060:
061: Element root = doc.getRootElement();
062:
063: String packagePath = root.attributeValue("package-path");
064:
065: Element portlet = root.element("portlet");
066: Element namespace = root.element("namespace");
067:
068: if (portlet != null) {
069: _portletShortName = portlet
070: .attributeValue("short-name");
071: } else {
072: _portletShortName = namespace.getText();
073: }
074:
075: _outputPath = "src/"
076: + StringUtil.replace(packagePath, ".", "/")
077: + "/service/http";
078:
079: _packagePath = packagePath;
080:
081: List entities = root.elements("entity");
082:
083: Iterator itr = entities.iterator();
084:
085: while (itr.hasNext()) {
086: Element entity = (Element) itr.next();
087:
088: String entityName = entity.attributeValue("name");
089:
090: boolean remoteService = GetterUtil.getBoolean(entity
091: .attributeValue("remote-service"), true);
092:
093: if (remoteService) {
094: _createServiceWSDD(entityName);
095:
096: WSDDMerger.merge(_outputPath + "/" + entityName
097: + "Service_deploy.wsdd",
098: _serverConfigFileName);
099: }
100: }
101: } catch (Exception e) {
102: e.printStackTrace();
103: }
104: }
105:
106: private void _createServiceWSDD(String entityName)
107: throws IOException {
108: String className = _packagePath + ".service.http." + entityName
109: + "ServiceSoap";
110:
111: String serviceName = StringUtil.replace(_portletShortName, " ",
112: "_");
113:
114: if (!_portletShortName.equals("Portal")) {
115: serviceName = "Portlet_" + serviceName;
116: }
117:
118: serviceName += ("_" + entityName + "Service");
119:
120: String[] wsdds = Java2WsddTask.generateWsdd(className,
121: serviceName);
122:
123: FileUtil.write(new File(_outputPath + "/" + entityName
124: + "Service_deploy.wsdd"), wsdds[0], true);
125:
126: FileUtil.write(new File(_outputPath + "/" + entityName
127: + "Service_undeploy.wsdd"), wsdds[1], true);
128: }
129:
130: private String _serverConfigFileName;
131: private String _portletShortName;
132: private String _outputPath;
133: private String _packagePath;
134:
135: }
|