);
}
protected void generateProxy(Element proxyElement, String targetPackage, String[] filterSetter,
String[] filterGetter, boolean isEmbeddedType, TypeMirror locatorType) {
InterfaceGenerationHelper writer = null;
try {
ReflectionHelper reflection = new ReflectionHelper(getEnvironment(), (TypeElement) proxyElement);
String proxyElementSimpleName = reflection.getSimpleClassName();
String proxyElementClassName = reflection.getClassName();
String proxyElementPackage = reflection.getPackageName();
// Magic: By default proxies should be available for client and server side.
String preparedProxyElementClassName = proxyElementClassName.replace(".server", ".shared");
String preparedProxyElementPackage = proxyElementPackage.replace(".server", ".shared");
if (targetPackage != null && !targetPackage.isEmpty()) {
// Prepare user defined proxy target package and do not replace server with shared.
preparedProxyElementClassName = targetPackage + "." + proxyElementSimpleName;
preparedProxyElementPackage = targetPackage;
}
String proxySimpleName = proxyElementSimpleName + "Proxy";
String proxyClassName = preparedProxyElementClassName + "Proxy";
@SuppressWarnings("resource")
Writer sourceWriter = getEnvironment().getFiler().createSourceFile(proxyClassName,
proxyElement).openWriter();
writer = new InterfaceGenerationHelper(sourceWriter);
writer.generatePackageDeclaration(preparedProxyElementPackage);
if (isEmbeddedType) {
generateValueProxyHeader(writer, reflection, proxyElementClassName, proxySimpleName);
} else {
generateEntityProxyHeader(writer, reflection, proxyElementClassName, proxySimpleName, locatorType);
}
writer.println();
Collection<VariableElement> allFields = reflection.getNonConstantFields();
// Generate getters.
Collection<VariableElement> getterFields = reflection.filterFields(allFields, filterGetter);
for (VariableElement getterField : getterFields) {
generateGetter(writer, getterField);
}
// Generate setters.
Collection<VariableElement> setterFields = reflection.filterFields(allFields, filterSetter);
for (VariableElement setterField : setterFields) {
generateSetter(writer, setterField);
}
writer.println();
writer.generateFooter();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (writer != null) {
writer.close();
}
}
}