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. /*
  17. * $Id: XMLStringFactoryImpl.java,v 1.6 2004/02/17 04:34:38 minchau Exp $
  18. */
  19. package com.sun.org.apache.xpath.internal.objects;
  20. import com.sun.org.apache.xml.internal.utils.FastStringBuffer;
  21. import com.sun.org.apache.xml.internal.utils.XMLString;
  22. import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
  23. /**
  24. * Class XMLStringFactoryImpl creates XString versions of XMLStrings.
  25. * @xsl.usage internal
  26. */
  27. public class XMLStringFactoryImpl extends XMLStringFactory
  28. {
  29. /** The XMLStringFactory to pass to DTM construction. */
  30. private static XMLStringFactory m_xstringfactory =
  31. new XMLStringFactoryImpl();
  32. /**
  33. * Get the XMLStringFactory to pass to DTM construction.
  34. *
  35. *
  36. * @return A never-null static reference to a String factory.
  37. */
  38. public static XMLStringFactory getFactory()
  39. {
  40. return m_xstringfactory;
  41. }
  42. /**
  43. * Create a new XMLString from a Java string.
  44. *
  45. *
  46. * @param string Java String reference, which must be non-null.
  47. *
  48. * @return An XMLString object that wraps the String reference.
  49. */
  50. public XMLString newstr(String string)
  51. {
  52. return new XString(string);
  53. }
  54. /**
  55. * Create a XMLString from a FastStringBuffer.
  56. *
  57. *
  58. * @param string FastStringBuffer reference, which must be non-null.
  59. * @param start The start position in the array.
  60. * @param length The number of characters to read from the array.
  61. *
  62. * @return An XMLString object that wraps the FastStringBuffer reference.
  63. */
  64. public XMLString newstr(FastStringBuffer fsb, int start, int length)
  65. {
  66. return new XStringForFSB(fsb, start, length);
  67. }
  68. /**
  69. * Create a XMLString from a FastStringBuffer.
  70. *
  71. *
  72. * @param string FastStringBuffer reference, which must be non-null.
  73. * @param start The start position in the array.
  74. * @param length The number of characters to read from the array.
  75. *
  76. * @return An XMLString object that wraps the FastStringBuffer reference.
  77. */
  78. public XMLString newstr(char[] string, int start, int length)
  79. {
  80. return new XStringForChars(string, start, length);
  81. }
  82. /**
  83. * Get a cheap representation of an empty string.
  84. *
  85. * @return An non-null reference to an XMLString that represents "".
  86. */
  87. public XMLString emptystr()
  88. {
  89. return XString.EMPTYSTRING;
  90. }
  91. }