
net.jangaroo.jooc.mvnplugin.sencha.configbuilder.SenchaConfigBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jangaroo-maven-plugin Show documentation
Show all versions of jangaroo-maven-plugin Show documentation
This plugin compiles Jangaroo sources to JavaScript.
The newest version!
package net.jangaroo.jooc.mvnplugin.sencha.configbuilder;
import net.jangaroo.jooc.mvnplugin.sencha.SenchaUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* A base class for all builders for Sencha JSON formats.
*/
public class SenchaConfigBuilder {
protected Map config = new LinkedHashMap<>();
private File destFile = null;
private String destFileComment = null;
@SuppressWarnings("unchecked")
T nameValue(@Nonnull String name, @Nullable Object value) {
handleNewValue(config, name, config.get(name), value);
return (T) this;
}
private static void mergeMap(@Nonnull Map baseMap,
@Nonnull Map mapWithNewValues) {
for (Map.Entry entry : mapWithNewValues.entrySet()) {
String key = entry.getKey();
handleNewValue(baseMap, key, baseMap.get(key), entry.getValue());
}
}
private static void handleNewValue(@Nonnull Map baseMap,
@Nonnull String key,
@Nullable Object currentValue,
@Nullable Object newValue) {
boolean isListValue = newValue instanceof List;
boolean isMapValue = newValue instanceof Map;
if (currentValue == null || newValue == null || !(isListValue || isMapValue)) {
baseMap.put(key, newValue);
} else if (isMapValue) {
//noinspection unchecked
addToMapRecursively(baseMap, key, currentValue, (Map) newValue);
} else {
addToList(baseMap, key, currentValue, (Collection>) newValue);
}
}
private static void addToList(@Nonnull Map baseMap,
@Nonnull String key,
@Nonnull Object currentValue,
@Nonnull Collection> additionalValues) {
if (!(currentValue instanceof List)) {
String errorMessage = String.format("Expected a list as value for property name %s, but got %s", key, currentValue);
throw new IllegalArgumentException(errorMessage);
}
@SuppressWarnings("unchecked")
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy