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.Map;
 

Author(s):
SAP AG
 
 public class JsonPropertyConsumer {
 
   public Map<StringObjectreadPropertyStandalone(final JsonReader readerfinal EdmProperty propertyfinal EntityProviderReadProperties readPropertiesthrows EntityProviderException {
     try {
       EntityPropertyInfo entityPropertyInfo = EntityInfoAggregator.create(property);
       Map<StringObjecttypeMappings = readProperties == null ? null : readProperties.getTypeMappings();
       Map<StringObjectresult = new HashMap<StringObject>();
 
       reader.beginObject();
       String nextName = reader.nextName();
       if (..equals(nextName)) {
         reader.beginObject();
         nextName = reader.nextName();
         handleName(readertypeMappingsentityPropertyInforesultnextName);
         reader.endObject();
       } else {
         handleName(readertypeMappingsentityPropertyInforesultnextName);
       }
       reader.endObject();
 
       if (reader.peek() != .) {
         //TODO: CA Messagetext
       }
 
       return result;
     } catch (final IOException e) {
     } catch (final IllegalStateException e) {
     }
   }
 
   private void handleName(final JsonReader readerfinal Map<StringObjecttypeMappingsfinal EntityPropertyInfo entityPropertyInfofinal Map<StringObjectresultfinal String nextNamethrows EntityProviderException {
     Object mapping = null;
     if (typeMappings != null) {
       mapping = typeMappings.get(nextName);
     }
     Object propertyValue = readPropertyValue(readerentityPropertyInfomapping);
     result.put(nextNamepropertyValue);
   }
 
   protected Object readPropertyValue(final JsonReader readerfinal EntityPropertyInfo entityPropertyInfofinal Object typeMappingthrows EntityProviderException {
     try {
       return entityPropertyInfo.isComplex() ?
           readComplexProperty(reader, (EntityComplexPropertyInfoentityPropertyInfotypeMapping) :
           readSimpleProperty(readerentityPropertyInfotypeMapping);
     } catch (final EdmException e) {
     } catch (final IOException e) {
     }
   }
 
   private Object readSimpleProperty(final JsonReader readerfinal EntityPropertyInfo entityPropertyInfofinal Object typeMappingthrows EdmExceptionEntityProviderExceptionIOException {
     final EdmSimpleType type = (EdmSimpleTypeentityPropertyInfo.getType();
     Object value = null;
     final JsonToken tokenType = reader.peek();
     if (tokenType == .) {
       reader.nextNull();
     } else {
      switch (EdmSimpleTypeKind.valueOf(type.getName())) {
      case :
        if (tokenType == .) {
          value = reader.nextBoolean();
          value = value.toString();
        } else {
        }
        break;
      case :
      case :
      case :
      case :
        if (tokenType == .) {
          value = reader.nextInt();
          value = value.toString();
        } else {
        }
        break;
      default:
        if (tokenType == .) {
          value = reader.nextString();
        } else {
        }
        break;
      }
    }
    final Class<?> typeMappingClass = typeMapping == null ? type.getDefaultType() : (Class<?>) typeMapping;
    return type.valueOfString((Stringvalue.entityPropertyInfo.getFacets(), typeMappingClass);
  }
  @SuppressWarnings("unchecked")
  private Object readComplexProperty(final JsonReader readerfinal EntityComplexPropertyInfo complexPropertyInfofinal Object typeMappingthrows EdmExceptionEntityProviderExceptionIOException {
    reader.beginObject();
    Map<StringObjectdata = new HashMap<StringObject>();
    Map<StringObjectmapping;
    if (typeMapping != null) {
      if (typeMapping instanceof Map) {
        mapping = (Map<StringObject>) typeMapping;
      } else {
        throw new EntityProviderException(..addContent(complexPropertyInfo.getName()));
      }
    } else {
      mapping = new HashMap<StringObject>();
    }
    while (reader.hasNext()) {
      String childName = reader.nextName();
      if (..equals(childName)) {
        reader.beginObject();
        childName = reader.nextName();
        if (!..equals(childName)) {
        }
        reader.nextString();
        reader.endObject();
      } else {
        EntityPropertyInfo childPropertyInfo = complexPropertyInfo.getPropertyInfo(childName);
        Object childData = readPropertyValue(readerchildPropertyInfomapping.get(childName));
        if (data.containsKey(childName)) {
        }
        data.put(childNamechildData);
      }
    }
    reader.endObject();
    return data;
  }
New to GrepCode? Check out our FAQ X