001: /*
002: * $Id: RemoveList.java,v 1.1 2003/08/17 06:06:11 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024: package org.ofbiz.minilang.method.entityops;
025:
026: import java.util.List;
027:
028: import org.ofbiz.base.util.Debug;
029: import org.ofbiz.entity.GenericEntityException;
030: import org.ofbiz.minilang.SimpleMethod;
031: import org.ofbiz.minilang.method.ContextAccessor;
032: import org.ofbiz.minilang.method.MethodContext;
033: import org.ofbiz.minilang.method.MethodOperation;
034: import org.w3c.dom.Element;
035:
036: /**
037: * Uses the delegator to remove the specified value object (or psuedo-pk) list from the datasource
038: *
039: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
040: * @version $Revision: 1.1 $
041: * @since 2.0
042: */
043: public class RemoveList extends MethodOperation {
044:
045: public static final String module = RemoveList.class.getName();
046:
047: ContextAccessor listAcsr;
048: String doCacheClearStr;
049:
050: public RemoveList(Element element, SimpleMethod simpleMethod) {
051: super (element, simpleMethod);
052: listAcsr = new ContextAccessor(element
053: .getAttribute("list-name"));
054: doCacheClearStr = element.getAttribute("do-cache-clear");
055: }
056:
057: public boolean exec(MethodContext methodContext) {
058: boolean doCacheClear = !"false".equals(doCacheClearStr);
059:
060: List values = (List) listAcsr.get(methodContext);
061: if (values == null) {
062: String errMsg = "In remove-list a value list was not found with the specified listAcsr: "
063: + listAcsr + ", not removing";
064:
065: Debug.logWarning(errMsg, module);
066: if (methodContext.getMethodType() == MethodContext.EVENT) {
067: methodContext.putEnv(simpleMethod
068: .getEventErrorMessageName(), errMsg);
069: methodContext.putEnv(simpleMethod
070: .getEventResponseCodeName(), simpleMethod
071: .getDefaultErrorCode());
072: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
073: methodContext.putEnv(simpleMethod
074: .getServiceErrorMessageName(), errMsg);
075: methodContext.putEnv(simpleMethod
076: .getServiceResponseMessageName(), simpleMethod
077: .getDefaultErrorCode());
078: }
079: return false;
080: }
081:
082: try {
083: methodContext.getDelegator()
084: .removeAll(values, doCacheClear);
085: } catch (GenericEntityException e) {
086: Debug.logError(e, module);
087: String errMsg = "ERROR: Could not complete the "
088: + simpleMethod.getShortDescription()
089: + " process [problem removing the " + listAcsr
090: + " value list: " + e.getMessage() + "]";
091:
092: if (methodContext.getMethodType() == MethodContext.EVENT) {
093: methodContext.putEnv(simpleMethod
094: .getEventErrorMessageName(), errMsg);
095: methodContext.putEnv(simpleMethod
096: .getEventResponseCodeName(), simpleMethod
097: .getDefaultErrorCode());
098: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
099: methodContext.putEnv(simpleMethod
100: .getServiceErrorMessageName(), errMsg);
101: methodContext.putEnv(simpleMethod
102: .getServiceResponseMessageName(), simpleMethod
103: .getDefaultErrorCode());
104: }
105: return false;
106: }
107: return true;
108: }
109: }
|