/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */
package org.objectweb.jonas.security.rules;

import org.apache.commons.digester.Digester;

import org.objectweb.jonas_lib.deployment.rules.JRuleSetBase;


/**
 * Add the rules for the memory in the jonas-realm.xml file
 *
 * @author Guillaume Sauthier
 */
public class JMemoryRuleSet extends JRuleSetBase {

    /**
     * Construct an object with a specific prefix
     * @param prefix prefix to use during the parsing
     */
    public JMemoryRuleSet(String prefix) {
        super(prefix);
   }
     /**
     * Add a set of rules to the digester object
     * @param digester Digester instance
     */
    public void addRuleInstances(Digester digester) {
        // Configure the actions we will be using
        digester.addObjectCreate(prefix + "memoryrealm",
                                 "org.objectweb.jonas.security.realm.factory.JResourceMemory");

        digester.addSetProperties(prefix + "memoryrealm");
        digester.addSetNext(prefix + "memoryrealm",
                            "addJResource",
                            "org.objectweb.jonas.security.realm.factory.JResource");

        digester.addObjectCreate(prefix + "memoryrealm/roles/role",
                                 "org.objectweb.jonas.security.realm.principals.Role");
        digester.addSetProperties(prefix + "memoryrealm/roles/role");
        digester.addSetNext("memoryrealm/roles/role",
                            "addRole",
                            "org.objectweb.jonas.security.realm.principals.Role");

        digester.addObjectCreate(prefix + "memoryrealm/groups/group",
                                 "org.objectweb.jonas.security.realm.principals.Group");
        digester.addSetProperties(prefix + "memoryrealm/groups/group");
        digester.addSetNext(prefix + "memoryrealm/groups/group",
                            "addGroup",
                            "org.objectweb.jonas.security.realm.principals.Group");

        digester.addObjectCreate(prefix + "memoryrealm/users/user",
                                 "org.objectweb.jonas.security.realm.principals.User");
        digester.addSetProperties(prefix + "memoryrealm/users/user");
        digester.addSetNext(prefix + "memoryrealm/users/user",
                            "addUser",
                            "org.objectweb.jonas.security.realm.principals.User");
    }

}
