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.aggregator;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
Aggregator to get easy and fast access to all for serialization and de-serialization necessary com.sap.core.odata.api.edm.EdmEntitySet informations.

Author(s):
SAP AG
 
 public class EntityInfoAggregator {
 
   private static final Set<StringSYN_TARGET_PATHS = new HashSet<String>(Arrays.asList(
 
 
   /*
    * list with all property names in the order based on order in {@link EdmProperty} (normally [key, entity,
    * navigation])
    */
   private List<StringetagPropertyNames = new ArrayList<String>();
   private List<StringpropertyNames;
 
 
   private boolean isDefaultEntityContainer;
   private String entitySetName;
   private String entityContainerName;
 
   private EdmEntityType entityType;
   private EdmEntitySet entitySet;

  
Constructor is private to force creation over create(com.sap.core.odata.api.edm.EdmEntitySet) method.
 
   private EntityInfoAggregator() {}

  
Create an EntityInfoAggregator based on given com.sap.core.odata.api.edm.EdmEntitySet

Parameters:
entitySet with which the EntityInfoAggregator is initialized.
expandSelectTree
Returns:
created and initialized EntityInfoAggregator
Throws:
com.sap.core.odata.api.ep.EntityProviderException if during initialization of EntityInfoAggregator something goes wrong (e.g. exceptions during access of com.sap.core.odata.api.edm.EdmEntitySet).
  public static EntityInfoAggregator create(final EdmEntitySet entitySetfinal ExpandSelectTreeNode expandSelectTreethrows EntityProviderException {
    eia.initialize(entitySetexpandSelectTree);
    return eia;
  }

  
Create an EntityInfoAggregator based on given com.sap.core.odata.api.edm.EdmEntitySet

Parameters:
entitySet with which the EntityInfoAggregator is initialized.
Returns:
created and initialized EntityInfoAggregator
Throws:
com.sap.core.odata.api.ep.EntityProviderException if during initialization of EntityInfoAggregator something goes wrong (e.g. exceptions during access of com.sap.core.odata.api.edm.EdmEntitySet).
  public static EntityInfoAggregator create(final EdmEntitySet entitySetthrows EntityProviderException {
    eia.initialize(entitySetnull);
    return eia;
  }

  
Create an EntityPropertyInfo based on given com.sap.core.odata.api.edm.EdmProperty

Parameters:
property for which the EntityPropertyInfo is created.
Returns:
created EntityPropertyInfo
Throws:
com.sap.core.odata.api.ep.EntityProviderException if create of EntityPropertyInfo something goes wrong (e.g. exceptions during access of com.sap.core.odata.api.edm.EdmProperty).
  public static EntityPropertyInfo create(final EdmProperty propertythrows EntityProviderException {
    try {
      EntityInfoAggregator eia = new EntityInfoAggregator();
      return eia.createEntityPropertyInfo(property);
    } catch (EdmException e) {
    }
  }

  
Create an map of complex type property name to EntityPropertyInfo based on given com.sap.core.odata.api.edm.EdmComplexType

Parameters:
complexType for which the EntityPropertyInfo is created.
Returns:
created map of complex type property name to EntityPropertyInfo
Throws:
com.sap.core.odata.api.ep.EntityProviderException if create of EntityPropertyInfo something goes wrong (e.g. exceptions during access of EntityPropertyInfo).
  public static Map<StringEntityPropertyInfocreate(final EdmComplexType complexTypethrows EntityProviderException {
    try {
      EntityInfoAggregator entityInfo = new EntityInfoAggregator();
      return entityInfo.createPropertyInfoObjects(complexTypecomplexType.getPropertyNames());
    } catch (EdmException e) {
    }
  }

  
Create an EntityPropertyInfo based on given com.sap.core.odata.api.edm.EdmFunctionImport

Parameters:
functionImport for which the EntityPropertyInfo is created.
Returns:
created EntityPropertyInfo
Throws:
com.sap.core.odata.api.ep.EntityProviderException if create of EntityPropertyInfo something goes wrong (e.g. exceptions during access of com.sap.core.odata.api.edm.EdmFunctionImport).
  public static EntityPropertyInfo create(final EdmFunctionImport functionImportthrows EntityProviderException {
    try {
      EntityInfoAggregator eia = new EntityInfoAggregator();
      return eia.createEntityPropertyInfo(functionImportfunctionImport.getReturnType().getType());
    } catch (EdmException e) {
    }
  }

  

Returns:
the edm entity set which was used to build this entity info aggregator object
  public EdmEntitySet getEntitySet() {
    return ;
  }

  

Returns:
entity set name.
  public String getEntitySetName() {
    return ;
  }

  

Returns:
true if the entity container of com.sap.core.odata.api.edm.EdmEntitySet is the default container, otherwise false.
  public boolean isDefaultEntityContainer() {
  }
  public EntityPropertyInfo getTargetPathInfo(final String targetPath) {
    return .get(targetPath);
  }
    return ;
  }
    return ;
  }

  

Returns:
unmodifiable set of all found target path names.
  }

  

Returns:
unmodifiable set of found none syndication target path names (all target path names which are not pre-defined).
    return Collections.unmodifiableList();
  }

  

Returns:
unmodifiable set of all found navigation property names.
    return Collections.unmodifiableList();
  }

  

Returns:
unmodifiable set of all property names.
    return Collections.unmodifiableList();
  }

  

Returns:
unmodifiable set of selected property names.
    return Collections.unmodifiableList();
  }

  

Returns:
unmodifiable set of selected property names.
  }
    return Collections.unmodifiableCollection(.values());
  }
  public EntityPropertyInfo getPropertyInfo(final String name) {
    return .get(name);
  }
    List<EntityPropertyInfokeyProperties = new ArrayList<EntityPropertyInfo>();
    for (String etagPropertyName : ) {
      EntityPropertyInfo e = .get(etagPropertyName);
      keyProperties.add(e);
    }
    return keyProperties;
  }

  

Returns:
list of all key property infos
Throws:
com.sap.core.odata.api.ep.EntityProviderException
    if ( == null) {
      try {
         = new ArrayList<EntityPropertyInfo>();
        for (String keyPropertyName : .getKeyPropertyNames()) {
          .add(.get(keyPropertyName));
        }
      } catch (EdmException e) {
      }
    }
    return ;
  }
    return .get(name);
  }
  private void initialize(final EdmEntitySet entitySetfinal ExpandSelectTreeNode expandSelectTreethrows EntityProviderException {
    try {
      this. = entitySet;
       = entitySet.getEntityType();
       = entitySet.getName();
       = entitySet.getEntityContainer().getName();
      if (expandSelectTree != null && !expandSelectTree.isAll()) {
         = new ArrayList<String>();
        for (EdmProperty property : expandSelectTree.getProperties()) {
          .add(property.getName());
        }
        for (String property : expandSelectTree.getLinks().keySet()) {
          .add(property);
          if (expandSelectTree.getLinks().get(property) != null) {
            .add(property);
          }
        }
      } else if (expandSelectTree != null) {
        for (String property : expandSelectTree.getLinks().keySet()) {
          if (expandSelectTree.getLinks().get(property) != null) {
            .add(property);
          }
        }
      }
    } catch (EdmException e) {
    }
  }
  private Map<StringEntityPropertyInfocreatePropertyInfoObjects(final EdmStructuralType typefinal List<StringpropertyNamesthrows EntityProviderException {
    try {
      Map<StringEntityPropertyInfoinfos = new HashMap<StringEntityPropertyInfo>();
      for (String propertyName : propertyNames) {
        EdmProperty property = (EdmPropertytype.getProperty(propertyName);
        checkETagRelevant(property);
        EntityPropertyInfo info = createEntityPropertyInfo(property);
        infos.put(info.getName(), info);
        checkTargetPathInfo(propertyinfo);
      }
      return infos;
    } catch (EdmException e) {
    }
  }
  private Map<StringNavigationPropertyInfocreateNavigationInfoObjects(final EdmStructuralType typefinal List<StringpropertyNamesthrows EntityProviderException {
    try {
      for (String propertyName : propertyNames) {
        EdmNavigationProperty navProperty = (EdmNavigationPropertytype.getProperty(propertyName);
        NavigationPropertyInfo info = NavigationPropertyInfo.create(navProperty);
        infos.put(propertyNameinfo);
      }
      return infos;
    } catch (EdmException e) {
    }
  }
    EdmType type = property.getType();
    if (type instanceof EdmSimpleType) {
      return EntityPropertyInfo.create(property);
    } else if (type instanceof EdmComplexType) {
      EdmComplexType complex = (EdmComplexTypetype;
      Map<StringEntityPropertyInforecursiveInfos = createPropertyInfoObjects(complexcomplex.getPropertyNames());
      return EntityComplexPropertyInfo.create(propertycomplex.getPropertyNames(), recursiveInfos);
    } else {
    }
  }
  private EntityPropertyInfo createEntityPropertyInfo(final EdmFunctionImport functionImportfinal EdmType typethrows EdmExceptionEntityProviderException {
    EntityPropertyInfo epi;
    if (type.getKind() == .) {
      EdmComplexType complex = (EdmComplexTypetype;
      Map<StringEntityPropertyInfoeia = EntityInfoAggregator.create(complex);
      List<EntityPropertyInfochildEntityInfoList = new ArrayList<EntityPropertyInfo>();
      for (String propertyName : complex.getPropertyNames()) {
        childEntityInfoList.add(eia.get(propertyName));
      }
      epi = new EntityComplexPropertyInfo(functionImport.getName(), typenullnullchildEntityInfoList);
    } else if (type.getKind() == .) {
      epi = new EntityPropertyInfo(functionImport.getName(), typenullnullnullnull);
    } else {
    }
    return epi;
  }
  private void checkETagRelevant(final EdmProperty edmPropertythrows EntityProviderException {
    try {
      if (edmProperty.getFacets() != null && edmProperty.getFacets().getConcurrencyMode() == .) {
        .add(edmProperty.getName());
      }
    } catch (EdmException e) {
    }
  }
  private void checkTargetPathInfo(final EdmProperty propertyfinal EntityPropertyInfo propertyInfothrows EntityProviderException {
    try {
      EdmCustomizableFeedMappings customizableFeedMappings = property.getCustomizableFeedMappings();
      if (customizableFeedMappings != null) {
        String targetPath = customizableFeedMappings.getFcTargetPath();
        .put(targetPathpropertyInfo);
        if (!.contains(targetPath)) {
          .add(targetPath);
        }
      }
    } catch (EdmException e) {
    }
  }
  }
New to GrepCode? Check out our FAQ X