    001    /*****************************************************************************
    002     * Copyright (C) NanoContainer Organization. All rights reserved.            *
    003     * ------------------------------------------------------------------------- *
    004     * The software in this package is published under the terms of the BSD      *
    005     * style license a copy of which has been included with this distribution in *
    006     * the LICENSE.txt file.                                                     *
    007     *                                                                           *
    008     * Original code by James Strachan                                           *
    009     *****************************************************************************/
    010
    011    package org.nanocontainer.script.groovy.buildernodes;
    012
    013    import java.util.Map;
    014    import java.security.Permission;
    015
    016    import org.nanocontainer.ClassPathElement;
    017    import org.nanocontainer.script.NanoContainerMarkupException;
    018
    019    /**
    020     * @author Paul Hammant
    021     * @version $Revision: 2695 $
    022     */
    023    public class GrantNode extends AbstractBuilderNode {
    024
    025        public static final String NODE_NAME = "grant";
    026
    027        public GrantNode() {
    028            super(NODE_NAME);
    029        }
    030
    031
    032
    033        public Object createNewNode(Object current, Map attributes) {
    034
    035            Permission perm = (Permission) attributes.remove("class");
    036
    037            if (!(current instanceof ClassPathElement)) {
    038                throw new NanoContainerMarkupException("Don't know how to create a 'grant' child of a '" + current.getClass() + "' parent");
    039            }
    040
    041            ClassPathElement cpe = (ClassPathElement) current;
    042
    043            return cpe.grantPermission(perm);
    044        }
    045
    046    }