All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src-tool.org.neodatis.odb.tool.ClassGenerator Maven / Gradle / Ivy

There is a newer version: 1.9.30.689
Show newest version
/**
 * 
 */
package org.neodatis.odb.tool;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import org.neodatis.odb.ODB;
import org.neodatis.odb.ODBFactory;
import org.neodatis.odb.OdbConfiguration;
import org.neodatis.odb.core.layers.layer2.meta.ClassAttributeInfo;
import org.neodatis.odb.core.layers.layer2.meta.ClassInfo;
import org.neodatis.odb.core.layers.layer2.meta.MetaModel;
import org.neodatis.odb.impl.core.layers.layer3.engine.Dummy;
import org.neodatis.tool.DLogger;
import org.neodatis.tool.wrappers.OdbClassUtil;
import org.neodatis.tool.wrappers.list.IOdbList;

/**
 * @author olivier
 *
 */
public class ClassGenerator {
	
	public void genereateClasses(String sourceFolder, ODB odb) throws IOException{
		DLogger.info(String.format("Generating classes to %s",sourceFolder));
		MetaModel metaModel = Dummy.getEngine(odb).getSession(true).getMetaModel();
		
		Collection cis = metaModel.getUserClasses();
		
		Iterator iterator = cis.iterator();
		
		while(iterator.hasNext()){
			generateOneClass(sourceFolder, iterator.next());
		}
	}

	/**
	 * @param next
	 * @throws IOException 
	 */
	private void generateOneClass(String sourceFolder, ClassInfo ci) throws IOException {
		
		if(ci.getFullClassName().startsWith("java.") || ci.getFullClassName().startsWith("sun.")){
			return;
		}

		
		DLogger.info(String.format("Generating class for %s", ci.getFullClassName()));
		IOdbList cais = ci.getAttributes();
		StringBuffer buffer = new StringBuffer();
		buffer.append("// Generated by NeoDatis on ").append(new Date()).append("\n");
		buffer.append(String.format("package %s;\n\n",OdbClassUtil.getPackageName(ci.getFullClassName())));
		buffer.append(String.format("public class %s{\n\n",OdbClassUtil.getClassName(ci.getFullClassName())));
		StringBuffer gettersAndSetters = new StringBuffer();
		
		for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy