Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
AssetType.java
1 
16 package net.squiz.matrix.core;
17 
18 import java.util.*;
19 import javax.swing.Icon;
20 import org.w3c.dom.*;
21 import java.io.*;
22 
23 
30 public class AssetType implements Serializable {
31 
32  private String typeCode;
33  private String name = "";
34  private boolean instantiable;
35  private String version;
36  private String allowedAccess;
37  private AssetType parentType = null;
38  private Set childTypes;
39  private String[] menuPath = new String[0];
40  private List screens = new Vector();
41 
45  public AssetType(String typeCode) {
46  this.typeCode = typeCode;
47  }
48 
49  void setInfo(Element typeElement) {
50  name = typeElement.getAttribute("name");
51  instantiable = typeElement.getAttribute("instantiable").equals("1");
52  version = typeElement.getAttribute("version");
53  allowedAccess = typeElement.getAttribute("allowed_access");
54  String menuPath = typeElement.getAttribute("flash_menu_path");
55 
56  if (!menuPath.trim().equals(""))
57  this.menuPath = menuPath.split("/\\/");
58 
59  NodeList screenNodes = typeElement.getChildNodes();
60  for (int j = 0; j < screenNodes.getLength(); j++) {
61  if (!(screenNodes.item(j) instanceof Element))
62  continue;
63  Element screenElement = (Element) screenNodes.item(j);
64  String codeName = screenElement.getAttribute("code_name");
65  String screenName = screenElement.getFirstChild().getNodeValue();
66  addScreen(codeName, screenName);
67  }
68  }
69 
70 
75  public boolean isCreatable() {
76 
77  if (!instantiable || allowedAccess.equals("system"))
78  return false;
79 
80  return true;
81 
82 /* AssetType parentUserType = AssetManager.getCurrentUserType();
83  while (parentUserType != null) {
84  if (parentUserType.getTypeCode().equals(allowedAccess)) {
85  return true;
86  }
87  parentUserType = parentUserType.getParentType();
88  }
89  return false;
90 */ }
91 
96  public String[] getMenuPath() {
97  return menuPath;
98  }
99 
104  public String getName() {
105  return name;
106  }
107 
112  public Icon getIcon() {
113  return GUIUtilities.getIconForTypeCode(typeCode);
114  }
115 
120  public boolean isIconLoaded() {
122  }
123 
128  public String getTypeCode() {
129  return typeCode;
130  }
131 
138  private void addScreen(String codeName, String name) {
139  AssetTypeScreen screen = new AssetTypeScreen(codeName, name);
140  screens.add(screen);
141  }
142 
147  public Iterator getScreens() {
148  return screens.iterator();
149  }
150 
156  return parentType;
157  }
158 
159  public boolean isAncestor(AssetType parentType) {
160  AssetType child = this;
161  while (child != null) {
162  if (child.equals(parentType))
163  return true;
164  child = child.getParentType();
165  }
166  return false;
167  }
168 
169  public boolean isAncestor(String assetType) {
170  return isAncestor(AssetManager.getAssetType(assetType));
171  }
172 
177  public void setParentType(AssetType parentType) {
178  this.parentType = parentType;
179  }
180 
185  public int hashCode() {
186  return typeCode.hashCode();
187  }
188 
189  public String toString() {
190  return typeCode;
191  }
192 
197  public boolean equals(Object obj) {
198  if (!(obj instanceof AssetType))
199  return false;
200  return (((AssetType) obj).typeCode.equals(typeCode));
201  }
202 }