org.babyfish.jimmer.client.generator.Context Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-client Show documentation
Show all versions of jimmer-client Show documentation
A revolutionary ORM framework for both java and kotlin
package org.babyfish.jimmer.client.generator;
import org.babyfish.jimmer.client.runtime.*;
import org.babyfish.jimmer.client.source.Source;
import org.babyfish.jimmer.client.source.SourceManager;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public abstract class Context {
private final Metadata metadata;
private final String indent;
SourceManager sourceManager;
protected Context(Metadata metadata, String indent) {
this.metadata = metadata;
this.indent = indent != null && !indent.isEmpty() ? indent : " ";
}
private void init() {
if (this.sourceManager != null) {
return;
}
this.sourceManager = createSourceManager();
Set handledTypes = new HashSet<>();
for (Service service : metadata.getServices()) {
sourceManager.getSource(service);
for (Operation operation : service.getOperations()) {
sourceManager.getSource(operation);
Type returnType = operation.getReturnType();
if (returnType != null) {
initSource(returnType, handledTypes);
}
for (Parameter parameter : operation.getParameters()) {
initSource(parameter.getType(), handledTypes);
}
for (ObjectType exceptionType : operation.getExceptionTypes()) {
initSource(exceptionType, handledTypes);
}
}
}
sourceManager.createAdditionalSources();
}
private void initSource(Type type, Set handledTypes) {
if (!handledTypes.add(type)) {
return;
}
if (type instanceof ObjectType) {
ObjectType objectType = (ObjectType) type;
switch (objectType.getKind()) {
case FETCHED:
sourceManager.getSource(objectType);
initEnumTypes(objectType, handledTypes);
return;
case DYNAMIC:
case EMBEDDABLE:
case STATIC:
sourceManager.getSource(objectType);
for (Type argument : objectType.getArguments()) {
initSource(argument, handledTypes);
}
// No break
default:
for (Property property : objectType.getProperties().values()) {
initSource(property.getType(), handledTypes);
}
}
} else if (type instanceof NullableType) {
initSource(((NullableType)type).getTargetType(), handledTypes);
} else if (type instanceof ListType) {
initSource(((ListType)type).getElementType(), handledTypes);
} else if (type instanceof MapType) {
initSource(((MapType)type).getKeyType(), handledTypes);
initSource(((MapType)type).getValueType(), handledTypes);
} else {
sourceManager.getSource(type);
}
}
private void initEnumTypes(Type type, Set handledTypes) {
if (type instanceof ObjectType) {
ObjectType objectType = (ObjectType) type;
for (Property property : objectType.getProperties().values()) {
initEnumTypes(property.getType(), handledTypes);
}
} else if (type instanceof EnumType) {
initSource(type, handledTypes);
}
}
public Metadata getMetadata() {
return metadata;
}
public String getIndent() {
return indent;
}
public Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy