001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.minilang.method.entityops;
019:
020: import java.util.List;
021:
022: import org.ofbiz.base.util.Debug;
023: import org.ofbiz.entity.GenericEntityException;
024: import org.ofbiz.minilang.SimpleMethod;
025: import org.ofbiz.minilang.method.ContextAccessor;
026: import org.ofbiz.minilang.method.MethodContext;
027: import org.ofbiz.minilang.method.MethodOperation;
028: import org.w3c.dom.Element;
029:
030: /**
031: * Uses the delegator to remove the specified value object (or psuedo-pk) list from the datasource
032: */
033: public class RemoveList extends MethodOperation {
034:
035: public static final String module = RemoveList.class.getName();
036:
037: ContextAccessor listAcsr;
038: String doCacheClearStr;
039:
040: public RemoveList(Element element, SimpleMethod simpleMethod) {
041: super (element, simpleMethod);
042: listAcsr = new ContextAccessor(element
043: .getAttribute("list-name"));
044: doCacheClearStr = element.getAttribute("do-cache-clear");
045: }
046:
047: public boolean exec(MethodContext methodContext) {
048: boolean doCacheClear = !"false".equals(doCacheClearStr);
049:
050: List values = (List) listAcsr.get(methodContext);
051: if (values == null) {
052: String errMsg = "In remove-list a value list was not found with the specified listAcsr: "
053: + listAcsr + ", not removing";
054:
055: Debug.logWarning(errMsg, module);
056: if (methodContext.getMethodType() == MethodContext.EVENT) {
057: methodContext.putEnv(simpleMethod
058: .getEventErrorMessageName(), errMsg);
059: methodContext.putEnv(simpleMethod
060: .getEventResponseCodeName(), simpleMethod
061: .getDefaultErrorCode());
062: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
063: methodContext.putEnv(simpleMethod
064: .getServiceErrorMessageName(), errMsg);
065: methodContext.putEnv(simpleMethod
066: .getServiceResponseMessageName(), simpleMethod
067: .getDefaultErrorCode());
068: }
069: return false;
070: }
071:
072: try {
073: methodContext.getDelegator()
074: .removeAll(values, doCacheClear);
075: } catch (GenericEntityException e) {
076: Debug.logError(e, module);
077: String errMsg = "ERROR: Could not complete the "
078: + simpleMethod.getShortDescription()
079: + " process [problem removing the " + listAcsr
080: + " value list: " + e.getMessage() + "]";
081:
082: if (methodContext.getMethodType() == MethodContext.EVENT) {
083: methodContext.putEnv(simpleMethod
084: .getEventErrorMessageName(), errMsg);
085: methodContext.putEnv(simpleMethod
086: .getEventResponseCodeName(), simpleMethod
087: .getDefaultErrorCode());
088: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
089: methodContext.putEnv(simpleMethod
090: .getServiceErrorMessageName(), errMsg);
091: methodContext.putEnv(simpleMethod
092: .getServiceResponseMessageName(), simpleMethod
093: .getDefaultErrorCode());
094: }
095: return false;
096: }
097: return true;
098: }
099:
100: public String rawString() {
101: // TODO: something more than the empty tag
102: return "<remove-list/>";
103: }
104:
105: public String expandedString(MethodContext methodContext) {
106: // TODO: something more than a stub/dummy
107: return this.rawString();
108: }
109: }
|