Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 SAP AG Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package com.sap.core.odata.core.ep.consumer;
 
 import java.util.List;
 
Reads the OData service document (JSON).

Author(s):
SAP AG
 
 public class JsonServiceDocumentConsumer {
   private static final String DEFAULT_CHARSET = "UTF-8";
 
     return readServiceDocument(createJsonReader(in));
   }
 
     try {
       reader.beginObject();
        = reader.nextName();
         reader.beginObject();
         readContent(reader);
         reader.endObject();
       }
       reader.endObject();
       reader.peek();
       reader.close();
     } catch (final IOException e) {
     } catch (final IllegalStateException e) {
       throw new EntityProviderException(..addContent("The structure of the service document is not valid"), e);
     } catch (final EdmException e) {
     } catch (final ODataException e) {
     }
   }
 
   private void readContent(final JsonReader readerthrows IOExceptionEdmExceptionEntityProviderException {
      = reader.nextName();
       reader.beginArray();
       readEntitySets(reader);
       reader.endArray();
     }
   }
 
   private void readEntitySets(final JsonReader readerthrows IOExceptionEntityProviderExceptionEdmException {
     while (reader.hasNext()) {
        = reader.nextString();
       if ( != null) {
         // Looking for the last dot: "\\.(?=[^.]+$)"
         String[] names = .split("\\" + . + "(?=[^" + . + "]+$)");
         if (names.length == 1) {
           EntitySet entitySet = new EntitySet().setName(names[0]);
           EntityContainerInfo container = new EntityContainerInfo().setDefaultEntityContainer(true);
           EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySetcontainer);
           .add(entitySetInfo);
         } else {
           EntitySet entitySet = new EntitySet().setName(names[1]);
           EntityContainerInfo container = new EntityContainerInfo().setName(names[0]).setDefaultEntityContainer(false);
           EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySetcontainer);
           .add(entitySetInfo);
         }
      }
    }
  }
    if (in == null) {
      throw new EntityProviderException(..addContent(("Got not supported NULL object as content to de-serialize.")));
    }
    InputStreamReader isReader;
    try {
      isReader = new InputStreamReader(in);
    } catch (UnsupportedEncodingException e) {
    }
    return new JsonReader(isReader);
  }
New to GrepCode? Check out our FAQ X