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