1 7 package org.jboss.security.auth.spi; 8 9 import org.jboss.xb.binding.ObjectModelFactory; 10 import org.jboss.xb.binding.UnmarshallingContext; 11 import org.jboss.logging.Logger; 12 import org.xml.sax.Attributes ; 13 14 18 public class UsersObjectModelFactory implements ObjectModelFactory 19 { 20 private static Logger log = Logger.getLogger(UsersObjectModelFactory.class); 21 22 public Object completeRoot(Object root, UnmarshallingContext ctx, 23 String uri, String name) 24 { 25 return root; 26 } 27 28 public Object newRoot(Object root, UnmarshallingContext navigator, 29 String namespaceURI, String localName, Attributes attrs) 30 { 31 if (!localName.equals("users")) 32 { 33 throw new IllegalStateException ("Unexpected root element: was expecting 'users' but got '" + localName + "'"); 34 } 35 log.trace("newRoot, root="+root); 36 return new Users(); 37 } 38 39 public void setValue(Users users, UnmarshallingContext navigator, 40 String namespaceUri, String localName, String value) 41 { 42 } 43 44 public Object newChild(Users users, UnmarshallingContext navigator, 45 String namespaceUri, String localName, Attributes attrs) 46 { 47 Users.User child = null; 48 if("user".equals(localName)) 49 { 50 String name = attrs.getValue("name"); 51 child = new Users.User(name); 52 String password = attrs.getValue("password"); 53 child.setPassword(password); 54 String encoding = attrs.getValue("encoding"); 55 child.setEncoding(encoding); 56 log.trace("newChild, user="+child); 57 } 58 return child; 59 } 60 61 public void addChild(Users users, Users.User user, 62 UnmarshallingContext navigator, String namespaceURI, String localName) 63 { 64 users.addUser(user); 65 } 66 67 public Object newChild(Users.User user, UnmarshallingContext navigator, 68 String namespaceUri, String localName, Attributes attrs) 69 { 70 String [] roleInfo = {null, "Roles"}; 71 if("role".equals(localName)) 72 { 73 roleInfo[0] = attrs.getValue("name"); 74 roleInfo[1] = attrs.getValue("group"); 75 if( roleInfo[1] == null ) 76 roleInfo[1] = "Roles"; 77 } 78 return roleInfo; 79 } 80 81 public void addChild(Users.User user, String [] roleInfo, 82 UnmarshallingContext navigator, String namespaceURI, String localName) 83 { 84 user.addRole(roleInfo[0], roleInfo[1]); 85 } 86 } 87 | Popular Tags |