/** * Store the given SchemaObject into the OidRegistry. Available only to * the current package. A weak form (no check is done) of the register * method, define for clone methods. * * @param schemaObject The SchemaObject to inject into the OidRegistry */ /* No qualifier */void put( SchemaObject schemaObject ) { byOid.put( schemaObject.getOid(), schemaObject ); }
/** * @see Object#toString() */ public String toString() { return "<" + schemaObject.getObjectType() + "," + schemaObject.getOid() + ">"; } }
/** * @see Object#toString() */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( schemaObjectType ).append( ": " ); boolean isFirst = true; for ( String name : byName.keySet() ) { if ( isFirst ) { isFirst = false; } else { sb.append( ", " ); } T schemaObject = byName.get( name ); sb.append( '<' ).append( name ).append( ", " ).append( schemaObject.getOid() ).append( '>' ); } return sb.toString(); }
/** * Compute the hash code for this wrapper. We only use the object type * and its oid. */ public int hashCode() { int h = 37; h += h * 17 + schemaObject.getObjectType().getValue(); h += h * 17 + schemaObject.getOid().hashCode(); return h; }
/** * {@inheritDoc} */ public String getOidByName( String name ) throws LdapException { T schemaObject = byName.get( name ); if ( schemaObject == null ) { // last resort before giving up check with lower cased version String lowerCased = name.toLowerCase(); schemaObject = byName.get( lowerCased ); // ok this name is not for a schema object in the registry if ( schemaObject == null ) { throw new LdapException( I18n.err( I18n.ERR_04274, name ) ); } } // we found the schema object by key on the first lookup attempt return schemaObject.getOid(); }
/** * Checks if a specific SchemaObject is referenced by any other SchemaObject. * * @param schemaObject The SchemaObject we are looking for * @return true if there is at least one SchemaObjetc referencing the given one */ public boolean isReferenced( SchemaObject schemaObject ) { SchemaObjectWrapper wrapper = new SchemaObjectWrapper( schemaObject ); Set<SchemaObjectWrapper> set = usedBy.get( wrapper ); boolean referenced = ( set != null ) && ( set.size() != 0 ); if ( LOG.isDebugEnabled() ) { if ( referenced ) { LOG.debug( "The {}:{} is referenced", schemaObject.getObjectType(), schemaObject.getOid() ); } else { LOG.debug( "The {}:{} is not referenced", schemaObject.getObjectType(), schemaObject.getOid() ); } } return referenced; }
/** * @see Object#equals(Object) */ public boolean equals( Object o ) { if ( o == this ) { return true; } if ( !( o instanceof SchemaObjectWrapper ) ) { return false; } SchemaObject that = ( ( SchemaObjectWrapper ) o ).get(); SchemaObject current = get(); return ( that.getOid().equals( current.getOid() ) && ( that.getObjectType() == current.getObjectType() ) ); }
.getOid() ); LOG.debug( "The {}:{} does not reference any " + message, reference.getObjectType(), reference.getOid() ); LOG.debug( "The {}:{} is not referenced by any " + message, referee.getObjectType(), referee.getOid() ); LOG.debug( "The {}:{} is not referenced by any " + message, referee.getObjectType(), referee.getOid() );
/** * Dump the Using data structure as a String */ public String dumpUsing() { StringBuilder sb = new StringBuilder(); sb.append( "USING :\n" ); for ( SchemaObjectWrapper wrapper : using.keySet() ) { sb.append( wrapper.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() ).append( "] : {" ); boolean isFirst = true; for ( SchemaObjectWrapper uses : using.get( wrapper ) ) { if ( isFirst ) { isFirst = false; } else { sb.append( ", " ); } sb.append( uses.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() ).append( "]" ); } sb.append( "}\n" ); } return sb.toString(); }
/** * {@inheritDoc} */ public void unregisterSchemaElements( String schemaName ) throws LdapException { if ( schemaName == null ) { return; } // Loop on all the SchemaObjects stored and remove those associated // with the give schemaName for ( T schemaObject : this ) { if ( schemaName.equalsIgnoreCase( schemaObject.getSchemaName() ) ) { String oid = schemaObject.getOid(); SchemaObject removed = unregister( oid ); if ( DEBUG ) { LOG.debug( "Removed {} with oid {} from the registry", removed, oid ); } } } }
/** * Dump the UsedBy data structure as a String */ public String dumpUsedBy() { StringBuilder sb = new StringBuilder(); sb.append( "USED BY :\n" ); for ( SchemaObjectWrapper wrapper : usedBy.keySet() ) { sb.append( wrapper.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() ).append( "] : {" ); boolean isFirst = true; for ( SchemaObjectWrapper uses : usedBy.get( wrapper ) ) { if ( isFirst ) { isFirst = false; } else { sb.append( ", " ); } sb.append( uses.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() ).append( "]" ); } sb.append( "}\n" ); } return sb.toString(); }
/** * Get the inner SchemaObject if it's not a C/N/SC */ private SchemaObject getSchemaObject( SchemaObject schemaObject ) throws LdapException { if ( schemaObject instanceof LoadableSchemaObject ) { return schemaObject; } else { return registries.getGlobalOidRegistry().getSchemaObject( schemaObject.getOid() ); } }
/** * Get an OID from an entry. Handles the bad cases (null OID, * not a valid OID, ...) */ private String getOid( SchemaObject description, String objectType ) throws LdapInvalidAttributeValueException { // The OID String oid = description.getOid(); if ( oid == null ) { String msg = I18n.err( I18n.ERR_10005, objectType, MetaSchemaConstants.M_OID_AT ); LOG.warn( msg ); throw new NullPointerException( msg ); } if ( !OID.isOID( oid ) ) { String msg = I18n.err( I18n.ERR_10006, oid ); LOG.warn( msg ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg ); } return oid; }
/** * Check that the given OID exists in the globalOidRegistry. */ private boolean checkOidExist( SchemaObject schemaObject ) { if ( !( schemaObject instanceof LoadableSchemaObject ) ) { return registries.getGlobalOidRegistry().contains( schemaObject.getOid() ); } if ( schemaObject instanceof LdapComparator<?> ) { return registries.getComparatorRegistry().contains( schemaObject.getOid() ); } if ( schemaObject instanceof SyntaxChecker ) { return registries.getSyntaxCheckerRegistry().contains( schemaObject.getOid() ); } if ( schemaObject instanceof Normalizer ) { return registries.getNormalizerRegistry().contains( schemaObject.getOid() ); } return false; }
String oid = schemaObject.getOid();
private SchemaObject copy( SchemaObject schemaObject ) { SchemaObject copy = null; if ( !( schemaObject instanceof LoadableSchemaObject ) ) { copy = schemaObject.copy(); } else { // Check the schemaObject here. if ( ( ( LoadableSchemaObject ) schemaObject ).isValid() ) { copy = schemaObject; } else { // We have an invalid SchemaObject, no need to go any further Throwable error = new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_11007, schemaObject.getOid() ) ); errors.add( error ); } } return copy; }
/** * {@inheritDoc} */ public T unregister( T schemaObject ) throws LdapException { String oid = schemaObject.getOid(); if ( !byName.containsKey( oid ) ) { String msg = I18n.err( I18n.ERR_04273, schemaObjectType.name(), oid ); LOG.warn( msg ); throw new LdapException( msg ); } // Remove the oid T removed = byName.remove( oid ); /* * Remove the aliases/names from the name map along with their toLowerCase * versions of the name. */ for ( String name : schemaObject.getNames() ) { byName.remove( StringTools.trim( StringTools.toLowerCase( name ) ) ); } // And unregister the oid -> schemaObject relation oidRegistry.unregister( oid ); return removed; }
private final void injectCommon( SchemaObject object, ServerEntry entry, SchemaManager schemaManager ) throws LdapException { injectNames( object.getNames(), entry, schemaManager ); entry.put( MetaSchemaConstants.M_OBSOLETE_AT, getBoolean( object.isObsolete() ) ); entry.put( MetaSchemaConstants.M_OID_AT, object.getOid() ); if ( object.getDescription() != null ) { entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, object.getDescription() ); } }