1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.processor;
  58. import org.xml.sax.ContentHandler;
  59. import org.apache.xalan.templates.Constants;
  60. import org.apache.xml.utils.QName;
  61. import org.apache.xalan.res.XSLMessages;
  62. import org.apache.xalan.res.XSLTErrorResources;
  63. import java.util.Hashtable;
  64. import java.util.Enumeration;
  65. /**
  66. * This class defines the allowed structure for an element in a XSLT stylesheet,
  67. * is meant to reflect the structure defined in http://www.w3.org/TR/xslt#dtd, and the
  68. * mapping between Xalan classes and the markup elements in the XSLT instance.
  69. * This actually represents both text nodes and elements.
  70. */
  71. public class XSLTElementDef
  72. {
  73. /**
  74. * Construct an instance of XSLTElementDef. This must be followed by a
  75. * call to build().
  76. */
  77. XSLTElementDef(){}
  78. /**
  79. * Construct an instance of XSLTElementDef.
  80. *
  81. * @param namespace The Namespace URI, "*", or null.
  82. * @param name The local name (without prefix), "*", or null.
  83. * @param nameAlias A potential alias for the name, or null.
  84. * @param elements An array of allowed child element defs, or null.
  85. * @param attributes An array of allowed attribute defs, or null.
  86. * @param contentHandler The element processor for this element.
  87. * @param classObject The class of the object that this element def should produce.
  88. */
  89. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  90. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  91. XSLTElementProcessor contentHandler, Class classObject)
  92. {
  93. build(namespace, name, nameAlias, elements, attributes, contentHandler,
  94. classObject);
  95. if ( (null != namespace)
  96. && (namespace.equals(Constants.S_XSLNAMESPACEURL)
  97. || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)
  98. || namespace.equals(Constants.S_BUILTIN_OLD_EXTENSIONS_URL)))
  99. {
  100. schema.addAvailableElement(new QName(namespace, name));
  101. if(null != nameAlias)
  102. schema.addAvailableElement(new QName(namespace, nameAlias));
  103. }
  104. }
  105. /**
  106. * Construct an instance of XSLTElementDef.
  107. *
  108. * @param namespace The Namespace URI, "*", or null.
  109. * @param name The local name (without prefix), "*", or null.
  110. * @param nameAlias A potential alias for the name, or null.
  111. * @param elements An array of allowed child element defs, or null.
  112. * @param attributes An array of allowed attribute defs, or null.
  113. * @param contentHandler The element processor for this element.
  114. * @param classObject The class of the object that this element def should produce.
  115. * @param has_required true if this element has required elements by the XSLT specification.
  116. */
  117. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  118. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  119. XSLTElementProcessor contentHandler, Class classObject, boolean has_required)
  120. {
  121. this.m_has_required = has_required;
  122. build(namespace, name, nameAlias, elements, attributes, contentHandler,
  123. classObject);
  124. if ( (null != namespace)
  125. && (namespace.equals(Constants.S_XSLNAMESPACEURL)
  126. || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)
  127. || namespace.equals(Constants.S_BUILTIN_OLD_EXTENSIONS_URL)))
  128. {
  129. schema.addAvailableElement(new QName(namespace, name));
  130. if(null != nameAlias)
  131. schema.addAvailableElement(new QName(namespace, nameAlias));
  132. }
  133. }
  134. /**
  135. * Construct an instance of XSLTElementDef.
  136. *
  137. * @param namespace The Namespace URI, "*", or null.
  138. * @param name The local name (without prefix), "*", or null.
  139. * @param nameAlias A potential alias for the name, or null.
  140. * @param elements An array of allowed child element defs, or null.
  141. * @param attributes An array of allowed attribute defs, or null.
  142. * @param contentHandler The element processor for this element.
  143. * @param classObject The class of the object that this element def should produce.
  144. * @param has_required true if this element has required elements by the XSLT specification.
  145. * @param required true if this element is required by the XSLT specification.
  146. */
  147. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  148. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  149. XSLTElementProcessor contentHandler, Class classObject,
  150. boolean has_required, boolean required)
  151. {
  152. this(schema, namespace, name, nameAlias,
  153. elements, attributes,
  154. contentHandler, classObject, has_required);
  155. this.m_required = required;
  156. }
  157. /**
  158. * Construct an instance of XSLTElementDef.
  159. *
  160. * @param namespace The Namespace URI, "*", or null.
  161. * @param name The local name (without prefix), "*", or null.
  162. * @param nameAlias A potential alias for the name, or null.
  163. * @param elements An array of allowed child element defs, or null.
  164. * @param attributes An array of allowed attribute defs, or null.
  165. * @param contentHandler The element processor for this element.
  166. * @param classObject The class of the object that this element def should produce.
  167. * @param has_required true if this element has required elements by the XSLT specification.
  168. * @param required true if this element is required by the XSLT specification.
  169. * @param order the order this element should appear according to the XSLT specification.
  170. * @param multiAllowed whether this element is allowed more than once
  171. */
  172. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  173. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  174. XSLTElementProcessor contentHandler, Class classObject,
  175. boolean has_required, boolean required, int order,
  176. boolean multiAllowed)
  177. {
  178. this(schema, namespace, name, nameAlias,
  179. elements, attributes,
  180. contentHandler, classObject, has_required, required);
  181. this.m_order = order;
  182. this.m_multiAllowed = multiAllowed;
  183. }
  184. /**
  185. * Construct an instance of XSLTElementDef.
  186. *
  187. * @param namespace The Namespace URI, "*", or null.
  188. * @param name The local name (without prefix), "*", or null.
  189. * @param nameAlias A potential alias for the name, or null.
  190. * @param elements An array of allowed child element defs, or null.
  191. * @param attributes An array of allowed attribute defs, or null.
  192. * @param contentHandler The element processor for this element.
  193. * @param classObject The class of the object that this element def should produce.
  194. * @param has_required true if this element has required elements by the XSLT specification.
  195. * @param required true if this element is required by the XSLT specification.
  196. * @param has_order whether this element has ordered child elements
  197. * @param order the order this element should appear according to the XSLT specification.
  198. * @param multiAllowed whether this element is allowed more than once
  199. */
  200. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  201. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  202. XSLTElementProcessor contentHandler, Class classObject,
  203. boolean has_required, boolean required, boolean has_order, int order,
  204. boolean multiAllowed)
  205. {
  206. this(schema, namespace, name, nameAlias,
  207. elements, attributes,
  208. contentHandler, classObject, has_required, required);
  209. this.m_order = order;
  210. this.m_multiAllowed = multiAllowed;
  211. this.m_isOrdered = has_order;
  212. }
  213. /**
  214. * Construct an instance of XSLTElementDef.
  215. *
  216. * @param namespace The Namespace URI, "*", or null.
  217. * @param name The local name (without prefix), "*", or null.
  218. * @param nameAlias A potential alias for the name, or null.
  219. * @param elements An array of allowed child element defs, or null.
  220. * @param attributes An array of allowed attribute defs, or null.
  221. * @param contentHandler The element processor for this element.
  222. * @param classObject The class of the object that this element def should produce.
  223. * @param has_order whether this element has ordered child elements
  224. * @param order the order this element should appear according to the XSLT specification.
  225. * @param multiAllowed whether this element is allowed more than once
  226. */
  227. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  228. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  229. XSLTElementProcessor contentHandler, Class classObject,
  230. boolean has_order, int order, boolean multiAllowed)
  231. {
  232. this(schema, namespace, name, nameAlias,
  233. elements, attributes,
  234. contentHandler, classObject,
  235. order, multiAllowed);
  236. this.m_isOrdered = has_order;
  237. }
  238. /**
  239. * Construct an instance of XSLTElementDef.
  240. *
  241. * @param namespace The Namespace URI, "*", or null.
  242. * @param name The local name (without prefix), "*", or null.
  243. * @param nameAlias A potential alias for the name, or null.
  244. * @param elements An array of allowed child element defs, or null.
  245. * @param attributes An array of allowed attribute defs, or null.
  246. * @param contentHandler The element processor for this element.
  247. * @param classObject The class of the object that this element def should produce.
  248. * @param order the order this element should appear according to the XSLT specification.
  249. * @param multiAllowed whether this element is allowed more than once
  250. */
  251. XSLTElementDef(XSLTSchema schema, String namespace, String name, String nameAlias,
  252. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  253. XSLTElementProcessor contentHandler, Class classObject,
  254. int order, boolean multiAllowed)
  255. {
  256. this(schema, namespace, name, nameAlias, elements, attributes, contentHandler,
  257. classObject);
  258. this.m_order = order;
  259. this.m_multiAllowed = multiAllowed;
  260. }
  261. /**
  262. * Construct an instance of XSLTElementDef that represents text.
  263. *
  264. * @param classObject The class of the object that this element def should produce.
  265. * @param contentHandler The element processor for this element.
  266. * @param type Content type, one of T_ELEMENT, T_PCDATA, or T_ANY.
  267. */
  268. XSLTElementDef(Class classObject, XSLTElementProcessor contentHandler,
  269. int type)
  270. {
  271. this.m_classObject = classObject;
  272. this.m_type = type;
  273. setElementProcessor(contentHandler);
  274. }
  275. /**
  276. * Construct an instance of XSLTElementDef.
  277. *
  278. * @param namespace The Namespace URI, "*", or null.
  279. * @param name The local name (without prefix), "*", or null.
  280. * @param nameAlias A potential alias for the name, or null.
  281. * @param elements An array of allowed child element defs, or null.
  282. * @param attributes An array of allowed attribute defs, or null.
  283. * @param contentHandler The element processor for this element.
  284. * @param classObject The class of the object that this element def should produce.
  285. */
  286. void build(String namespace, String name, String nameAlias,
  287. XSLTElementDef[] elements, XSLTAttributeDef[] attributes,
  288. XSLTElementProcessor contentHandler, Class classObject)
  289. {
  290. this.m_namespace = namespace;
  291. this.m_name = name;
  292. this.m_nameAlias = nameAlias;
  293. this.m_elements = elements;
  294. this.m_attributes = attributes;
  295. setElementProcessor(contentHandler);
  296. this.m_classObject = classObject;
  297. if (hasRequired() && m_elements != null)
  298. {
  299. int n = m_elements.length;
  300. for (int i = 0; i < n; i++)
  301. {
  302. XSLTElementDef def = m_elements[i];
  303. if (def != null && def.getRequired())
  304. {
  305. if (m_requiredFound == null)
  306. m_requiredFound = new Hashtable();
  307. m_requiredFound.put(def.getName(), "xsl:" +def.getName());
  308. }
  309. }
  310. }
  311. }
  312. /**
  313. * Tell if two objects are equal, when either one may be null.
  314. * If both are null, they are considered equal.
  315. *
  316. * @param obj1 A reference to the first object, or null.
  317. * @param obj2 A reference to the second object, or null.
  318. *
  319. * @return true if the to objects are equal by both being null or
  320. * because obj2.equals(obj1) returns true.
  321. */
  322. private static boolean equalsMayBeNull(Object obj1, Object obj2)
  323. {
  324. return (obj2 == obj1)
  325. || ((null != obj1) && (null != obj2) && obj2.equals(obj1));
  326. }
  327. /**
  328. * Tell if the two string refs are equal,
  329. * equality being defined as:
  330. * 1) Both strings are null.
  331. * 2) One string is null and the other is empty.
  332. * 3) Both strings are non-null, and equal.
  333. *
  334. * @param s1 A reference to the first string, or null.
  335. * @param s2 A reference to the second string, or null.
  336. *
  337. * @return true if Both strings are null, or if
  338. * one string is null and the other is empty, or if
  339. * both strings are non-null, and equal because
  340. * s1.equals(s2) returns true.
  341. */
  342. private static boolean equalsMayBeNullOrZeroLen(String s1, String s2)
  343. {
  344. int len1 = (s1 == null) ? 0 : s1.length();
  345. int len2 = (s2 == null) ? 0 : s2.length();
  346. return (len1 != len2) ? false
  347. : (len1 == 0) ? true
  348. : s1.equals(s2);
  349. }
  350. /** Content type enumerations */
  351. static final int T_ELEMENT = 1, T_PCDATA = 2, T_ANY = 3;
  352. /**
  353. * The type of this element.
  354. */
  355. private int m_type = T_ELEMENT;
  356. /**
  357. * Get the type of this element.
  358. *
  359. * @return Content type, one of T_ELEMENT, T_PCDATA, or T_ANY.
  360. */
  361. int getType()
  362. {
  363. return m_type;
  364. }
  365. /**
  366. * Set the type of this element.
  367. *
  368. * @param t Content type, one of T_ELEMENT, T_PCDATA, or T_ANY.
  369. */
  370. void setType(int t)
  371. {
  372. m_type = t;
  373. }
  374. /**
  375. * The allowed namespace for this element.
  376. */
  377. private String m_namespace;
  378. /**
  379. * Get the allowed namespace for this element.
  380. *
  381. * @return The Namespace URI, "*", or null.
  382. */
  383. String getNamespace()
  384. {
  385. return m_namespace;
  386. }
  387. /**
  388. * The name of this element.
  389. */
  390. private String m_name;
  391. /**
  392. * Get the local name of this element.
  393. *
  394. * @return The local name of this element, "*", or null.
  395. */
  396. String getName()
  397. {
  398. return m_name;
  399. }
  400. /**
  401. * The name of this element.
  402. */
  403. private String m_nameAlias;
  404. /**
  405. * Get the name of this element.
  406. *
  407. * @return A potential alias for the name, or null.
  408. */
  409. String getNameAlias()
  410. {
  411. return m_nameAlias;
  412. }
  413. /**
  414. * The allowed elements for this type.
  415. */
  416. private XSLTElementDef[] m_elements;
  417. /**
  418. * Get the allowed elements for this type.
  419. *
  420. * @return An array of allowed child element defs, or null.
  421. */
  422. XSLTElementDef[] getElements()
  423. {
  424. return m_elements;
  425. }
  426. /**
  427. * Set the allowed elements for this type.
  428. *
  429. * @param defs An array of allowed child element defs, or null.
  430. */
  431. void setElements(XSLTElementDef[] defs)
  432. {
  433. m_elements = defs;
  434. }
  435. /**
  436. * Tell if the namespace URI and local name match this
  437. * element.
  438. * @param uri The namespace uri, which may be null.
  439. * @param localName The local name of an element, which may be null.
  440. *
  441. * @return true if the uri and local name arguments are considered
  442. * to match the uri and local name of this element def.
  443. */
  444. private boolean QNameEquals(String uri, String localName)
  445. {
  446. return (equalsMayBeNullOrZeroLen(m_namespace, uri)
  447. && (equalsMayBeNullOrZeroLen(m_name, localName)
  448. || equalsMayBeNullOrZeroLen(m_nameAlias, localName)));
  449. }
  450. /**
  451. * Given a namespace URI, and a local name, get the processor
  452. * for the element, or return null if not allowed.
  453. *
  454. * @param uri The Namespace URI, or an empty string.
  455. * @param localName The local name (without prefix), or empty string if not namespace processing.
  456. *
  457. * @return The element processor that matches the arguments, or null.
  458. */
  459. XSLTElementProcessor getProcessorFor(String uri, String localName)
  460. {
  461. XSLTElementProcessor elemDef = null; // return value
  462. if (null == m_elements)
  463. return null;
  464. int n = m_elements.length;
  465. int order = -1;
  466. boolean multiAllowed = true;
  467. for (int i = 0; i < n; i++)
  468. {
  469. XSLTElementDef def = m_elements[i];
  470. // A "*" signals that the element allows literal result
  471. // elements, so just assign the def, and continue to
  472. // see if anything else matches.
  473. if (def.m_name.equals("*"))
  474. {
  475. // Don't allow xsl elements
  476. if (!equalsMayBeNullOrZeroLen(uri, Constants.S_XSLNAMESPACEURL))
  477. {
  478. elemDef = def.m_elementProcessor;
  479. order = def.getOrder();
  480. multiAllowed = def.getMultiAllowed();
  481. }
  482. }
  483. else if (def.QNameEquals(uri, localName))
  484. {
  485. if (def.getRequired())
  486. this.setRequiredFound(def.getName(), true);
  487. order = def.getOrder();
  488. multiAllowed = def.getMultiAllowed();
  489. elemDef = def.m_elementProcessor;
  490. break;
  491. }
  492. }
  493. if (elemDef != null && this.isOrdered())
  494. {
  495. int lastOrder = getLastOrder();
  496. if (order > lastOrder)
  497. setLastOrder(order);
  498. else if (order == lastOrder && !multiAllowed)
  499. {
  500. return null;
  501. }
  502. else if (order < lastOrder && order > 0)
  503. {
  504. return null;
  505. }
  506. }
  507. return elemDef;
  508. }
  509. /**
  510. * Given an unknown element, get the processor
  511. * for the element.
  512. *
  513. * @param uri The Namespace URI, or an empty string.
  514. * @param localName The local name (without prefix), or empty string if not namespace processing.
  515. *
  516. * @return normally a {@link ProcessorUnknown} reference.
  517. * @see ProcessorUnknown
  518. */
  519. XSLTElementProcessor getProcessorForUnknown(String uri, String localName)
  520. {
  521. // XSLTElementProcessor lreDef = null; // return value
  522. if (null == m_elements)
  523. return null;
  524. int n = m_elements.length;
  525. for (int i = 0; i < n; i++)
  526. {
  527. XSLTElementDef def = m_elements[i];
  528. if (def.m_name.equals("unknown") && uri.length() > 0)
  529. {
  530. return def.m_elementProcessor;
  531. }
  532. }
  533. return null;
  534. }
  535. /**
  536. * The allowed attributes for this type.
  537. */
  538. private XSLTAttributeDef[] m_attributes;
  539. /**
  540. * Get the allowed attributes for this type.
  541. *
  542. * @return An array of allowed attribute defs, or null.
  543. */
  544. XSLTAttributeDef[] getAttributes()
  545. {
  546. return m_attributes;
  547. }
  548. /**
  549. * Given a namespace URI, and a local name, return the element's
  550. * attribute definition, if it has one.
  551. *
  552. * @param uri The Namespace URI, or an empty string.
  553. * @param localName The local name (without prefix), or empty string if not namespace processing.
  554. *
  555. * @return The attribute def that matches the arguments, or null.
  556. */
  557. XSLTAttributeDef getAttributeDef(String uri, String localName)
  558. {
  559. XSLTAttributeDef defaultDef = null;
  560. XSLTAttributeDef[] attrDefs = getAttributes();
  561. int nAttrDefs = attrDefs.length;
  562. for (int k = 0; k < nAttrDefs; k++)
  563. {
  564. XSLTAttributeDef attrDef = attrDefs[k];
  565. String uriDef = attrDef.getNamespace();
  566. String nameDef = attrDef.getName();
  567. if (nameDef.equals("*") && (equalsMayBeNullOrZeroLen(uri, uriDef) ||
  568. (uriDef != null && uriDef.equals("*") && uri!=null && uri.length() > 0 )))
  569. {
  570. return attrDef;
  571. }
  572. else if (nameDef.equals("*") && (uriDef == null))
  573. {
  574. // In this case, all attributes are legal, so return
  575. // this as the last resort.
  576. defaultDef = attrDef;
  577. }
  578. else if (equalsMayBeNullOrZeroLen(uri, uriDef)
  579. && localName.equals(nameDef))
  580. {
  581. return attrDef;
  582. }
  583. }
  584. if (null == defaultDef)
  585. {
  586. if (uri.length() > 0 && !equalsMayBeNullOrZeroLen(uri, Constants.S_XSLNAMESPACEURL))
  587. {
  588. return XSLTAttributeDef.m_foreignAttr;
  589. }
  590. }
  591. return defaultDef;
  592. }
  593. /**
  594. * If non-null, the ContentHandler/TransformerFactory for this element.
  595. */
  596. private XSLTElementProcessor m_elementProcessor;
  597. /**
  598. * Return the XSLTElementProcessor for this element.
  599. *
  600. * @return The element processor for this element.
  601. */
  602. XSLTElementProcessor getElementProcessor()
  603. {
  604. return m_elementProcessor;
  605. }
  606. /**
  607. * Set the XSLTElementProcessor for this element.
  608. *
  609. * @param handler The element processor for this element.
  610. */
  611. void setElementProcessor(XSLTElementProcessor handler)
  612. {
  613. if (handler != null)
  614. {
  615. m_elementProcessor = handler;
  616. m_elementProcessor.setElemDef(this);
  617. }
  618. }
  619. /**
  620. * If non-null, the class object that should in instantiated for
  621. * a Xalan instance of this element.
  622. */
  623. private Class m_classObject;
  624. /**
  625. * Return the class object that should in instantiated for
  626. * a Xalan instance of this element.
  627. *
  628. * @return The class of the object that this element def should produce, or null.
  629. */
  630. Class getClassObject()
  631. {
  632. return m_classObject;
  633. }
  634. /**
  635. * If true, this has a required element.
  636. */
  637. private boolean m_has_required = false;
  638. /**
  639. * Get whether or not this has a required element.
  640. *
  641. * @return true if this this has a required element.
  642. */
  643. boolean hasRequired()
  644. {
  645. return m_has_required;
  646. }
  647. /**
  648. * If true, this is a required element.
  649. */
  650. private boolean m_required = false;
  651. /**
  652. * Get whether or not this is a required element.
  653. *
  654. * @return true if this is a required element.
  655. */
  656. boolean getRequired()
  657. {
  658. return m_required;
  659. }
  660. Hashtable m_requiredFound;
  661. /**
  662. * Set this required element found.
  663. *
  664. */
  665. void setRequiredFound(String elem, boolean found)
  666. {
  667. if (m_requiredFound.get(elem) != null)
  668. m_requiredFound.remove(elem);
  669. }
  670. /**
  671. * Get whether all required elements were found.
  672. *
  673. * @return true if all required elements were found.
  674. */
  675. boolean getRequiredFound()
  676. {
  677. if (m_requiredFound == null)
  678. return true;
  679. return m_requiredFound.isEmpty();
  680. }
  681. /**
  682. * Get required elements that were not found.
  683. *
  684. * @return required elements that were not found.
  685. */
  686. String getRequiredElem()
  687. {
  688. if (m_requiredFound == null)
  689. return null;
  690. Enumeration elems = m_requiredFound.elements();
  691. String s = "";
  692. boolean first = true;
  693. while (elems.hasMoreElements())
  694. {
  695. if (first)
  696. first = false;
  697. else
  698. s = s + ", ";
  699. s = s + (String)elems.nextElement();
  700. }
  701. return s;
  702. }
  703. boolean m_isOrdered = false;
  704. /**
  705. * Get whether this element requires ordered children.
  706. *
  707. * @return true if this element requires ordered children.
  708. */
  709. boolean isOrdered()
  710. {
  711. /*if (!m_CheckedOrdered)
  712. {
  713. m_CheckedOrdered = true;
  714. m_isOrdered = false;
  715. if (null == m_elements)
  716. return false;
  717. int n = m_elements.length;
  718. for (int i = 0; i < n; i++)
  719. {
  720. if (m_elements[i].getOrder() > 0)
  721. {
  722. m_isOrdered = true;
  723. return true;
  724. }
  725. }
  726. return false;
  727. }
  728. else*/
  729. return m_isOrdered;
  730. }
  731. /**
  732. * the order that this element should appear, or -1 if not ordered
  733. */
  734. private int m_order = -1;
  735. /**
  736. * Get the order that this element should appear .
  737. *
  738. * @return the order that this element should appear.
  739. */
  740. int getOrder()
  741. {
  742. return m_order;
  743. }
  744. /**
  745. * the highest order of child elements have appeared so far,
  746. * or -1 if not ordered
  747. */
  748. private int m_lastOrder = -1;
  749. /**
  750. * Get the highest order of child elements have appeared so far .
  751. *
  752. * @return the highest order of child elements have appeared so far.
  753. */
  754. int getLastOrder()
  755. {
  756. return m_lastOrder;
  757. }
  758. /**
  759. * Set the highest order of child elements have appeared so far .
  760. *
  761. * @param order the highest order of child elements have appeared so far.
  762. */
  763. void setLastOrder(int order)
  764. {
  765. m_lastOrder = order ;
  766. }
  767. /**
  768. * True if this element can appear multiple times
  769. */
  770. private boolean m_multiAllowed = true;
  771. /**
  772. * Get whether this element can appear multiple times
  773. *
  774. * @return true if this element can appear multiple times
  775. */
  776. boolean getMultiAllowed()
  777. {
  778. return m_multiAllowed;
  779. }
  780. }