1 7 package org.jboss.test.xml.book; 8 9 import org.jboss.xb.binding.GenericObjectModelProvider; 10 import org.jboss.xb.binding.MarshallingContext; 11 12 16 public class BookGenericObjectModelProvider 17 implements GenericObjectModelProvider 18 { 19 public Object getChildren(Object o, MarshallingContext ctx, String namespaceURI, String localName) 20 { 21 Object 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 getElementValue(Object o, MarshallingContext ctx, String namespaceURI, String localName) 38 { 39 Object 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 getAttributeValue(Object o, MarshallingContext ctx, String namespaceURI, String localName) 76 { 77 Object 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 getRoot(Object o, MarshallingContext ctx, String namespaceURI, String localName) 90 { 91 return o; 92 } 93 } 94 | Popular Tags |