Java源码示例:org.apache.directory.api.ldap.model.schema.registries.Schema
示例1
/**
* {@inheritDoc}
*/
@Override
public List<Schema> getDisabled()
{
List<Schema> disabled = new ArrayList<>();
for ( Schema schema : registries.getLoadedSchemas().values() )
{
if ( schema.isDisabled() )
{
disabled.add( schema );
}
}
return disabled;
}
示例2
protected void addSchemaObjects( Schema schema, Registries registries ) throws LdapException
{
// Create a content container for this schema
registries.addSchema( schema.getSchemaName() );
schemaMap.put( schema.getSchemaName(), schema );
// And inject any existing SchemaObject into the registries
try
{
addComparators( schema, registries );
addNormalizers( schema, registries );
addSyntaxCheckers( schema, registries );
addSyntaxes( schema, registries );
addMatchingRules( schema, registries );
addAttributeTypes( schema, registries );
addObjectClasses( schema, registries );
//addMatchingRuleUses( schema, registries );
//addDitContentRules( schema, registries );
//addNameForms( schema, registries );
//addDitStructureRules( schema, registries );
}
catch ( IOException ioe )
{
throw new LdapOtherException( ioe.getMessage(), ioe );
}
}
示例3
@BeforeAll
public static void setup() throws Exception
{
tmpFolder = Files.createTempDirectory( MatchingRuleTest.class.getSimpleName() );
SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tmpFolder.toFile() );
extractor.extractOrCopy();
LdifSchemaLoader loader = new LdifSchemaLoader( new File( tmpFolder.toFile(), "schema" ) );
schemaManager = new DefaultSchemaManager( loader );
for ( Schema schema : loader.getAllSchemas() )
{
schema.enable();
}
schemaManager.loadAllEnabled();
}
示例4
/**
* {@inheritDoc}
*/
@Override
public boolean loadAllEnabledRelaxed() throws LdapException
{
Schema[] enabledSchemas = new Schema[schemaMap.size()];
int i = 0;
for ( Schema schema : schemaMap.values() )
{
if ( schema.isEnabled() )
{
enabledSchemas[i++] = schema;
}
}
return loadWithDepsRelaxed( enabledSchemas );
}
示例5
/**
* Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
*
* @param relaxed If the schema manager should be relaxed or not
* @param schemas The list of schema to load
*/
public DefaultSchemaManager( boolean relaxed, Collection<Schema> schemas )
{
// Default to the the root (one schemaManager for all the entries
namingContext = Dn.ROOT_DSE;
for ( Schema schema : schemas )
{
schemaMap.put( schema.getSchemaName(), schema );
}
registries = new Registries();
factory = new SchemaEntityFactory();
isRelaxed = relaxed;
setErrorHandler( new LoggingSchemaErrorHandler() );
}
示例6
/**
* Test that we can't load a new schema with bad dependencies
*/
@Test
public void loadNewSchemaBadDependencies() throws Exception
{
LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
SchemaManager schemaManager = new DefaultSchemaManager( loader );
Schema dummy = new DefaultSchema( loader, "dummy" );
dummy.addDependencies( "bad" );
assertFalse( schemaManager.load( dummy ) );
assertFalse( schemaManager.getErrors().isEmpty() );
assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 0, schemaManager.getComparatorRegistry().size() );
assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
assertEquals( 0, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNull( schemaManager.getRegistries().getLoadedSchema( "dummy" ) );
}
示例7
/**
* Delete all the schemaObjects for a given schema from the registries
*
* @param schema The schema from which we want teh SchemaObjects to be deleted
* @param registries The Registries to process
* @throws LdapException If the SchemaObjects cannot be deleted
*/
private void deleteSchemaObjects( Schema schema, Registries registries ) throws LdapException
{
Map<String, Set<SchemaObjectWrapper>> schemaObjects = registries.getObjectBySchemaName();
Set<SchemaObjectWrapper> content = schemaObjects.get( Strings.toLowerCaseAscii( schema.getSchemaName() ) );
List<SchemaObject> toBeDeleted = new ArrayList<>();
if ( content != null )
{
// Build an intermediate list to avoid concurrent modifications
for ( SchemaObjectWrapper schemaObjectWrapper : content )
{
toBeDeleted.add( schemaObjectWrapper.get() );
}
for ( SchemaObject schemaObject : toBeDeleted )
{
registries.delete( schemaObject );
}
}
}
示例8
private List<Entry> loadSchemaObjects( String schemaObjectType, Schema... schemas )
{
Map<String, List<Entry>> m = scObjEntryMap.get( schemaObjectType );
List<Entry> atList = new ArrayList<>();
for ( Schema s : schemas )
{
List<Entry> preLoaded = m.get( s.getSchemaName() );
if ( preLoaded != null )
{
atList.addAll( preLoaded );
}
}
return atList;
}
示例9
/**
* Process the common attributes to all SchemaObjects :
* - obsolete
* - description
* - names
* - schemaName
* - specification (if any)
* - extensions
* - isEnabled
*
* @param schemaObject The SchemaObject to set
* @param description The SchemaObjetc description
* @param schema the updated Schema
*/
private void setSchemaObjectProperties( SchemaObject schemaObject, SchemaObject description, Schema schema )
{
// The isObsolete field
schemaObject.setObsolete( description.isObsolete() );
// The description field
schemaObject.setDescription( description.getDescription() );
// The names field
schemaObject.setNames( description.getNames() );
// The isEnabled field. Has the description does not hold a
// Disable field, we will inherit from the schema enable field
schemaObject.setEnabled( schema.isEnabled() );
// The specification field
schemaObject.setSpecification( description.getSpecification() );
// The schemaName field
schemaObject.setSchemaName( schema.getSchemaName() );
// The extensions field
schemaObject.setExtensions( description.getExtensions() );
}
示例10
/**
* {@inheritDoc}
*/
@Override
public List<Schema> getEnabled()
{
List<Schema> enabled = new ArrayList<>();
for ( Schema schema : registries.getLoadedSchemas().values() )
{
if ( schema.isEnabled() )
{
enabled.add( schema );
}
}
return enabled;
}
示例11
/**
* Get the schema from its name. Return the Other reference if there
* is no schema name. Throws a NPE if the schema is not loaded.
*
* @param schemaName The schema name to fetch
* @param registries The registries where we get the schema from
* @return the found Schema
*/
private Schema getSchema( String schemaName, Registries registries )
{
if ( Strings.isEmpty( schemaName ) )
{
schemaName = MetaSchemaConstants.SCHEMA_OTHER;
}
Schema schema = registries.getLoadedSchema( schemaName );
if ( schema == null )
{
String msg = I18n.err( I18n.ERR_16015_NON_EXISTENT_SCHEMA, schemaName );
LOG.error( msg );
}
return schema;
}
示例12
/**
* Test that we can load a new schema
*/
@Test
public void loadNewSchema() throws Exception
{
LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
SchemaManager schemaManager = new DefaultSchemaManager( loader );
Schema dummy = new DefaultSchema( loader, "dummy" );
assertTrue( schemaManager.load( dummy ) );
assertTrue( schemaManager.getErrors().isEmpty() );
assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 0, schemaManager.getComparatorRegistry().size() );
assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
assertEquals( 0, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 1, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNotNull( schemaManager.getRegistries().getLoadedSchema( "dummy" ) );
}
示例13
/**
* Get a SchemaObject as an Entry
*
* @param obj The schema oobject to convert
* @param schema The schema which this object belongs to
* @param schemaManager The SchemaManager
* @return The converted schema object as an Entry
* @throws LdapException If we can't convert teh schema object
*/
public Entry getAttributes( SchemaObject obj, Schema schema, SchemaManager schemaManager ) throws LdapException
{
if ( obj instanceof LdapSyntax )
{
return convert( ( LdapSyntax ) obj, schema, schemaManager );
}
else if ( obj instanceof MatchingRule )
{
return convert( ( MatchingRule ) obj, schema, schemaManager );
}
else if ( obj instanceof AttributeType )
{
return convert( ( AttributeType ) obj, schema, schemaManager );
}
else if ( obj instanceof ObjectClass )
{
return convert( ( ObjectClass ) obj, schema, schemaManager );
}
else if ( obj instanceof MatchingRuleUse )
{
return convert( ( MatchingRuleUse ) obj, schema, schemaManager );
}
else if ( obj instanceof DitStructureRule )
{
return convert( ( DitStructureRule ) obj, schema, schemaManager );
}
else if ( obj instanceof DitContentRule )
{
return convert( ( DitContentRule ) obj, schema, schemaManager );
}
else if ( obj instanceof NameForm )
{
return convert( ( NameForm ) obj, schema, schemaManager );
}
throw new IllegalArgumentException( I18n.err( I18n.ERR_13712_UNKNOWN_SCHEMA_OBJECT_TYPE, obj.getClass() ) );
}
示例14
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException
{
List<Entry> syntaxCheckerList = new ArrayList<>();
if ( schemas == null )
{
return syntaxCheckerList;
}
for ( Schema schema : schemas )
{
File syntaxCheckersDirectory = new File( getSchemaDirectory( schema ), SchemaConstants.SYNTAX_CHECKERS_PATH );
if ( !syntaxCheckersDirectory.exists() )
{
return syntaxCheckerList;
}
File[] syntaxCheckerFiles = syntaxCheckersDirectory.listFiles( ldifFilter );
if ( syntaxCheckerFiles != null )
{
for ( File ldifFile : syntaxCheckerFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();
syntaxCheckerList.add( entry.getEntry() );
}
}
}
return syntaxCheckerList;
}
示例15
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException, IOException
{
List<Entry> matchingRuleList = new ArrayList<>();
if ( schemas == null )
{
return matchingRuleList;
}
for ( Schema schema : schemas )
{
File matchingRulesDirectory = new File( getSchemaDirectory( schema ), SchemaConstants.MATCHING_RULES_PATH );
if ( !matchingRulesDirectory.exists() )
{
return matchingRuleList;
}
File[] matchingRuleFiles = matchingRulesDirectory.listFiles( ldifFilter );
if ( matchingRuleFiles != null )
{
for ( File ldifFile : matchingRuleFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();
matchingRuleList.add( entry.getEntry() );
}
}
}
return matchingRuleList;
}
示例16
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException
{
List<Entry> nameFormList = new ArrayList<>();
if ( schemas == null )
{
return nameFormList;
}
for ( Schema schema : schemas )
{
File nameFormsDirectory = new File( getSchemaDirectory( schema ), SchemaConstants.NAME_FORMS_PATH );
if ( !nameFormsDirectory.exists() )
{
return nameFormList;
}
File[] nameFormFiles = nameFormsDirectory.listFiles( ldifFilter );
if ( nameFormFiles != null )
{
for ( File ldifFile : nameFormFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();
nameFormList.add( entry.getEntry() );
}
}
}
return nameFormList;
}
示例17
/**
* Convert a LdapComparator instance into an Entry
*
* @param oid The LdapComparator's OID
* @param comparator The LdapComparator to convert
* @param schema The schema containing this Comparator
* @param schemaManager The SchemaManager
* @return An Entry defining a LdapComparator
*/
public Entry convert( String oid, LdapComparator<? super Object> comparator, Schema schema, SchemaManager schemaManager )
{
Entry entry = new DefaultEntry( schemaManager );
entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC );
entry.put( MetaSchemaConstants.M_OID_AT, oid );
entry.put( MetaSchemaConstants.M_FQCN_AT, comparator.getClass().getName() );
entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
return entry;
}
示例18
/**
* Converts a MatchingRule into an Entry
*
* @param matchingRule The MatchingRule to convert
* @param schema The schema containing this ObjectClass
* @param schemaManager The SchemaManager
* @return The converted MatchingRule
* @throws LdapException If the conversion failed
*/
public Entry convert( MatchingRule matchingRule, Schema schema, SchemaManager schemaManager )
throws LdapException
{
Entry entry = new DefaultEntry( schemaManager );
entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_MATCHING_RULE_OC );
entry.put( MetaSchemaConstants.M_SYNTAX_AT, matchingRule.getSyntaxOid() );
entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
injectCommon( matchingRule, entry, schemaManager );
return entry;
}
示例19
/**
* Converts a MatchingRuleUse into an Entry
*
* @param matchingRuleUse The MatchingRuleUse to convert
* @param schema The schema containing this MatchingRuleUse
* @param schemaManager The SchemaManager
* @return The converted MatchingRuleUse
*/
public Entry convert( MatchingRuleUse matchingRuleUse, Schema schema, SchemaManager schemaManager )
{
Entry entry = new DefaultEntry( schemaManager );
entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
return entry;
}
示例20
/**
* {@inheritDoc}
*/
@Override
public boolean unload( String... schemaNames ) throws LdapException
{
Schema[] schemas = toArray( schemaNames );
return unload( schemas );
}
示例21
/**
*
* Converts a NameForm into an Entry
*
* @param nameForm The NameForm to convert
* @param schema The schema containing this NameForm
* @param schemaManager The SchemaManager
* @return The converted NameForm
*/
public Entry convert( NameForm nameForm, Schema schema, SchemaManager schemaManager )
{
Entry entry = new DefaultEntry( schemaManager );
entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
return entry;
}
示例22
/**
* Add all the Schema's AttributeTypes
*
* @param schema The schema in which the AttributeTypes will be added
* @param registries The Registries to process
* @throws LdapException If the AttributeTypes cannot be added
* @throws IOException If the AttributeTypes cannot be loaded
*/
private void addAttributeTypes( Schema schema, Registries registries ) throws LdapException, IOException
{
if ( schema.getSchemaLoader() == null )
{
return;
}
for ( Entry entry : schema.getSchemaLoader().loadAttributeTypes( schema ) )
{
AttributeType attributeType = factory.getAttributeType( this, entry, registries, schema.getSchemaName() );
addSchemaObject( registries, attributeType, schema );
}
}
示例23
/**
* Add all the Schema's Normalizers
*
* @param schema The schema in which the Normalizers will be added
* @param registries The Registries to process
* @throws LdapException If the Normalizers cannot be added
* @throws IOException If the Normalizers cannot be loaded
*/
private void addNormalizers( Schema schema, Registries registries ) throws LdapException, IOException
{
if ( schema.getSchemaLoader() == null )
{
return;
}
for ( Entry entry : schema.getSchemaLoader().loadNormalizers( schema ) )
{
Normalizer normalizer = factory.getNormalizer( this, entry, registries, schema.getSchemaName() );
addSchemaObject( registries, normalizer, schema );
}
}
示例24
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException, IOException
{
List<Entry> attributeTypeEntries = new ArrayList<>();
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 AttributeType )
{
AttributeType attributeType = ( AttributeType ) schemaObject;
Entry attributeTypeEntry = factory.convert( attributeType, schema, null );
attributeTypeEntries.add( attributeTypeEntry );
}
}
}
return attributeTypeEntries;
}
示例25
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException
{
List<Entry> comparatorEntries = new ArrayList<>();
if ( schemas == null )
{
return comparatorEntries;
}
for ( Schema schema : schemas )
{
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
{
SchemaObject schemaObject = schemaObjectWrapper.get();
if ( schemaObject instanceof LdapComparatorDescription )
{
LdapComparatorDescription ldapComparatorDescription = ( LdapComparatorDescription ) schemaObject;
Entry lcEntry = getEntry( ldapComparatorDescription );
comparatorEntries.add( lcEntry );
}
}
}
return comparatorEntries;
}
示例26
/**
* Test the loadEnabled() method
*/
@Test
public void testLoadAllEnabled() throws Exception
{
assertTrue( schemaManager.getEnabled().isEmpty() );
assertTrue( schemaManager.loadAllEnabled() );
for ( String schemaName : allSchemas )
{
assertTrue( schemaManager.isSchemaLoaded( schemaName ) );
}
// The enabled schemas
Collection<Schema> enabled = schemaManager.getEnabled();
assertEquals( enabled.size(), enabledSchemas.size() );
for ( Schema schema : enabled )
{
assertTrue( enabledSchemas.contains( Strings.toLowerCaseAscii( schema.getSchemaName() ) ) );
}
// The disabled schemas
List<Schema> disabled = schemaManager.getDisabled();
assertEquals( 0, disabled.size() );
assertTrue( schemaManager.getErrors().isEmpty() );
assertEquals( 430, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 49, schemaManager.getComparatorRegistry().size() );
assertEquals( 55, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 48, schemaManager.getNormalizerRegistry().size() );
assertEquals( 123, schemaManager.getObjectClassRegistry().size() );
assertEquals( 68, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 80, schemaManager.getLdapSyntaxRegistry().size() );
assertEquals( 688, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 12, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
}
示例27
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException, IOException
{
List<Entry> ditStructureRuleEntries = new ArrayList<>();
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;
Entry ditStructureRuleEntry = factory.convert( ditStructureRule, schema, null );
ditStructureRuleEntries.add( ditStructureRuleEntry );
}
}
}
return ditStructureRuleEntries;
}
示例28
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException, IOException
{
List<Entry> matchingRuleEntries = new ArrayList<>();
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;
Entry matchingRuleEntry = factory.convert( matchingRule, schema, null );
matchingRuleEntries.add( matchingRuleEntry );
}
}
}
return matchingRuleEntries;
}
示例29
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException
{
List<Entry> nameFormEntries = new ArrayList<>();
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;
Entry nameFormEntry = factory.convert( nameForm, schema, null );
nameFormEntries.add( nameFormEntry );
}
}
}
return nameFormEntries;
}
示例30
/**
* Add all the Schema's Syntaxes
*
* @param schema The schema in which the Syntaxes will be added
* @param registries The Registries to process
* @throws LdapException If the Syntaxes cannot be added
* @throws IOException If the Syntaxes cannot be loaded
*/
private void addSyntaxes( Schema schema, Registries registries ) throws LdapException, IOException
{
if ( schema.getSchemaLoader() == null )
{
return;
}
for ( Entry entry : schema.getSchemaLoader().loadSyntaxes( schema ) )
{
LdapSyntax syntax = factory.getSyntax( this, entry, registries, schema.getSchemaName() );
addSchemaObject( registries, syntax, schema );
}
}