|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.decisiondeck.jmcda.persist.xmcda2.utils.XMCDAErrorsManagerForwarder
org.decisiondeck.jmcda.persist.xmcda2.utils.XMCDAReadUtils
public class XMCDAReadUtils
Helper class containing methods useful for parsing various XMCDA fragments.
| Field Summary | |
|---|---|
static String |
DEFAULT_XMCDA_VERSION
|
| Constructor Summary | |
|---|---|
XMCDAReadUtils()
Creates a new object which will use the default error management strategy XMCDAErrorsManager.ErrorManagement.THROW. |
|
XMCDAReadUtils(XMCDAErrorsManager errorsManager)
Creates a new object delegating error management to the given error manager in case of unexpected data read. |
|
| Method Summary | ||
|---|---|---|
static InputSupplier<? extends Reader> |
getAsVersion_Reader(InputSupplier<? extends Reader> source,
String version)
Blindly transforms an XMCDA document corresponding to any version to a new XMCDA document corresponding to a different version. |
|
static InputSupplier<? extends InputStream> |
getAsVersion(InputSupplier<? extends InputStream> source,
String version)
Blindly transforms an XMCDA document corresponding to any version to a new XMCDA document corresponding to a different version. |
|
String |
getLastVersionRead()
Retrieves the version number of the last XMCDA document read by this object, as assessed by its namespace. |
|
static String |
getNamespace_Reader(InputSupplier<? extends Reader> source)
Retrieves the namespace associated to the document root of the given xml source document. |
|
static String |
getNamespace(InputSupplier<? extends InputStream> source)
Retrieves the namespace associated to the document root of the given xml source document. |
|
static String |
getTagName(Class<? extends XmlObject> targetType)
|
|
|
getUnique(Collection<T> collection,
String contextMessageIfEmpty)
Retrieves the only element from the given collection of elements. |
|
|
getUniqueOrZero(Collection<T> collection)
Retrieves the only element from the given collection of elements, or null if the collection is
empty. |
|
XMCDADoc.XMCDA |
getXMCDA_Reader(InputSupplier<? extends Reader> source)
Retrieves the XMCDA document from the given source. |
|
XMCDADoc.XMCDA |
getXMCDA(InputSupplier<? extends InputStream> source)
Retrieves the XMCDA document from the given source. |
|
XMCDADoc |
getXMCDADoc(InputSupplier<? extends InputStream> source)
Retrieves the XMCDA document from the given source. |
|
| Methods inherited from class org.decisiondeck.jmcda.persist.xmcda2.utils.XMCDAErrorsManagerForwarder |
|---|
error, getErrors, getStrategy, setStrategy |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static String DEFAULT_XMCDA_VERSION
| Constructor Detail |
|---|
public XMCDAReadUtils(XMCDAErrorsManager errorsManager)
errorsManager - not null.public XMCDAReadUtils()
XMCDAErrorsManager.ErrorManagement.THROW.
| Method Detail |
|---|
public <T extends XmlTokenSource> T getUnique(Collection<T> collection,
String contextMessageIfEmpty)
throws InvalidInputException
Retrieves the only element from the given collection of elements. This method expects the collection of elements to contain exactly one element.
In case of unexpected contents, this method returns null or throws an exception depending on the
strategy this object follows.
T - the type of content of the collection.collection - not null.contextMessageIfEmpty - if not null, is used to give a more useful error message about the context when the given
collection is empty. If parsing an XmlObject, one possibility is to use the qualified name of
the parsed type, see e.g. XPerformanceTable.type and SchemaType.getName().
null iff the collection contains more or less than one element and this object follows a
permissive strategy.
InvalidInputException - iff the collection contains more or less than one element and this object follows the
XMCDAErrorsManager.ErrorManagement.THROW strategy.
public <T> T getUniqueOrZero(Collection<T> collection)
throws InvalidInputException
Retrieves the only element from the given collection of elements, or null if the collection is
empty. This method expects the collection of elements to contain zero or one elements, thus maximum one element.
If the given collection contains more than one element, this method returns null or throws an
exception depending on the strategy this object follows.
T - the type of content of the collection.collection - not null.
null if the collection contains zero elements, or if the given collection contains more than
one element and this object follows a permissive strategy.
InvalidInputException - iff the given collection contains more than one element and this object follows the
XMCDAErrorsManager.ErrorManagement.THROW strategy.
public XMCDADoc.XMCDA getXMCDA_Reader(InputSupplier<? extends Reader> source)
throws IOException,
XmlException
Retrieves the XMCDA document from the given source. Ensures that it validates.
If the document contained in the given source appears, according to its namespace, to be an XMCDA document not
matching the expected version DEFAULT_XMCDA_VERSION, this method attemps to proceed as if the source
version matched the expected one.
The underlying reader is closed when this method returns.
source - not null, with a non null reader.
null.
IOException - if an exception happens while opening or closing the given reader, or while parsing the source.
XmlException - if an exception related to the contents of the source happens while parsing the source, including if
the source document does not validate.getLastVersionRead()
public static InputSupplier<? extends InputStream> getAsVersion(InputSupplier<? extends InputStream> source,
String version)
throws IOException,
XmlException
Blindly transforms an XMCDA document corresponding to any version to a new XMCDA document corresponding to a different version. This method only changes the namespace associated with the document and performs no validation whatsoever, except that the source document must have a namespace which has the appropriate prefix for an XMCDA document. The resulting document is therefore not necessarily a valid XMCDA document.
This method may typically be useful in two situations: transforming an old version of an XMCDA document into the
version supported by this library (see DEFAULT_XMCDA_VERSION) in order to be able to read data using the
reader classes this library proposes; or transforming a version of an XMCDA document obtained by writer classes
in this library into an older version possibly expected by some user.
source - not null, must contain an XMCDA document.version - not null, e.g. "2.0.0" or .
null.
IOException - if an IO error occurs.
XmlException - if a parse error occurs.
public static String getNamespace(InputSupplier<? extends InputStream> source)
throws IOException,
XmlException
source - not null, must correspond to an xml document.
null if none has been found.
IOException - if an IO error occurs.
XmlException - if a parse error occurs.public String getLastVersionRead()
null iff no document has been read or the version number could not be retrieved.
public XMCDADoc getXMCDADoc(InputSupplier<? extends InputStream> source)
throws IOException,
XmlException
Retrieves the XMCDA document from the given source. Ensures that it validates.
If the document contained in the given source appears, according to its namespace, to be an XMCDA document not
matching the expected version DEFAULT_XMCDA_VERSION, this method attemps to proceed as if the source
version matched the expected one.
The underlying reader is closed when this method returns.
source - not null, with a non null reader.
null.
IOException - if an exception happens while opening or closing the given reader, or while parsing the source.
XmlException - if an exception related to the contents of the source happens while parsing the source, including if
the source document does not validate.getLastVersionRead()
public XMCDADoc.XMCDA getXMCDA(InputSupplier<? extends InputStream> source)
throws IOException,
XmlException
Retrieves the XMCDA document from the given source. Ensures that it validates.
If the document contained in the given source appears, according to its namespace, to be an XMCDA document not
matching the expected version DEFAULT_XMCDA_VERSION, this method attemps to proceed as if the source
version matched the expected one.
The underlying reader is closed when this method returns.
source - not null, with a non null reader.
null.
IOException - if an exception happens while opening or closing the given reader, or while parsing the source.
XmlException - if an exception related to the contents of the source happens while parsing the source, including if
the source document does not validate.getLastVersionRead()public static String getTagName(Class<? extends XmlObject> targetType)
public static String getNamespace_Reader(InputSupplier<? extends Reader> source)
throws IOException,
XmlException
source - not null, must correspond to an xml document.
null if none has been found.
IOException - if an IO error occurs.
XmlException - if a parse error occurs.
public static InputSupplier<? extends Reader> getAsVersion_Reader(InputSupplier<? extends Reader> source,
String version)
throws IOException,
XmlException
Blindly transforms an XMCDA document corresponding to any version to a new XMCDA document corresponding to a different version. This method only changes the namespace associated with the document and performs no validation whatsoever, except that the source document must have a namespace which has the appropriate prefix for an XMCDA document. The resulting document is therefore not necessarily a valid XMCDA document.
This method may typically be useful in two situations: transforming an old version of an XMCDA document into the
version supported by this library (see DEFAULT_XMCDA_VERSION) in order to be able to read data using the
reader classes this library proposes; or transforming a version of an XMCDA document obtained by writer classes
in this library into an older version possibly expected by some user.
source - not null, must contain an XMCDA document.version - not null, e.g. "2.0.0" or .
null.
IOException - if an IO error occurs.
XmlException - if a parse error occurs.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||