📄 unmarshallingcontext.java
字号:
}
/**
* Find optional text value in enumeration. Looks up and returns the
* enumeration value corresponding to the target text, or the default
* value if the text is <code>null</code>.
*
* @param target text to be found in enumeration (may be <code>null</code>)
* @param enums ordered array of texts included in enumeration
* @param vals array of values to be returned for corresponding text match
* positions (position returned directly if this is <code>null</code>)
* @param dflt default value returned if target text is <code>null</code>
* @return enumeration value for target text
* @throws JiBXException if target text not found in enumeration
*/
public int convertEnum(String target, String[] enums, int[] vals, int dflt)
throws JiBXException {
if (target == null) {
return dflt;
}
try {
return Utility.enumValue(target, enums, vals);
} catch (JiBXException ex) {
throw new JiBXException(ex.getMessage() + ' ' +
buildPositionString());
}
}
/**
* Get enumeration attribute value from current start tag.
* Throws an exception if the attribute value is not found in the start
* tag or the text does not match a value defined in the enumeration table.
*
* @param ns namespace URI for expected attribute (may be <code>null</code>
* or the empty string for the empty namespace)
* @param name attribute name expected
* @param enums ordered array of texts included in enumeration
* @param vals array of values to be returned for corresponding text match
* positions (position returned directly if this is <code>null</code>)
* @return enumeration value for target text
* @throws JiBXException if attribute not present or value not found in
* enumeration list
*/
public int attributeEnumeration(String ns, String name, String[] enums,
int[] vals) throws JiBXException {
return convertEnum(getAttributeValue(ns, name), enums, vals);
}
/**
* Get optional enumeration attribute value from current start tag.
* Throws an exception if the attribute value is present but does not match
* a value defined in the enumeration table.
*
* @param ns namespace URI for expected attribute (may be <code>null</code>
* or the empty string for the empty namespace)
* @param name attribute name expected
* @param enums ordered array of texts included in enumeration
* @param vals array of values to be returned for corresponding text match
* positions (position returned directly if this is <code>null</code>)
* @param dflt default value returned if attribute is not present
* @return enumeration value for target text
* @throws JiBXException if attribute not present or value not found in
* enumeration list
*/
public int attributeEnumeration(String ns, String name, String[] enums,
int[] vals, int dflt) throws JiBXException {
return convertEnum(getAttributeValue(ns, name), enums, vals, dflt);
}
/**
* Parse past end of element, returning enumeration value of content.
* Assumes you've already parsed past the start tag of the element, so it
* just looks for text content followed by the end tag, and returns with the
* parser positioned after the end tag.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @param enums ordered array of texts included in enumeration
* @param vals array of values to be returned for corresponding text match
* positions (position returned directly if this is <code>null</code>)
* @return enumeration value for element text
* @throws JiBXException on any error (possible wrapping other exception)
*/
public int parseContentEnumeration(String ns, String tag, String[] enums,
int[] vals) throws JiBXException {
return convertEnum(parseContentText(ns, tag), enums, vals);
}
/**
* Parse entire element, returning enumeration value of optional content.
* Expects to find the element start tag, text content, and end tag,
* in that order, and returns with the parser positioned following
* the end tag. Returns the default value if no content is present.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @param enums ordered array of texts included in enumeration
* @param vals array of values to be returned for corresponding text match
* positions (position returned directly if this is <code>null</code>)
* @param dflt default value
* @return enumeration value for element text
* @throws JiBXException on any error (possibly wrapping other exception)
*/
public int parseElementEnumeration(String ns, String tag, String[] enums,
int[] vals, int dflt) throws JiBXException {
if (parseIfStartTag(ns, tag)) {
String text = parseContentText(ns, tag);
return convertEnum(text, enums, vals, dflt);
} else {
return dflt;
}
}
/**
* Convert byte value with exception wrapper. This internal method is used
* by all the byte unmarshalling calls. It adds position information to
* any exceptions that occur.
*
* @param text text for value to be converted
* @return converted byte value
* @throws JiBXException if not a valid byte value
*/
public byte convertByte(String text) throws JiBXException {
try {
return Utility.parseByte(text);
} catch (JiBXException ex) {
throw new JiBXException(ex.getMessage() + ' ' +
buildPositionString(), ex.getRootCause());
}
}
/**
* Get byte value of attribute from current start tag. Throws an exception
* if the attribute is not found in the start tag, or if it is not a valid
* integer value.
*
* @param ns namespace URI for expected attribute (may be <code>null</code>
* or the empty string for the empty namespace)
* @param name attribute name expected
* @return attribute byte value
* @throws JiBXException if attribute not present or not a valid byte value
*/
public byte attributeByte(String ns, String name) throws JiBXException {
return convertByte(attributeText(ns, name));
}
/**
* Get byte value of optional attribute from current start tag. If the
* attribute is not present the supplied default value is returned instead.
*
* @param ns namespace URI for expected attribute (may be <code>null</code>
* or the empty string for the empty namespace)
* @param name attribute name expected
* @param dflt value to be returned if attribute is not present
* @return attribute byte value
* @throws JiBXException if attribute value is not a valid byte
*/
public byte attributeByte(String ns, String name, byte dflt)
throws JiBXException {
String text = getAttributeValue(ns, name);
if (text == null) {
return dflt;
} else {
return convertByte(text);
}
}
/**
* Parse past end of element, returning byte value of content. Assumes
* you've already parsed past the start tag of the element, so it just looks
* for text content followed by the end tag, and returns with the parser
* positioned after the end tag.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @return converted value from element text
* @throws JiBXException on any error (possible wrapping other exception)
*/
public byte parseContentByte(String ns, String tag) throws JiBXException {
return convertByte(parseContentText(ns, tag));
}
/**
* Parse entire element, returning byte value of content.
* Expects to find the element start tag, text content, and end tag,
* in that order, and returns with the parser positioned following
* the end tag.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @return content text from element
* @throws JiBXException on any error (possibly wrapping other exception)
*/
public byte parseElementByte(String ns, String tag) throws JiBXException {
parsePastStartTag(ns, tag);
return parseContentByte(ns, tag);
}
/**
* Parse entire element, returning byte value of optional content.
* Expects to find the element start tag, text content, and end tag,
* in that order, and returns with the parser positioned following
* the end tag. Returns the default value if no content is present.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @param dflt default value
* @return content text from element
* @throws JiBXException on any error (possibly wrapping other exception)
*/
public byte parseElementByte(String ns, String tag, byte dflt)
throws JiBXException {
if (parseIfStartTag(ns, tag)) {
return convertByte(parseContentText(ns, tag));
} else {
return dflt;
}
}
/**
* Convert short value with exception wrapper. This internal method is used
* by all the short unmarshalling calls. It adds position information to
* any exceptions that occur.
*
* @param text text for value to be converted
* @return converted short value
* @throws JiBXException if not a valid short value
*/
public short convertShort(String text) throws JiBXException {
try {
return Utility.parseShort(text);
} catch (JiBXException ex) {
throw new JiBXException(ex.getMessage() + ' ' +
buildPositionString(), ex.getRootCause());
}
}
/**
* Get short value of attribute from current start tag. Throws an exception
* if the attribute is not found in the start tag, or if it is not a valid
* integer value.
*
* @param ns namespace URI for expected attribute (may be <code>null</code>
* or the empty string for the empty namespace)
* @param name attribute name expected
* @return attribute short value
* @throws JiBXException if attribute not present or not a valid short value
*/
public short attributeShort(String ns, String name) throws JiBXException {
return convertShort(attributeText(ns, name));
}
/**
* Get short value of optional attribute from current start tag. If the
* attribute is not present the supplied default value is returned instead.
*
* @param ns namespace URI for expected attribute (may be <code>null</code>
* or the empty string for the empty namespace)
* @param name attribute name expected
* @param dflt value to be returned if attribute is not present
* @return attribute short value
* @throws JiBXException if attribute value is not a valid short
*/
public short attributeShort(String ns, String name, short dflt)
throws JiBXException {
String text = getAttributeValue(ns, name);
if (text == null) {
return dflt;
} else {
return convertShort(text);
}
}
/**
* Parse past end of element, returning short value of content. Assumes
* you've already parsed past the start tag of the element, so it just looks
* for text content followed by the end tag, and returns with the parser
* positioned after the end tag.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @return converted value from element text
* @throws JiBXException on any error (possible wrapping other exception)
*/
public short parseContentShort(String ns, String tag) throws JiBXException {
return convertShort(parseContentText(ns, tag));
}
/**
* Parse entire element, returning short value of content.
* Expects to find the element start tag, text content, and end tag,
* in that order, and returns with the parser positioned following
* the end tag.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @return content text from element
* @throws JiBXException on any error (possibly wrapping other exception)
*/
public short parseElementShort(String ns, String tag) throws JiBXException {
parsePastStartTag(ns, tag);
return parseContentShort(ns, tag);
}
/**
* Parse entire element, returning short value of optional content.
* Expects to find the element start tag, text content, and end tag,
* in that order, and returns with the parser positioned following
* the end tag. Returns the default value if no content is present.
*
* @param ns namespace URI for expected element (may be <code>null</code>
* or the empty string for the empty namespace)
* @param tag element name expected
* @param dflt default value
* @return content text from element
* @throws JiBXException on any error (possibly
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -