org.apache.olingo.commons.api.edm.provider.CsdlSchema Java Examples

The following examples show how to use org.apache.olingo.commons.api.edm.provider.CsdlSchema. 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
CsdlSchema getSchemaRecursively(String ns, Set<String> parsedPath) {
  // find the schema by namespace in current provider
  CsdlSchema schema = getSchemaDirectly(ns);
  if (schema != null) {
    return schema;
  }

  // find the schema by namespace in the reference schema provider
  for (Map.Entry<String, SchemaBasedEdmProvider> entry : this.referenceSchemas.entrySet()) {
    String namespace = entry.getKey();
    if (parsedPath.contains(namespace)) {
      continue;
    }
    SchemaBasedEdmProvider provider = entry.getValue();
    parsedPath.add(namespace);
    schema = provider.getSchemaRecursively(ns, parsedPath);
    if (schema != null) {
      return schema;
    }
  }

  return getVocabularySchema(ns);
}
 
Example #2
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {
  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  schema.setEntityTypes(entityTypes);

  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;

}
 
Example #3
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {
  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  schema.setEntityTypes(entityTypes);

  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;

}
 
Example #4
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {

  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  entityTypes.add(getEntityType(ET_CATEGORY_FQN));
  schema.setEntityTypes(entityTypes);
  
  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #5
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {
  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  entityTypes.add(getEntityType(ET_CATEGORY_FQN));
  schema.setEntityTypes(entityTypes);

  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #6
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {

  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  schema.setEntityTypes(entityTypes);

  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #7
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * @param schema
 */
private void fetchAnnotationsInMetadataAndExternalFile(CsdlSchema schema) {
  List<CsdlAnnotations> annotationGrps = schema.getAnnotationGroups();
  for (CsdlAnnotations annotationGrp : annotationGrps) {
    if (!getAnnotationsMap().containsKey(annotationGrp.getTarget())) {
      getAnnotationsMap().put(annotationGrp.getTarget(), annotationGrp.getAnnotations());
    } else {
      List<CsdlAnnotation> annotations = getAnnotationsMap().get(annotationGrp.getTarget());
      List<CsdlAnnotation> newAnnotations = new ArrayList<CsdlAnnotation>();
      for (CsdlAnnotation annotation : annotationGrp.getAnnotations()) {
        if (!compareAnnotations(annotations, annotation)) {
          newAnnotations.add(annotation);
        }
      }
      if (!newAnnotations.isEmpty()) {
        getAnnotationsMap().get(annotationGrp.getTarget()).addAll(newAnnotations);
      }
    }
  }
}
 
Example #8
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected Map<String, EdmSchema> createSchemas() {
  try {
    final Map<String, EdmSchema> providerSchemas = new LinkedHashMap<>();
    List<CsdlSchema> localSchemas = provider.getSchemas();
    if (localSchemas != null) {
      for (CsdlSchema schema : localSchemas) {
        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);
  }
}
 
Example #9
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected EdmTerm createTerm(final FullQualifiedName termName) {
  try {
    CsdlTerm providerTerm = provider.getTerm(termName);
    if (providerTerm != null) {
      return new EdmTermImpl(this, termName.getNamespace(), providerTerm);
    } else {
        for (CsdlSchema schema : termSchemaDefinition) {
            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())) {
                  return new EdmTermImpl(this, termName.getNamespace(), term);
                }
              }
            }
          }
      }
    return null;
  } catch (ODataException e) {
    throw new EdmException(e);
  }
}
 
Example #10
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {
  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  schema.setEntityTypes(entityTypes);

  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;

}
 
Example #11
Source File: CarsEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() throws ODataException {
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);
  // EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_CAR));
  entityTypes.add(getEntityType(ET_MANUFACTURER));
  schema.setEntityTypes(entityTypes);

  // ComplexTypes
  List<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>();
  complexTypes.add(getComplexType(CT_ADDRESS));
  schema.setComplexTypes(complexTypes);

  // EntityContainer
  schema.setEntityContainer(getEntityContainer());
  schemas.add(schema);

  return schemas;
}
 
Example #12
Source File: EdmProviderImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName targetName, String qualifier) {
  try {
    CsdlAnnotations providerGroup = provider.getAnnotationsGroup(targetName, qualifier);
    if (null == providerGroup) {
      for(CsdlSchema schema : termSchemaDefinition) {
        providerGroup = schema.getAnnotationGroup(targetName.getFullQualifiedNameAsString(), qualifier);
        break;
      }
    }
    if (providerGroup != null) {
      return new EdmAnnotationsImpl(this, providerGroup);
    }
    return null;
  } catch (ODataException e) {
    throw new EdmException(e);
  }
}
 
Example #13
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {

  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  entityTypes.add(getEntityType(ET_CATEGORY_FQN));
  schema.setEntityTypes(entityTypes);
  
  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #14
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlFunction> getFunctions(FullQualifiedName fqn) throws ODataException {
  ArrayList<CsdlFunction> foundFuncs = new ArrayList<>();
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    List<CsdlFunction> functions = schema.getFunctions();
    if (functions != null) {
      for (CsdlFunction func : functions) {
        if (func.getName().equals(fqn.getName())) {
          foundFuncs.add(func);
        }
      }
    }
  }
  return foundFuncs;
}
 
Example #15
Source File: MetadataParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void readEntityType(XMLEventReader reader, StartElement element, CsdlSchema schema)
    throws XMLStreamException {
  CsdlEntityType entityType = new CsdlEntityType();
  entityType.setProperties(new ArrayList<CsdlProperty>());
  entityType.setNavigationProperties(new ArrayList<CsdlNavigationProperty>());
  entityType.setKey(new ArrayList<CsdlPropertyRef>());
  entityType.setName(attr(element, "Name"));
  if (attr(element, "BaseType") != null) {
    entityType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
  }
  entityType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
  entityType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
  entityType.setHasStream(Boolean.parseBoolean(attr(element, "HasStream")));
  readEntityProperties(reader, entityType);
  schema.getEntityTypes().add(entityType);
}
 
Example #16
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 #17
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 #18
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {

  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  schema.setEntityTypes(entityTypes);

  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #19
Source File: EdmSchemaImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public EdmSchemaImpl(final EdmProviderImpl edm, final CsdlEdmProvider provider, final CsdlSchema schema) {
  super(edm, schema);
  this.edm = edm;
  this.provider = provider;
  this.schema = schema;
  namespace = schema.getNamespace();
  alias = schema.getAlias();

  if (alias != null) {
    edm.cacheAliasNamespaceInfo(alias, namespace);
  }

  enumTypes = createEnumTypes();
  typeDefinitions = createTypeDefinitions();
  entityTypes = createEntityTypes();
  complexTypes = createComplexTypes();
  actions = createActions();
  functions = createFunctions();
  entityContainer = createEntityContainer();
  annotationGroups = createAnnotationGroups();
  annotations = createAnnotations();
  terms = createTerms();
}
 
Example #20
Source File: ClientCsdlEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlSingleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
    throws ODataException {
  CsdlSchema schema = xmlSchemas.get(entityContainer.getNamespace());
  if (schema != null) {
    return schema.getEntityContainer().getSingleton(singletonName);
  }
  return null;
}
 
Example #21
Source File: DemoEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public List<CsdlSchema> getSchemas() {

  // create Schema
  CsdlSchema schema = new CsdlSchema();
  schema.setNamespace(NAMESPACE);

  // add EntityTypes
  List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
  entityTypes.add(getEntityType(ET_PRODUCT_FQN));
  entityTypes.add(getEntityType(ET_CATEGORY_FQN));
  schema.setEntityTypes(entityTypes);
  
  // add actions
  List<CsdlAction> actions = new ArrayList<CsdlAction>();
  actions.addAll(getActions(ACTION_RESET_FQN));
  schema.setActions(actions);
  
  // add functions
  List<CsdlFunction> functions = new ArrayList<CsdlFunction>();
  functions.addAll(getFunctions(FUNCTION_COUNT_CATEGORIES_FQN));
  schema.setFunctions(functions);
  
  // add EntityContainer
  schema.setEntityContainer(getEntityContainer());

  // finally
  List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
  schemas.add(schema);

  return schemas;
}
 
Example #22
Source File: ClientCsdlEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
    throws ODataException {
  CsdlSchema schema = xmlSchemas.get(entityContainer.getNamespace());
  if (schema != null) {
    return schema.getEntityContainer().getActionImport(actionImportName);
  }
  return null;
}
 
Example #23
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 #24
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 #25
Source File: ClientCsdlEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlFunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
    throws ODataException {
  CsdlSchema schema = xmlSchemas.get(entityContainer.getNamespace());
  if (schema != null) {
    return schema.getEntityContainer().getFunctionImport(functionImportName);
  }
  return null;
}
 
Example #26
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlTypeDefinition getTypeDefinition(FullQualifiedName fqn) throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    List<CsdlTypeDefinition> types = schema.getTypeDefinitions();
    if (types != null) {
      for (CsdlTypeDefinition type : types) {
        if (type.getName().equals(fqn.getName())) {
          return type;
        }
      }
    }
  }
  return null;
}
 
Example #27
Source File: ClientCsdlEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlAnnotations getAnnotationsGroup(FullQualifiedName targetName, String qualifier) throws ODataException {
  CsdlSchema schema = xmlSchemas.get(targetName.getNamespace());
  if (schema != null) {
    return schema.getAnnotationGroup(targetName.getFullQualifiedNameAsString(), qualifier);
  }
  return null;
}
 
Example #28
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlEnumType getEnumType(FullQualifiedName fqn) throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    List<CsdlEnumType> types = schema.getEnumTypes();
    if (types != null) {
      for (CsdlEnumType type : types) {
        if (type.getName().equals(fqn.getName())) {
          return type;
        }
      }
    }
  }
  return null;
}
 
Example #29
Source File: SchemaBasedEdmProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public CsdlTerm getTerm(FullQualifiedName fqn) throws ODataException {
  CsdlSchema schema = getSchema(fqn.getNamespace());
  if (schema != null) {
    List<CsdlTerm> terms = schema.getTerms();
    if (terms != null) {
      for (CsdlTerm term : terms) {
        if (term.getName().equals(fqn.getName())) {
          return term;
        }
      }
    }
  }
  return null;
}
 
Example #30
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;
}