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.entity.GenericEntityException;
22: import org.ofbiz.entity.GenericValue;
23: import org.ofbiz.minilang.SimpleMethod;
24: import org.ofbiz.minilang.method.ContextAccessor;
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 refresh the specified value object entity from the datasource
31: */
32: public class RefreshValue extends MethodOperation {
33:
34: public static final String module = RemoveValue.class.getName();
35:
36: ContextAccessor valueAcsr;
37: String doCacheClearStr;
38:
39: public RefreshValue(Element element, SimpleMethod simpleMethod) {
40: super (element, simpleMethod);
41: valueAcsr = new ContextAccessor(element
42: .getAttribute("value-name"));
43: doCacheClearStr = element.getAttribute("do-cache-clear");
44: }
45:
46: public boolean exec(MethodContext methodContext) {
47: boolean doCacheClear = !"false".equals(methodContext
48: .expandString(doCacheClearStr));
49:
50: GenericValue value = (GenericValue) valueAcsr
51: .get(methodContext);
52: if (value == null) {
53: String errMsg = "In remove-value a value was not found with the specified valueAcsr: "
54: + valueAcsr + ", not removing";
55: Debug.logWarning(errMsg, module);
56: methodContext.setErrorReturn(errMsg, simpleMethod);
57: return false;
58: }
59:
60: try {
61: methodContext.getDelegator().refresh(value, doCacheClear);
62: } catch (GenericEntityException e) {
63: String errMsg = "ERROR: Could not complete the "
64: + simpleMethod.getShortDescription()
65: + " process [problem removing the " + valueAcsr
66: + " value: " + e.getMessage() + "]";
67: Debug.logError(e, errMsg, module);
68: methodContext.setErrorReturn(errMsg, simpleMethod);
69: return false;
70: }
71: return true;
72: }
73:
74: public String rawString() {
75: // TODO: something more than the empty tag
76: return "<refresh-value/>";
77: }
78:
79: public String expandedString(MethodContext methodContext) {
80: // TODO: something more than a stub/dummy
81: return this.rawString();
82: }
83: }
|