Java el-Series -3.1.juel expression factory

Source: Internet
Author: User

Inkfish translation, do not reprint the commercial nature, reproduced please indicate the source (http://blog.csdn.net/inkfish). This article is I study juel at the same time, to the original website carries on the simple translation, the original website address: http://juel.sourceforge.net/guide/basic/factory.html. To tell you the truth, this translation is really not so.

Expression Factory (Expression Factory)

If you want to use EL, you must have an instance of javax.el.ExpressionFactory. An expression factory is used to create multiple types of expressions. The Juel expression factory implementation class is De.odysseus.el.ExpressionFactoryImpl, and the easiest way to get an expression factory instance is to:

Javax.el.ExpressionFactory factory = new De.odysseus.el.ExpressionFactoryImpl ();

The expression factory is thread-safe, allowing an unlimited number of expressions to be created. The expression factory provides the following actions: Provide type cast (coercions) to create a tree-valued expression (expressions) Create an object-valued expression (objects value expressions) Create a tree-method expression (expressions)

Expression Caching

Each factory instance uses its own expression cache. A cached expression is an important feature, because parsing is a relatively expensive operation. An expression caches mapped expression strings to the expression (tree) that they have resolved.

Juel provides a caching interface that allows applications to use their own caching mechanisms. Although, in most cases, the default implementation of Juel should be good enough. The default cache uses the following two mappings: The primary mapping is implemented with JAVA.UTIL.LINKEDHASHMAP, and if the cache is reached, the new entity (entry) is added and the old mapping relationship is removed from the main map with the most recent use principle (LRU). The old mapping relationship is saved to the Level two mapping table. The second-level mapping table is implemented with JAVA.UTIL.WEAKHASHMAP. Entities ensure that lifetimes are at least as long as their string's strong references. The corresponding entity may be reclaimed by the garbage collector when there are no references.

The default constructor uses a cache capacity of 1000, and you can customize the cache size by setting the Javax.el.cacheSize property, such as 5000:

Java.util.Properties Properties = new Java.util.Properties (); Properties.put ("Javax.el.cacheSize", "5000"); Javax.el.ExpressionFactory factory = new De.odysseus.el.ExpressionFactoryImpl (properties);

Use your own caching mechanism to refer to the "Advanced Topics" section.

Type Conversions

In a calculation expression, there are several points that may be type-converted. Cast-value expressions in arithmetic or logical operations cast to the expected type character method expression when created the text that is evaluated is coerced to the type non-character method expression expected at creation, and the last property is cast to the method name (not translated). Conforming an expression to cast all word expressions as strings when connected

All of these casts follow the same rules, which are described in detail in the specification. It supports conversions between strings, characters, Boolean, enumerations, numeric types, and from string conversions to other types using the JavaBeans property editor. The client program can implement the cast rule for El by means of an expression factory approach.

Expressionfactoryimpl.coercetotype (Object, class<?>)

The above code returns an object type. Juel can be configured to use other cast rules, which can be referenced in the "Advanced Topics" section.

Factory Configuration

The factory can be configured through a property file. The following is the mechanism that the expression factory creates when no property is specified, and the query for the property is as follows: java_home/lib/el.properties--If there is a Javax.el.ExpressionFactory property, And the value is De.odysseus.el.ExpressionFactoryImpl, then the Juel is started as the default El; System.getproperties ()--if Rule 1 does not match, The system property sets the value of Javax.el.ExpressionFactory to De.odysseus.el.ExpressionFactoryImpl, setting settings that can override 1; el.properties files anywhere in the Classpath- -the properties set here can override 1 and 20% for default values.

With those above, the next attribute reads: The size of the javax.el.cachesize--expression cache (default is 1000); javax.el.methodinvocations--If set to true means that method calls are allowed. For more information, refer to the "Advanced Topics" section; javax.el.nullproperties--the Null property is resolved if set to true. For more information, refer to the "Advanced Topics" section; javax.el.varargs--if set to True, allows a function/method call with variable variables in an expression.

The factory class also gives a constructor that allows you to accurately convey your attributes. If you just want to change from JEE5 style to JEE6 style, Juel provides enumeration constructors as profiles use.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.