KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > expression > ExpressionFactory


1 /*
2 * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/expression/ExpressionFactory.java,v 1.2 2004/07/28 09:48:21 ib Exp $
3 * $Revision: 1.2 $
4 * $Date: 2004/07/28 09:48:21 $
5 *
6 * ====================================================================
7 *
8 * Copyright 1999-2002 The Apache Software Foundation
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 */

23
24 package org.apache.slide.projector.expression;
25
26 import java.util.Iterator JavaDoc;
27
28 import org.jdom.Element;
29
30 /**
31  * The ConditionParser class
32  *
33  */

34 public class ExpressionFactory {
35     public static Expression create(Element element) {
36         String JavaDoc name = element.getName();
37         Expression expression = null;
38         if ( name.equals("and") ) {
39             expression = new AndExpression();
40         } else if ( name.equals("or") ) {
41             expression = new OrExpression();
42         } else if ( name.equals("true") ) {
43             expression = new TrueExpression();
44         } else if ( name.equals("event") ) {
45             String JavaDoc method = element.getAttributeValue("method");
46             expression = new EventExpression(method);
47             for ( Iterator JavaDoc i = element.getChildren().iterator(); i.hasNext(); ) {
48                 Element child = (Element)i.next();
49                 String JavaDoc key = child.getAttributeValue("key");
50                 String JavaDoc value = child.getAttributeValue("value");
51                 ((EventExpression)expression).addProperty(key, value);
52             }
53         }
54         if ( expression instanceof EnclosingExpression ) {
55             for ( Iterator JavaDoc i = element.getChildren().iterator(); i.hasNext(); ) {
56                 Element child = (Element)i.next();
57                 Expression nestedExpression = create(child);
58                 ((EnclosingExpression)expression).addExpression(nestedExpression);
59             }
60         }
61         return expression;
62     }
63 }
Popular Tags