<commit_before>/*
 * Copyright  1999-2004 The Apache Software Foundation
 *
 *  Licensed 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.apache.lenya.cms.cocoon.components.modules.input;

import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.transaction.Operation;
import org.apache.lenya.transaction.UnitOfWork;

/**
 * Super class for operation-based input modules.
 *
 * @version $Id$ 
 */
public class OperationModule extends AbstractInputModule implements Operation, Serviceable, Initializable {

    /**
     * Ctor.
     */
    public OperationModule() {
        super();
    }

    private UnitOfWork unitOfWork;
    
    private DocumentIdentityMap documentIdentityMap;
    
    protected DocumentIdentityMap getDocumentIdentityMap() {
        if (this.documentIdentityMap == null) {
            this.documentIdentityMap = new DocumentIdentityMap(this.manager, getLogger());
        }
        return this.documentIdentityMap;
    }

    /**
     * Retrieves a unit-of-work, which gives the operation access to business
     * objects affected by the operation.
     *
     * @return a UnitOfWork, the interface to access the objects
     * @throws ServiceException if the unit-of-work component can not be initialized by the component framework
     *
     * @see org.apache.lenya.transaction.Operation#getUnitOfWork()
     */
    public UnitOfWork getUnitOfWork() throws ServiceException {
        if (this.unitOfWork == null) {
           if (getLogger().isDebugEnabled())
               getLogger().debug("OperationModule.getUnitOfWork() does not yet have instance, looking up role [" + UnitOfWork.ROLE + "]");

           this.unitOfWork = (UnitOfWork) this.manager.lookup(UnitOfWork.ROLE);
           this.unitOfWork.setIdentityMap(getDocumentIdentityMap());
        }

        return this.unitOfWork;
    }


    protected ServiceManager manager;

    /**
     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
     */
    public void service(ServiceManager _manager) throws ServiceException {
        this.manager = _manager;
    }

    /**
     * @see org.apache.avalon.framework.activity.Initializable#initialize()
     */
    public void initialize() throws Exception {
       // do nothing
    }

    /**
     * @see org.apache.avalon.framework.activity.Disposable#dispose()
     */
    public void dispose() {
        if (this.manager != null) {
            if (this.unitOfWork != null) {
                this.manager.release(this.unitOfWork);
            }
        }
    }

    /**
     * @see org.apache.lenya.transaction.Operation#setUnitOfWork(org.apache.lenya.transaction.UnitOfWork)
     */
    public void setUnitOfWork(UnitOfWork unit) {
        this.unitOfWork = unit;
    }
    
}
<commit_msg>[minor change] removed reference to UnitOfWork.ROLE<commit_after>/*
 * Copyright  1999-2004 The Apache Software Foundation
 *
 *  Licensed 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.apache.lenya.cms.cocoon.components.modules.input;

import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.modules.input.AbstractInputModule;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.transaction.Operation;
import org.apache.lenya.transaction.UnitOfWork;
import org.apache.lenya.transaction.UnitOfWorkImpl;

/**
 * Super class for operation-based input modules.
 *
 * @version $Id$ 
 */
public class OperationModule extends AbstractInputModule implements Operation, Serviceable, Initializable {

    /**
     * Ctor.
     */
    public OperationModule() {
        super();
    }

    private UnitOfWork unitOfWork;
    
    private DocumentIdentityMap documentIdentityMap;
    
    protected DocumentIdentityMap getDocumentIdentityMap() {
        if (this.documentIdentityMap == null) {
            this.documentIdentityMap = new DocumentIdentityMap(this.manager, getLogger());
        }
        return this.documentIdentityMap;
    }

    /**
     * Retrieves a unit-of-work, which gives the operation access to business
     * objects affected by the operation.
     *
     * @return a UnitOfWork, the interface to access the objects
     * @throws ServiceException if the unit-of-work component can not be initialized by the component framework
     *
     * @see org.apache.lenya.transaction.Operation#getUnitOfWork()
     */
    public UnitOfWork getUnitOfWork() throws ServiceException {
        if (this.unitOfWork == null) {
           if (getLogger().isDebugEnabled())
               getLogger().debug("OperationModule.getUnitOfWork() does not yet have instance.");

           this.unitOfWork = new UnitOfWorkImpl();
           this.unitOfWork.setIdentityMap(getDocumentIdentityMap());
        }

        return this.unitOfWork;
    }


    protected ServiceManager manager;

    /**
     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
     */
    public void service(ServiceManager _manager) throws ServiceException {
        this.manager = _manager;
    }

    /**
     * @see org.apache.avalon.framework.activity.Initializable#initialize()
     */
    public void initialize() throws Exception {
       // do nothing
    }

    /**
     * @see org.apache.avalon.framework.activity.Disposable#dispose()
     */
    public void dispose() {
        if (this.manager != null) {
            if (this.unitOfWork != null) {
                this.manager.release(this.unitOfWork);
            }
        }
    }

    /**
     * @see org.apache.lenya.transaction.Operation#setUnitOfWork(org.apache.lenya.transaction.UnitOfWork)
     */
    public void setUnitOfWork(UnitOfWork unit) {
        this.unitOfWork = unit;
    }
    
}

{'fraction_non_alphanumeric': 0.0962406015037594, 'fraction_numerical': 0.0032809295967190706, 'mean_word_length': 3.0153677277716793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2773446', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1954, 'n_words': 503}