public static void requestSessionCreation(boolean createSessionRequest) { ThreadContext.put(AUTO_CREATE_SESSION_KEY, createSessionRequest); } }
/** * {@link ThreadContext#remove Remove}s all thread-state that was bound by this instance. If any previous * thread-bound resources existed prior to the {@link #bind bind} call, they are restored back to the * {@code ThreadContext} to ensure the thread state is exactly as it was before binding. */ public void restore() { ThreadContext.remove(); if (!CollectionUtils.isEmpty(this.originalResources)) { ThreadContext.setResources(this.originalResources); } }
/** * Creates an instance using the sources bytes directly - it does not create a copy of the * argument's byte array. * * @param source the source to use to populate the underlying byte array. * @since 1.1 */ public SimpleByteSource(ByteSource source) { this.bytes = source.getBytes(); }
public static void init(Object o) throws ShiroException { if (o instanceof Initializable) { init((Initializable) o); } }
/** * Completely {@link ThreadContext#remove removes} the {@code ThreadContext} state. Typically this method should * only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous * state than to clear it entirely. */ public void clear() { ThreadContext.remove(); } }
protected Class lookupHashFormatClass(String name) { try { return ClassUtils.forName(name); } catch (UnknownClassException ignored) { } return null; }
/** * Returns a new {@code ByteSource} instance representing the specified character array's bytes. The byte * array is obtained assuming {@code UTF-8} encoding. * * @param chars the character array to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified character array's bytes. */ public static ByteSource bytes(char[] chars) { return new SimpleByteSource(chars); }
/** * Creates an instance by converting the file to a byte array. * * @param file the file from which to acquire bytes. * @since 1.1 */ public SimpleByteSource(File file) { this.bytes = new BytesHelper().getBytes(file); }
/** * Assert that the provided object is an instance of the provided class. * <pre class="code">Assert.instanceOf(Foo.class, foo);</pre> * @param clazz the required class * @param obj the object to check * @throws IllegalArgumentException if the object is not an instance of clazz * @see Class#isInstance */ public static void isInstanceOf(Class clazz, Object obj) { isInstanceOf(clazz, obj, ""); }
/** * Assert that <code>superType.isAssignableFrom(subType)</code> is <code>true</code>. * <pre class="code">Assert.isAssignable(Number.class, myClass);</pre> * @param superType the super type to check * @param subType the sub type to check * @throws IllegalArgumentException if the classes are not assignable */ public static void isAssignable(Class superType, Class subType) { isAssignable(superType, subType, ""); }
/** * Creates a {@code SoftHashMap} backed by the specified {@code source}, with a default retention * size of {@link #DEFAULT_RETENTION_SIZE DEFAULT_RETENTION_SIZE} (100 entries). * * @param source the backing map to populate this {@code SoftHashMap} * @see #SoftHashMap(Map,int) */ public SoftHashMap(Map<K, V> source) { this(DEFAULT_RETENTION_SIZE); putAll(source); }
/** * Assert that an array has elements; that is, it must not be * <code>null</code> and must have at least one element. * <pre class="code">Assert.notEmpty(array);</pre> * @param array the array to check * @throws IllegalArgumentException if the object array is <code>null</code> or has no elements */ public static void notEmpty(Object[] array) { notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element"); }
/** * Assert that the given String has valid text content; that is, it must not * be <code>null</code> and must contain at least one non-whitespace character. * <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre> * @param text the String to check * @see StringUtils#hasText */ public static void hasText(String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); }
/** * Assert that an array has no null elements. * Note: Does not complain if the array is empty! * <pre class="code">Assert.noNullElements(array);</pre> * @param array the array to check * @throws IllegalArgumentException if the object array contains a <code>null</code> element */ public static void noNullElements(Object[] array) { noNullElements(array, "[Assertion failed] - this array must not contain any null elements"); }
public static boolean isAvailable(String fullyQualifiedClassName) { try { forName(fullyQualifiedClassName); return true; } catch (UnknownClassException e) { return false; } }
/** * Returns a new {@code ByteSource} instance representing the specified ByteSource. * * @param source the ByteSource to represent as a new {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified ByteSource. */ public static ByteSource bytes(ByteSource source) { return new SimpleByteSource(source); }
/** * Creates an instance by converting the stream to a byte array. * * @param stream the stream from which to acquire bytes. * @since 1.1 */ public SimpleByteSource(InputStream stream) { this.bytes = new BytesHelper().getBytes(stream); }
/** * Assert that a collection has elements; that is, it must not be * <code>null</code> and must have at least one element. * <pre class="code">Assert.notEmpty(collection, "Collection must have elements");</pre> * @param collection the collection to check * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements */ public static void notEmpty(Collection collection) { notEmpty(collection, "[Assertion failed] - this collection must not be empty: it must contain at least 1 element"); }
/** * Assert that a Map has entries; that is, it must not be <code>null</code> * and must have at least one entry. * <pre class="code">Assert.notEmpty(map);</pre> * @param map the map to check * @throws IllegalArgumentException if the map is <code>null</code> or has no entries */ public static void notEmpty(Map map) { notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry"); }