KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > transformer > KeyManager


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: KeyManager.java,v 1.16 2004/02/16 20:41:30 minchau Exp $
18  */

19 package org.apache.xalan.transformer;
20
21 import java.util.Vector JavaDoc;
22
23 import org.apache.xalan.templates.ElemTemplateElement;
24 import org.apache.xml.utils.PrefixResolver;
25 import org.apache.xml.utils.QName;
26 import org.apache.xml.utils.XMLString;
27 import org.apache.xpath.XPathContext;
28 import org.apache.xpath.objects.XNodeSet;
29
30 /**
31  * This class manages the key tables.
32  */

33 public class KeyManager
34 {
35
36   /**
37    * Table of tables of element keys.
38    * @see org.apache.xalan.transformer.KeyTable
39    */

40   private transient Vector JavaDoc m_key_tables = null;
41
42   /**
43    * Given a valid element key, return the corresponding node list.
44    *
45    * @param xctxt The XPath runtime state
46    * @param doc The document node
47    * @param name The key element name
48    * @param ref The key value we're looking for
49    * @param nscontext The prefix resolver for the execution context
50    *
51    * @return A nodelist of nodes mathing the given key
52    *
53    * @throws javax.xml.transform.TransformerException
54    */

55   public XNodeSet getNodeSetDTMByKey(
56           XPathContext xctxt, int doc, QName name, XMLString ref, PrefixResolver nscontext)
57             throws javax.xml.transform.TransformerException JavaDoc
58   {
59
60     XNodeSet nl = null;
61     ElemTemplateElement template = (ElemTemplateElement) nscontext; // yuck -sb
62

63     if ((null != template)
64             && null != template.getStylesheetRoot().getKeysComposed())
65     {
66       boolean foundDoc = false;
67
68       if (null == m_key_tables)
69       {
70         m_key_tables = new Vector JavaDoc(4);
71       }
72       else
73       {
74         int nKeyTables = m_key_tables.size();
75
76         for (int i = 0; i < nKeyTables; i++)
77         {
78           KeyTable kt = (KeyTable) m_key_tables.elementAt(i);
79
80           if (kt.getKeyTableName().equals(name) && doc == kt.getDocKey())
81           {
82             nl = kt.getNodeSetDTMByKey(name, ref);
83
84             if (nl != null)
85             {
86               foundDoc = true;
87
88               break;
89             }
90           }
91         }
92       }
93
94       if ((null == nl) &&!foundDoc /* && m_needToBuildKeysTable */)
95       {
96         KeyTable kt =
97           new KeyTable(doc, nscontext, name,
98                        template.getStylesheetRoot().getKeysComposed(),
99                        xctxt);
100
101         m_key_tables.addElement(kt);
102
103         if (doc == kt.getDocKey())
104         {
105           foundDoc = true;
106           nl = kt.getNodeSetDTMByKey(name, ref);
107         }
108       }
109     }
110
111     return nl;
112   }
113 }
114
Popular Tags