Solved

Xstream question and java object

Posted on 2010-08-22
6
330 Views
Last Modified: 2012-05-10
I am looking to build java objects

<placement_rules>
  <section name="news">
    <front_order>
       <article_type name="article1"></article_type>
       <article_type name="article2"></article_type>
    </front_order>
    <back_order>
       <article_type name="article3"></article_type>
    </back_order>
  </section>
  <section name="sports">
    <front_order>
      <article_type name="article4"></article_type>
    </front_order>
    <back_order>
      <article_type name="article5"></article_type>
      <article_type name="article6"></article_type>
    </back_order>
  </section>
</placement_rules>

Open in new window


What are the objects that i need to create?

i am starting from inside SectionRule.java
@XStreamAsAttribute
@XStreamAlias("name")
private String sectionName;

@XStreamAlias("front_order")
private List<ConfigPlacementNode> frontOrder = new ArrayList<ConfigPlacementNode>(0);

@XStreamAlias("back_order")
private List<ConfigPlacementNode> backOrder = new ArrayList<ConfigPlacementNode>(0);

Open in new window


how do i create other first class objects around it? any help will be highly appreciated.

Regards, Amar
0
Comment
Question by:Amar-ms
  • 4
  • 2
6 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33497322
It has been a while since I looked at XStream, but I don't think you want XStreamAsAttribute there since the results are in elements. You would just surround these with class that represents PlacementRules. And what you have underneath is a Section class that has in it a FrontOrder and BackOrder class that has within it a List. Again I will have to do a quick refresher on XStream if that doesn't make sense to test it out, but believe that is what you are looking for.

The tutorials are pretty decent on the site by the way:
http://xstream.codehaus.org/

Kevin
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33497327
And actually to be more precise, I would create an Order class with List then in your Section class you have two different variables: front and back. Those variables get aliases to the respective XML nodes.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33497495
Okay, I tested it and should work the way I said for you pending you tweak it for your own liking of object functionality and resulting xml but to get what you showed above I used:

@XStreamAlias("article_type")
class ArticleType {
    @XStreamAlias("name")
    @XStreamAsAttribute
    Private String name;

    // ...
}

class Order {
    @XStreamImplicit(itemFieldName="article_type")
    List articleTypes;

    // ...
}

class Section {
    // contains String (name) and two Order (front, back) members
}

class PlacementRules {
    // contains List
}

Figured that should be enough for you to give this a try. You should be able to learn more that way and with the tutorial than me giving you what I had which I threw together quick and dirty to test. You will want your code to be more appropriate to your functionality.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Amar-ms
ID: 33497818
thanks a lot i will try it and let you know.. this should be a good starting point for me.
0
 

Author Closing Comment

by:Amar-ms
ID: 33506431
Thanks a lot for your help it worked great. tjhanks for taking time out.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33506686
You are most welcome!
Best regards and happy coding,
Kevin
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Restore security prompts not working 10 110
ASP and Extracting XML 7 24
How to log java errors in tomcat 8 23
ASP Classic - Read XML File inner content 10 42
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question