Java Code Examples for org.apache.olingo.odata2.api.edm.Edm#DELIMITER

The following examples show how to use org.apache.olingo.odata2.api.edm.Edm#DELIMITER . 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: EdmComplexPropertyImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  try {
    return edmType.getNamespace()+ Edm.DELIMITER +  edmType.getName();
  } catch (EdmException e) { //NOPMD  - suppressed
    return null; //NOSONAR
  }
}
 
Example 2
Source File: XmlPropertyEntityProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a simple-property value to the XML stream.
 * @param writer the XML stream writer
 * @param prop property informations
 * @param value the value of the property
 * @throws XMLStreamException
 * @throws EdmException
 * @throws EntityProviderProducerException 
 */
private void appendProperty(final XMLStreamWriter writer, final EntityPropertyInfo prop, final Object value)
    throws XMLStreamException, EdmException, EntityProviderProducerException {
  Object contentValue = value;
  String mimeType = null;
  if (prop.getMimeType() != null) {
    mimeType = prop.getMimeType();
  } else if (prop.getMapping() != null && prop.getMapping().getMediaResourceMimeTypeKey() != null) {
    mimeType = (String) extractChildValue(value, prop.getMapping().getMediaResourceMimeTypeKey());
    contentValue = extractChildValue(value, prop.getName());
  }

  if (mimeType != null) {
    writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.M_MIME_TYPE, mimeType);
  }

  final EdmSimpleType type = (EdmSimpleType) prop.getType();
  if (includeSimplePropertyType) {
    String fqnTypeName = type.getNamespace() + Edm.DELIMITER + type.getName();
    writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.ATOM_TYPE, fqnTypeName);
  }

  final EdmFacets facets = validateFacets ? prop.getFacets() : null;
  String valueAsString = null;
  try {
    valueAsString = type.valueToString(contentValue, EdmLiteralKind.DEFAULT, facets);
  } catch (EdmSimpleTypeException e) {
      throw new EntityProviderProducerException(EdmSimpleTypeException.getMessageReference(
          e.getMessageReference()).updateContent(
              e.getMessageReference().getContent(), prop.getName()), e);
  }
  if (valueAsString == null) {
    writer.writeAttribute(Edm.NAMESPACE_M_2007_08, FormatXml.ATOM_NULL, FormatXml.ATOM_VALUE_TRUE);
  } else {
    writer.writeCharacters(valueAsString);
  }
}
 
Example 3
Source File: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
protected static String createETag(final EntityInfoAggregator eia, final Map<String, Object> data)
    throws EntityProviderException {
  String propertyName = "";
  try {
    String etag = null;

    Collection<EntityPropertyInfo> propertyInfos = eia.getETagPropertyInfos();
    for (EntityPropertyInfo propertyInfo : propertyInfos) {
      propertyName = propertyInfo.getName();
      EdmType edmType = propertyInfo.getType();
      if (edmType instanceof EdmSimpleType) {
        EdmSimpleType edmSimpleType = (EdmSimpleType) edmType;
        if (etag == null) {
          etag =
              edmSimpleType.valueToString(data.get(propertyInfo.getName()), EdmLiteralKind.DEFAULT, propertyInfo
                  .getFacets());
        } else {
          etag =
              etag
                  + Edm.DELIMITER
                  + edmSimpleType.valueToString(data.get(propertyInfo.getName()), EdmLiteralKind.DEFAULT,
                      propertyInfo.getFacets());
        }
      }
    }

    if (etag != null) {
      etag = "W/\"" + etag + "\"";
    }

    return etag;
  } catch (EdmSimpleTypeException e) {
    throw new EntityProviderProducerException(EdmSimpleTypeException.getMessageReference(
        e.getMessageReference()).updateContent(e.getMessageReference().getContent(), propertyName), e);
  }
}
 
Example 4
Source File: EdmStructuralTypeImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  try {
    return namespace + Edm.DELIMITER + getName();
  } catch (final EdmException e) {
    return null;
  }
}
 
Example 5
Source File: AbstractSimpleType.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  try {
    return getNamespace() + Edm.DELIMITER + getName();
  } catch (final EdmException e) {
    return super.toString();
  }
}
 
Example 6
Source File: JsonVisitor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static String getType(final CommonExpression expression) {
  try {
    final EdmType type = expression.getEdmType();
    return type == null ? null : type.getNamespace() + Edm.DELIMITER + type.getName();
  } catch (final EdmException e) {
    return "EdmException occurred: " + e.getMessage();
  }
}
 
Example 7
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  String eTag = null;
  for (final String propertyName : entityType.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
    if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      final EdmSimpleType type = (EdmSimpleType) property.getType();
      final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
          EdmLiteralKind.DEFAULT, property.getFacets());
      eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
    }
  }
  return eTag == null ? null : "W/\"" + eTag + "\"";
}
 
Example 8
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  String eTag = null;
  for (final String propertyName : entityType.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
    if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      final EdmSimpleType type = (EdmSimpleType) property.getType();
      final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
          EdmLiteralKind.DEFAULT, property.getFacets());
      eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
    }
  }
  return eTag == null ? null : "W/\"" + eTag + "\"";
}
 
Example 9
Source File: EdmStructuralTypeImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  try {
    return namespace + Edm.DELIMITER + getName();
  } catch (final EdmException e) {
    return null; //NOSONAR
  }
}
 
Example 10
Source File: XmlPropertyDeserializer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected Object readStartedElement(XMLStreamReader reader, final String name, //NOSONAR
    final EntityPropertyInfo propertyInfo, 
    final EntityTypeMapping typeMappings, final DeserializerProperties readProperties)
    throws EntityProviderException, EdmException { 
  Object result = null;

  try {
    reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_D_2007_08, name);
    final String nullAttribute = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, FormatXml.M_NULL);

    if (!(nullAttribute == null || TRUE.equals(nullAttribute) || FALSE.equals(nullAttribute))) {
      throw new EntityProviderException(EntityProviderException.COMMON);
    }

    if (TRUE.equals(nullAttribute)) {
      if ((readProperties == null || readProperties.isValidatingFacets()) && propertyInfo.isMandatory()) {
        throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE.addContent(name));
      }
      reader.nextTag();
    } else if (propertyInfo.isComplex()) {
      final String typeAttribute = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, FormatXml.M_TYPE);
      if (typeAttribute != null) {
        final String expectedTypeAttributeValue =
            propertyInfo.getType().getNamespace() + Edm.DELIMITER + propertyInfo.getType().getName();
        if (!expectedTypeAttributeValue.equals(typeAttribute)) { //NOSONAR
          throw new EntityProviderException(EntityProviderException.INVALID_COMPLEX_TYPE.addContent(
              expectedTypeAttributeValue).addContent(typeAttribute));
        }
      }

      reader.nextTag();
      Map<String, Object> name2Value = new HashMap<String, Object>();
      while (reader.hasNext() && !reader.isEndElement()) {
        final String childName = reader.getLocalName();
        final EntityPropertyInfo childProperty =
            ((EntityComplexPropertyInfo) propertyInfo).getPropertyInfo(childName);
        if (childProperty == null) { //NOSONAR
          throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY.addContent(childName));
        }
        final Object value = readStartedElement(reader, childName, childProperty,
            typeMappings.getEntityTypeMapping(name), readProperties);
        name2Value.put(childName, value);
        reader.nextTag();
      }
      result = name2Value;
    } else {
      result = convert(propertyInfo, reader.getElementText(), typeMappings.getMappingClass(name), readProperties);
    }
    reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_D_2007_08, name);

    return result;
  } catch (XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
        .getSimpleName()), e);
  }
}
 
Example 11
Source File: EdmUsingImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return namespace + Edm.DELIMITER + alias;
}
 
Example 12
Source File: EdmAnnotationElementImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return namespace + Edm.DELIMITER + name;
}
 
Example 13
Source File: EdmAssociationImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return namespace + Edm.DELIMITER + name;
}
 
Example 14
Source File: EdmTypedImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return typeName.getNamespace() + Edm.DELIMITER + typeName.getName();
}
 
Example 15
Source File: EdmAssociationSetImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return associationSetFQName.getNamespace() + Edm.DELIMITER + associationSetFQName.getName();
}
 
Example 16
Source File: JsonEntryDeserializer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @throws IOException
 * @throws EdmException
 * @throws EntityProviderException
 */
private void readMetadata() throws IOException, EdmException, EntityProviderException {//NOSONAR
  String name = null;
  String value = null;
  reader.beginObject();
  while (reader.hasNext()) {
    name = reader.nextName();

    if (FormatJson.PROPERTIES.equals(name)) {
      reader.skipValue();
      continue;
    }

    value = reader.nextString();
    if (FormatJson.ID.equals(name)) {
      entryMetadata.setId(value);
    } else if (FormatJson.URI.equals(name)) {
      entryMetadata.setUri(value);
    } else if (FormatJson.TYPE.equals(name)) {
      String fullQualifiedName = eia.getEntityType().getNamespace() + Edm.DELIMITER + eia.getEntityType().getName();
      if (!fullQualifiedName.equals(value)) {
        throw new EntityProviderException(EntityProviderException.INVALID_ENTITYTYPE.addContent(fullQualifiedName)
            .addContent(value));
      }
    } else if (FormatJson.ETAG.equals(name)) {
      entryMetadata.setEtag(value);
    } else if (FormatJson.EDIT_MEDIA.equals(name)) {
      mediaMetadata.setEditLink(value);
    } else if (FormatJson.MEDIA_SRC.equals(name)) {
      mediaMetadata.setSourceLink(value);
    } else if (FormatJson.MEDIA_ETAG.equals(name)) {
      mediaMetadata.setEtag(value);
    } else if (FormatJson.CONTENT_TYPE.equals(name)) {
      mediaMetadata.setContentType(value);
    } else {
      throw new EntityProviderException(EntityProviderException.INVALID_CONTENT.addContent(name).addContent(
          FormatJson.METADATA));
    }
  }

  reader.endObject();
}
 
Example 17
Source File: XmlPropertyConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected Object readStartedElement(XMLStreamReader reader, final String name, final EntityPropertyInfo propertyInfo,
    final EntityTypeMapping typeMappings, final EntityProviderReadProperties readProperties)
    throws EntityProviderException, EdmException {
  Object result = null;

  try {
    reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_D_2007_08, name);
    final String nullAttribute = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, FormatXml.M_NULL);

    if (!(nullAttribute == null || TRUE.equals(nullAttribute) || FALSE.equals(nullAttribute))) {
      throw new EntityProviderException(EntityProviderException.COMMON);
    }

    if (TRUE.equals(nullAttribute)) {
      if ((readProperties == null || readProperties.isValidatingFacets()) && propertyInfo.isMandatory()) {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_NULL_NOT_ALLOWED.addContent(name));
      }
      reader.nextTag();
    } else if (propertyInfo.isComplex()) {
      final String typeAttribute = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, FormatXml.M_TYPE);
      if (typeAttribute != null) {
        final String expectedTypeAttributeValue =
            propertyInfo.getType().getNamespace() + Edm.DELIMITER + propertyInfo.getType().getName();
        if (!expectedTypeAttributeValue.equals(typeAttribute)) {
          throw new EntityProviderException(EntityProviderException.INVALID_COMPLEX_TYPE.addContent(
              expectedTypeAttributeValue).addContent(typeAttribute));
        }
      }

      reader.nextTag();
      Map<String, Object> name2Value = new HashMap<String, Object>();
      while (reader.hasNext() && !reader.isEndElement()) {
        final String childName = reader.getLocalName();
        final EntityPropertyInfo childProperty =
            ((EntityComplexPropertyInfo) propertyInfo).getPropertyInfo(childName);
        if (childProperty == null) {
          throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY.addContent(childName));
        }
        final Object value = readStartedElement(reader, childName, childProperty,
            typeMappings.getEntityTypeMapping(name), readProperties);
        name2Value.put(childName, value);
        reader.nextTag();
      }
      result = name2Value;
    } else {
      result = convert(propertyInfo, reader.getElementText(), typeMappings.getMappingClass(name), readProperties);
    }
    reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_D_2007_08, name);

    return result;
  } catch (XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
        .getSimpleName()), e);
  }
}
 
Example 18
Source File: JsonEntryConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void readMetadata() throws IOException, EdmException, EntityProviderException {
  String name = null;
  String value = null;
  reader.beginObject();
  while (reader.hasNext()) {
    name = reader.nextName();

    if (FormatJson.PROPERTIES.equals(name)) {
      reader.skipValue();
      continue;
    }

    value = reader.nextString();
    if (FormatJson.ID.equals(name)) {
      entryMetadata.setId(value);
    } else if (FormatJson.URI.equals(name)) {
      entryMetadata.setUri(value);
    } else if (FormatJson.TYPE.equals(name)) {
      String fullQualifiedName = eia.getEntityType().getNamespace() + Edm.DELIMITER + eia.getEntityType().getName();
      if (!fullQualifiedName.equals(value)) {
        throw new EntityProviderException(EntityProviderException.INVALID_ENTITYTYPE.addContent(fullQualifiedName)
            .addContent(value));
      }
    } else if (FormatJson.ETAG.equals(name)) {
      entryMetadata.setEtag(value);
    } else if (FormatJson.EDIT_MEDIA.equals(name)) {
      mediaMetadata.setEditLink(value);
    } else if (FormatJson.MEDIA_SRC.equals(name)) {
      mediaMetadata.setSourceLink(value);
    } else if (FormatJson.MEDIA_ETAG.equals(name)) {
      mediaMetadata.setEtag(value);
    } else if (FormatJson.CONTENT_TYPE.equals(name)) {
      mediaMetadata.setContentType(value);
    } else {
      throw new EntityProviderException(EntityProviderException.INVALID_CONTENT.addContent(name).addContent(
          FormatJson.METADATA));
    }
  }

  reader.endObject();
}
 
Example 19
Source File: EdmAnnotationAttributeImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return namespace + Edm.DELIMITER + name;
}
 
Example 20
Source File: XmlPropertyEntitySerializer.java    From olingo-odata2 with Apache License 2.0 2 votes vote down vote up
/**
 * Returns full qualified name of a type of a given PropertyInfo.
 * @return Full qualified name
 */
private String getFqnTypeName(final EntityComplexPropertyInfo propertyInfo) throws EdmException {
  return propertyInfo.getType().getNamespace() + Edm.DELIMITER + propertyInfo.getType().getName();
}