KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > book > BookGenericObjectModelProvider


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.xml.book;
8
9 import org.jboss.xb.binding.GenericObjectModelProvider;
10 import org.jboss.xb.binding.MarshallingContext;
11
12 /**
13  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
14  * @version <tt>$Revision: 1.2.2.2 $</tt>
15  */

16 public class BookGenericObjectModelProvider
17    implements GenericObjectModelProvider
18 {
19    public Object JavaDoc getChildren(Object JavaDoc o, MarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
20    {
21       Object JavaDoc children = null;
22       if(o instanceof Book)
23       {
24          Book book = (Book)o;
25          if(localName.equals("character"))
26          {
27             children = book.getCharacters();
28          }
29          else if(localName.equals("book"))
30          {
31             children = book;
32          }
33       }
34       return children;
35    }
36
37    public Object JavaDoc getElementValue(Object JavaDoc o, MarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
38    {
39       Object JavaDoc value = null;
40       if(o instanceof Book)
41       {
42          Book book = (Book)o;
43          if("title".equals(localName))
44          {
45             value = book.getTitle();
46          }
47          else if("author".equals(localName))
48          {
49             value = book.getAuthor();
50          }
51       }
52       else if(o instanceof BookCharacter)
53       {
54          BookCharacter character = (BookCharacter)o;
55          if("name".equals(localName))
56          {
57             value = character.getName();
58          }
59          else if("friend-of".equals(localName))
60          {
61             value = character.getFriendOf();
62          }
63          else if("since".equals(localName))
64          {
65             value = character.getSince();
66          }
67          else if("qualification".equals(localName))
68          {
69             value = character.getQualification();
70          }
71       }
72       return value;
73    }
74
75    public Object JavaDoc getAttributeValue(Object JavaDoc o, MarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
76    {
77       Object JavaDoc value = null;
78       if(o instanceof Book)
79       {
80          Book book = (Book)o;
81          if("isbn".equals(localName))
82          {
83             value = book.getIsbn();
84          }
85       }
86       return value;
87    }
88
89    public Object JavaDoc getRoot(Object JavaDoc o, MarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
90    {
91       return o;
92    }
93 }
94
Popular Tags