private void parseName()

in modules/jndi/src/main/java/javax/naming/CompoundName.java [429:528]


    private void parseName(String s) throws InvalidNameException {
        this.elem = new Vector<String>();
        if ("".equals(s)) { //$NON-NLS-1$
            // if empty string, return empty vector
            return;
        }

        // init variables
        int status = INIT_STATUS;
        StringBuilder element = new StringBuilder();
        int pos = 0;
        int length = s.length();
        boolean hasNotNullElement = false;
        boolean includeQuote = false;

        // scan name
        while (pos < length) {
            if (startsWithFromPos(s, pos, endQuoteString)
                    && status == QUOTE1_STATUS) {
                status = QUOTEEND_STATUS;
                pos += addBuffer(element, endQuoteString, includeQuote);
            } else if (startsWithFromPos(s, pos, endQuoteString2)
                    && status == QUOTE2_STATUS) {
                status = QUOTEEND_STATUS;
                pos += addBuffer(element, endQuoteString2, includeQuote);
            } else if (startsWithFromPos(s, pos, beginQuoteString)
                    && status == INIT_STATUS) {
                hasNotNullElement = true;
                status = QUOTE1_STATUS;
                pos += addBuffer(element, beginQuoteString, includeQuote);
            } else if (startsWithFromPos(s, pos, beginQuoteString2)
                    && status == INIT_STATUS) {
                hasNotNullElement = true;
                status = QUOTE2_STATUS;
                pos += addBuffer(element, beginQuoteString2, includeQuote);
            } else if (startsWithFromPos(s, pos, separatorString)
                    && (!flat)
                    && (status == INIT_STATUS || status == QUOTEEND_STATUS || status == NORMAL_STATUS)) {
                hasNotNullElement = hasNotNullElement || element.length() > 0;
                addElement(element);
                status = INIT_STATUS;
                pos += separatorString.length();
                includeQuote = false;
            } else if (startsWithFromPos(s, pos, separatorString2)
                    && (!flat)
                    && (status == INIT_STATUS || status == QUOTEEND_STATUS || status == NORMAL_STATUS)) {
                hasNotNullElement = hasNotNullElement || element.length() > 0;
                addElement(element);
                status = INIT_STATUS;
                pos += separatorString2.length();
                includeQuote = false;
            } else if (startsWithFromPos(s, pos, escapeString)) {
                pos += escapeString.length();
                if (pos == s.length()) {
                    // if this escape char is last character, throw exception
                    // jndi.06=The {0} cannot be at end of the component
                    throw new InvalidNameException(Messages.getString(
                            "jndi.06", escapeString)); //$NON-NLS-1$
                }
                // if one escape char followed by a special char, append the
                // special char to current element
                String str = extractEscapedString(s, pos, status);
                if (null == str) {
                    pos -= escapeString.length();
                    element.append(s.charAt(pos++));
                } else {
                    pos += str.length();
                    element.append(str);
                }

            } else if (startsWithFromPos(s, pos, sepTypeValString)
                    && (status == INIT_STATUS || status == NORMAL_STATUS)) {
                includeQuote = true;
                pos += addBuffer(element, sepTypeValString, true);
                status = INIT_STATUS;
            } else if (startsWithFromPos(s, pos, sepAvaString)
                    && (status == INIT_STATUS || status == NORMAL_STATUS)) {
                includeQuote = true;
                pos += addBuffer(element, sepAvaString, true);
                status = INIT_STATUS;
            } else if (status == QUOTEEND_STATUS) {
                // jndi.07={0}: close quote must appears at end of component in
                // quoted string
                throw new InvalidNameException(Messages.getString("jndi.07", s)); //$NON-NLS-1$
            } else {
                status = status == INIT_STATUS ? NORMAL_STATUS : status;
                element.append(s.charAt(pos++));
            }
        }
        if (QUOTE1_STATUS != status && QUOTE2_STATUS != status) {
            hasNotNullElement = hasNotNullElement || element.length() > 0;
            addElement(element);
        } else {
            // jndi.08={0}: close quote is required for quoted string
            throw new InvalidNameException(Messages.getString("jndi.08", s)); //$NON-NLS-1$
        }
        if (!hasNotNullElement) {
            elem.remove(elem.size() - 1);
        }
    }