1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.el;
18
19 import javax.el.ELContext;
20 import javax.el.ELResolver;
21 import javax.el.ExpressionFactory;
22 import javax.el.MethodExpression;
23 import javax.el.ValueExpression;
24
25 import org.apache.el.lang.ELSupport;
26 import org.apache.el.lang.ExpressionBuilder;
27 import org.apache.el.stream.StreamELResolverImpl;
28 import org.apache.el.util.MessageFactory;
29
30
31 /**
32  * @see javax.el.ExpressionFactory
33  *
34  * @author Jacob Hookom [jacob@hookom.net]
35  */

36 public class ExpressionFactoryImpl extends ExpressionFactory {
37
38     /**
39      *
40      */

41     public ExpressionFactoryImpl() {
42         super();
43     }
44
45     @Override
46     public Object coerceToType(Object obj, Class<?> type) {
47         return ELSupport.coerceToType(null, obj, type);
48     }
49
50     @Override
51     public MethodExpression createMethodExpression(ELContext context,
52             String expression, Class<?> expectedReturnType,
53             Class<?>[] expectedParamTypes) {
54         ExpressionBuilder builder = new ExpressionBuilder(expression, context);
55         return builder.createMethodExpression(expectedReturnType,
56                 expectedParamTypes);
57     }
58
59     @Override
60     public ValueExpression createValueExpression(ELContext context,
61             String expression, Class<?> expectedType) {
62         if (expectedType == null) {
63             throw new NullPointerException(MessageFactory
64                     .get("error.value.expectedType"));
65         }
66         ExpressionBuilder builder = new ExpressionBuilder(expression, context);
67         return builder.createValueExpression(expectedType);
68     }
69
70     @Override
71     public ValueExpression createValueExpression(Object instance,
72             Class<?> expectedType) {
73         if (expectedType == null) {
74             throw new NullPointerException(MessageFactory
75                     .get("error.value.expectedType"));
76         }
77         return new ValueExpressionLiteral(instance, expectedType);
78     }
79
80     @Override
81     public ELResolver getStreamELResolver() {
82         return new StreamELResolverImpl();
83     }
84 }
85