KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > metadata > PathSetFactory


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

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 /**
31  * Specific implementation of XTreeBuilder.
32  * <p><B>Warning:</B> This factory is not synchronized since path set is.
33  *
34  */

35 public class PathSetFactory extends XTreeBuilder
36 {
37     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
38     private static final String JavaDoc RCSName = "$Name: $";
39     private CollectionMetadata collection;
40     private MappingFactory mappingFactory;
41     private PathSet pathSet;
42     /**
43      * To use when createTree() is going to be called.
44      **/

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     //
62
// XModelFactory IMPLEMENTATION
63
//
64
public XTree createTree()
65     {
66         pathSet = (PathSet)super.createTree();
67         pathSet.initRoot();
68         
69         // create an empty (no pid) copy of the repository mapping tree
70
// TO IMPROVE : now that all ps table is browsed, only perform duplicate when ps is new ? (browse symetrically Reposiory mapping to attach mapping nodes)
71
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 JavaDoc namespace, String JavaDoc localName, byte type)
87     {
88         return new PathNode((PathSet)tree, (PathNode)parent, namespace, localName, type);
89     }
90     
91     /** This version is used direcly by the mapping duplication (mapping node is not
92      * allocated, it is copied from the RepositoryMapping by customizeDuplicate())
93      */

94     public XTreeNode createNamedNode(XTreeNode parent, String JavaDoc namespace, String JavaDoc 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     /** This version is to be used by the pathset construction during document
109      * instance storage <B>only</B>.
110      *
111      */

112     public synchronized XTreeNode createNamedNodeIfNotExist(XTreeNode parent, String JavaDoc namespace, String JavaDoc localName, byte type)
113     {
114         /* Then create */
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