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.sample;
18  
19  import net.sf.json.JSONException;
20  import net.sf.json.util.JsonEventListener;
21  
22  /**
23   * @author Andres Almiray <aalmiray@users.sourceforge.net>
24   */
25  public class JsonEventAdpater implements JsonEventListener {
26     private int arrayEnd = 0;
27     private int arrayStart = 0;
28     private int elementAdded = 0;
29     private int error = 0;
30     private int objectEnd = 0;
31     private int objectStart = 0;
32     private int propertySet = 0;
33     private int warning = 0;
34  
35     public int getArrayEnd() {
36        return arrayEnd;
37     }
38  
39     public int getArrayStart() {
40        return arrayStart;
41     }
42  
43     public int getElementAdded() {
44        return elementAdded;
45     }
46  
47     public int getError() {
48        return error;
49     }
50  
51     public int getObjectEnd() {
52        return objectEnd;
53     }
54  
55     public int getObjectStart() {
56        return objectStart;
57     }
58  
59     public int getPropertySet() {
60        return propertySet;
61     }
62  
63     public int getWarning() {
64        return warning;
65     }
66  
67     public void onArrayEnd() {
68        arrayEnd++;
69     }
70  
71     public void onArrayStart() {
72        arrayStart++;
73     }
74  
75     public void onElementAdded( int index, Object element ) {
76        elementAdded++;
77     }
78  
79     public void onError( JSONException jsone ) {
80        error++;
81     }
82  
83     public void onObjectEnd() {
84        objectEnd++;
85     }
86  
87     public void onObjectStart() {
88        objectStart++;
89     }
90  
91     public void onPropertySet( String key, Object value, boolean accumulated ) {
92        propertySet++;
93     }
94  
95     public void onWarning( String warning ) {
96        this.warning++;
97     }
98  
99     public void reset() {
100       objectStart = 0;
101       objectEnd = 0;
102       arrayStart = 0;
103       arrayEnd = 0;
104       error = 0;
105       warning = 0;
106       propertySet = 0;
107       elementAdded = 0;
108    }
109 }