Re: Object Oriented Subclassing Question
Re: Object Oriented Subclassing Question
- Subject: Re: Object Oriented Subclassing Question
- From: James Cicenia <email@hidden>
- Date: Sat, 6 Mar 2004 14:27:12 -0600
On Mar 6, 2004, at 1:32 PM, Chuck Hill wrote:
> Two thoughts, without seeing the rest of the class:
see class at bottom
>
> 1. Perhaps those ought to be bindings?
how can they be bindings?Each list will have their
own item type and list. I would like to understand this part
better.
-James
>
> 2. Public ivars are sort of OK with WOComponents *provided that* you
> only
> reference them in the WOD file and never in code.
> Otherwise, for
> sub-classing and code referenced abstract the concept:
>
> private PortfolioRole newItem;
>
> public PortfolioRole newItem() {return newItem; }
> public void setNewItem(PortfolioRole newRole) { newItem = newRole; }
>
> The sub-classes can override the implemention of these methods without
> affecting the abstract concept of the newItem of the component.
> Likely you
> will also want to use a less specific class than PortfolioRole such as
> Role
> or just plain old Object.
>
>
// Generated by the WOLips Core at Fri Mar 05 20:55:24 CST 2004
import com.webobjects.appserver.*;
import com.webobjects.eoaccess.*;
import com.webobjects.eocontrol.*;
import com.webobjects.foundation.*;
import eo.*;
public class EditPortfolioLists extends WOComponent {
/** @TypeInfo eo.PortfolioRole */
public PortfolioRole newItem;
public PortfolioRole theItem;
public String QUERY_DELETE_VALUE = "rosterMembers.role.value";
public String QUERY_OBJECT = "PortfolioRole";
public NSMutableArray theList;
public String feedback;
protected static String DUPLICATE_MSG = "That entry has already
been entered.";
protected static String BEING_USED_MSG = "You must first delete all
project roster members with that entry first.";
protected static String NO_ENTRY_MSG = "Please enter a value.";
protected static String WAS_DELETED_MSG = " was successfully deleted.";
public EditPortfolioLists(WOContext context) {
super(context);
newItem = new PortfolioRole();
//newItem.setValue("");
}
public WOComponent deleteItem() {
try{
EOFetchSpecification fetchSpec;
EOEditingContext ec = session().defaultEditingContext();
Portfolio portfolio = ((Session)session()).portfolio();
EOQualifier qual1;
NSMutableArray args = new NSMutableArray();
args.addObject(QUERY_DELETE_VALUE);
args.addObject(theItem.value());
qual1 = EOQualifier.qualifierWithQualifierFormat("%@ = %@", args);
EOQualifier qual2;
NSMutableArray args2 = new NSMutableArray();
args2.addObject("portfolio");
args2.addObject(portfolio);
qual2 = EOQualifier.qualifierWithQualifierFormat("%@ = %@", args);
EOAndQualifier andQual =
new EOAndQualifier(
new NSArray(new Object[] { qual1, qual2 }));
fetchSpec = new
EOFetchSpecification("PortfolioProject",andQual,null);
NSMutableArray rosterList = (NSMutableArray)
ec.objectsWithFetchSpecification(fetchSpec);
if (rosterList.count() == 0) {
session().defaultEditingContext().deleteObject(theItem);
session().defaultEditingContext().saveChanges();
feedback = theItem.value()+WAS_DELETED_MSG;
}else{
feedback = BEING_USED_MSG;
}
} catch (EOObjectNotAvailableException e2) {
session().defaultEditingContext().deleteObject(theItem);
session().defaultEditingContext().saveChanges();
feedback = theItem.value()+WAS_DELETED_MSG;
}
return null;
}
public WOComponent addItem() {
if(newItem.value()!=null && !newItem.value().equals("")){
//First Search for Duplicate
EOFetchSpecification fetchSpec;
EOEditingContext ec = session().defaultEditingContext();
EOQualifier qual1;
NSMutableArray args = new NSMutableArray();
args.addObject("portfolio");
args.addObject(((Session)session()).portfolio());
qual1 = EOQualifier.qualifierWithQualifierFormat("%@ = %@", args);
EOKeyValueQualifier qual2 = new EOKeyValueQualifier("value",
EOQualifier.QualifierOperatorCaseInsensitiveLike, newItem.value());
EOAndQualifier andQual =
new EOAndQualifier(
new NSArray(new Object[] { qual1, qual2 }));
fetchSpec = new EOFetchSpecification(QUERY_OBJECT,andQual,null);
theList = (NSMutableArray)
ec.objectsWithFetchSpecification(fetchSpec);
if(theList == null || theList.count() == 0){
newItem.setAddUser(((Session)session()).user());
newItem.setModUser(((Session)session()).user());
newItem.setPortfolio(((Session)session()).portfolio());
session().defaultEditingContext().insertObject(newItem);
session().defaultEditingContext().saveChanges();
}else{
feedback = DUPLICATE_MSG;
}
}else{
feedback = NO_ENTRY_MSG;
}
return null;
}
public void appendToResponse(WOResponse response, WOContext
context){
EOFetchSpecification fetchSpec;
EOEditingContext ec = session().defaultEditingContext();
EOQualifier myQualifier;
NSMutableArray args = new NSMutableArray();
args.addObject("portfolio");
args.addObject(((Session)session()).portfolio());
myQualifier = EOQualifier.qualifierWithQualifierFormat("%@ = %@",
args);
fetchSpec = new
EOFetchSpecification(QUERY_OBJECT,myQualifier,null);
theList = (NSMutableArray)
ec.objectsWithFetchSpecification(fetchSpec);
super.appendToResponse(response,context);
}
}
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.