View Javadoc
1   /*
2    * Portions of this software was developed by employees of the National Institute
3    * of Standards and Technology (NIST), an agency of the Federal Government and is
4    * being made available as a public service. Pursuant to title 17 United States
5    * Code Section 105, works of NIST employees are not subject to copyright
6    * protection in the United States. This software may be subject to foreign
7    * copyright. Permission in the United States and in foreign countries, to the
8    * extent that NIST may hold copyright, to use, copy, modify, create derivative
9    * works, and distribute this software and its documentation without fee is hereby
10   * granted on a non-exclusive basis, provided that this notice and disclaimer
11   * of warranty appears in all copies.
12   *
13   * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14   * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15   * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17   * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18   * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE.  IN NO EVENT
19   * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20   * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21   * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22   * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23   * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24   * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25   */
26  
27  package gov.nist.secauto.metaschema.databind.io.xml;
28  
29  import gov.nist.secauto.metaschema.databind.io.IParsingContext;
30  import gov.nist.secauto.metaschema.databind.model.IBoundNamedModelInstance;
31  import gov.nist.secauto.metaschema.databind.model.IClassBinding;
32  
33  import org.codehaus.stax2.XMLEventReader2;
34  import org.codehaus.stax2.XMLStreamReader2;
35  
36  import java.io.IOException;
37  
38  import javax.xml.stream.XMLStreamConstants;
39  import javax.xml.stream.XMLStreamException;
40  import javax.xml.stream.events.StartElement;
41  import javax.xml.stream.events.XMLEvent;
42  
43  import edu.umd.cs.findbugs.annotations.NonNull;
44  import edu.umd.cs.findbugs.annotations.Nullable;
45  
46  public interface IXmlParsingContext extends IParsingContext<XMLEventReader2, IXmlProblemHandler> {
47  
48    /**
49     * Read the XML data associated with the {@code targetInstance} and apply it to
50     * the provided {@code parentObject}.
51     *
52     * @param <T>
53     *          the resulting object type
54     * @param targetInstance
55     *          the instance to parse data for
56     * @param parentObject
57     *          the Java object that data parsed by this method will be stored in
58     * @param start
59     *          the XML element start and attribute data previously parsed
60     * @return the Java object read, or {@code null} if no data was read
61     * @throws IOException
62     *           if an error occurred while parsing the input
63     * @throws XMLStreamException
64     *           if an error occurred while parsing XML events
65     */
66    @Nullable
67    <T> T readModelInstanceValue(
68        @NonNull IBoundNamedModelInstance targetInstance,
69        @NonNull Object parentObject,
70        @NonNull StartElement start) throws XMLStreamException, IOException;
71  
72    /**
73     * Reads a XML element storing the associated data in a Java class instance,
74     * returning the resulting instance.
75     * <p>
76     * When called the next {@link XMLEvent} of the {@link XMLStreamReader2} is
77     * expected to be a {@link XMLStreamConstants#START_ELEMENT} that is the XML
78     * element associated with the Java class.
79     * <p>
80     * After returning the next {@link XMLEvent} of the {@link XMLStreamReader2} is
81     * expected to be a the next event after the
82     * {@link XMLStreamConstants#END_ELEMENT} for the XML
83     * {@link XMLStreamConstants#START_ELEMENT} element associated with the Java
84     * class.
85     *
86     * @param <T>
87     *          the resulting object type
88     * @param targetDefinition
89     *          the Module definition that describes the syntax of the data to read
90     * @param parentObject
91     *          the Java object parent of the target object, which can be
92     *          {@code null} if there is no parent
93     * @param start
94     *          the XML element start and attribute data previously parsed
95     * @return the Java object containing the data parsed by this method
96     * @throws IOException
97     *           if an error occurred while parsing the input
98     * @throws XMLStreamException
99     *           if an error occurred while parsing XML events
100    *
101    */
102   @NonNull
103   <T> T readDefinitionValue(
104       @NonNull IClassBinding targetDefinition,
105       @Nullable Object parentObject,
106       @NonNull StartElement start) throws IOException, XMLStreamException;
107 }