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;
 import java.util.Map;
 
 
 public class JsonEntryConsumer {
 
   private final Map<StringObjectproperties = new HashMap<StringObject>();
   private final MediaMetadataImpl mediaMetadata = new MediaMetadataImpl();
   private final EntryMetadataImpl entryMetadata = new EntryMetadataImpl();
   private final Map<StringObjecttypeMappings;
   private final EntityInfoAggregator eia;
   private final JsonReader reader;
   private final ODataEntryImpl entryResult;
 
   public JsonEntryConsumer(final JsonReader readerfinal EntityInfoAggregator eiafinal EntityProviderReadProperties readProperties) {
      = readProperties.getTypeMappings();
     this. = eia;
     this. = readProperties;
     this. = reader;
   }
 
     try {
       .beginObject();
       String nextName = .nextName();
       if (..equals(nextName)) {
         .beginObject();
         readEntryContent();
         .endObject();
       } else {
         handleName(nextName);
         readEntryContent();
       }
       .endObject();
 
       if (.peek() != .) {
         //TODO: CA Messagetext
       }
     } catch (IOException e) {
     } catch (EdmException e) {
     } catch (IllegalStateException e) {
     }
 
     return ;
   }
 
     .beginObject();
     readEntryContent();
     .endObject();
    return ;
  }
    while (.hasNext()) {
      String name = .nextName();
      handleName(name);
    }
    //TODO: Ca validate created entry
  }
  private void handleName(final String namethrows IOExceptionEdmExceptionEntityProviderException {
    if (..equals(name)) {
      readMetadata();
      validateMetadata();
    } else {
      EntityPropertyInfo propertyInfo = .getPropertyInfo(name);
      if (propertyInfo != null) {
        JsonPropertyConsumer jpc = new JsonPropertyConsumer();
        Object propertyValue = jpc.readPropertyValue(propertyInfo.get(name));
        if (.containsKey(name)) {
        }
        .put(namepropertyValue);
      } else {
        readNavigationProperty(name);
      }
    }
  }
    String name = null;
    String value = null;
    while (.hasNext()) {
      name = .nextName();
      if (..equals(name)) {
        .skipValue();
        continue;
      }
      value = .nextString();
      if (..equals(name)) {
        .setId(value);
      } else if (..equals(name)) {
        .setUri(value);
      } else if (..equals(name)) {
        String fullQualifiedName = .getEntityType().getNamespace() + . + .getEntityType().getName();
        if (!fullQualifiedName.equals(value)) {
          throw new EntityProviderException(..addContent(fullQualifiedName).addContent(value));
        }
      } else if (..equals(name)) {
        .setEtag(value);
      } else if (..equals(name)) {
        .setEditLink(value);
      } else if (..equals(name)) {
        .setSourceLink(value);
      } else if (..equals(name)) {
        .setEtag(value);
      } else if (..equals(name)) {
        .setContentType(value);
      } else {
      }
    }
    .endObject();
  }
  private void validateMetadata() throws EdmExceptionEntityProviderException {
    if (.getEntityType().hasStream()) {
      if (.getSourceLink() == null) {
      }
      if (.getContentType() == null) {
      }
      //TODO Mime Type Mapping
    } else {
      if (.getContentType() != null || .getEditLink() != null
          || .getEtag() != null || .getSourceLink() != null) {
      }
    }
  }
  private void readNavigationProperty(final String navigationPropertyNamethrows IOExceptionEntityProviderExceptionEdmException {
    NavigationPropertyInfo navigationPropertyInfo = .getNavigationPropertyInfo(navigationPropertyName);
    if (navigationPropertyInfo == null) {
      throw new EntityProviderException(..addContent(navigationPropertyName));
    }
    if (.peek() == .) {
      .beginObject();
      String name = .nextName();
      if (..equals(name)) {
        .beginObject();
        String uri = .nextName();
        if (..equals(uri)) {
          String value = .nextString();
          .putAssociationUri(navigationPropertyInfo.getName(), value);
        } else {
        }
        .endObject();
      } else {
        EdmNavigationProperty navigationProperty = (EdmNavigationProperty.getEntityType().getProperty(navigationPropertyName);
        EdmEntitySet inlineEntitySet = .getEntitySet().getRelatedEntitySet(navigationProperty);
        EntityInfoAggregator inlineEia = EntityInfoAggregator.create(inlineEntitySet);
        EntityProviderReadProperties inlineReadProperties;
        OnReadInlineContent callback = .getCallback();
        try {
          if (callback == null) {
            inlineReadProperties = EntityProviderReadProperties.init().mergeSemantic(.getMergeSemantic()).build();
          } else {
            inlineReadProperties = callback.receiveReadProperties(navigationProperty);
          }
          if (navigationProperty.getMultiplicity() == .) {
            JsonEntryConsumer inlineConsumer = new JsonEntryConsumer(inlineEiainlineReadProperties);
            ODataEntry entry = inlineConsumer.readInlineEntry(name);
            updateExpandSelectTree(navigationPropertyNameentry);
            if (callback == null) {
              .put(navigationPropertyNameentry);
              .setContainsInlineEntry(true);
            } else {
              ReadEntryResult result = new ReadEntryResult(inlineReadPropertiesnavigationPropertyentry);
              callback.handleReadEntry(result);
            }
          } else {
            JsonFeedConsumer inlineConsumer = new JsonFeedConsumer(inlineEiainlineReadProperties);
            ODataFeed feed = inlineConsumer.readStartedInlineFeed(name);
            updateExpandSelectTree(navigationPropertyNamefeed);
            if (callback == null) {
              .put(navigationPropertyNamefeed);
              .setContainsInlineEntry(true);
            } else {
              ReadFeedResult result = new ReadFeedResult(inlineReadPropertiesnavigationPropertyfeed);
              callback.handleReadFeed(result);
            }
          }
        } catch (ODataApplicationException e) {
          throw new EntityProviderException(.e);
        }
      }
      .endObject();
    } else {
      final EdmNavigationProperty navigationProperty = (EdmNavigationProperty.getEntityType().getProperty(navigationPropertyName);
      final EdmEntitySet inlineEntitySet = .getEntitySet().getRelatedEntitySet(navigationProperty);
      final EntityInfoAggregator inlineInfo = EntityInfoAggregator.create(inlineEntitySet);
      EntityProviderReadProperties inlineReadProperties;
      if (callback == null) {
        inlineReadProperties = EntityProviderReadProperties.init().mergeSemantic(.getMergeSemantic()).build();
      } else {
        try {
          inlineReadProperties = callback.receiveReadProperties(navigationProperty);
        } catch (final ODataApplicationException e) {
          throw new EntityProviderException(.e);
        }
      }
      ODataFeed feed = new JsonFeedConsumer(inlineInfoinlineReadProperties).readInlineFeedStandalone();
      updateExpandSelectTree(navigationPropertyNamefeed);
      if (callback == null) {
        .put(navigationPropertyNamefeed);
        .setContainsInlineEntry(true);
      } else {
        ReadFeedResult result = new ReadFeedResult(inlineReadPropertiesnavigationPropertyfeed);
        try {
          callback.handleReadFeed(result);
        } catch (final ODataApplicationException e) {
          throw new EntityProviderException(.e);
        }
      }
    }
  }
  private void updateExpandSelectTree(final String navigationPropertyNamefinal ODataFeed feed) {
    List<ODataEntryentries = feed.getEntries();
    if (entries.size() > 0) {
      updateExpandSelectTree(navigationPropertyNameentries.get(0));
    } else {
      .putLink(navigationPropertyNamenew ExpandSelectTreeNodeImpl());
    }
  }
  private void updateExpandSelectTree(final String navigationPropertyNamefinal ODataEntry entry) {
    //TODO: CA get rid of cast
    .putLink(navigationPropertyName, (ExpandSelectTreeNodeImplentry.getExpandSelectTree());
  }
    //consume the already started content
    handleName(name);
    //consume the rest of the entry content
    return ;
  }
New to GrepCode? Check out our FAQ X