blob: a0f4300b491b5eb9f7e77beae785a273f899a9c8 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>LifecycleUtils.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: Jar Bundle</a> &gt; <a href="../index.html" class="el_bundle">shiro-core</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.util</a> &gt; <span class="el_source">LifecycleUtils.java</span></div><h1>LifecycleUtils.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.util;
import org.apache.shiro.ShiroException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
/**
* Utility class to help call {@link org.apache.shiro.util.Initializable#init() Initializable.init()} and
* {@link org.apache.shiro.util.Destroyable#destroy() Destroyable.destroy()} methods cleanly on any object.
*
* @since 0.2
*/
<span class="nc" id="L34">public abstract class LifecycleUtils {</span>
<span class="fc" id="L36"> private static final Logger log = LoggerFactory.getLogger(LifecycleUtils.class);</span>
public static void init(Object o) throws ShiroException {
<span class="fc bfc" id="L39" title="All 2 branches covered."> if (o instanceof Initializable) {</span>
<span class="fc" id="L40"> init((Initializable) o);</span>
}
<span class="fc" id="L42"> }</span>
public static void init(Initializable initializable) throws ShiroException {
<span class="fc" id="L45"> initializable.init();</span>
<span class="fc" id="L46"> }</span>
/**
* Calls {@link #init(Object) init} for each object in the collection. If the collection is {@code null} or empty,
* this method returns quietly.
*
* @param c the collection containing objects to {@link #init init}.
* @throws ShiroException if unable to initialize one or more instances.
* @since 0.9
*/
public static void init(Collection c) throws ShiroException {
<span class="pc bpc" id="L57" title="2 of 4 branches missed."> if (c == null || c.isEmpty()) {</span>
<span class="nc" id="L58"> return;</span>
}
<span class="fc bfc" id="L60" title="All 2 branches covered."> for (Object o : c) {</span>
<span class="fc" id="L61"> init(o);</span>
<span class="fc" id="L62"> }</span>
<span class="fc" id="L63"> }</span>
public static void destroy(Object o) {
<span class="fc bfc" id="L66" title="All 2 branches covered."> if (o instanceof Destroyable) {</span>
<span class="fc" id="L67"> destroy((Destroyable) o);</span>
<span class="pc bpc" id="L68" title="1 of 2 branches missed."> } else if (o instanceof Collection) {</span>
<span class="nc" id="L69"> destroy((Collection)o);</span>
}
<span class="fc" id="L71"> }</span>
public static void destroy(Destroyable d) {
<span class="pc bpc" id="L74" title="1 of 2 branches missed."> if (d != null) {</span>
try {
<span class="fc" id="L76"> d.destroy();</span>
<span class="nc" id="L77"> } catch (Throwable t) {</span>
<span class="nc bnc" id="L78" title="All 2 branches missed."> if (log.isDebugEnabled()) {</span>
<span class="nc" id="L79"> String msg = &quot;Unable to cleanly destroy instance [&quot; + d + &quot;] of type [&quot; + d.getClass().getName() + &quot;].&quot;;</span>
<span class="nc" id="L80"> log.debug(msg, t);</span>
}
<span class="fc" id="L82"> }</span>
}
<span class="fc" id="L84"> }</span>
/**
* Calls {@link #destroy(Object) destroy} for each object in the collection.
* If the collection is {@code null} or empty, this method returns quietly.
*
* @param c the collection of objects to destroy.
* @since 0.9
*/
public static void destroy(Collection c) {
<span class="pc bpc" id="L94" title="1 of 4 branches missed."> if (c == null || c.isEmpty()) {</span>
<span class="fc" id="L95"> return;</span>
}
<span class="fc bfc" id="L98" title="All 2 branches covered."> for (Object o : c) {</span>
<span class="fc" id="L99"> destroy(o);</span>
<span class="fc" id="L100"> }</span>
<span class="fc" id="L101"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>