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.core.model.IFlagContainer;
30  import gov.nist.secauto.metaschema.databind.io.IProblemHandler;
31  import gov.nist.secauto.metaschema.databind.model.IAssemblyClassBinding;
32  import gov.nist.secauto.metaschema.databind.model.IBoundFlagInstance;
33  import gov.nist.secauto.metaschema.databind.model.IBoundNamedModelInstance;
34  import gov.nist.secauto.metaschema.databind.model.IClassBinding;
35  
36  import java.io.IOException;
37  import java.util.Collection;
38  
39  import javax.xml.stream.events.Attribute;
40  import javax.xml.stream.events.StartElement;
41  
42  import edu.umd.cs.findbugs.annotations.NonNull;
43  
44  public interface IXmlProblemHandler extends IProblemHandler {
45    /**
46     * Callback used to handle an attribute that is unknown to the model being
47     * parsed.
48     *
49     * @param parentDefinition
50     *          the bound class currently describing the data being parsed
51     * @param targetObject
52     *          the Java object for the {@code parentDefinition}
53     * @param attribute
54     *          the unknown attribute
55     * @param parsingContext
56     *          the XML parsing context used for parsing
57     * @return {@code true} if the attribute was handled by this method, or
58     *         {@code false} otherwise
59     * @throws IOException
60     *           if an error occurred while handling the unrecognized data
61     */
62    default boolean handleUnknownAttribute(
63        @NonNull IFlagContainer parentDefinition,
64        @NonNull Object targetObject,
65        @NonNull Attribute attribute,
66        @NonNull IXmlParsingContext parsingContext) throws IOException {
67      return false;
68    }
69  
70    /**
71     * Callback used to handle an element that is unknown to the model being parsed.
72     *
73     * @param parentDefinition
74     *          the bound assembly class on which the missing instances are found
75     * @param targetObject
76     *          the Java object for the {@code parentDefinition}
77     * @param start
78     *          the parsed XML start element
79     * @param parsingContext
80     *          the XML parsing context used for parsing
81     * @return {@code true} if the element was handled by this method, or
82     *         {@code false} otherwise
83     * @throws IOException
84     *           if an error occurred while handling the unrecognized data
85     */
86    default boolean handleUnknownElement(
87        @NonNull IAssemblyClassBinding parentDefinition,
88        @NonNull Object targetObject,
89        @NonNull StartElement start,
90        @NonNull IXmlParsingContext parsingContext) throws IOException {
91      return false;
92    }
93  
94    /**
95     * A callback used to handle bound flag instances for which no data was found
96     * when the content was parsed.
97     * <p>
98     * This can be used to supply default or prescribed values based on application
99     * logic.
100    *
101    * @param parentDefinition
102    *          the bound assembly class on which the missing instances are found
103    * @param targetObject
104    *          the Java object for the {@code parentDefinition}
105    * @param unhandledInstances
106    *          the set of instances that had no data to parse
107    * @throws IOException
108    *           if an error occurred while handling the missing instances
109    */
110   default void handleMissingFlagInstances(
111       @NonNull IClassBinding parentDefinition,
112       @NonNull Object targetObject,
113       @NonNull Collection<IBoundFlagInstance> unhandledInstances)
114       throws IOException {
115     handleMissingInstances(parentDefinition, targetObject, unhandledInstances);
116   }
117 
118   /**
119    * A callback used to handle bound model instances for which no data was found
120    * when the content was parsed.
121    * <p>
122    * This can be used to supply default or prescribed values based on application
123    * logic.
124    *
125    * @param parentDefinition
126    *          the bound assembly class on which the missing instances are found
127    * @param targetObject
128    *          the Java object for the {@code parentDefinition}
129    * @param unhandledInstances
130    *          the set of instances that had no data to parse
131    * @throws IOException
132    *           if an error occurred while handling the missing instances
133    */
134   default void handleMissingModelInstances(
135       @NonNull IAssemblyClassBinding parentDefinition,
136       @NonNull Object targetObject,
137       @NonNull Collection<IBoundNamedModelInstance> unhandledInstances)
138       throws IOException {
139     handleMissingInstances(parentDefinition, targetObject, unhandledInstances);
140 
141   }
142 }