1 22 23 package org.xquark.mapper.metadata; 24 25 import org.xquark.mapper.RepositoryException; 26 import org.xquark.mapper.mapping.MappingFactory; 27 import org.xquark.mapper.mapping.RepositoryMapping; 28 import org.xquark.xpath.*; 29 30 35 public class PathSetFactory extends XTreeBuilder 36 { 37 private static final String RCSRevision = "$Revision: 1.1 $"; 38 private static final String RCSName = "$Name: $"; 39 private CollectionMetadata collection; 40 private MappingFactory mappingFactory; 41 private PathSet pathSet; 42 45 public PathSetFactory(CollectionMetadata collection, MappingFactory mappingFactory) 46 { 47 set(collection, mappingFactory); 48 } 49 50 private void set(CollectionMetadata collection, MappingFactory mappingFactory) 51 { 52 this.collection = collection; 53 this.mappingFactory = mappingFactory; 54 } 55 56 public RepositoryMapping getMapping() 57 { 58 return (RepositoryMapping)mappingFactory.getTree(); 59 } 60 61 public XTree createTree() 65 { 66 pathSet = (PathSet)super.createTree(); 67 pathSet.initRoot(); 68 69 mappingFactory.duplicate(this); 72 try { 73 if (!pathSet.isNew()) 74 pathSet.refresh(); 75 } 76 catch (RepositoryException e) { 77 throw new XTreeRuntimeException(e); 78 } 79 return pathSet; 80 } 81 public XTree allocateTree() 82 { 83 return new PathSet(collection); 84 } 85 86 public XTreeNode allocateNode(XTreeNode parent, String namespace, String localName, byte type) 87 { 88 return new PathNode((PathSet)tree, (PathNode)parent, namespace, localName, type); 89 } 90 91 94 public XTreeNode createNamedNode(XTreeNode parent, String namespace, String localName, byte type) 95 { 96 XTreeNode newNode = super.createNamedNode(parent, namespace, localName, type); 97 try 98 { 99 pathSet.allocateID((PathNode)newNode); 100 } 101 catch (RepositoryException e) 102 { 103 throw new XTreeRuntimeException(e); 104 } 105 return newNode; 106 } 107 108 112 public synchronized XTreeNode createNamedNodeIfNotExist(XTreeNode parent, String namespace, String localName, byte type) 113 { 114 115 PathNode node = (PathNode)super.createNamedNodeIfNotExist(parent, namespace, localName, type); 116 if (node.getMapping() == null) 117 { 118 try 119 { 120 node.setDefaultMapping(mappingFactory, type); 121 } 122 catch (RepositoryException e) 123 { 124 throw new XTreeRuntimeException(e); 125 } 126 } 127 return node; 128 } 129 } 130 | Popular Tags |