1 29 30 package com.caucho.jcr.base; 31 32 import javax.jcr.PropertyType; 33 import javax.jcr.Value; 34 import javax.jcr.nodetype.NodeDefinition; 35 import javax.jcr.nodetype.NodeType; 36 import javax.jcr.nodetype.PropertyDefinition; 37 import javax.jcr.version.OnParentVersionAction; 38 import java.util.ArrayList ; 39 40 43 public class BaseNodeType implements NodeType { 44 public static final BaseNodeType MIX_REFERENCEABLE; 45 46 public static final BaseNodeType NT_BASE; 47 48 public static final BaseNodeType NT_HIERARCHY_NODE; 49 public static final BaseNodeType NT_FILE; 50 public static final BaseNodeType NT_FOLDER; 51 public static final BaseNodeType NT_RESOURCE; 52 53 private final String _name; 54 55 private final NodeType []_declaredSuperTypes; 56 57 private final NodeType []_superTypes; 58 59 private boolean _isMixin; 60 61 private boolean _hasOrderableChildNodes; 62 63 private String _primaryItemName; 64 65 private ArrayList <PropertyDefinition> _properties 66 = new ArrayList <PropertyDefinition>(); 67 68 private ArrayList <NodeDefinition> _childNodes 69 = new ArrayList <NodeDefinition>(); 70 71 public BaseNodeType(String name, 72 NodeType []declaredSuperTypes) 73 { 74 _name = name; 75 _declaredSuperTypes = declaredSuperTypes; 76 77 ArrayList <NodeType> superTypes = new ArrayList <NodeType>(); 78 79 for (NodeType type : declaredSuperTypes) { 80 if (! superTypes.contains(type)) 81 superTypes.add(type); 82 83 for (NodeType parentType : type.getSupertypes()) { 84 if (! superTypes.contains(parentType)) 85 superTypes.add(parentType); 86 } 87 } 88 89 _superTypes = new NodeType[superTypes.size()]; 90 superTypes.toArray(_superTypes); 91 } 92 93 public BaseNodeType(String name, NodeType superType) 94 { 95 this(name, new NodeType[] { superType }); 96 } 97 98 101 public String getName() 102 { 103 return _name; 104 } 105 106 109 public boolean isMixin() 110 { 111 return _isMixin; 112 } 113 114 117 public void setMixin(boolean isMixin) 118 { 119 _isMixin = isMixin; 120 } 121 122 125 public boolean hasOrderableChildNodes() 126 { 127 return _hasOrderableChildNodes; 128 } 129 130 133 public void setHasOrderableChildNodes(boolean hasOrder) 134 { 135 _hasOrderableChildNodes = hasOrder; 136 } 137 138 141 public String getPrimaryItemName() 142 { 143 return _primaryItemName; 144 } 145 146 149 public void setPrimaryItemName(String name) 150 { 151 _primaryItemName = name; 152 } 153 154 157 public NodeType[] getSupertypes() 158 { 159 return _superTypes; 160 } 161 162 165 public NodeType[] getDeclaredSupertypes() 166 { 167 return _declaredSuperTypes; 168 } 169 170 173 public boolean isNodeType(String nodeTypeName) 174 { 175 return false; 176 } 177 178 181 public PropertyDefinition[] getPropertyDefinitions() 182 { 183 return getDeclaredPropertyDefinitions(); 184 } 185 186 189 public PropertyDefinition[] getDeclaredPropertyDefinitions() 190 { 191 PropertyDefinition []props; 192 193 props = new PropertyDefinition[_properties.size()]; 194 _properties.toArray(props); 195 196 return props; 197 } 198 199 202 public void addProperty(PropertyDefinition prop) 203 { 204 _properties.add(prop); 205 } 206 207 210 public NodeDefinition[] getChildNodeDefinitions() 211 { 212 return getDeclaredChildNodeDefinitions(); 213 } 214 215 218 public NodeDefinition[] getDeclaredChildNodeDefinitions() 219 { 220 NodeDefinition []children; 221 222 children = new NodeDefinition[_childNodes.size()]; 223 _childNodes.toArray(children); 224 225 return children; 226 } 227 228 231 public void addChildNode(NodeDefinition child) 232 { 233 _childNodes.add(child); 234 } 235 236 239 public boolean canSetProperty(String propertyName, Value value) 240 { 241 return false; 242 } 243 244 247 public boolean canSetProperty(String propertyName, Value[] values) 248 { 249 return false; 250 } 251 252 255 public boolean canAddChildNode(String childNodeName) 256 { 257 return false; 258 } 259 260 263 public boolean canAddChildNode(String childNodeName, String nodeTypeName) 264 { 265 return false; 266 } 267 268 271 public boolean canRemoveItem(String itemName) 272 { 273 return false; 274 } 275 276 public int hashCode() 277 { 278 return getName().hashCode(); 279 } 280 281 public boolean equals(Object o) 282 { 283 if (this == o) 284 return true; 285 else if (! (o instanceof BaseNodeType)) 286 return false; 287 288 BaseNodeType nodeType = (BaseNodeType) o; 289 290 return getName().equals(nodeType.getName()); 291 } 292 293 public String toString() 294 { 295 return "BaseNodeType[" + getName() + "]"; 296 } 297 298 static { 299 BasePropertyDefinition prop; 300 BaseNodeDefinition child; 301 302 304 MIX_REFERENCEABLE = new BaseNodeType("mix:referenceable", new NodeType[0]); 305 306 308 NT_BASE = new BaseNodeType("nt:base", new NodeType[0]); 309 310 prop = new BasePropertyDefinition("jcr:primaryType", NT_BASE, 311 PropertyType.NAME); 312 prop.setAutoCreated(true); 313 prop.setMandatory(true); 314 prop.setOnParentVersion(OnParentVersionAction.COMPUTE); 315 prop.setProtected(true); 316 NT_BASE.addProperty(prop); 317 318 prop = new BasePropertyDefinition("jcr:mixinTypes", NT_BASE, 319 PropertyType.NAME); 320 prop.setOnParentVersion(OnParentVersionAction.COMPUTE); 321 prop.setProtected(true); 322 prop.setMultiple(true); 323 NT_BASE.addProperty(prop); 324 325 327 329 NT_HIERARCHY_NODE = new BaseNodeType("nt:hierarchyNode", NT_BASE); 330 331 prop = new BasePropertyDefinition("jcr:created", NT_HIERARCHY_NODE, 332 PropertyType.DATE); 333 prop.setAutoCreated(true); 334 prop.setOnParentVersion(OnParentVersionAction.INITIALIZE); 335 prop.setProtected(true); 336 NT_HIERARCHY_NODE.addProperty(prop); 337 338 340 NT_FILE = new BaseNodeType("nt:file", NT_HIERARCHY_NODE); 341 NT_FILE.setPrimaryItemName("jcr:content"); 342 343 child = new BaseNodeDefinition("jcr:content", NT_FILE); 344 child.setRequiredPrimaryTypes(new NodeType[] { NT_BASE }); 345 child.setMandatory(true); 346 NT_FILE.addChildNode(child); 347 348 350 352 NT_FOLDER = new BaseNodeType("nt:folder", NT_HIERARCHY_NODE); 353 354 child = new BaseNodeDefinition("*", NT_FOLDER); 355 child.setRequiredPrimaryTypes(new NodeType[] { NT_HIERARCHY_NODE }); 356 child.setOnParentVersion(OnParentVersionAction.VERSION); 357 358 360 NT_RESOURCE = new BaseNodeType("nt:resource", 361 new NodeType[] { NT_HIERARCHY_NODE, 362 MIX_REFERENCEABLE }); 363 NT_RESOURCE.setPrimaryItemName("jcr:data"); 364 365 prop = new BasePropertyDefinition("jcr:encoding", NT_RESOURCE, 366 PropertyType.STRING); 367 NT_FOLDER.addProperty(prop); 368 369 prop = new BasePropertyDefinition("jcr:mimeType", NT_RESOURCE, 370 PropertyType.STRING); 371 prop.setMandatory(true); 372 NT_FOLDER.addProperty(prop); 373 374 prop = new BasePropertyDefinition("jcr:data", NT_RESOURCE, 375 PropertyType.BINARY); 376 prop.setMandatory(true); 377 NT_FOLDER.addProperty(prop); 378 379 prop = new BasePropertyDefinition("jcr:lastModified", NT_RESOURCE, 380 PropertyType.DATE); 381 prop.setMandatory(true); 382 prop.setOnParentVersion(OnParentVersionAction.IGNORE); 383 NT_FOLDER.addProperty(prop); 384 } 385 } 386 | Popular Tags |