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