Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments #9

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,6 +34,8 @@ public class JavaLanguageVariable {
*/
private boolean header;

private String description;

public boolean isHeader() {
return header;
}
Expand Down Expand Up @@ -80,4 +82,11 @@ public void setMultiOccurs(boolean multiOccurs) {
this.multiOccurs = multiOccurs;
}

public void setDescription(String description) {
this.description = description;
}

public String getDescription() {
return description;
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/jaxws/stub2html/model/Stub.java
Expand Up @@ -41,6 +41,7 @@ public class Stub {
* if parent stub's type = Product, is it FunProduct or NotFunProduct?
*/
private Class<?> subTypeOfParentStub;
private String description = "TODO";

public Stub getParentStub() {
return parentStub;
Expand Down Expand Up @@ -142,7 +143,7 @@ public String getDescription() {
if (this.header) {
return "In header";
}
return null;
return description;
}

@Override
Expand All @@ -151,4 +152,7 @@ public String toString() {
return "[Stub: " + type.getSimpleName() + "," + path + "]";
}

public void setStubDescription(String stubDescription) {
this.description = stubDescription;
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/jaxws/stub2html/model/WebMethodStubSet.java
Expand Up @@ -17,6 +17,7 @@ public class WebMethodStubSet {
private List<Stub> requestStubs = new ArrayList<Stub>();
private Stub responseStub;
private StubTypeTreeRepository stubTypeTreeRepository = new StubTypeTreeRepository();
private String methodDescription;

public String getMethodName() {
return methodName;
Expand Down Expand Up @@ -50,4 +51,11 @@ public boolean isInheritanceInvolved() {
return !stubTypeTreeRepository.isEmpty();
}

public String getMethodDescription() {
return methodDescription;
}

public void setMethodDescription(String methodDescription) {
this.methodDescription = methodDescription;
}
}
@@ -0,0 +1,121 @@
package org.jaxws.stub2html.service;

import org.jaxws.wsdl2html.ui.Wsdl2HtmlMain;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

public class DescriptionLocatorRepository {
private static DescriptionLocatorRepository instance = null;
private DescriptionLocatorRepository() {}
private List<Description> contents = new ArrayList();

public static synchronized DescriptionLocatorRepository getInstance() {
if (instance == null) instance = new DescriptionLocatorRepository();
return instance;
}

public String findDescriptionByMethod(Method method) {
if (contents.isEmpty()) {
loadContents();
}
String descriptionFound = "";
for (Description description : contents) {
if (description.getSymbol().contains(method.getName())) {
descriptionFound = description.getContent();
break;
}
}
if (descriptionFound.isEmpty()) {
System.out.println("No doc found for: " + method.getName());
}
return descriptionFound;
}

public String findDescriptionByVariable(Method method, String name) {
if (contents.isEmpty()) {
loadContents();
}

String descriptionFound = "";
for (Description description : contents) {
if (description.getSymbol().contains(method.getName() + "." + name)) {
descriptionFound = description.getContent();
break;
}
}
if (descriptionFound.isEmpty()) {
System.out.println("No doc found for: " + method.getName() + "." + name);
}
return descriptionFound;
}

public String getDescriptionByField(Field field) {
if (contents.isEmpty()) {
loadContents();
}

String descriptionFound = "";
for (Description description : contents) {
if (description.getSymbol().contains(field.getDeclaringClass().getSimpleName() + "." + field.getName())) {
descriptionFound = description.getContent();
break;
}
}
if (descriptionFound.isEmpty()) {
System.out.println("No doc found for: " + field.getDeclaringClass().getSimpleName() + ":" + field.getName());
}
return descriptionFound;
}

private void loadContents() {
File dir = new File(Wsdl2HtmlMain.getDescriptionsPath());
File[] files = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith(".txt");
}
});
if (files == null) {
return;
}
for (File file : files) {
try {
String content = "";
for (String allLines : Files.readAllLines(file.toPath(), Charset.defaultCharset())) {
content += allLines;
}
contents.add(new Description(file.getName(), content));
} catch (IOException e) {
e.printStackTrace();
}
}

}


static class Description {
private final String symbol;
private final String content;

public Description(String symbol, String content) {
this.symbol = symbol;
this.content = content;
}

public String getSymbol() {
return symbol;
}

public String getContent() {
return content;
}
}

}
Expand Up @@ -31,9 +31,11 @@ public static JavaLanguageVariable createVariableFromField(Field field) {
XmlElement annotation = field.getAnnotation(XmlElement.class);
if (annotation == null) {
variable.setVariableName(getElementName(field));
variable.setDescription(DescriptionLocatorRepository.getInstance().getDescriptionByField(field));
variable.setRequired(true);
} else {
variable.setVariableName(getVariableName(field, annotation));
variable.setDescription(DescriptionLocatorRepository.getInstance().getDescriptionByField(field));
variable.setRequired(isVariableRequired(annotation));
}
variable.setType(GenericsUtils.getFieldGenericType(field));
Expand Down Expand Up @@ -84,6 +86,7 @@ public static JavaLanguageVariable createVariableFromMethodReturn(Method method)
}
JavaLanguageVariable variable = new JavaLanguageVariable();
variable.setType(GenericsUtils.getMethodGenericReturnType(method));
variable.setDescription(DescriptionLocatorRepository.getInstance().findDescriptionByVariable(method, webResultAnnotation.name()));
variable.setVariableName(webResultAnnotation.name());
variable.setRequired(true);
variable.setHeader(webResultAnnotation.header());
Expand All @@ -97,6 +100,7 @@ private static JavaLanguageVariable buildJavaVariableFromMethodParam(Method meth
JavaLanguageVariable variable = new JavaLanguageVariable();
variable.setType(GenericsUtils.getMethodGenericParameterTypes(method, paramIndex));
variable.setVariableName(xmlAnnotation.name());
variable.setDescription(DescriptionLocatorRepository.getInstance().findDescriptionByVariable(method, xmlAnnotation.name()));
variable.setRequired(true);
variable.setHeader(xmlAnnotation.header());
Class<?> paramClass = method.getParameterTypes()[paramIndex];
Expand Down
Expand Up @@ -28,6 +28,7 @@ public static Stub convertToStub(JavaLanguageVariable variable, Stub parentStub,
Stub stub = new Stub();
stub.setParentStubRelation(parentStub);
stub.setStubName(variable.getVariableName());
stub.setStubDescription(variable.getDescription());
stub.setRequired(variable.isRequired());
stub.setHeader(variable.isHeader());
stub.setMultiOccurs(variable.isMultiOccurs());
Expand Down
Expand Up @@ -20,6 +20,8 @@ public class WebMethodStubSetFactory {
public static WebMethodStubSet createWebMethodStubSet(Method method) {
WebMethodStubSet stubSet = new WebMethodStubSet();
stubSet.setMethodName(method.getName());
stubSet.setMethodDescription(DescriptionLocatorRepository.getInstance().findDescriptionByMethod(method));

addRequestStubs(method, stubSet);
if (!Void.TYPE.equals(method.getReturnType())) {
addResponseStub(method, stubSet);
Expand Down
Expand Up @@ -4,6 +4,7 @@

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import javax.jws.WebMethod;
Expand All @@ -21,6 +22,12 @@ public static WebServiceStubSet createWebServiceStubSet(Class<?> webServiceClass
List<Method> methods = getWebMethods(webServiceClass);
WebServiceStubSet serviceStubs = new WebServiceStubSet();
serviceStubs.setWebServiceClass(webServiceClass);
methods.sort(new Comparator<Method>() {
@Override
public int compare(Method o1, Method o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (Method method : methods) {
serviceStubs.addMethodStub(createWebMethodStubSet(method));
}
Expand Down
Expand Up @@ -44,6 +44,7 @@ public String displayWebSerivce() {
rootMap.put("stubOgnl", new DisplayStubOgnlPathMethodModel());
rootMap.put("stubType", new DisplayStubTypeMethodModel());
rootMap.put("className", new DisplayClassNameMethodModel());
rootMap.put("description", new DisplayStubDescriptionMethodModel());

StringWriter out = new StringWriter();
template.process(rootMap, out);
Expand Down Expand Up @@ -81,6 +82,16 @@ public Object exec(List arguments) throws TemplateModelException {
}
}

private final class DisplayStubDescriptionMethodModel implements TemplateMethodModelEx {

@SuppressWarnings("rawtypes")
@Override
public Object exec(List arguments) throws TemplateModelException {
Stub stub = (Stub) DeepUnwrap.unwrap((TemplateModel) arguments.get(0));
return stub.getDescription();
}
}

private final class DisplayClassNameMethodModel implements TemplateMethodModelEx {

@SuppressWarnings("rawtypes")
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jaxws/wsdl2html/ui/Wsdl2HtmlMain.java
Expand Up @@ -19,6 +19,8 @@
*
*/
public class Wsdl2HtmlMain {
private static final String TARGET_APIDOCS_LOCATION = "/target/classes/META-INF/apidocs/";
private static String descriptionsPath = "";

public static void main(String[] args) throws IOException, WsdlImportException {

Expand All @@ -41,6 +43,7 @@ public static void main(String[] args) throws IOException, WsdlImportException {
File htmlDir = getHtmlDir(outputRootDir);

System.out.println("Generating from " + wsdlUrl);
Wsdl2HtmlMain.descriptionsPath = wsdlUrl;

FreemarkerWebServiceDisplayEngine displayEngine = createDisplayEngine(argList);
String html = Wsdl2Html.generateHtml(byteCodeDir.getAbsolutePath(), wsdlUrl, displayEngine);
Expand Down Expand Up @@ -69,4 +72,7 @@ private static File getByteCodeDir(File outputRootDir) {
return byteCodeDir;
}

public static String getDescriptionsPath() {
return (new File(descriptionsPath)).getParent() + TARGET_APIDOCS_LOCATION;
}
}
11 changes: 4 additions & 7 deletions src/main/resources/include/macros.ftl
Expand Up @@ -4,7 +4,6 @@
<tr>
<th>Property</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
<#list stub.childStubs as childStub>
Expand All @@ -24,12 +23,10 @@
${stubType(stub)}
</td>

<td>${stub.required?string("Y","N")}</td>

<td></td>

</tr>
<td>${stub.description!}</td>

</tr>
<#list stub.childStubs as childStub>
<@stubRow stub=childStub parentPath=stubOgnl(stub, parentPath)/>
</#list>
</#macro>
</#macro>
1 change: 0 additions & 1 deletion src/main/resources/include/methodParams.ftl
Expand Up @@ -7,7 +7,6 @@
<th>Name</th>
<th>Type</th>

<th>Required</th>
<th>Description</th>

</tr>
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/include/methodResponse.ftl
Expand Up @@ -7,11 +7,8 @@
<th>Name</th>
<th>Type</th>

<th>Required</th>
<th>Description</th>

</tr>
<#include "rootStubRow.ftl"/>
<#include "responseRootStubRow.ftl"/>
</tbody>

</table>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/include/methodsSummary.ftl
Expand Up @@ -31,7 +31,7 @@
${stubType(method.responseStub)}
</#if>
</td>
<td></td>
<td>${method.methodDescription}</td>

</tr>
</#list>
Expand All @@ -40,4 +40,4 @@
</div>
<#else>
No Operations
</#if>
</#if>
10 changes: 10 additions & 0 deletions src/main/resources/include/responseRootStubRow.ftl
@@ -0,0 +1,10 @@
<tr>
<td>${stubName(stub)}</td>
<td>
<div class="panel panel-default">
<div class="panel-heading">${stubType(stub)}</div>
<@stubChildrenAsTable stub=stub/>
</div>
</td>

</tr>
5 changes: 2 additions & 3 deletions src/main/resources/include/rootStubRow.ftl
Expand Up @@ -6,9 +6,8 @@
<@stubChildrenAsTable stub=stub/>
</div>
</td>
<td>${stub.required?string("Y","N")}</td>
<td>
${stub.description!}
${description(stub)}
</td>

</tr>
</tr>