KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > pattern > KeyPattern


1 package com.icl.saxon.pattern;
2 import com.icl.saxon.*;
3 import com.icl.saxon.om.*;
4 import com.icl.saxon.om.NodeEnumeration;
5 import com.icl.saxon.expr.XPathException;
6
7 import java.util.*;
8
9 /**
10 * A KeyPattern is a pattern of the form key(keyname, keyvalue)
11 */

12
13 public final class KeyPattern extends Pattern {
14
15     private int keyfingerprint; // the fingerprint of the key name
16
private String JavaDoc keyvalue; // the value of the key
17

18     /**
19     * Constructor
20     * @param name the name of the key
21     * @param value the value of the key
22     */

23
24     public KeyPattern(int namecode, String JavaDoc value) {
25         keyfingerprint = namecode & 0xfffff;
26         keyvalue = value;
27     }
28
29     /**
30     * Determine whether this Pattern matches the given Node.
31     * @param e The NodeInfo representing the Element or other node to be tested against the Pattern
32     * @return true if the node matches the Pattern, false otherwise
33     */

34
35     public boolean matches(NodeInfo e, Context c) throws XPathException {
36         DocumentInfo doc = e.getDocumentRoot();
37         Controller controller = c.getController();
38         KeyManager km = controller.getKeyManager();
39         NodeEnumeration nodes = km.selectByKey(keyfingerprint, doc, keyvalue, controller);
40         while(nodes.hasMoreElements()) {
41             if (nodes.nextElement().isSameNode(e)) {
42                 return true;
43             }
44         }
45         return false;
46     }
47
48 }
49
50 //
51
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
52
// you may not use this file except in compliance with the License. You may obtain a copy of the
53
// License at http://www.mozilla.org/MPL/
54
//
55
// Software distributed under the License is distributed on an "AS IS" basis,
56
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
57
// See the License for the specific language governing rights and limitations under the License.
58
//
59
// The Original Code is: all this file.
60
//
61
// The Initial Developer of the Original Code is
62
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
63
//
64
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
65
//
66
// Contributor(s): none.
67
//
68
Popular Tags