?
Solved

Xstream question and java object

Posted on 2010-08-22
6
Medium Priority
?
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 60

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 60

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 60

Accepted Solution

by:
Kevin Cross earned 2000 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 60

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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