Package com.linkedin.data.schema

Examples of com.linkedin.data.schema.DataSchema


  }

  @Override
  public boolean evaluate(DataElement element)
  {
    DataSchema schema = element.getSchema();
    return (schema != null && schema instanceof NamedDataSchema && ((NamedDataSchema) schema).getFullName().equals(_name));
  }
View Full Code Here


    }
    else
    {
      key = _map.keySet().iterator().next();
    }
    DataSchema memberType = _schema.getType(key);
    if (memberType == null)
    {
      throw new TemplateOutputCastException(key + " is not a member of " + _schema);
    }
    return memberType;
View Full Code Here

   */
  protected <T> void selectDirect(DataSchema memberSchema, Class<T> memberClass, Class<?> dataClass, String key, T value)
      throws ClassCastException, NullUnionUnsupportedOperationException
  {
    checkNotNull();
    DataSchema memberType = _schema.getType(key);
    assert(memberType != null); // something is wrong with the generated code if this occurs.
    Object object = DataTemplateUtil.coerceInput(value, memberClass, dataClass);
    _map.clear();
    _map.put(key, object);
  }
View Full Code Here

   */
  protected <T extends DataTemplate<?>> void selectWrapped(DataSchema memberSchema, Class<T> memberClass, String key, T value)
      throws ClassCastException, NullUnionUnsupportedOperationException
  {
    checkNotNull();
    DataSchema memberType = _schema.getType(key);
    assert(memberType != null); // something is wrong with the generated code if this occurs.
    if (value.getClass() != memberClass)
    {
      throw new ClassCastException("Input " + value + " should be a " + memberClass.getName());
    }
View Full Code Here

   * @param type to get a schema for. Has to be primitive or a generated data template.
   * @throws TemplateRuntimeException if the {@link DataSchema} for the specified type cannot be provided.
   */
  public static DataSchema getSchema(Class<?> type) throws TemplateRuntimeException
  {
    final DataSchema primitiveSchema = DataSchemaUtil.classToPrimitiveDataSchema(type);
    if (primitiveSchema != null)
    {
      return primitiveSchema;
    }

    try
    {
      Field schemaField = type.getDeclaredField(SCHEMA_FIELD_NAME);
      schemaField.setAccessible(true);
      DataSchema schema = (DataSchema) schemaField.get(null);
      if (schema == null)
      {
        throw new TemplateRuntimeException("Class missing schema: " + type.getName());
      }

View Full Code Here

   * Gets the data schema name for a given java type.
   * @param type to get a schema for. Has to be a named data type.
   */
  public static String getSchemaName(Class<?> type)
  {
    DataSchema schema = getSchema(type);
    if (! (schema instanceof NamedDataSchema))
    {
      throw new TemplateRuntimeException("Class' schema is unnamed: " + type.getName());
    }

View Full Code Here

    try
    {
      assertTrue(Enum.class.isAssignableFrom(enumClass));

      // has embedded EnumDataSchema
      DataSchema schema = DataTemplateUtil.getSchema(enumClass);
      assertNotNull(schema);
      assertTrue(schema instanceof EnumDataSchema);

      // get symbols
      EnumDataSchema enumSchema = (EnumDataSchema) schema;
View Full Code Here

  @Test
  public void testCustomAnyRecordSchema()
  {
    RecordDataSchema schemaFromInstance = (new AnyRecord()).schema();
    DataSchema schemaFromClass = DataTemplateUtil.getSchema(AnyRecord.class);
    assertSame(schemaFromClass, schemaFromInstance);

    CustomAnyRecord custom = new CustomAnyRecord();
    RecordDataSchema customSchemaFromInstance = custom.schema();
    DataSchema customSchemaFromClass = DataTemplateUtil.getSchema(CustomAnyRecord.class);
    assertSame(customSchemaFromClass, customSchemaFromInstance);

    assertEquals(customSchemaFromClass, schemaFromClass);
  }
View Full Code Here

  private ValidationResult validateEntity(ByteString entity,
                                          Class<? extends RecordTemplate> recordClass,
                                          ValidationOptions options) throws IOException
  {
    final DataMap respData = _codec.bytesToMap(entity.copyBytes());
    final DataSchema recordSchema = DataTemplateUtil.getSchema(recordClass);
    return ValidateDataAgainstSchema.validate(respData, recordSchema, options);
  }
View Full Code Here

                                              ValidationOptions options)
      throws IOException
  {
    final DataMap respData = _codec.bytesToMap(response.getEntity().copyBytes());
    final CollectionResponse<T> collResp = new CollectionResponse<T>(respData, recordClass);
    final DataSchema recordSchema = DataTemplateUtil.getSchema(recordClass);

    for (T record: collResp.getElements())
    {
      final ValidationResult valRet = ValidateDataAgainstSchema.validate(record.data(), recordSchema, options);
      if (!valRet.isValid())
View Full Code Here

TOP

Related Classes of com.linkedin.data.schema.DataSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.