01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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:
20: package org.apache.axis2.json;
21:
22: import java.io.InputStream;
23:
24: import org.codehaus.jettison.badgerfish.BadgerFishXMLInputFactory;
25: import org.codehaus.jettison.json.JSONTokener;
26:
27: /**
28: * JSONDataSource keeps the JSON String inside and consumes it when needed. This is to be kept in
29: * the OMSourcedElementImpl and can be used either to expand the tree or get the JSON String
30: * directly without expanding. This uses the "Badgerfish" JSON convention.
31: */
32:
33: public class JSONBadgerfishDataSource extends JSONDataSource {
34:
35: public JSONBadgerfishDataSource(InputStream jsonInputStream,
36: String localName) {
37: super (jsonInputStream, localName);
38: }
39:
40: /**
41: * Gives the StAX reader using the "Badgerfish" formatted input JSON String.
42: *
43: * @return The XMLStreamReader according to the JSON String.
44: * @throws javax.xml.stream.XMLStreamException
45: * if there is an error while making the StAX reader.
46: */
47: public javax.xml.stream.XMLStreamReader getReader()
48: throws javax.xml.stream.XMLStreamException {
49:
50: //input factory for "Badgerfish"
51: BadgerFishXMLInputFactory inputFactory = new BadgerFishXMLInputFactory();
52: return inputFactory.createXMLStreamReader(new JSONTokener("{"
53: + localName + ":" + this.getJSONString()));
54:
55: }
56: }
|