01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */
18:
19: /* $Id: ConditionFactory.java 473861 2006-11-12 03:51:14Z gregor $ */
20:
21: package org.apache.lenya.workflow.impl;
22:
23: import org.apache.avalon.framework.container.ContainerUtil;
24: import org.apache.avalon.framework.logger.AbstractLogEnabled;
25: import org.apache.avalon.framework.logger.Logger;
26: import org.apache.lenya.workflow.Condition;
27: import org.apache.lenya.workflow.WorkflowException;
28:
29: /**
30: * Factory to build conditions.
31: */
32: public final class ConditionFactory extends AbstractLogEnabled {
33:
34: /**
35: * Ctor.
36: * @param logger The logger to use.
37: */
38: public ConditionFactory(Logger logger) {
39: ContainerUtil.enableLogging(this , logger);
40: }
41:
42: /**
43: * Creates a condition.
44: * @param className The condition class name.
45: * @param expression The condition expression.
46: * @return A condition.
47: * @throws WorkflowException when creating the condition failed.
48: */
49: protected Condition createCondition(String className,
50: String expression) throws WorkflowException {
51:
52: Condition condition;
53:
54: try {
55: Class clazz = Class.forName(className);
56: condition = (Condition) clazz.newInstance();
57: ContainerUtil.enableLogging(condition, getLogger());
58: condition.setExpression(expression);
59: } catch (ClassNotFoundException e) {
60: throw new WorkflowException(e);
61: } catch (InstantiationException e) {
62: throw new WorkflowException(e);
63: } catch (IllegalAccessException e) {
64: throw new WorkflowException(e);
65: }
66:
67: return condition;
68: }
69: }
|