[java-opensaml COMMIT] in /trunk/opensaml-messaging-api/src: main/java/org/opensaml/messaging/context/BaseContext.jav...
noreply at shibboleth.net
noreply at shibboleth.net
Mon May 12 10:17:31 EDT 2014
Author: scantor
Date: Mon May 12 10:17:31 2014
New Revision: 3861
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3861&view=rev
Log:
Add string-based access to subcontexts for environments like Velocity
Modified:
trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java
trunk/opensaml-messaging-api/src/test/java/org/opensaml/messaging/context/BaseContextTest.java
Modified: trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java?rev=3861&r1=3860&r2=3861&view=diff
==============================================================================
--- trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java (original)
+++ trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java Mon May 12 10:17:31 2014
@@ -22,11 +22,13 @@
import java.util.Iterator;
import javax.annotation.Nonnull;
-
+import javax.annotation.Nullable;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.collection.ClassIndexedSet;
import net.shibboleth.utilities.java.support.logic.Constraint;
-import org.joda.time.DateTime;
import org.opensaml.messaging.MessageRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,16 +60,13 @@
public abstract class BaseContext implements Iterable<BaseContext> {
/** Logger. */
- private final Logger log = LoggerFactory.getLogger(BaseContext.class);
+ @Nonnull private final Logger log = LoggerFactory.getLogger(BaseContext.class);
/** The owning parent context. */
- private BaseContext parent;
+ @Nullable private BaseContext parent;
/** The subcontexts being managed. */
- private ClassIndexedSet<BaseContext> subcontexts;
-
- /** The context creation time. */
- private DateTime creationTime;
+ @Nonnull @NonnullElements private ClassIndexedSet<BaseContext> subcontexts;
/** Flag indicating whether subcontexts should, by default, be created if they do not exist. */
private boolean autoCreateSubcontexts;
@@ -75,26 +74,16 @@
/** Constructor. Generates a random context id. */
public BaseContext() {
subcontexts = new ClassIndexedSet<BaseContext>();
- creationTime = new DateTime();
setAutoCreateSubcontexts(false);
}
/**
- * Get the timestamp of the creation of the context.
- *
- * @return the creation timestamp
- */
- public DateTime getCreationTime() {
- return creationTime;
- }
-
- /**
* Get the parent context, if there is one.
*
* @return the parent context or null
*/
- public BaseContext getParent() {
+ @Nullable public BaseContext getParent() {
return parent;
}
@@ -103,7 +92,7 @@
*
* @param newParent the new context parent
*/
- protected void setParent(final BaseContext newParent) {
+ protected void setParent(@Nullable final BaseContext newParent) {
parent = newParent;
}
@@ -114,7 +103,7 @@
* @param clazz the class type to obtain
* @return the held instance of the class, or null
*/
- public <T extends BaseContext> T getSubcontext(@Nonnull final Class<T> clazz) {
+ @Nullable public <T extends BaseContext> T getSubcontext(@Nonnull final Class<T> clazz) {
return getSubcontext(clazz, isAutoCreateSubcontexts());
}
@@ -126,7 +115,7 @@
* @param autocreate flag indicating whether the subcontext instance should be auto-created
* @return the held instance of the class, or null
*/
- public <T extends BaseContext> T getSubcontext(@Nonnull final Class<T> clazz, boolean autocreate) {
+ @Nullable public <T extends BaseContext> T getSubcontext(@Nonnull final Class<T> clazz, final boolean autocreate) {
Constraint.isNotNull(clazz, "Class type cannot be null");
log.trace("Request for subcontext of type: {}", clazz.getName());
@@ -146,6 +135,31 @@
log.trace("Subcontext not found of type: {}", clazz.getName());
return null;
}
+
+ /**
+ * Get a subcontext of the current context.
+ *
+ * @param className the name of the class type to obtain
+ * @return the held instance of the class, or null
+ * @throws ClassNotFoundException
+ */
+ @Nullable public BaseContext getSubcontext(@Nonnull @NotEmpty final String className)
+ throws ClassNotFoundException {
+ return getSubcontext(className, isAutoCreateSubcontexts());
+ }
+
+ /**
+ * Get a subcontext of the current context.
+ *
+ * @param className the name of the class type to obtain
+ * @param autocreate flag indicating whether the subcontext instance should be auto-created
[... 122 lines stripped ...]
More information about the commits
mailing list