1
22
23 package com.liferay.portal.tools;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.StringUtil;
27 import com.liferay.portal.util.PortalUtil;
28 import com.liferay.util.FileUtil;
29 import com.liferay.util.ant.Java2WsddTask;
30
31 import java.io.File;
32 import java.io.IOException;
33
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.dom4j.Document;
38 import org.dom4j.Element;
39
40
46 public class WSDDBuilder {
47
48 public static void main(String[] args) {
49 if (args.length == 2) {
50 new WSDDBuilder(args[0], args[1]);
51 }
52 else {
53 throw new IllegalArgumentException();
54 }
55 }
56
57 public WSDDBuilder(String fileName, String serverConfigFileName) {
58 try {
59 _serverConfigFileName = serverConfigFileName;
60
61 Document doc = PortalUtil.readDocumentFromFile(
62 new File(fileName), true);
63
64 Element root = doc.getRootElement();
65
66 String packagePath = root.attributeValue("package-path");
67
68 Element portlet = root.element("portlet");
69 Element namespace = root.element("namespace");
70
71 if (portlet != null) {
72 _portletShortName = portlet.attributeValue("short-name");
73 }
74 else {
75 _portletShortName = namespace.getText();
76 }
77
78 _outputPath =
79 "src/" + StringUtil.replace(packagePath, ".", "/") +
80 "/service/http";
81
82 _packagePath = packagePath;
83
84 List entities = root.elements("entity");
85
86 Iterator itr = entities.iterator();
87
88 while (itr.hasNext()) {
89 Element entity = (Element)itr.next();
90
91 String entityName = entity.attributeValue("name");
92
93 boolean remoteService = GetterUtil.getBoolean(
94 entity.attributeValue("remote-service"), true);
95
96 if (remoteService) {
97 _createServiceWSDD(entityName);
98
99 WSDDMerger.merge(
100 _outputPath + "/" + entityName + "Service_deploy.wsdd",
101 _serverConfigFileName);
102 }
103 }
104 }
105 catch (Exception e) {
106 e.printStackTrace();
107 }
108 }
109
110 private void _createServiceWSDD(String entityName) throws IOException {
111 String className =
112 _packagePath + ".service.http." + entityName + "ServiceSoap";
113
114 String serviceName = StringUtil.replace(_portletShortName, " ", "_");
115
116 if (!_portletShortName.equals("Portal")) {
117 serviceName = "Portlet_" + serviceName;
118 }
119
120 serviceName += ("_" + entityName + "Service");
121
122 String[] wsdds = Java2WsddTask.generateWsdd(className, serviceName);
123
124 FileUtil.write(
125 new File(_outputPath + "/" + entityName + "Service_deploy.wsdd"),
126 wsdds[0], true);
127
128 FileUtil.write(
129 new File(_outputPath + "/" + entityName + "Service_undeploy.wsdd"),
130 wsdds[1], true);
131 }
132
133 private String _serverConfigFileName;
134 private String _portletShortName;
135 private String _outputPath;
136 private String _packagePath;
137
138 }