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    
012    import org.picocontainer.classname.ClassPathElement;
013    import org.picocontainer.classname.ClassLoadingPicoContainer;
014    import org.picocontainer.script.util.ClassPathElementHelper;
015    
016    
017    /**
018     * @author James Strachan
019     * @author Paul Hammant
020     * @author Aslak Hellesøy
021     * @author Michael Rimov
022     * @author Mauro Talevi
023     */
024    @SuppressWarnings("serial")
025    public class ClasspathNode extends AbstractBuilderNode {
026    
027        public static final String NODE_NAME = "classPathElement";
028    
029    
030        private static final String PATH = "path";
031    
032    
033        public ClasspathNode() {
034            super(NODE_NAME);
035    
036            addAttribute(PATH);
037        }
038    
039    
040        @SuppressWarnings("unchecked")
041        public Object createNewNode(Object current, Map attributes) {
042            return createClassPathElementNode(attributes, (ClassLoadingPicoContainer) current);
043        }
044    
045        @SuppressWarnings("unchecked")
046        private ClassPathElement createClassPathElementNode(Map attributes, ClassLoadingPicoContainer container) {
047    
048            final String path = (String) attributes.remove(PATH);
049            return ClassPathElementHelper.addClassPathElement(path, container);
050        }
051    
052    }