1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is Neil Deakin
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either of the GNU General Public License Version 2 or later (the "GPL"),
25 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsXMLBinding_h__
38 #define nsXMLBinding_h__
40 #include "nsAutoPtr.h"
43 class nsXULTemplateResultXML
;
44 class nsXMLBindingValues
;
47 * Classes related to storing bindings for XML handling.
51 * a <binding> description
54 nsCOMPtr
<nsIAtom
> mVar
;
55 nsCOMPtr
<nsIDOMXPathExpression
> mExpr
;
57 nsAutoPtr
<nsXMLBinding
> mNext
;
59 nsXMLBinding(nsIAtom
* aVar
, nsIDOMXPathExpression
* aExpr
)
60 : mVar(aVar
), mExpr(aExpr
), mNext(nsnull
)
62 MOZ_COUNT_CTOR(nsXMLBinding
);
67 MOZ_COUNT_DTOR(nsXMLBinding
);
72 * a collection of <binding> descriptors. This object is refcounted by
73 * nsXMLBindingValues objects and the query processor.
79 // results hold a reference to a binding set in their
80 // nsXMLBindingValues fields
83 // pointer to the first binding in a linked list
84 nsAutoPtr
<nsXMLBinding
> mFirst
;
88 NS_IMETHOD_(nsrefcnt
) AddRef();
89 NS_IMETHOD_(nsrefcnt
) Release();
93 * Add a binding to the set
96 AddBinding(nsIAtom
* aVar
, nsIDOMXPathExpression
* aExpr
);
99 * The nsXMLBindingValues class stores an array of values, one for each
100 * target symbol that could be set by the bindings in the set.
101 * LookupTargetIndex determines the index into the array for a given
105 LookupTargetIndex(nsIAtom
* aTargetVariable
, nsXMLBinding
** aBinding
);
109 * a set of values of bindings. This object is used once per result.
111 class nsXMLBindingValues
116 nsRefPtr
<nsXMLBindingSet
> mBindings
;
119 * A set of values for variable bindings. To look up a binding value,
120 * scan through the binding set in mBindings for the right target atom.
121 * Its index will correspond to the index in this array.
123 nsCOMArray
<nsIDOMXPathResult
> mValues
;
127 nsXMLBindingValues() { MOZ_COUNT_CTOR(nsXMLBindingValues
); }
128 ~nsXMLBindingValues() { MOZ_COUNT_DTOR(nsXMLBindingValues
); }
130 nsXMLBindingSet
* GetBindingSet() { return mBindings
; }
132 void SetBindingSet(nsXMLBindingSet
* aBindings
) { mBindings
= aBindings
; }
135 LookupTargetIndex(nsIAtom
* aTargetVariable
, nsXMLBinding
** aBinding
)
138 mBindings
->LookupTargetIndex(aTargetVariable
, aBinding
) : -1;
142 * Retrieve the assignment for a particular variable
144 * aResult the result generated from the template
145 * aBinding the binding looked up using LookupTargetIndex
146 * aIndex the index of the assignment to retrieve
147 * aType the type of result expected
148 * aValue the value of the assignment
151 GetAssignmentFor(nsXULTemplateResultXML
* aResult
,
152 nsXMLBinding
* aBinding
,
155 nsIDOMXPathResult
** aValue
);
158 GetNodeAssignmentFor(nsXULTemplateResultXML
* aResult
,
159 nsXMLBinding
* aBinding
,
161 nsIDOMNode
** aValue
);
164 GetStringAssignmentFor(nsXULTemplateResultXML
* aResult
,
165 nsXMLBinding
* aBinding
,
170 #endif // nsXMLBinding_h__