01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.minilang.method.conditional;
19:
20: import org.w3c.dom.*;
21: import org.ofbiz.base.util.*;
22: import org.ofbiz.minilang.*;
23:
24: /**
25: * Creates Conditional objects according to the element that is passed.
26: */
27: public class ConditionalFactory {
28:
29: public static final String module = ConditionalFactory.class
30: .getName();
31:
32: public static Conditional makeConditional(Element element,
33: SimpleMethod simpleMethod) {
34: String tagName = element.getTagName();
35:
36: if ("or".equals(tagName)) {
37: return new CombinedCondition(element, CombinedCondition.OR,
38: simpleMethod);
39: } else if ("xor".equals(tagName)) {
40: return new CombinedCondition(element,
41: CombinedCondition.XOR, simpleMethod);
42: } else if ("and".equals(tagName)) {
43: return new CombinedCondition(element,
44: CombinedCondition.AND, simpleMethod);
45: } else if ("not".equals(tagName)) {
46: return new CombinedCondition(element,
47: CombinedCondition.NOT, simpleMethod);
48: } else if ("if-validate-method".equals(tagName)) {
49: return new ValidateMethodCondition(element);
50: } else if ("if-compare".equals(tagName)) {
51: return new CompareCondition(element, simpleMethod);
52: } else if ("if-compare-field".equals(tagName)) {
53: return new CompareFieldCondition(element, simpleMethod);
54: } else if ("if-empty".equals(tagName)) {
55: return new EmptyCondition(element, simpleMethod);
56: } else if ("if-regexp".equals(tagName)) {
57: return new RegexpCondition(element, simpleMethod);
58: } else if ("if-has-permission".equals(tagName)) {
59: return new HasPermissionCondition(element, simpleMethod);
60: } else {
61: Debug.logWarning("Found an unknown if condition: "
62: + tagName, module);
63: return null;
64: }
65: }
66: }
|