Bundle templateBundle = _insideEclipse ? Activator.getDefault().getBundle() : null;
VelocityEngine velocityEngine = WOLipsVelocityUtils.createVelocityEngine("EOGenerator", templateBundle, eogeneratorModel.getTemplateDir(), eogeneratorModel.getProjectPath(), _insideEclipse, resourceLoaderClass);
List<EOModel> models = new LinkedList<EOModel>();
EOModelRenderContext renderContext = new EOModelRenderContext();
try {
String prefix = eogeneratorModel.getPrefix();
if (prefix != null) {
renderContext.setPrefix(prefix);
}
renderContext.setSuperclassPackage(eogeneratorModel.getSuperclassPackage());
String eogenericRecordClassName = eogeneratorModel.getDefineValueNamed("EOGenericRecord");
if (eogenericRecordClassName != null) {
renderContext.setEOGenericRecordClassName(eogenericRecordClassName);
}
renderContext.setJavaClientCommon(eogeneratorModel.isJavaClientCommon() != null && eogeneratorModel.isJavaClientCommon().booleanValue());
renderContext.setJavaClient(eogeneratorModel.isJavaClient() != null && eogeneratorModel.isJavaClient().booleanValue());
EOModelRenderContext.setRenderContext(renderContext);
EOModelGroup modelGroup;
if (preloadedModelGroup == null) {
modelGroup = new EOModelGroup();
Set<EOModelVerificationFailure> failures = new HashSet<EOModelVerificationFailure>();
if (BooleanUtils.isTrue(eogeneratorModel.isLoadModelGroup())) {
for (EOModelReference eomodelReference : eogeneratorModel.getModels()) {
EOModelGroup generatingModelGroup = new EOModelGroup();
URL modelURL = getModelURL(eogeneratorModel, eomodelReference);
IEOModelGroupFactory.Utility.loadModelGroup(modelURL, generatingModelGroup, failures, true, modelURL, monitor);
if (monitor.isCanceled()) {
throw new OperationCanceledException("EOGenerator canceled.");
}
EOModel generatingModel = generatingModelGroup.getEditingModel();
models.add(generatingModel);
for (EOModel model : generatingModelGroup.getModels()) {
if (!modelGroup.containsModelNamed(model.getName())) {
modelGroup.addModel(model);
}
}
}
} else {
loadModels(eogeneratorModel, modelGroup, eogeneratorModel.getModels(), models, monitor);
loadModels(eogeneratorModel, modelGroup, eogeneratorModel.getRefModels(), new LinkedList<EOModel>(), monitor);
modelGroup.resolve(failures);
modelGroup.verify(failures);
}
for (EOModelVerificationFailure failure : failures) {
if (!failure.isWarning()) {
results.append("Error: " + failure.getMessage() + "\n");
showResults = true;
}
}
} else {
modelGroup = preloadedModelGroup;
for (EOModelReference modelRef : eogeneratorModel.getModels()) {
String modelName = modelRef.getName();
EOModel model = modelGroup.getModelNamed(modelName);
if (model == null) {
throw new RuntimeException("There was no model named '" + modelName + "' in this model group.");
}
models.add(model);
}
}
File superclassDestination = new File(eogeneratorModel.getDestination());
if (!superclassDestination.isAbsolute()) {
IPath projectPath = eogeneratorModel.getProjectPath();
if (projectPath != null) {
superclassDestination = new File(projectPath.toFile(), eogeneratorModel.getDestination());
}
}
if (!superclassDestination.exists()) {
if (!superclassDestination.mkdirs()) {
throw new IOException("Failed to create destination '" + superclassDestination + "'.");
}
}
File subclassDestination = new File(eogeneratorModel.getSubclassDestination());
if (!subclassDestination.isAbsolute()) {
IPath projectPath = eogeneratorModel.getProjectPath();
if (projectPath != null) {
subclassDestination = new File(projectPath.toFile(), eogeneratorModel.getSubclassDestination());
}
}
if (!subclassDestination.exists()) {
if (!subclassDestination.mkdirs()) {
throw new IOException("Failed to create subclass destination '" + subclassDestination + "'.");
}
}
// String filePathTemplate = eogeneratorModel.getFilenameTemplate();
// if (filePathTemplate == null || filePathTemplate.trim().length()
// == 0) {
// }
String extension = eogeneratorModel.getExtension();
Set<String> entitySet = new HashSet<String>();
if (entityList != null) {
entitySet.addAll(entityList);
}
Date date = new Date();
for (EOModel model : models) {
if (monitor.isCanceled()) {
throw new OperationCanceledException("EOGenerator canceled.");
}
// System.out.println("Generating " + model.getName() + " ...");
for (EOEntity entity : model.getEntities()) {
VelocityContext context = new VelocityContext();
context.put("eogeneratorModel", eogeneratorModel);
context.put("date", date);
context.put("calendar", Calendar.getInstance());
for (Define define : eogeneratorModel.getDefines()) {
context.put(define.getName(), define.getValue());
}
context.put("list", new ListTool());
context.put("set", new SetTool());
//context.put("sorter", new SortTool());
context.put("model", model);
if (entitySet.size() != 0 && !entitySet.contains(entity.getName())) {
continue;
}
if (monitor.isCanceled()) {
throw new OperationCanceledException("EOGenerator canceled.");
}
// System.out.println("Generating " + model.getName() + "."
// + entity.getName() + " ...");
context.put("entity", entity);
String classNameWithPackage = renderContext.getClassNameForEntity(entity);
boolean eogenericRecord = classNameWithPackage == null || (classNameWithPackage.endsWith("GenericRecord") && !entity.getName().endsWith("GenericRecord"));
if (entity.isGenerateSource() && !eogenericRecord) {
String prefixClassNameWithPackage = entity.getPrefixClassName();
context.put("className", classNameWithPackage);
context.put("prefixClassName", prefixClassNameWithPackage);