01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Original code by James Strachan *
09: *****************************************************************************/package org.nanocontainer.script.groovy.buildernodes;
10:
11: import java.util.Map;
12: import java.security.Permission;
13:
14: import org.nanocontainer.ClassPathElement;
15: import org.nanocontainer.script.NanoContainerMarkupException;
16:
17: /**
18: * @author Paul Hammant
19: * @version $Revision: 2695 $
20: */
21: public class GrantNode extends AbstractBuilderNode {
22:
23: public static final String NODE_NAME = "grant";
24:
25: public GrantNode() {
26: super (NODE_NAME);
27: }
28:
29: public Object createNewNode(Object current, Map attributes) {
30:
31: Permission perm = (Permission) attributes.remove("class");
32:
33: if (!(current instanceof ClassPathElement)) {
34: throw new NanoContainerMarkupException(
35: "Don't know how to create a 'grant' child of a '"
36: + current.getClass() + "' parent");
37: }
38:
39: ClassPathElement cpe = (ClassPathElement) current;
40:
41: return cpe.grantPermission(perm);
42: }
43:
44: }
|