Jsr223LanguageAdapter.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:scripturian 作者:
/**
 * Constructor. Uses the JSR-223 script engine factory to gather the
 * language adapter attributes. Sub-classes must be annotated with
 * {@link ScriptEngines}.
 * 
 * @throws LanguageAdapterException
 */
public Jsr223LanguageAdapter() throws LanguageAdapterException
{
    ScriptEngines scriptEngineNames = getClass().getAnnotation( ScriptEngines.class );
    if( scriptEngineNames == null )
        throw new LanguageAdapterException( getClass(), getClass().getCanonicalName() + " does not have a ScriptEngines annotation" );

    String scriptEngineName = scriptEngineNames.value()[0];
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    scriptEngine = scriptEngineManager.getEngineByName( scriptEngineName );
    if( scriptEngine == null )
        throw new LanguageAdapterException( getClass(), getClass().getCanonicalName() + " could not load ScriptEngine " + scriptEngineName );

    ScriptEngineFactory factory = scriptEngine.getFactory();

    attributes.put( NAME, "JSR-223/" + factory.getEngineName() );
    attributes.put( VERSION, factory.getEngineVersion() );
    attributes.put( LANGUAGE_NAME, factory.getLanguageName() );
    attributes.put( LANGUAGE_VERSION, factory.getLanguageVersion() );
    attributes.put( EXTENSIONS, new ArrayList<String>( factory.getExtensions() ) );
    attributes.put( DEFAULT_EXTENSION, factory.getExtensions().get( 0 ) );
    attributes.put( TAGS, Arrays.asList( scriptEngineNames.value() ) );
    attributes.put( DEFAULT_TAG, factory.getNames().get( 0 ) );

    attributes.put( JSR223_SCRIPT_ENGINE_NAME, scriptEngineName );
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号