How to clone a user-defined object?

Hello,
I need to clone an Object[] array (propArray) that holds objects of Integer, Double, Boolean type, along with objects of user-defined ClassA, ClassB, ClassC type. The matter is that the ClassA object isn't being cloned, while the rest of the user-defined objects are cloned just fine.
In more detail, ClassA has two properties:
public class ClassA implements Cloneable{
   private String penaltyFor;
   private Penalty[] penaltyArray;
   protected Object clone(){
      try{
         ClassA o = (ClassA)super.clone();
         o.penaltyFor = this.penaltyFor;
//         o.penaltyArray = (Penalty[])penaltyArray.clone();  //This ain't working.
         //But neither does this :(.
         int penCount = this.penaltyArray.length;
         o.penaltyArray = new Penalty[penCount];
         for(int i = 0; i < penCount; i++)
            o.penaltyArray[i] = (Penalty)this.penaltyArray.clone();
return o;
} catch(CloneNotSupportedException e){ throw new InternalError(); }
The Penalty class contains properties of primitive type and here is its clone() method:
public class Penalty implements Cloneable{
   private String penaltyDesc;
   private int lowLimit, upperLimit, penaltyValue;
   protected Object clone(){
      try{
         Penalty o = (Penalty)super.clone();
         o.penaltyDesc = this.penaltyDesc;
         o.lowLimit = this.lowLimit;
         o.upperLimit = this.upperLimit;
         o.penaltyValue = this.penaltyValue;
         return o;
      } catch(CloneNotSupportedException e){ throw new InternalError(); }
   }I don't know what else to try. I suppose the problem is the Penalty[] array, but I may be wrong. An alternative would be to use Copy Constructors, but it will cause too many changes to the code, since the clone() method is used for the propArray copy in many places and the ClassA object is a late addition to the propArray (unfortunately it wasn't planned to exist from the beginning).
Thank's.

class ClassA implements Cloneable{
   private String penaltyFor;
   private Penalty[] penaltyArray;
   public Object clone(){
      try{
         ClassA o = (ClassA) super.clone();
         if (penaltyArray!=null){
            o.penaltyArray = (Penalty[]) penaltyArray.clone();
            for(int i = 0; i < penaltyArray.length; i++) {
                Penalty penalty = this.penaltyArray;
if (penalty!=null)
o.penaltyArray[i] = (Penalty) penalty.clone();
return o;
} catch(CloneNotSupportedException e){
throw new InternalError();
class Penalty implements Cloneable{
private String penaltyDesc;
private int lowLimit, upperLimit, penaltyValue;
public Object clone(){
try{
return super.clone();
} catch(CloneNotSupportedException e){
throw new InternalError();
If your Penalties are immutable, you don't need to clone them -- rather,
make then unclonable, like Strings.

Similar Messages

  • How can i send user defined Object as a argument to the MBean methods in authentication provider to create user?

    I developed our own Authentication, Identity Assertion & Authorization providers
    for weblogic 8.1 SP1. In the authenticator MBean i have one method which takes
    user defined object as a argument and returns a user defined object. i am able
    to call all the methods which takes java objects(for example: String, int, ArrayList,
    HashMap, Etc...) as a argument and returns also a java object but when i user
    any user defined object then it gives exception. if in the argument i used user
    defined object then it is not able to call that method telling NoSuchMethodException.
    Is there any way to use user defined object as an argument to MBean method?
    can anyone please help us as we r in the final stage of the project?
    Thanks
    Lakshmi

    "Lakshmi Padhy" <[email protected]> wrote in message
    news:3fc2f50c$[email protected]..
    >
    I developed our own Authentication, Identity Assertion & Authorizationproviders
    for weblogic 8.1 SP1. In the authenticator MBean i have one method whichtakes
    user defined object as a argument and returns a user defined object. i amable
    to call all the methods which takes java objects(for example: String, int,ArrayList,
    HashMap, Etc...) as a argument and returns also a java object but when iuser
    any user defined object then it gives exception. if in the argument i useduser
    defined object then it is not able to call that method tellingNoSuchMethodException.
    >
    Is there any way to use user defined object as an argument to MBeanmethod?
    >
    I seem to remember that jmx only supports scalar datatypes. Ask in the
    weblogic.developer.interest.management newsgroup.

  • How to pass a "user defined" object to a thread?

    Hi...
    I have created an object say 'obj1' . I want to pass to a thread say 'T1' .
    The thread T1 implements the runnable class.
    I need to pass the "obj1" object to the T1 for it to be processed in the "run" method of T1.
    As far as I have seen there is no thread constructor in Java that accepts an object created by the user.
    My question is there any way to pass an object to a thread? and if so how can it be done?

    You can just add your own method to the class. Then call that method to pass the object to the thread before you call start on the thread.
    class MyThread implements Runnable
       public void run()
          userObj.whatever();
       public void addObj(Object obj)
          userObj = obj;
       Object userObj = null;
    // your code
    MyThread thread = new MyThread();
    thread.addObj(myObj);
    thread.start();As long as you don't call start before your pass the object to your thread, then you won't have a problem. Hope this helps.

  • UDO--user defined object

    how to use UDO--user defined object in sap b1????

    Creating UDO in SAP B1
    1. Create UDT, ( Create UDT as Document if want the code to be in auto increament form)
    2. Create UDFs for created UDT,
    3. Register Object using  "Object Registration Wizard",
                    (a) Put UDT's unique name in "UNIQUE ID" field of UDO (Image - UDO01.jpg) ,
                    (b) Do further as per requirements,
    4. After Registering the UDO, you can access it from where you have set it to access (@ UI Settings of "User - Defined Object Registration Wizard"),
    5. If you wana change the field location / change the design of the form, Open screen painter as and click on "Open User Defined Object List " (Mostly 3rd icon from Left in screen painter),
    6. Make required changes and save it by clicking "Save Form To Database" ( Mostly 2nd icon from Left in Screen Painter),
    7. Now the UDO is ready and can be used by user.

  • How to assign a query retrived value to a user defined  object in a table

    how to assign a query retrived value to a user defined  object in a table

    Rajeshwar,
    If you use the "Search" feature in this forum, you should be able to find helpful links to similar questions.  You could also look at the RecordSet and DoQuery documentation in the SAP Business One SDK Help Center documentation to assist you with your question.
    HTH,
    Eddy

  • EJB : How to return user defined object

    hi,
    i am a newbie in EJB. i have the following simple problem:
    public interface MyApp extends EJBObject
       public String getResult() throws RemoteException;
    }the above code will be ok because it is returning String object.
    however, i need to return a user defined object like:
    public interface MyApp extends EJBObject
       public MyResult getResult() throws RemoteException;
    }then i got java.lang.ClassCastException during runtime.
    please tell me how to resolve this problem.
    thank you very much

    since you are a newbie, let me explain something to you. Ask your question in the proper forum. In case, you still don't understand there is a forum for EJB questions.

  • How to alter user defined  objects in  oracle

    Hi all,
    Can any one tell me how to alter user defined objects in oracle .
    Thanks,
    P Prakash

    prakash wrote:
    Hi all,
    Can any one tell me how to alter user defined objects in oracle .
    DROP
    then
    CREATE
    Handle:      prakash
    Email:      [email protected]
    Status Level:      Newbie (80)
    Registered:      Feb 3, 2011
    Total Posts:      185
    Total Questions:      67 (65 unresolved)
    so many questions & so few answers.
    How SAD!
    Edited by: sb92075 on Sep 22, 2011 9:22 AM

  • How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCI

    Hi
    we are using Timesten 11 version and as per the documentation, it doesn't support User-Defined Aggregate Functions.
    So we are looking for alternatives to do it. Could you please provide your expert voice on this.
    Thanks a lot.
    As the following:
    create or replace type strcat_type as object (
    cat_string varchar2(32767),
    static function ODCIAggregateInitialize(cs_ctx In Out strcat_type) return number,
    member function ODCIAggregateIterate(self In Out strcat_type,value in varchar2) return number,
    member function ODCIAggregateMerge(self In Out strcat_type,ctx2 In Out strcat_type) return number,
    member function ODCIAggregateTerminate(self In Out strcat_type,returnValue Out varchar2,flags in number) return
    number
    How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCIAggregateInitialize ?

    Dear user6258915,
    You absolutely right, TimesTen doesnt support object types (http://docs.oracle.com/cd/E13085_01/doc/timesten.1121/e13076/plsqldiffs.htm) and User-Defined Aggregate Functions.
    Is it crucial for your application? Could you rewrite this functionality by using standart SQL or PL/SQL?
    Best regards,
    Gennady

  • Link button to User Defined Object in Grid

    Hi,
    I'm using SAP B1 8.81 with B1DE.
    I have added a grid which is populated from a DataTable to a form.
    One of the columns in the grid contains the DocEntry of a User Defined Object.
    How can I display a link button on the grid ?
    Regards,
    Ben

    Hello Ben,
    You need to set the column object type.
    Dim oGrid As SAPbouiCOM.Grid = oForm.Items.Item("MyGrid").Specific
    oGrid.Columns.Item("DocEntry").Type = BoGridColumnType.gct_EditText
    Dim oEditCol As SAPbouiCOM.EditTextColumn = oGrid.Columns.Item("DocEntry")
    oEditCol.LinkedObjectType = "2" 'The SDK documentation says you should use the value 0, but in previous versions it didn't work, so I recommend you user a value other than -1 or 0
    You then need to catch the et_MATRIX_LINK_PRESSED event and other your user form...
    From the SDK Help File regarding the BoLinkedObjectType enum
    lf_None -1 No target object
    lf_UserDefinedObject 0 User-defined object
    lf_GLAccounts 1 G/L account object
    lf_BusinessPartner 2 Business Partner object
    lf_Items 4 Item object
    lf_SalesEmployee 53 Sales employee object
    Regards,
    Vítor Vieira

  • Dispose a user-defined object in Java

    Hello,
    Suppose I have the following loop :
    while ( some_condition) {
    UserDefinedClass abc = new UserDefinedClass();
    // do some work and exit loop.
    Everytime, I enter this loop I instantiate a new object "abc". I am worrying that if I keep doing this, after a while, I will run out
    of memory. Is there a way to dispose a user-defined object? Or is this scenario taken care of by Java garbage collection process?
    Any advice is much appreciated.
    Akino.

    Akino wrote:
    Hello,
    Thank you for your reply.
    I wonder if you could tell me how often Java does its garbage collection?That's pretty unpredictable.
    I ran a test and observed that
    my program's memory usage kept going up and up.If you gave it it 64M, and the most it ever needs at one time is 10M, it can still ramp up to the full 64M, even if it's doing frequent GC. Running GC does NOT mean that the JVM gives the memory back to the OS. It can do that, and I think it does under some circumstances, but there's no guarantee if, when, or how much it will give back. GC only means that the JVM has reclaimed space that is no longer in use by objects. Whether it holds onto that memory for future use or gives it back to the OS is up to it.

  • Object to user defined object

    I pushed user defined objects in to the Vector or Stack.
    But they return an java defined Object type when I try to use them.
    Is there way that I can convert this Object into my defined object.
    MyClass a;
    MyClass b;
    Stack table = new Stack();
    table.push(a);
    table.push(b);
    //now when i use pop to get it back it returns an Object type
    Object temp = table.pop();
    //how do I change this object into MyClass so i can have access to MyClass stuff?

    dam..thank you so much I feel stupid..Don't.
    Casting is one of those things that can take a while to get used to.
    In your original post, you asked: how do I change this object into MyClass so i can have access to MyClass stuff?
    It's important that you understand that casting doesn't change the object in any way.
    All it does is cause a reference that's been declared as one type to be treated as a different type. So even though all the compiler knows about what's returned from pop() is that it refers to an Object, you're telling it you know better, and that the object pointed at will in fact be a MyClass, and so you can access MyClass' members.
    If, at runtime, the object you happen to pop off the stack isn't a MyClass, casting won't magically turn it into one. You'll get a ClassCastException.

  • How to pass a user defined table type to stored procedure?

    Hi,
    I am trying to call a stored procedure from Java. The store procedure has three IN parameter, 2 IN/OUT params and 3 OUT parameters. The two IN/OUT parameters are user defined objects. Can anyone tell me how to set these IN/OUT parameters in Java.
    Thanks

    It is database/driver specific so you need to use the specific functionality of the driver (not jdbc) to access it.

  • Portal Entitlements for user defined objects

    Hi,
    The UUP aggregates the user profile information from different backed data sources.
    One of the properties in the propertyset is a multivalued property. I populate
    this by the following code:
    PropertyMapKey propertyMapKeyM = new PropertyMapKeyImpl(null,"DA_Privilege");
    String str="LAB1_CAPLinks_ViewReports" + "," + "LAB1_CAPLinks_EditReports"; //hardcoded
    for testing
    propertyCache.put(propertyMapKeyM,str);
    (This code resides in the MyEntityPropertyManager)
    When I go to the portal administration screen, I do not see the values, it instead
    only gives me the object id of the java String array.
    Could someone please help me with the following questions:
    1. How do I populate the multivalued property ? I see in documentation that there
    is 2 different PropertyCache implementation......confused which one to use and
    how.
    2. Is there a way to define user defined objects in UUP and have portlets entitled
    to the state of the object ? (a custom entitlement code)
    3. Any sample code would be helpfull
    Thanks,
    Uday

    Thank You Greg. Now it works.
    -Uday
    Gregory Smith <[email protected]> wrote:
    I'm not totally sure, but I would imagine you want to put a List of
    Strings into the propertyCache if the property is supposed to be
    multivalued text, e.g.:
    PropertyMapKey propertyMapKeyM = new PropertyMapKeyImpl(null,
         "DA_Privilege");
    List strs = new ArrayList(2);
    strs.add("LAB1_CAPLinks_ViewReports");
    strs.add("LAB1_CAPLinks_EditReports");
    propertyCache.put(propertyMapKeyM, strs);
    I know that all of the code that calls the UUP and property sets code
    expects a Collection back from a multivalued property (but I'm not sure
    about a UUP implementation).
    Greg
    Udayraj Nair wrote:
    Hi,
    The UUP aggregates the user profile information from different backeddata sources.
    One of the properties in the propertyset is a multivalued property.I populate
    this by the following code:
    PropertyMapKey propertyMapKeyM = new PropertyMapKeyImpl(null,"DA_Privilege");
    String str="LAB1_CAPLinks_ViewReports" + "," + "LAB1_CAPLinks_EditReports";//hardcoded
    for testing
    propertyCache.put(propertyMapKeyM,str);
    (This code resides in the MyEntityPropertyManager)
    When I go to the portal administration screen, I do not see the values,it instead
    only gives me the object id of the java String array.
    Could someone please help me with the following questions:
    1. How do I populate the multivalued property ? I see in documentationthat there
    is 2 different PropertyCache implementation......confused which oneto use and
    how.
    2. Is there a way to define user defined objects in UUP and have portletsentitled
    to the state of the object ? (a custom entitlement code)
    3. Any sample code would be helpfull
    Thanks,
    Uday

  • Recon and provisioning of user-defined object class ICF Active Directory

    I have followed the documentation instructions for reconciliation of a user-defined object class in the ICF Active Directory connector. I am using OIM 11gR2 with the ICF Active Directory 11.1.1.5 connector patched to 11.1.1.5.0A. The procedure states to create the new object class in AD and then change the objectClass value in the Lookup.Configuration.ActiveDirectory lookup. In my case I am using the existing ObjectClass of contact, rather than a new object class. Just for completeness I am using a clone of the AD User Resource Object which I call AD User Contact and so my lookup name is Lookup.Configuration.ActiveDirCon.
    When I changed the ObjectClass from User to Contact, and ran the Active DirCon User Target Recon scheduled job, with Object Type also = contact. The first issue I noticed was that the connector wanted a different set of lookups, which is not in the documentation. It is looking for a lookup in my Configuration lookup where code key=contact Configuration Lookup (which I should have expected since there are code keys for User, Group, and organizationalUnit). I added a line to the lookup where code key=contact Configuration Lookup and the Decode=Lookup.ActiveDirCon.CM.Configuration and then I created a new lookup by that name, assigning the 5 values to be the Lookup.ActiveDirCon.UM.xxx lookups. I did not see any need to create a new set of Lookup.ActiveDirCon.CM.xxx lookups with the exact same values.
    I re-ran the scheduled job and it ran successfully, but did not generate any Recon Events, even though I had objects in the OU and I have that same OU in the Lookup.ActiveDirCon.OrganizationalUnits lookup (from the Org Lookup Recon). Everything looks good but getting no results. Looked at the log file from the ConnectorServer and it is building the query properly and executing it properly with the correct syntax, getting no errors, but the SearchAndReturnObjects method is returning zero results.
    Looking to see if anyone has successfully reconciled in user-defined or other non-User objectClass objects from Active Directory, and if so, can you provide Lookup configuration and Connector Server information so I can troubleshoot.
    I resolved this issue by changing the recon lookups to a blank lookup called Lookup.ActiveDirCon.CM.ReconAttrMap and only added in the parameters that are used by a Contact object. Only populate the ReconAttrMap with parameters that exist for the custom object.
    Edited by: Keith Smith AptecLLC on Mar 27, 2013 6:31 AM

    Oracle Support answered this question via SR

  • Approval Templates for the User Defined Object(UDO)

    Hi,
    I just wanted to check whether the Approval Templates for the User Defined Object(UDO)...i.e. Said to the User Defined Form..
    if possibe how it can be done.....
    Thanks in Advance,
    With Regards,
    MadhuSudhana Rao.G

    Hi MadhuSudhana Rao,
    The function you requested is not available yet.
    Thanks,
    Gordon

Maybe you are looking for

  • Bootcamp drive not showing up in Lion

    hi! ^^ Bootcamp drive not showing up in Lion. Lion is just downgrade version of Leopard. nothing changed but good functions are disappear. c:/aaa folder? i can not access directly from os x boot. haha.

  • Music played in itunes skips

    When I try to play music in Itunes the music skips and then picks up and skips again at about 1/2 second intervals. I think I need to deinstall Itunes and then reinstall but will this delete my library?

  • How to design a web to improve PR of google?

    Everyone know:PR is very improtant for a websit,and the web designed is a important factors, and how to design a web to improve PR,is a improtant question,please disiness ? i have designed a jewelry wholesale business wensite, my PR is 3,and how to i

  • Full Screen Photos on iPhone 5....

    I know there are many topics about this already, but as I was watching the new commercial for the iPhone 5, I realized the pictures were full screen, what's going on here?? http://www.youtube.com/watch?v=2xHquhlr45w&list=UUE_M8A5yxnLfW0KghEeajjw&inde

  • Which web dynpro I am using?

    Hi all,     I can not contact with my basis now, I want to know I am using ABAP web dynpro or JAVA web dynpro. How can I check it? Thanks~