• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
EOGenerator template wrapping EOUtilities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EOGenerator template wrapping EOUtilities


  • Subject: EOGenerator template wrapping EOUtilities
  • From: Greg <email@hidden>
  • Date: Fri, 23 Sep 2005 14:16:30 +1000

I have been doing a post-mortem of my current development cycle and have been looking at ways to increase the readability of the code in my components. One of the things I have noticed is that I use EOUtilities quite a lot and always cast the returned EO. I decided to modify my EOGenerator template to wrap most of the EOUtilities methods so that you don't have to cast anymore.

I has to modify eogenerator by adding a new string method lastLetter to improve the grammar of the generated method names. This is for checking if an identifier ends with an 's' as to whether or not put an 's' or 'es' on method names. If you don't want to modify eogenerator you can easily remove the parts <$if classNameWithoutPackage.lowercaseString.lastLetter eq 's'$>es<$else $>s<$endif$>

I thought I would share my code as so many others on here do the same. I wished I had done this at the start of my project, but like a lot of others I was a newbie, so I made my code more readable. If people want my complete template just let me know and I will send it on to you.

Regards,
Greg


/* EOUtilities casted methods */

public static <$GEN_PREFIX$><$classNameWithoutPackage$> < $classNameWithoutPackage.initialLowercaseString$>MatchingKeyAndValue (EOEditingContext ec, String key, Object value) {
<$className$> matchingObject = null;
try {
matchingObject = (<$className$>) EOUtilities.objectMatchingKeyAndValue(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, key, value);
} catch (EOObjectNotAvailableException ex) {
if (log.isDebugEnabled()) log.debug("Could not Find < $classNameWithoutPackage$> matching " + key + " = " + value);
} catch (EOUtilities.MoreThanOneException mto) {
if (log.isDebugEnabled()) log.debug("Found more than one <$classNameWithoutPackage$> matching " + key + " = " + value);
}
return matchingObject;
}


public static NSArray < $classNameWithoutPackage.initialLowercaseString$><$if classNameWithoutPackage.lowercaseString.lastLetter eq 's'$>es<$else $>s<$endif$>MatchingKeyAndValue(EOEditingContext ec, String key, Object value) {
return EOUtilities.objectsMatchingKeyAndValue(ec, < $GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME, key, value);
}


public static NSArray all< $classNameWithoutPackage.initialCapitalString$><$if classNameWithoutPackage.lowercaseString.lastLetter eq 's'$>es<$else $>s<$endif$>(EOEditingContext ec) {
return EOUtilities.objectsForEntityNamed(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME);
}


public <$GEN_PREFIX$><$classNameWithoutPackage$> localInstance (EOEditingContext ec) {
return (<$GEN_PREFIX$><$classNameWithoutPackage$>) EOUtilities.localInstanceOfObject(ec, this);
}


public static <$GEN_PREFIX$><$classNameWithoutPackage$> < $classNameWithoutPackage.initialLowercaseString$>MatchingValues (EOEditingContext ec, NSDictionary values) {
<$className$> matchingObject = null;
try {
matchingObject = (<$className$>) EOUtilities.objectMatchingValues(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, values);
} catch (EOObjectNotAvailableException ex) {
if (log.isDebugEnabled()) log.debug("Could not Find < $classNameWithoutPackage$> matching: " + values);
} catch (EOUtilities.MoreThanOneException mto) {
if (log.isDebugEnabled()) log.debug("Found more than one <$classNameWithoutPackage$> matching: " + values);
}
return matchingObject;
}


public static NSArray < $classNameWithoutPackage.initialLowercaseString$><$if classNameWithoutPackage.lowercaseString.lastLetter eq 's'$>es<$else $>s<$endif$>MatchingValues(EOEditingContext ec, NSDictionary values) {
return EOUtilities.objectsMatchingValues(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, values);
}


public static <$GEN_PREFIX$><$classNameWithoutPackage$> < $classNameWithoutPackage.initialLowercaseString$>FromRawRow (EOEditingContext ec, NSDictionary row) {
return (<$GEN_PREFIX$><$classNameWithoutPackage$>) EOUtilities.objectFromRawRow(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, row);
}


public static <$GEN_PREFIX$><$classNameWithoutPackage$> < $classNameWithoutPackage.initialLowercaseString$>WithQualifierFormat (EOEditingContext ec, String format, NSArray args) {
<$className$> matchingObject = null;
try {
matchingObject = (<$className$>) EOUtilities.objectWithQualifierFormat(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, format, args);
} catch (EOObjectNotAvailableException ex) {
if (log.isDebugEnabled()) log.debug("Could not Find < $classNameWithoutPackage$> matching: " + format);
} catch (EOUtilities.MoreThanOneException mto) {
if (log.isDebugEnabled()) log.debug("Found more than one <$classNameWithoutPackage$> matching: " + format);
}
return matchingObject;
}


public static NSArray < $classNameWithoutPackage.initialLowercaseString$><$if classNameWithoutPackage.lowercaseString.lastLetter eq 's'$>es<$else $>s<$endif$>MatchingValues(EOEditingContext ec, String format, NSArray args) {
return EOUtilities.objectsWithQualifierFormat(ec, < $GEN_PREFIX$><$classNameWithoutPackage$>.ENTITY_NAME, format, args);
}


public static <$GEN_PREFIX$><$classNameWithoutPackage$> < $classNameWithoutPackage.initialLowercaseString$>WithPrimaryKey (EOEditingContext ec, NSDictionary pk) {
return (<$GEN_PREFIX$><$classNameWithoutPackage$>) EOUtilities.objectFromRawRow(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, pk);
}


public static <$GEN_PREFIX$><$classNameWithoutPackage$> < $classNameWithoutPackage.initialLowercaseString$>WithPrimaryKeyValue (EOEditingContext ec, Object value) {
return (<$GEN_PREFIX$><$classNameWithoutPackage$>) EOUtilities.objectWithPrimaryKeyValue(ec, <$GEN_PREFIX$>< $classNameWithoutPackage$>.ENTITY_NAME, value);
}


public EOQualifier qualifier() {
return EOUtilities.qualifierForEnterpriseObject (editingContext(), this);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: qualifierWithQualifierFormat
  • Next by Date: Re: XHTML generation
  • Previous by thread: Re: qualifierWithQualifierFormat
  • Next by thread: Example WebObjects project to make graphs
  • Index(es):
    • Date
    • Thread