|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.ldaptive.beans.generate.BeanGenerator
public class BeanGenerator
Utility class for creating Java POJOs from an LDAP schema. Sample usage:
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 Summary | |
|---|---|
BeanGenerator()
Default constructor. |
|
BeanGenerator(org.ldaptive.schema.Schema s,
String name,
String[] oc)
Creates a new bean generator. |
|
| Method Summary | |
|---|---|
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. |
org.ldaptive.schema.Schema |
getSchema()
Returns the schema. |
protected Class<?> |
getSyntaxType(org.ldaptive.schema.AttributeType type,
org.ldaptive.schema.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(org.ldaptive.schema.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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BeanGenerator()
public BeanGenerator(org.ldaptive.schema.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 for| Method Detail |
|---|
public org.ldaptive.schema.Schema getSchema()
public void setSchema(org.ldaptive.schema.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 mappings
NullPointerException - if m is nullpublic String[] getExcludedNames()
public void setExcludedNames(String... names)
names - to exclude
NullPointerException - if names is nullprotected static Map<String,Class<?>> getDefaultTypeMappings()
protected Class<?> getSyntaxType(org.ldaptive.schema.AttributeType type,
org.ldaptive.schema.Syntax syntax)
type - attribute typesyntax - associated with the attribute type
public 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 create
IllegalArgumentException - if the class already exists
protected 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 collection
public void write()
throws IOException
write(String) with
".".
IOException - if the write fails
public void write(String path)
throws IOException
path - to write the classes to
IOException - if the write fails
public 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 arguments
Exception - if any error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||