You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2012/02/14 12:00:48 UTC
svn commit: r1243871 -
/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/DefaultSchemaLoader.java
Author: pamarcelot
Date: Tue Feb 14 11:00:47 2012
New Revision: 1243871
URL: http://svn.apache.org/viewvc?rev=1243871&view=rev
Log:
Prevented NPEs.
Re-grouped methods by kind.
Applied code formatter.
Modified:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/DefaultSchemaLoader.java
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/DefaultSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/DefaultSchemaLoader.java?rev=1243871&r1=1243870&r2=1243871&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/DefaultSchemaLoader.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/DefaultSchemaLoader.java Tue Feb 14 11:00:47 2012
@@ -79,7 +79,7 @@ public class DefaultSchemaLoader extends
{
/** the logger */
private static final Logger LOG = LoggerFactory.getLogger( DefaultSchemaLoader.class );
-
+
/** the connection to the ldap server */
private LdapConnection connection;
@@ -87,19 +87,19 @@ public class DefaultSchemaLoader extends
private Dn subschemaSubentryDn;
/** The SubschemaSubentry descriptions parsers */
- private static AttributeTypeDescriptionSchemaParser AT_DESCR_SCHEMA_PARSER = new AttributeTypeDescriptionSchemaParser();
- private static DITStructureRuleDescriptionSchemaParser DSR_DESCR_SCHEMA_PARSER = new DITStructureRuleDescriptionSchemaParser();
- private static DITContentRuleDescriptionSchemaParser DCR_DESCR_SCHEMA_PARSER = new DITContentRuleDescriptionSchemaParser();
- private static MatchingRuleDescriptionSchemaParser MR_DESCR_SCHEMA_PARSER = new MatchingRuleDescriptionSchemaParser();
- private static MatchingRuleUseDescriptionSchemaParser MRU_DESCR_SCHEMA_PARSER = new MatchingRuleUseDescriptionSchemaParser();
- private static NameFormDescriptionSchemaParser NF_DESCR_SCHEMA_PARSER = new NameFormDescriptionSchemaParser();
- private static ObjectClassDescriptionSchemaParser OC_DESCR_SCHEMA_PARSER = new ObjectClassDescriptionSchemaParser();
- private static LdapSyntaxDescriptionSchemaParser LS_DESCR_SCHEMA_PARSER = new LdapSyntaxDescriptionSchemaParser();
-
- private static LdapComparatorDescriptionSchemaParser C_DESCR_SCHEMA_PARSER = new LdapComparatorDescriptionSchemaParser();
- private static NormalizerDescriptionSchemaParser N_DESCR_SCHEMA_PARSER = new NormalizerDescriptionSchemaParser();
- private static SyntaxCheckerDescriptionSchemaParser SC_DESCR_SCHEMA_PARSER = new SyntaxCheckerDescriptionSchemaParser();
-
+ private static AttributeTypeDescriptionSchemaParser AT_DESCR_SCHEMA_PARSER = new AttributeTypeDescriptionSchemaParser();
+ private static DITStructureRuleDescriptionSchemaParser DSR_DESCR_SCHEMA_PARSER = new DITStructureRuleDescriptionSchemaParser();
+ private static DITContentRuleDescriptionSchemaParser DCR_DESCR_SCHEMA_PARSER = new DITContentRuleDescriptionSchemaParser();
+ private static MatchingRuleDescriptionSchemaParser MR_DESCR_SCHEMA_PARSER = new MatchingRuleDescriptionSchemaParser();
+ private static MatchingRuleUseDescriptionSchemaParser MRU_DESCR_SCHEMA_PARSER = new MatchingRuleUseDescriptionSchemaParser();
+ private static NameFormDescriptionSchemaParser NF_DESCR_SCHEMA_PARSER = new NameFormDescriptionSchemaParser();
+ private static ObjectClassDescriptionSchemaParser OC_DESCR_SCHEMA_PARSER = new ObjectClassDescriptionSchemaParser();
+ private static LdapSyntaxDescriptionSchemaParser LS_DESCR_SCHEMA_PARSER = new LdapSyntaxDescriptionSchemaParser();
+
+ private static LdapComparatorDescriptionSchemaParser C_DESCR_SCHEMA_PARSER = new LdapComparatorDescriptionSchemaParser();
+ private static NormalizerDescriptionSchemaParser N_DESCR_SCHEMA_PARSER = new NormalizerDescriptionSchemaParser();
+ private static SyntaxCheckerDescriptionSchemaParser SC_DESCR_SCHEMA_PARSER = new SyntaxCheckerDescriptionSchemaParser();
+
/**
* Creates a new instance of NetworkSchemaLoader.
@@ -114,17 +114,17 @@ public class DefaultSchemaLoader extends
{
throw new InvalidConnectionException( "Cannot connect on the server, the connection is null" );
}
-
+
// Get the subschemaSubentry Dn from the rootDSE
try
{
this.connection = connection;
connection.connect();
Entry rootDse = connection.lookup( Dn.ROOT_DSE, SchemaConstants.SUBSCHEMA_SUBENTRY_AT );
-
+
String subschemaSubentryStr = rootDse.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).getString();
subschemaSubentryDn = new Dn( connection.getSchemaManager(), subschemaSubentryStr );
-
+
loadSchemas();
}
catch ( IOException ioe )
@@ -164,7 +164,7 @@ public class DefaultSchemaLoader extends
private void loadSchemas() throws LdapException
{
LOG.debug( "initializing schemas" );
-
+
// Load all the elements from the SubschemaSubentry
Entry subschemaSubentry = connection.lookup( subschemaSubentryDn,
SchemaConstants.ATTRIBUTE_TYPES_AT,
@@ -179,47 +179,47 @@ public class DefaultSchemaLoader extends
SchemaConstants.OBJECT_CLASSES_AT,
SchemaConstants.SYNTAX_CHECKERS_AT
);
-
+
// Load all the AT
Attribute attributeTypes = subschemaSubentry.get( SchemaConstants.ATTRIBUTE_TYPES_AT );
loadAttributeTypes( attributeTypes );
-
+
// Load all the C
Attribute comparators = subschemaSubentry.get( SchemaConstants.COMPARATORS_AT );
loadComparators( comparators );
-
+
// Load all the DCR
Attribute ditContentRules = subschemaSubentry.get( SchemaConstants.DIT_CONTENT_RULES_AT );
loadDitContentRules( ditContentRules );
-
+
// Load all the DSR
Attribute ditStructureRules = subschemaSubentry.get( SchemaConstants.DIT_STRUCTURE_RULES_AT );
loadDitStructureRules( ditStructureRules );
-
+
// Load all the LS
Attribute ldapSytaxes = subschemaSubentry.get( SchemaConstants.LDAP_SYNTAXES_AT );
loadLdapSyntaxes( ldapSytaxes );
-
+
// Load all the MR
Attribute matchingRules = subschemaSubentry.get( SchemaConstants.MATCHING_RULES_AT );
loadMatchingRules( matchingRules );
-
+
// Load all the MRU
Attribute matchingRuleUse = subschemaSubentry.get( SchemaConstants.MATCHING_RULE_USE_AT );
loadMatchingRuleUses( matchingRuleUse );
-
+
// Load all the N
Attribute normalizers = subschemaSubentry.get( SchemaConstants.NORMALIZERS_AT );
loadNormalizers( normalizers );
-
+
// Load all the NF
Attribute nameForms = subschemaSubentry.get( SchemaConstants.NAME_FORMS_AT );
loadNameForms( nameForms );
-
+
// Load all the OC
Attribute objectClasses = subschemaSubentry.get( SchemaConstants.OBJECT_CLASSES_AT );
loadObjectClasses( objectClasses );
-
+
// Load all the SC
Attribute syntaxCheckers = subschemaSubentry.get( SchemaConstants.SYNTAX_CHECKERS_AT );
loadSyntaxCheckers( syntaxCheckers );
@@ -229,39 +229,13 @@ public class DefaultSchemaLoader extends
/**
* {@inheritDoc}
*/
- public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException, IOException
+ private void loadAttributeTypes( Attribute attributeTypes ) throws LdapException
{
- List<Entry> attributeTypeEntries = new ArrayList<Entry>();
- AttributesFactory factory = new AttributesFactory();
-
- for ( Schema schema : schemas )
+ if ( attributeTypes == null )
{
- Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
- for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
- {
- SchemaObject schemaObject = schemaObjectWrapper.get();
-
- if ( schemaObject instanceof AttributeType )
- {
- AttributeType attributeType = (AttributeType)schemaObject;
-
- Entry attributeTypeEntry = factory.convert( attributeType, schema, null );
-
- attributeTypeEntries.add( attributeTypeEntry );
- }
- }
+ return;
}
- return attributeTypeEntries;
- }
-
-
- /**
- * {@inheritDoc}
- */
- private void loadAttributeTypes( Attribute attributeTypes ) throws LdapException
- {
for ( Value<?> value : attributeTypes )
{
String desc = value.getString();
@@ -269,7 +243,7 @@ public class DefaultSchemaLoader extends
try
{
AttributeType attributeType = AT_DESCR_SCHEMA_PARSER.parseAttributeTypeDescription( desc );
-
+
updateSchemas( attributeType );
}
catch ( ParseException pe )
@@ -285,6 +259,11 @@ public class DefaultSchemaLoader extends
*/
private void loadComparators( Attribute comparators ) throws LdapException
{
+ if ( comparators == null )
+ {
+ return;
+ }
+
for ( Value<?> value : comparators )
{
String desc = value.getString();
@@ -292,7 +271,7 @@ public class DefaultSchemaLoader extends
try
{
LdapComparatorDescription comparator = C_DESCR_SCHEMA_PARSER.parseComparatorDescription( desc );
-
+
updateSchemas( comparator );
}
catch ( ParseException pe )
@@ -308,6 +287,11 @@ public class DefaultSchemaLoader extends
*/
private void loadDitContentRules( Attribute ditContentRules ) throws LdapException
{
+ if ( ditContentRules == null )
+ {
+ return;
+ }
+
for ( Value<?> value : ditContentRules )
{
String desc = value.getString();
@@ -315,7 +299,7 @@ public class DefaultSchemaLoader extends
try
{
DITContentRule ditContentRule = DCR_DESCR_SCHEMA_PARSER.parseDITContentRuleDescription( desc );
-
+
updateSchemas( ditContentRule );
}
catch ( ParseException pe )
@@ -331,6 +315,11 @@ public class DefaultSchemaLoader extends
*/
private void loadDitStructureRules( Attribute ditStructureRules ) throws LdapException
{
+ if ( ditStructureRules == null )
+ {
+ return;
+ }
+
for ( Value<?> value : ditStructureRules )
{
String desc = value.getString();
@@ -338,7 +327,7 @@ public class DefaultSchemaLoader extends
try
{
DITStructureRule ditStructureRule = DSR_DESCR_SCHEMA_PARSER.parseDITStructureRuleDescription( desc );
-
+
updateSchemas( ditStructureRule );
}
catch ( ParseException pe )
@@ -354,6 +343,11 @@ public class DefaultSchemaLoader extends
*/
private void loadLdapSyntaxes( Attribute ldapSyntaxes ) throws LdapException
{
+ if ( ldapSyntaxes == null )
+ {
+ return;
+ }
+
for ( Value<?> value : ldapSyntaxes )
{
String desc = value.getString();
@@ -361,7 +355,7 @@ public class DefaultSchemaLoader extends
try
{
LdapSyntax ldapSyntax = LS_DESCR_SCHEMA_PARSER.parseLdapSyntaxDescription( desc );
-
+
updateSchemas( ldapSyntax );
}
catch ( ParseException pe )
@@ -377,6 +371,11 @@ public class DefaultSchemaLoader extends
*/
private void loadMatchingRules( Attribute matchingRules ) throws LdapException
{
+ if ( matchingRules == null )
+ {
+ return;
+ }
+
for ( Value<?> value : matchingRules )
{
String desc = value.getString();
@@ -384,7 +383,7 @@ public class DefaultSchemaLoader extends
try
{
MatchingRule matchingRule = MR_DESCR_SCHEMA_PARSER.parseMatchingRuleDescription( desc );
-
+
updateSchemas( matchingRule );
}
catch ( ParseException pe )
@@ -400,6 +399,11 @@ public class DefaultSchemaLoader extends
*/
private void loadMatchingRuleUses( Attribute matchingRuleUses ) throws LdapException
{
+ if ( matchingRuleUses == null )
+ {
+ return;
+ }
+
for ( Value<?> value : matchingRuleUses )
{
String desc = value.getString();
@@ -407,7 +411,7 @@ public class DefaultSchemaLoader extends
try
{
MatchingRuleUse matchingRuleUse = MRU_DESCR_SCHEMA_PARSER.parseMatchingRuleUseDescription( desc );
-
+
updateSchemas( matchingRuleUse );
}
catch ( ParseException pe )
@@ -423,6 +427,11 @@ public class DefaultSchemaLoader extends
*/
private void loadNameForms( Attribute nameForms ) throws LdapException
{
+ if ( nameForms == null )
+ {
+ return;
+ }
+
for ( Value<?> value : nameForms )
{
String desc = value.getString();
@@ -430,7 +439,7 @@ public class DefaultSchemaLoader extends
try
{
NameForm nameForm = NF_DESCR_SCHEMA_PARSER.parseNameFormDescription( desc );
-
+
updateSchemas( nameForm );
}
catch ( ParseException pe )
@@ -446,6 +455,11 @@ public class DefaultSchemaLoader extends
*/
private void loadNormalizers( Attribute normalizers ) throws LdapException
{
+ if ( normalizers == null )
+ {
+ return;
+ }
+
for ( Value<?> value : normalizers )
{
String desc = value.getString();
@@ -453,7 +467,7 @@ public class DefaultSchemaLoader extends
try
{
NormalizerDescription normalizer = N_DESCR_SCHEMA_PARSER.parseNormalizerDescription( desc );
-
+
updateSchemas( normalizer );
}
catch ( ParseException pe )
@@ -469,6 +483,11 @@ public class DefaultSchemaLoader extends
*/
private void loadObjectClasses( Attribute objectClasses ) throws LdapException
{
+ if ( objectClasses == null )
+ {
+ return;
+ }
+
for ( Value<?> value : objectClasses )
{
String desc = value.getString();
@@ -476,7 +495,7 @@ public class DefaultSchemaLoader extends
try
{
ObjectClass objectClass = OC_DESCR_SCHEMA_PARSER.parseObjectClassDescription( desc );
-
+
updateSchemas( objectClass );
}
catch ( ParseException pe )
@@ -492,6 +511,11 @@ public class DefaultSchemaLoader extends
*/
private void loadSyntaxCheckers( Attribute syntaxCheckers ) throws LdapException
{
+ if ( syntaxCheckers == null )
+ {
+ return;
+ }
+
for ( Value<?> value : syntaxCheckers )
{
String desc = value.getString();
@@ -499,7 +523,7 @@ public class DefaultSchemaLoader extends
try
{
SyntaxCheckerDescription syntaxChecker = SC_DESCR_SCHEMA_PARSER.parseSyntaxCheckerDescription( desc );
-
+
updateSchemas( syntaxChecker );
}
catch ( ParseException pe )
@@ -508,13 +532,13 @@ public class DefaultSchemaLoader extends
}
}
}
-
-
+
+
private void updateSchemas( SchemaObject schemaObject )
{
String schemaName = schemaObject.getSchemaName();
Schema schema = null;
-
+
if ( Strings.isEmpty( schemaName ) || Strings.equals( "null", schemaName ) )
{
schemaName = "default";
@@ -524,14 +548,14 @@ public class DefaultSchemaLoader extends
{
schema = schemaMap.get( schemaName );
}
-
+
if ( schema == null )
{
schema = new DefaultSchema( schemaName );
-
+
schemaMap.put( schemaName, schema );
}
-
+
schema.getContent().add( new SchemaObjectWrapper( schemaObject ) );
}
@@ -540,110 +564,71 @@ public class DefaultSchemaLoader extends
/**
* {@inheritDoc}
*/
- public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException
+ public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException, IOException
{
- List<Entry> comparatorEntries = new ArrayList<Entry>();
+ List<Entry> attributeTypeEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return attributeTypeEntries;
+ }
+
+ AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
- if ( schemaObject instanceof LdapComparatorDescription )
+
+ if ( schemaObject instanceof AttributeType )
{
- LdapComparatorDescription ldapComparatorDescription = (LdapComparatorDescription)schemaObject;
- Entry lcEntry = getEntry( ldapComparatorDescription );
+ AttributeType attributeType = ( AttributeType ) schemaObject;
- comparatorEntries.add( lcEntry );
+ Entry attributeTypeEntry = factory.convert( attributeType, schema, null );
+
+ attributeTypeEntries.add( attributeTypeEntry );
}
}
}
- return comparatorEntries;
+ return attributeTypeEntries;
}
-
- private Entry getEntry( LdapComparatorDescription comparatorDescription )
- {
- Entry entry = new DefaultEntry();
- entry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- MetaSchemaConstants.META_TOP_OC,
- MetaSchemaConstants.META_COMPARATOR_OC );
-
- entry.put( MetaSchemaConstants.M_OID_AT, comparatorDescription.getOid() );
- entry.put( MetaSchemaConstants.M_FQCN_AT, comparatorDescription.getFqcn() );
-
- if ( comparatorDescription.getBytecode() != null )
- {
- entry.put( MetaSchemaConstants.M_BYTECODE_AT,
- Base64.decode( comparatorDescription.getBytecode().toCharArray() ) );
- }
-
- if ( comparatorDescription.getDescription() != null )
- {
- entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, comparatorDescription.getDescription() );
- }
-
- return entry;
- }
-
-
- private Entry getEntry( SyntaxCheckerDescription syntaxCheckerDescription )
+ /**
+ * {@inheritDoc}
+ */
+ public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException
{
- Entry entry = new DefaultEntry();
-
- entry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- MetaSchemaConstants.META_TOP_OC,
- MetaSchemaConstants.META_SYNTAX_CHECKER_OC );
-
- entry.put( MetaSchemaConstants.M_OID_AT, syntaxCheckerDescription.getOid() );
- entry.put( MetaSchemaConstants.M_FQCN_AT, syntaxCheckerDescription.getFqcn() );
+ List<Entry> comparatorEntries = new ArrayList<Entry>();
- if ( syntaxCheckerDescription.getBytecode() != null )
+ if ( schemas == null )
{
- entry.put( MetaSchemaConstants.M_BYTECODE_AT,
- Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() ) );
+ return comparatorEntries;
}
- if ( syntaxCheckerDescription.getDescription() != null )
+ for ( Schema schema : schemas )
{
- entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, syntaxCheckerDescription.getDescription() );
- }
-
- return entry;
- }
-
-
- private Entry getEntry( NormalizerDescription normalizerDescription )
- {
- Entry entry = new DefaultEntry();
-
- entry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- MetaSchemaConstants.META_TOP_OC,
- MetaSchemaConstants.META_NORMALIZER_OC );
+ Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
- entry.put( MetaSchemaConstants.M_OID_AT, normalizerDescription.getOid() );
- entry.put( MetaSchemaConstants.M_FQCN_AT, normalizerDescription.getFqcn() );
+ for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
+ {
+ SchemaObject schemaObject = schemaObjectWrapper.get();
- if ( normalizerDescription.getBytecode() != null )
- {
- entry.put( MetaSchemaConstants.M_BYTECODE_AT,
- Base64.decode( normalizerDescription.getBytecode().toCharArray() ) );
- }
+ if ( schemaObject instanceof LdapComparatorDescription )
+ {
+ LdapComparatorDescription ldapComparatorDescription = ( LdapComparatorDescription ) schemaObject;
+ Entry lcEntry = getEntry( ldapComparatorDescription );
- if ( normalizerDescription.getDescription() != null )
- {
- entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, normalizerDescription.getDescription() );
+ comparatorEntries.add( lcEntry );
+ }
+ }
}
- return entry;
+ return comparatorEntries;
}
@@ -653,19 +638,25 @@ public class DefaultSchemaLoader extends
public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException, IOException
{
List<Entry> ditContentRuleEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return ditContentRuleEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof DITContentRule )
{
- DITContentRule ditContentRule = (DITContentRule)schemaObject;
+ DITContentRule ditContentRule = ( DITContentRule ) schemaObject;
Entry ditContentRuleEntry = factory.convert( ditContentRule, schema, null );
@@ -674,7 +665,6 @@ public class DefaultSchemaLoader extends
}
}
-
return ditContentRuleEntries;
}
@@ -685,19 +675,25 @@ public class DefaultSchemaLoader extends
public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException, IOException
{
List<Entry> ditStructureRuleEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return ditStructureRuleEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof DITStructureRule )
{
- DITStructureRule ditStructureRule = (DITStructureRule)schemaObject;
+ DITStructureRule ditStructureRule = ( DITStructureRule ) schemaObject;
Entry ditStructureRuleEntry = factory.convert( ditStructureRule, schema, null );
@@ -706,7 +702,6 @@ public class DefaultSchemaLoader extends
}
}
-
return ditStructureRuleEntries;
}
@@ -717,19 +712,25 @@ public class DefaultSchemaLoader extends
public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException
{
List<Entry> matchingRuleUseEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return matchingRuleUseEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof MatchingRuleUse )
{
- MatchingRuleUse matchingRuleUse = (MatchingRuleUse)schemaObject;
+ MatchingRuleUse matchingRuleUse = ( MatchingRuleUse ) schemaObject;
Entry matchingRuleUseEntry = factory.convert( matchingRuleUse, schema, null );
@@ -738,7 +739,6 @@ public class DefaultSchemaLoader extends
}
}
-
return matchingRuleUseEntries;
}
@@ -749,19 +749,25 @@ public class DefaultSchemaLoader extends
public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException, IOException
{
List<Entry> matchingRuleEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return matchingRuleEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof MatchingRule )
{
- MatchingRule matchingRule = (MatchingRule)schemaObject;
+ MatchingRule matchingRule = ( MatchingRule ) schemaObject;
Entry matchingRuleEntry = factory.convert( matchingRule, schema, null );
@@ -780,19 +786,25 @@ public class DefaultSchemaLoader extends
public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException
{
List<Entry> nameFormEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return nameFormEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof NameForm )
{
- NameForm nameForm = (NameForm)schemaObject;
+ NameForm nameForm = ( NameForm ) schemaObject;
Entry nameFormEntry = factory.convert( nameForm, schema, null );
@@ -801,7 +813,6 @@ public class DefaultSchemaLoader extends
}
}
-
return nameFormEntries;
}
@@ -813,17 +824,22 @@ public class DefaultSchemaLoader extends
{
List<Entry> normalizerEntries = new ArrayList<Entry>();
+ if ( schemas == null )
+ {
+ return normalizerEntries;
+ }
+
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof NormalizerDescription )
{
- NormalizerDescription normalizerDescription = (NormalizerDescription)schemaObject;
+ NormalizerDescription normalizerDescription = ( NormalizerDescription ) schemaObject;
Entry normalizerEntry = getEntry( normalizerDescription );
normalizerEntries.add( normalizerEntry );
@@ -831,7 +847,6 @@ public class DefaultSchemaLoader extends
}
}
-
return normalizerEntries;
}
@@ -842,23 +857,29 @@ public class DefaultSchemaLoader extends
public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException, IOException
{
List<Entry> objectClassEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return objectClassEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof ObjectClass )
{
- ObjectClass objectClass = (ObjectClass)schemaObject;
+ ObjectClass objectClass = ( ObjectClass ) schemaObject;
Entry objectClassEntry = factory.convert( objectClass, schema, null );
- objectClassEntries.add(objectClassEntry );
+ objectClassEntries.add( objectClassEntry );
}
}
}
@@ -874,17 +895,22 @@ public class DefaultSchemaLoader extends
{
List<Entry> syntaxCheckerEntries = new ArrayList<Entry>();
+ if ( schemas == null )
+ {
+ return syntaxCheckerEntries;
+ }
+
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof SyntaxCheckerDescription )
{
- SyntaxCheckerDescription syntaxCheckerDescription = (SyntaxCheckerDescription)schemaObject;
+ SyntaxCheckerDescription syntaxCheckerDescription = ( SyntaxCheckerDescription ) schemaObject;
Entry syntaxCheckerEntry = getEntry( syntaxCheckerDescription );
syntaxCheckerEntries.add( syntaxCheckerEntry );
@@ -902,19 +928,25 @@ public class DefaultSchemaLoader extends
public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException
{
List<Entry> syntaxEntries = new ArrayList<Entry>();
+
+ if ( schemas == null )
+ {
+ return syntaxEntries;
+ }
+
AttributesFactory factory = new AttributesFactory();
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
-
+
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
-
+
if ( schemaObject instanceof LdapSyntax )
{
- LdapSyntax ldapSyntax = (LdapSyntax)schemaObject;
+ LdapSyntax ldapSyntax = ( LdapSyntax ) schemaObject;
Entry ldapSyntaxEntry = factory.convert( ldapSyntax, schema, null );
@@ -923,7 +955,87 @@ public class DefaultSchemaLoader extends
}
}
-
return syntaxEntries;
}
+
+
+ private Entry getEntry( LdapComparatorDescription comparatorDescription )
+ {
+ Entry entry = new DefaultEntry();
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ MetaSchemaConstants.META_TOP_OC,
+ MetaSchemaConstants.META_COMPARATOR_OC );
+
+ entry.put( MetaSchemaConstants.M_OID_AT, comparatorDescription.getOid() );
+ entry.put( MetaSchemaConstants.M_FQCN_AT, comparatorDescription.getFqcn() );
+
+ if ( comparatorDescription.getBytecode() != null )
+ {
+ entry.put( MetaSchemaConstants.M_BYTECODE_AT,
+ Base64.decode( comparatorDescription.getBytecode().toCharArray() ) );
+ }
+
+ if ( comparatorDescription.getDescription() != null )
+ {
+ entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, comparatorDescription.getDescription() );
+ }
+
+ return entry;
+ }
+
+
+ private Entry getEntry( SyntaxCheckerDescription syntaxCheckerDescription )
+ {
+ Entry entry = new DefaultEntry();
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ MetaSchemaConstants.META_TOP_OC,
+ MetaSchemaConstants.META_SYNTAX_CHECKER_OC );
+
+ entry.put( MetaSchemaConstants.M_OID_AT, syntaxCheckerDescription.getOid() );
+ entry.put( MetaSchemaConstants.M_FQCN_AT, syntaxCheckerDescription.getFqcn() );
+
+ if ( syntaxCheckerDescription.getBytecode() != null )
+ {
+ entry.put( MetaSchemaConstants.M_BYTECODE_AT,
+ Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() ) );
+ }
+
+ if ( syntaxCheckerDescription.getDescription() != null )
+ {
+ entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, syntaxCheckerDescription.getDescription() );
+ }
+
+ return entry;
+ }
+
+
+ private Entry getEntry( NormalizerDescription normalizerDescription )
+ {
+ Entry entry = new DefaultEntry();
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT,
+ SchemaConstants.TOP_OC,
+ MetaSchemaConstants.META_TOP_OC,
+ MetaSchemaConstants.META_NORMALIZER_OC );
+
+ entry.put( MetaSchemaConstants.M_OID_AT, normalizerDescription.getOid() );
+ entry.put( MetaSchemaConstants.M_FQCN_AT, normalizerDescription.getFqcn() );
+
+ if ( normalizerDescription.getBytecode() != null )
+ {
+ entry.put( MetaSchemaConstants.M_BYTECODE_AT,
+ Base64.decode( normalizerDescription.getBytecode().toCharArray() ) );
+ }
+
+ if ( normalizerDescription.getDescription() != null )
+ {
+ entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, normalizerDescription.getDescription() );
+ }
+
+ return entry;
+ }
}