001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023package dk.netarkivet.viewerproxy; 024 025import java.net.URI; 026import java.util.Observable; 027import java.util.Observer; 028 029/** 030 * Super class for all URIObservers - calls the URIObserver notify method on all notifications of a URI and its response 031 * code. 032 */ 033public abstract class URIObserver implements Observer { 034 /** 035 * This notify method is called on every notification of URI and response code. 036 * 037 * @param uri The uri notified about 038 * @param responseCode The response code of this uri. 039 */ 040 public abstract void notify(URI uri, int responseCode); 041 042 /** Helper class to be able to notify about a pair of <uri,responsecode>. */ 043 static final class URIResponseCodePair { 044 /** The uri. */ 045 private final URI uri; 046 /** The response code. */ 047 private final int responseCode; 048 049 /** 050 * initialise values. 051 * 052 * @param uri The URI 053 * @param code The code 054 */ 055 public URIResponseCodePair(URI uri, int code) { 056 this.uri = uri; 057 this.responseCode = code; 058 } 059 } 060 061 /** 062 * Will call the abstract notify method if arg is an URIResponseCodePair value. 063 * 064 * @param o The observable which called this method. Ignored. 065 * @param arg The argument. If Response instance, notify is called. Otherwise ignored. 066 */ 067 public final void update(Observable o, Object arg) { 068 if (arg != null && arg instanceof URIResponseCodePair) { 069 URIResponseCodePair URIResponseCodePair = (URIResponseCodePair) arg; 070 notify(URIResponseCodePair.uri, URIResponseCodePair.responseCode); 071 } 072 } 073}