KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > mapping > MappingContext


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.mapping;
24
25 import java.util.List JavaDoc;
26
27 import org.xquark.schema.ElementDeclaration;
28 import org.xquark.schema.SchemaContext;
29 import org.xquark.xpath.NodeKind;
30 import org.xquark.xpath.PathExpr;
31 import org.xquark.xpath.XNode;
32
33 /** This class allows to iterate through a repository mapping (and a schema)
34  * while parsing a document.
35  * <p>It is used for instance to provide table or column mappings while
36  * storing or reading mapped XML documents. This object maintains a context
37  * for the current Schema component. It contains features to manage the fact
38  * that it follows both document (therefore schema) and mapping structure that
39  * is a subset of the first.</p>
40  * @deprecated use MappingIterator instead
41  */

42 public class MappingContext extends SchemaContext
43 implements MappingLocator
44 {
45 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
46 private static final String JavaDoc RCSName = "$Name: $";
47     
48     //
49
// DATA
50
//
51

52     /** The XMLCollection Mapping browsed
53      */

54     protected MappingFactory factory;
55     protected MappingNode wNode;
56     protected XNode pattern = new XNode();
57     
58     //
59
// CONSTRUCTORS
60
//
61

62     public MappingContext(MappingFactory factory)
63     {
64         super(factory.getSchemaManager());
65         this.factory = factory;
66         wNode = (MappingNode)factory.getTree().getRoot();
67     }
68     
69     //
70
// MappingLocator IMPLEMENTATION
71
//
72
/** Get the table mappings for the current context
73      */

74     public List JavaDoc currentTableMappings()
75     {
76         return wNode.getTableMappings();
77     }
78     
79     /** Get the column mappings for the current context
80      */

81     public List JavaDoc currentColumnMappings()
82     {
83         return wNode.getColumnMappings();
84     }
85     
86     /** Get the table mappings for a particular subelement in the current context
87      */

88     public List JavaDoc getElementTableMappings(String JavaDoc namespace, String JavaDoc localName)
89     {
90         pattern.set(namespace, localName, NodeKind.ELEMENT);
91         MappingNode node = (MappingNode)wNode.getChild(pattern);
92         if (node == null)
93             return null;
94         else
95             return node.getTableMappings();
96     }
97     
98     /** Get the column mappings for a particular subelement in the current context
99      */

100     public List JavaDoc getElementColumnMappings(String JavaDoc namespace, String JavaDoc localName)
101     {
102         pattern.set(namespace, localName, NodeKind.ELEMENT);
103         MappingNode node = (MappingNode)wNode.getChild(pattern);
104         if (node == null)
105             return null; // SET schema component ?
106
else
107             return node.getColumnMappings();
108     }
109     
110     /** Get the table mappings for a particular attribute in the current context
111      */

112     public List JavaDoc getAttributeTableMappings(String JavaDoc namespace, String JavaDoc localName)
113     {
114         pattern.set(namespace, localName, NodeKind.ATTRIBUTE);
115         MappingNode node = (MappingNode)wNode.getChild(pattern);
116         if (node == null)
117             return null; // SET schema component ?
118
else
119             return node.getTableMappings();
120     }
121     
122     /** Get the column mappings for a particular attribute in the current context
123      */

124     public List JavaDoc getAttributeColumnMappings(String JavaDoc namespace, String JavaDoc localName)
125     {
126         pattern.set(namespace, localName, NodeKind.ATTRIBUTE);
127         MappingNode node = (MappingNode)wNode.getChild(pattern);
128         if (node == null)
129             return null; // SET schema component ?
130
else
131             return node.getColumnMappings();
132     }
133     
134     //
135
// SchemaContext OVERLOADING
136
//
137

138     public final void push(ElementDeclaration decl)
139     {
140         super.push(decl);
141         pattern.set(decl.getNamespace(), decl.getName(), NodeKind.ELEMENT);
142         wNode = (MappingNode)wNode.getChild(pattern);
143     }
144     
145     public final ElementDeclaration pop()
146     {
147         ElementDeclaration ret = super.pop();
148         wNode = (MappingNode)wNode.getParent();
149         return ret;
150     }
151     
152     
153     /** Return the absolute position of the locator.
154      * <p>i.e., !isDiscardable()</p>
155      */

156     public PathExpr getLocation()
157     {
158         return wNode.getLocation();
159     }
160     
161 }
162
Popular Tags