1 16 package org.springframework.webflow.definition.registry; 17 18 import java.io.Serializable ; 19 20 import org.springframework.core.io.Resource; 21 import org.springframework.core.style.ToStringCreator; 22 import org.springframework.util.Assert; 23 import org.springframework.webflow.core.collection.AttributeMap; 24 import org.springframework.webflow.core.collection.CollectionUtils; 25 26 35 public class FlowDefinitionResource implements Serializable { 36 37 40 private String id; 41 42 45 private AttributeMap attributes; 46 47 50 private Resource location; 51 52 57 public FlowDefinitionResource(Resource location) { 58 Assert.notNull(location, "The location of the externalized flow definition is required"); 59 init(conventionalFlowId(location), location, null); 60 } 61 62 67 public FlowDefinitionResource(String id, Resource location) { 68 init(id, location, null); 69 } 70 71 77 public FlowDefinitionResource(String id, Resource location, AttributeMap attributes) { 78 init(id, location, attributes); 79 } 80 81 84 public String getId() { 85 return id; 86 } 87 88 91 public Resource getLocation() { 92 return location; 93 } 94 95 98 public AttributeMap getAttributes() { 99 return attributes; 100 } 101 102 public boolean equals(Object o) { 103 if (!(o instanceof FlowDefinitionResource)) { 104 return false; 105 } 106 FlowDefinitionResource other = (FlowDefinitionResource)o; 107 return id.equals(other.id) && location.equals(other.location); 108 } 109 110 public int hashCode() { 111 return id.hashCode() + location.hashCode(); 112 } 113 114 116 119 private void init(String id, Resource location, AttributeMap attributes) { 120 Assert.hasText(id, "The id of the externalized flow definition is required"); 121 Assert.notNull(location, "The location of the externalized flow definition is required"); 122 this.id = id; 123 this.location = location; 124 if (attributes != null) { 125 this.attributes = attributes; 126 } 127 else { 128 this.attributes = CollectionUtils.EMPTY_ATTRIBUTE_MAP; 129 } 130 } 131 132 136 private String conventionalFlowId(Resource location) { 137 String fileName = location.getFilename(); 138 int extensionIndex = fileName.lastIndexOf('.'); 139 if (extensionIndex != -1) { 140 return fileName.substring(0, extensionIndex); 141 } 142 else { 143 return fileName; 144 } 145 } 146 147 public String toString() { 148 return new ToStringCreator(this).append("id", id).append("location", location).append("attributes", attributes) 149 .toString(); 150 } 151 } | Popular Tags |