[java-shib-shared] 03/05: JSSH-71, JSPT-98 Integrate lifecycle checking methods in base classes
Codeberg
noreply at shibboleth.net
Tue May 26 13:21:49 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch dev/JSSH-71
in repository java-shib-shared.
View the commit online:
https://codeberg.org/Shibboleth/java-shib-shared/commit/434e6288492637baf86b0a9269e916f917b6abff
commit 434e6288492637baf86b0a9269e916f917b6abff
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun May 24 13:55:33 2026 +0100
JSSH-71, JSPT-98 Integrate lifecycle checking methods in base classes
https://shibboleth.atlassian.net/browse/JSPT-98
https://shibboleth.atlassian.net/browse/JSSH-71
Remove deprecated class "net.shibboleth.shared.component.ComponentSupport"
and associated tests
---
.../shared/component/ComponentSupport.java | 133 -----------------
.../shared/component/ComponentSupportTest.java | 162 ---------------------
2 files changed, 295 deletions(-)
diff --git a/shib-support/src/main/java/net/shibboleth/shared/component/ComponentSupport.java b/shib-support/src/main/java/net/shibboleth/shared/component/ComponentSupport.java
deleted file mode 100644
index 6b3e2208..00000000
--- a/shib-support/src/main/java/net/shibboleth/shared/component/ComponentSupport.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * 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 "AS IS" 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 net.shibboleth.shared.component;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import net.shibboleth.shared.logic.Constraint;
-import net.shibboleth.shared.primitive.StringSupport;
-
-/** Support class for working with {@link Component} objects. */
- at Deprecated(forRemoval = true, since = "5.0")
-public final class ComponentSupport {
-
- /** Constructor. */
- private ComponentSupport() {
- }
-
- /**
- * If the given object is not null and an instance of {@link DestructableComponent}, then this method calls the
- * given object's {@link DestructableComponent#destroy()} method.
- *
- * @param obj object to destroy, may be null
- */
- public static void destroy(@Nullable final Object obj) {
- if (obj == null) {
- return;
- }
-
- if (obj instanceof DestructableComponent) {
- final DestructableComponent destructable = (DestructableComponent) obj;
- if (!destructable.isDestroyed()) {
- destructable.destroy();
- }
- }
- }
-
- /**
- * If the given object is not null and an instance of {@link InitializableComponent}, then this method calls the
- * given object's {@link InitializableComponent#initialize()} method.
- *
- * @param obj object to initialize, may be null
- *
- * @throws ComponentInitializationException thrown if there is a problem initializing the object
- */
- public static void initialize(@Nullable final Object obj) throws ComponentInitializationException {
- if (obj == null) {
- return;
- }
-
- if (obj instanceof InitializableComponent) {
- final InitializableComponent initializable = (InitializableComponent) obj;
- if (!initializable.isInitialized()) {
- initializable.initialize();
- }
- }
- }
-
- /**
- * Checks if a component is destroyed and, if so, throws a {@link DestroyedComponentException}. If the component is
- * also an instance of {@link IdentifiedComponent}, the component's ID is included in the error message.
- *
- * @param component component to check
- */
- public static void ifDestroyedThrowDestroyedComponentException(@Nonnull final DestructableComponent component) {
- Constraint.isNotNull(component, "Component cannot be null");
-
- if (component.isDestroyed()) {
- if (component instanceof IdentifiedComponent) {
- throw new DestroyedComponentException("Component '"
- + StringSupport.trimOrNull(((IdentifiedComponent) component).getId())
- + "' has already been destroyed and can no longer be used.");
- }
- throw new DestroyedComponentException("Component has already been destroyed and can no longer be used");
- }
-
- }
-
- /**
- * Checks if a component has not been initialized and, if so, throw)s a {@link UninitializedComponentException}. If
- * the component is also an instance of {@link IdentifiedComponent}, the component's ID is included in the error
- * message.
- *
- * @param component component to check
- */
- public static void
- ifNotInitializedThrowUninitializedComponentException(@Nonnull final InitializableComponent component) {
- Constraint.isNotNull(component, "Component cannot be null");
-
- if (!component.isInitialized()) {
- if (component instanceof IdentifiedComponent) {
- throw new UninitializedComponentException("Component '"
- + StringSupport.trimOrNull(((IdentifiedComponent) component).getId())
- + "' has not yet been initialized and cannot be used.");
- }
- throw new UninitializedComponentException("Component has not yet been initialized and cannot be used.");
- }
- }
-
- /**
- * Checks if a component has been initialized and, if so, throws a {@link UnmodifiableComponentException}. If the
- * component is also an instance of {@link IdentifiedComponent}, the component's ID is included in the error
- * message.
- *
- * @param component component to check
- */
- public static void
- ifInitializedThrowUnmodifiabledComponentException(@Nonnull final InitializableComponent component) {
- Constraint.isNotNull(component, "Component cannot be null");
-
- if (component.isInitialized()) {
- if (component instanceof IdentifiedComponent) {
- throw new UnmodifiableComponentException("Component '"
- + StringSupport.trimOrNull(((IdentifiedComponent) component).getId())
- + "' has already been initialized and can no longer be modified");
- }
- throw new UnmodifiableComponentException(
- "Component has already been initialized and can no longer be modified");
- }
- }
-}
\ No newline at end of file
diff --git a/shib-support/src/test/java/net/shibboleth/shared/component/ComponentSupportTest.java b/shib-support/src/test/java/net/shibboleth/shared/component/ComponentSupportTest.java
deleted file mode 100644
index d7f92f90..00000000
--- a/shib-support/src/test/java/net/shibboleth/shared/component/ComponentSupportTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * 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 "AS IS" 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 net.shibboleth.shared.component;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import net.shibboleth.shared.logic.ConstraintViolationException;
-
-/** Tests for {@link ComponentSupport} */
-public class ComponentSupportTest {
-
- @Test public void testDestroy() throws ComponentInitializationException {
- ComponentSupport.destroy(null);
-
- ComponentSupport.destroy(new Object());
-
- MockDestructableComponent component = new MockDestructableComponent();
- Assert.assertFalse(component.isDestroyed(), "New component not destroyed");
-
- ComponentSupport.destroy(component);
- Assert.assertTrue(component.isDestroyed(), "Destroyed component destroyed");
- }
-
- @Test public void testInitialized() throws ComponentInitializationException {
- ComponentSupport.initialize(null);
-
- ComponentSupport.initialize(new Object());
-
- MockInitializableComponent component = new MockInitializableComponent();
- Assert.assertFalse(component.isInitialized(), "New component not initialized");
-
- ComponentSupport.initialize(component);
- Assert.assertTrue(component.isInitialized(), "Initialized component initialized");
- }
-
- @Test public void testIfDestroyedThrowDestroyedComponentException() {
- MockDestructableComponent component = new MockDestructableComponent();
-
- try {
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(component);
- } catch (DestroyedComponentException e) {
- Assert.fail();
- }
-
- component.destroy();
- try {
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(component);
- Assert.fail();
- } catch (DestroyedComponentException e) {
- // expected this
- }
-
- try {
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(nullValue());
- Assert.fail();
- } catch (ConstraintViolationException e) {
- // expected this
- }
- }
-
- @Test public void testIfNotInitializedThrowUninitializedComponentException() throws Exception {
- MockInitializableComponent component = new MockInitializableComponent();
-
- try {
- ComponentSupport.ifNotInitializedThrowUninitializedComponentException(component);
- Assert.fail();
- } catch (UninitializedComponentException e) {
- // expected this
- }
-
- component.initialize();
- try {
- ComponentSupport.ifNotInitializedThrowUninitializedComponentException(component);
- } catch (UninitializedComponentException e) {
- Assert.fail();
- }
-
- try {
- ComponentSupport.ifNotInitializedThrowUninitializedComponentException(nullValue());
- Assert.fail();
- } catch (ConstraintViolationException e) {
- // expected this
- }
- }
-
- @Test public void testIfInitializedThrowUnmodifiabledComponentException() throws Exception {
- MockInitializableComponent component = new MockInitializableComponent();
-
- try {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(component);
- } catch (UnmodifiableComponentException e) {
- Assert.fail();
- }
-
- component.initialize();
- try {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(component);
- Assert.fail();
- } catch (UnmodifiableComponentException e) {
- // expected this
- }
-
- try {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(nullValue());
- Assert.fail();
- } catch (ConstraintViolationException e) {
- // expected this
- }
- }
-
- private <T> T nullValue() {
- return null;
- }
-
- private class MockDestructableComponent implements DestructableComponent {
-
- private boolean destroyed;
-
- /** {@inheritDoc} */
- @Override
- public void destroy() {
- destroyed = true;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isDestroyed() {
- return destroyed;
- }
- }
-
- public class MockInitializableComponent implements InitializableComponent {
-
- private boolean initialized;
-
- /** {@inheritDoc} */
- @Override
- public void initialize() throws ComponentInitializationException {
- initialized = true;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isInitialized() {
- return initialized;
- }
- }
-
-}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list