/*
 * Copyright (c) 2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 *
 */

package com.jscape.util.net.connection;

import java.io.IOException;

/**
 * @author Alex Usun
 */
public interface ConnectionProtector {

    ConnectionProtector NULL = new ConnectionProtector() {
        @Override
        public void protect(Connection connection) {
            // empty
        }

        @Override
        public void unprotect(Connection connection) {
            // empty
        }
    };

    void protect(Connection connection)
            throws OperationException;

    void unprotect(Connection connection);

    class OperationException
            extends IOException {

        public static OperationException wrap(Throwable e) {
            return e instanceof OperationException ? (OperationException) e : new OperationException(e);
        }

        public OperationException() {
        }

        public OperationException(String message) {
            super(message);
        }

        public OperationException(String message, Throwable cause) {
            super(message, cause);
        }

        public OperationException(Throwable cause) {
            super(cause.getMessage() != null ? cause.getMessage() : cause.toString(), cause);
        }
    }

}
