Package org.apache.avro

Examples of org.apache.avro.Schema$Parser


    this.path = path;

    documentManager.attachToEditor(document, editor);

    Parser codeMirrorParser = CodeMirror2.getParser(path);
    parser = codeMirrorParser == null ? null
        : DocumentParser.create(document, codeMirrorParser, userActivityManager);

    LanguageHelper languageHelper = LanguageHelperResolver.getHelper(parser.getSyntaxType());
    RootActionExecutor actionExecutor = editor.getInput().getActionExecutor();
View Full Code Here


      parser.teardown();
      parser = null;
    }


    Parser codeMirrorParser = CodeMirror2.getParser(path);
    parser = DocumentParser.create(document, codeMirrorParser, userActivityManager);
    Preconditions.checkNotNull(parser);

    editor.setDocument(document);
    editor.addLineRenderer(diffRenderer);
View Full Code Here

        path, false, new MockIncrementalScheduler(), Document.createEmpty());
  }

  public static DocumentParser createDocumentParser(PathUtil path, boolean setupRealParser,
      IncrementalScheduler scheduler, Document document) {
    Parser parser = setupRealParser ? CodeMirror2.getParser(path)
        : new MockParser(SyntaxType.syntaxTypeByFilePath(path));
    return DocumentParser.create(document, parser, scheduler);
  }
View Full Code Here

    private static Model empty = ModelFactory.createDefaultModel();
   
    @Test public void testEmptyBlankNode()
        {
        Model m = ModelFactory.createDefaultModel();
        Resource r = new Parser( "[]" ).resourceIn( m );
        assertIsoModels( empty, m );
        assertTrue( r.isAnon() );
        }
View Full Code Here

        }
   
    @Test public void testResourceURI()
        {
        Model m = ModelFactory.createDefaultModel();
        Resource r = new Parser( "noProperties" ).resourceIn( m );
        assertIsoModels( empty, m );
        assertEquals( ModelTestBase.resource( "noProperties" ), r );
        }
View Full Code Here

        }
   
    private Resource parseAsResource( String modelString )
        {
        Model m = ModelFactory.createDefaultModel();
        return new Parser( modelString ).resourceIn( m );
        }
View Full Code Here

    protected Model m( String s )
        { return modelWithStatements( s ); }

    protected Model parse( String s )
        { Model m = createModel( ReificationStyle.Standard );
        Model mDash = new Parser( s ).parseInto( m );
        assertSame( m, mDash );
        return m; }
View Full Code Here

    protected OntModel ontModel( String facts )
        {
        OntModel result =  ModelFactory.createOntologyModel();
        result.setNsPrefixes( PrefixMapping.Extended );
        setRequiredPrefixes( result );
        new Parser( facts ).parseInto( result );
        return result;
        }
View Full Code Here

    /**
        Eyeball test models are constructed using the extended parser.
    */
    protected Model modelAddFacts( Model result, String s )
        { return new Parser( s ).parseInto( result ); }
View Full Code Here

  protected Schema createSchema(Type type, Map<String,Schema> names) {
    if (type instanceof GenericArrayType) {                  // generic array
      Type component = ((GenericArrayType)type).getGenericComponentType();
      if (component == Byte.TYPE)                            // byte array
        return Schema.create(Schema.Type.BYTES);          
      Schema result = Schema.createArray(createSchema(component, names));
      setElement(result, component);
      return result;
    } else if (type instanceof ParameterizedType) {
      ParameterizedType ptype = (ParameterizedType)type;
      Class raw = (Class)ptype.getRawType();
      Type[] params = ptype.getActualTypeArguments();
      if (Map.class.isAssignableFrom(raw)) {                 // Map
        Schema schema = Schema.createMap(createSchema(params[1], names));
        Class key = (Class)params[0];
        if (isStringable(key)) {                             // Stringable key
          schema.addProp(KEY_CLASS_PROP, key.getName());
        } else if (key != String.class) {
          throw new AvroTypeException("Map key class not String: "+key);
        }
        return schema;
      } else if (Collection.class.isAssignableFrom(raw)) {   // Collection
        if (params.length != 1)
          throw new AvroTypeException("No array type specified.");
        Schema schema = Schema.createArray(createSchema(params[0], names));
        schema.addProp(CLASS_PROP, raw.getName());
        return schema;
      }
    } else if ((type == Byte.class) || (type == Byte.TYPE)) {
      Schema result = Schema.create(Schema.Type.INT);
      result.addProp(CLASS_PROP, Byte.class.getName());
      return result;
    } else if ((type == Short.class) || (type == Short.TYPE)) {
      Schema result = Schema.create(Schema.Type.INT);
      result.addProp(CLASS_PROP, Short.class.getName());
      return result;
    } else if ((type == Character.class) || (type == Character.TYPE)) {
        Schema result = Schema.create(Schema.Type.INT);
        result.addProp(CLASS_PROP, Character.class.getName());
        return result;
    } else if (type instanceof Class) {                      // Class
      Class<?> c = (Class<?>)type;
      if (c.isPrimitive() ||                                 // primitives
          c == Void.class || c == Boolean.class ||
          c == Integer.class || c == Long.class ||
          c == Float.class || c == Double.class ||
          c == Byte.class || c == Short.class ||
          c == Character.class)
        return super.createSchema(type, names);
      if (c.isArray()) {                                     // array
        Class component = c.getComponentType();
        if (component == Byte.TYPE) {                        // byte array
          Schema result = Schema.create(Schema.Type.BYTES);
          result.addProp(CLASS_PROP, c.getName());
          return result;
        }
        Schema result = Schema.createArray(createSchema(component, names));
        result.addProp(CLASS_PROP, c.getName());
        setElement(result, component);
        return result;
      }
      AvroSchema explicit = c.getAnnotation(AvroSchema.class);
      if (explicit != null)                                  // explicit schema
        return Schema.parse(explicit.value());
      if (CharSequence.class.isAssignableFrom(c))            // String
        return Schema.create(Schema.Type.STRING);
      if (ByteBuffer.class.isAssignableFrom(c))              // bytes
        return Schema.create(Schema.Type.BYTES);
      if (Collection.class.isAssignableFrom(c))              // array
        throw new AvroRuntimeException("Can't find element type of Collection");
      String fullName = c.getName();
      Schema schema = names.get(fullName);
      if (schema == null) {
        String name = c.getSimpleName();
        String space = c.getPackage() == null ? "" : c.getPackage().getName();
        if (c.getEnclosingClass() != null)                   // nested class
          space = c.getEnclosingClass().getName() + "$";
        Union union = c.getAnnotation(Union.class);
        if (union != null) {                                 // union annotated
          return getAnnotatedUnion(union, names);
        } else if (isStringable(c)) {                        // Stringable
          Schema result = Schema.create(Schema.Type.STRING);
          result.addProp(CLASS_PROP, c.getName());
          return result;
        } else if (c.isEnum()) {                             // Enum
          List<String> symbols = new ArrayList<String>();
          Enum[] constants = (Enum[])c.getEnumConstants();
          for (int i = 0; i < constants.length; i++)
            symbols.add(constants[i].name());
          schema = Schema.createEnum(name, null /* doc */, space, symbols);
          consumeAvroAliasAnnotation(c, schema);
        } else if (GenericFixed.class.isAssignableFrom(c)) { // fixed
          int size = c.getAnnotation(FixedSize.class).value();
          schema = Schema.createFixed(name, null /* doc */, space, size);
          consumeAvroAliasAnnotation(c, schema);
        } else if (IndexedRecord.class.isAssignableFrom(c)) { // specific
          return super.createSchema(type, names);
        } else {                                             // record
          List<Schema.Field> fields = new ArrayList<Schema.Field>();
          boolean error = Throwable.class.isAssignableFrom(c);
          schema = Schema.createRecord(name, null /* doc */, space, error);
          consumeAvroAliasAnnotation(c, schema);
          names.put(c.getName(), schema);
          for (Field field : getCachedFields(c))
            if ((field.getModifiers()&(Modifier.TRANSIENT|Modifier.STATIC))==0
                && !field.isAnnotationPresent(AvroIgnore.class)) {
              Schema fieldSchema = createFieldSchema(field, names);
              AvroDefault defaultAnnotation
                = field.getAnnotation(AvroDefault.class);
              JsonNode defaultValue = (defaultAnnotation == null)
                ? null
                : Schema.parseJson(defaultAnnotation.value());
             
              if (defaultValue == null
                  && fieldSchema.getType() == Schema.Type.UNION) {
                Schema defaultType = fieldSchema.getTypes().get(0);
                if (defaultType.getType() == Schema.Type.NULL) {
                  defaultValue = NullNode.getInstance();
                }
              }
              AvroName annotatedName = field.getAnnotation(AvroName.class);       // Rename fields
              String fieldName = (annotatedName != null)           
View Full Code Here

TOP

Related Classes of org.apache.avro.Schema$Parser

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.