001    package railo.commons.io.res.type.cache;
002    
003    import java.io.Serializable;
004    
005    /**
006     * Core of a Ram Resource, holds the concrete data for a existing resource
007     */
008    public final class CacheResourceCore implements Serializable {
009    
010    
011            /**
012             * Directory Resource
013             */
014            public static final int TYPE_DIRECTORY=1;
015    
016            /**
017             * Directory Resource
018             */
019            public static final int TYPE_FILE=2;
020    
021            
022            private int type;
023            private String name;
024            private byte[] data;
025            private long lastModified=System.currentTimeMillis();
026    
027            private int mode=0777;
028            private int attributes=0;
029    
030            private String path;
031            
032            /**
033             * Konstruktor
034             * @param parent
035             * @param type
036             * @param name
037             * @param caseSensitive 
038             */
039            public CacheResourceCore(int type,String path,String name) {
040                    this.type=type;
041                    this.path=path;
042                    this.name=name;
043            }
044    
045    
046            /**
047             * Gibt den Feldnamen lastModified zur�ck.
048             * @return lastModified
049             */
050            public long getLastModified() {
051                    return this.lastModified;
052            }
053    
054            /**
055             * Setzt den Feldnamen lastModified.
056             * @param lastModified lastModified 
057             */
058            public void setLastModified(long lastModified) {
059                    this.lastModified = lastModified;
060            }
061    
062            /**
063             * Gibt den Feldnamen data zur�ck.
064             * @return data
065             */
066            public byte[] getData() {
067                    return this.data;
068            }
069    
070            /**
071             * Setzt den Feldnamen data.
072             * @param data data 
073             * @param append 
074             */
075            public void setData(byte[] data,boolean append) {
076                    lastModified=System.currentTimeMillis();
077                    
078                    // set data
079                    if(append) {
080                            if(this.data!=null && data!=null) {
081                                    byte[] newData=new byte[this.data.length+data.length];
082                                    int i=0;
083                                    for(;i<this.data.length;i++) {
084                                            newData[i]=this.data[i];
085                                    }
086                                    for(;i<this.data.length+data.length;i++) {
087                                            newData[i]=data[i-this.data.length];
088                                    }
089                                    this.data=newData;
090                            }
091                            else if(data!=null) {
092                                    this.data=data;
093                            }
094                    }
095                    else {
096                            this.data=data;
097                    }
098                    
099                    // set type
100                    if(this.data!=null) this.type=TYPE_FILE;
101                    
102            }
103    
104            /**
105             * Gibt den Feldnamen name zur�ck.
106             * @return name
107             */
108            public String getName() {
109                    return this.name;
110            }
111    
112            /**
113             * Setzt den Feldnamen name.
114             * @param name name 
115             */
116            public void setName(String name) {
117                    lastModified=System.currentTimeMillis();
118                    this.name = name;
119            }
120            
121    
122            /**
123             * @return the path
124             */
125            public String getPath() {
126                    return path;
127            }
128    
129            /**
130             * Gibt den Feldnamen type zur�ck.
131             * @return type
132             */
133            public int getType() {
134                    return this.type;
135            }
136    
137            /**
138             * Setzt den Feldnamen type.
139             * @param type type 
140             */
141            public void setType(int type) {
142                    lastModified=System.currentTimeMillis();
143                    this.type = type;
144            }
145            
146            /**
147             * @return the mode
148             */
149            public int getMode() {
150                    return mode;
151            }
152    
153            /**
154             * @param mode the mode to set
155             */
156            public void setMode(int mode) {
157                    this.mode=mode;
158            }
159            
160            public int getAttributes() {
161                    return attributes;
162            }
163            
164            public void setAttributes(int attributes) {
165                    this.attributes=attributes;
166            }
167    
168            public void remove() {
169                    setType(0);
170                    setData(null,false);
171            }
172    
173    }