public final class ProtoSchemaBuilder extends Object
@Proto*
annotated classes. The generated schema and marshallers are registered to a SerializationContext
given during creation. The needed types, on which the currently generated types depend on, are
also looked up in the same SerializationContext
.
See annotations ProtoName
, ProtoMessage
, ProtoField
, ProtoEnum
, ProtoTypeId
,
ProtoEnumValue
, ProtoDoc
, ProtoDocs
, ProtoUnknownFieldSet
, ProtoFactory
,
ProtoReserved
and ProtoReservedStatements
.
NOTE: This builder contains state that cannot be reset making it impossible to reuse properly. Please create separate instances for each schema generation.
This class performs run-time generation. For a compile-time equivalent see AutoProtoSchemaBuilder
and SerializationContextInitializer
.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_GENERATED_SCHEMA_NAME |
static String |
FILE_LONG_OPT |
static String |
FILE_OPT |
static boolean |
generateSchemaDebugComments
Deprecated.
|
static String |
HELP_LONG_OPT |
static String |
HELP_OPT |
static String |
MARSHALLER_LONG_OPT |
static String |
MARSHALLER_OPT |
static String |
PACKAGE_LONG_OPT |
static String |
PACKAGE_OPT |
static String |
SCHEMA_LONG_OPT |
static String |
SCHEMA_OPT |
Constructor and Description |
---|
ProtoSchemaBuilder() |
Modifier and Type | Method and Description |
---|---|
ProtoSchemaBuilder |
addClass(Class<?> clazz)
Add a @ProtoXyz annotated class to be analyzed.
|
ProtoSchemaBuilder |
addClasses(Class<?>... classes)
Add several @ProtoXyz annotated classes to be analyzed.
|
ProtoSchemaBuilder |
autoImportClasses(boolean autoImportClasses)
A flag to control processing of classes that were not directly added but were discovered by analyzing the
annotated fields/properties of the added classes.
|
String |
build(SerializationContext serializationContext)
Builds the Protocol Buffers schema file defining the types and generates marshaller implementations for these
types and registers everything with the given
SerializationContext . |
ProtoSchemaBuilder |
fileName(String fileName)
Set the name of the Protobuf schema file to generate.
|
ProtoSchemaBuilder |
generator(String generator)
Sets the 'generated by' comment.
|
static void |
main(String[] args) |
ProtoSchemaBuilder |
packageName(String packageName)
Set the name of the Protobuf package to generate.
|
public static final String DEFAULT_GENERATED_SCHEMA_NAME
public static final String FILE_OPT
public static final String FILE_LONG_OPT
public static final String PACKAGE_OPT
public static final String PACKAGE_LONG_OPT
public static final String HELP_OPT
public static final String HELP_LONG_OPT
public static final String MARSHALLER_OPT
public static final String MARSHALLER_LONG_OPT
public static final String SCHEMA_OPT
public static final String SCHEMA_LONG_OPT
@Deprecated public static boolean generateSchemaDebugComments
true
to enable output of debug comments in the generated Protobuf schema.public ProtoSchemaBuilder fileName(String fileName)
SerializationContext
with this given name.fileName
- the name of the file to generatepublic ProtoSchemaBuilder packageName(String packageName)
packageName
- the package namepublic ProtoSchemaBuilder generator(String generator)
generator
- a string to be added as a comment in the generated schemapublic ProtoSchemaBuilder addClass(Class<?> clazz)
Its superclass and superinterfaces will be also included in the analysis but no separate Protobuf types and marshallers will be generated for them as Protobuf does not have any notion of type hierarchy and inheritance. The fields defined by the superclass or superinterfaces will be just included in the schema of the derived class.
Its inner classes will also be automatically processed if they are referenced by the outer class. If you want to
make sure an inner class is processed regardless if referenced or not you will have to add it explicitly using
#addClass
or addClasses(java.lang.Class<?>...)
.
clazz
- the class to analyzepublic ProtoSchemaBuilder addClasses(Class<?>... classes)
Their superclasses and superinterfaces will be also included in the analysis but no separate Protobuf types and marshallers will be generated for them as Protobuf does not have any notion of type hierarchy and inheritance. The fields defined by the superclass or superinterfaces will be just included in the schema of the derived class.
Inner classes will also be automatically processed if they are referenced by the outer class. If you want to make
sure an inner class is processed regardless if referenced or not you will have to add it explicitly using addClass(java.lang.Class<?>)
or #addClasses
.
classes
- the classes to analyzepublic ProtoSchemaBuilder autoImportClasses(boolean autoImportClasses)
true
by default to simplify usability (and also for backward
compatibility) but can be turned off whenever you need to be very specific about which classes are to be
processed. We encourage you to turn it off for maximum control.autoImportClasses
- public String build(SerializationContext serializationContext) throws ProtoSchemaBuilderException, IOException
SerializationContext
.serializationContext
- ProtoSchemaBuilderException
IOException
Copyright © 2019 JBoss, a division of Red Hat. All rights reserved.