/*
* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.wso2.carbon.deployment.synchronizer.services;
import org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizationManager;
import org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizer;
import org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizerException;
import org.wso2.carbon.registry.synchronization.SynchronizationException;
public class DeploymentSynchronizerServiceImpl implements DeploymentSynchronizerService {
private DeploymentSynchronizationManager syncManager = DeploymentSynchronizationManager.getInstance();
public boolean synchronizerExists(String filePath) {
return syncManager.getSynchronizer(filePath) != null;
}
public boolean isAutoCommitOn(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
return synchronizer.isAutoCommit();
}
public boolean isAutoCheckoutOn(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
return synchronizer.isAutoCheckout();
}
public long getLastCommitTime(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
return synchronizer.getLastCommitTime();
}
public long getLastCheckoutTime(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
return synchronizer.getLastCheckoutTime();
}
public String getRegistryPath(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
return synchronizer.getRegistryPath();
}
public void checkout(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
try {
synchronizer.checkout();
} catch (SynchronizationException e) {
throw new DeploymentSynchronizerException("Error while invoking checkout on the " +
"repository at: " + filePath, e);
}
}
public void commit(String filePath) throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = getSynchronizer(filePath);
try {
synchronizer.commit();
} catch (SynchronizationException e) {
throw new DeploymentSynchronizerException("Error while invoking commit on the " +
"repository at: " + filePath, e);
}
}
private DeploymentSynchronizer getSynchronizer(String filePath)
throws DeploymentSynchronizerException {
DeploymentSynchronizer synchronizer = syncManager.getSynchronizer(filePath);
if (synchronizer == null) {
throw new DeploymentSynchronizerException("A repository synchronizer has not been " +
"engaged for the file path: " + filePath);
}
return synchronizer;
}
}