NameImpl.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The implementation class for CompoundName and CompositeName.
* This class is package private.
*
* @author Rosanna Lee
* @author Scott Seligman
* @author Aravindan Ranganathan
* @since 1.3
*/
class NameImpl {
private static final byte LEFT_TO_RIGHT = 1;
private static final byte RIGHT_TO_LEFT = 2;
private static final byte FLAT = 0;
private Vector components;
private byte syntaxDirection = LEFT_TO_RIGHT;
private boolean syntaxCaseInsensitive = false;
private boolean syntaxTrimBlanks = false;
// escapingStyle gives the method used at creation time for
// quoting or escaping characters in the name. It is set to the
// first style of quote or escape encountered if and when the name
// is parsed.
private static final int STYLE_NONE = 0;
private static final int STYLE_QUOTE1 = 1;
private static final int STYLE_QUOTE2 = 2;
private static final int STYLE_ESCAPE = 3;
private int escapingStyle = STYLE_NONE;
// Returns true if "match" is not null, and n contains "match" at
// position i.
}
return (isA(n, i, syntaxEscape) ||
isA(n, i, syntaxBeginQuote1) ||
isA(n, i, syntaxBeginQuote2) ||
isSeparator(n, i));
}
private final boolean isSeparator(String n, int i) {
return (isA(n, i, syntaxSeparator) ||
isA(n, i, syntaxSeparator2));
}
i += syntaxSeparator.length();
i += syntaxSeparator2.length();
}
return (i);
}
throws InvalidNameException {
boolean start = true;
boolean one = false;
while (i < len) {
// handle quoted strings
// record choice of quote chars being used
if (escapingStyle == STYLE_NONE) {
}
// consume string until matching quote
for (i += beginQuote.length();
i++) {
// skip escape character if it is escaping ending quote
// otherwise leave as is.
i += syntaxEscape.length();
}
}
// no ending quote found
if (i >= len)
throw
// new Exception("no close quote");
// verify that end-quote occurs at separator or end of string
break;
}
// throw (new Exception(
throw (new InvalidNameException(name +
": close quote appears before end of component"));
} else if (isSeparator(name, i)) {
break;
// if escape precedes meta, consume escape and let
// meta through
i += syntaxEscape.length();
if (escapingStyle == STYLE_NONE) {
}
throw (new InvalidNameException(name +
}
// Handle quote occurring after typeval separator
i += syntaxTypevalSeparator.length();
// consume string until matching quote
for (i += beginQuote.length();
i++) {
// skip escape character if it is escaping ending quote
// otherwise leave as is.
i += syntaxEscape.length();
}
}
// no ending quote found
if (i >= len)
throw
// verify that end-quote occurs at separator or end of string
break;
}
": typeval close quote appears before end of component"));
}
start = false;
}
if (syntaxDirection == RIGHT_TO_LEFT)
else
return i;
}
}
}
private final void recordNamingConvention(Properties p) {
} else {
throw new IllegalArgumentException(syntaxDirectionStr +
"is not a valid value for the jndi.syntax.direction property");
}
if (syntaxDirection != FLAT) {
if (syntaxSeparator == null) {
throw new IllegalArgumentException(
"jndi.syntax.separator property required for non-flat syntax");
}
} else {
}
p.getProperty("jndi.syntax.separator.typeval");
}
}
components = new Vector();
}
this(syntax);
boolean compsAllEmpty = true;
for (int i = 0; i < len; ) {
compsAllEmpty = false;
}
if (i < len) {
i = skipSeparator(n, i);
if ((i == len) && !compsAllEmpty) {
// Trailing separator found. Add an empty component.
if (rToL) {
} else {
}
}
}
}
}
this(syntax);
// %% comps could shrink in the middle.
while (comps.hasMoreElements())
}
/*
// Determines whether this component needs any escaping.
private final boolean escapingNeeded(String comp) {
int len = comp.length();
for (int i = 0; i < len; i++) {
if (i == 0) {
if (isA(comp, 0, syntaxBeginQuote1) ||
isA(comp, 0, syntaxBeginQuote2)) {
return (true);
}
}
if (isSeparator(comp, i)) {
return (true);
}
if (isA(comp, i, syntaxEscape)) {
i += syntaxEscape.length();
if (i >= len || isMeta(comp, i)) {
return (true);
}
}
}
return (false);
}
*/
boolean escapeSeparator = false, escapeSeparator2 = false;
// determine whether there are any separators; if so escape
// or quote them
if (syntaxSeparator != null &&
if (syntaxBeginQuote1 != null) {
} else if (syntaxBeginQuote2 != null) {
} else if (syntaxEscape != null)
escapeSeparator = true;
}
if (syntaxSeparator2 != null &&
if (syntaxBeginQuote1 != null) {
if (beginQuote == null) {
}
} else if (syntaxBeginQuote2 != null) {
if (beginQuote == null) {
}
} else if (syntaxEscape != null)
escapeSeparator2 = true;
}
// if quoting component,
if (beginQuote != null) {
// start string off with opening quote
// component is being quoted, so we only need to worry about
// escaping end quotes that occur in component
for (int i = 0; i < len; ) {
// end-quotes must be escaped when inside a quoted string
} else {
// no special treatment required
}
}
// end with closing quote
} else {
// When component is not quoted, add escape for:
// 1. leading quote
// 2. an escape preceding any meta char
// 3. an escape at the end of a component
// 4. separator
// go through characters in component and escape where necessary
boolean start = true;
for (int i = 0; i < len; ) {
// leading quote must be escaped
i += syntaxBeginQuote1.length();
i += syntaxBeginQuote2.length();
} else
// Escape an escape preceding meta characters, or at end.
// Other escapes pass through.
// escape an ending escape
// escape meta strings
}
i += syntaxEscape.length();
} else
// escape unescaped separator
// escape separator
i += syntaxSeparator.length();
} else if (escapeSeparator2 &&
// escape separator2
i += syntaxSeparator2.length();
} else {
// no special treatment required
}
start = false;
}
}
}
boolean compsAllEmpty = true;
for (int i = 0; i < size; i++) {
if (syntaxDirection == RIGHT_TO_LEFT) {
comp =
} else {
}
compsAllEmpty = false;
}
}
while (mycomps.hasMoreElements()) {
// %% comps could shrink in the middle.
if (syntaxTrimBlanks) {
}
if (syntaxCaseInsensitive) {
return false;
} else {
return false;
}
}
return true;
}
}
return false;
}
/**
* Compares obj to this NameImpl to determine ordering.
* Takes into account syntactic properties such as
* elimination of blanks, case-ignore, etc, if relevant.
*
* Note: using syntax of this NameImpl and ignoring
* that of comparison target.
*/
if (this == obj) {
return 0;
}
while (n-- != 0) {
// normalize according to syntax
if (syntaxTrimBlanks) {
}
if (syntaxCaseInsensitive) {
}
if (local != 0) {
return local;
}
}
}
public int size() {
return (components.size());
}
public Enumeration getAll() {
return components.elements();
}
}
throw new ArrayIndexOutOfBoundsException(posn);
}
}
throw new ArrayIndexOutOfBoundsException(posn);
}
}
public boolean isEmpty() {
return (components.isEmpty());
}
return false;
}
try {
while (mycomps.hasMoreElements()) {
if (syntaxTrimBlanks) {
}
if (syntaxCaseInsensitive) {
return false;
} else {
return false;
}
}
} catch (NoSuchElementException e) {
return false;
}
return true;
}
// posn is number of elements in suffix
// startIndex is the starting position in this name
// at which to start the comparison. It is calculated by
// subtracting 'posn' from size()
return false;
}
try {
while (mycomps.hasMoreElements()) {
if (syntaxTrimBlanks) {
}
if (syntaxCaseInsensitive) {
return false;
} else {
return false;
}
}
} catch (NoSuchElementException e) {
return false;
}
return true;
}
boolean added = false;
while (comps.hasMoreElements()) {
try {
throw new InvalidNameException(
"A flat name can only have a single component");
}
added = true;
} catch (NoSuchElementException e) {
break; // "comps" has shrunk.
}
}
return added;
}
throws InvalidNameException {
boolean added = false;
try {
throw new InvalidNameException(
"A flat name can only have a single component");
}
added = true;
} catch (NoSuchElementException e) {
break; // "comps" has shrunk.
}
}
return added;
}
throw new InvalidNameException(
"A flat name can only have a single component");
}
}
throw new InvalidNameException(
"A flat name can only zero or one component");
}
}
return r;
}
public int hashCode() {
int hash = 0;
if (syntaxTrimBlanks) {
}
if (syntaxCaseInsensitive) {
}
}
return hash;
}
}
final
class NameImplEnumerator implements Enumeration {
int count;
int limit;
vector = v;
}
public boolean hasMoreElements() {
}
public Object nextElement() {
}
throw new NoSuchElementException("NameImplEnumerator");
}
}