ObjectUtil doesnt deep copy correctly

I am using an ObjectProxy for a complex object containing
arrays of objects. I bind a datagrid to the array and . notation to
fields. This all works fine, datagrid behaiving properly, inserts
and deletes working properly.
I want to have an undo function that will put the objectproxy
object back to its original state. So when i open the screen with
the datagrid I do a ObjectUtil.copy() and use this latter if the
user wants to revert changes. The problem is that the copy doesn't
do a deep copy. In the Object is an ArrayCollection of userdefined
objects. These objects instead of being copied as their type are
being copied as plain objects.
The serialize meathod the copy uses doesn't retain the types
of user defined objects.
Will I have to create clone or copy methods for every object
type I have?
If so do I just need to make them ezxternalizable? How will
the objectutil copy pick up these methods?
Thanks,
Jeff

Unfortunatlly you will need to implement it for every class
that has complex objects, as it does not know how to deal with
them. Your classes need to extend EventDispatcher and/or implement
IExternalizable.
Then create methods writeExternal and readExternal for every
local variables you need to retain. eg..
public function writeExternal(output:IDataOutput):void {
output.writeUTF(msgString);
output.writeObject(anyObject);
output.writeInt(id);
public function readExternal(input:IDataInput):void {
msgString = input.readUTF()as String;
anyObject = input.readObject()as Array;
id = input.readInt() as int;
}

Similar Messages

  • Deep copy of String

    As String is called by reference, how can I perform deep copy?
    Anything similar to System.arraycopy for String?

    That's funny, this works for me:
    String k = "kkkkkkkk";
    String m = k;
    Now, when I change 'k' (f.i. k = k.substring(0, 2); )
    'm' does not change.
    So that's a deep copy!
    ;JOOP!No - it's not a deep copy. Your statement k = k.substring(0, 2) does not change the string that was referenced by k previously, but changes the k variable itself so that it references a new string.
    It's really important to get a handle on the difference between objects
    on the one hand, and references to them on the other. Without that understanding you have little hope of writing correct and efficient Java programs.
    Sylvia.

  • TRYING TO REGISTER MY MACBOOK PRO THAT I HAVE PURCHASED TODAY, THE REGISTRATION SYSTEM DOESNT APPROVE MY CORRECT PRODUCT SERIAL NUMBER (WHICH I PROPERLY CONTROLLED ON BOX AND ON INVOICE)

    TRYING TO REGISTER MY MACBOOK PRO THAT I HAVE PURCHASED TODAY, THE REGISTRATION SYSTEM DOESNT APPROVE MY CORRECT PRODUCT SERIAL NUMBER (WHICH I PROPERLY CONTROLLED ON BOX AND ON INVOICE)

    Where did you buy the machine? An Apple store, an authorized reseller, or ??
    Also, what is the model/identifier? Is it the latest or was it purchased used?

  • Hello After upgrading iPhoto 9.1.2 when you synchronize the iphone / iphoto ipad events are not copied correctly (this option checked all the photos on itunes).

    Hello
    After upgrading iPhoto 9.1.2 when you synchronize the iphone / iphoto ipad events are not copied correctly (this option checked all the photos on itunes).

    I found this other thread discussing this topic, no fix, I will revert to 9.1.1 from Time Machine and wait for a new update.
    https://discussions.apple.com/thread/3023160?

  • Transfered files from Mac Pro to iMac OS10.7. Copied bookmarks using "backup and restore" from "Organize bookmarks". File copied correctly as bookmarks 10-10-11.jsom, but would not restore on new iMac.

    Transfered files from Mac Pro to iMac OS10.7. Copied bookmarks using "backup and restore" from "Organize bookmarks". File copied correctly as bookmarks 10-10-11.jsom, but would not restore on Firefox on new iMac.

    Firefox 2 versions use the file bookmarks.html to store the bookmarks.
    See http://kb.mozillazine.org/Backing_up_and_restoring_bookmarks_-_Firefox
    See also http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox
    With Mac OS X 10.4 you can use Firefox 3.5 or 3.6
    * http://www.mozilla.com/firefox/all.html
    * http://www.mozilla.com/firefox/all-older.html
    *http://www.mozilla.com/en-US/firefox/system-requirements.html
    *http://www.mozilla.com/firefox/system-requirements-v3.html

  • Shipping instructions not copying correctly from sto to delivery

    hi ,
    i am facing issue like shipping instructions from STO header are not getting copied correctly to delivery , what may be the problem , please help.
    regards,
    veeru.

    how is the text copied from STO to delivery in your system?
    there are a some alternative options, which need to be implemented before a text copies from STO to a delivery.
    However, if it is not an error in a routine developed by an ABAPer (reading text from the wrong STO), then a text certainly does not exchange its content when getting copied.
    Maybe you should check whether the text is maintained in the customer master and does default from there instead of coming from the STO.

  • Creating a deep copy

    I wrote a stack implementation using a LinkedList, I have null constructor to create the first stack and it works fine but now i have to create a copy for a second stack using the element of the first constructor
    this my code
    import java.util.LinkedList;
    public class Stack<T>{
      private LinkedList<T> stack;
      public Stack(){
        stack =  new LinkedList<T>();
      public Stack(Stack<T> s) {// the problem is here it compile but when i run
                                                     // the program the second stack raised an exception because is empty
                                                     // i want to create a deep copy with the elements of the first stack
         stack = new LinkedList<T>();
      public boolean isEmpty(){
      return stack.isEmpty();
      public void push(T item){
       /*method to add object information
        *pre the object is not full
        * pos: the object is inserted
          stack.addFirst(item);
      public T top() throws EmptyStackException{
        if (!stack.isEmpty()){ 
          return stack.getFirst();
        else{
          throw new EmptyStackException("StackException on top " + " Stack empty");
      public T pop() throws EmptyStackException{
        /*method to remove an element of the stack
        *pre the object is not empty
        * pos: the object is remove
        * response throws an exception
        if (!stack.isEmpty()){ 
          return stack.removeFirst();
        else{
          throw new EmptyStackException("StackException on top" + "stack empty");
    public int numElements(){
        return stack.size();
    public void clear(){
      stack.clear();
    public class EmptyStackException extends Exception{
            public EmptyStackException( String message){
              super(message);
    }

    wel well... are you doing this on a mobile phone???
    neways to get to ur question u can use the clone() method to generate a clone of your object which is the same as a deep copy for eg:
    public class CloneTest{
        CloneTest test1 = new CloneTest();
        CloneTest test2;
        CloneTest(){
          //Some initialization code;
        CloneTest(CloneTest temp){
             test2 = test1.clone();
    }clone is a method of the object class.

  • Some items doesnt get copied with header partner

    Hi ,
    I have a issue with an order, where when teh order header partners are redetermined, (ship to), some of the items on the order doesnt get copied with the new ship to.
    There is a check box at the item partner screen which is been ticked only for the items where thsi change doesnt take place.
    It indicates that 'Partner valid at item level, if this indicator has been activated, the partner is valid at item level.'.
    Could someone please advice the reason as to whta the check box means as well as the reason as to why the header partner doesnt get copied to the line item partner.
    Thanks,
    Keshini

    Hi,
    Read OSS  Note 550073 - FAQ: SD Partner Determination I, points 1 and 2.
    The description from the note is,
    1. Question: Why is a new partner determination not executed when I change the partner ?
    Answer: The partner determination always runs when you create a document. Then dependent partners are automatically determined and checked. If in the existing document you change a partner, the system does not run a redetermination of the partners (except when the sold-to party is changed). This works as designed and possible dependent partners are not redetermined.
    2. Question: Does the partner determination take place on item level ?
    Answer: An item partner determination is not provided in the standard system. You can enter item partners manually. Here, in Customizing of the item partners you can specify which partner functions should be allowed on item level and which not. The header partner functions are always allowed on item level. On item level, if you enter a partner, it is visualized by the item partner flag. For an item partner you can change the address data, header partner addresses cannot be changed on item level. The logic of the item partners is: If for an item there is no partner, the header partners are displayed. If as described above you enter a partner on item level, this partner exists on item level. If for a partner you enter an address differing from the header but the partner should stay the same, you can just enter the partner again manually for the respective item. Thus the partner becomes an item partner and the address can be changed.
    Regards,

  • Help with a deep copy

    What is the best practice for sending doing a deep copy between two View Controllers in an iPhone app. I've designed an app that sends over arrays of arrays and the deeper items aren't coming over as easily as I thought. Do you explicitly copy? Just alloc placeholders and set them equal? Links to any samples would be greatly appreciated.
    Is it a best practice to avoid that kind of data passing - as being overly complex?
    Background:
    I'm building an iPhone application where I need to send a complex object from one view controller to another - This complex object is an array of arrays of objects.
    I can't just copy a reference to the complex object over to a variable on the receiving view controller, as none of the nested array contents come over.
    So I think I need to do a deep copy - but need advice on best practices for that. The array of arrays contain objects, so ideally, Id just be able to :
    Thanks for any advice!

    There are many ways of solving this.
    One way is to centralize the information:
    You create a singleton class that is the datasource for both view, so you don't need to pass in anything. If you can't do that because the datasources are generally different except for this specific array of arrays, then make the singleton class be the source of that array and nothing else.

  • Clarification regarding deep cloning/deep copy

    Hi,
    While performing deep copy of an object should all the subobject that the parent object constitute also constitute the clone method.
    For Eg:
    I have a class called Document and a class called Field. Document constitutes of List<Field> fields. Field class has a String fieldName as its member variable.
    I need to perform a deep copy of Document object. Should Field class also implement the clone method or can I create field objects in the documents clone method and fill these fields with values from the existing field list to form a new Document with these new fields.
    Or do I call clone() method on each field to get a new field object and
    add it to the new Document object that I am creating in the clone() method .
    //First approach
    public Document clone(){
    Document doc = new Document();
    List<Field> fields = doc.getFields()
    Field newField = null;
    for(Field f: fields){
        newField = new Field();
        newField.setName(f.getName());
       doc.addField(newField);
    return doc;
    //Second Approach
    public Document clone(){
    Document doc = new Document();
    List<Field> fields = doc.getFields()
    Field newField = null;
    for(Field f: fields){
        newField = f.clone()
       doc.addField(newField);
    return doc;
    }Please let me know which is a better approach and the standard coding
    practise.
    Thanks

    the second method is better, because it lets you the possibility to create a subclass of Field with a specific clone method, integrate some instances in a Document object; without changing the Document.clone method.

  • Deep Copy

    Hi all,
    I have a question I can't find any documentation about, not on google, not here on the forums. We are developping a EJB J2EE application (with glassfish) with flex as the view. We are using BlazeDS to interchange objects back and forth between flex and java.
    The problem we are having is we have to do a deep copy of an object tree, but blaze by default copies shallow.
    The setup is like this:
    We generated the actionscript classes that represent the java classes on the client side with a code generator named Gas3 (the only one out there, no?). This generator created classes with RemoteClass and Bindable annotations already in place. Gas3 also implemented the IExternalizable interface but we threw that out because it gave us problems in java. We have our EJB services configured in the remoting-config.xml file and everything works except for deep copy so I don't think there is anything missing, no?
    Is somebody aware of a way we can achieve a deep copy? I imagine there would be an xml tag or attribute that would allow for this ...
    Any help would be greatly appreciated!
    Thank you,
    Bruno Windels
    3S

    Or is it creating a deep copy of each element in the Array and placing them into a new array object?

  • Routine doesnt get copied

    Hi
    we have a cube on which there are update rules. Now created a new cube same as the old one and copied update rules from the old cube update rules. After copying the update rules, i deleted few keyfigures from the new cube and activated. So update rules gets deactivated. When i try to activate the update rule, it says there is error in the routine.
    Here my question is when i copied the update rules to the new cube, the routine which is under
    $$ begin of routine - insert your code only below this line        -*
    fill the internal table "MONITOR", to make monitor entries*
    Doesnt get copied to the new update rule..Why is it?
    REgards
    Annie

    Hi Annie,
    Every update rules are exclusive used by the infoprovider to where it attached. Now, you can do copying the structure of a particular cube or infoprovider. Then, in update rules you can also copy the same code manually and once you'd like to remove infoobjects with it, you need to make it sure that it was not included in your routine or no mapping has been defined on your update rules.
    You could find lot of materials here in SDN to understand more.
    Godbless,
    nips

  • How to deep copy a component configuration?

    Hi Experts,
    I want to deep copy a component configuration named EHHSS_RAS_OIF.
    But following was the error shown.
    Can you please help/guide to do the same.
    Thanks in advance.
    Sanket.

    Hi Sanket,
    I think you might be copying the config in Unit test client but not in Development client.
    Thanks
    KH

  • Shallow copying and Deep copying ???

    hi,
    what is meant by shallow copying and deep copying in context to clone() method found in Object class?
    thanks,
    swapnaja

    swapnaja wrote:
    Shallow copying: only cloneable object is copied but any object references within that object would not be copied but would rather be shared.
    Deep copying: cloneable object along with any object references contained within that object will also be copied.
    Am i right?Yep; when you want to make a deep copy you have to watch out for circular references, i.e. if you have made a copy of an object already you shouldn't make another one during the deep copying process; (see how the ObjectOutputStream does things).
    kind regards,
    Jos

  • Shadow copy vs deep copy

    hi,
    any body tell me what is the difference between shadow copy and deep copy of a object.

    would you tell me any prectical example of this. i
    mean when i should use shallow copy and when i should
    use deep copy of object.I'm hoping someone else will step in here, because in my OO thinking, there's seldom a need for copying an object at all.
    One practical example, though: Say you're copying a list of objects. After the copy, you want to alter the objects in the copied list, but you don't want the objects in the original list altered. In this case, you need a deep copy. Had you only done a shallow copy, both lists would have referred to the same objects, and therefore, any change in an object would be visible through both lists.
    clone() method makes shallow copy or deep copy.You'd have to consult the doc for the class you are cloning. For example, the doc for LinkedList.clone() says "Returns a shallow copy of this LinkedList."

Maybe you are looking for