[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ganymede Dev] Sensitive Invid Field

Date Thu, 01 May 2003 00:26:11 +0000
From "John King" <the_king17@hotmail.com>

There you go! I've got it. It's so simple I couldn't come up with it unless 
having it held under my nose :)



>| >If you look at the method signature for DBEditObject.finalizeSetValue(),
>| >you'll see that it is defined as
>| >
>| >  public ReturnVal finalizeSetValue(DBField field, Object value)
>|
>| field is in this case PARENT, value doesn't matter because I want the
>| current value of ZONE, which is either something or null.
>
>The current value of ZONE?  So you're saying you want the code called
>by your finalizeSetValue() method to be able to determine the value of
>ZONE from before the time that the PARENT field's value was changed?
>
>I'm confused.

Ok I have to admit I wasn't really clear: This code makes up the DName for 
this domain out of the zone and the DName of the parent. So it has to know 
the this zone, and upon change of this parent invid it should get the dname 
of the parentobject.
But this zone has to exist. This parent invid too. So I pass it the 
knowledge PARENT was changed and what the zone is, assuming it's set already 
in the easy case.
What I should do is pass the Invid value of finalizeSetValue too and use 
that as reference to the parent DName instead of current invid of PARENT.



>
>| >in this case, value will be the new Invid to be set into that field.
>| >If you do a getFieldValue() or something like that on an
>| >InvidDBField() between the time that finalizeSetValue() is called and
>| >the time that finalizeSetValue() is returned, you'll always see the
>| >old value of the Invid field.
>|
>| like I thought. So at
>| 		try{
>| 		    parentDName =
>| ((StringDBField)getFieldInTarget(PARENT,DNAME)).getValueString();
>| 		}
>
>getFieldInTarget()?

shortcut:
maybe a long one? I composed it quickly.

public Object getFieldInTarget(short thisInvidField, short 
requestedFieldID){

		//declare variables
		db_field requestedField;

		try{
			//get the reference to our target object
			Invid targetInvid = (Invid) getFieldValueLocal(thisInvidField);
			if(targetInvid==null){
				Ganymede.debug("getFieldInTarget("+thisInvidField+","+requestedFieldID+"): 
target reference could not be obtained");
				return null;
			}
			// get the target object itself
			DBObject targetObject = getSession().viewDBObject(targetInvid);
			if(targetObject==null){
				Ganymede.debug("getFieldInTarget("+thisInvidField+","+requestedFieldID+"): 
target object could not be obtained");
				return null;
	    	}
			//get the level field of the parent
	    	requestedField = targetObject.getField(requestedFieldID);
	    	if(requestedField==null){
	    
		Ganymede.debug("getFieldInTarget("+thisInvidField+","+requestedFieldID+"): 
target field could not be obtained");
				return null;
			}
		}
		catch(ClassCastException ex){
			throw new RuntimeException("Error while trying to cast in Invid field 
"+ex.getMessage());
		}
		return requestedField;
	}



>
>| the current value isn't finalized yet. And so I read the previous value..
>
>Well, values aren't finalized.. changes to fields are finalized.  So
>in this case, since you are still in the middle of finalizeSetValue(),
>the change to the PARENT field hasn't been finalized yet, and if you
>try to get the value of the PARENT field, you'll see the old value.
>
>If you want to get the new value that has been submitted for placement
>into the PARENT field, you'll need to use
>
>    (Invid) value
>
>where value is the Object passed in as the second parameter of
>finalizeSetValue().
>

Excuse me for saying value's are finalized :) I meant of course the fields 
are finalized.




>| >The whole point of finalizeSetValue() and the other finalize methods
>| >is that if your finalize methods don't return a successful ReturnVal
>| >or null, the change that you are being notified for will not actually
>| >be performed.
>| >
>| >Does this make sense?
>|
>| yes it does. But can I finalize this Invid manually? Or is there some 
>other
>| way to retreive the object referenced to in the yet unfinalized Invid?
>
>Again, you don't finalize an Invid, you finalize a change to a
>field.. finalizeSetValue() is called to finalize the act of putting a
>new value into a scalar field.
>
>If you want to retrieve an object based on the proposed new Invid
>value, you can do something like the following:
>
>   public ReturnVal finalizeSetValue(DBField field, Object value)
>   {
>      if (field.getID() != PARENT)
>        {
>           return null;
>        }
>
>      // we'll use the DBSession viewDBObject() method here rather than
>      // the GanymedeSession view_db_object() method, since we're not
>      // going to ever provide otherObject to a remote client.. the
>      // DBSession viewDBObject() method is more efficient and doesn't
>      // require us to unpack and case the DBObject reference from the
>      // ReturnVal getObject() method
>
>      DBObject otherObject = this.getSession().viewDBObject((Invid) value);
>
>      // now we can look at the otherObject to see if it is appropriate to
>      // link to..
>
>      if (otherObject != null && otherObject.isSet(ABOOLEANFIELDTOTEST))
>        {
>          return null;
>        }
>      else
>        {
>          return Ganymede.createErrorDialog("Error, can't link to that 
>object",
>                                            "I can't link to that object, 
>it doesn't" +
>                                            "have field ABOOLEANFIELDTOTEST 
>set");
>        }
>   }
>
>Something like that, using the proposed new value passed in to
>finalizeSetValue().

hmmm I reall yneed to clean up my own code yours looks better :)


Well you helped me out again.


Thanks,

Regards,

Jan Bonne Aans
DTO, TU Delft
The Netherlands


_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail


----------------------------------------------------------------------------
To make changes to your subscription to the Ganymede Dev mailing list, send
mail to majordomo@arlut.utexas.edu.

To unsubcribe, include the line

unsubscribe ganymede-dev

in the body of your mail message

Visit the Ganymede web page at http://www.arlut.utexas.edu/gash2

----------------------------------------------------------------------------