// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/InsufficientCapacityException.java
// public class InsufficientCapacityException extends Exception {
// 
//     public InsufficientCapacityException() {
//     }
// 
//     public InsufficientCapacityException(String message) {
//         super(message);
//     }
// 
//     public InsufficientCapacityException(StackTraceElement[] stackTraceElements) {
//         setStackTrace(stackTraceElements);
//     }
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/ReadOnlyTagException.java
// public class ReadOnlyTagException extends TagNotWritableException {
// 
//     public ReadOnlyTagException() {
//     }
// 
//     public ReadOnlyTagException(String message) {
//         super(message);
//     }
// 
// 
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NdefWrite.java
// public interface NdefWrite {
//     /**
//      * Write message to ndef
//      *
//      * @param message
//      *         to write
//      * @param ndef
//      *         from tag to write to
//      *
//      * @return true if success, false if ndef == null || message == null
//      *
//      * @throws ReadOnlyTagException
//      *         if tag is read-only
//      * @throws InsufficientCapacityException
//      *         if the tag's capacity is not sufficient
//      * @throws FormatException
//      *         if the message is malformed
//      */
//     boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write message to ndef and make readonly
//      *
//      * @see NdefWrite#writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
//      */
//     boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable
//      * @param message to write
//      * @param ndefFormatable to write to
//      * @return true if success, false if ndefFormatable == null || message == null
//      * @throws FormatException
//      */
//     boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable and make readonly
//      * @see NdefWrite#writeToNdefFormatable(android.nfc.NdefMessage, android.nfc.tech.NdefFormatable)
//      */
//     boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException;
// 
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/WriteUtility.java
// public interface WriteUtility extends NdefWrite {
// 
// 
//     /**
//      * Writes towards a {@link android.nfc.Tag}
//      *
//      * @param message
//      *         to write
//      * @param tag
//      *         to write to
//      *
//      * @return true if success
//      *
//      * @see #writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
//      */
//     boolean writeSafelyToTag(NdefMessage message, Tag tag);
// 
//     /**
//      * Write the given message to the tag
//      *
//      * @param message
//      *         to write
//      * @param tag
//      *         to write to
//      *
//      * @return true if success
//      *
//      * @throws android.nfc.FormatException if the message is in an incorrect format
//      * @throws be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException if there is not enough space available on the tag
//      * @throws be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException when attempting to write to a read-only tag
//      */
//     boolean writeToTag(NdefMessage message, Tag tag) throws FormatException, ReadOnlyTagException, InsufficientCapacityException;
// 
//     /**
//      * Used to mark the following operation as readonly
//      * @return an instance of WriteUtility in order to chain
//      */
//     WriteUtility makeOperationReadOnly();
// }


import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
import be.appfoundry.nfclibrary.utilities.interfaces.WriteUtility;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.util.Log;
import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;
/*
 * WriteUtilityImpl.java
 * NfcLibrary project.
 *
 * Created by : Daneo van Overloop - 17/6/2014.
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 AppFoundry. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 */

package be.appfoundry.nfclibrary.utilities.sync;



/**
 * @author Daneo Van Overloop
 * NfcLibrary
 * Created on 11/04/14.
 */
public class WriteUtilityImpl implements WriteUtility {

    private static final String TAG = WriteUtilityImpl.class.getName();

    private boolean readOnly = false;

// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/InsufficientCapacityException.java
// public class InsufficientCapacityException extends Exception {
// 
//     public InsufficientCapacityException() {
//     }
// 
//     public InsufficientCapacityException(String message) {
//         super(message);
//     }
// 
//     public InsufficientCapacityException(StackTraceElement[] stackTraceElements) {
//         setStackTrace(stackTraceElements);
//     }
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/exceptions/ReadOnlyTagException.java
// public class ReadOnlyTagException extends TagNotWritableException {
// 
//     public ReadOnlyTagException() {
//     }
// 
//     public ReadOnlyTagException(String message) {
//         super(message);
//     }
// 
// 
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NdefWrite.java
// public interface NdefWrite {
//     /**
//      * Write message to ndef
//      *
//      * @param message
//      *         to write
//      * @param ndef
//      *         from tag to write to
//      *
//      * @return true if success, false if ndef == null || message == null
//      *
//      * @throws ReadOnlyTagException
//      *         if tag is read-only
//      * @throws InsufficientCapacityException
//      *         if the tag's capacity is not sufficient
//      * @throws FormatException
//      *         if the message is malformed
//      */
//     boolean writeToNdef(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write message to ndef and make readonly
//      *
//      * @see NdefWrite#writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
//      */
//     boolean writeToNdefAndMakeReadonly(NdefMessage message, Ndef ndef) throws ReadOnlyTagException, InsufficientCapacityException, FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable
//      * @param message to write
//      * @param ndefFormatable to write to
//      * @return true if success, false if ndefFormatable == null || message == null
//      * @throws FormatException
//      */
//     boolean writeToNdefFormatable(NdefMessage message, NdefFormatable ndefFormatable) throws FormatException;
// 
//     /**
//      * Write the message to an NdefFormatable and make readonly
//      * @see NdefWrite#writeToNdefFormatable(android.nfc.NdefMessage, android.nfc.tech.NdefFormatable)
//      */
//     boolean writeToNdefFormatableAndMakeReadonly(NdefMessage message, NdefFormatable ndefFormat) throws FormatException;
// 
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/WriteUtility.java
// public interface WriteUtility extends NdefWrite {
// 
// 
//     /**
//      * Writes towards a {@link android.nfc.Tag}
//      *
//      * @param message
//      *         to write
//      * @param tag
//      *         to write to
//      *
//      * @return true if success
//      *
//      * @see #writeToNdef(android.nfc.NdefMessage, android.nfc.tech.Ndef)
//      */
//     boolean writeSafelyToTag(NdefMessage message, Tag tag);
// 
//     /**
//      * Write the given message to the tag
//      *
//      * @param message
//      *         to write
//      * @param tag
//      *         to write to
//      *
//      * @return true if success
//      *
//      * @throws android.nfc.FormatException if the message is in an incorrect format
//      * @throws be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException if there is not enough space available on the tag
//      * @throws be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException when attempting to write to a read-only tag
//      */
//     boolean writeToTag(NdefMessage message, Tag tag) throws FormatException, ReadOnlyTagException, InsufficientCapacityException;
// 
//     /**
//      * Used to mark the following operation as readonly
//      * @return an instance of WriteUtility in order to chain
//      */
//     WriteUtility makeOperationReadOnly();
// }


// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/WriteUtilityImpl.java
import be.appfoundry.nfclibrary.utilities.interfaces.NdefWrite;
import be.appfoundry.nfclibrary.utilities.interfaces.WriteUtility;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.util.Log;
import be.appfoundry.nfclibrary.exceptions.InsufficientCapacityException;
import be.appfoundry.nfclibrary.exceptions.ReadOnlyTagException;

/*
 * WriteUtilityImpl.java
 * NfcLibrary project.
 *
 * Created by : Daneo van Overloop - 17/6/2014.
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 AppFoundry. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 */

package be.appfoundry.nfclibrary.utilities.sync;



/**
 * @author Daneo Van Overloop
 * NfcLibrary
 * Created on 11/04/14.
 */
public class WriteUtilityImpl implements WriteUtility {

    private static final String TAG = WriteUtilityImpl.class.getName();

    private boolean readOnly = false;

    private NdefWrite mNdefWrite;