Dashboard > WOProject / WOLips > ... > EOGenerator Templates and Additions > JBND Client-Side _Entity.java Template
  WOProject / WOLips Log In View a printable version of the current page.  
  JBND Client-Side _Entity.java Template
Added by David Avendasora, last edited by Florijan Stamenkovic on Jul 31, 2008  (view change)
Labels: 
(None)

This template requires the JBND library or source code be included on the Client-Side of the application. NSArray is not parameterized so if you want to use it with 5.4, slight modifications might be beneficial.

// <$GEN_PREFIX$><$classNameWithoutPackage$>.java
// 
// Created by eogenerator
//
// DO NOT EDIT.  Make changes to <$classNameWithoutPackage$>.java instead.
//
// This EO was generated to perform standard JBND behaviors
//	1. All setter methods will not set new values if they are identical to old values.
//	2. All setter methods invoke EOFDataObject.fireDataObjectEvent(String key, Object oldValue).
//	3. All attribute and relationship keys are stored as static final Strings.
//	4. A default constructor is provided to automatically call the superclass constructor
//	that accepts an EOClassDescription argument, used to avoid bugs in the client side EOF.

#if ($entity.superclassPackageName)
package $entity.superclassPackageName;
#end

import com.webobjects.foundation.*;
import com.webobjects.eocontrol.*;
import java.math.BigDecimal;
import java.util.*;
import org.jbnd.support.Utilities;
import org.jbnd.eof.EOFDataObject;
import org.jbnd.event.DataObjectEvent;

/**
 * DO NOT EDIT!
 */
@SuppressWarnings("all")
public abstract class ${entity.prefixClassNameWithoutPackage} extends #if ($entity.parentSet)${entity.parent.classNameWithDefault}#elseif ($EOGenericRecord)${EOGenericRecord}#else EOFDataObject#end {

	/** Entity name */
	public static final String ENTITY_NAME = "$entity.name";

	/** Attribute keys */
	#foreach ($attribute in $entity.sortedClientClassAttributes)
	public static final String ${attribute.uppercaseUnderscoreName}_KEY = "$attribute.name";
	#end

	/** To-one relationship keys */
	#foreach ($relationship in $entity.sortedClientClassRelationships)
	public static final String ${relationship.uppercaseUnderscoreName}_KEY = "$relationship.name";
	#end


	/**
	 * Constructor. Creates an EO with the <tt>EOClassDescription</tt> of the
	 * relevant entity, to ensure a proper client side behavior.
	 */
	public ${entity.prefixClassNameWithoutPackage}() {
		super(EOClassDescription.classDescriptionForEntityName("$entity.name"));
	}

#foreach ($attribute in $entity.sortedClientClassAttributes)
#if (!$attribute.inherited)
	public $attribute.javaClassName ${attribute.name}() {
		return ($attribute.javaClassName)storedValueForKey(${attribute.uppercaseUnderscoreName}_KEY);
	}

	public void set${attribute.capitalizedName}($attribute.javaClassName aValue) {
		// extract old value
		$attribute.javaClassName oldValue = ${attribute.name}();
		
		// do not perform EOF work unless values are different
		if(Utilities.equals(oldValue, aValue)) return;

		takeStoredValueForKey(aValue, ${attribute.uppercaseUnderscoreName}_KEY);
		fireDataObjectEvent(${attribute.uppercaseUnderscoreName}_KEY, oldValue, DataObjectEvent.ATTRIBUTE_CHANGE);
	}
#end
#end

#foreach ($relationship in $entity.sortedClientClassToOneRelationships)
#if (!$relationship.inherited) 
	public $relationship.actualDestination.classNameWithDefault ${relationship.name}() {
		return ($relationship.actualDestination.classNameWithDefault)storedValueForKey(${relationship.uppercaseUnderscoreName}_KEY);
	}

	public void set${relationship.capitalizedName}($relationship.actualDestination.classNameWithDefault aValue) {
		// get old value
		$relationship.actualDestination.classNameWithDefault oldValue = ${relationship.name}();

		// do not perform EOF work unless values are different
		if(Utilities.equals(oldValue, aValue)) return;

		takeStoredValueForKey(aValue, ${relationship.uppercaseUnderscoreName}_KEY);
		fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, oldValue, DataObjectEvent.TO_ONE_CHANGE);
	}
#end
#end

#foreach ($relationship in $entity.sortedClientClassToManyRelationships)
#if (!$relationship.inherited) 
	public NSArray ${relationship.name}() {
		return (NSArray)storedValueForKey(${relationship.uppercaseUnderscoreName}_KEY);
	}

	public void set${relationship.capitalizedName}(NSArray aValue) {
		Object oldValue = ${relationship.name}().clone();
		takeStoredValueForKey(aValue, ${relationship.uppercaseUnderscoreName}_KEY);
		fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, oldValue, DataObjectEvent.TO_MANY_CHANGE);
	}

	public void addTo${relationship.capitalizedName}(${relationship.actualDestination.classNameWithDefault} object) {
		if(${relationship.name}().contains(object)) return;
		includeObjectIntoPropertyWithKey(object, ${relationship.uppercaseUnderscoreName}_KEY);
		fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, object, DataObjectEvent.TO_MANY_ADD);
	}

	public void removeFrom${relationship.capitalizedName}(${relationship.actualDestination.classNameWithDefault} object) {
		if(!${relationship.name}().contains(object)) return;
		excludeObjectFromPropertyWithKey(object, ${relationship.uppercaseUnderscoreName}_KEY);
		fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, object, DataObjectEvent.TO_MANY_REMOVE);
	}
#end
#end
}

Site running on a free Atlassian Confluence Open Source Project License granted to ObjectStyle. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators