1 package org.jmage; 2 3 import javax.media.jai.PlanarImage; 4 import java.net.URI; 5 import java.net.URISyntaxException; 6 import java.util.Properties; 7 import java.util.Arrays; 8 9 /*** 10 * ImageRequest 11 */ 12 public class ImageRequest { 13 protected URI imageURI; 14 protected PlanarImage image; 15 protected URI[] filterChainURI; 16 protected Properties filterChainProperties; 17 protected String encodingFormat; 18 protected byte[] encoded; 19 20 public ImageRequest() { 21 try { 22 filterChainURI = new URI[] { new URI("chain:org.jmage.filter.NoOpFilter") }; 23 } catch (URISyntaxException e) { 24 assert(false) : "filterchainURI not a URI, this should never happen"; 25 } 26 filterChainProperties = new Properties(); 27 } 28 29 public URI getImageURI() { 30 return imageURI; 31 } 32 33 public void setImageURI(URI imageURI) { 34 this.imageURI = imageURI; 35 } 36 37 public PlanarImage getImage() { 38 return image; 39 } 40 41 public void setImage(PlanarImage image) { 42 this.image = image; 43 } 44 45 public URI[] getFilterChainURI() { 46 return filterChainURI; 47 } 48 49 public void setFilterChainURI(URI[] filterChainURI) { 50 this.filterChainURI = filterChainURI; 51 } 52 53 public void setFilterChainURI(URI filterChainURI) { 54 this.filterChainURI = new URI[] { filterChainURI }; 55 } 56 57 public Properties getFilterChainProperties() { 58 return filterChainProperties; 59 } 60 61 public void setFilterChainProperties(Properties filterChainProperties) { 62 this.filterChainProperties = filterChainProperties; 63 } 64 65 public String getEncodingFormat() { 66 return encodingFormat; 67 } 68 69 public void setEncodingFormat(String encodingFormat) { 70 this.encodingFormat = encodingFormat; 71 } 72 73 public byte[] getEncoded() { 74 return encoded; 75 } 76 77 public void setEncoded(byte[] encoded) { 78 this.encoded = encoded; 79 } 80 81 public boolean equals(Object o) { 82 if (this == o) return true; 83 if (!(o instanceof ImageRequest)) return false; 84 85 final ImageRequest imageRequest = (ImageRequest) o; 86 87 if (encodingFormat != null ? !encodingFormat.equals(imageRequest.encodingFormat) : imageRequest.encodingFormat != null) return false; 88 if (filterChainURI != null ? !Arrays.asList(filterChainURI).equals(Arrays.asList(imageRequest.filterChainURI)) : imageRequest.filterChainURI != null) return false; 89 if (filterChainProperties != null ? !filterChainProperties.equals(imageRequest.filterChainProperties) : imageRequest.filterChainProperties != null) return false; 90 if (imageURI != null ? !imageURI.equals(imageRequest.imageURI) : imageRequest.imageURI != null) return false; 91 92 return true; 93 } 94 95 public int hashCode() { 96 int result; 97 result = (imageURI != null ? imageURI.hashCode() : 0); 98 result = 29 * result + (filterChainURI != null ? Arrays.asList(filterChainURI).hashCode() : 0); 99 result = 29 * result + (filterChainProperties != null ? filterChainProperties.hashCode() : 0); 100 result = 29 * result + (encodingFormat != null ? encodingFormat.hashCode() : 0); 101 return result; 102 } 103 104 /*** 105 * Override toString() for better readability 106 * 107 * @return a string representation of the object. 108 */ 109 public String toString() { 110 String sourceImage = this.imageURI != null ? this.imageURI.toASCIIString() : "null"; 111 String filterChain = this.filterChainURI != null ? this.filterChainURI.toString() : "null"; 112 long filterProperties = this.filterChainProperties != null ? this.filterChainProperties.hashCode() : 0; 113 filterProperties += this.encodingFormat != null ? this.encodingFormat.hashCode() : 0; 114 115 return "[" + sourceImage + "@" + filterChain + "#" + filterProperties + "]"; 116 } 117 }