Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2011 vvakame
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.vvakame.util.jsonpullparser.factory.template;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.tools.JavaFileObject;
import net.vvakame.util.jsonpullparser.factory.JsonKeyModel;
import net.vvakame.util.jsonpullparser.factory.JsonModelModel;
import net.vvakame.util.jsonpullparser.factory.Log;
import net.vvakame.util.jsonpullparser.factory.StoreJsonModel;
import org.mvel2.templates.TemplateRuntime;
/**
* MVEL templating facility.
* @author vvakame
*/
public class MvelTemplate {
private MvelTemplate() {
}
/**
* Generates source code into the given file object from the given data model, utilizing the templating engine.
* @param fileObject Target file object
* @param model Data model for source code generation
* @throws IOException
* @author vvakame
*/
public static void writeGen(JavaFileObject fileObject, JsonModelModel model) throws IOException {
Map map = convModelToMap(model);
Writer writer = fileObject.openWriter();
PrintWriter printWriter = new PrintWriter(writer);
String generated =
(String) TemplateRuntime.eval(getTemplateString("JsonModelGen.java.mvel"), map);
try {
printWriter.write(generated);
printWriter.flush();
printWriter.close();
} catch (Exception e) {
throw new RuntimeException("error raised in process " + model.getTarget(), e);
}
}
/**
* Generates source code into the given file object from the given data model, utilizing the templating engine.
* @param fileObject Target file object
* @param model Data model for source code generation
* @throws IOException
* @author vvakame
*/
public static void writeJsonMeta(JavaFileObject fileObject, JsonModelModel model)
throws IOException {
Map map = convModelToMap(model);
Writer writer = fileObject.openWriter();
PrintWriter printWriter = new PrintWriter(writer);
String generated =
(String) TemplateRuntime.eval(getTemplateString("JsonModelMeta.java.mvel"), map);
try {
printWriter.write(generated);
printWriter.flush();
printWriter.close();
} catch (Exception e) {
throw new RuntimeException("error raised in process " + model.getTarget(), e);
}
}
static Map convModelToMap(JsonModelModel model) {
Map map = new LinkedHashMap();
map.put("packageName", model.getPackageName());
map.put("postfix", model.getPostfix());
map.put("existsBase", model.isExistsBase());
map.put("targetBase", model.getTargetBase());
map.put("target", model.getTarget());
map.put("targetNew", model.getTargetNew());
{
List