text:
package org.shaolin.bmdp.designtime.bediagram;

import java.io.File;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.shaolin.bmdp.datamodel.bediagram.BECollectionType;
import org.shaolin.bmdp.datamodel.bediagram.BEComplexType;
import org.shaolin.bmdp.datamodel.bediagram.BEDiagram;
import org.shaolin.bmdp.datamodel.bediagram.BEListType;
import org.shaolin.bmdp.datamodel.bediagram.BEMapType;
import org.shaolin.bmdp.datamodel.bediagram.BEObjRefType;
import org.shaolin.bmdp.datamodel.bediagram.BEPrimitiveType;
import org.shaolin.bmdp.datamodel.bediagram.BESetType;
import org.shaolin.bmdp.datamodel.bediagram.BEType;
import org.shaolin.bmdp.datamodel.bediagram.BinaryType;
import org.shaolin.bmdp.datamodel.bediagram.BooleanType;
import org.shaolin.bmdp.datamodel.bediagram.BusinessEntityType;
import org.shaolin.bmdp.datamodel.bediagram.CEObjRefType;
import org.shaolin.bmdp.datamodel.bediagram.ConstantEntityType;
import org.shaolin.bmdp.datamodel.bediagram.DateTimeType;
import org.shaolin.bmdp.datamodel.bediagram.DoubleType;
import org.shaolin.bmdp.datamodel.bediagram.FileType;
import org.shaolin.bmdp.datamodel.bediagram.IntType;
import org.shaolin.bmdp.datamodel.bediagram.JavaObjRefType;
import org.shaolin.bmdp.datamodel.bediagram.LongType;
import org.shaolin.bmdp.datamodel.bediagram.MemberType;
import org.shaolin.bmdp.datamodel.bediagram.ObjectRefType;
import org.shaolin.bmdp.datamodel.bediagram.PersistenceTypeType;
import org.shaolin.bmdp.datamodel.bediagram.PersistentConfigType;
import org.shaolin.bmdp.datamodel.bediagram.StringType;
import org.shaolin.bmdp.datamodel.bediagram.TimeType;
import org.shaolin.bmdp.datamodel.common.DiagramType;
import org.shaolin.bmdp.datamodel.common.TargetEntityType;
import org.shaolin.bmdp.datamodel.common.TargetJavaType;
import org.shaolin.bmdp.datamodel.common.VariableType;
import org.shaolin.bmdp.designtime.immocompiler.MemoryCompiler;
import org.shaolin.bmdp.designtime.tools.GeneratorOptions;
import org.shaolin.bmdp.designtime.tools.PumpWriter;
import org.shaolin.bmdp.runtime.AppContext;
import org.shaolin.bmdp.runtime.Registry;
import org.shaolin.bmdp.runtime.VariableUtil;
import org.shaolin.bmdp.runtime.be.BEUtil;
import org.shaolin.bmdp.runtime.entity.EntityAddedEvent;
import org.shaolin.bmdp.runtime.entity.EntityManager;
import org.shaolin.bmdp.runtime.entity.EntityUpdatedEvent;
import org.shaolin.bmdp.runtime.entity.IEntityEventListener;
import org.shaolin.bmdp.utils.ClassUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class BESourceGenerator implements IEntityEventListener<BusinessEntityType, BEDiagram> {

	private static final Logger logger = LoggerFactory.getLogger(BESourceGenerator.class.getName());

	private static Map<Class<?>, String> dataTypeToJavaTypeMap
		= new HashMap<Class<?>, String>();

	private final PumpWriter out = new PumpWriter();

	private GeneratorOptions option = null;

	private final CESourceGenerator ceGenerator;

	private List<String> classpathElements = null;

	private EntityManager entityManager;

	private List<String> generatedBEs = new ArrayList<String>();

	private boolean genExtension = false;

	static {
		dataTypeToJavaTypeMap.put(BooleanType.class, "boolean");
		dataTypeToJavaTypeMap.put(IntType.class, "int");
		dataTypeToJavaTypeMap.put(LongType.class, "long");
		dataTypeToJavaTypeMap.put(DoubleType.class, "double");
		dataTypeToJavaTypeMap.put(BinaryType.class, "byte[]");
		dataTypeToJavaTypeMap.put(StringType.class, "java.lang.String");
		// needed to update!!!
		dataTypeToJavaTypeMap.put(FileType.class, "java.lang.String");
		dataTypeToJavaTypeMap.put(DateTimeType.class, "java.util.Date");
		dataTypeToJavaTypeMap.put(TimeType.class, "java.sql.Time");
	}

	public BESourceGenerator(GeneratorOptions option, CESourceGenerator ceGenerator, List<String> classpathElements) {
		this.option = option;
		this.ceGenerator = ceGenerator;
		this.classpathElements = classpathElements;

		out.setOutputDir(option.getSrcDir());
		out.setEncoding(Registry.getInstance().getEncoding());
	}

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	// temporary global variables.
	private static String cePackage;
	private static String bePackage;

	public void notify(EntityAddedEvent<BusinessEntityType, BEDiagram> event) {
		if (event.getDiagram().getBePackage().indexOf(option.getBundleName()) == -1) {
			return;
		}

		out.write("\n\n");

		File interfaceRoot = option.getSrcDir();
		File implementRoot = option.getSrcDir();
		String entityName = event.getEntity().getEntityName();
		cePackage = event.getDiagram().getCePackage();
		bePackage = event.getDiagram().getBePackage();
		String packageName = entityName.substring(0, entityName.lastIndexOf("."));
		String name = entityName.substring(entityName.lastIndexOf(".") + 1);
		String interfaceJava = packageName + ".I" + name;
		String implementJava = entityName + "Impl";

		try {
			generateBEInterface(event.getEntity(), interfaceRoot, interfaceJava, out);
		} catch (Exception e) {
			logger.error("Error when generate interface for " + entityName,
					e);
		}
		try {
			generateBEImplement(event.getEntity(), implementRoot, implementJava,
					interfaceJava, out);
		} catch (Exception e) {
			logger.error("Error when generate implement for " + entityName,
					e);
		}

		out.write("\n\n");
		out.finish();
	}

	public void notify(EntityUpdatedEvent<BusinessEntityType, BEDiagram> event) {

	}

	public Class<BusinessEntityType> getEventType() {
		return BusinessEntityType.class;
	}

	public void notifyLoadFinish(DiagramType diagram) {
		BEDiagram bediagram = (BEDiagram)diagram;
		if (bediagram.getBePackage().indexOf(option.getBundleName()) == -1) {
			return;
		}

		File ceDir = new File(option.getSrcDir(), bediagram.getCePackage().replace('.', '/'));
		if (!ceDir.exists()) {
			ceDir.mkdirs();

			// generate a fake class for compiling process.
			ConstantEntityType entity = new ConstantEntityType();
			entity.setEntityName(bediagram.getCePackage() + ".FakeCE");
			EntityAddedEvent<ConstantEntityType, BEDiagram> event =
					new EntityAddedEvent(diagram, entity);
			ceGenerator.notify(event);
		}
	}

	public void notifyAllLoadFinish() {
		if (generatedBEs.isEmpty() && ceGenerator.getGeneratedCEs().isEmpty()) {
			return;
		}

		String sep = System.getProperty("path.separator");
		StringBuffer cp = new StringBuffer();
		if (Thread.currentThread().getContextClassLoader() instanceof URLClassLoader) {
			URLClassLoader urlCL = ((URLClassLoader) (Thread.currentThread().getContextClassLoader()));
			ClassLoader parent = urlCL.getParent();
			ClassLoader temp = parent;
			while (temp != null && temp instanceof URLClassLoader) {
				java.net.URL[] ulrs = ((URLClassLoader) (temp)).getURLs();
				for (java.net.URL url : ulrs) {
					cp.append(new java.io.File(url.getPath()));
					cp.append(sep);
				}
				temp = temp.getParent();
			}
			java.net.URL[] ulrs = urlCL.getURLs();
			for (java.net.URL url : ulrs) {
				cp.append(new java.io.File(url.getPath()));
				cp.append(sep);
			}
		}
		if (classpathElements != null && !classpathElements.isEmpty()) {
			// load into current class loader.
			for (String p : classpathElements) {
				cp.append(p).append(sep);
			}
		}
		// add ce classes.
		cp.append(option.getTargetClassesDir().getAbsolutePath());
		String classpath = cp.toString();

		logger.info("Pre-compile BE source code...");
		logger.debug("Built class path: " + classpath);
		logger.info("sourcepath: " + option.getSrcDir().getAbsolutePath());
		logger.info("targetpath: " + option.getTargetClassesDir().getAbsolutePath());

		if (!option.getTargetClassesDir().exists()) {
			option.getTargetClassesDir().mkdirs();
		}

		MemoryCompiler compiler = new MemoryCompiler();
		try {
			// compiling CEs from disk to momery.
			List<String> generatedCEs = ceGenerator.getGeneratedCEs();
			if (generatedCEs.size() > 0) {
				File[] files = new File[generatedCEs.size()];
				for (int i=0 ; i<generatedCEs.size(); i++) {
					files[i] = new File(generatedCEs.get(i));
				}
				compiler.compileToDisk(classpath, option.getTargetClassesDir().getAbsolutePath(), files);
				compiler.compile(classpath, option.getTargetClassesDir().getAbsolutePath(), files);
			}

			// compiling BEs.
			if (generatedBEs.size() > 0) {
				File[] files = new File[generatedBEs.size()];
				for (int i=0 ; i<generatedBEs.size(); i++) {
					files[i] = new File(generatedBEs.get(i));
				}
				compiler.compile(classpath, option.getTargetClassesDir().getAbsolutePath(), files);
			}
			// get MemoryClassLoader
			option.setBEMemoryClassLoader(compiler.getClassLoader());

		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
		} finally {
			ceGenerator.getGeneratedCEs().clear();
			generatedBEs.clear();
			compiler.close();
		}
	}

	private void generateBEInterface(BusinessEntityType businessEntity, File interfaceRoot,
			String interfaceJava, PumpWriter out) {
		if (interfaceJava != null) {
			String interfaceName = ClassUtil.getClassName(interfaceJava);
			String packageName = ClassUtil.getPackageName(interfaceJava);
			generateHeader(businessEntity, packageName, interfaceJava,
					interfaceRoot, true, out);

			out.write("\n\n/**\n * ");
			out.print(businessEntity.getDescription());
			out.write("\n * ");
			out.write("\n * This code is generated automatically, any change will be replaced after rebuild.");
			out.write("\n * ");
			out.write("\n *\n */\n\npublic interface ");
			out.print(interfaceName);
			out.write(" ");
			generateInterfaceExtends(businessEntity, out);
			out.write("\n{\n    public final static String ENTITY_NAME = \"");
			out.print(businessEntity.getEntityName());
			out.write("\";\n    \n ");

			if (businessEntity.isNeedOrgId()) {
				out.write("\n    /**\n     *  get orgId");
				out.write("\n     *\n     *  @return orgId");
				out.write("\n     */\n    public long getOrgId();\n");
				out.write("\n    /**\n     *  set orgId");
				out.write("\n     */\n    public void setOrgId(long orgId);\n");
			}
			generateGetDeclaration(businessEntity, out);
			generateSetDeclaration(businessEntity, out);

			if (genExtension) {
				// TODO:
			}

			out.write("\n\n}\n\n        ");

		}
	}

	private void generateBEImplement(BusinessEntityType businessEntity, File implementRoot,
			String implementJava, String interfaceJava, PumpWriter out) {
		if (implementJava != null) {
			String implClsName = ClassUtil.getClassName(implementJava);
			String implPkgName = ClassUtil.getPackageName(implementJava);
			String intfClsName = ClassUtil.getClassName(interfaceJava);
			String intfPkgName = ClassUtil.getPackageName(interfaceJava);
			generateHeader(businessEntity, implPkgName, implementJava,
					implementRoot, false, out);

			out.write("\n\n/**\n * ");
			out.print(businessEntity.getDescription());
			out.write("\n * ");
			out.write("\n * This code is generated automatically, any change will be replaced after rebuild.");
			out.write("\n * ");
			out.write("\n *\n */\n\npublic class ");
			out.print(implClsName);
			out.write(" ");
			generateImplementExtends(businessEntity, out);
			out.write(" implements ");
			out.print(interfaceJava);
			out.write("\n{\n    private static final long serialVersionUID = 0x90B1123CE87B50FFL;");
			out.write("\n\n    protected String getBusinessEntityName()\n    {\n        return \"");
			out.print(businessEntity.getEntityName());
			out.write("\";\n    }\n\n    public ");
			out.print(implClsName);
			out.write("()\n    {\n        ");
			generateConstructor(businessEntity, out);
			out.write("\n    }\n    \n    ");

			if (genExtension) {
				// TODO:
			}

			out.write("\n    ");
			generateAttrDeclaration(businessEntity, out);
			out.write("\n    ");
			generateGetDefinition(businessEntity, out);
			out.write("\n    ");
			generateSetDefinition(businessEntity, out);
			out.write("\n    ");
			generateEqualsMethod(businessEntity, out);
			out.write("\n    ");
			generateToStringMethod(businessEntity, out);
			out.write("\n    ");
			generateToJsonMethod(businessEntity, out);
			out.write("\n    ");
			generateFromJsonMethod(businessEntity, out);
			out.write("\n    ");
//			generateGetMemberListMethod(businessEntity, out);
			out.write("\n    public ");
			out.print(intfClsName);
			out.write(" createEntity ()\n    {\n");
			out.write("        return new ");
			out.print(implClsName);
			out.write("();\n    }\n    ");

			if (genExtension) {
				// TODO:
			}
			out.write("\n}\n\n        ");

		}
	}

	// //////////////////////////////////////////////////////////////////////
	private void generateHeader(BusinessEntityType businessEntity,
			String packageName, String fullClassName, File rootDir,
			boolean isInterface, PumpWriter out) {
		String fileName = getJavaFileName(rootDir, fullClassName);
		if (logger.isInfoEnabled()) {
			logger.info("BusinessEntity is {}, whose generated file is {}",
					businessEntity.getEntityName(), fileName);
		}
		option.getI18nProperty().put(businessEntity.getEntityName(), businessEntity.getEntityName());
		generatedBEs.add(fileName);

		out.write("\n!!!!file ");
		out.print(fileName);
		out.write("\n/*\n *\n * This file is automatically generated on ");
		out.print(new Date());
		out.write("\n */\n\n    ");

		if ((packageName != null) && (!packageName.equals(""))) {
			out.write("\npackage ");
			out.print(packageName);
			out.write(";\n        ");
		}

		out.write("\nimport java.util.Collections;\n");
		out.write("import java.util.List;\n");
		out.write("import java.util.ArrayList;\n");

		out.write("\nimport org.shaolin.bmdp.datamodel.bediagram.*;\n");
		out.write("import org.shaolin.bmdp.datamodel.common.*;\n");
		out.write("import org.shaolin.bmdp.runtime.be.IBusinessEntity;\n");
		out.write("import org.shaolin.bmdp.runtime.be.IExtensibleEntity;\n");
		out.write("import org.shaolin.bmdp.runtime.be.IPersistentEntity;\n");
		out.write("import org.shaolin.bmdp.runtime.be.IHistoryEntity;\n");
		out.write("import org.shaolin.bmdp.runtime.be.ITaskEntity;\n");
		out.write("import org.shaolin.bmdp.runtime.be.BEExtensionInfo;\n\n");
		out.write("import org.shaolin.bmdp.runtime.spi.IConstantService;\n\n");
		out.write("import org.shaolin.bmdp.runtime.spi.IServerServiceManager;\n\n");
		out.write("import org.shaolin.bmdp.runtime.AppContext;\n\n");
		out.write("import org.shaolin.bmdp.runtime.ce.CEUtil;\n\n");
		out.write("import org.shaolin.bmdp.runtime.be.BEUtil;\n\n");
		out.write("import org.shaolin.bmdp.json.JSONObject;\n\n");
		out.write("import org.shaolin.bmdp.json.JSONArray;\n\n");
		out.write("import org.shaolin.bmdp.json.JSONException;\n\n");

		List<MemberType> members = businessEntity.getMembers();
		for (MemberType m : members) {
			if (m.getType().getClass() == CEObjRefType.class) {
				out.write("import " + cePackage + ".*;\n");
				break;
			} else if (m.getType().getClass() == BEListType.class
					&& ((BEListType)m.getType()).getElementType().getClass() == CEObjRefType.class) {
				out.write("import " + cePackage + ".*;\n");
				break;
			} else if (m.getType().getClass() == BESetType.class
					&& ((BESetType)m.getType()).getElementType().getClass() == CEObjRefType.class) {
				out.write("import " + cePackage + ".*;\n");
				break;
			}
		}

	}

	private void generateInterfaceExtends(BusinessEntityType businessEntity, PumpWriter out) {
		String parentInterface = null;
		if (businessEntity.isNeedPersist()) {
			parentInterface = "IPersistentEntity";
			if (businessEntity.isNeedTask()) {
				parentInterface = "ITaskEntity";
			}
		} else if (businessEntity.isNeedHistory()) {
			parentInterface = "IHistoryEntity";
		} else {
			parentInterface = "IBusinessEntity";
		}

		ObjectRefType parentObj = businessEntity.getParentObject();
		if (parentObj != null) {
			if (parentObj instanceof BEObjRefType) {
				parentInterface += ", "
						+ getBEInterfaceClassName(((BEObjRefType) parentObj)
								.getTargetEntity().getEntityName());
			} else {
				/**
				String parentImplement = getJavaClassName(((JavaObjRefType) parentObj)
						.getTargetJava());
				try {
					String parentBE = getBENameByImplementClassName(parentImplement);
					parentInterface += ", " + getBEInterfaceClassName(parentBE);
				} catch (EntityNotFoundException e) {
					logger.info("Can't get BusinessEntity for implement: "
							+ parentImplement);
				}
				*/
			}
		}

		if (isSelfExtensible(businessEntity)) {
			parentInterface += ", IExtensibleEntity";
		}

		out.write("\n    extends ");
		out.print(parentInterface);

	}

	private void generateImplementExtends(BusinessEntityType businessEntity, PumpWriter out) {
		ObjectRefType parentObj = businessEntity.getParentObject();
		if (parentObj != null) {
			String parentImplement = null;
			if (parentObj instanceof BEObjRefType)
				parentImplement = getBEImplementClassName(((BEObjRefType) parentObj)
						.getTargetEntity().getEntityName());
			else
				parentImplement = getJavaClassName(((JavaObjRefType) parentObj)
						.getTargetJava());

			out.write("\n    extends ");
			out.print(parentImplement);
			out.write("\n        ");

		}
	}

	private void generateConstructor(BusinessEntityType businessEntity, PumpWriter out) {
		List<MemberType> members = businessEntity.getMembers();
		for (MemberType member: members) {
			String attrName = member.getName();

			option.getI18nProperty().put(businessEntity.getEntityName() + '.' + attrName, attrName);

			BEType attrType = member.getType();
			if (attrType instanceof BESetType) {
				out.write("\n        ");
				out.print(attrName);
				out.write(" = new java.util.HashSet");
				out.print(BEUtil.getGenericType(((BESetType)attrType).getElementType()));
				out.write("();\n            ");
			} else if (attrType instanceof BEListType) {
				out.write("\n        ");
				out.print(attrName);
				out.write(" = new java.util.ArrayList");
				out.print(BEUtil.getGenericType(((BEListType)attrType).getElementType()));
				out.write("();\n            ");
			} else if (attrType instanceof BEMapType) {
				BEMapType beMapType = (BEMapType)attrType;
				out.write("\n        ");
				out.print(attrName);
				out.write(" = new java.util.HashMap");
				out.print(BEUtil.getGenericTypes(beMapType.getKeyType(),
												 beMapType.getElementType()));
				out.write("();\n            ");
			}
		}
		if (isSelfExtensible(businessEntity)) {
			out.write("\n        _extField = new BEExtensionInfo();\n        ");
		}
	}

	private void generateGetDeclaration(BusinessEntityType beEntity, PumpWriter out) {
		List<MemberType> members = beEntity.getMembers();
		for (MemberType member: members) {
			if (member.isAccessible()) {
				String attrName = member.getName();
				BEType attrType = member.getType();
				String beanName = getBeanName(attrName);
				String attrTypeString = getDataTypeClassName(beEntity.isNeedPersist(), attrType);

				out.write("\n    /**\n     *  get ");
				out.print(attrName);
				out.write("\n     *\n     *  @return ");
				out.print(attrName);
				out.write("\n     */\n    public ");
				out.print(attrTypeString);
				out.write(" get");
				out.print(beanName);
				out.write("();\n");
//				if (attrType instanceof BEObjRefType) {
//					out.write("\n     public ");
//					TargetEntityType be = ((BEObjRefType) attrType).getTargetEntity();
//					out.print(getBEInterfaceClassName(be.getEntityName()));
//					out.write(" get");
//					out.print(beanName);
//					out.write("();\n");
//				}
			}
		}
	}

	private void generateSetDeclaration(BusinessEntityType beEntity, PumpWriter out) {
		List<MemberType> members = beEntity.getMembers();
		for (MemberType member: members) {

			if (member.isModifiable()) {
				String attrName = member.getName();
				BEType attrType = member.getType();
				String beanName = getBeanName(attrName);
				String attrTypeString = getDataTypeClassName(beEntity.isNeedPersist(), attrType);

				out.write("\n    /**\n     *  set ");
				out.print(attrName);
				out.write("\n     */\n    public void set");
				out.print(beanName);
				out.write("(");
				out.print(attrTypeString);
				out.write(" ");
				out.print(attrName);
				out.write(");\n");
				if (attrType instanceof BEObjRefType) {
					out.write("\n    public void set");
					out.print(beanName);
					out.write("(");
					TargetEntityType be = ((BEObjRefType) attrType).getTargetEntity();
					out.print(getBEInterfaceClassName(be.getEntityName()));
					out.write(" ");
					out.print(attrName);
					out.write(");\n");
				}
			}
		}
	}

	private void generateGetDefinition(BusinessEntityType beEntity, PumpWriter out) {
		out.write("    /**\n");
		out.write("     *  Get createDate\n");
		out.write("     *\n");
		out.write("     *  @return java.util.Date\n");
		out.write("     */\n");
		out.write("    public java.util.Date getCreateDate() {\n");
		out.write("        return createDate;\n");
		out.write("    }\n        ");
		if (isSelfNeedPersist(beEntity) || isSelfNeedHistory(beEntity)) {
			out.write("    /**\n");
			out.write("     *  Is enable\n");
			out.write("     *\n");
			out.write("     *  @return boolean\n");
			out.write("     */\n");
			out.write("    public boolean isEnabled() {\n");
			out.write("        return _enable;\n");
			out.write("    }\n        ");
			out.write("    /**\n");
			out.write("     *  Is enable\n");
			out.write("     *\n");
			out.write("     *  @return boolean\n");
			out.write("     */\n");
			out.write("    private boolean get_enable() {\n");
			out.write("        return _enable;\n");
			out.write("    }\n        ");
			out.write("    /**\n");
			out.write("     *  Get cas id.\n");
			out.write("     *\n");
			out.write("     *  @return long\n");
			out.write("     */\n");
			out.write("    public long getCas() {\n");
			out.write("        return _cas;\n");
			out.write("    }\n        ");
			out.write("    private long get_cas() {\n");
			out.write("        return _cas;\n");
			out.write("    }\n        ");
			if (beEntity.isNeedTask()) {
				out.write("    /**\n");
				out.write("     *  Get taskId\n");
				out.write("     *\n");
				out.write("     *  @return long\n");
				out.write("     */\n");
				out.write("    public long getTaskId() {\n");
				out.write("        return _taskId;\n");
				out.write("    }\n        ");
				out.write("    private long get_taskId() {\n");
				out.write("        return _taskId;\n");
				out.write("    }\n");
				out.write("    /**\n");
				out.write("     *  Get sessionId\n");
				out.write("     *\n");
				out.write("     *  @return String\n");
				out.write("     */\n");
				out.write("    public String getSessionId() {\n");
				out.write("        return _sessionId;\n");
				out.write("    }\n        ");
				out.write("    private String get_sessionId() {\n");
				out.write("        return _sessionId;\n");
				out.write("    }\n        ");
			}
		}
		if (beEntity.isNeedOrgId()) {
			out.write("    /**\n");
			out.write("     *  get orgId\n");
			out.write("     */\n");
			out.write("    public long getOrgId() {\n");
			out.write("        return this.orgId;\n");
			out.write("    }\n\n    ");
		}

		if (isSelfNeedHistory(beEntity)) {
			out.write("\n    /**\n");
			out.write("     *  get version\n");
			out.write("     *\n");
			out.write("     *  @return version\n");
			out.write("     */\n");
			out.write("    public int getVersion() {\n");
			out.write("        return _version;\n");
			out.write("    }\n\n");
			out.write("    private int get_version() {\n");
			out.write("        return _version;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  get operator user id\n");
			out.write("     *\n");
			out.write("     *  @return user id\n");
			out.write("     */\n");
			out.write("    public long getOptUserId() {\n");
			out.write("        return _optuserid;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  get operator user id\n");
			out.write("     *\n");
			out.write("     *  @return user id\n");
			out.write("     */\n");
			out.write("    private long get_optuserid() {\n");
			out.write("        return _optuserid;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  get start time\n");
			out.write("     *\n");
			out.write("     *  @return start time\n");
			out.write("     */\n");
			out.write("    public java.util.Date getStarttime() {\n");
			out.write("        return _starttime;\n");
			out.write("    }\n\n");
			out.write("    private java.util.Date get_starttime() {\n");
			out.write("        return _starttime;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  get endtime\n");
			out.write("     *\n");
			out.write("     *  @return endtime\n");
			out.write("     */\n");
			out.write("    public java.util.Date getEndtime() {\n");
			out.write("        return _endtime;\n");
			out.write("    }\n\n");
			out.write("    private java.util.Date get_endtime() {\n");
			out.write("        return _endtime;\n");
			out.write("    }\n\n");
		}

		if (isSelfExtensible(beEntity)) {
			out.write("\n    /**\n");
			out.write("     *  get _extType\n");
			out.write("     *\n");
			out.write("     *  @return _extType\n");
			out.write("     */\n");
			out.write("    public String get_extType() {\n");
			out.write("        return _extType;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  get _extField\n");
			out.write("     *\n");
			out.write("     *  @return _extField\n");
			out.write("     */\n");
			out.write("    public BEExtensionInfo get_extField() {\n");
			out.write("        return _extField;\n");
			out.write("    }\n        ");
		}

		List<MemberType> members = beEntity.getMembers();
		for (MemberType member: members) {
			if (member.isAccessible()) {
				String attrName = member.getName();
				BEType attrType = member.getType();
				String beanName = getBeanName(attrName);
				String attrTypeString = getDataTypeClassName(beEntity.isNeedPersist(), attrType);

				out.write("\n    /**\n     *  get ");
				out.print(attrName);
				out.write("\n     *\n     *  @return ");
				out.print(attrName);
				out.write("\n     */\n    public ");
				out.print(attrTypeString);
				out.write(" get");
				out.print(beanName);
				out.write("() {\n        return ");
				out.print(attrName);
				out.write(";\n    }\n");
//				if (attrType instanceof BEObjRefType) {
//					out.write("\n     public ");
//					TargetEntityType be = ((BEObjRefType) attrType).getTargetEntity();
//					out.print(getBEInterfaceClassName(be.getEntityName()));
//					out.write(" get");
//					out.print(beanName);
//					out.write("() {\n        return ");
//					out.print(attrName);
//					out.write(";\n    }\n");
//				}
				if (member.getType() instanceof CEObjRefType)  {
					String intAttrName = attrName + "Int";
					out.write("\n    /**\n     *  get ");
					out.print(intAttrName);
					out.write("\n     *\n     *  @return ");
					out.print(intAttrName);
					out.write("\n     */\n    private int get");
					out.print(beanName);
					out.write("Int() {\n        return ");
					out.print(intAttrName);
					out.write(";\n    }\n");
				} else if (member.getType().getClass() == BEListType.class
						&& ((BEListType)member.getType()).getElementType().getClass() == CEObjRefType.class) {
					String intAttrName = attrName + "IntValues";
					out.write("\n    /**\n     *  get ");
					out.print(intAttrName);
					out.write("\n     *\n     *  @return ");
					out.print(intAttrName);
					out.write("\n     */\n    public String get");
					out.print(beanName);
					out.write("IntValues() {\n        return ");
					out.print(intAttrName);
					out.write(";\n    }\n");
				}
			}
		}
	}

	private void generateSetDefinition(BusinessEntityType beEntity, PumpWriter out) {
		out.write("    /**\n");
		out.write("     *  set createDate\n");
		out.write("     *  @parameter true or false.\n");
		out.write("     */\n");
		out.write("    public void setCreateDate(java.util.Date createDate) {\n");
		out.write("        this.createDate = createDate;\n");
		out.write("    }\n\n    ");
		if (isSelfNeedPersist(beEntity) || isSelfNeedHistory(beEntity)) {
			out.write("    /**\n");
			out.write("     *  set enable\n");
			out.write("     *  @parameter true or false.\n");
			out.write("     */\n");
			out.write("    public void setEnabled(boolean enable) {\n");
			out.write("        _enable = enable;\n");
			out.write("    }\n\n    ");
			out.write("    /**\n");
			out.write("     *  set enable\n");
			out.write("     *  @parameter true or false.\n");
			out.write("     */\n");
			out.write("    private void set_enable(boolean enable) {\n");
			out.write("        _enable = enable;\n");
			out.write("    }\n\n    ");
			out.write("    /**\n");
			out.write("     *  set cas\n");
			out.write("     *  @parameter true or false.\n");
			out.write("     */\n");
			out.write("    public void setCas(long cas) {\n");
			out.write("        _cas = cas;\n");
			out.write("    }\n\n    ");
			out.write("    private void set_cas(long cas) {\n");
			out.write("        _cas = cas;\n");
			out.write("    }\n\n    ");

			if (beEntity.isNeedTask()) {
				out.write("    /**\n");
				out.write("     *  set taskId\n");
				out.write("     */\n");
				out.write("    public void setTaskId(long taskId) {\n");
				out.write("        this._taskId = taskId;\n");
				out.write("    }\n        ");
				out.write("    private void set_taskId(long taskId) {\n");
				out.write("        this._taskId = taskId;\n");
				out.write("    }\n");
				out.write("    /**\n");
				out.write("     *  set sessionId\n");
				out.write("     */\n");
				out.write("    public void setSessionId(String sessionId) {\n");
				out.write("        this._sessionId = sessionId;\n");
				out.write("    }\n        ");
				out.write("    private void set_sessionId(String sessionId) {\n");
				out.write("        this._sessionId = sessionId;\n");
				out.write("    }\n        ");
			}
		}

		if (beEntity.isNeedOrgId()) {
			out.write("    /**\n");
			out.write("     *  set orgId\n");
			out.write("     *  @parameter orgId.\n");
			out.write("     */\n");
			out.write("    public void setOrgId(long orgId) {\n");
			out.write("        this.orgId = orgId;\n");
			out.write("    }\n\n    ");
		}

		if (isSelfNeedHistory(beEntity)) {
			out.write("\n    /**\n");
			out.write("     *  set version\n");
			out.write("     */\n");
			out.write("    public void setVersion(int version) {\n");
			out.write("        _version = version;\n");
			out.write("    }\n\n");
			out.write("    private void set_version(int version) {\n");
			out.write("        _version = version;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  set operator user id\n");
			out.write("     *  @parameter user id.\n");
			out.write("     */\n");
			out.write("    public void setOptUserId(long optUserId) {\n");
			out.write("        _optuserid = optUserId;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  set operator user id\n");
			out.write("     *  @parameter user id.\n");
			out.write("     */\n");
			out.write("    private void set_optuserid(long optUserId) {\n");
			out.write("        _optuserid = optUserId;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  set start time\n");
			out.write("     *  @parameter start time which is the start time of object.\n");
			out.write("     */\n");
			out.write("    public void setStarttime(java.util.Date starttime) {\n");
			out.write("        _starttime = starttime;\n");
			out.write("    }\n\n");
			out.write("    private void set_starttime(java.util.Date starttime) {\n");
			out.write("        _starttime = starttime;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     *  set endtime\n");
			out.write("     *  @parameter endtime which is the end time of object.\n");
			out.write("     */\n");
			out.write("    public void setEndtime(java.util.Date endtime) {\n");
			out.write("        _endtime = endtime;\n");
			out.write("    }\n\n");
			out.write("    private void set_endtime(java.util.Date endtime) {\n");
			out.write("        _endtime = endtime;\n");
			out.write("    }\n\n");
		}

		if (isSelfExtensible(beEntity)) {
			out.write("/**\n");
			out.write("     *  set _extType\n");
			out.write("     *  @param _extType which is the extension type of be object.\n");
			out.write("     */\n");
			out.write("    public void set_extType(java.lang.String _extType) {\n");
			out.write("        this._extType = _extType;\n");
			out.write("    }\n        ");
		}

		List<MemberType> members = beEntity.getMembers();
		for (MemberType member: members) {

			if (member.isModifiable()) {
				String attrName = member.getName();
				BEType attrType = member.getType();
				String beanName = getBeanName(attrName);
				String attrTypeString = getDataTypeClassName(beEntity.isNeedPersist(), attrType);

				out.write("\n    /**\n     *  set ");
				out.print(attrName);
				out.write("\n     */\n    public void set");
				out.print(beanName);
				out.write("(");
				out.print(attrTypeString);
				out.write(" ");
				out.print(attrName);
				out.write(") {");
				if (member.isPk()) {
					out.write("\n    if(this." + attrName + " == 0) {");
				}
				generateSetBody(beEntity, attrTypeString, attrName, out);
				if (member.isPk()) {
					out.write("    }\n");
				}
				if (member.getType() instanceof CEObjRefType)  {
					String intAttrName = attrName + "Int";

					out.write("    if (");
					out.print(intAttrName);
					out.write(" != ");
					out.print(attrName);
					out.write(".getIntValue()) {\n");
					out.write("            ");
					out.print(intAttrName);
					out.write(" = ");
					out.print(attrName);
					out.write(".getIntValue();\n");
					out.write("        }\n");

				} else if (member.getType().getClass() == BEListType.class
						&& ((BEListType)member.getType()).getElementType().getClass() == CEObjRefType.class) {
					out.write("        this.");
					out.print(attrName);
					out.write("IntValues = CEUtil.parseCEIntValues2String("+attrName+");\n");
				}
				out.write("    }\n");
				if (attrType instanceof BEObjRefType) {
					out.write("\n    public void set");
					out.print(beanName);
					out.write("(");
					TargetEntityType be = ((BEObjRefType) attrType).getTargetEntity();
					out.print(getBEInterfaceClassName(be.getEntityName()));
					out.write(" ");
					out.print(attrName);
					out.write(") {");

					out.write("\n        this.");
					out.print(attrName);
					out.write(" = ("+getBEImplementClassName(be.getEntityName())+")");
					out.print(attrName);
					out.write(";\n");
					out.write("    }\n");
				}

				if (member.getType() instanceof CEObjRefType)  {
					String intAttrName = attrName + "Int";
					out.write("\n    /**\n     *  set int ");
					out.print(attrName);
					out.write("\n     */\n    private void set");
					out.print(beanName);
					out.write("Int(int intValue) {\n");
					out.write("        this.");
					out.print(intAttrName);
					out.write(" = intValue;\n");
					out.write("        if (");
					out.print(intAttrName);
					out.write(" != ");
					out.print(attrName);
					out.write(".getIntValue()) {\n");
		        	out.write("            ");
					out.print(attrName);
					out.write(" = (");
					out.print(attrTypeString);
					out.write(")IServerServiceManager.INSTANCE.getConstantService().getConstantEntity("+attrTypeString+".ENTITY_NAME).getByIntValue(");
					out.print(intAttrName);
					out.write(");\n");
		        	out.write("        }\n");
					out.write("    }\n");
				} else if (member.getType().getClass() == BEListType.class
						&& ((BEListType)member.getType()).getElementType().getClass() == CEObjRefType.class) {
					String elementType = ((CEObjRefType)((BEListType)member.getType()).getElementType()).getTargetEntity().getEntityName();
					String intAttrName = attrName + "IntValues";
					out.write("\n    /**\n     *  set String ");
					out.print(attrName);
					out.write("\n     */\n    private void set");
					out.print(beanName);
					out.write("IntValues(String intValues) {\n");
					out.write("        this.");
					out.print(intAttrName);
					out.write(" = intValues;\n");
					out.write("        this.");
					out.print(attrName);
					out.write(" = CEUtil.parseCEIntValues("+elementType+".class, intValues);\n");
					out.write("    }\n");
				}
			}
		}
	}

	private void generateSetBody(BusinessEntityType businessEntity,
			String attrTypeString, String attrName, PumpWriter out) {
		out.write("\n        this.");
		out.print(attrName);
		out.write(" = ");
		out.print(attrName);
		out.write(";\n");
	}

	private void generateAttrDeclaration(BusinessEntityType beEntity, PumpWriter out) {
		out.write("    /**\n");
		out.write("     * Create Date\n");
		out.write("     */\n");
		out.write("    private java.util.Date createDate = null;\n\n");
		if (isSelfNeedPersist(beEntity) || isSelfNeedHistory(beEntity)) {
			out.write("    /**\n");
			out.write("     * Enable record\n");
			out.write("     */\n");
			out.write("    private boolean _enable = true;\n\n");
			out.write("    /**\n");
			out.write("     * Cas record\n");
			out.write("     */\n");
			out.write("    private long _cas = 0;\n\n");

			if (beEntity.isNeedTask()) {
				out.write("    /**\n");
				out.write("     * task id\n");
				out.write("     */\n");
				out.write("    private long _taskId;\n\n");
				out.write("    /**\n");
				out.write("     * session id\n");
				out.write("     */\n");
				out.write("    private String _sessionId;\n\n");

			}
		}

		if (beEntity.isNeedOrgId()) {
			out.write("    /**\n");
			out.write("     *  set orgId\n");
			out.write("     *  @parameter orgId.\n");
			out.write("     */\n");
			out.write("    private long orgId = 0;\n\n");
		}

		if (isSelfNeedHistory(beEntity)) {
			out.write("\n    /**\n");
			out.write("     * History version\n");
			out.write("     */\n");
			out.write("    protected int _version = 0;\n\n");
			out.write("    /**\n");
			out.write("     * History starttime\n");
			out.write("     */\n");
			out.write("    private java.util.Date _starttime = new java.util.Date();\n\n");
			out.write("    /**\n");
			out.write("     * History endtime\n");
			out.write("     */\n");
			out.write("    private java.util.Date _endtime = null;\n\n");
			out.write("    /**\n");
			out.write("     * History _optuserid\n");
			out.write("     */\n");
			out.write("    private long _optuserid = 0L;\n\n");
		}

		if (isSelfExtensible(beEntity)) {
			out.write("\n    /**\n");
			out.write("     *  BEExtension _extType\n");
			out.write("     */\n");
			out.write("    protected String _extType;\n\n");
			out.write("    /**\n");
			out.write("     *  BEExtension _extField\n");
			out.write("     */\n");
			out.write("    protected BEExtensionInfo _extField;\n");
			out.write("        ");
		}

		List<MemberType> members = beEntity.getMembers();
		for (MemberType member: members) {
			String description = member.getDescription();
			if (description == null) {
				description = "help is not available";
			}
			String attrName = member.getName();
			BEType attrType = member.getType();
			String attrTypeString = getDataTypeClassName(beEntity.isNeedPersist(), attrType);
			String attrInitString = member.getDefaultValue();
			String isTransient = member.isTransient() ? "transient " : "";

			out.write("\n   /**\n     *  ");
			out.print(description);
			out.write("\n     */    ");

			if (attrInitString != null) {
				out.write("\n    protected ");
				out.print(isTransient);
				out.print(attrTypeString);
				out.write(" ");
				out.print(attrName);
				out.write(" = ");
				out.print(attrInitString);
				out.write(";\n    ");
			} else if (attrType instanceof CEObjRefType) {
				out.write("\n    protected ");
				out.print(isTransient);
				out.print(attrTypeString);
				out.write(" ");
				out.print(attrName);
				out.write(" = ");
				out.print(attrTypeString);
				out.write(".NOT_SPECIFIED;\n    ");

				out.write("\n    protected int ");
				out.print(attrName);
				out.write("Int = ");
				out.print(attrTypeString);
				out.write(".NOT_SPECIFIED.getIntValue();\n    ");

			} else {
				out.write("\n    protected ");
				out.print(isTransient);
				out.print(attrTypeString);
				out.write(" ");
				out.print(attrName);
				out.write(";\n    ");
				if (member.getType().getClass() == BEListType.class
						&& ((BEListType)member.getType()).getElementType().getClass() == CEObjRefType.class) {
					out.write("\n    protected String ");
					out.print(attrName);
					out.write("IntValues = null;\n    ");
				}
			}
		}
	}

	private void generateEqualsMethod(BusinessEntityType businessEntity, PumpWriter out) {
		if (businessEntity.isNeedEquals()) {
			String implCls = getBEImplementClassName(businessEntity.getEntityName());

			out.write("\n    /**\n");
			out.write("     * Check different according to primary key.\n");
			out.write("     */\n");
			out.write("    public boolean equals(Object obj) {\n");
			out.write("        if (obj == this)\n");
			out.write("            return true;\n");
			out.write("        if (!(obj instanceof ");
			out.print(implCls);
			out.write("))\n            return false;\n        ");
			out.print(implCls);
			out.write(" o = (");
			out.print(implCls);
			out.write(")obj;\n        ");

			out.write("\n        boolean result = super.equals(obj);\n");
			out.write("\n        boolean eq = true;\n        ");

			out.write("\n        return result;\n");
			out.write("    }\n\n");
			out.write("    /**\n");
			out.write("     * Generate hashCode according to primary key.\n");
			out.write("     */\n");
			out.write("    public int hashCode() {\n        ");

			out.write("\n        int result = super.hashCode();\n");
			out.write("\n        return result;\n    }\n        ");

		}
	}

	private void generateToStringMethod(BusinessEntityType businessEntity, PumpWriter out) {

		out.write("\n     /**\n");
		out.write("     * Gets the String format of the business entity.\n");
		out.write("     *\n");
		out.write("     * @return String the business entity in String format.\n");
		out.write("     */\n");
		out.write("    public  String  toString() {\n");
		out.write("        JSONObject json = new JSONObject(this);\n");
		out.write("        return json.toString();\n    }\n    ");

	}

	private void generateToJsonMethod(BusinessEntityType businessEntity, PumpWriter out) {

		out.write("\n    /**\n");
		out.write("     *\n");
		out.write("     * @return JSONObject\n");
		out.write("     */\n");
		out.write("    public JSONObject toJSON() throws JSONException {\n");
		if (getParentBusinessEntityName(businessEntity) != null) {
			out.write("        JSONObject json = super.toJSON();\n        ");
		} else {
			out.write("        JSONObject json = new JSONObject();\n        ");
		}

		if (isSelfNeedPersist(businessEntity) || isSelfNeedHistory(businessEntity)) {
			out.write("\n        json.put(\"_enable\", this._enable);");
			out.write("\n        json.put(\"_cas\", this._cas);");
			if (businessEntity.isNeedTask()) {
				out.write("\n        json.put(\"_taskId\", this._taskId);");
				out.write("\n        if (this._sessionId != null) { json.put(\"_sessionId\", this._sessionId); }");
			}
		}
		if (businessEntity.isNeedOrgId()) {
			out.write("\n        json.put(\"orgId\", this.orgId); ");
		}

		List<MemberType> members = businessEntity.getMembers();
		for (MemberType member: members) {
			out.write("\n        json.put(\"");
			out.print(member.getName());
			out.write("\", ");
			if (member.getType().getClass() == BEObjRefType.class) {
				out.write(" \"\");\n        if(");
				out.print(member.getName());
				out.write(" != null) {");
				out.write("\n           json.put(\"");
				out.print(member.getName());
				out.write("\", ");
				out.print(member.getName());
				out.write(".toJSON());");
				out.write("\n        } else {");
				out.write("\n           json.remove(\"");
				out.print(member.getName());
				out.write("\");");
				out.write("\n        }");
			} else if (member.getType().getClass() == CEObjRefType.class) {
				out.print(member.getName());
				out.write(".getIntValue());");
			} else if (member.getType().getClass() == JavaObjRefType.class) {
				out.write(" \"\");\n        if(");
				out.print(member.getName());
				out.write(" != null) {");
				out.write("\n           json.put(\"");
				out.print(member.getName());
				out.write("\", ");
				out.write("org.shaolin.bmdp.utils.SerializeUtil.serializeData2((java.io.Serializable)");
				out.print(member.getName());
				out.write("));");
				out.write("\n        } else {");
				out.write("\n           json.remove(\"");
				out.print(member.getName());
				out.write("\");");
				out.write("\n        }");
			} else if (member.getType().getClass() == BEListType.class
						|| member.getType().getClass() == BEMapType.class
						|| member.getType().getClass() == BESetType.class) {
				BEType type = ((BECollectionType)member.getType()).getElementType();
				out.write(" \"\");\n        if(");
				out.print(member.getName());
				out.write(" != null) {");
				if (type instanceof CEObjRefType) {
					out.write("\n           json.put(\"");
					out.print(member.getName());
					out.write("\", CEUtil.convertInteger(");
					out.print(member.getName());
					out.write(");");
				} else {
					out.write("\n           json.put(\"");
					out.print(member.getName());
					out.write("\", new JSONArray(");
					out.print(member.getName());
					out.write("));");
				}
				out.write("\n        } else {");
				out.write("\n           json.remove(\"");
				out.print(member.getName());
				out.write("\");");
				out.write("\n        }");
			} else if (member.getType() instanceof DateTimeType
					|| member.getType() instanceof TimeType) {
				out.write(" \"\");\n        if(");
				out.print(member.getName());
				out.write(" != null) {");
				out.write("\n           json.put(\"");
				out.print(member.getName());
				out.write("\", ");
				out.print(member.getName());
				out.write(".getTime());");
				out.write("\n        } else {");
				out.write("\n           json.remove(\"");
				out.print(member.getName());
				out.write("\");");
				out.write("\n        }");
			} else {
				out.print(member.getName());
				out.write(");");
			}
		}
		out.write("\n        return json;\n    }\n    ");

	}

	private void generateFromJsonMethod(BusinessEntityType businessEntity, PumpWriter out) {

		out.write("\n    /**\n");
		out.write("     * Retrieves json object.\n");
		out.write("     */\n");
		out.write("    public void fromJSON(JSONObject json) throws JSONException {\n");
		if (getParentBusinessEntityName(businessEntity) != null) {
			out.write("        super.fromJSON(json);\n        ");
		}

		if (isSelfNeedPersist(businessEntity) || isSelfNeedHistory(businessEntity)) {
			out.write("\n        this._enable = json.getBoolean(\"_enable\");");
			out.write("\n        this._cas = json.getLong(\"_cas\");");
			if (businessEntity.isNeedTask()) {
				out.write("\n        this._taskId = json.getLong(\"_taskId\");");
				out.write("\n        if (json.has(\"_sessionId\")) { this._sessionId = json.getString(\"_sessionId\"); }");
			}
		}
		if (businessEntity.isNeedOrgId()) {
			out.write("\n        this.orgId = json.getLong(\"orgId\");");
		}

		List<MemberType> members = businessEntity.getMembers();
		for (MemberType member: members) {
			out.write("\n        this.");
			out.print(member.getName());
			out.write(" = ");
			if (member.getType().getClass() == BEObjRefType.class) {
				out.write(" null;");
				out.write("\n        if(json.has(\"");
				out.print(member.getName());
				out.write("\")) {");
				out.write("\n           this.");
				out.print(member.getName());
				out.write(" = ");
				TargetEntityType be = ((BEObjRefType) member.getType()).getTargetEntity();
				out.write("new ");
				out.print(be.getEntityName());
				out.write("Impl();");
				out.write("\n           this.");
				out.print(member.getName());
				out.write(".fromJSON(json.getJSONObject(\"");
				out.print(member.getName());
				out.write("\"));\n        }");

			} else if (member.getType().getClass() == CEObjRefType.class) {
				out.write("(");
				out.print(((CEObjRefType)member.getType()).getTargetEntity().getEntityName());
				out.write(")CEUtil.getConstantEntity(");
				out.print(((CEObjRefType)member.getType()).getTargetEntity().getEntityName());
				out.write(".ENTITY_NAME, json.getInt(\"");
				out.print(member.getName());
				out.write("\"));");
				out.write("\n        this.");
				out.print(member.getName());
				out.write("Int = json.getInt(\"");
				out.print(member.getName());
				out.write("\");");
			} else if (member.getType().getClass() == JavaObjRefType.class) {
				TargetJavaType targetJava = ((JavaObjRefType) member.getType())
						.getTargetJava();

				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? org.shaolin.bmdp.utils.SerializeUtil.readData2(json.getBytes(\"");
				out.print(member.getName());
				out.write("\"), "+targetJava.getName()+".class) : null;");
			} else if (member.getType().getClass() == BEListType.class
					|| member.getType().getClass() == BEMapType.class
					|| member.getType().getClass() == BESetType.class) {
				BEType type = ((BECollectionType)member.getType()).getElementType();
				if (type instanceof BEObjRefType) {
					BEObjRefType beType = (BEObjRefType)type;
					out.write("json.has(\"");
					out.print(member.getName());
					if (member.getType().getClass() == BEListType.class) {
						out.write("\") ? BEUtil.convertToList(");
					} else if (member.getType().getClass() == BESetType.class){
						out.write("\") ? BEUtil.convertToSet(");
					} else {
						out.write("\") ? BEUtil.convertToMap(");
					}
					out.print(BEUtil.getBEInterfaceClassName(beType.getTargetEntity().getEntityName()));
					out.write(".class, ");
					out.print(BEUtil.getBEImplementClassName(beType.getTargetEntity().getEntityName()));
					out.write(".class, json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof CEObjRefType) {
					CEObjRefType ceType = (CEObjRefType)type;
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? CEUtil.convertToList(");
					out.print(ceType.getTargetEntity().getEntityName());
					out.write(".class, \"");
					out.print(BEUtil.getBEInterfaceClassName(ceType.getTargetEntity().getEntityName()));
					out.write("\", json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof BooleanType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToBooleanList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof DateTimeType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToBooleanList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof TimeType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToBooleanList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof DoubleType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToDoubleList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof IntType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToIntegerList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof LongType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToLongList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else if (type instanceof StringType) {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? BEUtil.convertToStringList(json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\")) : null;");
				} else {
					out.write("json.has(\"");
					out.print(member.getName());
					out.write("\") ? json.getJSONArray(\"");
					out.print(member.getName());
					out.write("\") : null;");
				}
			} else if (member.getType().getClass() == BooleanType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? json.getBoolean(\"");
				out.print(member.getName());
				out.write("\") : false;");
			} else if (member.getType().getClass() == DateTimeType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? new java.util.Date(json.getLong(\"");
				out.print(member.getName());
				out.write("\")) : null;");
			} else if (member.getType().getClass() == TimeType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? new java.util.Date(json.getLong(\"");
				out.print(member.getName());
				out.write("\")) : null;");
			} else if (member.getType().getClass() == DoubleType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? json.getDouble(\"");
				out.print(member.getName());
				out.write("\") : 0.0d;");
			} else if (member.getType().getClass() == IntType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? json.getInt(\"");
				out.print(member.getName());
				out.write("\") : 0;");
			} else if (member.getType().getClass() == LongType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? json.getLong(\"");
				out.print(member.getName());
				out.write("\") : 0l;");
			} else if (member.getType().getClass() == BinaryType.class) {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? json.getBytes(\"");
				out.print(member.getName());
				out.write("\") : null;");
			} else {
				out.write("json.has(\"");
				out.print(member.getName());
				out.write("\") ? json.getString(\"");
				out.print(member.getName());
				out.write("\") : null;");
			}
		}
		out.write("\n       }\n    ");

	}

	private void generateGetMemberListMethod(BusinessEntityType businessEntity, PumpWriter out) {

		out.write("\n     /**\n");
		out.write("     * Gets list of MemberType.\n");
		out.write("     *\n");
		out.write("     * @return List     the list of MemberType.\n");
		out.write("     */\n");
		out.write("    public List<MemberType> getMemberList() {\n");
		out.write("        List<MemberType> memberTypeList = new ArrayList<MemberType>();\n        ");

		if (getParentBusinessEntityName(businessEntity) != null) {
			out.write("\n        List<MemberType> parentList = super.getMemberList();\n");
			out.write("        for(int i=0, n=parentList.size(); i<n; i++)\n");
			out.write("            memberTypeList.add(parentList.get(i));\n            ");
		}

		out.write("\n        MemberType member = null;\n        ");

		List<MemberType> members = businessEntity.getMembers();
		for (MemberType member: members) {
			String description = member.getDescription();
			BEType beType = member.getType();
			String beTypeVar = generateBEType(beType, member.getName(), out);

			out.write("\n        //MemberType Define for ");
			out.print(member.getName());
			out.write("\n        member = new MemberType();\n");
			out.write("        member.setName(\"");
			out.print(member.getName());
			out.write("\");\n        member.setDescription(\"");
			out.print(description);
			out.write("\");\n        member.setType(");
			out.print(beTypeVar);
			out.write(");\n        memberTypeList.add(member);\n            ");
		}
		out.write("\n        return memberTypeList;\n    }\n    ");

	}

	private String generateBEType(BEType beType, String name, PumpWriter out) {
		String beTypeVar = name + "BEType";

		out.write("\n        ");
		out.print(beType.getClass().getName());
		out.write(" ");
		out.print(beTypeVar);
		out.write(" = new ");
		out.print(beType.getClass().getName());
		out.write("();\n    ");

		if (beType instanceof BEComplexType) {
			if (beType instanceof BEObjRefType) {
				String targetEntityVar = name + "TargetEntity";
				TargetEntityType be = ((BEObjRefType) beType).getTargetEntity();
				if (be.getEntityName().indexOf('.') == -1) {
					be.setEntityName(bePackage + "." + be.getEntityName());
				}

				out.write("\n        TargetEntityType ");
				out.print(targetEntityVar);
				out.write(" = new TargetEntityType();\n        ");
				out.print(targetEntityVar);
				out.write(".setEntityName(\"");
				out.print(be.getEntityName());
				out.write("\");\n        ");
				out.print(beTypeVar);
				out.write(".setTargetEntity(");
				out.print(targetEntityVar);
				out.write(");\n            ");

			} else if (beType instanceof CEObjRefType) {
				String targetEntityVar = name + "TargetEntity";
				TargetEntityType ce = ((CEObjRefType) beType).getTargetEntity();
				if (ce.getEntityName().indexOf('.') == -1) {
					ce.setEntityName(cePackage + "." + ce.getEntityName());
				}

				out.write("\n        TargetEntityType ");
				out.print(targetEntityVar);
				out.write(" = new TargetEntityType();\n        ");
				out.print(beTypeVar);
				out.write(".setTargetEntity(");
				out.print(targetEntityVar);
				out.write(");\n        ");
				out.print(targetEntityVar);
				out.write(".setEntityName(\"");
				out.print(ce.getEntityName());
				out.write("\");\n            ");

			} else if (beType instanceof JavaObjRefType) {
				String targetJavaVar = name + "TargetJava";
				TargetJavaType targetJava = ((JavaObjRefType) beType)
						.getTargetJava();

				out.write("\n        TargetJavaType ");
				out.print(targetJavaVar);
				out.write(" = new TargetJavaType();\n        ");
				out.print(targetJavaVar);
				out.write(".setName(\"");
				out.print(targetJava.getName());
				out.write("\");\n        ");
				out.print(targetJavaVar);
				out.write(".setPackageName(\"");
				out.print(targetJava.getPackageName());
				out.write("\");\n        ");
				out.print(beTypeVar);
				out.write(".setTargetJava(");
				out.print(targetJavaVar);
				out.write(");\n            ");

			} else if (beType instanceof BESetType) {
				BEType elementBEType = ((BESetType) beType).getElementType();
				String elementBETypeVar = generateBEType(elementBEType, name
						+ "Element", out);

				out.write("\n        ");
				out.print(beTypeVar);
				out.write(".setElementType(");
				out.print(elementBETypeVar);
				out.write(");\n            ");

			} else if (beType instanceof BEListType) {
				BEType elementBEType = ((BEListType) beType).getElementType();
				String elementBETypeVar = generateBEType(elementBEType, name
						+ "Element", out);

				out.write("\n        ");
				out.print(beTypeVar);
				out.write(".setElementType(");
				out.print(elementBETypeVar);
				out.write(");\n            ");

			} else if (beType instanceof BEMapType) {
				BEType keyBEType = ((BEMapType) beType).getKeyType();
				String keyBETypeVar = generateBEType(keyBEType, name + "Key", out);
				BEType elementBEType = ((BEMapType) beType).getElementType();
				String elementBETypeVar = generateBEType(elementBEType, name
						+ "Element", out);

				out.write("\n        ");
				out.print(beTypeVar);
				out.write(".setKeyType(");
				out.print(keyBETypeVar);
				out.write(");\n        ");
				out.print(beTypeVar);
				out.write(".setElementType(");
				out.print(elementBETypeVar);
				out.write(");\n            ");
			}
		}
		return beTypeVar;
	}

	// ///////////////////////////Util
	// method////////////////////////////////////////////

	private String getBeanName(String attrName) {
		return Character.toUpperCase(attrName.charAt(0))
				+ attrName.substring(1);
	}

	static boolean isPersistentByBE(BusinessEntityType be, PersistenceTypeType rdbType) {
		for (PersistentConfigType pct : be.getPersistentConfigs()) {
			PersistenceTypeType pt = pct.getSupportedPersistenceType();
			if (pt == rdbType) {
				return true;
			}
		}
		return false;
	}

	static boolean isSelfNeedPersist(BusinessEntityType businessEntity) {
		return businessEntity.isNeedPersist();
	}

	static boolean isSelfNeedHistory(BusinessEntityType businessEntity) {
		return businessEntity.isNeedHistory();
	}

	static boolean isSelfExtensible(BusinessEntityType businessEntity) {
		return businessEntity.isExtensible();
	}

	private String getParentBusinessEntityName(BusinessEntityType businessEntity) {
		ObjectRefType parentObj = businessEntity.getParentObject();
		if (parentObj != null) {
			if (parentObj instanceof BEObjRefType) {
				return ((BEObjRefType) parentObj).getTargetEntity()
						.getEntityName();
			}
			/**
			String javaClass = getJavaClassName(((JavaObjRefType) parentObj)
					.getTargetJava());
			return javaClass;
			*/
		}
		return null;
	}

	static String getJavaClassName(TargetJavaType targetJava) {
		String className = targetJava.getName();
		String packageName = targetJava.getPackageName();
		return ClassUtil.getFullClassName(packageName, className);
	}

	private String getJavaFileName(File rootDir, String fullClassName) {
		return new File(rootDir, fullClassName.replace('.', File.separatorChar)
				+ ".java").getAbsolutePath();
	}

	static String getDataTypeClassName(boolean isPersistent, BEType dataType) {
		String typeClass = null;

		if (dataType instanceof BEPrimitiveType) {
			typeClass = (String) dataTypeToJavaTypeMap.get(dataType.getClass());
		} else if (dataType instanceof BEComplexType) {
			if (dataType instanceof BEObjRefType) {
				TargetEntityType be = ((BEObjRefType) dataType)
						.getTargetEntity();
				if (be != null) {
					//FIXED: due to hibernate engine needs the concrete class mapping.
					//the interface won't work for that mapping. so, we decide
					//always return the implementation class.
//					if (isPersistent) {
					typeClass = getBEImplementClassName(be.getEntityName());
//					} else {
//						typeClass = getBEInterfaceClassName(be.getEntityName());
//					}
				}
			} else if (dataType instanceof CEObjRefType) {
				TargetEntityType ce = ((CEObjRefType) dataType)
						.getTargetEntity();
				if (ce != null)
					typeClass = getConstantEntityClassName(ce.getEntityName());
			} else if (dataType instanceof JavaObjRefType) {
				TargetJavaType targetJava = ((JavaObjRefType) dataType)
						.getTargetJava();
				if (targetJava != null)
					typeClass = getJavaClassName(targetJava);
			} else if (dataType instanceof BESetType) {
				typeClass = "java.util.Set" +
						BEUtil.getGenericType(((BESetType)dataType).getElementType());
			} else if (dataType instanceof BEListType) {
				typeClass = "java.util.List" +
						BEUtil.getGenericType(((BEListType)dataType).getElementType());
			} else if (dataType instanceof BEMapType) {
				BEMapType beMapType = (BEMapType)dataType;
				typeClass = "java.util.Map" + BEUtil.getGenericTypes(beMapType.getKeyType(),
						 					 beMapType.getElementType());
			}
		}
		return typeClass;
	}

	static String getWrappedDataTypeClass(boolean isPersistent, BEType dataType) {
		String typeClass = null;
		if (dataType instanceof BooleanType) {
			typeClass = "Boolean";
		} else if (dataType instanceof IntType) {
			typeClass = "Integer";
		} else if (dataType instanceof LongType) {
			typeClass = "Long";
		} else if (dataType instanceof DoubleType) {
			typeClass = "Double";
		} else {
			typeClass = getDataTypeClassName(isPersistent, dataType);
		}
		return typeClass;
	}

	private String getWrapperDataTypeMethod(BEType dataType) {
		String valueMethod = "";
		if (dataType instanceof BooleanType) {
			valueMethod = ".booleanValue()";
		} else if (dataType instanceof IntType) {
			valueMethod = ".intValue()";
		} else if (dataType instanceof LongType) {
			valueMethod = ".longValue()";
		} else if (dataType instanceof DoubleType) {
			valueMethod = ".doubleValue()";
		}
		return valueMethod;
	}

	static String getWrapperDataTypeObject(BEType dataType, String value) {
		String wrapper = value;
		if (dataType instanceof BooleanType) {
			wrapper = value + " ? Boolean.TRUE : Boolean.FALSE";
			;
		} else if (dataType instanceof IntType) {
			wrapper = "new Integer(" + value + ")";
		} else if (dataType instanceof LongType) {
			wrapper = "new Long(" + value + ")";
		} else if (dataType instanceof DoubleType) {
			wrapper = "new Double(" + value + ")";
		}
		return wrapper;
	}

	private static String getBENameByImplementClassName(String implementClassName) {
		if (implementClassName.indexOf('.') == -1) {
			return bePackage + "." + implementClassName;
		}

		return implementClassName.substring(0, implementClassName.length()-4);
	}

	static String getBEInterfaceClassName(String beName) {
		if (beName.indexOf('.') == -1) {
			beName = bePackage + "." + beName;
		}
		String packageName = beName.substring(0, beName.lastIndexOf("."));
		String name = beName.substring(beName.lastIndexOf(".") + 1);
		return packageName + ".I" + name;
	}

	private static String getBEImplementClassName(String beName) {
		String clsName = beName + "Impl";
		return clsName;
	}

	static String getConstantEntityClassName(String ceName) {
		String clsName = ceName;
		return clsName;
	}

	private static String getVarWrapper(VariableType var) {
		return getWrapper(var.getName(), VariableUtil.getVariableClassName(var));
	}

	private static String getWrapper(String varName, String varType) {
		if ("int".equals(varType)) {
			return "new Integer(" + varName + ")";
		}
		if ("long".equals(varType)) {
			return "new Long(" + varName + ")";
		}
		if ("boolean".equals(varType)) {
			return varName + " ? Boolean.TRUE : Boolean.FALSE";
		}
		if ("double".equals(varType)) {
			return "new Double(" + varName + ")";
		}
		if ("char".equals(varType)) {
			return "new Character(" + varName + ")";
		}
		if ("float".equals(varType)) {
			return "new Float(" + varName + ")";
		}
		if ("short".equals(varType)) {
			return "new Short(" + varName + ")";
		}
		if ("byte".equals(varType)) {
			return "new Byte(" + varName + ")";
		}
		return varName;
	}

	private static String fieldToString(MemberType field) {
		String fieldName = field.getName();
		BEType fieldType = field.getType();
		if (fieldType instanceof BEPrimitiveType
				|| fieldType instanceof CEObjRefType) {
			return fieldName;
		}
		if (fieldType instanceof BEObjRefType) {
			return fieldName + "==null? \"\" : " + fieldName + ".toString()";
		}
		return null;
	}

	private void createI18NProperties(String projectRoot, StringBuffer keys) {
		File resourcePath = new File(projectRoot + "/src/main/resources");
		if (!resourcePath.exists()) {
			resourcePath.mkdirs();
		}

		File resource_en = new File(resourcePath, "i18n_en_US.properties");
		File resource_zh = new File(resourcePath, "i18n_zh_CN.properties");

	}

}


text:
import unittest
from satistjenesten import io
import numpy
import datetime

class TestIoMitiff(unittest.TestCase):

    def setUp(self):
        mitiff_file_path = 'test_data/avhrr-swath.mitiff'
        mitiff = io.MitiffScene(filepath=mitiff_file_path)
        mitiff.load()
        self.mitiff = mitiff

    def tearDown(self):
        del self.mitiff

    def test_load_NumpyArray(self):
        self.mitiff.load()
        bands = self.mitiff.bands
        numpy_band = bands.values()[0].data
        self.assertIsInstance(numpy_band, numpy.ndarray)

    def test_parse_MitiffTags(self):
        self.mitiff.load()
        self.mitiff.get_mitiff_tags()
        self.assertIsNotNone(self.mitiff.tags_dict['satellite'])
        self.assertIsNotNone(self.mitiff.tags_dict['timestamp'])
        self.assertIsNotNone(self.mitiff.tags_dict['x0'])
        self.assertIsNotNone(self.mitiff.tags_dict['y0'])
        self.assertIsNotNone(self.mitiff.tags_dict['xsize'])
        self.assertIsNotNone(self.mitiff.tags_dict['ysize'])
        self.assertIsNotNone(self.mitiff.tags_dict['x_px_size'])
        self.assertIsNotNone(self.mitiff.tags_dict['y_px_size'])

    def test_get_AreaDef_from_MitiffTags(self):
        self.mitiff.load()
        self.mitiff.get_mitiff_tags()
        self.mitiff.get_area_def()
        self.assertIsNotNone(self.mitiff.area_def)

    def test_get_timestamp(self):
        self.mitiff.get_mitiff_tags()
        self.mitiff.get_timestamp()
        self.assertIsInstance(self.mitiff.timestamp, datetime.datetime)

class TestIoNetcdf(unittest.TestCase):
    def setUp(self):
        netcdf_filepath = 'test_data/amsr2.nc'
        netcdf_scene = io.NetcdfScene(filepath=netcdf_filepath, bands=['lat_h'])
        self.netcdf = netcdf_scene
        self.netcdf.load()

    def test_Load_DefinedBands(self):
        self.assertIsNotNone(self.netcdf.bands)

redpajama_set_name: RedPajamaGithub


text:
Quick Start
===========

Install
-------

The recommended installation method is `pip <http://pip.readthedocs.org/>`_.::

    $ pip install pyweaving

You can also download a source package here `directly from the Python Package Index <https://pypi.python.org/pypi/pyweaving>`_.

PyWeaving can be used via the command line or Python code. Generating a new
draft from scratch will generally require writing Python code.

Open a Draft
------------

Lots of great drafts are available in WIF format. A huge repository is `Handweaving.net <http://handweaving.net/>`_. To open a .wif file as an image, do::

    $ pyweaving render draft.wif

To open a draft from Python, do::

    from pyweaving import WIFReader

    draft = WIFReader('draft.wif').read()


text:
*  Filename MUST be `trips.txt`
 *  File MUST contain a record for every transit vehicle trip (i.e. the Muni 14 Local Outbound that leaves at 8:02 AM)
 *  File MUST be a valid CSV file.
 *  The first line of each file MUST contain case-sensitive field names.
 *  Field names MUST NOT contain tabs, carriage returns or new lines.

File MUST contain the following attributes:

Required Attributes	| Description
----------			| -------------
`trip_id`			| ID that uniquely identifies a vehicle trip
`route_id`			| ID that uniquely identifies a route
`service_id`		| ID that uniquely identifies set of dates when service is available from calendar or calendar dates files.

File MAY contain the following attributes:

Optional Attributes		| Description
----------				| -------------
`trip_headsign`			| Text that appears on the vehicle headsign to identify destination to passengers.
`trip_short_name`		| Text that appears in schedules and sign boards.
`block_id`				| Two or more sequential trips made using same vehicle where passenger can transfer by staying on same vehicle. `block_id` must be referenced by two or more trips in trips.txt.
`shape_id`				| Defines shape for the trip from [`shapes.txt`](shapes.md) file.
`wheelchair_accessible`	| Is this transit vehicle trip wheelchair accessible:
 *0 - no accessibility info*
 *1 - vehicle on this trip can accommodate at least one rider in a wheelchair*
 *2 - no riders in wheelchairs can be accommodated on this trip*
`bikes_allowed`			| Does this transit vehicle trip bike allow bikes:
 *0 - no bike accessibility info*
 *1 - vehicle on this trip can accommodate at least one bicycle*
 *2 - no bicycles can be accommodated on this trip*
`direction_id`			| ID that contains a binary value that indicates the direction of the trip:
 *0 - travel in one direction*
*1 - travel in opposite direction*


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<title>MIME::compose()</title>

MIME :: array compose ( [ string text [, string html [, array attach [, integer unique [, string line_end ]]]]] )

Return ARRAY ('header' => string value, 'content' => string value).

Notice: Text or Html version of message must be set.

Default values are:
integer unique: 0
string line_end: CRLF [\r\n]

Example:

// set text/plain version of message
$text = MIME::message('Text version of message.', 'text/plain');
// set text/html version of message
$html = MIME::message('<b>HTML</b> version of <u>message</u>.', 'text/html');
// add attachment with name 'file.txt'
$at[] = MIME::message('source file', 'text/plain', 'file.txt', 'iso-8859-1', 'base64', 'attachment');

// compose mail message in MIME format
$mess = MIME::compose($text, $html, $at);

// print result
print_r($mess);

See Also: MIME::message()

[ Comments ]

Last update: Thursday, August 16, 2007


text:
import os
import sys
from io import StringIO
from textwrap import dedent

from django.conf import settings
from django.core.management.base import CommandError, no_translations
from django.core.management.commands import makemigrations, showmigrations

class Command(makemigrations.Command):

    LOCK_PATH = os.path.join(settings.BASE_DIR, "migrations.lock")
    LOCK_PREAMBLE = dedent("""\
        # This file is autogenerated every time Django migrations are written
        # by the `makemigrations` management command.
        # You can also update it to match current migrations by executing:
        #
        # ./manage.py makemigrations --lock-update
        #
        # The commcare-hq automated tests require that the contents of this file
        # match the current Django migrations list. If that check fails on a
        # GitHub PR, the PR will not be eligible for merging. You can check if
        # the current state of this file will pass automated tests by executing:
        #
        # ./manage.py makemigrations --lock-check
        #
        # Although integrated into the Django `makemigrations` utility, this
        # file is not part of the Django ecosystem. It is a migration safety
        # feature added by commcare-hq.
        # See: ./hqscripts/management/commands/makemigrations.py
        #
    """)

    def add_arguments(self, parser):
        super().add_arguments(parser)
        parser.add_argument(
            "--lock-path", metavar="FILE", default=self.LOCK_PATH,
            help="Read/write lock file %(metavar)s (default=%(default)s).",
        )
        parser.add_argument(
            "--lock-check", action="store_true",
            help="Exit with a non-zero status if the lock file is inconsistent.",
        )
        parser.add_argument(
            "--lock-update", action="store_true",
            help="Write a new (updated) lock file and exit.",
        )

    @no_translations
    def handle(self, *app_labels, **options):

        def assert_exclusive_options(opt_name, extra=[]):
            prevent = extra + ["dry_run", "merge", "empty", "name", "check_changes"]
            enforce = ["interactive", "include_header"]  # default=True
            if app_labels or any(options[k] for k in prevent) or not all(options[k] for k in enforce):
                raise CommandError(f"{opt_name} does not support other options besides --lock-path")

        self.lock_path = options["lock_path"]
        if options["lock_check"]:
            assert_exclusive_options("--lock-check", ["lock_update"])
            if not self.check_migrations_lock():
                self.stderr.write("Migrations lock file does not match migrations list.")
                sys.exit(1)
            self.stdout.write("Migrations lock file is up-to-date.")
        elif options["lock_update"]:
            assert_exclusive_options("--lock-update", ["lock_check"])
            self.write_migrations_lock()
        else:
            super().handle(*app_labels, **options)

    def write_migration_files(self, changes):
        super().write_migration_files(changes)
        self.write_migrations_lock()

    def get_migrations_list(self, preamble=LOCK_PREAMBLE):
        """Generate and return the full list of existing migrations.

        :param preamble: String which will become the first line(s) of the
                         returned migration list.
        """
        stream = StringIO()
        command = showmigrations.Command(stdout=stream, no_color=True)
        # Use `run_from_argv()` to avoid extra command setup boilerplate.
        # First two argv items are `prog` and `subcommand`, used to setup the
        # command's argument parser, leaving them empty because it works.
        command.run_from_argv(["", "", "--list"])
        stream.seek(0)
        lines = preamble.splitlines(keepends=True)
        # strip the applied status off the front of migration lines
        for line in stream:
            if line[:5] in {" [ ] ", " [X] "}:
                line = line[4:]  # leave a leading space
            lines.append(line)
        return lines

    def write_migrations_lock(self):
        """Write a new migrations.lock file."""
        with open(self.lock_path, "w") as file:
            file.write("".join(self.get_migrations_list()))

    def check_migrations_lock(self):
        """Check if the current migrations list matches the migrations.lock."""
        with open(self.lock_path, "r") as file:
            frozen = list(file)
        current = self.get_migrations_list()
        return frozen == current


text:
package gov.nih.nci.ncicb.cadsr.loader.ui;

import gov.nih.nci.ncicb.cadsr.domain.*;
import gov.nih.nci.ncicb.cadsr.loader.event.*;

import gov.nih.nci.ncicb.cadsr.loader.ext.CadsrModule;
import gov.nih.nci.ncicb.cadsr.loader.ui.event.NavigationEvent;
import gov.nih.nci.ncicb.cadsr.loader.ui.event.NavigationListener;
import gov.nih.nci.ncicb.cadsr.loader.ui.tree.*;
import gov.nih.nci.ncicb.cadsr.loader.ui.util.UIUtil;

import gov.nih.nci.ncicb.cadsr.loader.util.*;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;

import java.util.*;
import javax.swing.*;
import java.awt.*;

public class UMLElementViewPanel extends JPanel
  implements Editable, NodeViewPanel {

  private ConceptEditorPanel conceptEditorPanel;
  private DEPanel dePanel;
  private OCPanel ocPanel;
  private ButtonPanel buttonPanel;
  private GMEViewPanel gmePanel;
  private DescriptionPanel dsp;

  //TODO uncomment to enable concept inheritance feature
  //private ExcludeFromSemanticInheritancePanel excludeSemPanel;
  private UMLNode node;

  private InfoPanel cannotMapVMInfoPanel;

  private JPanel cardPanel;

  private JPanel displayedPanel;

  static final String DE_PANEL_KEY = "dePanel",
    OC_PANEL_KEY = "ocPanel",
    CONCEPT_PANEL_KEY = "conceptPanel",
    CANNOT_MAP_VM_KEY = "cannotMapVm";

  private Map<String, JPanel> panelKeyMap = new HashMap<String, JPanel>();

  public UMLElementViewPanel(UMLNode node)
  {
    this.node = node;
    conceptEditorPanel = new ConceptEditorPanel(node);
    dePanel = new DEPanel(node);
    ocPanel = new OCPanel(node);
    gmePanel= new GMEViewPanel(node);
    dsp = new DescriptionPanel(node);
    // TODO uncomment to enable concept inheritance feature
    //excludeSemPanel = new ExcludeFromSemanticInheritancePanel(node);

    cannotMapVMInfoPanel = new InfoPanel();
    cannotMapVMInfoPanel.setOutputText("This Permissible Value cannot be modified because the Value Domain where it is included is mapped to a caDSR Value Domain");

    if(node instanceof AttributeNode){
      buttonPanel = new ButtonPanel(conceptEditorPanel, this, dePanel);}
    else if(node instanceof ValueMeaningNode)
    {
	buttonPanel = new ButtonPanel(conceptEditorPanel, this, null);
    }
    else
    {
	buttonPanel = new ButtonPanel(conceptEditorPanel, this, ocPanel);
    }

    if (conceptEditorPanel != null) { conceptEditorPanel.addPropertyChangeListener(buttonPanel); }
    if (dePanel != null) { dePanel.addPropertyChangeListener(buttonPanel); }
    if (ocPanel != null) { ocPanel.addPropertyChangeListener(buttonPanel); }
    if (gmePanel != null) { gmePanel.addPropertyChangeListener(buttonPanel); }
    if (dsp != null) { dsp.addPropertyChangeListener(buttonPanel); }
    // TODO uncomment to enable concept inheritance feature
    //excludeSemPanel.addPropertyChangeListener(buttonPanel);

    cardPanel = new JPanel();
    initUI();
  }

  private void initUI() {

    conceptEditorPanel.initUI();

    cardPanel.setLayout(new CardLayout());
    cardPanel.add(conceptEditorPanel, CONCEPT_PANEL_KEY);
    cardPanel.add(dePanel, DE_PANEL_KEY);
    cardPanel.add(ocPanel, OC_PANEL_KEY);
    cardPanel.add(cannotMapVMInfoPanel, CANNOT_MAP_VM_KEY);

    panelKeyMap.put(CONCEPT_PANEL_KEY, conceptEditorPanel);
    panelKeyMap.put(DE_PANEL_KEY, dePanel);
    panelKeyMap.put(OC_PANEL_KEY, ocPanel);

    setLayout(new BorderLayout());

    JPanel newPanel = new JPanel();
    newPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    JLabel space = new JLabel("      ");
    newPanel.add(space);
    newPanel.add(buttonPanel);

    JPanel editPanel = new JPanel();
    editPanel.setLayout(new GridBagLayout());

    UserPreferences prefs = UserPreferences.getInstance();
    if(prefs.getUmlDescriptionOrder().equals("first"))
      UIUtil.insertInBag(editPanel, dsp.getDescriptionPanel(), 0, 0);
    else
      UIUtil.insertInBag(editPanel, dsp.getDescriptionPanel(), 0, 3);

    UIUtil.insertInBag(editPanel, cardPanel, 0, 1);
    UIUtil.insertInBag(editPanel, gmePanel, 0, 2);

    // TODO uncomment to enable concept inheritance feature
    //UIUtil.insertInBag(editPanel, excludeSemPanel, 0, 3);

    JScrollPane scrollPane = new JScrollPane(editPanel);
    scrollPane.getVerticalScrollBar().setUnitIncrement(30);

    this.add(scrollPane, BorderLayout.CENTER);
    this.add(newPanel, BorderLayout.SOUTH);
  }

  public void setEnabled(boolean enabled) {
    buttonPanel.setEnabled(enabled);
    conceptEditorPanel.setEnabled(enabled);
    dePanel.setEnabled(enabled);
  }

  public void switchCards(String key)
  {
    CardLayout layout = (CardLayout)cardPanel.getLayout();

    if(displayedPanel instanceof ConceptEditorPanel) {
      conceptEditorPanel.setExpanded(false);
    }

    layout.show(cardPanel, key);
    displayedPanel = panelKeyMap.get(key);

    if(displayedPanel instanceof ConceptEditorPanel) {
      conceptEditorPanel.setExpanded(true);
    }

  }

  public void updateNode(UMLNode node)
  {

    this.node = node;
    buttonPanel.setVisible(true);
    // is UMLNode a de?
    Object o = node.getUserObject();
    if(o instanceof DataElement) { //if it is, does it have pubID
      DataElement de = (DataElement)o;
      if(!StringUtil.isEmpty(de.getPublicId()))
      {
        switchCards(DE_PANEL_KEY);
      } else {
        switchCards(CONCEPT_PANEL_KEY);
      }
    } else if(o instanceof ObjectClass) {
      ObjectClass oc = (ObjectClass)o;
      if(!StringUtil.isEmpty(oc.getPublicId()))
      {
        switchCards(OC_PANEL_KEY);
      }
      else
      {
        switchCards(CONCEPT_PANEL_KEY);
      }
    } else if (o instanceof ValueMeaning) {
      ValueMeaningNode vmNode = (ValueMeaningNode)node;
      AlternateName fullName = DomainObjectFactory.newAlternateName();
      fullName.setType(AlternateName.TYPE_FULL_NAME);
      fullName.setName(vmNode.getVdName());

      if(StringUtil.isEmpty(LookupUtil.lookupValueDomain(fullName).getPublicId()))  {
        switchCards(CONCEPT_PANEL_KEY);
      } else {
        switchCards(CANNOT_MAP_VM_KEY);
        buttonPanel.setVisible(false);
      }
    }

    conceptEditorPanel.updateNode(node);
    dePanel.updateNode(node);
    ocPanel.updateNode(node);
    gmePanel.updateNode(node);

 // TODO uncomment to enable concept inheritance feature
//    excludeSemPanel.updateNode(node);

    if(node instanceof AttributeNode)
      buttonPanel.setEditablePanel(dePanel);
    else if (node instanceof ValueMeaningNode)
      buttonPanel.setEditablePanel(null);
    else
      buttonPanel.setEditablePanel(ocPanel);

    buttonPanel.propertyChange
      (new PropertyChangeEvent(this, ButtonPanel.SETUP, null, true));

    buttonPanel.update();

  }

//  public boolean isReviewed()
//  {
//    return ((ReviewableUMLNode)node).isReviewed();
//  }

  public void apply(boolean value) throws ApplyException
  {
    conceptEditorPanel.apply(value);
  }

  public void navigate(NavigationEvent evt) {
    buttonPanel.navigate(evt);
  }

  public void addReviewListener(ReviewListener listener) {
    buttonPanel.addReviewListener(listener);
  }

  public void addNavigationListener(NavigationListener listener)
  {
    buttonPanel.addNavigationListener(listener);
  }

  public void addElementChangeListener(ElementChangeListener listener) {
    conceptEditorPanel.addElementChangeListener(listener);
    dePanel.addElementChangeListener(listener);
    dsp.addElementChangeListener(listener);

 // TODO uncomment to enable concept inheritance feature
//    excludeSemPanel.addElementChangeListener(listener);
  }

  public void addPropertyChangeListener(PropertyChangeListener l) {

	// TODO uncomment to enable concept inheritance feature
//    excludeSemPanel.addPropertyChangeListener(l);
    if (dsp != null) { dsp.addPropertyChangeListener(l); }
    if (conceptEditorPanel != null) { conceptEditorPanel.addPropertyChangeListener(l); }
    if (buttonPanel != null) { buttonPanel.addPropertyChangeListener(l); }
    if (dePanel != null) { dePanel.addPropertyChangeListener(l); }
    if (ocPanel != null) { ocPanel.addPropertyChangeListener(l); }
  }

  public void applyPressed() throws ApplyException
  {
    if(displayedPanel instanceof Editable)
    {
     ((Editable)displayedPanel).applyPressed();
    }
    dsp.applyPressed();

 // TODO uncomment to enable concept inheritance feature
//    excludeSemPanel.applyPressed();
  }

  public ConceptEditorPanel getConceptEditorPanel() {
    return conceptEditorPanel;
  }

  public void setCadsrModule(CadsrModule cadsrModule) {
    dePanel.setCadsrModule(cadsrModule);
    ocPanel.setCadsrModule(cadsrModule);
  }

}


text:
package com.blog.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

import com.blog.library.JsonReader;
import com.blog.library.Locators;
import com.blog.library.ResourceType;

public class LoginPage extends Page{

	private String FileName = "LoginPageObj.json";
	private JsonReader jsonReader = JsonReader.getInstance();
	String filePath=this.getResourcesPath(LoginPage.class, ResourceType.OBJECTREPOSITORY+"/");
	private By usrName= null;
	private By usrPass=null;
	private By submitLogin=null;
	private By backToBlog=null;

	public LoginPage(){
		jsonReader.setJsonFile(filePath+FileName);
		usrName= this.getElementLocator(jsonReader.getJsonValue("UserName").get(Locators.LOCATOR.toString()),
				jsonReader.getJsonValue("UserName").get(Locators.LOCATORVALUE.toString()));

		usrPass= this.getElementLocator(jsonReader.getJsonValue("UserPass").get(Locators.LOCATOR.toString()),
				jsonReader.getJsonValue("UserPass").get(Locators.LOCATORVALUE.toString()));

		submitLogin= this.getElementLocator(jsonReader.getJsonValue("LoginSubmit").get(Locators.LOCATOR.toString()),
				jsonReader.getJsonValue("LoginSubmit").get(Locators.LOCATORVALUE.toString()));

		backToBlog= this.getElementLocator(jsonReader.getJsonValue("BackToBlog").get(Locators.LOCATOR.toString()),
				jsonReader.getJsonValue("BackToBlog").get(Locators.LOCATORVALUE.toString()));
	}

	private static class LoginPageInstance {
		public static final LoginPage INSTANCE = new LoginPage();
	}

	public static LoginPage getInstance() {

		return LoginPageInstance.INSTANCE;
	}

	public void EnterLoginDetails(String userName,String userPass){
		this.Type(usrName, userName);
		this.Type(usrPass, userPass);
	}

	public DashboardPage SubmitLogin(){
		this.Click(submitLogin);
		return new DashboardPage();
	}

	public HomePage NavigateToHomePage(){
		this.Click(backToBlog);
		return HomePage.getInstance();
	}

}


text:
/*global Backbone, BackboneProxy, _, QUnit, test, ok */
(function () {
  'use strict';

  QUnit.module('.off() by callback', {
    setup: function () {},
  });

  var

    proxied, proxy, proxy2, proxyProxy, models, targetModel, otherModel,

    setup = function (tM, oM) {
      var Proxy, ProxyProxy;

      proxied    = new Backbone.Model({ name: 'Anna' });
      Proxy      = BackboneProxy.extend(proxied);

      proxy      = new Proxy();
      proxy2     = new Proxy();
      ProxyProxy = BackboneProxy.extend(proxy);

      proxyProxy = new ProxyProxy();

      models = {
        proxied: proxied,
        proxy: proxy,
        proxy2: proxy2,
        proxyProxy: proxyProxy
      };

      tM && (targetModel = models[tM]);
      oM && (otherModel  = models[oM]);
    },

    s = function (tM, oM, expect) {
      return function () {
        setup(tM, oM);
        expect();
      };
    };

  _(['proxied', 'proxy', 'proxy2', 'proxyProxy']).each(function (tM) {

    _(['proxied', 'proxy', 'proxy2', 'proxyProxy']).each(function (oM) {

      // Registering listener on some model - removing from another (different) model
      if (tM !== oM) {

        test(tM + '.off(null, callback) should not remove change:attr-event-listener registered on ' + oM, 1, s(tM, oM, function () {
          var callback = function () {
              ok(true);
            };
          otherModel.on('change:name', callback);
          targetModel.off(null, callback);

          targetModel.set({ name: 'Betty' }); // or otherModel.set - should make no difference
        }));

      }

    }); // for every other-model in ['proxied', 'proxy', 'proxy2', 'proxyProxy']

    test(tM + '.off(null, callback) should remove change:attr-event-listener registered on ' + tM, 0, s(tM, null, function () {
      var callback = function () {
          ok(false, 'change:name listener on ' + tM + ' should not be invoked');
        };
      targetModel.on('change:name', callback);
      targetModel.off(null, callback);

      targetModel.set({ name: 'Betty' });
    }));

  }); // for every target-model in ['proxied', 'proxy', 'proxy2', 'proxyProxy']

}());


text:
package com.firstlight.wallet;

import java.util.HashMap;
import java.util.List;

import javafx.beans.property.ReadOnlyBooleanProperty;

import com.firstlight.service.IWalletService;

/**
 * @author MrMoneyChanger
 *
 */
public interface IWallet {

	Class<? extends IWalletService> getWalletServiceClass();

	String getName();
	void setName(String newName);

	String getHashCode();
	void setHashCode(String newHashCode);

	String getLocation();
	void setLocation(String newLocation);

	WalletState getWalletState();
	void setWalletState(WalletState state);

	WalletState openWallet();
	WalletState closeWallet();
	HashMap<String, IWallet> getListOfKnownWallets();

	List<IAssetAccount> getAssetAccounts();
	void setAssetAccounts(List<IAssetAccount> assetAccounts);

	Boolean getWalletStateChanged();
	ReadOnlyBooleanProperty walletStateChangedProperty();
	void indicateWalletStateChangeStarted();
	void indicateWalletStateChangeCompleted();

}