View Javadoc

1   /*
2    * Copyright 2002-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.json.util;
18  
19  import net.sf.json.JSONException;
20  
21  /**
22   * Defines the contract to handle JsonEvents when building an object or array.
23   *
24   * @author Andres Almiray <aalmiray@users.sourceforge.net>
25   */
26  public interface JsonEventListener {
27  
28     /**
29      * Ttriggered when reaching the end of an array.
30      */
31     void onArrayEnd();
32  
33     /**
34      * triggered when the start of an array is encountered.
35      */
36     void onArrayStart();
37  
38     /**
39      * Triggered when an element has been added to the current array.
40      *
41      * @param index the index where the element was added
42      * @param element the added element
43      */
44     void onElementAdded( int index, Object element );
45  
46     /**
47      * Triggered when an exception is thrown.
48      *
49      * @param jsone the thrown exception
50      */
51     void onError( JSONException jsone );
52  
53     /**
54      * triggered when reaching the end of an object.
55      */
56     void onObjectEnd();
57  
58     /**
59      * Triggered when the start of an object is encountered.
60      */
61     void onObjectStart();
62  
63     /**
64      * Triggered when a property is set on an object
65      *
66      * @param key the name of the property
67      * @param value the value of the property
68      * @param accumulated if the value has been accumulated over 'key'
69      */
70     void onPropertySet( String key, Object value, boolean accumulated );
71  
72     /**
73      * Triggered when a warning is encountered.
74      *
75      * @param warning the warning message
76      */
77     void onWarning( String warning );
78  }