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 java.util.Map;
21:
22: import org.ofbiz.base.util.Debug;
23: import org.ofbiz.entity.GenericEntityException;
24: import org.ofbiz.minilang.SimpleMethod;
25: import org.ofbiz.minilang.method.ContextAccessor;
26: import org.ofbiz.minilang.method.MethodContext;
27: import org.ofbiz.minilang.method.MethodOperation;
28: import org.w3c.dom.Element;
29:
30: /**
31: * Uses the delegator to remove entity values constrained by anding the map fields
32: */
33: public class RemoveByAnd extends MethodOperation {
34:
35: public static final String module = RemoveByAnd.class.getName();
36:
37: String entityName;
38: ContextAccessor mapAcsr;
39: String doCacheClearStr;
40:
41: public RemoveByAnd(Element element, SimpleMethod simpleMethod) {
42: super (element, simpleMethod);
43: entityName = element.getAttribute("entity-name");
44: mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
45: doCacheClearStr = element.getAttribute("do-cache-clear");
46: }
47:
48: public boolean exec(MethodContext methodContext) {
49: boolean doCacheClear = !"false".equals(doCacheClearStr);
50: String entityName = methodContext.expandString(this .entityName);
51:
52: try {
53: methodContext.getDelegator().removeByAnd(entityName,
54: (Map) mapAcsr.get(methodContext), doCacheClear);
55: } catch (GenericEntityException e) {
56: Debug.logError(e, module);
57: String errMsg = "ERROR: Could not complete the "
58: + simpleMethod.getShortDescription()
59: + " process [problem removing the " + entityName
60: + " entity by and: " + e.getMessage() + "]";
61:
62: if (methodContext.getMethodType() == MethodContext.EVENT) {
63: methodContext.putEnv(simpleMethod
64: .getEventErrorMessageName(), errMsg);
65: methodContext.putEnv(simpleMethod
66: .getEventResponseCodeName(), simpleMethod
67: .getDefaultErrorCode());
68: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
69: methodContext.putEnv(simpleMethod
70: .getServiceErrorMessageName(), errMsg);
71: methodContext.putEnv(simpleMethod
72: .getServiceResponseMessageName(), simpleMethod
73: .getDefaultErrorCode());
74: }
75: return false;
76: }
77: return true;
78: }
79:
80: public String rawString() {
81: // TODO: something more than the empty tag
82: return "<remove-by-and/>";
83: }
84:
85: public String expandedString(MethodContext methodContext) {
86: // TODO: something more than a stub/dummy
87: return this.rawString();
88: }
89: }
|