001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.scripting.config; 018 019import org.springframework.beans.factory.xml.NamespaceHandlerSupport; 020 021/** 022 * {@code NamespaceHandler} that supports the wiring of 023 * objects backed by dynamic languages such as Groovy, JRuby and 024 * BeanShell. The following is an example (from the reference 025 * documentation) that details the wiring of a Groovy backed bean: 026 * 027 * <pre class="code"> 028 * <lang:groovy id="messenger" 029 * refresh-check-delay="5000" 030 * script-source="classpath:Messenger.groovy"> 031 * <lang:property name="message" value="I Can Do The Frug"/> 032 * </lang:groovy> 033 * </pre> 034 * 035 * @author Rob Harrop 036 * @author Juergen Hoeller 037 * @author Mark Fisher 038 * @since 2.0 039 */ 040public class LangNamespaceHandler extends NamespaceHandlerSupport { 041 042 @Override 043 public void init() { 044 registerScriptBeanDefinitionParser("groovy", "org.springframework.scripting.groovy.GroovyScriptFactory"); 045 registerScriptBeanDefinitionParser("jruby", "org.springframework.scripting.jruby.JRubyScriptFactory"); 046 registerScriptBeanDefinitionParser("bsh", "org.springframework.scripting.bsh.BshScriptFactory"); 047 registerScriptBeanDefinitionParser("std", "org.springframework.scripting.support.StandardScriptFactory"); 048 registerBeanDefinitionParser("defaults", new ScriptingDefaultsParser()); 049 } 050 051 private void registerScriptBeanDefinitionParser(String key, String scriptFactoryClassName) { 052 registerBeanDefinitionParser(key, new ScriptBeanDefinitionParser(scriptFactoryClassName)); 053 } 054 055}