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. package org.apache.commons.jxpath;
  17. /**
  18. * The {@link JXPathContext#createPath JXPathContext.createPath()} method of
  19. * JXPathContext can create missing objects as it traverses an XPath; it
  20. * utilizes an AbstractFactory for that purpose. Install a factory on
  21. * JXPathContext by calling {@link JXPathContext#setFactory JXPathContext.
  22. * setFactory()}.
  23. * <p>
  24. * All methods of this class return false. Override any of them to return true
  25. * to indicate that the factory has successfully created the described object.
  26. *
  27. * @author Dmitri Plotnikov
  28. * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:42 $
  29. */
  30. public abstract class AbstractFactory {
  31. /**
  32. * The parameters may describe a collection element or an individual
  33. * object. It is up to the factory to infer which one it is. If it is a
  34. * collection, the factory should check if the collection exists. If not,
  35. * it should create the collection. Then it should create the index'th
  36. * element of the collection and return true.
  37. * <p>
  38. *
  39. * @param context can be used to evaluate other XPaths, get to variables
  40. * etc.
  41. * @param pointer describes the location of the node to be created
  42. * @param parent is the object that will server as a parent of the new
  43. * object
  44. * @param name is the name of the child of the parent that needs to be
  45. * created. In the case of DOM may be qualified.
  46. * @param index is used if the pointer represents a collection element. You
  47. * may need to expand or even create the collection to accomodate the new
  48. * element.
  49. *
  50. * @return true if the object was successfully created
  51. */
  52. public boolean createObject(JXPathContext context, Pointer pointer,
  53. Object parent, String name, int index)
  54. {
  55. return false;
  56. }
  57. /**
  58. * Declare the specified variable
  59. *
  60. * @param context hosts variable pools. See
  61. * {@link JXPathContext#getVariables() JXPathContext.getVariables()}
  62. * @param name is the name of the variable without the "$" sign
  63. *
  64. * @return true if the variable was successfully defined
  65. */
  66. public boolean declareVariable(JXPathContext context, String name) {
  67. return false;
  68. }
  69. }