Java Code Examples for org.apache.olingo.commons.api.edm.provider.CsdlSchema#getEntityContainer()

The following examples show how to use org.apache.olingo.commons.api.edm.provider.CsdlSchema#getEntityContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlActionImport getActionImport(FullQualifiedName fqn, String actionImportName)
    throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    CsdlEntityContainer ec = schema.getEntityContainer();
    if (ec != null && ec.getActionImports() != null) {
      for (CsdlActionImport es : ec.getActionImports()) {
        if (es.getName().equals(actionImportName)) {
          return es;
        }
      }
    }
  }
  return null;
}
 
Example 2
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public CsdlFunctionImport getFunctionImport(FullQualifiedName fqn, String functionImportName)
    throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    CsdlEntityContainer ec = schema.getEntityContainer();
    if (ec != null && ec.getFunctionImports() != null) {
      for (CsdlFunctionImport es : ec.getFunctionImports()) {
        if (es.getName().equals(functionImportName)) {
          return es;
        }
      }
    }
  }
  return null;
}
 
Example 3
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleSchemas() {
  final XMLMetadata metadata = client.getDeserializer(ContentType.APPLICATION_XML).
      toMetadata(getClass().getResourceAsStream("northwind-metadata.xml"));
  assertNotNull(metadata);

  final CsdlSchema first = metadata.getSchema("NorthwindModel");
  assertNotNull(first);

  final CsdlSchema second = metadata.getSchema("ODataWebExperimental.Northwind.Model");
  assertNotNull(second);

  final CsdlEntityContainer entityContainer = second.getEntityContainer();
  assertNotNull(entityContainer);
  assertEquals("NorthwindEntities", entityContainer.getName());
}
 
Example 4
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntitySet getEntitySet(FullQualifiedName fqn, String entitySetName) throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    CsdlEntityContainer ec = schema.getEntityContainer();
    if (ec != null && ec.getEntitySets() != null) {
      for (CsdlEntitySet es : ec.getEntitySets()) {
        if (es.getName().equals(entitySetName)) {
          return es;
        }
      }
    }
  }
  return null;
}
 
Example 5
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlSingleton getSingleton(FullQualifiedName fqn, String singletonName) throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    CsdlEntityContainer ec = schema.getEntityContainer();
    if (ec != null && ec.getSingletons() != null) {
      for (CsdlSingleton es : ec.getSingletons()) {
        if (es.getName().equals(singletonName)) {
          return es;
        }
      }
    }
  }
  return null;
}
 
Example 6
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityContainerInfo getEntityContainerInfo(FullQualifiedName fqn) throws ODataException {
  CsdlSchema schema = null;

  if (fqn == null) {
    for (CsdlSchema s : this.edmSchemas) {
      if (s.getEntityContainer() != null) {
        schema = s;
        break;
      }
    }
  } else {
    schema = getSchema(fqn.getNamespace());
  }

  if (schema != null) {
    CsdlEntityContainer ec = schema.getEntityContainer();
    if (ec != null) {
      CsdlEntityContainerInfo info = new CsdlEntityContainerInfo();
      info.setContainerName(new FullQualifiedName(schema.getNamespace(), ec.getName()));
      if (schema.getEntityContainer().getExtendsContainer() != null) {
        info.setExtendsContainer(new FullQualifiedName(schema.getEntityContainer().getExtendsContainer()));
      }
      return info;
    }
  }
  return null;
}
 
Example 7
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityContainer getEntityContainer() throws ODataException {
  // note that there can be many schemas, but only one needs to contain the
  // entity container in a given metadata document.
  for (CsdlSchema s : this.edmSchemas) {
    if (s.getEntityContainer() != null) {
      return s.getEntityContainer();
    }
  }
  return null;
}
 
Example 8
Source File: ClientCsdlEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEntityContainer getEntityContainer() throws ODataException {
  for (CsdlSchema schema : xmlSchemas.values()) {
    if (schema.getEntityContainer() != null) {
      return schema.getEntityContainer();
    }
  }
  return null;
}
 
Example 9
Source File: CsdlTypeValidator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
  * This checks if XMLMetadata is a service document.
  * @param xmlMetadata
  * @return boolean
  */
 public boolean isServiceDocument(XMLMetadata xmlMetadata){
boolean isServDoc = false;
List<CsdlSchema> schemas = xmlMetadata.getSchemas();
for (CsdlSchema schema : schemas) {
	// for metadata to be a service document it should have an entity
	// container
	if (schema.getEntityContainer() != null) {
		isServDoc = true;
		break;
	}
}
return isServDoc;  
 }
 
Example 10
Source File: ODataMetadataValidationImpl.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public void validateMetadata(XMLMetadata xmlMetadata) {
  Map<FullQualifiedName, CsdlEntityType> csdlEntityTypesMap = new HashMap<>();
  Map<FullQualifiedName, CsdlComplexType> csdlComplexTypesMap = new HashMap<>();
  Map<FullQualifiedName, CsdlAction> csdlActionsMap = new HashMap<>();
  Map<FullQualifiedName, CsdlFunction> csdlFunctionsMap = new HashMap<>();
  Map<FullQualifiedName, CsdlEntityContainer> csdlContainersMap = 
      new HashMap<>();
  Map<String, String> aliasNamespaceMap = new HashMap<>();
  List<CsdlSchema> csdlSchemas = xmlMetadata.getSchemas();
  for (CsdlSchema csdlSchema : csdlSchemas) {
    List<CsdlEntityType> csdlEntityTypes = csdlSchema.getEntityTypes();
    for (CsdlEntityType csdlEntityType : csdlEntityTypes) {
      csdlEntityTypesMap.put(new FullQualifiedName(
          csdlSchema.getNamespace(), csdlEntityType.getName()), csdlEntityType);
    }
    List<CsdlComplexType> csdlComplexTypes = csdlSchema.getComplexTypes();
    for (CsdlComplexType csdlComplexType : csdlComplexTypes) {
      csdlComplexTypesMap.put(new FullQualifiedName(
          csdlSchema.getNamespace(), csdlComplexType.getName()), csdlComplexType);
    }
    List<CsdlAction> csdlActions = csdlSchema.getActions();
    for (CsdlAction csdlAction : csdlActions) {
      csdlActionsMap.put(new FullQualifiedName(
          csdlSchema.getNamespace(), csdlAction.getName()), csdlAction);
    }
    List<CsdlFunction> csdlFunctions = csdlSchema.getFunctions();
    for (CsdlFunction csdlFunction : csdlFunctions) {
      csdlFunctionsMap.put(
          new FullQualifiedName(csdlSchema.getNamespace(), csdlFunction.getName()), csdlFunction);
    }
    aliasNamespaceMap.put(csdlSchema.getAlias(), csdlSchema.getNamespace());
    if (csdlSchema.getEntityContainer() != null) {
      csdlContainersMap.put(new FullQualifiedName(
          csdlSchema.getNamespace(), csdlSchema.getEntityContainer().getName()), csdlSchema.getEntityContainer());
    }
  }
  CsdlTypeValidator csdlTypeValidator = new CsdlTypeValidator(aliasNamespaceMap, csdlContainersMap, 
      csdlEntityTypesMap, csdlComplexTypesMap, csdlActionsMap, csdlFunctionsMap);
  csdlTypeValidator.validateMetadataXML();
}