Best way to write objects in an xml and send the file?

hello all
i am making some objects, which i conver to xml using the XStream and then i am saving them to a file, call a function to send the file to a servant (basically i do this by sending bytes and this may be the problem). In the servant i take the data i write them to a file and then i read them again to make them objects...
i have the following code in the client
        XStream xstream = new XStream(new DomDriver());     
        xstream.alias("Jobb", WorkflowFramework.Jobb.class);
     String xml = xstream.toXML(translation);
           FileWriter fw = new FileWriter("translation.xml");
           ObjectOutputStream out = xstream.createObjectOutputStream(fw);
           out.writeObject(new Jobb("ougk2", "Walnes",null));
           out.close();
           File file=new File("translation.xml");
           byte buffer[]=new byte[(int)file.length()];
           try {
                BufferedInputStream input=new BufferedInputStream(new FileInputStream("translation.xml"));
                input.read(buffer,0,buffer.length);
                input.close();
           } catch(Exception e) {
                  System.out.println("Error: "+e.getMessage());
                   e.printStackTrace();
           theRemoteObjRef.translationService(theCallbackObjectRef, buffer);i write the file and then i read it so as to have a buffer of bytes (there should be a better ways..)
the last line sends an objectRef (we dont care about that) and the file in bytes to a server (to be specific to a servant of a server)..
in the servant i do the following
public void translationService(TheCallbackInterface objRef, byte data[]){
          try{
                    File file = new File("translation2.xml");
                BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream("translation2.xml"));
              output.write(data, 0, data.length);
              output.flush();
              output.close();
          } catch(Exception e) {
                    System.out.println("Error: " + e.getMessage());
                    e.printStackTrace();
           XStream xstream = new XStream(new DomDriver());
           try { // If an error occurs, go to the "catch" block
                FileReader fr2 = new FileReader("translation2.xml");
                ObjectInputStream in = xstream.createObjectInputStream(fr2);
                Jobb newJob = (Jobb)in.readObject();
               System.out.println(newJob.getObjServerRef());
               System.out.println(newJob.getForTranslation());
               System.out.println(newJob.getTranslated());
                }catch (Exception e) {  
                     System.err.println("File input error"+e);
                Jobb testJob=new Jobb("ougka","mpougka","falalala");
                System.out.println(testJob.getObjServerRef());
                   System.out.println(testJob.getForTranslation());
                System.out.println(testJob.getTranslated());
the problem is that in the first group of System.out.println i get the error File input errorcom.thoughtworks.xstream.mapper.CannotResolveClassException: Jobb : Jobb
but the second group of printlns, prints the correct results...
do you know what is the problem? Why can i read the content of the file and get the objects from there?
do you have any suggestions of writing and reading the file in an another way or to send it by NOT using a bytes array?
do you have an alternative way of making the xml file?
many thanks!

Hi,
I would suggest to reconsider building of your document so that it doesn't contain duplicates if you don't need them. And it doesn't have much to do with DB XML then.
Also you could insert your document with duplicates and use XQuery Update facilities to delete undesirable nodes.
Vyacheslav

Similar Messages

  • Best way for Java objects to relate to DB tables

    When creating a Java app which relies on a backend DB, it is convenient (and necessary) to create Java classes which relate to the data in those tables. However with a normalised set of tables, should the Java classes relate purely to the tables, or the "view" of the un-normalised data?
    e.g. (rough example of what I mean)
    CREATE TABLE teams
    team_id INTEGER NOT NULL PRIMARY KEY,
    team_name CHAR(50)
    CREATE TABLE users
    user_id INTEGER NOT NULL PRIMARY KEY,
    user_name CHAR(50),
    team_id INTEGER REFERENCES teams(team_id)
    Now, the Java class for a user could have either have a variable (e.g. teamName) declared as an int (to fully reflect the table design) or a String (to represent the "view" of the data). I know that views can be used etc. and in this example that would be very easy � I am just using these simplified tables as an example.
    I have tried both and both have pitfalls. For instance, when getting the data from the database, it is very easy to create the object from the DB if it reflects the �view� of the data. However when it comes to updating the data in the DB, you need to do a lot of other work to find out what needs updating in which tables, because the actual raw data (as will be inserted/updated with SQL commands) is not available in the Java object.
    I hope this makes sense.
    Thanks.

    My question is what is the best way to write the classes that represent the DB data. As I said this is not EJB (that would handle the DB side of things anyway), as this is overkill for this particular situation. It was more of a general question anyway - should the class contain the actual data (e.g. should the user Class contain a String for the team name (e.g. Purchasing) or a link to the underlying DB id for Purchasing.
    In reality, I would create a Team class, but the same applies - should the Java Class ever contain any relationship to the underlying DB. I think not, but it seems inefficient to have to continually query the DB to find out information we already have.
    Apologies if I am not explaining this very well.

  • What is the best way to write 10 channels of data each sampled at 4kHz to file?

    Hi everyone,
    I have developed a vi with about 8 AI channels and 2 AO channels... The vi uses a number of parallel while loops to acquire, process, and display continous data.. All data are read at 400 points per loop interation and all synchronously sampled at 4kHz...
    My questions is: Which is the best way of writing the data to file? The "Write Measurement To File.vi" or low-level "open/create file" and "close file" functions? From my understanding there are limitations with both approaches, which I have outlines below..
    The "Write Measurement To File.vi" is simple to use and closes the file after each interation so if the program crashes not all data would necessary be lost; however, the fact it closes and opens the file after each iteration consumes the processor and takes time... This may cause lags or data to be lost, which I absolutely do not want..
    The low-level "open/create file" and "close file" functions involves a bit more coding, but does not require the file to be closed/opened after each iteration; so processor consumption is reduced and associated lag due to continuous open/close operations will not occur.. However, if the program crashes while data is being acquired ALL data in the buffer yet to be written will be lost... This is risky to me...
    Does anyone have any comments or suggestions about which way I should go?... At the end of the day, I want to be able to start/stop the write to file process within a running while loop... To do this can the opn/create file and close file functions even be used (as they will need to be inside a while loop)?
    I think I am ok with the coding... Just the some help to clarify which direction I should go and the pros and cons for each...
    Regards,
    Jack
    Attachments:
    TMS [PXI] FINAL DONE.vi ‏338 KB

    One thing you have not mentioned is how you are consuming the data after you save it.  Your solution should be compatible with whatever software you are using at both ends.
    Your data rate (40kS/s) is relatively slow.  You can achieve it using just about any format from ASCII, to raw binary and TDMS, provided you keep your file open and close operations out of the write loop.  I would recommend a producer/consumer architecture to decouple the data collection from the data writing.  This may not be necessary at the low rates you are using, but it is good practice and would enable you to scale to hardware limited speeds.
    TDMS was designed for logging and is a safe format (<fullDisclosure> I am a National Instruments employee </fullDisclosure> ).  If you are worried about power failures, you should flush it after every write operation, since TDMS can buffer data and write it in larger chunks to give better performance and smaller file sizes.  This will make it slower, but should not be an issue at your write speeds.  Make sure you read up on the use of TDMS and how and when it buffers data so you can make sure your implementation does what you would like it to do.
    If you have further questions, let us know.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Best way to write SELECT statement

    Hi,
    I am selecting fields from one table, and need to use two fields on that table to look up additional fields in two other tables.
    I do not want to use a VIEW to do this. 
    I need to keep all records in the original selection, yet I've been told that it's not good practice to use LEFT OUTER joins.  What I really need to do is multiple LEFT OUTER joins.
    What is the best way to write this?  Please reply with actual code.
    I could use 3 internal tables, where the second 2 use "FOR ALL ENTRIES" to obtain the additional data.  But then how do I append the 2 internal tables back to the first?  I've been told it's bad practice to use nested loops as well.
    Thanks.

    Hi,
    in your case having 2 internal table to update the one internal tables.
    do the following steps:
    *get the records from tables
    sort: itab1 by key field,  "Sorting by key is very important
          itab2 by key field.  "Same key which is used for where condition is used here
    loop at itab1 into wa_tab1.
      read itab2 into wa_tab2     " This sets the sy-tabix
           with key key field = wa_tab1-key field
           binary search.
      if sy-subrc = 0.              "Does not enter the inner loop
        v_kna1_index = sy-tabix.
        loop at itab2 into wa_tab2 from v_kna1_index. "Avoiding Where clause
          if wa_tab2-keyfield <> wa_tab1-key field.  "This checks whether to exit out of loop
            exit.
          endif.
    ****** Your Actual logic within inner loop ******
       endloop. "itab2 Loop
      endif.
    endloop.  " itab1 Loop
    Refer the link also you can get idea about the Parallel Cursor - Loop Processing.
    http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing
    Regards,
    Dhina..

  • Best way to write this sql ?

    Please let me know best way to write this SQL.
    select col1, count(*)
    from TableA
    group by col1
    having count(*) =
    (select max(vals)
    from
    select col1, count(*) as vals
    from TableA
    group by col1
    having count(*) > 1
    )

    post EXPLAIN PLAN
    SELECT col1,
           COUNT(*)
    FROM   tablea
    GROUP  BY col1
    HAVING COUNT(*) = (SELECT MAX(vals)
                       FROM   (SELECT col1,
                                      COUNT(*) AS vals
                               FROM   tablea
                               GROUP  BY col1
                               HAVING COUNT(*) > 1))

  • GAME: best way to MOVE objects: tweenlite them or increment their x any values

    As the title says, need best way to move objects in game. Always used x and y increments. Read about tweenlite and use it, very easy. So which do I use taking into account that these games can be ported to mobiles ie: which is more optimized. It's a platform type game. I will have
    a. A little girl that walks and climbs
    b. Little platforms that slide from side to side - you have to jump on them
    c. The little girl will jump
    d. Little baddies will fly around the screen.
    ALSO, as the girl jumps I would like it to look natural
    a. Gravity as she falls down
    b. The correct increment on x and y as she jumps.
    Shouldn't their be an actionscript 3 games forum . anybody know a good site for that?
    Cheers in advance

    OK - I get the message. I should increment x.
    I must have phrased the question wrongly. I'm just looking at optimization techniques so when games go on mobile they work OK.

  • What is a best way to write SQL ?

    Sample Case
    drop table t;
    drop table b;
    create table t ( a varchar2(4), b number, c varchar2(1));
    insert into t values ('A00', 10, 'R');
    insert into t values ('A01', 11, 'R');
    insert into t values ('A02', 12, 'R');
    insert into t values ('A03', 13, 'R');
    insert into t values ('A00', 10, 'P');
    insert into t values ('A01', 11, 'P');
    insert into t values ('A02', 12, 'P');
    insert into t values ('A03', 13, 'P');
    commit;
    create table b ( j varchar(4), k varchar2(1), l varchar2(5), m number(3), n varchar2(5), o number(3));
    insert into b values ('A00', 'P', 'FIXED', 100, 'FLOAT', 60);
    insert into b values ('A01', 'P', 'FIXED', 101, 'FIXED', 30);
    insert into b values ('A02', 'R', 'FLOAT', 45, 'FLOAT', 72);
    insert into b values ('A03', 'R', 'FIXED', 55, 'FLOAT', 53);
    commit;
    10:19:13 SQL> select * from t;
    A B C
    A00 10 R
    A01 11 R
    A02 12 R
    A03 13 R
    A00 10 P
    A01 11 P
    A02 12 P
    A03 13 P
    8 rows selected.
    10:19:19 SQL> select * from b;
    J K L M N O
    A00 P FIXED 100 FLOAT 60
    A01 P FIXED 101 FIXED 30
    A02 R FLOAT 45 FLOAT 72
    A03 R FIXED 55 FLOAT 53
    1/     In table t each reference having 2 records one with P another is with R
    2/     In table b each refrence merged into single record and there are many records which are not existing in table t
    3/      both t and j tables can be joined using a = j
    4/     If from table t for a reference indicator is 'P' then if have to pick up l and m columns, if it is 'R' then I have to pick up n and o columns
    5/     I want output in following format
    A00     P     FIXED          100
    A00     R     FLOAT          60
    A01     P     FIXED          101
    A01     R     FIXED          30
    A02     P     FLOAT          72
    A02     R     FLOAT          45
    A03     P     FLOAT          53
    A03     R     FIXED          55
    6/     Above example is a sample ouput, In above example I have picked up only l,m,n,o columns, but in real example there are many columns ( around 40 ) to be selected. ( using "case when" may not be practical )
    Kindly suggest me what is a best way to write SQL ?
    thanks & regards
    pjp

    Is this?
    select b.j,t.c as k,decode(t.c,'P',l,n) as l,decode(t.c,'P',m,o) as m
    from t,b
    where t.a=b.j
    order by j,k
    J K L M
    A00 P FIXED 100
    A00 R FLOAT 60
    A01 P FIXED 101
    A01 R FIXED 30
    A02 P FLOAT 45
    A02 R FLOAT 72
    A03 P FIXED 55
    A03 R FLOAT 53
    8 rows selected.
    or is this?
    select b.j,t.c as k,decode(t.c,b.k,l,n) as l,decode(t.c,b.k,m,o) as m
    from t,b
    where t.a=b.j
    order by j,k
    J K L M
    A00 P FIXED 100
    A00 R FLOAT 60
    A01 P FIXED 101
    A01 R FIXED 30
    A02 P FLOAT 72
    A02 R FLOAT 45
    A03 P FLOAT 53
    A03 R FIXED 55
    8 rows selected.

  • Best way to write Pl/Sql

    Dear all,
    Can someone say the best way writing below stored proc:
    procedure missing_authorized_services is
    v_truncate_sql varchar2(200);
    v_sql varchar2(2000);
    BEGIN
    v_truncate_sql := 'truncate table missing_authorized_services';
         execute immediate v_truncate_sql;
         commit;
    v_sql := 'INSERT into missing_authorized_services select distinct trim(service_group_Cd) as service_group_Cd, trim(service_cd) as service_cd from stage_1_mg_service_request
    where (service_group_cd, service_cd) not in (
                        select distinct service_group_cd, service_cd from stage_3_servcd_servgrp_dim)';
    execute immediate v_sql;
         commit;
    END missing_authorized_services;
    /* I am doing select from table and then try to Insert into a different table the result set */
    Please guide,
    Thanks
    J

    Hi,
    The best way to write PL/SQL (or any code) is in very small increments.
    Start with a very simple procedure that does something (anything), just enough to test that it's working.
    Add lots of ouput statments so you can see what the procedure is doing. Remember to remove them after testing is finished.
    For example:
    CREATE OR REPLACE procedure missing_authorized_services IS
            v_truncate_sql  VARCHAR2 (200);
    BEGIN
         v_truncate_sql := 'truncate table missing_authorized_services';
         dbms_output.put_line (  v_truncate_sql
                        || ' = v_truncate_sql inside missing_authorized_services'
    END      missing_authorized_services;If you get any errors (for example, ORA-00955, becuase you're trying to give the same name to a procedure that you're already using for a table), then fix the error and try again.
    When it worls perfectly, then add another baby step. For example, you might add the one line
    EXECUTE IMMEDIATE v_truncate_sql;and test again.
    Don't use dynamic SQL (EXECUTE IMMEDIATE) unless you have to.
    Is there any reason to use dynamic SQL for the INSERT?

  • Best way to write an Wrapper class around a POJO

    Hi guys,
    What is the best way to write an Wrapper around a Hibernate POJO, given the latest 2.2 possibilities? The goal is, of course, to map 'regular' Java Bean properties to JavaFX 2 Properties, so that they can be used in GUI.
    Thanks!

    what about this:
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    public class PersonPropertyWrapper {
         private StringProperty firstName;
         private StringProperty lastName;
         private Person _person;
         public PersonPropertyWrapper(Person person) {
              super();
              this._person = person;
              firstName = new SimpleStringProperty(_person.getFirstName()) {
                   @Override
                   protected void invalidated() {
                        _person.setFirstName(getValue());
              lastName = new SimpleStringProperty(_person.getLastName()) {
                   @Override
                   protected void invalidated() {
                        _person.setLastName(getValue());
         public StringProperty firstNameProperty() {
              return firstName;
         public StringProperty lastNameProperty() {
              return lastName;
         public static class Person {
              private String firstName;
              private String lastName;
              public String getFirstName() {
                   return firstName;
              public void setFirstName(String firstName) {
                   this.firstName = firstName;
              public String getLastName() {
                   return lastName;
              public void setLastName(String lastName) {
                   this.lastName = lastName;
         public static void main(String[] args) {
              Person p = new Person();
              p.setFirstName("Jim");
              p.setLastName("Green");
              PersonPropertyWrapper wrapper = new PersonPropertyWrapper(p);
              wrapper.firstNameProperty().setValue("Jerry");
              System.out.println(p.getFirstName());
    }Edited by: 906680 on 2012-7-27 上午10:56

  • Best way to extend wireless via airport express and time capsule

    best way to extend wireless via airport express and time capsule
    i live in a two storey house where i use my airport express to create a wireless network in the main floor, and time capsule to extend it in the upper floor, where my room is. i have like 16 mbps in the main floor, and 2-3 mbps in the upper floor after having speediest.
    i used time capsule in the upper floor because i use wireless backup daily and don't want to put internet down while i im doin it and consequently my parent can have internet access in the main floor, am i right? or do i have make just the opposite in order to have a good internet speed?
    secondly, while checking airport express wireless mode on airport utility, there is like 4 different type of radio mode(802 11n bg comp, 802 11n 2.4, 802 11n a comp, 802 11n 5ghz) which i have no idea what they mean
    what do you recommend?
    we have like iphone4, iphone 3g, mbookpro, ipad, ipad 2, samsung tv and a sony vaio laptop in the wireless network
    thank you

    What you have would appear to be working but I can comment how I would redefine your setup.  Note that both Airport Express and Time Capsule can function as wireless base stations so you do have wireless everywhere and at all times — using the Time Capsules for backups doesn’t mean your parents won’t have internet access regardless of the where the base stations are located.
    You appear to have devices to connect to your network that use the 2.4 GHz band with 802.11g such as the iPhone 3G and perhaps the 5 GHz band with 802.11n such as likely the Macbook Pro if it’s a recent model.  The iPhone 4 can use 5 GHz and 802.11n.  Can’t comment on the Sony and Samsung but you can check their specs.
    Now the Time Capsule (if it’s a recent version), can simultaneously supply 2.4 GHz and 5 GHz band signals, but the Airport Express (if it’s recent) can only use one of those bands at one time.  Likely the lowest common denominator for your devices is going to be the 2.4 GHz band since the devices that are capable of using 5 GHZ also support 2.4 GHz.  If you don’t use 5 GHz, you won’t lose much in a two-storey home because likely it’s the 2.4 GHz band is better signal anyway because 5 GHz signals drop off quickly with several walls/floors to penetrate.
    You also didn’t mention if the Airport Express is used to support a printer and/or AirPlay (using iTunes to play on remote speakers via the Airport Express connection) but that might also be a factor in the best location to place the Airport Express.  Although the printer could be switched between the Time Capsule and the Airport Express if needed, only the Airport Express will support your remote speakers.
    Recommend you use the Time Capsule as the Base station.  When using Airport Utility to define the network, after you name your network, etc., select the Wireless tab, check the box “Allow this network to be extended” and set the Radio Mode to "802.11n (802.11b/g compatible)”.
    Using the Airport Utility, click on the Airport Express; after you define the device and network name, select the Wireless tab, define the Wireless Mode as “Extend a Wireless Network” and check the box “Allow wireless clients”. 
    Hope that helps.

  • What is the best way to do a 10.8 reinstall and keep all of my data?

    What is the best way to do a 10.8 reinstall and keep all of my data?

    Boot to the recovery disk and reinstall the os. That said you do have a back up just in case (I trust)?

  • What is the best way to deal with different audio sample rates on the same timeline ?

    what is the best way to deal with different audio sample rates on the same timeline ?

    You don't have to do anything special. If possible, start your project with a clip that has the desired target frame rate and audio sample rate, and your project parameters will be set automatically. Other sample rates will be converted under the covers.
    For example, if your video is shot at 48khz, you can add music files at 44.1khz with no problem.
    If you are recording audio that you want to synch with video (multicam), you will get best results if everything is 48khz, but you can use 44.1 if that is all you have. Once I forgot to reset my Zoom to 48,000 and it still worked.

  • What is the best way to import word documents from a PC to the Ipad2

    What is the best way to import word documents from a PC to the Ipad 2?

    You first need an app on the iPad that supports word documents - the iPad doesn't have a file structure like a 'normal' computer, and every file/document needs to be associated with an app. If you don't have such an app then options include Apple's Pages app and third-party apps such as Documents To Go and QuickOffice HD. How you then get the documents on the iPad will depend upon the app that you have/get as different apps may use different methods e.g. via the file sharing section at the bottom of the device's apps tab when connected to iTunes, via wifi, email, dropbox etc.

  • My wife has gave me her old ipad what would be the best way to set up her new ipad and to have my own ID?

    My wife has gave me her old ipad what would be the best way to set up her new ipad and to have my own ID?

    Backup the old iPad first, either to itunes or iCloud.
    Once that is done, setup the new iPad from the backup. Choose the Restore from Backup option when setting up the new iPad.
    iOS: How to back up /  Restore
    http://support.apple.com/kb/ht1766
    When that is done, wipe the old iPad clean and set up as new.
    Settings->General->Reset->Erase all Content and Settings
    You can create a new Apple Id when you set up the iPad again.

  • [svn:bz-3.x] 15191: Minor update to the build. xml and only make files write protected with chmod.

    Revision: 15191
    Revision: 15191
    Author:   [email protected]
    Date:     2010-04-01 07:06:21 -0700 (Thu, 01 Apr 2010)
    Log Message:
    Minor update to the build.xml and only make files write protected with chmod.
    Modified Paths:
        blazeds/branches/3.x/modules/sdk/build.xml

    DyNamic I agree that is sounds like you may be facing a network configuration issue.  Please let your network people know that you need access to the following servers and ports to download Adobe applications through the Adobe Application Manager:
    ccmdls.adobe.com:443
    ims-na1.adobelogin.com:443
    na1r.services.adobe.com:443
    prod-rel-ffc-ccm.oobesaas.adobe.com:443
    lm.licenses.adobe.com:443
    In addition for updates to download properly you will also need access to the following servers:
    http://www.adobe.com/:80
    htttp:///swupmf.adobe.com/:80
    http://swupdl.adobe.com/:80
    http://crl.adobe.com/:80

Maybe you are looking for

  • Compressor/FCP quits unexpectedly possibly due to ProMedia plug-in

    Hi all I am sending a finished project to Compressor from FCP, without rendering first. Much of the project is comprised of embedded Motion files. I keep getting a "quit unexpectedly possibly due to the ProMedia plug-in" alert. After repairing the HD

  • How do I fix an Error during Compiling

    Error 1380 occurred at Invoke Node in AB_EXE.lvclass:Build.vi->AB_Engine_Build.vi->AB_Build_Invoke.vi->AB_Build_Invoke.vi.ProxyCaller Possible reason(s): LabVIEW:  (Hex 0x564) License checkout failure.  Unable to checkout the requested license featur

  • How to run a report in SAP

    hi sap gurus can anybody tell me about how to run a report in sap (ABAP). what is the TCode for that one.while i am trying to post asset master it is asking to start a report first and then post. kindly reply me soon thanx in advance

  • Cannot enable keyboard & character viewer

    After a fresh install of 10.7.5, I cannot enable the keyboard & character viewer. Neither the checkbox will stay checked, nor does the option appear in the input sources menu... Any ideas? Thanks, Klaus

  • Repost: Problem in downloading a file from Portal Center

    Hi, I try to access the file http://toolsweb.us.oracle.com/pls/tools/docs/FOLDER/ROOTFOLDER/EIT/EITDOC/DOCDELIVS/DOC_DRAFTS/WEBDBDRAFTS/GS_SITE.ZIP but this server is inaccessible. I can't even ping it. could you please arrange it quickly ? Thanks a