[java-opensaml COMMIT] in /trunk/opensaml-messaging-api/src: main/java/org/opensaml/messaging/context/AbstractContext...
noreply at shibboleth.net
noreply at shibboleth.net
Tue Jan 24 00:57:44 GMT 2012
Author: putmanb
Date: Tue Jan 24 00:57:44 2012
New Revision: 2929
URL: http://svn.shibboleth.net/view/java-opensaml?rev=2929&view=rev
Log:
Update AbstractContext:
- set make auto-creation of subcontexts false by default
- fully manage context/subcontext parent/child links across relationship mutation operations
Update some Javadocs on both interface and impl.
Create unit test for exercising AbstractContext.
- one test still failing due to pesky reflection issue on subcontext auto-creation
Added:
trunk/opensaml-messaging-api/src/test/java/org/
trunk/opensaml-messaging-api/src/test/java/org/opensaml/
trunk/opensaml-messaging-api/src/test/java/org/opensaml/messaging/
trunk/opensaml-messaging-api/src/test/java/org/opensaml/messaging/context/
trunk/opensaml-messaging-api/src/test/java/org/opensaml/messaging/context/AbstractContextTest.java (with props)
Modified:
trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/AbstractContext.java
trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/Context.java
Modified: trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/AbstractContext.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/AbstractContext.java?rev=2929&r1=2928&r2=2929&view=diff
==============================================================================
--- trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/AbstractContext.java (original)
+++ trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/AbstractContext.java Tue Jan 24 00:57:44 2012
@@ -58,9 +58,10 @@
/** Constructor. Generates a random context id. */
public AbstractContext() {
subcontexts = new ClassIndexedSet<Context>();
- id = UUID.randomUUID().toString();
creationTime = new DateTime();
- autoCreateSubcontexts = true;
+
+ setAutoCreateSubcontexts(false);
+ setId(UUID.randomUUID().toString());
}
/**
@@ -81,7 +82,7 @@
*/
public AbstractContext(final Context newParent) {
this();
- setParent(newParent);
+ newParent.addSubcontext(this);
}
/**
@@ -93,7 +94,7 @@
public AbstractContext(final String contextId, final Context newParent) {
this();
setId(contextId);
- setParent(newParent);
+ newParent.addSubcontext(this);
}
/** {@inheritDoc} */
@@ -126,30 +127,7 @@
* @param newParent the new context parent
*/
protected void setParent(final Context newParent) {
- Context oldParent = parent;
parent = newParent;
-
- if (parent != null) {
- log.trace("Setting context with type '{}' with id '{}' as parent of context with type '{}' with id '{}'",
- new String[]{parent.getClass().getName(), parent.getId(), this.getClass().getName(), this.getId()});
- Context currentChild = parent.getSubcontext(this.getClass());
- if (currentChild == null) {
- log.trace("Adding context to parent");
- parent.addSubcontext(this);
- } else if (currentChild == this) {
- log.trace("Context was already in parent's subcontext collection");
- } else {
- // TODO: not sure what to do here, perhaps either throw exception or else do a force add.
- log.warn("A different instance of type {} was a child of parent context, could not add this instance");
- }
- } else {
- log.trace("New parent context was null for context '{}' with id '{}'", this.getClass().getName(), this.getId());
- }
-
- if (oldParent != null) {
- log.trace("Removing context from old parent");
- oldParent.removeSubcontext(this);
- }
}
/** {@inheritDoc} */
@@ -183,12 +161,58 @@
}
/** {@inheritDoc} */
- public void addSubcontext(Context subContext, boolean replace) {
- subcontexts.add(subContext, replace);
+ public void addSubcontext(Context subcontext, boolean replace) {
+ Context existing = subcontexts.get(subcontext.getClass());
+ if (existing == subcontext) {
+ log.trace("Subcontext to add was already a child of the current context, skipping");
+ return;
+ }
+
+ // Note: This will throw if replace == false and existing != null.
+ // In that case, no link management happens, which is what we want, to leave things in a consistent state.
+ log.trace("Attempting to store a subcontext with type '{}' id '{}' with replace option '{}'",
+ new String[]{subcontext.getClass().getName(), subcontext.getId(), new Boolean(replace).toString()});
+ subcontexts.add(subcontext, replace);
+
+ // Manage parent/child links
+
+ // If subcontext was formerly a child of another parent, remove that link
[... 221 lines stripped ...]
More information about the commits
mailing list