/*
 * 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.repository;

import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.Identity;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.transaction.IdentityMapImpl;

/**
 * Repository manager implementation.
 * @version $Id:$
 */
public class RepositoryManagerImpl extends AbstractLogEnabled implements RepositoryManager,
        Serviceable {

    public void copy(Node source, Node destination) throws RepositoryException {

        SourceResolver resolver = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
            String[] namespaces = source.getMetaDataNamespaceUris();
            for (int i = 0; i < namespaces.length; i++) {
                destination.getMetaData(namespaces[i]).replaceBy(source.getMetaData(namespaces[i]));
            }
            SourceUtil.copy(resolver, source.getSourceURI(), destination.getSourceURI());
        } catch (Exception e) {
            throw new RepositoryException(e);
        } finally {
            if (resolver != null) {
                this.manager.release(resolver);
            }
        }
    }

    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.lenya.cms.repository.RepositoryManager#delete(org.apache.lenya.cms.repository.Node)
     */
    public void delete(Node node) throws RepositoryException {
        if (!node.isLocked()) {
            throw new RuntimeException("Cannot delete node [" + node + "]: not locked!");
        } else {
            node.registerRemoved();
        }
    }

    public Session createSession(Identity identity) throws RepositoryException {
        return new SessionImpl(new IdentityMapImpl(getLogger()), identity, getLogger());
    }

}

@@ -2521,151 +2521,8 @@
 n %7B%0A
-        if (!node.isLocked()) %7B%0A            throw new RuntimeException(%22Cannot delete node %5B%22 + node + %22%5D: not locked!%22);%0A        %7D else %7B%0A    
     
@@ -2549,26 +2549,16 @@
 oved();%0A
-        %7D%0A
     %7D%0A%0A 

Allow to delete nodes without locking.