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