public class BeanGenerator extends Object
Schema schema = new Schema(new DefaultConnectionFactory( "ldap://directory.ldaptive.org")); BeanGenerator generator = new BeanGenerator( schema, "com.my.package", new String[] {"inetOrgPerson"}); generator.generate(); generator.write();
Constructor and Description |
---|
BeanGenerator()
Default constructor.
|
BeanGenerator(Schema s,
String name,
String[] oc)
Creates a new bean generator.
|
Modifier and Type | Method and Description |
---|---|
protected com.sun.codemodel.JDefinedClass |
createClass(String classPackage,
String className)
Creates a class in the supplied package.
|
protected void |
createMutators(com.sun.codemodel.JDefinedClass clazz,
String name,
Class<?> syntaxType,
boolean multivalue)
Creates the getter and setter methods on the supplied class for the supplied name.
|
void |
generate()
Generates a class for each configured object class.
|
protected static Map<String,Class<?>> |
getDefaultTypeMappings()
Returns the default syntax types used to determine attribute property type.
|
String[] |
getExcludedNames()
Returns the attribute names to exclude from bean generation.
|
Map<String,String> |
getNameMappings()
Returns the mapping of directory attribute name to bean property.
|
String[] |
getObjectClasses()
Returns the object classes.
|
String |
getPackageName()
Returns the package name where beans will be generated.
|
Schema |
getSchema()
Returns the schema.
|
protected Class<?> |
getSyntaxType(AttributeType type,
Syntax syntax)
Returns the class for the supplied attribute type and syntax.
|
Map<String,Class<?>> |
getTypeMappings()
Returns the type mappings.
|
boolean |
isIncludeSuperiorClasses()
Returns whether to include superior classes in bean generation.
|
boolean |
isUseOperationalAttributes()
Returns whether to include operational attributes in bean generation.
|
boolean |
isUseOptionalAttributes()
Returns whether to include optional attributes in bean generation.
|
static void |
main(String[] args)
Provides command line access to a
BeanGenerator . |
void |
setExcludedNames(String... names)
Sets the attribute names to exclude from bean generation.
|
void |
setIncludeSuperiorClasses(boolean b)
Sets whether to include superior classes in bean generation.
|
void |
setNameMappings(Map<String,String> m)
Sets the mapping of directory attribute name to bean property.
|
void |
setObjectClasses(String... oc)
Sets the object classes.
|
void |
setPackageName(String name)
Sets the package name where beans will be generated.
|
void |
setSchema(Schema s)
Sets the schema.
|
void |
setTypeMappings(Map<String,Class<?>> m)
Sets the type mappings.
|
void |
setUseOperationalAttributes(boolean b)
Sets whether to include operational attributes in bean generation.
|
void |
setUseOptionalAttributes(boolean b)
Sets whether to include optional attributes in bean generation.
|
void |
write()
Writes the generated classes to disk.
|
void |
write(String path)
Writes the generated classes to disk at the supplied path.
|
public BeanGenerator()
public BeanGenerator(Schema s, String name, String[] oc)
s
- schema containing directory data for generationname
- package name to place the generated classes inoc
- object classes to generate beans forpublic Schema getSchema()
public void setSchema(Schema s)
s
- schemapublic String getPackageName()
public void setPackageName(String name)
name
- package namepublic String[] getObjectClasses()
public void setObjectClasses(String... oc)
oc
- object classespublic boolean isUseOptionalAttributes()
public void setUseOptionalAttributes(boolean b)
b
- whether to include optional attributespublic boolean isUseOperationalAttributes()
public void setUseOperationalAttributes(boolean b)
b
- whether to include operational attributespublic boolean isIncludeSuperiorClasses()
public void setIncludeSuperiorClasses(boolean b)
b
- whether to include superior classespublic Map<String,Class<?>> getTypeMappings()
public void setTypeMappings(Map<String,Class<?>> m)
m
- type mappingspublic Map<String,String> getNameMappings()
public void setNameMappings(Map<String,String> m)
m
- name mappingsNullPointerException
- if m is nullpublic String[] getExcludedNames()
public void setExcludedNames(String... names)
names
- to excludeNullPointerException
- if names is nullprotected static Map<String,Class<?>> getDefaultTypeMappings()
protected Class<?> getSyntaxType(AttributeType type, Syntax syntax)
type
- attribute typesyntax
- associated with the attribute typepublic void generate()
objectClasses
. write(String)
must be
invoked to write the classes to disk.protected com.sun.codemodel.JDefinedClass createClass(String classPackage, String className)
classPackage
- to place the class inclassName
- to createIllegalArgumentException
- if the class already existsprotected void createMutators(com.sun.codemodel.JDefinedClass clazz, String name, Class<?> syntaxType, boolean multivalue)
clazz
- to put getter and setter methods onname
- of the propertysyntaxType
- of the propertymultivalue
- whether this property is a collectionpublic void write() throws IOException
write(String)
with ".".IOException
- if the write failspublic void write(String path) throws IOException
path
- to write the classes toIOException
- if the write failspublic static void main(String[] args) throws Exception
BeanGenerator
. Expects two arguments:
A sample configuration property file looks like:
org.ldaptive.packageName=my.package.ldap.beans org.ldaptive.objectClasses=eduPerson org.ldaptive.nameMappings=c=countryName,l=localityName org.ldaptive.excludedNames=userPassword org.ldaptive.ldapUrl=ldap://directory.ldaptive.org
args
- command line argumentsException
- if any error occursCopyright © 2016. All rights reserved.