01: /**
02: * MVEL (The MVFLEX Expression Language)
03: *
04: * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * 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, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: */package org.mvel.integration;
19:
20: /**
21: * A set of tools for dealing with factorys, specifically to make chaining issues easy to deal with.
22: *
23: * @author Christopher Brock
24: */
25: public class ResolverTools {
26: /**
27: * Based on a root factory, append the new factory to the end of the chain.
28: *
29: * @param root The root factory
30: * @param newFactory The new factory
31: * @return An instance of the new factory
32: */
33: public static <T extends VariableResolverFactory> T appendFactory(
34: VariableResolverFactory root, T newFactory) {
35: if (root.getNextFactory() == null) {
36: root.setNextFactory(newFactory);
37: } else {
38: VariableResolverFactory vrf = root;
39:
40: while (vrf.getNextFactory() != null) {
41: vrf = vrf.getNextFactory();
42: }
43: vrf.setNextFactory(newFactory);
44: }
45:
46: return newFactory;
47: }
48:
49: /**
50: * Based on the root factory, insert the new factory right after the root, and before any other in the chain.
51: *
52: * @param root The root factory
53: * @param newFactory The new factory
54: * @return An instance of the new factory.
55: */
56: public static <T extends VariableResolverFactory> T insertFactory(
57: VariableResolverFactory root, T newFactory) {
58: if (root.getNextFactory() == null) {
59: root.setNextFactory(newFactory);
60: } else {
61: newFactory.setNextFactory(root.getNextFactory());
62: root.setNextFactory(newFactory);
63: }
64:
65: return newFactory;
66: }
67: }
|