Java tutorial
/* * Copyright 2007 The JA-SIG Collaborative. All rights reserved. See license * distributed with this file and available online at * http://www.ja-sig.org/products/cas/overview/license/ */ package org.jasig.cas.ticket.registry; import org.jasig.cas.ticket.Ticket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.Assert; /** * @author Scott Battaglia * @version $Revision$ $Date$ * @since 3.0.4 * <p> * This is a published and supported CAS Server 3 API. * </p> */ public abstract class AbstractTicketRegistry implements TicketRegistry { /** The Commons Logging log instance. */ protected final Logger log = LoggerFactory.getLogger(getClass()); /** * @throws IllegalArgumentException if class is null. * @throws ClassCastException if class does not match requested ticket * class. */ public final Ticket getTicket(final String ticketId, final Class<? extends Ticket> clazz) { Assert.notNull(clazz, "clazz cannot be null"); final Ticket ticket = this.getTicket(ticketId); if (ticket == null) { return null; } if (!clazz.isAssignableFrom(ticket.getClass())) { throw new ClassCastException("Ticket [" + ticket.getId() + " is of type " + ticket.getClass() + " when we were expecting " + clazz); } return ticket; } }