Object cloning question

Hello all,
I have a question about cloning a class. My class is something like this...
public class Message implements Cloneable
  int id;
  Fields fromClient;
  Fields fromProcessor;
  Fields toClient;
  Fields toProcessor;
  protected Object clone() throws CloneNotSupportedException
    return (super.clone());
}FYI, the Fields object is another class that contains a Vector of Field objects... A Field is simple class containing three strings, one string named name, one is named value, the other string is named defaultValue.
At application startup, I create this class and each of the Fields objects are initialized with various Field object stuff.
Message baseMessage = new Message();Later in the process, when I need to create a new Message object, instead of doing a 'new' I instead do a
Message msg1 = baseMessage.clone();The newly cloned msg1 object is then processed and manipulated.
The problem I am having is that on the next call to
Message msg2 = baseMessage.clone();the newly cloned msg2 object contains the contents of msg1! This is very strange because I thought that msg2 would be a clone of baseMessage which does not contain any of the information found in msg1...
Any ideas? I hope I explained it well enough...
Thanks,
-Jeff

Also, did you realy intend your clone() method tobe protected?
I am not really sure why a make the clone()
protected. I most likely read somewhere that it
needed to be protected... Is this a bad thing?Not necessarily. It depends on who you want to be able to clone your object. If you want everbody to be able to, make it public. If you want only classes in that package and subclasses of your class to be able to do it, make it protected. I just wondered because public is probably more common.
As for your other comment about why you weren't using new: You can still use new to make a deep or shallow copy. It's called a copy constructor.
public class Message {
  public Message(Message orig) {
    field1 = orig.field1; // shallow copy
    field2 = new Field2(orig.field2); // deep copy, assuming Field2 has such a constructor
    etc.
}

Similar Messages

  • Docs about RowSet, and Object RowSet questions?

    Docs about RowSet, and Object RowSet questions?
    I can find RowSet forum, so I ask here!
    Can you give me URLs where I can find more about RowSet and URLs for any RowSet implementation?
    Does Borlans, Oracle, IBM, etc., have RowSet implementation?
    I find out about Sun's RowSet implementation, but I can't find Object Rowset in this implementation?
    Is it possible to develop Object RowSet and is it useful?
    I know about O/R tools like Hibernate, but Object RowSet can be useful?
    Run SQL query and get Objects, or maybe even run Object query (like EJB or Hibernate or JDO have) and get Objects.
    No XML mapping mess and simmilar, like with EJB or Hibernate or JDO?

    You can try
    http://java.sun.com/developer/Books/JDBCTutorial/chapter5.html
    This is a tutorail for RowSet

  • System and Object privileges question

    hello everyone.
    I was really making it a priority to really understand both system and object privileges for users. I have setup a couple of 'sandboxes' at home and have done lots of testing. So far, it has gone very well in helping me understand all the security involved with Oralce (which, IMHO, is flat out awesome!).
    Anyway, a couple of quick questions.
    As a normal user, what view can I use to see what permissions I have in general? what about permissions on other schemas?
    I know I can do a:
    select * from session_privs
    which lists my session privileges.
    What other views (are they views/data dictionary?) that I can use to see what I have? Since this is a normal user, they don't have access to any of the DBA_ views.
    I'll start here for now, but being able to see everything this user has, would be fantastic.
    Cheers,
    TCG

    Sorry. should have elaborated more.
    In SQLPLUS, (logged in while logged into my Linux OS), I am working to try and get sqlplus to display the results of my query so it is easy to read. Right now, it just displays using the first 1/4 or 1/3 of the monitor screen to the left. Make sense? So it does not stretch the results out to utilize the full screen. it is hard to break down and read the results because they are "stacked" on top of each other.
    Would be nice if I could adjust sqlplus so the results are easier to read.
    HTH.
    Jason

  • Object oriented question

    I am sure my n00bieness is going to shine here but I have a pressing question.
    I have two classes that do a similar activity they attach some elements to an xml document and then call a web service.
    Object A uses in its method signature different object parameters then Object B does.
    For example -
    Object A{
      public ProprietaryObject doMagic(ProprietaryObject po){
        //do stuff
    Object B{
      public DiffProprietaryObject doMagic(DiffProprietaryObject po){
        //do stuff
    }There is more than one method that is similar between the two objects but this is just to get the point across.
    Anyway, Instead of creating two separate objects that do "almost" the same thing (on different object types) how can I create an elegant solution to this?
    The problem I run into is that if I create a common interface for these two object to implement the object use different proprietary objects to do their work.
    I find that I keep using the instanceof operator everywehre to determine the object type.
    Hope this is not explained to horribly...
    Any help is appreciated!

    I'd create an Interface which defines a common access method for the-operations-you-require from both proprietory classes, then implement that interface in a couple of "boundary" classes which "wrap" the proprietory classes...
    If possible, extend the disparate proprietory classes, and delegate to the appropriate methods of the "real" classes.
    If the propritory classes are final then you have to write a ship load more "boilerplate" code... every single fraggin method has to pass the buck to the appropriate method of the private instance of the "wrapped" class, and return the result... which isn't usually too bad once you roll up your sleeves and get into it.
    From memory (mine is poor) this is the essence of the [Adapter pattern|http://en.wikipedia.org/wiki/Adapter_pattern].
    Like a said, there may be quit a bit of work involved, but the advantages usually outweigh the costs... You can "refer to" the disparate proprietory classes seemlessly throughout the rest of your system... if ProprietoryClassA changes (in the next release) you can (hopefully) adapt your adapter to those changes, without having to modify all your consumer code... because it still exposes the same interface... which is the motivation for any boundary class ("Trust no one";-)
    Cheers. Keith.
    Edited by: corlettk on 8/08/2008 06:28 - Better.

  • Should I use Embed or Object - quick question...

    Hi all,
    I've got a few .swf files on my site. One of them uses the following code:
    <object style="float:left;" id="intro" name="intro"
    type="application/x-shockwave-flash"
    data="<?php echo $siteurl; ?>/intro_movie/intro.swf" width="300"
    height="188">
    <param name="wmode" value="image" />
    <param name="movie" value="<?php echo $siteurl; ?>/intro_movie/intro.swf" />
    </object>
    Another one uses the following:
    <script type="text/javascript">
    var flashvars = {};
    var params = {};
    var attributes = {};
    swfobject.embedSWF("<?php echo $siteurl;  ?>/swf/testimonials.swf", "_testimonials", "405", "43", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    </script>
    <div id="_testimonials">
    <a href="http://www.adobe.com/go/getflashplayer" title="Get flashplayer">
    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" width="112" height="33" alt="Get Flashplayer" border="0" />
    </a>
    </div>
    On a computer recently the first example showed up fine but the second example didn't show up at all.
    I just wondered what the correct way to show .swf files is on a webpage.
    I'm very sorry if this is a stupid question but any help you could give me on this would be much appreciated.
    Many thanks
    John Thornley ;-)

    kglad.com
    Thank you for your reply.
    I should clarify that both of those examples are working on my machine. However, on another machine only the top example showed up at the bottom example caused 404 errors as it was trying to load expressInstall.swf which wasn't in the directory.
    This confused me as I wondered if there was any detriment to just having all my swf on my site integrated using the top method?
    I didn't write the bottom example and I don't really understand it fully. I'm not sure whether my best move is to just convert everything to the top example or whether I should try and find a copy of "expressInstall.swf" and try and get the bottom example working on this other machine?
    Which is the correct way?
    Thanks again for your continued support
    Cheers
    John ;-)

  • Help In ABAP Object Certification Question

    Hi ABAP Gurus,
       iam going to write certification Exam on Nov 11. i have got some model question from SAP domain for all the topics Except ABAP Objects which is so important...
    Please anybody send me some Example question you guys got from the Certification Exam
    it will be be grateful to me...
    Thanks a lot in advance.
    Prabhu
    SAP Lead Consultant

    Hi,
    Sending ABAP Objects questions is not an option but normally, your concepts are tested for:
    - Classes and objects
    - Inheritance
    - Casting
    - Interfaces
    - Events
    - Global classes and interfaces
    - Exception handling
    - Dynamic programming
    You can use help.sap.com to take a look at these topics one by one. Hope this helps.
    Good luck.

  • LR2:DNG - PSCS3:'Smart Object' workflow question

    Hello, I've just started working with DNG files exported as Smart Object from LR2 to PSCS3 and I would appreciate some feedback on my experiences thus far.
    Let us assume that I've made basic corrections to _DSC1190.dng within LR2. I then want to apply a filter to a particular region of the DNG file with all of my LR2 adjustments applied.
    1. Here are the steps I currently follow:
    1.1. Right-click on the DNG file and select 'Edit In'->'Open as Smart Object in Photoshop...'. This results (I believe) in the DNG file with all of my LR2 changes being embedded within a smart object and the resulting temporary file being opened within PSCS3.
    1.2. I perform my edits in PSCS3 and save the file as a PSD (i.e. _DSC1190.psd). As long as I was smart about things, I can now go back at any time and alter any of the changes I made in PSCS3, as well as access the DNG file within the smart object to make and ACR changes I desire.
    1.3. If I want the new PSD file to be added to my LR2 catalog, I then need to navigate to where it was saved and manually add it.
    1.4. If I want to make any exposure adjustments, or really, any adjustments that I'd normally make within LR2 or ACR to _DSC1190.psd, I need to open the file within PSCS3, double click on the smart object to get the ACR dialog, make my changes, and voila!, the PSD composite now reflects those changes.
    1.5. If I make any changes within LR2 to the original DNG file (i.e. _DSC1190.dng), those changes are *not* reflected within the PSD file.
    1.6. Questions
    1.6.1. Is what I've described the expected behavior?
    1.6.2. Although it might seem silly to some, and may present a technical challenge not worth the trouble, it seems it would be beneficial to have the smart object exported from within LR2 to PSCS3, contain a link to the original DNG file, and not now have two separate DNG files, one visible to the file system, and the other embedded within the smart object saved as presumably a PSD. I'm sure there are a lot of corner cases to consider, but it just seems very strange to now have two files wherein if you want to change something you would normally do through LR2 or ACR, you now have to do it in two different programs to two different files. Is this a problem Adobe has considered, i.e. any discussion about supporting this perhaps in an update to LR2 along with PSCS3/4?
    Thanks much for any help/insight,
    Matt

    I haven't tried doing what you are in CS but do you have the embed xmp into file enabled or are you updating the xmp by saving it out of LR CTRL-s? Do you have ACR set to read the xmp data? I don't have access to LR at the moment but will have a play l8r and get back to you if no one else does.

  • Business Object Modeler Question

    Hi Experts,
    I'm new to CE and currently trying to figure out what can I do with it?
    Assume that I'm planning to create an application to follow activities that our consultants doing.
    For this, we're planning to use Local Portal Database to store datas.
    When I checked, "Business Object Modeler" is a tool which helps to create business objects and generates tables behind and access services automatically.
    Then generating a Web Service for this BO and then using the WS with VC and WD4J is a great asset for us.
    But, my questions?
    1. Is this a right approach for  such scenario?
    2. I've created a sample BO and generated WS and tried to use with VC. Create, Delete, Reand and Update Operations can be made available for WebService, but I'm unable to add FindAll or FindByMultiple Parameter operations to Web Service?
    Any idea for Q1 and answer for Q2 will be appreciated.
    Regards

    Hi,
    Yes, You have to arite the code.Actually, Application services are the place where you will wrtie your business logic.
    In th application service operations you have to call the business object operations.
    For architechturel guidelines you can go [through thii doc|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00caf8bd-487a-2a10-36a9-93d840309310].
    answer to second question:
    You can't change the code in the BO operations. What ever you want, you have to do it in the application servcies only.
    Create an application service operation  say:
    operation(). Create a input/output data structures.
    Exapmle:     OperationResponce operation(OperationRequest).
    Yuor lists add to the  OperationRequest datatype. Similarly for  OperationResponce also. In this case you don,t have any issues.Actually this is the standered for Web Services.
    [This document|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f0d97ec6-5de0-2a10-a5b3-b5926075566c], you can use as an example
    [CE 7.1 Tuorial Center.|https://www.sdn.sap.com/irj/sdn/nw-development?rid=/webcontent/uuid/903c2cdb-98d6-2a10-84b7-ab22535de11a]
    Reward Points, If you feel it is useful.
    Sampath

  • 9 shared objects performance question

    I have 9 shared objects 8 of which contain dynamic data which i cannot really consolidate into a single shared object because the shared object often has to be cleared.....my question is what performance issues will I exsperience with this number of shared objects .....I maybe wrong in thinking that 9 shared objects is alot.....anybody with any exsperience using multiple shared objects plz respond.

    I've used many more than 9 SO's in an application without issue. I suppose what it really comes down to is how many clients are connected to those SO's and how often each one is being updated.

  • Where is the getString() implementation for RS and Object class question

    Dear all,
    I had these two questions ringing since a long time.
    1)ResultSet is an interface.
    In my jdbc code I have generally written rs.getString() and rs.getInt etc.. without giving a second thought as to where exactly is this getter implemented !
    I have RTF API .. without too much help.
    Could some one kindly explain Where is the implementation of the getString method ?
    2) Could you please tell why the Wait() Notify() and NotifyAll methods have been implemented in the Object class ? What was the need to define em in the Object class ?
    Thanks in advance for your time spent on this.
    Rgds

    Sarvananda wrote:
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    Rgds
    >
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    A desire to not have to couple your code to a particular database and JDBC driver. It's a classic example of the abstract factory pattern

  • SCC4 and Object Changeability question

    Gurus,
    Note - Please do not send me links ,which has no reference to my questions whtsoever,pls provide me direct answers to the questions if possible.
    1)do you need to open the system using SCC4 in order to make the "object changeability" option work??
    2)what is the relation between SCC4 and  "object changeability"
    3)Can the Infopackage transported from dev to prod be changed with "object changeability" option??if yes how ?
    or only object created in the production local be changed using "object changeability" option
    or i can only change the transported Infopack in production using SCC4 ,system open
    thanks in advance.

    1)do you need to open the system using SCC4 in order to make the "object changeability" option work??
    ans) Pre-requisite -Close the system
    2)what is the relation between SCC4 and "object changeability"
    ans) Objects of the selected object types exist in your system as changeable with "object changeability option" even if this system is globally set to not changeable.
    3)Can the Infopackage transported from dev to prod be changed with "object changeability" option??if yes how ?
    or only object created in the production local be changed using "object changeability" option
    or i can only change the transported Infopack in production using SCC4 ,system open
    ans)"Choose Original Changeable" If you not only want to make objects which are generated in this system changeable, but also those that were imported. This option is required, for example, if you need to make repairs or want to change flexible starting times. Note: New imports can overwrite the changes again
    I would advocate to read this link carefully -
    http://help.sap.com/saphelp_nw04s/helpdata/en/0e/a7343e8c7f6329e10000000a114084/frameset.htm
    Hope it Helps
    Chetan
    @CP..

  • Callable object context question

    HI All.
    1)If i make web dynpro as a callable object then - i have 2 types of context - 1 is the web dynpro context as always and one is the calleble object context (GP Context)
    What is the difference between the two contexts?
    2)What is achieved when i map the webdynpro context attribute's value  to the attribute of GP Context -ie - what purpose does it serve?
    3)Whati if i do not set any attributes in the technical description of the GP Context
    Please help me in the above things
    Points assured for help

    Hi,
    1) By GP context I think you mean the input/ouput parameter of the GP CO context. These are defined in the getdescription() method of the Web Dynpro callable object which are exposed in GP as Callable object's parameters. In WDP there is no context node available as GP context. This is defined and operated by code using GP API.
    2) The GP context of a WDP CO is what available in GP design time from the callable object as input and output parameters. In the WDP application you may not have any physical context as GP context. Because anyway you have to write code to define, read and write the GP context in the getDescription(), execute() and complete() methods. So you may or may not keep a specific context node in WDP for the GP context. You can read any relevant context node of the WDP and populate the GP context by coding. So no question of mapping physically.
    3) if you don't set any attributes in the getDescription() method no input or output parameter will be available in GP from that callable object.
    Thanks,
    Dipankar

  • Cloning question

    Hi All,
    I have a question about cloning. In copying apps tier to destination, I am asked to copy those files to appldev, and not applmgr. The database files are still under oracle.
    I am not sure what will be the impact from this? Any process or scripts I need to run to accomodate this change?
    Thanks,
    milic

    I have a question about cloning. In copying apps tier to destination, I am asked to copy those files to appldev, and not applmgr. The database files are still under oracle.
    I am not sure what will be the impact from this? Any process or scripts I need to run to accomodate this change?There should be no impact as long as the appldev user owns all the application tier node files on the target machine. So, all what you have to do after running preclone on the source application node, and copying the files is to change the ownership of the files on the target application tier node (make the files owned by appldev), then run postclone on the target node as appldev user.
    Thanks,
    Hussein

  • Copying or cloning question...

    I'm upgrading my MBP with a bigger hard drive this weekend.
    I know of a couple of recommended programs to 'clone' my HD (Carbon Copy Cloner and SuperDuper) my question is:
    Do these programs actually make an identical copy (clone) of the source, complete with any fragmentation and scattered files, or do these programs transfer the data in a logical order and reassemble files and, in doing so, de-frag the data?
    I'm guessing they do the former but wonder if the later is possible in any way.
    Would a better way of restoring the data be to install the OS from DVD, upgrade/update to it's latest spec and then run the migration program (again, I'm assuming the migration program does more than just 'clone' the data)?
    Thanks...

    They do the latter - those are file-based duplication programs, so cloning the drive with either program will defrag it (although FYI, the Mac OS automatically defrags files <20 MB in the background). It's actually more work to make a byte-for-byte copy (which you don't want to do).
    The reinstall of the OS and migrate from the old system would work too, but your easiest path in this case is just to clone the drive with either of the two programs you mentioned.

  • Object move question

    Hi.
    I think the whole day on this thing: In this example http://www.stanko-b.com/heelbopps/ (project https://www.dropbox.com/s/dr41wme9uqnm0a9/heelbopps4.zip) when you press the "down" button, the screen scrolls down to a particular object.
    Сode assigned to the button "down" is:
    var element = sym.$("object1");
    $('html,body').animate({scrollTop: element.offset().top}, "slow");
    My question. How to make itself the "down" button to move to the  "object1"?
    In other words, what would I need one object, wherever it was (on click), moved to other objects on the Y axis?
    Thank you.

    In your Stage > compositionReady event handler, add the following code block just before your yepnope.
    If I assume correctly, you will only need one of the arrowDown elements to move when the page scrolls or when the arrow is clicked. In this case I used your 'arrowDown_Products' element; then remove the remaining three since they will no longer be needed.
    /////------- Copy Start ---------- //////
    $(window).scroll(function(){
           var element = sym.$("arrowDown_products");
                 element
                .stop()
                .animate({"marginTop": ($(window).scrollTop() -45) + "px"}, 100 );
    /////--------- End Copy --------- ///////
    Hope this helps. - I havn't tackled the click event but its going to require some conditional logic to function 100%.
    Darrell

Maybe you are looking for