Package org.ofbiz.minilang.method.entityops

Source Code of org.ofbiz.minilang.method.entityops.EntityAnd

/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.minilang.method.entityops;

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.finder.ByAndFinder;
import org.ofbiz.minilang.SimpleMethod;
import org.ofbiz.minilang.method.MethodContext;
import org.ofbiz.minilang.method.MethodOperation;
import org.w3c.dom.Element;

/**
* Uses the delegator to find entity values by a condition
*/
public class EntityAnd extends MethodOperation {
    public static final class EntityAndFactory implements Factory<EntityAnd> {
        public EntityAnd createMethodOperation(Element element, SimpleMethod simpleMethod) {
            return new EntityAnd(element, simpleMethod);
        }

        public String getName() {
            return "entity-and";
        }
    }

    public static final String module = EntityAnd.class.getName();

    protected ByAndFinder finder;

    public EntityAnd(Element element, SimpleMethod simpleMethod) {
        super(element, simpleMethod);
        this.finder = new ByAndFinder(element);
    }

    @Override
    public boolean exec(MethodContext methodContext) {
        try {
            Delegator delegator = methodContext.getDelegator();
            this.finder.runFind(methodContext.getEnvMap(), delegator);
        } catch (GeneralException e) {
            Debug.logError(e, module);
            String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process: " + e.getMessage();

            if (methodContext.getMethodType() == MethodContext.EVENT) {
                methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg);
                methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode());
            } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
                methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg);
                methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode());
            }
            return false;
        }
        return true;
    }

    public String getEntityName() {
        return this.finder.getEntityName();
    }

    @Override
    public String rawString() {
        // TODO: something more than the empty tag
        return "<entity-and/>";
    }
    @Override
    public String expandedString(MethodContext methodContext) {
        // TODO: something more than a stub/dummy
        return this.rawString();
    }
}
TOP

Related Classes of org.ofbiz.minilang.method.entityops.EntityAnd

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.