Source code: com/flexstor/common/data/ejb/disguiserecord/AssetRoleData.java
1 /*
2 * AssetRoleData.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:28 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.data.ejb.disguiserecord;
12
13 /**
14 * The role the asset plays in FlexstorDB and how it relates to other
15 * asset roles.
16 * This is the superclass for specific roles
17 */
18 public class AssetRoleData
19 extends GenericBucketRecordData
20 {
21 /**
22 * True if this instance of the role is acting like a temporary instance.
23 */
24 protected boolean bTempRole = false;
25 /**
26 * The type of file this asset is. Examples are: JPEG, JIF, ...
27 */
28 protected String sAssetFileType = null;
29 /**
30 * Id identifying this role (unique across applications)
31 */
32 protected int nAssetRoleId = 0;
33
34 /**
35 * All subclasses of AssetRoleData need to overwrite this method.
36 */
37 protected Object cloneRole() { return null; }
38
39 /**
40 * Overwrite this method in subclases.
41 * Add getAssetFileType() in implementation.
42 * Creates a String[] with all the values for all fields in this object
43 */
44 public String[] gatherData() { return null; }
45
46 /**
47 * Query this Asset to determine if it's a temporary asset (not to be stored in the database)
48 */
49 public boolean isTempRole()
50 {
51 if(bTempRole) return true;
52 else return false;
53 }
54
55 /**
56 * Set this asset as temporary.
57 */
58 public boolean setTempRole(boolean temp)
59 {
60 bTempRole = temp;
61 return true;
62 }
63
64 /**
65 * Get the file type represented by this asset.
66 */
67 public String getAssetFileType()
68 {
69 return sAssetFileType;
70 }
71
72 /**
73 * Set the file type for this asset.
74 */
75 public boolean setAssetFileType(String type)
76 {
77 sAssetFileType = type;
78 return true;
79 }
80
81 /**
82 * Get the role Id of this asset.
83 */
84 public int getAssetRoleId()
85 {
86 return nAssetRoleId;
87 }
88
89 /**
90 * Set the role Id of this asset.
91 * @see com.flexstor.common.constants.AssetRolesI
92 */
93 public boolean setAssetRoleId(int roleId)
94 {
95 nAssetRoleId = roleId;
96 return true;
97 }
98
99 public static AssetRoleData getAssetRoleData(String sRoleType)
100 {
101 int nRoleId = 0;
102 if(sRoleType != null)
103 {
104 if(sRoleType.toUpperCase().equals("HIGHRES"))
105 nRoleId = com.flexstor.common.constants.AssetRolesI.HIGHRES;
106 else if(sRoleType.toUpperCase().equals("LOWRES"))
107 nRoleId = com.flexstor.common.constants.AssetRolesI.LOWRES;
108 else if(sRoleType.toUpperCase().equals("THUMBNAIL"))
109 nRoleId = com.flexstor.common.constants.AssetRolesI.THUMBNAIL;
110 else if(sRoleType.toUpperCase().equals("LAYOUT"))
111 nRoleId = com.flexstor.common.constants.AssetRolesI.LAYOUT;
112 else if(sRoleType.toUpperCase().equals("VIDEO"))
113 nRoleId = com.flexstor.common.constants.AssetRolesI.AUDIO;
114 else if(sRoleType.toUpperCase().equals("AUDIO"))
115 nRoleId = com.flexstor.common.constants.AssetRolesI.VIDEO;
116 }
117 return getAssetRoleData(nRoleId);
118 }
119
120 public static AssetRoleData getAssetRoleData(int nRoleId)
121 {
122 AssetRoleData theRole = null;
123 switch(nRoleId)
124 {
125 case 1: // HIGHRES
126 theRole = new HighresRoleData();
127 break;
128 case 2: // LOWRES
129 theRole = new LowresRoleData();
130 break;
131 case 3: // THUMB
132 theRole = new ThumbnailRoleData();
133 break;
134 case 4: // LAYOUT
135 theRole = new LayoutRoleData();
136 break;
137 case 5: // VIDEO
138 theRole = new VideoRoleData();
139 break;
140 case 6: // AUDIO
141 theRole = new AudioRoleData();
142 break;
143 }
144 return theRole;
145
146 }
147
148 /**
149 * Returns a cloned version of this AssetRoleData object
150 */
151 public synchronized Object cloneAssetRole()
152 {
153 AssetRoleData clonedObject = (AssetRoleData) this.cloneRole();
154 if ( clonedObject == null )
155 clonedObject = new AssetRoleData();
156
157 clonedObject.setTempRole( this.bTempRole );
158 clonedObject.setAssetFileType( sAssetFileType );
159 clonedObject.setAssetRoleId( nAssetRoleId );
160 return clonedObject;
161 }
162
163 }
164