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.entityops;
19:
20: import org.ofbiz.base.util.Debug;
21: import org.ofbiz.base.util.GeneralException;
22: import org.ofbiz.entity.GenericDelegator;
23: import org.ofbiz.entity.finder.ByConditionFinder;
24: import org.ofbiz.minilang.SimpleMethod;
25: import org.ofbiz.minilang.method.MethodContext;
26: import org.ofbiz.minilang.method.MethodOperation;
27: import org.w3c.dom.Element;
28:
29: /**
30: * Uses the delegator to find entity values by a condition
31: */
32: public class EntityCondition extends MethodOperation {
33:
34: public static final String module = EntityCondition.class.getName();
35:
36: protected ByConditionFinder finder;
37:
38: public EntityCondition(Element element, SimpleMethod simpleMethod) {
39: super (element, simpleMethod);
40: this .finder = new ByConditionFinder(element);
41: }
42:
43: public boolean exec(MethodContext methodContext) {
44: try {
45: GenericDelegator delegator = methodContext.getDelegator();
46: this .finder.runFind(methodContext.getEnvMap(), delegator);
47: } catch (GeneralException e) {
48: Debug.logError(e, module);
49: String errMsg = "ERROR: Could not complete the "
50: + simpleMethod.getShortDescription() + " process: "
51: + e.getMessage();
52:
53: if (methodContext.getMethodType() == MethodContext.EVENT) {
54: methodContext.putEnv(simpleMethod
55: .getEventErrorMessageName(), errMsg);
56: methodContext.putEnv(simpleMethod
57: .getEventResponseCodeName(), simpleMethod
58: .getDefaultErrorCode());
59: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
60: methodContext.putEnv(simpleMethod
61: .getServiceErrorMessageName(), errMsg);
62: methodContext.putEnv(simpleMethod
63: .getServiceResponseMessageName(), simpleMethod
64: .getDefaultErrorCode());
65: }
66: return false;
67: }
68: return true;
69: }
70:
71: public String rawString() {
72: // TODO: something more than the empty tag
73: return "<entity-condition/>";
74: }
75:
76: public String expandedString(MethodContext methodContext) {
77: // TODO: something more than a stub/dummy
78: return this.rawString();
79: }
80: }
|