WebObjects 4.5.1: Putting Custom Attribute Class in Separate Java Package from Enterprise Object Class

This article explains how to put a Custom Attribute Class in a Separate Java Package from the Enterprise Object (EO) Class.

When using Java in a WebObjects application, successfully getting a custom attribute type working when the custom attribute class is in the Enterprise Object's package can be tricky.

There are times when a WebObjects programmer may find it useful to build a custom attribute type in a custom attribute class. This is not very difficult and directions can be found in the WebObjects 4.5 'EOF Developer's Guide'; 'Modeling Complex Attributes' Chapter; 'Custom Data Types' Section, which is located at:

http://developer.apple.com/techpubs/webobjects/System/Documentation/Developer/EnterpriseObjects/DevGuide/EOsII1.html#311

The difficulties arise because the Java language provides for Packages, which can be used to group related objects or interfaces, and can provide a means of name space protection. Getting custom attribute types to work can be tricky if the custom attribute class is not in the same package as the Enterprise Object class.

There are four things you must do to get this to work properly in Java:


Example

Here is an example (the rest of the class is constructors and setters and getters and so forth):

// EOF valueFactoryMethodName

public static PhoneNumber objectWithArchiveData(String str) {

System.out.println("factory Here...");

PhoneNumber phone = new PhoneNumber(str);

return phone;

}

// EOF adaptorValueConversionMethodName

public String archiveData() {

return _wholePhone;

}

// EOF bug workaround

public Object clone() {

System.out.println("clone Here...");

return this;

}

Here is the relevant snippet from the EO:

{

adaptorValueConversionMethodName = archiveData;

allowsNull = Y;

columnName = PHONE;

externalType = CHAR;

factoryMethodArgumentType = EOFactoryMethodArgumentIsNSString;

name = phone;

valueClassName = PhoneNumber;

valueFactoryMethodName = "objectWithArchiveData:";

width = 10;

},

Published Date: Feb 18, 2012