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