1 16 package org.springframework.webflow.execution.repository.support; 17 18 import java.io.Serializable ; 19 20 import org.springframework.util.Assert; 21 import org.springframework.webflow.conversation.ConversationId; 22 import org.springframework.webflow.conversation.ConversationManager; 23 import org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException; 24 import org.springframework.webflow.execution.repository.FlowExecutionKey; 25 import org.springframework.webflow.execution.repository.continuation.FlowExecutionContinuation; 26 27 45 class CompositeFlowExecutionKey extends FlowExecutionKey { 46 47 50 private static final String CONVERSATION_ID_PREFIX = "_c"; 51 52 55 private static final String CONTINUATION_ID_PREFIX = "_k"; 56 57 61 private static final String FORMAT = 62 CONVERSATION_ID_PREFIX + "<conversationId>" + CONTINUATION_ID_PREFIX + "<continuationId>"; 63 64 67 private ConversationId conversationId; 68 69 72 private Serializable continuationId; 73 74 79 public CompositeFlowExecutionKey(ConversationId conversationId, Serializable continuationId) { 80 Assert.notNull(conversationId, "The conversation id is required"); 81 Assert.notNull(continuationId, "The continuation id is required"); 82 this.conversationId = conversationId; 83 this.continuationId = continuationId; 84 } 85 86 89 public ConversationId getConversationId() { 90 return conversationId; 91 } 92 93 96 public Serializable getContinuationId() { 97 return continuationId; 98 } 99 100 public boolean equals(Object obj) { 101 if (!(obj instanceof CompositeFlowExecutionKey)) { 102 return false; 103 } 104 CompositeFlowExecutionKey other = (CompositeFlowExecutionKey)obj; 105 return conversationId.equals(other.conversationId) && continuationId.equals(other.continuationId); 106 } 107 108 public int hashCode() { 109 return conversationId.hashCode() + continuationId.hashCode(); 110 } 111 112 public String toString() { 113 return new StringBuffer ().append(CONVERSATION_ID_PREFIX).append(getConversationId()) 114 .append(CONTINUATION_ID_PREFIX).append(getContinuationId()).toString(); 115 } 116 117 119 126 public static String [] keyParts(String encodedKey) throws BadlyFormattedFlowExecutionKeyException { 127 if (!encodedKey.startsWith(CONVERSATION_ID_PREFIX)) { 128 throw new BadlyFormattedFlowExecutionKeyException(encodedKey, FORMAT); 129 } 130 int continuationStart = encodedKey.indexOf(CONTINUATION_ID_PREFIX, CONVERSATION_ID_PREFIX.length()); 131 if (continuationStart == -1) { 132 throw new BadlyFormattedFlowExecutionKeyException(encodedKey, FORMAT); 133 } 134 String conversationId = encodedKey.substring(CONVERSATION_ID_PREFIX.length(), continuationStart); 135 String continuationId = encodedKey.substring(continuationStart + CONTINUATION_ID_PREFIX.length()); 136 return new String [] { conversationId, continuationId }; 137 } 138 } | Popular Tags |