KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > auth > spi > UsersObjectModelFactory


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.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 JavaDoc;
13
14 /** A JBossXB object factory for parsing the
15  * @author Scott.Stark@jboss.org
16  * @version $Revision: 1.1.2.4 $
17  */

18 public class UsersObjectModelFactory implements ObjectModelFactory
19 {
20    private static Logger log = Logger.getLogger(UsersObjectModelFactory.class);
21
22    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx,
23          String JavaDoc uri, String JavaDoc name)
24    {
25       return root;
26    }
27
28    public Object JavaDoc newRoot(Object JavaDoc root, UnmarshallingContext navigator,
29       String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
30    {
31       if (!localName.equals("users"))
32       {
33          throw new IllegalStateException JavaDoc("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 JavaDoc namespaceUri, String JavaDoc localName, String JavaDoc value)
41    {
42    }
43
44    public Object JavaDoc newChild(Users users, UnmarshallingContext navigator,
45       String JavaDoc namespaceUri, String JavaDoc localName, Attributes JavaDoc attrs)
46    {
47       Users.User child = null;
48       if("user".equals(localName))
49       {
50          String JavaDoc name = attrs.getValue("name");
51          child = new Users.User(name);
52          String JavaDoc password = attrs.getValue("password");
53          child.setPassword(password);
54          String JavaDoc 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 JavaDoc namespaceURI, String JavaDoc localName)
63    {
64       users.addUser(user);
65    }
66
67    public Object JavaDoc newChild(Users.User user, UnmarshallingContext navigator,
68       String JavaDoc namespaceUri, String JavaDoc localName, Attributes JavaDoc attrs)
69    {
70       String JavaDoc[] 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 JavaDoc[] roleInfo,
82       UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
83    {
84       user.addRole(roleInfo[0], roleInfo[1]);
85    }
86 }
87
Popular Tags