private static Schema getSchema( JNDIConnectionWrapper wrapper, SearchResult searchResult,
StudioProgressMonitor monitor ) throws NamingException, ParseException
{
// Creating the schema
Schema schema = new SchemaImpl( "schema" ); //$NON-NLS-1$
Attribute attributeTypesAttribute = searchResult.getAttributes().get( "attributeTypes" );
if ( attributeTypesAttribute != null )
{
NamingEnumeration<?> ne = attributeTypesAttribute.getAll();
if ( ne != null )
{
while ( ne.hasMoreElements() )
{
String value = ( String ) ne.nextElement();
AttributeTypeDescriptionSchemaParser parser = new AttributeTypeDescriptionSchemaParser();
parser.setQuirksMode( true );
AttributeTypeDescription atd = parser.parseAttributeTypeDescription( value );
AttributeTypeImpl impl = new AttributeTypeImpl( atd.getNumericOid() );
impl.setOid( atd.getNumericOid() );
impl.setNames( atd.getNames().toArray( new String[0] ) );
impl.setDescription( atd.getDescription() );
impl.setSuperiorName( atd.getSuperType() );
impl.setUsage( atd.getUsage() );
impl.setSyntaxOid( atd.getSyntax() );
impl.setLength( atd.getSyntaxLength() );
impl.setObsolete( atd.isObsolete() );
impl.setCollective( atd.isCollective() );
impl.setSingleValue( atd.isSingleValued() );
impl.setCanUserModify( atd.isUserModifiable() );
impl.setEqualityName( atd.getEqualityMatchingRule() );
impl.setOrderingName( atd.getOrderingMatchingRule() );
impl.setSubstrName( atd.getSubstringsMatchingRule() );
impl.setSchema( schema.getName() );
impl.setSchemaObject( schema );
// Active Directory hack
if ( impl.getSyntaxOid() != null && "OctetString".equalsIgnoreCase( impl.getSyntaxOid() ) ) //$NON-NLS-1$
{
impl.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.40" );
}
schema.addAttributeType( impl );
}
}
}
Attribute objectClassesAttribute = searchResult.getAttributes().get( "objectClasses" );
if ( objectClassesAttribute != null )
{
NamingEnumeration<?> ne = objectClassesAttribute.getAll();
if ( ne != null )
{
while ( ne.hasMoreElements() )
{
String value = ( String ) ne.nextElement();
ObjectClassDescriptionSchemaParser parser = new ObjectClassDescriptionSchemaParser();
parser.setQuirksMode( true );
ObjectClassDescription ocd = parser.parseObjectClassDescription( value );
ObjectClassImpl impl = new ObjectClassImpl( ocd.getNumericOid() );
impl.setOid( ocd.getNumericOid() );
impl.setNames( ocd.getNames().toArray( new String[0] ) );
impl.setDescription( ocd.getDescription() );
impl.setSuperClassesNames( ocd.getSuperiorObjectClasses().toArray( new String[0] ) );
impl.setType( ocd.getKind() );
impl.setObsolete( ocd.isObsolete() );
impl.setMustNamesList( ocd.getMustAttributeTypes().toArray( new String[0] ) );
impl.setMayNamesList( ocd.getMayAttributeTypes().toArray( new String[0] ) );
impl.setSchema( schema.getName() );
impl.setSchemaObject( schema );
schema.addObjectClass( impl );
}
}
}
Attribute ldapSyntaxesAttribute = searchResult.getAttributes().get( "ldapSyntaxes" );
if ( ldapSyntaxesAttribute != null )
{
NamingEnumeration<?> ne = ldapSyntaxesAttribute.getAll();
if ( ne != null )
{
while ( ne.hasMoreElements() )
{
String value = ( String ) ne.nextElement();
LdapSyntaxDescriptionSchemaParser parser = new LdapSyntaxDescriptionSchemaParser();
parser.setQuirksMode( true );
LdapSyntaxDescription lsd = parser.parseLdapSyntaxDescription( value );
SyntaxImpl impl = new SyntaxImpl( lsd.getNumericOid() );
impl.setDescription( lsd.getDescription() );
impl.setNames( new String[]
{ lsd.getDescription() } );
//impl.setObsolete( lsd.isObsolete() );
impl.setHumanReadable( true );
impl.setSchema( schema.getName() );
impl.setSchemaObject( schema );
schema.addSyntax( impl );
}
}
}
// if online: assume all received syntaxes in attributes are valid -> create dummy syntaxes if missing
for ( AttributeTypeImpl at : schema.getAttributeTypes() )
{
String syntaxOid = at.getSyntaxOid();
if ( syntaxOid != null && schema.getSyntax( syntaxOid ) == null )
{
SyntaxImpl impl = new SyntaxImpl( syntaxOid );
impl.setSchema( schema.getName() );
impl.setSchemaObject( schema );
String oidDescription = Utils.getOidDescription( syntaxOid );
impl.setDescription( oidDescription != null ? oidDescription : "Dummy" ); //$NON-NLS-1$
impl.setNames( new String[]
{ impl.getDescription() } );
schema.addSyntax( impl );
}
}
Attribute matchingRulesAttribute = searchResult.getAttributes().get( "matchingRules" );
if ( matchingRulesAttribute != null )
{
NamingEnumeration<?> ne = matchingRulesAttribute.getAll();
if ( ne != null )
{
while ( ne.hasMoreElements() )
{
String value = ( String ) ne.nextElement();
MatchingRuleDescriptionSchemaParser parser = new MatchingRuleDescriptionSchemaParser();
parser.setQuirksMode( true );
MatchingRuleDescription mrd = parser.parseMatchingRuleDescription( value );
MatchingRuleImpl impl = new MatchingRuleImpl( mrd.getNumericOid() );
impl.setDescription( mrd.getDescription() );
impl.setNames( mrd.getNames().toArray( new String[0] ) );
impl.setObsolete( mrd.isObsolete() );
impl.setSyntaxOid( mrd.getSyntax() );
impl.setSchema( schema.getName() );
impl.setSchemaObject( schema );
schema.addMatchingRule( impl );
}
}
}
// if online: assume all received matching rules in attributes are valid -> create dummy matching rules if missing
for ( AttributeTypeImpl at : schema.getAttributeTypes() )
{
String equalityName = at.getEqualityName();
String orderingName = at.getOrderingName();
String substrName = at.getSubstrName();
checkMatchingRules( schema, equalityName, orderingName, substrName );