diff --git a/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java b/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java index 50221e1fd..13954f113 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java +++ b/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java @@ -12,6 +12,7 @@ import org.osgi.framework.*; import org.w3c.dom.*; + import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.contactlist.event.*; @@ -290,7 +291,8 @@ void start(BundleContext bc, // create the failsafe transaction and restore the file if needed try { - contactlistTrans = new FailSafeTransaction(this.contactlistFile); + contactlistTrans = faService.createFailSafeTransaction( + this.contactlistFile); contactlistTrans.restoreFile(); } catch (NullPointerException e) { logger.error("the contactlist file is null", e); diff --git a/src/net/java/sip/communicator/util/FailSafeTransaction.java b/src/net/java/sip/communicator/impl/fileaccess/FailSafeTransactionImpl.java similarity index 94% rename from src/net/java/sip/communicator/util/FailSafeTransaction.java rename to src/net/java/sip/communicator/impl/fileaccess/FailSafeTransactionImpl.java index 4cd0612b7..29d5ef575 100644 --- a/src/net/java/sip/communicator/util/FailSafeTransaction.java +++ b/src/net/java/sip/communicator/impl/fileaccess/FailSafeTransactionImpl.java @@ -5,18 +5,20 @@ * See terms of license at gnu.org. */ -package net.java.sip.communicator.util; +package net.java.sip.communicator.impl.fileaccess; import java.io.*; +import net.java.sip.communicator.service.fileaccess.*; /** - * A failsafe transaction utility class. By failsafe we mean here that the file + * A failsafe transaction class. By failsafe we mean here that the file * concerned always stays in a coherent state. This class use the transactional * model. * * @author Benoit Pradelle */ -public class FailSafeTransaction +public class FailSafeTransactionImpl + implements FailSafeTransaction { /** @@ -46,7 +48,7 @@ public class FailSafeTransaction * * @throws NullPointerException if the file is null */ - public FailSafeTransaction(File file) + protected FailSafeTransactionImpl(File file) throws NullPointerException { if (file == null) { diff --git a/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java b/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java index 1537c5bfa..1de8ebea0 100644 --- a/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java +++ b/src/net/java/sip/communicator/impl/fileaccess/FileAccessServiceImpl.java @@ -330,5 +330,21 @@ else if (!homedirFile.canWrite()) return file; } + + /** + * Creates a failsafe transaction which can be used to safely store + * informations into a file. + * + * @param file The file concerned by the transaction, null if file is null. + * + * @return A new failsafe transaction related to the given file. + */ + public FailSafeTransaction createFailSafeTransaction(File file) { + if (file == null) { + return null; + } + + return new FailSafeTransactionImpl(file); + } } diff --git a/src/net/java/sip/communicator/service/fileaccess/FileAccessService.java b/src/net/java/sip/communicator/service/fileaccess/FileAccessService.java index 94fd5117d..634932f8e 100644 --- a/src/net/java/sip/communicator/service/fileaccess/FileAccessService.java +++ b/src/net/java/sip/communicator/service/fileaccess/FileAccessService.java @@ -106,4 +106,14 @@ public interface FileAccessService { * directory. */ File getPrivatePersistentDirectory(String[] dirNames) throws Exception; + + /** + * Creates a failsafe transaction which can be used to safely store + * informations into a file. + * + * @param file The file concerned by the transaction, null if file is null. + * + * @return A new failsafe transaction related to the given file. + */ + FailSafeTransaction createFailSafeTransaction(File file); } diff --git a/test/net/java/sip/communicator/slick/fileaccess/FileAccessServiceLick.java b/test/net/java/sip/communicator/slick/fileaccess/FileAccessServiceLick.java index f80a38708..906c9e2c8 100644 --- a/test/net/java/sip/communicator/slick/fileaccess/FileAccessServiceLick.java +++ b/test/net/java/sip/communicator/slick/fileaccess/FileAccessServiceLick.java @@ -39,6 +39,7 @@ public void start(BundleContext bundleContext) properties.put("service.pid", getName()); addTestSuite(TestFileAccessService.class); + addTestSuite(TestFailSafeTransaction.class); bundleContext.registerService(getClass().getName(), this, properties); logger.debug("Successfully registered " + getClass().getName()); diff --git a/test/net/java/sip/communicator/slick/slickless/util/TestFailSafeTransaction.java b/test/net/java/sip/communicator/slick/fileaccess/TestFailSafeTransaction.java similarity index 82% rename from test/net/java/sip/communicator/slick/slickless/util/TestFailSafeTransaction.java rename to test/net/java/sip/communicator/slick/fileaccess/TestFailSafeTransaction.java index 4726d64ce..300829948 100644 --- a/test/net/java/sip/communicator/slick/slickless/util/TestFailSafeTransaction.java +++ b/test/net/java/sip/communicator/slick/fileaccess/TestFailSafeTransaction.java @@ -5,10 +5,14 @@ * See terms of license at gnu.org. */ -package net.java.sip.communicator.slick.slickless.util; +package net.java.sip.communicator.slick.fileaccess; import java.io.*; -import net.java.sip.communicator.util.*; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import net.java.sip.communicator.service.fileaccess.*; import junit.framework.*; /** @@ -19,6 +23,11 @@ public class TestFailSafeTransaction extends TestCase { + /** + * The Service that we will be testing. + */ + private FileAccessService fileAccessService = null; + /** * Test data to write in the original file */ @@ -41,6 +50,19 @@ public class TestFailSafeTransaction */ private static String tempName = "wzsxedcrfv" + System.currentTimeMillis(); + /** + * Standart constructor. + * + * @param name + */ + public TestFailSafeTransaction(String name) + { + super(name); + BundleContext context = FileAccessServiceLick.bc; + ServiceReference ref = context + .getServiceReference(FileAccessService.class.getName()); + this.fileAccessService = (FileAccessService) context.getService(ref); + } /** * Tests the commit operation */ @@ -53,7 +75,8 @@ public void testCommit() { out.write(origData.getBytes()); // write a modification during a transaction - FailSafeTransaction trans = new FailSafeTransaction(temp); + FailSafeTransaction trans = this.fileAccessService + .createFailSafeTransaction(temp); trans.beginTransaction(); out.write(addedData.getBytes()); @@ -97,7 +120,8 @@ public void testRollback() { out.write(origData.getBytes()); // write a modification during a transaction - FailSafeTransaction trans = new FailSafeTransaction(temp); + FailSafeTransaction trans = this.fileAccessService + .createFailSafeTransaction(temp); trans.beginTransaction(); out.write(wrongData.getBytes()); @@ -141,7 +165,8 @@ public void testCommitOnReOpen() { out.write(origData.getBytes()); // write a modification during a transaction - FailSafeTransaction trans = new FailSafeTransaction(temp); + FailSafeTransaction trans = this.fileAccessService + .createFailSafeTransaction(temp); trans.beginTransaction(); out.write(addedData.getBytes()); @@ -190,8 +215,10 @@ public void testRollbackOnFailure() { out.write(origData.getBytes()); // write a modification during a transaction - FailSafeTransaction trans = new FailSafeTransaction(temp); - FailSafeTransaction trans2 = new FailSafeTransaction(temp); + FailSafeTransaction trans = this.fileAccessService + .createFailSafeTransaction(temp); + FailSafeTransaction trans2 = this.fileAccessService + .createFailSafeTransaction(temp); trans.beginTransaction(); out.write(wrongData.getBytes()); diff --git a/test/net/java/sip/communicator/slick/slickless/SlicklessTests.java b/test/net/java/sip/communicator/slick/slickless/SlicklessTests.java index e927afa27..d4eae48a0 100644 --- a/test/net/java/sip/communicator/slick/slickless/SlicklessTests.java +++ b/test/net/java/sip/communicator/slick/slickless/SlicklessTests.java @@ -43,7 +43,6 @@ public void start(BundleContext bundleContext) throws Exception addTestSuite(TestXMLUtils.class); addTestSuite(TestBase64.class); - addTestSuite(TestFailSafeTransaction.class); bundleContext.registerService(getClass().getName(), this, properties); logger.debug("Successfully registered " + getClass().getName());