This project has retired. For details please refer to its Attic page.
ContentHandler xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.commons.impl.json.parser;
20  
21  import java.io.IOException;
22  
23  /**
24   * A simplified and stoppable SAX-like content handler for stream processing of
25   * JSON text.
26   * 
27   * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
28   * for OpenCMIS.)
29   * 
30   * @see org.xml.sax.ContentHandler
31   * @see JSONParser#parse(java.io.Reader, ContentHandler, boolean)
32   * 
33   * @author FangYidong<fangyidong@yahoo.com.cn>
34   */
35  public interface ContentHandler {
36      /**
37       * Receive notification of the beginning of JSON processing. The parser will
38       * invoke this method only once.
39       * 
40       * @throws JSONParseException
41       *             - JSONParser will stop and throw the same exception to the
42       *             caller when receiving this exception.
43       */
44      void startJSON() throws JSONParseException, IOException;
45  
46      /**
47       * Receive notification of the end of JSON processing.
48       * 
49       * @throws JSONParseException
50       */
51      void endJSON() throws JSONParseException, IOException;
52  
53      /**
54       * Receive notification of the beginning of a JSON object.
55       * 
56       * @return false if the handler wants to stop parsing after return.
57       * @throws JSONParseException
58       *             - JSONParser will stop and throw the same exception to the
59       *             caller when receiving this exception.
60       * @see #endJSON
61       */
62      boolean startObject() throws JSONParseException, IOException;
63  
64      /**
65       * Receive notification of the end of a JSON object.
66       * 
67       * @return false if the handler wants to stop parsing after return.
68       * @throws JSONParseException
69       * 
70       * @see #startObject
71       */
72      boolean endObject() throws JSONParseException, IOException;
73  
74      /**
75       * Receive notification of the beginning of a JSON object entry.
76       * 
77       * @param key
78       *            - Key of a JSON object entry.
79       * 
80       * @return false if the handler wants to stop parsing after return.
81       * @throws JSONParseException
82       * 
83       * @see #endObjectEntry
84       */
85      boolean startObjectEntry(String key) throws JSONParseException, IOException;
86  
87      /**
88       * Receive notification of the end of the value of previous object entry.
89       * 
90       * @return false if the handler wants to stop parsing after return.
91       * @throws JSONParseException
92       * 
93       * @see #startObjectEntry
94       */
95      boolean endObjectEntry() throws JSONParseException, IOException;
96  
97      /**
98       * Receive notification of the beginning of a JSON array.
99       * 
100      * @return false if the handler wants to stop parsing after return.
101      * @throws JSONParseException
102      * 
103      * @see #endArray
104      */
105     boolean startArray() throws JSONParseException, IOException;
106 
107     /**
108      * Receive notification of the end of a JSON array.
109      * 
110      * @return false if the handler wants to stop parsing after return.
111      * @throws JSONParseException
112      * 
113      * @see #startArray
114      */
115     boolean endArray() throws JSONParseException, IOException;
116 
117     /**
118      * Receive notification of the JSON primitive values: java.lang.String,
119      * java.lang.Number, java.lang.Boolean null
120      * 
121      * @param value
122      *            - Instance of the following: java.lang.String,
123      *            java.lang.Number, java.lang.Boolean null
124      * 
125      * @return false if the handler wants to stop parsing after return.
126      * @throws JSONParseException
127      */
128     boolean primitive(Object value) throws JSONParseException, IOException;
129 }