001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: XMLStringFactoryImpl.java 468655 2006-10-28 07:12:06Z minchau $
020     */
021    package org.apache.xpath.objects;
022    
023    import org.apache.xml.utils.FastStringBuffer;
024    import org.apache.xml.utils.XMLString;
025    import org.apache.xml.utils.XMLStringFactory;
026    
027    /**
028     * Class XMLStringFactoryImpl creates XString versions of XMLStrings.
029     * @xsl.usage internal
030     */
031    public class XMLStringFactoryImpl extends XMLStringFactory
032    {
033      /** The XMLStringFactory to pass to DTM construction.   */
034      private static XMLStringFactory m_xstringfactory =
035        new XMLStringFactoryImpl();
036    
037      /**
038       * Get the XMLStringFactory to pass to DTM construction.
039       *
040       *
041       * @return A never-null static reference to a String factory.
042       */
043      public static XMLStringFactory getFactory()
044      {
045        return m_xstringfactory;
046      }
047    
048      /**
049       * Create a new XMLString from a Java string.
050       *
051       *
052       * @param string Java String reference, which must be non-null.
053       *
054       * @return An XMLString object that wraps the String reference.
055       */
056      public XMLString newstr(String string)
057      {
058        return new XString(string);
059      }
060    
061      /**
062       * Create a XMLString from a FastStringBuffer.
063       *
064       *
065       * @param fsb FastStringBuffer reference, which must be non-null.
066       * @param start The start position in the array.
067       * @param length The number of characters to read from the array.
068       *
069       * @return An XMLString object that wraps the FastStringBuffer reference.
070       */
071      public XMLString newstr(FastStringBuffer fsb, int start, int length)
072      {
073        return new XStringForFSB(fsb, start, length);
074      }
075      
076      /**
077       * Create a XMLString from a FastStringBuffer.
078       *
079       *
080       * @param string FastStringBuffer reference, which must be non-null.
081       * @param start The start position in the array.
082       * @param length The number of characters to read from the array.
083       *
084       * @return An XMLString object that wraps the FastStringBuffer reference.
085       */
086      public XMLString newstr(char[] string, int start, int length)
087      {
088        return new XStringForChars(string, start, length);
089      }
090      
091      /**
092       * Get a cheap representation of an empty string.
093       * 
094       * @return An non-null reference to an XMLString that represents "".
095       */
096      public XMLString emptystr()
097      {
098        return XString.EMPTYSTRING;
099      }
100    
101    }