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