KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > dom > NodeSortRecordFactory


1 /*
2  * Copyright 2001-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: NodeSortRecordFactory.java,v 1.14 2004/02/27 01:58:29 zongaro Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.dom;
21
22 import com.sun.org.apache.xalan.internal.xsltc.DOM;
23 import com.sun.org.apache.xalan.internal.xsltc.Translet;
24 import com.sun.org.apache.xalan.internal.xsltc.TransletException;
25 import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
26 import com.sun.org.apache.xml.internal.utils.LocaleUtility;
27 import java.util.Locale JavaDoc;
28 import java.text.Collator JavaDoc;
29
30 public class NodeSortRecordFactory {
31
32     private static int DESCENDING = "descending".length();
33     private static int NUMBER = "number".length();
34
35     private final DOM _dom;
36     private final String JavaDoc _className;
37     private Class JavaDoc _class;
38     private SortSettings _sortSettings;
39
40     /**
41      *
42      */

43     protected Collator JavaDoc _collator;
44
45     /**
46      * Creates a NodeSortRecord producing object. The DOM specifies which tree
47      * to get the nodes to sort from, the class name specifies what auxillary
48      * class to use to sort the nodes (this class is generated by the Sort
49      * class), and the translet parameter is needed for methods called by
50      * this object.
51      *
52      * @deprecated This constructor is no longer used in generated code. It
53      * exists only for backwards compatibility.
54      */

55      public NodeSortRecordFactory(DOM dom, String JavaDoc className, Translet translet,
56                  String JavaDoc order[], String JavaDoc type[])
57          throws TransletException
58      {
59          this(dom, className, translet, order, type, null, null);
60      }
61
62     /**
63      * Creates a NodeSortRecord producing object. The DOM specifies which tree
64      * to get the nodes to sort from, the class name specifies what auxillary
65      * class to use to sort the nodes (this class is generated by the Sort
66      * class), and the translet parameter is needed for methods called by
67      * this object.
68      */

69      public NodeSortRecordFactory(DOM dom, String JavaDoc className, Translet translet,
70                  String JavaDoc order[], String JavaDoc type[], String JavaDoc lang[],
71                  String JavaDoc caseOrder[])
72          throws TransletException
73      {
74          try {
75              _dom = dom;
76              _className = className;
77              // This should return a Class definition if using TrAX
78
_class = translet.getAuxiliaryClass(className);
79              // This code is only run when the native API is used
80
if (_class == null) {
81                  _class = ObjectFactory.findProviderClass(
82                       className, ObjectFactory.findClassLoader(), true);
83              }
84
85              int levels = order.length;
86              int[] iOrder = new int[levels];
87              int[] iType = new int[levels];
88              for (int i = 0; i < levels; i++) {
89                   if (order[i].length() == DESCENDING) {
90                       iOrder[i] = NodeSortRecord.COMPARE_DESCENDING;
91                   }
92                   if (type[i].length() == NUMBER) {
93                       iType[i] = NodeSortRecord.COMPARE_NUMERIC;
94                   }
95              }
96
97              // Old NodeSortRecordFactory constructor had no lang or case_order
98
// arguments. Provide default values in that case for binary
99
// compatibility.
100
String JavaDoc[] emptyStringArray = null;
101              if (lang == null || caseOrder == null) {
102                  int numSortKeys = order.length;
103                  emptyStringArray = new String JavaDoc[numSortKeys];
104
105                  // Set up array of zero-length strings as default values
106
// of lang and case_order
107
for (int i = 0; i < numSortKeys; i++) {
108                      emptyStringArray[i] = "";
109                  }
110              }
111
112              if (lang == null) {
113                  lang = emptyStringArray;
114              }
115              if (caseOrder == null) {
116                  caseOrder = emptyStringArray;
117              }
118
119              final int length = lang.length;
120              Locale JavaDoc[] locales = new Locale JavaDoc[length];
121              Collator JavaDoc[] collators = new Collator JavaDoc[length];
122              for (int i = 0; i< length; i++){
123                  locales[i] = LocaleUtility.langToLocale(lang[i]);
124                  collators[i] = Collator.getInstance(locales[i]);
125              }
126
127              _sortSettings = new SortSettings((AbstractTranslet) translet,
128                                               iOrder, iType, locales, collators,
129                                               caseOrder);
130         } catch (ClassNotFoundException JavaDoc e) {
131             throw new TransletException(e);
132         }
133     }
134     
135     
136
137     /**
138      * Create an instance of a sub-class of NodeSortRecord. The name of this
139      * sub-class is passed to us in the constructor.
140      */

141     public NodeSortRecord makeNodeSortRecord(int node, int last)
142     throws ExceptionInInitializerError JavaDoc,
143            LinkageError JavaDoc,
144            IllegalAccessException JavaDoc,
145            InstantiationException JavaDoc,
146            SecurityException JavaDoc,
147            TransletException {
148
149     final NodeSortRecord sortRecord =
150         (NodeSortRecord)_class.newInstance();
151     sortRecord.initialize(node, last, _dom, _sortSettings);
152     return sortRecord;
153     }
154
155     public String JavaDoc getClassName() {
156     return _className;
157     }
158     
159    private final void setLang(final String JavaDoc lang[]){
160         
161     }
162 }
163
Popular Tags