Repository: olingo-odata4
Updated Branches:
  refs/heads/master 58ec0358c -> 8cbe468c2


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLabeledElementReference.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLabeledElementReference.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLabeledElementReference.java
index b9b9483..36379f6 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLabeledElementReference.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLabeledElementReference.java
@@ -38,4 +38,25 @@ public class CsdlLabeledElementReference extends 
CsdlDynamicExpression {
     this.value = value;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlLabeledElementReference)) {
+      return false;
+    }
+    CsdlLabeledElementReference csdlLabelledEleRef = 
(CsdlLabeledElementReference) obj;
+    return (this.getValue() == null ? csdlLabelledEleRef.getValue() == null :
+        this.getValue().equals(csdlLabelledEleRef.getValue()));
+  }
+  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLogicalOrComparisonExpression.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLogicalOrComparisonExpression.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLogicalOrComparisonExpression.java
index bbf50f4..e14c944 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLogicalOrComparisonExpression.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlLogicalOrComparisonExpression.java
@@ -145,4 +145,51 @@ public class CsdlLogicalOrComparisonExpression extends 
CsdlDynamicExpression imp
     }
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlLogicalOrComparisonExpression)) {
+      return false;
+    }
+    CsdlLogicalOrComparisonExpression csdlLogComp = 
(CsdlLogicalOrComparisonExpression) obj;
+    return (this.getLeft() == null ? csdlLogComp.getLeft() == null :
+      this.getLeft().equals(csdlLogComp.getLeft()))
+        && (this.getRight() == null ? csdlLogComp.getRight() == null : 
+          this.getRight().equals(csdlLogComp.getRight()))
+        && (this.getType() == null ? csdlLogComp.getType() == null : 
+          this.getType().equals(csdlLogComp.getType()))
+        && (this.getAnnotations() == null ? csdlLogComp.getAnnotations() == 
null : 
+            checkAnnotations(csdlLogComp.getAnnotations()));
+  }
+  
+  private boolean checkAnnotations(List<CsdlAnnotation> csdlLogCompAnnot) {
+    if (csdlLogCompAnnot == null) {
+      return false;
+    }
+    if (this.getAnnotations().size() == csdlLogCompAnnot.size()) {
+      for (int i = 0; i < this.getAnnotations().size() ; i++) {
+        if (!this.getAnnotations().get(i).equals(csdlLogCompAnnot.get(i))) {
+          return false;
+        }
+      }
+    } else {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((type == null) ? 0 : type.hashCode());
+    result = prime * result + ((left == null) ? 0 : left.hashCode());
+    result = prime * result + ((right == null) ? 0 : right.hashCode());
+    result = prime * result + ((annotations == null) ? 0 : 
+      annotations.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNavigationPropertyPath.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNavigationPropertyPath.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNavigationPropertyPath.java
index f600c0a..32a1b8f 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNavigationPropertyPath.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNavigationPropertyPath.java
@@ -39,4 +39,25 @@ public class CsdlNavigationPropertyPath extends 
CsdlDynamicExpression {
     this.value = value;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlNavigationPropertyPath)) {
+      return false;
+    }
+    CsdlNavigationPropertyPath csdlNavPropPath = (CsdlNavigationPropertyPath) 
obj;
+    return (this.getValue() == null ? csdlNavPropPath.getValue() == null :
+      this.getValue().equals(csdlNavPropPath.getValue()));
+  }
+  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNull.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNull.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNull.java
index b7c85d7..b75ffb2 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNull.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlNull.java
@@ -40,4 +40,42 @@ public class CsdlNull extends CsdlDynamicExpression 
implements CsdlAnnotatable {
     this.annotations = annotations;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlNull)) {
+      return false;
+    }
+    CsdlNull csdlNull = (CsdlNull) obj;
+    return (this.getAnnotations() == null ? csdlNull.getAnnotations() == null :
+        checkAnnotations(csdlNull.getAnnotations()));
+  }
+  
+  private boolean checkAnnotations(List<CsdlAnnotation> csdlNullAnnot) {
+    if (csdlNullAnnot == null) {
+      return false;
+    }
+    if (this.getAnnotations().size() == csdlNullAnnot.size()) {
+      for (int i = 0; i < this.getAnnotations().size() ; i++) {
+        if (!this.getAnnotations().get(i).equals(csdlNullAnnot.get(i))) {
+          return false;
+        }
+      }
+    } else {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((annotations == null) ? 0 : 
+      annotations.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPath.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPath.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPath.java
index 4d1d2e1..01087ff 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPath.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPath.java
@@ -40,4 +40,25 @@ public class CsdlPath extends CsdlDynamicExpression {
     this.value = value;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlPath)) {
+      return false;
+    }
+    CsdlPath csdlPath = (CsdlPath) obj;
+    return (this.getValue() == null ? csdlPath.getValue() == null :
+      this.getValue().equals(csdlPath.getValue()));
+  }
+  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyPath.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyPath.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyPath.java
index f1d562f..5160889 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyPath.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyPath.java
@@ -38,4 +38,25 @@ public class CsdlPropertyPath extends CsdlDynamicExpression {
     this.value = value;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlPropertyPath)) {
+      return false;
+    }
+    CsdlPropertyPath csdlPropPath = (CsdlPropertyPath) obj;
+    return this.getValue() == null ? csdlPropPath.getValue() == null : 
+      this.getValue().equals(csdlPropPath.getValue());
+  }
+  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyValue.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyValue.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyValue.java
index 4ee4b79..35524eb 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyValue.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlPropertyValue.java
@@ -71,4 +71,50 @@ public class CsdlPropertyValue extends CsdlAbstractEdmItem 
implements CsdlAnnota
     this.value = value;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlPropertyValue)) {
+      return false;
+    }
+    CsdlPropertyValue csdlPropertyValue = (CsdlPropertyValue) obj;
+    
+    return (this.getProperty() == null ? csdlPropertyValue.getProperty() == 
null :
+      this.getProperty().equalsIgnoreCase(csdlPropertyValue.getProperty()))
+        && (this.getValue() == null ? csdlPropertyValue.getValue() == null :
+          this.getValue().equals(csdlPropertyValue.getValue()))
+        && (this.getAnnotations() == null ? csdlPropertyValue.getAnnotations() 
== null :
+            checkAnnotations(csdlPropertyValue.getAnnotations()));
+  }
+  
+  private boolean checkAnnotations(List<CsdlAnnotation> 
csdlPropertyValueAnnot) {
+    if (csdlPropertyValueAnnot == null) {
+      return false;
+    }
+    if (this.getAnnotations().size() == csdlPropertyValueAnnot.size()) {
+      for (int i = 0; i < this.getAnnotations().size() ; i++) {
+        if (!this.getAnnotations().get(i).equals(
+            csdlPropertyValueAnnot.get(i))) {
+          return false;
+        }
+      }
+    } else {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((property == null) ? 0 : property.hashCode());
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    result = prime * result + ((annotations == null) ? 0 : 
+      annotations.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlRecord.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlRecord.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlRecord.java
index 772e97e..a0fa747 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlRecord.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlRecord.java
@@ -69,4 +69,66 @@ public class CsdlRecord extends CsdlDynamicExpression 
implements CsdlAnnotatable
     this.propertyValues = propertyValues;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlRecord)) {
+      return false;
+    }
+    CsdlRecord csdlRecord = (CsdlRecord) obj;
+    return (this.getType() == null ? csdlRecord.getType() == null :
+      this.getType().equals(csdlRecord.getType()))
+        && (this.getAnnotations() == null ? csdlRecord.getAnnotations() == 
null :
+            checkAnnotations(csdlRecord.getAnnotations()))
+        && (this.getPropertyValues() == null ? csdlRecord.getPropertyValues() 
== null :
+            checkPropertyValues(csdlRecord.getPropertyValues()));
+  }
+  
+  private boolean checkPropertyValues(List<CsdlPropertyValue> 
csdlRecordpropertyValues) {
+    if (csdlRecordpropertyValues == null) {
+      return false;
+    }
+    if (this.getPropertyValues().size() == csdlRecordpropertyValues.size()) {
+      for (int i = 0; i < this.getPropertyValues().size(); i++) {
+        if (!this.getPropertyValues().get(i).equals(
+            csdlRecordpropertyValues.get(i))) {
+          return false;
+        }
+      }
+    } else {
+      return false;
+    }
+    return true;
+  }
+
+  private boolean checkAnnotations(List<CsdlAnnotation> csdlRecordAnnot) {
+    if (csdlRecordAnnot == null) {
+      return false;
+    }
+    if (this.getAnnotations().size() == csdlRecordAnnot.size()) {
+      for (int i = 0; i < this.getAnnotations().size() ; i++) {
+        if (!this.getAnnotations().get(i).equals(csdlRecordAnnot.get(i))) {
+          return false;
+        }
+      }
+    } else {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((type == null) ? 0 : type.hashCode());
+    result = prime * result + ((propertyValues == null) ? 0 : 
+      propertyValues.hashCode());
+    result = prime * result + ((annotations == null) ? 0 : 
+      annotations.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlUrlRef.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlUrlRef.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlUrlRef.java
index a08a279..b90ceba 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlUrlRef.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/annotation/CsdlUrlRef.java
@@ -55,4 +55,44 @@ public class CsdlUrlRef extends CsdlDynamicExpression 
implements CsdlAnnotatable
     this.value = value;
     return this;
   }
+  
+  @Override
+  public boolean equals (Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (!(obj instanceof CsdlUrlRef)) {
+      return false;
+    }
+    CsdlUrlRef csdlUrlRef = (CsdlUrlRef) obj;
+    return (this.getValue() == null ? csdlUrlRef.getValue() == null :
+      this.getValue().equals(csdlUrlRef.getValue()))
+        && (this.getAnnotations() == null ? csdlUrlRef.getAnnotations() == 
null :
+            checkAnnotations(csdlUrlRef.getAnnotations()));
+  }
+  
+  private boolean checkAnnotations(List<CsdlAnnotation> csdlUrlRefAnnot) {
+    if (csdlUrlRefAnnot == null) {
+      return false;
+    }
+    if (this.getAnnotations().size() == csdlUrlRefAnnot.size()) {
+      for (int i = 0; i < this.getAnnotations().size() ; i++) {
+        if (!this.getAnnotations().get(i).equals(csdlUrlRefAnnot.get(i))) {
+          return false;
+        }
+      }
+    } else {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((value == null) ? 0 : value.hashCode());
+    result = prime * result + ((annotations == null) ? 0 : 
annotations.hashCode());
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
index bcfd394..06d053e 100644
--- 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
+++ 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
@@ -42,6 +42,9 @@ public abstract class AbstractEdm implements Edm {
 
   protected Map<String, EdmSchema> schemas;
   protected List<EdmSchema> schemaList;
+  private boolean isEntityDerivedFromES;
+  private boolean isComplexDerivedFromES;
+  private boolean isPreviousES;
 
   private final Map<FullQualifiedName, EdmEntityContainer> entityContainers =
       Collections.synchronizedMap(new HashMap<FullQualifiedName, 
EdmEntityContainer>());
@@ -80,6 +83,18 @@ public abstract class AbstractEdm implements Edm {
       Collections.synchronizedMap(new HashMap<TargetQualifierMapKey, 
EdmAnnotations>());
 
   private Map<String, String> aliasToNamespaceInfo = null;
+  
+  private final Map<FullQualifiedName, EdmEntityType> 
entityTypesWithAnnotations =
+      Collections.synchronizedMap(new HashMap<FullQualifiedName, 
EdmEntityType>());
+  
+  private final Map<FullQualifiedName, EdmEntityType> entityTypesDerivedFromES 
=
+      Collections.synchronizedMap(new HashMap<FullQualifiedName, 
EdmEntityType>());
+  
+  private final Map<FullQualifiedName, EdmComplexType> 
complexTypesWithAnnotations =
+      Collections.synchronizedMap(new HashMap<FullQualifiedName, 
EdmComplexType>());
+  
+  private final Map<FullQualifiedName, EdmComplexType> 
complexTypesDerivedFromES =
+      Collections.synchronizedMap(new HashMap<FullQualifiedName, 
EdmComplexType>());
 
   @Override
   public List<EdmSchema> getSchemas() {
@@ -176,6 +191,56 @@ public abstract class AbstractEdm implements Edm {
   }
 
   @Override
+  public EdmEntityType getEntityTypeWithAnnotations(final FullQualifiedName 
namespaceOrAliasFQN) {
+    final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
+    EdmEntityType entityType = entityTypesWithAnnotations.get(fqn);
+    if (entityType == null) {
+      entityType = createEntityType(fqn);
+      if (entityType != null) {
+          entityTypesWithAnnotations.put(fqn, entityType);
+      }
+    }
+    setIsPreviousES(false);
+    return entityType;
+  }
+  
+  protected EdmEntityType getEntityTypeWithAnnotations(final FullQualifiedName 
namespaceOrAliasFQN, 
+      boolean isEntityDerivedFromES) {
+    this.isEntityDerivedFromES = isEntityDerivedFromES;
+    final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
+    if (!isPreviousES() && getEntityContainer() != null) {
+       getEntityContainer().getEntitySetsWithAnnotations();
+    }
+    EdmEntityType entityType = entityTypesDerivedFromES.get(fqn);
+    if (entityType == null) {
+      entityType = createEntityType(fqn);
+      if (entityType != null) {
+          entityTypesDerivedFromES.put(fqn, entityType);
+      }
+    }
+    this.isEntityDerivedFromES = false;
+    return entityType;
+  }
+  
+  protected EdmComplexType getComplexTypeWithAnnotations(final 
FullQualifiedName namespaceOrAliasFQN, 
+      boolean isComplexDerivedFromES) {
+    this.isComplexDerivedFromES = isComplexDerivedFromES;
+    final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
+    if (!isPreviousES() && getEntityContainer() != null) {
+       getEntityContainer().getEntitySetsWithAnnotations();
+    }
+    EdmComplexType complexType = complexTypesDerivedFromES.get(fqn);
+    if (complexType == null) {
+      complexType = createComplexType(fqn);
+      if (complexType != null) {
+          complexTypesDerivedFromES.put(fqn, complexType);
+      }
+    }
+    this.isComplexDerivedFromES = false;
+    return complexType;
+  }
+  
+  @Override
   public EdmComplexType getComplexType(final FullQualifiedName 
namespaceOrAliasFQN) {
     final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
     EdmComplexType complexType = complexTypes.get(fqn);
@@ -189,6 +254,20 @@ public abstract class AbstractEdm implements Edm {
   }
 
   @Override
+  public EdmComplexType getComplexTypeWithAnnotations(final FullQualifiedName 
namespaceOrAliasFQN) {
+    final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
+    EdmComplexType complexType = complexTypesWithAnnotations.get(fqn);
+    if (complexType == null) {
+      complexType = createComplexType(fqn);
+      if (complexType != null) {
+          complexTypesWithAnnotations.put(fqn, complexType);
+      }
+    }
+    setIsPreviousES(false);
+    return complexType;
+  }
+  
+  @Override
   public EdmAction getUnboundAction(final FullQualifiedName actionName) {
     final FullQualifiedName fqn = resolvePossibleAlias(actionName);
     EdmAction action = unboundActions.get(fqn);
@@ -452,4 +531,20 @@ public abstract class AbstractEdm implements Edm {
     }
     return functions;
   }
+  
+  protected boolean isEntityDerivedFromES() {
+    return isEntityDerivedFromES;
+  }
+  
+  protected boolean isComplexDerivedFromES() {
+    return isComplexDerivedFromES;
+  }
+  
+  protected void setIsPreviousES(boolean isPreviousES) {
+    this.isPreviousES = isPreviousES;
+  }
+  
+  protected boolean isPreviousES() {
+    return isPreviousES;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
index cade5a6..786285c 100644
--- 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
+++ 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
@@ -79,6 +79,17 @@ public abstract class AbstractEdmBindingTarget extends 
AbstractEdmNamed implemen
   }
 
   @Override
+  public EdmEntityType getEntityTypeWithAnnotations() {
+    final EdmEntityType entityType = ((AbstractEdm)edm).
+        getEntityTypeWithAnnotations(target.getTypeFQN(), true);
+    if (entityType == null) {
+      throw new EdmException("Can´t find entity type: " + target.getTypeFQN() 
+ " for entity set or singleton: "
+          + getName());
+    }
+    return entityType;
+  }
+  
+  @Override
   public EdmBindingTarget getRelatedBindingTarget(final String path) {
     if (path == null) {
       return null;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java
 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java
index 1ff83fe..9255cda 100644
--- 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java
+++ 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntityContainerImpl.java
@@ -34,12 +34,20 @@ import org.apache.olingo.commons.api.edm.EdmFunctionImport;
 import org.apache.olingo.commons.api.edm.EdmSingleton;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.provider.CsdlActionImport;
+import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
+import org.apache.olingo.commons.api.edm.provider.CsdlAnnotations;
+import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
 import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet;
+import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
 import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport;
+import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
+import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
 import org.apache.olingo.commons.api.edm.provider.CsdlSingleton;
+import org.apache.olingo.commons.api.ex.ODataException;
 
 public class EdmEntityContainerImpl extends AbstractEdmNamed implements 
EdmEntityContainer {
 
@@ -61,6 +69,12 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed 
implements EdmEntit
   private List<EdmFunctionImport> functionImports;
   private final Map<String, EdmFunctionImport> functionImportCache = 
Collections.synchronizedMap(
       new LinkedHashMap<String, EdmFunctionImport>());
+         private boolean isAnnotationsIncluded = false;
+  private final Map<String, EdmEntitySet> entitySetWithAnnotationsCache = 
Collections.synchronizedMap(
+      new LinkedHashMap<String, EdmEntitySet>());
+  private final Map<String, EdmSingleton> singletonWithAnnotationsCache = 
Collections.synchronizedMap(
+      new LinkedHashMap<String, EdmSingleton>());
+  private boolean isSingletonAnnotationsIncluded = false;
 
   public EdmEntityContainerImpl(final Edm edm, final CsdlEdmProvider provider,
       final CsdlEntityContainerInfo entityContainerInfo) {
@@ -76,7 +90,8 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed 
implements EdmEntit
     this.provider = provider;
     container = entityContainer;
     entityContainerName = containerFQN;
-    parentContainerName = entityContainer.getExtendsContainerFQN();
+    parentContainerName = entityContainer == null ? null : 
+      entityContainer.getExtendsContainerFQN();
   }
 
   @Override
@@ -91,11 +106,18 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
 
   @Override
   public EdmSingleton getSingleton(final String singletonName) {
-    EdmSingleton singleton = singletonCache.get(singletonName);
+    EdmSingleton singleton = singletonWithAnnotationsCache.get(singletonName);
     if (singleton == null) {
-      singleton = createSingleton(singletonName);
-      if (singleton != null) {
-        singletonCache.put(singletonName, singleton);
+      singleton = singletonCache.get(singletonName);
+      if (singleton == null) {
+        singleton = createSingleton(singletonName);
+        if (singleton != null) {
+          if (isSingletonAnnotationsIncluded) {
+            singletonWithAnnotationsCache.put(singletonName, singleton);
+          } else {
+            singletonCache.put(singletonName, singleton);
+          }
+        }
       }
     }
     return singleton;
@@ -103,13 +125,21 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
 
   @Override
   public EdmEntitySet getEntitySet(final String entitySetName) {
-    EdmEntitySet entitySet = entitySetCache.get(entitySetName);
+    EdmEntitySet entitySet = entitySetWithAnnotationsCache.get(entitySetName);
     if (entitySet == null) {
-      entitySet = createEntitySet(entitySetName);
-      if (entitySet != null) {
-        entitySetCache.put(entitySetName, entitySet);
+      entitySet = entitySetCache.get(entitySetName);
+      if (entitySet == null) {
+        entitySet = createEntitySet(entitySetName);
+        if (entitySet != null) {
+          if (isAnnotationsIncluded) {
+            entitySetWithAnnotationsCache.put(entitySetName, entitySet);
+          } else {
+            entitySetCache.put(entitySetName, entitySet);
+          }
+        }
       }
     }
+    ((EdmProviderImpl)edm).setIsPreviousES(true);
     return entitySet;
   }
 
@@ -146,6 +176,12 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
   }
 
   @Override
+  public List<EdmEntitySet> getEntitySetsWithAnnotations() {
+    loadAllEntitySets();
+    return Collections.unmodifiableList(entitySets);
+  }
+  
+  @Override
   public List<EdmFunctionImport> getFunctionImports() {
     if (functionImports == null) {
       loadAllFunctionImports();
@@ -180,6 +216,7 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
     try {
       final CsdlSingleton providerSingleton = 
provider.getSingleton(entityContainerName, singletonName);
       if (providerSingleton != null) {
+               addAnnotations(providerSingleton, entityContainerName);
         singleton = new EdmSingletonImpl(edm, this, providerSingleton);
       }
     } catch (ODataException e) {
@@ -189,12 +226,112 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
     return singleton;
   }
 
+  private void addAnnotations(CsdlSingleton singleton, FullQualifiedName 
entityContainerName) {
+    boolean isPropAnnotationsCleared = false;
+    boolean isNavPropAnnotationsCleared = false;
+    CsdlEntityType entityType = fetchEntityTypeFromSingleton(singleton);
+    if (entityType == null) {
+      return;
+    }
+    
+    List<CsdlSchema> termSchemaDefinition = 
((EdmProviderImpl)edm).getTermSchemaDefinitions();
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if (annotationGrp.getTarget().
+            equalsIgnoreCase(entityContainerName + "/" + singleton.getName())) 
{
+          isSingletonAnnotationsIncluded = true;
+          addAnnotationsToSingleton(singleton, annotationGrp);
+        } else {
+          addAnnotationsToPropertiesDerivedFromSingleton(singleton, 
isPropAnnotationsCleared,
+              isNavPropAnnotationsCleared, entityType, annotationGrp);
+          isPropAnnotationsCleared = true;
+          isNavPropAnnotationsCleared = true;
+        }
+      }
+    }
+   }
+
+  /** adds annotations to entity type properties derived from singleton
+   * @param singleton
+   * @param isPropAnnotationsCleared
+   * @param isNavPropAnnotationsCleared
+   * @param entityType
+   * @param annotationGrp
+   */
+  private void addAnnotationsToPropertiesDerivedFromSingleton(CsdlSingleton 
singleton, boolean isPropAnnotationsCleared,
+      boolean isNavPropAnnotationsCleared, CsdlEntityType entityType, 
CsdlAnnotations annotationGrp) {
+    for (CsdlProperty propertyName : entityType.getProperties()) {
+      if (!isPropAnnotationsCleared) {
+        
entityType.getProperty(propertyName.getName()).getAnnotations().clear();
+      }
+      if (isPropertyComplex(propertyName)) {
+        CsdlComplexType complexType = getComplexTypeFromProperty(propertyName);
+        addAnnotationsToComplexTypeIncludedFromSingleton(singleton, 
+           annotationGrp, propertyName, isNavPropAnnotationsCleared, 
complexType);
+      }
+    }
+  }
+
+  /** Adds annotation to singleton
+   * @param singleton
+   * @param annotationGrp
+   */
+  private void addAnnotationsToSingleton(CsdlSingleton singleton, 
CsdlAnnotations annotationGrp) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+      if (!compareAnnotations(singleton.getAnnotations(), annotation)) {
+        singleton.getAnnotations().add(annotation);
+      }
+    }
+  }
+
+  /**
+   * @param singleton
+   * @return
+   */
+  private CsdlEntityType fetchEntityTypeFromSingleton(CsdlSingleton singleton) 
{
+    CsdlEntityType entityType;
+    try {
+      entityType = singleton.getTypeFQN() != null ? 
this.provider.getEntityType(new FullQualifiedName(
+          singleton.getTypeFQN().getFullQualifiedNameAsString())) : null;
+   } catch (ODataException e) {
+     throw new EdmException(e);
+   }
+    return entityType;
+  }
+  
+  /**
+   * 
+   * @param singleton
+   * @param entityContainerName2
+   * @param annotationGrp
+   * @param propertyName
+   * @param isComplexNavPropAnnotationsCleared
+   * @param complexType
+   */
+  private void addAnnotationsToComplexTypeIncludedFromSingleton(CsdlSingleton 
singleton,
+      CsdlAnnotations annotationGrp, CsdlProperty propertyName,
+      boolean isComplexNavPropAnnotationsCleared, CsdlComplexType complexType) 
{
+    for (CsdlNavigationProperty complexNavPropertyName : 
complexType.getNavigationProperties()) {
+      if (!isComplexNavPropAnnotationsCleared) {
+        
complexType.getNavigationProperty(complexNavPropertyName.getName()).getAnnotations().clear();
+      }
+      if (annotationGrp.getTarget().
+          equalsIgnoreCase(entityContainerName + "/" + singleton.getName() + 
"/" + 
+      propertyName.getName() + "/" + complexNavPropertyName.getName())) {
+        isSingletonAnnotationsIncluded = true;
+        addAnnotationsToComplexTypeNavProperties(annotationGrp, complexType, 
complexNavPropertyName);
+      }
+    }    
+  }
+  
   protected EdmEntitySet createEntitySet(final String entitySetName) {
     EdmEntitySet entitySet = null;
 
     try {
       final CsdlEntitySet providerEntitySet = 
provider.getEntitySet(entityContainerName, entitySetName);
       if (providerEntitySet != null) {
+               addAnnotations(providerEntitySet, entityContainerName);
         entitySet = new EdmEntitySetImpl(edm, this, providerEntitySet);
       }
     } catch (ODataException e) {
@@ -204,12 +341,228 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
     return entitySet;
   }
 
+  private void addAnnotations(CsdlEntitySet entitySet, FullQualifiedName 
entityContainerName) {
+    boolean isPropAnnotationsCleared = false;
+    boolean isNavPropAnnotationsCleared = false;
+    CsdlEntityType entityType = getCsdlEntityTypeFromEntitySet(entitySet);
+    if (entityType == null) {
+      return;
+    }
+    
+   List<CsdlSchema> termSchemaDefinition = 
((EdmProviderImpl)edm).getTermSchemaDefinitions();
+   for (CsdlSchema schema : termSchemaDefinition) {
+     List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+     for (CsdlAnnotations annotationGrp : annotationGrps) {
+       if (annotationGrp.getTarget().
+           equalsIgnoreCase(entityContainerName + "/" + entitySet.getName())) {
+         isAnnotationsIncluded = true;
+         addAnnotationsToEntitySet(entitySet, annotationGrp);
+       } else {
+         addAnnotationsToEntityTypeIncludedFromES(entitySet, 
entityContainerName,
+             annotationGrp, isPropAnnotationsCleared, 
isNavPropAnnotationsCleared, entityType);
+         isPropAnnotationsCleared = true;
+         isNavPropAnnotationsCleared = true;
+       }
+     }
+   }
+  }
+
+  /**
+   * @param entitySet
+   * @param annotationGrp
+   */
+  private void addAnnotationsToEntitySet(CsdlEntitySet entitySet, 
CsdlAnnotations annotationGrp) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+       if (!compareAnnotations(entitySet.getAnnotations(), annotation)) {
+         entitySet.getAnnotations().add(annotation);
+       }
+     }
+  }
+
+  /**
+   * @param entitySet
+   * @return
+   */
+  private CsdlEntityType getCsdlEntityTypeFromEntitySet(CsdlEntitySet 
entitySet) {
+    CsdlEntityType entityType;
+    try {
+      entityType = entitySet.getTypeFQN() != null ? 
this.provider.getEntityType(new FullQualifiedName(
+          entitySet.getTypeFQN().getFullQualifiedNameAsString())) : null;
+   } catch (ODataException e) {
+     throw new EdmException(e);
+   }
+    return entityType;
+  }
+
+  /** Adds annotations to Entity type Properties derived from entity set
+   * @param entitySet
+   * @param entityContainerName
+   * @param annotationGrp
+   * @param entityType 
+   * @param isNavPropAnnotationsCleared 
+   * @param isPropAnnotationsCleared
+   * @return
+   */
+  private void addAnnotationsToEntityTypeIncludedFromES(CsdlEntitySet 
entitySet,
+      FullQualifiedName entityContainerName, CsdlAnnotations annotationGrp, 
+      boolean isPropAnnotationsCleared, boolean isNavPropAnnotationsCleared, 
CsdlEntityType entityType) {
+     for (CsdlProperty propertyName : entityType.getProperties()) {
+       if (!isPropAnnotationsCleared) {
+         
entityType.getProperty(propertyName.getName()).getAnnotations().clear();
+       }
+       if (isPropertyComplex(propertyName)) {
+         CsdlComplexType complexType = 
getComplexTypeFromProperty(propertyName);
+         addAnnotationsToComplexTypeIncludedFromES(entitySet, 
entityContainerName,
+            annotationGrp, propertyName, isPropAnnotationsCleared, 
isNavPropAnnotationsCleared, complexType);
+       } else {
+         if (annotationGrp.getTarget().
+             equalsIgnoreCase(entityContainerName + "/" + entitySet.getName() 
+ "/" + 
+         propertyName.getName())) {
+           isAnnotationsIncluded = true;
+           addAnnotationsToEntityTypeProperties(annotationGrp, entityType, 
propertyName);
+         }
+       }
+     }
+     for (CsdlNavigationProperty navPropertyName : 
entityType.getNavigationProperties()) {
+       if (!isNavPropAnnotationsCleared) {
+         
entityType.getNavigationProperty(navPropertyName.getName()).getAnnotations().clear();
+       }
+       if (annotationGrp.getTarget().
+           equalsIgnoreCase(entityContainerName + "/" + entitySet.getName() + 
"/" + 
+       navPropertyName.getName())) {
+         isAnnotationsIncluded = true;
+         addAnnotationsToEntityTypeNavProperties(annotationGrp, entityType, 
navPropertyName);
+       }
+     }
+  }
+
+  /** Adds annotations to Entity type Navigation Properties derived from 
entity set
+   * @param annotationGrp
+   * @param entityType
+   * @param navPropertyName
+   */
+  private void addAnnotationsToEntityTypeNavProperties(CsdlAnnotations 
annotationGrp, CsdlEntityType entityType,
+      CsdlNavigationProperty navPropertyName) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+       if (!compareAnnotations(entityType.getNavigationProperty(
+           navPropertyName.getName()).getAnnotations(), annotation)) {
+         
entityType.getNavigationProperty(navPropertyName.getName()).getAnnotations().add(annotation);
 
+       }
+     }
+  }
+
+  /** Adds annotations to Entity type Properties derived from entity set
+   * @param annotationGrp
+   * @param entityType
+   * @param propertyName
+   */
+  private void addAnnotationsToEntityTypeProperties(CsdlAnnotations 
annotationGrp, CsdlEntityType entityType,
+      CsdlProperty propertyName) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+       if (!compareAnnotations(entityType.getProperty(
+           propertyName.getName()).getAnnotations(), annotation)) {
+         
entityType.getProperty(propertyName.getName()).getAnnotations().add(annotation);
 
+       }
+     }
+  }
+
+  /**
+   * @param propertyName
+   * @return
+   */
+  private CsdlComplexType getComplexTypeFromProperty(CsdlProperty 
propertyName) {
+    CsdlComplexType complexType;
+     try {
+      complexType = 
this.provider.getComplexType(propertyName.getTypeAsFQNObject());
+    } catch (ODataException e) {
+      throw new EdmException(e);
+    }
+    return complexType;
+  }
+
+  /**
+   * @param entitySet
+   * @param entityContainerName
+   * @param annotationGrp
+   * @param propertyName
+   * @param complexType 
+   * @param isComplexNavPropAnnotationsCleared2 
+   * @param isComplexPropAnnotationsCleared2 
+   * @return
+   */
+  private void addAnnotationsToComplexTypeIncludedFromES(CsdlEntitySet 
entitySet,
+      FullQualifiedName entityContainerName, CsdlAnnotations annotationGrp, 
+      CsdlProperty propertyName, boolean isComplexPropAnnotationsCleared, 
+      boolean isComplexNavPropAnnotationsCleared, CsdlComplexType complexType) 
{
+     for (CsdlProperty complexPropertyName : complexType.getProperties()) {
+       if (!isComplexPropAnnotationsCleared) {
+         
complexType.getProperty(complexPropertyName.getName()).getAnnotations().clear();
+       }
+       if (annotationGrp.getTarget().
+           equalsIgnoreCase(entityContainerName + "/" + entitySet.getName() + 
"/" + 
+       propertyName.getName() + "/" + complexPropertyName.getName())) {
+         isAnnotationsIncluded = true;
+         addAnnotationsToComplexTypeProperties(annotationGrp, complexType, 
complexPropertyName);
+       }
+     }
+     for (CsdlNavigationProperty complexNavPropertyName : 
complexType.getNavigationProperties()) {
+       if (!isComplexNavPropAnnotationsCleared) {
+         
complexType.getNavigationProperty(complexNavPropertyName.getName()).getAnnotations().clear();
+       }
+       if (annotationGrp.getTarget().
+           equalsIgnoreCase(entityContainerName + "/" + entitySet.getName() + 
"/" + 
+       propertyName.getName() + "/" + complexNavPropertyName.getName())) {
+         isAnnotationsIncluded = true;
+         addAnnotationsToComplexTypeNavProperties(annotationGrp, complexType, 
complexNavPropertyName);
+       }
+     }
+  }
+
+  /**
+   * @param annotationGrp
+   * @param complexType
+   * @param complexNavPropertyName
+   */
+  private void addAnnotationsToComplexTypeNavProperties(CsdlAnnotations 
annotationGrp, CsdlComplexType complexType,
+      CsdlNavigationProperty complexNavPropertyName) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+       if (!compareAnnotations(complexType.getNavigationProperty(
+           complexNavPropertyName.getName()).getAnnotations(), annotation)) {
+         
complexType.getNavigationProperty(complexNavPropertyName.getName()).getAnnotations().add(annotation);
 
+       }
+     }
+  }
+
+  /**
+   * @param annotationGrp
+   * @param complexType
+   * @param complexPropertyName
+   */
+  private void addAnnotationsToComplexTypeProperties(CsdlAnnotations 
annotationGrp, CsdlComplexType complexType,
+      CsdlProperty complexPropertyName) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+       if (!compareAnnotations(complexType.getProperty(
+           complexPropertyName.getName()).getAnnotations(), annotation)) {
+         
complexType.getProperty(complexPropertyName.getName()).getAnnotations().add(annotation);
 
+       }
+     }
+  }
+
+  private boolean isPropertyComplex(CsdlProperty propertyName) {
+    try {
+      return this.provider.getComplexType(propertyName.getTypeAsFQNObject()) 
!= null ? true : false;
+    } catch (ODataException e) {
+      throw new EdmException(e);
+    }
+  }
+  
   protected EdmActionImport createActionImport(final String actionImportName) {
     EdmActionImport actionImport = null;
 
     try {
       final CsdlActionImport providerImport = 
provider.getActionImport(entityContainerName, actionImportName);
       if (providerImport != null) {
+               addAnnotations(providerImport, entityContainerName);
         actionImport = new EdmActionImportImpl(edm, this, providerImport);
       }
     } catch (ODataException e) {
@@ -219,12 +572,31 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
     return actionImport;
   }
 
+  private void addAnnotations(CsdlActionImport actionImport, FullQualifiedName 
entityContainerName) {
+    List<CsdlSchema> termSchemaDefinition = 
((EdmProviderImpl)edm).getTermSchemaDefinitions();
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if (annotationGrp.getTarget().
+            equalsIgnoreCase(entityContainerName + "/" + 
actionImport.getName())) {
+          for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+            if (!compareAnnotations(actionImport.getAnnotations(), 
annotation)) {
+              actionImport.getAnnotations().add(annotation);
+            }
+          }
+          break;
+        }
+      }
+    }
+   }
+   
   protected EdmFunctionImport createFunctionImport(final String 
functionImportName) {
     EdmFunctionImport functionImport = null;
 
     try {
       final CsdlFunctionImport providerImport = 
provider.getFunctionImport(entityContainerName, functionImportName);
       if (providerImport != null) {
+               addAnnotations(providerImport, entityContainerName);
         functionImport = new EdmFunctionImportImpl(edm, this, providerImport);
       }
     } catch (ODataException e) {
@@ -234,6 +606,24 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
     return functionImport;
   }
 
+  private void addAnnotations(CsdlFunctionImport functionImport, 
FullQualifiedName entityContainerName) {
+    List<CsdlSchema> termSchemaDefinition = 
((EdmProviderImpl)edm).getTermSchemaDefinitions();
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if (annotationGrp.getTarget().
+            equalsIgnoreCase(entityContainerName + "/" + 
functionImport.getName())) {
+          for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+            if (!compareAnnotations(functionImport.getAnnotations(), 
annotation)) {
+              functionImport.getAnnotations().add(annotation);
+            }
+          }
+          break;
+        }
+      }
+    }
+   }
+   
   protected void loadAllEntitySets() {
     loadContainer();
     final List<CsdlEntitySet> providerEntitySets = container.getEntitySets();
@@ -241,11 +631,17 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
 
     if (providerEntitySets != null) {
       for (CsdlEntitySet entitySet : providerEntitySets) {
+               addAnnotations(entitySet, entityContainerName);
         final EdmEntitySetImpl impl = new EdmEntitySetImpl(edm, this, 
entitySet);
-        entitySetCache.put(impl.getName(), impl);
+        if (isAnnotationsIncluded) {
+          entitySetWithAnnotationsCache.put(impl.getName(), impl);
+        } else {
+          entitySetCache.put(impl.getName(), impl);
+        }
         entitySetsLocal.add(impl);
       }
       entitySets = entitySetsLocal;
+         ((EdmProviderImpl)edm).setIsPreviousES(true);
     }
   }
 
@@ -256,6 +652,7 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
 
     if (providerFunctionImports != null) {
       for (CsdlFunctionImport functionImport : providerFunctionImports) {
+               addAnnotations(functionImport, entityContainerName);
         EdmFunctionImportImpl impl = new EdmFunctionImportImpl(edm, this, 
functionImport);
         functionImportCache.put(impl.getName(), impl);
         functionImportsLocal.add(impl);
@@ -271,6 +668,7 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
 
     if (providerSingletons != null) {
       for (CsdlSingleton singleton : providerSingletons) {
+               addAnnotations(singleton, entityContainerName);
         final EdmSingletonImpl impl = new EdmSingletonImpl(edm, this, 
singleton);
         singletonCache.put(singleton.getName(), impl);
         singletonsLocal.add(impl);
@@ -286,7 +684,8 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
 
     if (providerActionImports != null) {
       for (CsdlActionImport actionImport : providerActionImports) {
-        final EdmActionImportImpl impl = new EdmActionImportImpl(edm, this, 
actionImport);
+        addAnnotations(actionImport, entityContainerName);
+               final EdmActionImportImpl impl = new EdmActionImportImpl(edm, 
this, actionImport);
         actionImportCache.put(actionImport.getName(), impl);
         actionImportsLocal.add(impl);
       }
@@ -302,11 +701,20 @@ public class EdmEntityContainerImpl extends 
AbstractEdmNamed implements EdmEntit
         if (containerLocal == null) {
           containerLocal = new CsdlEntityContainer().setName(getName());
         }
-
+               ((EdmProviderImpl)edm).addAnnotations(containerLocal, 
entityContainerName);
         container = containerLocal;
       } catch (ODataException e) {
         throw new EdmException(e);
       }
     }
   }
+  
+  private boolean compareAnnotations(List<CsdlAnnotation> annotations, 
CsdlAnnotation annotation) {
+    for (CsdlAnnotation annot : annotations) {
+      if (annot.equals(annotation)) {
+        return true;
+      }
+    }
+    return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java
 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java
index 67d0a21..b74292a 100644
--- 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java
+++ 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmPropertyImpl.java
@@ -54,6 +54,21 @@ public class EdmPropertyImpl extends AbstractEdmNamed 
implements EdmProperty {
     return propertyType;
   }
 
+  @Override
+  public EdmType getTypeWithAnnotations() {
+    if (propertyType == null) {
+      if (typeInfo == null) {
+        buildTypeInfoWithAnnotations();
+      }
+      propertyType = typeInfo.getType();
+      if (propertyType == null) {
+        throw new EdmException("Cannot find type with name: " + 
typeInfo.getFullQualifiedName());
+      }
+    }
+
+    return propertyType;
+  }
+  
   private void buildTypeInfo() {
     if (property.getType() == null) {
       throw new EdmException("Property " + property.getName() + " must hava a 
full qualified type.");
@@ -61,6 +76,14 @@ public class EdmPropertyImpl extends AbstractEdmNamed 
implements EdmProperty {
     typeInfo = new 
EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(property.getType()).build();
   }
 
+  private void buildTypeInfoWithAnnotations() {
+    if (property.getType() == null) {
+      throw new EdmException("Property " + property.getName() + " must hava a 
full qualified type.");
+    }
+    typeInfo = new 
EdmTypeInfo.Builder().setEdm(edm).setIncludeAnnotations(true)
+        .setTypeExpression(property.getType()).build();
+  }
+  
   @Override
   public boolean isCollection() {
     return property.isCollection();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java
 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java
index 6f8e7f4..e4ad840 100644
--- 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java
+++ 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmProviderImpl.java
@@ -39,16 +39,20 @@ import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.provider.CsdlAction;
 import org.apache.olingo.commons.api.edm.provider.CsdlAliasInfo;
+import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
 import org.apache.olingo.commons.api.edm.provider.CsdlAnnotations;
 import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
 import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
+import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo;
 import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
 import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
 import org.apache.olingo.commons.api.edm.provider.CsdlFunction;
+import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
 import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
 import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
 import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
+import org.apache.olingo.commons.api.edm.provider.CsdlStructuralType;
 import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
 import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
 import org.apache.olingo.commons.api.ex.ODataException;
@@ -60,7 +64,7 @@ public class EdmProviderImpl extends AbstractEdm {
       Collections.synchronizedMap(new HashMap<FullQualifiedName, 
List<CsdlAction>>());
   private final Map<FullQualifiedName, List<CsdlFunction>> functionsMap =
       Collections.synchronizedMap(new HashMap<FullQualifiedName, 
List<CsdlFunction>>());
-  private List<CsdlSchema> termSchemaDefinition = null;
+  private List<CsdlSchema> termSchemaDefinition = new ArrayList<CsdlSchema>();
 
   public EdmProviderImpl(final CsdlEdmProvider provider) {
     this.provider = provider;
@@ -76,7 +80,9 @@ public class EdmProviderImpl extends AbstractEdm {
     try {
       CsdlEntityContainerInfo entityContainerInfo = 
provider.getEntityContainerInfo(containerName);
       if (entityContainerInfo != null) {
-        return new EdmEntityContainerImpl(this, provider, entityContainerInfo);
+               addAnnotations(provider.getEntityContainer(), 
entityContainerInfo.getContainerName());
+        return new EdmEntityContainerImpl(this, provider, 
entityContainerInfo.getContainerName(), 
+            provider.getEntityContainer());
       }
       return null;
     } catch (ODataException e) {
@@ -84,11 +90,28 @@ public class EdmProviderImpl extends AbstractEdm {
     }
   }
 
+  public void addAnnotations(CsdlEntityContainer csdlEntityContainer, 
FullQualifiedName containerName) {
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if 
(annotationGrp.getTarget().equalsIgnoreCase(containerName.getFullQualifiedNameAsString()))
 {
+          for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+            if (!compareAnnotations(csdlEntityContainer.getAnnotations(), 
annotation)) {
+              
csdlEntityContainer.getAnnotations().addAll(annotationGrp.getAnnotations());
+            }
+          }
+          break;
+        }
+      }
+    }
+  }
+  
   @Override
   public EdmEnumType createEnumType(final FullQualifiedName enumName) {
     try {
       CsdlEnumType enumType = provider.getEnumType(enumName);
       if (enumType != null) {
+               addAnnotations(enumType, enumName);
         return new EdmEnumTypeImpl(this, enumName, enumType);
       }
       return null;
@@ -97,11 +120,28 @@ public class EdmProviderImpl extends AbstractEdm {
     }
   }
 
+  public void addAnnotations(CsdlEnumType enumType, FullQualifiedName 
enumName) {
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if 
(annotationGrp.getTarget().equalsIgnoreCase(enumName.getFullQualifiedNameAsString()))
 {
+          for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+            if (!compareAnnotations(enumType.getAnnotations(), annotation)) {
+              enumType.getAnnotations().addAll(annotationGrp.getAnnotations());
+            }
+          }
+          break;
+        }
+      }
+    }
+  }
+  
   @Override
   public EdmTypeDefinition createTypeDefinition(final FullQualifiedName 
typeDefinitionName) {
     try {
       CsdlTypeDefinition typeDefinition = 
provider.getTypeDefinition(typeDefinitionName);
       if (typeDefinition != null) {
+               addAnnotations(typeDefinition, typeDefinitionName);
         return new EdmTypeDefinitionImpl(this, typeDefinitionName, 
typeDefinition);
       }
       return null;
@@ -109,12 +149,31 @@ public class EdmProviderImpl extends AbstractEdm {
       throw new EdmException(e);
     }
   }
+  
+  public void addAnnotations(CsdlTypeDefinition typeDefinition, 
FullQualifiedName typeDefinitionName) {
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if 
(annotationGrp.getTarget().equalsIgnoreCase(typeDefinitionName.getFullQualifiedNameAsString()))
 {
+          for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+            if (!compareAnnotations(typeDefinition.getAnnotations(), 
annotation)) {
+              
typeDefinition.getAnnotations().addAll(annotationGrp.getAnnotations());
+            }
+          }
+          break;
+        }
+      }
+    }
+  }
 
   @Override
   public EdmEntityType createEntityType(final FullQualifiedName 
entityTypeName) {
     try {
       CsdlEntityType entityType = provider.getEntityType(entityTypeName);
       if (entityType != null) {
+                 if (!isEntityDerivedFromES()) {
+          addAnnotations(entityType, entityTypeName);
+        }
         return new EdmEntityTypeImpl(this, entityTypeName, entityType);
       }
       return null;
@@ -123,11 +182,121 @@ public class EdmProviderImpl extends AbstractEdm {
     }
   }
 
+  /**
+   * Add the annotations defined in an external file to the property/
+   * navigation property and the entity
+   * @param structuralType
+   * @param typeName
+   */
+  public void addAnnotations(CsdlStructuralType structuralType, 
FullQualifiedName typeName) {
+    boolean isPropAnnotationsCleared = false;
+    boolean isNavPropAnnotationsCleared = false;
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if 
(annotationGrp.getTarget().equalsIgnoreCase(typeName.getFullQualifiedNameAsString()))
 {
+          addAnnotationsToStructuralTypes(structuralType, annotationGrp);
+        } else {
+          checkAnnotationsOnStructuralProperties(structuralType, typeName, 
isPropAnnotationsCleared, annotationGrp);
+          checkAnnotationsOnStructuralNavProperties(structuralType, typeName, 
isNavPropAnnotationsCleared,
+              annotationGrp);
+          isPropAnnotationsCleared = true;
+          isNavPropAnnotationsCleared = true;
+        }
+      }
+    }
+  }
+
+  /** Check if annotations are added on navigation properties of a structural 
type
+   * @param structuralType
+   * @param typeName
+   * @param isNavPropAnnotationsCleared
+   * @param annotationGrp
+   */
+  private void checkAnnotationsOnStructuralNavProperties(CsdlStructuralType 
structuralType, FullQualifiedName typeName,
+      boolean isNavPropAnnotationsCleared, CsdlAnnotations annotationGrp) {
+    List<CsdlNavigationProperty> navProperties = 
structuralType.getNavigationProperties();
+    for (CsdlNavigationProperty navProperty : navProperties) {
+      if (!isNavPropAnnotationsCleared) {
+        
structuralType.getNavigationProperty(navProperty.getName()).getAnnotations().clear();
+      }
+      if (annotationGrp.getTarget().equalsIgnoreCase(typeName + "/" + 
navProperty.getName())) {
+        addAnnotationsToStructuralTypeNavProperties(structuralType, 
annotationGrp, navProperty);
+      }
+    }
+  }
+
+  /** Check if annotations are added on properties of a structural type
+   * @param structuralType
+   * @param typeName
+   * @param isPropAnnotationsCleared
+   * @param annotationGrp
+   */
+  private void checkAnnotationsOnStructuralProperties(CsdlStructuralType 
structuralType, FullQualifiedName typeName,
+      boolean isPropAnnotationsCleared, CsdlAnnotations annotationGrp) {
+    List<CsdlProperty> properties = structuralType.getProperties();
+    for (CsdlProperty property : properties) {
+      if (!isPropAnnotationsCleared) {
+        
structuralType.getProperty(property.getName()).getAnnotations().clear();
+      }
+      if (annotationGrp.getTarget().equalsIgnoreCase(
+          typeName.getFullQualifiedNameAsString() + "/" + property.getName())) 
{
+        addAnnotationsToStructuralTypeProperties(structuralType, 
annotationGrp, property);
+      }
+    }
+  }
+
+  /**
+   * @param structuralType
+   * @param annotationGrp
+   * @param navProperty
+   */
+  private void addAnnotationsToStructuralTypeNavProperties(CsdlStructuralType 
structuralType,
+      CsdlAnnotations annotationGrp, CsdlNavigationProperty navProperty) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+      if (!compareAnnotations(structuralType.getNavigationProperty(
+          navProperty.getName()).getAnnotations(), annotation)) {
+        
structuralType.getNavigationProperty(navProperty.getName()).getAnnotations().
+        add(annotation);
+      }
+    }
+  }
+
+  /**
+   * @param structuralType
+   * @param annotationGrp
+   * @param property
+   */
+  private void addAnnotationsToStructuralTypeProperties(CsdlStructuralType 
structuralType,
+      CsdlAnnotations annotationGrp, CsdlProperty property) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+      if (!compareAnnotations(structuralType.getProperty(
+          property.getName()).getAnnotations(), annotation)) {
+        
structuralType.getProperty(property.getName()).getAnnotations().add(annotation);
 
+      }
+    }
+  }
+
+  /**
+   * @param structuralType
+   * @param annotationGrp
+   */
+  private void addAnnotationsToStructuralTypes(CsdlStructuralType 
structuralType, CsdlAnnotations annotationGrp) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+      if (!compareAnnotations(structuralType.getAnnotations(), annotation)) {
+        structuralType.getAnnotations().addAll(annotationGrp.getAnnotations());
+      }
+    }
+  }
+  
   @Override
   public EdmComplexType createComplexType(final FullQualifiedName 
complexTypeName) {
     try {
       final CsdlComplexType complexType = 
provider.getComplexType(complexTypeName);
       if (complexType != null) {
+                 if (!isComplexDerivedFromES()) {
+          addAnnotations(complexType, complexTypeName);
+        }
         return new EdmComplexTypeImpl(this, complexTypeName, complexType);
       }
       return null;
@@ -160,7 +329,7 @@ public class EdmProviderImpl extends AbstractEdm {
               
isComplexPreviousTypeCompatibleToBindingParam(bindingParameterTypeName, 
parameter, 
                   isBindingParameterCollection))
               && isBindingParameterCollection.booleanValue() == 
parameter.isCollection()) {
-
+                       addAnnotations(action, actionName);
             return new EdmActionImpl(this, actionName, action);
           }
 
@@ -172,6 +341,52 @@ public class EdmProviderImpl extends AbstractEdm {
     }
   }
 
+  public void addAnnotations(CsdlAction action, FullQualifiedName actionName) {
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if (annotationGrp.getTarget().equalsIgnoreCase(
+            actionName.getFullQualifiedNameAsString())) {
+          addAnnotationsToActions(action, annotationGrp);
+        } else {
+          addAnnotationsToParamsOfActions(action, actionName, annotationGrp);
+        }
+      }
+    }
+  }
+  
+  /** Adds annotations to actions
+   * @param action
+   * @param actionName
+   * @param annotationGrp
+   */
+  private void addAnnotationsToParamsOfActions(CsdlAction action, 
FullQualifiedName actionName,
+      CsdlAnnotations annotationGrp) {
+    final List<CsdlParameter> parameters = action.getParameters();
+    for (CsdlParameter parameter : parameters) {
+      if (annotationGrp.getTarget().equalsIgnoreCase(
+          actionName.getFullQualifiedNameAsString() + "/" + 
parameter.getName())) {
+        for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+          if 
(!compareAnnotations(action.getParameter(parameter.getName()).getAnnotations(), 
annotation)) {
+            
action.getParameter(parameter.getName()).getAnnotations().add(annotation);
+          }
+        }
+      }
+    }
+  }
+
+  /** Adds annotations to parameters of action
+   * @param action
+   * @param annotationGrp
+   */
+  private void addAnnotationsToActions(CsdlAction action, CsdlAnnotations 
annotationGrp) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+      if (!compareAnnotations(action.getAnnotations(), annotation)) {
+        action.getAnnotations().add(annotation);
+      }
+    }
+  }
+  
   /**
    * @param bindingParameterTypeName
    * @param parameter 
@@ -249,6 +464,7 @@ public class EdmProviderImpl extends AbstractEdm {
               providerParameterNames.add(providerParameters.get(i).getName());
             }
             if (parameterNamesCopy.containsAll(providerParameterNames)) {
+                         addAnnotations(function, functionName);
               return new EdmFunctionImpl(this, functionName, function);
             }
           }
@@ -260,6 +476,52 @@ public class EdmProviderImpl extends AbstractEdm {
     }
   }
 
+  public void addAnnotations(CsdlFunction function, FullQualifiedName 
functionName) {
+    for (CsdlSchema schema : termSchemaDefinition) {
+      List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
+      for (CsdlAnnotations annotationGrp : annotationGrps) {
+        if (annotationGrp.getTarget().equalsIgnoreCase(
+            functionName.getFullQualifiedNameAsString())) {
+          addAnnotationsToFunctions(function, annotationGrp);
+        } else {
+          addAnnotationsToParamsOFunctions(function, functionName, 
annotationGrp);
+        }
+      }
+    }
+  }
+
+  /** Adds annotations of function parameters
+   * @param function
+   * @param functionName
+   * @param annotationGrp
+   */
+  private void addAnnotationsToParamsOFunctions(CsdlFunction function, 
FullQualifiedName functionName,
+      CsdlAnnotations annotationGrp) {
+    final List<CsdlParameter> parameters = function.getParameters();
+    for (CsdlParameter parameter : parameters) {
+      if (annotationGrp.getTarget().equalsIgnoreCase(
+          functionName.getFullQualifiedNameAsString() + "/" + 
parameter.getName())) {
+        for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+          if 
(!compareAnnotations(function.getParameter(parameter.getName()).getAnnotations(),
 annotation)) {
+            
function.getParameter(parameter.getName()).getAnnotations().add(annotation);
+          }
+        }
+      }
+    }
+  }
+
+  /**Add annotations to functions
+   * @param function
+   * @param annotationGrp
+   */
+  private void addAnnotationsToFunctions(CsdlFunction function, 
CsdlAnnotations annotationGrp) {
+    for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
+      if (!compareAnnotations(function.getAnnotations(), annotation)) {
+        function.getAnnotations().add(annotation);
+      }
+    }
+  }
+  
   @Override
   protected Map<String, String> createAliasToNamespaceInfo() {
     final Map<String, String> aliasToNamespaceInfos = new HashMap<String, 
String>();
@@ -375,6 +637,10 @@ public class EdmProviderImpl extends AbstractEdm {
           providerSchemas.put(schema.getNamespace(), new EdmSchemaImpl(this, 
provider, schema));
         }
       }
+         for (CsdlSchema termSchemaDefn : termSchemaDefinition) {
+        providerSchemas.put(termSchemaDefn.getNamespace(), 
+            new EdmSchemaImpl(this, provider, termSchemaDefn));
+      }
       return providerSchemas;
     } catch (ODataException e) {
       throw new EdmException(e);
@@ -387,9 +653,11 @@ public class EdmProviderImpl extends AbstractEdm {
       CsdlTerm providerTerm = provider.getTerm(termName);
       if (providerTerm != null) {
         return new EdmTermImpl(this, termName.getNamespace(), providerTerm);
-      } else if (termSchemaDefinition != null && 
!termSchemaDefinition.isEmpty()) {
+      } else {
           for (CsdlSchema schema : termSchemaDefinition) {
-              if 
(schema.getNamespace().equalsIgnoreCase(termName.getNamespace())) {
+              if 
(schema.getNamespace().equalsIgnoreCase(termName.getNamespace()) ||
+                  (null != schema.getAlias() && 
+                  
schema.getAlias().equalsIgnoreCase(termName.getNamespace()))) {
                 List<CsdlTerm> terms = schema.getTerms();
                 for (CsdlTerm term : terms) {
                   if (term.getName().equals(termName.getName())) {
@@ -417,4 +685,17 @@ public class EdmProviderImpl extends AbstractEdm {
       throw new EdmException(e);
     }
   }
+  
+  public List<CsdlSchema> getTermSchemaDefinitions() {
+    return termSchemaDefinition;
+  }
+  
+  private boolean compareAnnotations(List<CsdlAnnotation> annotations, 
CsdlAnnotation annotation) {
+    for (CsdlAnnotation annot : annotations) {
+      if (annot.equals(annotation)) {
+        return true;
+      }
+    }
+    return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
index 75e0bff..b196b84 100644
--- 
a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
+++ 
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
@@ -41,6 +41,7 @@ public class EdmTypeInfo {
 
     private String typeExpression;
     private Edm edm;
+       private boolean includeAnnotations;
 
     public Builder setTypeExpression(final String typeExpression) {
       this.typeExpression = typeExpression;
@@ -52,8 +53,13 @@ public class EdmTypeInfo {
       return this;
     }
 
+       public Builder setIncludeAnnotations(final boolean includeAnnotations) {
+      this.includeAnnotations = includeAnnotations;
+      return this;
+    }
+       
     public EdmTypeInfo build() {
-      return new EdmTypeInfo(edm, typeExpression);
+      return new EdmTypeInfo(edm, typeExpression, includeAnnotations);
     }
   }
 
@@ -65,7 +71,7 @@ public class EdmTypeInfo {
   private EdmComplexType complexType;
   private EdmEntityType entityType;
 
-  private EdmTypeInfo(final Edm edm, final String typeExpression) {
+  private EdmTypeInfo(final Edm edm, final String typeExpression, final 
boolean includeAnnotations) {
     String baseType;
     final int collStartIdx = typeExpression.indexOf("Collection(");
     final int collEndIdx = typeExpression.lastIndexOf(')');
@@ -113,7 +119,12 @@ public class EdmTypeInfo {
       if (typeDefinition == null) {
         enumType = edm.getEnumType(fullQualifiedName);
         if (enumType == null) {
-          complexType = edm.getComplexType(fullQualifiedName);
+          if (includeAnnotations) {
+            complexType = ((AbstractEdm)edm).
+                getComplexTypeWithAnnotations(fullQualifiedName, true);
+          } else {
+            complexType = edm.getComplexType(fullQualifiedName);
+          }
           if (complexType == null) {
             entityType = edm.getEntityType(fullQualifiedName);
           }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
 
b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
index f4a4c27..038410b 100644
--- 
a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
+++ 
b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java
@@ -319,4 +319,45 @@ public class EdmImplCallCreateTest {
       return null;
     }
   }
+  @Test
+  public void callCreateComplexTypeWithAnnotations() {
+    EdmComplexType complexType = edm.getComplexTypeWithAnnotations(FQN);
+    assertNotNull(complexType);
+    assertEquals(FQN.getNamespace(), complexType.getNamespace());
+    assertEquals(FQN.getName(), complexType.getName());
+
+    assertNull(edm.getComplexType(WRONG_FQN));
+  }
+  
+  @Test
+  public void callCreateComplexTypeWithAnnotationsDerivedFromES() {
+    EdmComplexType complexType = ((AbstractEdm)edm).
+        getComplexTypeWithAnnotations(FQN, true);
+    assertNotNull(complexType);
+    assertEquals(FQN.getNamespace(), complexType.getNamespace());
+    assertEquals(FQN.getName(), complexType.getName());
+
+    assertNull(edm.getComplexType(WRONG_FQN));
+  }
+  
+  @Test
+  public void callCreateEntityTypeWithAnnotation() {
+    EdmEntityType entityType = edm.getEntityTypeWithAnnotations(FQN);
+    assertNotNull(entityType);
+    assertEquals(FQN.getNamespace(), entityType.getNamespace());
+    assertEquals(FQN.getName(), entityType.getName());
+
+    assertNull(edm.getEntityType(WRONG_FQN));
+  }
+  
+  @Test
+  public void callCreateEntityTypeWithAnnotationDerivedFromES() {
+    EdmEntityType entityType = ((AbstractEdm)edm).
+        getEntityTypeWithAnnotations(FQN, true);
+    assertNotNull(entityType);
+    assertEquals(FQN.getNamespace(), entityType.getNamespace());
+    assertEquals(FQN.getName(), entityType.getName());
+
+    assertNull(edm.getEntityType(WRONG_FQN));
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
 
b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
index 2c95ce1..0f29315 100644
--- 
a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
+++ 
b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
@@ -246,7 +246,7 @@ public class EdmSchemaImplTest {
 
     @Override
     public CsdlEntityType getEntityType(final FullQualifiedName 
entityTypeName) throws ODataException {
-      throw new RuntimeException("Provider must not be called in the schema 
case");
+      return null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cbe468c/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java
index d9fbde9..2cfe063 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/apply/DynamicProperty.java
@@ -115,4 +115,9 @@ public class DynamicProperty implements EdmProperty {
   public List<EdmAnnotation> getAnnotations() {
     return Collections.emptyList();
   }
+  
+  @Override
+  public EdmType getTypeWithAnnotations() {
+    return propertyType;
+  }
 }

Reply via email to