001 package org.tynamo.descriptor.extension;
002
003 import org.apache.commons.logging.Log;
004 import org.apache.commons.logging.LogFactory;
005 import org.tynamo.exception.TynamoRuntimeException;
006
007 public class BlobDescriptorExtension implements DescriptorExtension
008 {
009 protected static final Log LOG = LogFactory.getLog(BlobDescriptorExtension.class);
010
011 public enum ContentDisposition
012 {
013 INLINE, ATTACHMENT;
014
015 public String getValue()
016 {
017 return name().toLowerCase();
018 }
019 }
020
021 public enum RenderType
022 {
023 IMAGE, LINK; //, IFRAME, ICON; not yet supported in Tynamo
024
025 public boolean isImage()
026 {
027 return this == IMAGE;
028 }
029
030 public boolean isLink()
031 {
032 return this == LINK;
033 }
034
035 public boolean isIFrame()
036 {
037 return false; // this == IFRAME;
038 }
039
040 public boolean isIcon()
041 {
042 return false; // this == ICON;
043 }
044 }
045
046 private enum BlobType
047 {
048 BYTES, TYNAMO_BLOB
049 }
050
051 private BlobType blobType = BlobType.BYTES;
052
053 private String fileName = "";
054
055 private String contentType = "";
056
057 private ContentDisposition contentDisposition = ContentDisposition.INLINE;
058
059 private RenderType renderType = RenderType.LINK;
060
061 /**
062 * @param beanType
063 */
064 public BlobDescriptorExtension(Class beanType)
065 {
066 if (TynamoBlob.class.isAssignableFrom(beanType))
067 {
068 blobType = BlobType.TYNAMO_BLOB;
069 } else if (beanType.isArray())
070 {
071 blobType = BlobType.BYTES;
072 } else
073 {
074 throw new TynamoRuntimeException("type: " + beanType + " - Not supported");
075 }
076 }
077
078 public boolean isBytes()
079 {
080 return blobType == BlobType.BYTES;
081 }
082
083 public boolean isITynamoBlob()
084 {
085 return blobType == BlobType.TYNAMO_BLOB;
086 }
087
088 public String getFileName()
089 {
090 return fileName;
091 }
092
093 public void setFileName(String fileName)
094 {
095 this.fileName = fileName;
096 }
097
098 public String getContentType()
099 {
100 return contentType;
101 }
102
103 public void setContentType(String contentType)
104 {
105 this.contentType = contentType;
106 }
107
108 public RenderType getRenderType()
109 {
110 return renderType;
111 }
112
113 public void setRenderType(RenderType renderType)
114 {
115 this.renderType = renderType;
116 }
117
118 public ContentDisposition getContentDisposition()
119 {
120 return contentDisposition;
121 }
122
123 public void setContentDisposition(ContentDisposition contentDisposition)
124 {
125 this.contentDisposition = contentDisposition;
126 }
127 }