
org.distributeme.generator.jsonrpc.ServerInterfaceGenerator Maven / Gradle / Ivy
package org.distributeme.generator.jsonrpc;
import com.sun.mirror.apt.Filer;
import com.sun.mirror.declaration.MethodDeclaration;
import com.sun.mirror.declaration.TypeDeclaration;
import com.sun.mirror.type.ReferenceType;
import org.distributeme.core.lifecycle.ServiceAdapter;
import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.Remote;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Generator for RMI based remote interface.
*
* @author lrosenberg
*/
public class ServerInterfaceGenerator extends AbstractJsonRpcGenerator implements JsonRpcGenerator {
private final Filer filer;
public ServerInterfaceGenerator(final Filer filer) {
this.filer = filer;
}
@Override
public void generate(TypeDeclaration type) throws IOException {
PrintWriter writer = filer.createSourceFile(getPackageName(type) + "." + getServerInterfaceName(type));
setWriter(writer);
writePackage(type);
emptyline();
writeImport(ServiceAdapter.class);
writeImport(List.class);
writeImport(Map.class);
writeImport(Remote.class);
writeImport(getInterfaceFullName(type));
emptyline();
writeComment("generated by "+ServerInterfaceGenerator.class.getName());
writeString("public interface " + getServerInterfaceName(type) + " extends Remote, ServiceAdapter {");
increaseIdent();
Collection extends MethodDeclaration> methods = getAllDeclaredMethods(type);
for (MethodDeclaration method : methods) {
String methodDecl = getInterfaceMethodDeclaration(method, true);
if (method.getThrownTypes().size() > 0) {
String exceptions = "";
for (ReferenceType rt : method.getThrownTypes()) {
if (exceptions.length() > 0) {
exceptions += ", ";
}
exceptions += rt.toString();
}
methodDecl += " throws " + exceptions;
}
writeStatement(methodDecl);
emptyline();
}
writeStatement("public " + getInterfaceName(type) + " getImplementation()");
closeBlock();
writer.flush();
writer.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy