Author: akarasulu Date: Thu Oct 28 00:46:28 2004 New Revision: 55795 Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalAttributeTypeRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalComparatorRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalDitContentRuleRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalDitStructureRuleRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalMatchingRuleRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalMatchingRuleUseRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalNameFormRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalNormalizerRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalObjectClassRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalOidRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalSyntaxCheckerRegistry.java incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalSyntaxRegistry.java Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapAttributeTypeRegistry.java Log: adding all the global registries
Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalAttributeTypeRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalAttributeTypeRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,202 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import java.util.Iterator; +import javax.naming.NamingException; + +import org.apache.ldap.common.util.JoinIterator; +import org.apache.ldap.common.schema.AttributeType; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapAttributeTypeRegistry; + + +/** + * A plain old java object implementation of an AttributeTypeRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalAttributeTypeRegistry implements AttributeTypeRegistry +{ + /** maps an OID to an AttributeType */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private AttributeTypeRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapAttributeTypeRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates a GlobalAttributeTypeRegistry which accesses data stored within + * the system partition and within the bootstrapping registry to service + * AttributeType lookup requests. + * + * @param systemPartition the system database partition under ou=system + * @param bootstrap the bootstrapping registry to delegate to + */ + public GlobalAttributeTypeRegistry( SystemPartition systemPartition, + BootstrapAttributeTypeRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.monitor = new AttributeTypeRegistryMonitorAdapter(); + + this.oidRegistry = oidRegistry; + if ( this.oidRegistry == null ) + { + throw new NullPointerException( "the OID registry cannot be null" ) ; + } + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( AttributeTypeRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, AttributeType attributeType ) throws NamingException + { + if ( byOid.containsKey( attributeType.getOid() ) || + bootstrap.hasAttributeType( attributeType.getOid() ) ) + { + NamingException e = new NamingException( "attributeType w/ OID " + + attributeType.getOid() + " has already been registered!" ); + monitor.registerFailed( attributeType, e ); + throw e; + } + + String[] names = attributeType.getNames(); + for ( int ii = 0; ii < names.length; ii++ ) + { + oidRegistry.register( names[ii], attributeType.getOid() ); + } + + oidToSchema.put( attributeType.getOid(), schema ); + byOid.put( attributeType.getOid(), attributeType ); + monitor.registered( attributeType ); + } + + + public AttributeType lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( ! ( byOid.containsKey( id ) || bootstrap.hasAttributeType( id ) ) ) + { + NamingException e = new NamingException( "attributeType w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + AttributeType attributeType = ( AttributeType ) byOid.get( id ); + + if ( attributeType == null ) + { + attributeType = bootstrap.lookup( id ); + } + + monitor.lookedUp( attributeType ); + return attributeType; + } + + + public boolean hasAttributeType( String id ) + { + try + { + + if ( oidRegistry.hasOid( id ) ) + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasAttributeType( id ); + } + } + catch ( NamingException e ) + { + return false; + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.getSchemaName( id ) != null ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } + + + + public Iterator list() + { + return new JoinIterator( new Iterator[] + { byOid.values().iterator(),bootstrap.list() } ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalComparatorRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalComparatorRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,166 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import java.util.Comparator; +import javax.naming.NamingException; + +import org.apache.eve.schema.bootstrap.BootstrapComparatorRegistry; +import org.apache.eve.SystemPartition; + + +/** + * A simple POJO implementation of the ComparatorRegistry service interface. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalComparatorRegistry implements ComparatorRegistry +{ + /** the comparators in this registry */ + private final Map comparators; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the monitor for delivering callback events */ + private ComparatorRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapComparatorRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates a default ComparatorRegistry by initializing the map and the + * montior. + */ + public GlobalComparatorRegistry( SystemPartition systemPartition, + BootstrapComparatorRegistry bootstrap ) + { + this.oidToSchema = new HashMap(); + this.comparators = new HashMap(); + this.monitor = new ComparatorRegistryMonitorAdapter(); + + // override bootstrap registry used by serializable comparators + SerializableComparator.setRegistry( this ); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor used by this registry. + * + * @param monitor the monitor to set for registry event callbacks + */ + public void setMonitor( ComparatorRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, String oid, Comparator comparator ) + throws NamingException + { + if ( comparators.containsKey( oid ) || bootstrap.hasComparator( oid ) ) + { + NamingException e = new NamingException( "Comparator with OID " + + oid + " already registered!" ); + monitor.registerFailed( oid, comparator, e ); + throw e; + } + + oidToSchema.put( oid, schema ); + comparators.put( oid, comparator ); + monitor.registered( oid, comparator ); + } + + + public Comparator lookup( String oid ) throws NamingException + { + Comparator c; + NamingException e; + + if ( comparators.containsKey( oid ) ) + { + c = ( Comparator ) comparators.get( oid ); + monitor.lookedUp( oid, c ); + return c; + } + + if ( bootstrap.hasComparator( oid ) ) + { + c = ( Comparator ) bootstrap.lookup( oid ); + monitor.lookedUp( oid, c ); + return c; + } + + e = new NamingException( "Comparator not found for OID: " + oid ); + monitor.lookupFailed( oid, e ); + throw e; + } + + + public boolean hasComparator( String oid ) + { + return comparators.containsKey( oid ) || bootstrap.hasComparator( oid ); + } + + + public String getSchemaName( String oid ) throws NamingException + { + if ( ! Character.isDigit( oid.charAt( 0 ) ) ) + { + throw new NamingException( "OID " + oid + " is not a numeric OID" ); + } + + if ( oidToSchema.containsKey( oid ) ) + { + return ( String ) oidToSchema.get( oid ); + } + + if ( bootstrap.hasComparator( oid ) ) + { + return bootstrap.getSchemaName( oid ); + } + + throw new NamingException( "OID " + oid + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalDitContentRuleRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalDitContentRuleRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.DITContentRule; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapDitContentRuleRegistry; + + +/** + * A plain old java object implementation of an DITContentRuleRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalDitContentRuleRegistry implements DITContentRuleRegistry +{ + /** maps an OID to an DITContentRule */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private DITContentRuleRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapDitContentRuleRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapDitContentRuleRegistry. + */ + public GlobalDitContentRuleRegistry( SystemPartition systemPartition, + BootstrapDitContentRuleRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new DITContentRuleRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( DITContentRuleRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, DITContentRule dITContentRule ) throws NamingException + { + if ( byOid.containsKey( dITContentRule.getOid() ) || + bootstrap.hasDITContentRule( dITContentRule.getOid() ) ) + { + NamingException e = new NamingException( "dITContentRule w/ OID " + + dITContentRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITContentRule, e ); + throw e; + } + + oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; + byOid.put( dITContentRule.getOid(), dITContentRule ); + oidToSchema.put( dITContentRule.getOid(), schema ); + monitor.registered( dITContentRule ); + } + + + public DITContentRule lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + DITContentRule dITContentRule = ( DITContentRule ) byOid.get( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + if ( bootstrap.hasDITContentRule( id ) ) + { + DITContentRule dITContentRule = bootstrap.lookup( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + NamingException e = new NamingException( "dITContentRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasDITContentRule( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasDITContentRule( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasDITContentRule( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalDitStructureRuleRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalDitStructureRuleRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.DITStructureRule; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapDitStructureRuleRegistry; + + +/** + * A plain old java object implementation of an DITStructureRuleRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalDitStructureRuleRegistry implements DITStructureRuleRegistry +{ + /** maps an OID to an DITStructureRule */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private DITStructureRuleRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapDitStructureRuleRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapDitStructureRuleRegistry. + */ + public GlobalDitStructureRuleRegistry( SystemPartition systemPartition, + BootstrapDitStructureRuleRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new DITStructureRuleRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( DITStructureRuleRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, DITStructureRule dITStructureRule ) throws NamingException + { + if ( byOid.containsKey( dITStructureRule.getOid() ) || + bootstrap.hasDITStructureRule( dITStructureRule.getOid() ) ) + { + NamingException e = new NamingException( "dITStructureRule w/ OID " + + dITStructureRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITStructureRule, e ); + throw e; + } + + oidRegistry.register( dITStructureRule.getName(), dITStructureRule.getOid() ) ; + byOid.put( dITStructureRule.getOid(), dITStructureRule ); + oidToSchema.put( dITStructureRule.getOid(), schema ); + monitor.registered( dITStructureRule ); + } + + + public DITStructureRule lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + DITStructureRule dITStructureRule = ( DITStructureRule ) byOid.get( id ); + monitor.lookedUp( dITStructureRule ); + return dITStructureRule; + } + + if ( bootstrap.hasDITStructureRule( id ) ) + { + DITStructureRule dITStructureRule = bootstrap.lookup( id ); + monitor.lookedUp( dITStructureRule ); + return dITStructureRule; + } + + NamingException e = new NamingException( "dITStructureRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasDITStructureRule( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasDITStructureRule( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasDITStructureRule( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalMatchingRuleRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalMatchingRuleRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.MatchingRule; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapMatchingRuleRegistry; + + +/** + * A plain old java object implementation of an MatchingRuleRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalMatchingRuleRegistry implements MatchingRuleRegistry +{ + /** maps an OID to an MatchingRule */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private MatchingRuleRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapMatchingRuleRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapMatchingRuleRegistry. + */ + public GlobalMatchingRuleRegistry( SystemPartition systemPartition, + BootstrapMatchingRuleRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new MatchingRuleRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( MatchingRuleRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, MatchingRule dITContentRule ) throws NamingException + { + if ( byOid.containsKey( dITContentRule.getOid() ) || + bootstrap.hasMatchingRule( dITContentRule.getOid() ) ) + { + NamingException e = new NamingException( "dITContentRule w/ OID " + + dITContentRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITContentRule, e ); + throw e; + } + + oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; + byOid.put( dITContentRule.getOid(), dITContentRule ); + oidToSchema.put( dITContentRule.getOid(), schema ); + monitor.registered( dITContentRule ); + } + + + public MatchingRule lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + MatchingRule dITContentRule = ( MatchingRule ) byOid.get( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + if ( bootstrap.hasMatchingRule( id ) ) + { + MatchingRule dITContentRule = bootstrap.lookup( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + NamingException e = new NamingException( "dITContentRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasMatchingRule( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasMatchingRule( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasMatchingRule( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalMatchingRuleUseRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalMatchingRuleUseRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.MatchingRuleUse; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapMatchingRuleUseRegistry; + + +/** + * A plain old java object implementation of an MatchingRuleUseRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalMatchingRuleUseRegistry implements MatchingRuleUseRegistry +{ + /** maps an OID to an MatchingRuleUse */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private MatchingRuleUseRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapMatchingRuleUseRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapMatchingRuleUseRegistry. + */ + public GlobalMatchingRuleUseRegistry( SystemPartition systemPartition, + BootstrapMatchingRuleUseRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new MatchingRuleUseRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( MatchingRuleUseRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, MatchingRuleUse dITContentRule ) throws NamingException + { + if ( byOid.containsKey( dITContentRule.getOid() ) || + bootstrap.hasMatchingRuleUse( dITContentRule.getOid() ) ) + { + NamingException e = new NamingException( "dITContentRule w/ OID " + + dITContentRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITContentRule, e ); + throw e; + } + + oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; + byOid.put( dITContentRule.getOid(), dITContentRule ); + oidToSchema.put( dITContentRule.getOid(), schema ); + monitor.registered( dITContentRule ); + } + + + public MatchingRuleUse lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + MatchingRuleUse dITContentRule = ( MatchingRuleUse ) byOid.get( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + if ( bootstrap.hasMatchingRuleUse( id ) ) + { + MatchingRuleUse dITContentRule = bootstrap.lookup( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + NamingException e = new NamingException( "dITContentRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasMatchingRuleUse( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasMatchingRuleUse( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasMatchingRuleUse( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalNameFormRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalNameFormRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.NameForm; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapNameFormRegistry; + + +/** + * A plain old java object implementation of an NameFormRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalNameFormRegistry implements NameFormRegistry +{ + /** maps an OID to an NameForm */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private NameFormRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapNameFormRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapNameFormRegistry. + */ + public GlobalNameFormRegistry( SystemPartition systemPartition, + BootstrapNameFormRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new NameFormRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( NameFormRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, NameForm dITContentRule ) throws NamingException + { + if ( byOid.containsKey( dITContentRule.getOid() ) || + bootstrap.hasNameForm( dITContentRule.getOid() ) ) + { + NamingException e = new NamingException( "dITContentRule w/ OID " + + dITContentRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITContentRule, e ); + throw e; + } + + oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; + byOid.put( dITContentRule.getOid(), dITContentRule ); + oidToSchema.put( dITContentRule.getOid(), schema ); + monitor.registered( dITContentRule ); + } + + + public NameForm lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + NameForm dITContentRule = ( NameForm ) byOid.get( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + if ( bootstrap.hasNameForm( id ) ) + { + NameForm dITContentRule = bootstrap.lookup( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + NamingException e = new NamingException( "dITContentRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasNameForm( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasNameForm( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasNameForm( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalNormalizerRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalNormalizerRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,164 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.Normalizer; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapNormalizerRegistry; + + +/** + * A simple POJO implementation of the NormalizerRegistry service interface. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalNormalizerRegistry implements NormalizerRegistry +{ + /** the normalizers in this registry */ + private final Map normalizers; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the monitor for delivering callback events */ + private NormalizerRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapNormalizerRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates a default NormalizerRegistry by initializing the map and the + * montior. + */ + public GlobalNormalizerRegistry( SystemPartition systemPartition, + BootstrapNormalizerRegistry bootstrap ) + { + this.oidToSchema = new HashMap(); + this.normalizers = new HashMap(); + this.monitor = new NormalizerRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor used by this registry. + * + * @param monitor the monitor to set for registry event callbacks + */ + public void setMonitor( NormalizerRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, String oid, Normalizer normalizer ) + throws NamingException + { + if ( normalizers.containsKey( oid ) || bootstrap.hasNormalizer( oid ) ) + { + NamingException e = new NamingException( "Normalizer with OID " + + oid + " already registered!" ); + monitor.registerFailed( oid, normalizer, e ); + throw e; + } + + oidToSchema.put( oid, schema ); + normalizers.put( oid, normalizer ); + monitor.registered( oid, normalizer ); + } + + + public Normalizer lookup( String oid ) throws NamingException + { + Normalizer c; + NamingException e; + + if ( normalizers.containsKey( oid ) ) + { + c = ( Normalizer ) normalizers.get( oid ); + monitor.lookedUp( oid, c ); + return c; + } + + if ( bootstrap.hasNormalizer( oid ) ) + { + c = ( Normalizer ) bootstrap.lookup( oid ); + monitor.lookedUp( oid, c ); + return c; + } + + e = new NamingException( "Normalizer not found for OID: " + oid ); + monitor.lookupFailed( oid, e ); + throw e; + } + + + public boolean hasNormalizer( String oid ) + { + return normalizers.containsKey( oid ) || bootstrap.hasNormalizer( oid ); + } + + + public String getSchemaName( String oid ) throws NamingException + { + if ( ! Character.isDigit( oid.charAt( 0 ) ) ) + { + throw new NamingException( "OID " + oid + " is not a numeric OID" ); + } + + if ( oidToSchema.containsKey( oid ) ) + { + return ( String ) oidToSchema.get( oid ); + } + + if ( bootstrap.hasNormalizer( oid ) ) + { + return bootstrap.getSchemaName( oid ); + } + + throw new NamingException( "OID " + oid + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalObjectClassRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalObjectClassRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.ObjectClass; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapObjectClassRegistry; + + +/** + * A plain old java object implementation of an ObjectClassRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalObjectClassRegistry implements ObjectClassRegistry +{ + /** maps an OID to an ObjectClass */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private ObjectClassRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapObjectClassRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapObjectClassRegistry. + */ + public GlobalObjectClassRegistry( SystemPartition systemPartition, + BootstrapObjectClassRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new ObjectClassRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( ObjectClassRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, ObjectClass dITContentRule ) throws NamingException + { + if ( byOid.containsKey( dITContentRule.getOid() ) || + bootstrap.hasObjectClass( dITContentRule.getOid() ) ) + { + NamingException e = new NamingException( "dITContentRule w/ OID " + + dITContentRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITContentRule, e ); + throw e; + } + + oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; + byOid.put( dITContentRule.getOid(), dITContentRule ); + oidToSchema.put( dITContentRule.getOid(), schema ); + monitor.registered( dITContentRule ); + } + + + public ObjectClass lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + ObjectClass dITContentRule = ( ObjectClass ) byOid.get( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + if ( bootstrap.hasObjectClass( id ) ) + { + ObjectClass dITContentRule = bootstrap.lookup( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + NamingException e = new NamingException( "dITContentRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasObjectClass( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasObjectClass( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasObjectClass( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalOidRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalOidRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,320 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Collections; + +import javax.naming.NamingException; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapOidRegistry; + + +/** + * Default OID registry implementation used to resolve a schema object OID + * to a name and vice-versa. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev: 55327 $ + */ +public class GlobalOidRegistry implements OidRegistry +{ + /** Maps OID to a name or a list of names if more than one name exists */ + private Hashtable byOid = new Hashtable(); + /** Maps several names to an OID */ + private Hashtable byName = new Hashtable(); + /** Default OidRegistryMonitor */ + private OidRegistryMonitor monitor = new OidRegistryMonitorAdapter(); + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapOidRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates a default OidRegistry by initializing the map and the montior. + */ + public GlobalOidRegistry( SystemPartition systemPartition, + BootstrapOidRegistry bootstrap ) + { + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + + + /** + * Gets the monitor. + * + * @return the monitor + */ + OidRegistryMonitor getMonitor() + { + return monitor; + } + + + /** + * Sets the monitor. + * + * @param monitor monitor to set. + */ + void setMonitor( OidRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + /** + * @see OidRegistry#getOid(String) + */ + public String getOid( String name ) throws NamingException + { + if ( name == null ) + { + throw new NamingException( "name should not be null" ); + } + + /* If name is an OID than we return it back since inherently the + * OID is another name for the object referred to by OID and the + * caller does not know that the argument is an OID String. + */ + if ( Character.isDigit( name.charAt( 0 ) ) ) + { + monitor.getOidWithOid( name ); + return name; + } + + // If name is mapped to a OID already return OID + if ( byName.containsKey( name ) ) + { + String oid = ( String ) byName.get( name ); + monitor.oidResolved( name, oid ); + return oid; + } + + if ( bootstrap.hasOid( name ) ) + { + String oid = bootstrap.getOid( name ); + monitor.oidResolved( name, oid ); + return oid; + } + + /* + * As a last resort we check if name is not normalized and if the + * normalized version used as a key returns an OID. If the normalized + * name works add the normalized name as a key with its OID to the + * byName lookup. BTW these normalized versions of the key are not + * returned on a getNameSet. + */ + String lowerCase = name.trim().toLowerCase(); + if ( ! name.equals( lowerCase ) + && byName.containsKey( lowerCase ) ) + { + String oid = ( String ) byName.get( lowerCase ); + monitor.oidResolved( name, lowerCase, oid ); + + // We expect to see this version of the key again so we add it + byName.put( name, oid ); + return oid; + } + + NamingException fault = new NamingException ( "OID for name '" + + name + "' was not " + "found within the OID registry" ); + monitor.oidResolutionFailed( name, fault ); + throw fault; + } + + + /** + * @see OidRegistry#hasOid(String) + */ + public boolean hasOid( String name ) + { + return this.byName.contains( name ) || this.byOid.contains( name ); + } + + + /** + * @see OidRegistry#getPrimaryName(String) + */ + public String getPrimaryName( String oid ) throws NamingException + { + Object value = byOid.get( oid ); + + if ( null == value ) + { + NamingException fault = new NamingException ( "OID '" + oid + + "' was not found within the OID registry" ); + monitor.oidDoesNotExist( oid, fault ); + throw fault; + } + + if ( value instanceof String ) + { + monitor.nameResolved( oid, ( String ) value ); + return ( String ) value; + } + + String name = ( String ) ( ( List ) value ).get( 0 ); + monitor.nameResolved( oid, name ); + return name; + } + + + /** + * @see OidRegistry#getNameSet(String) + */ + public List getNameSet( String oid ) throws NamingException + { + Object value = byOid.get( oid ); + + if ( null == value ) + { + NamingException fault = new NamingException ( "OID '" + oid + + "' was not found within the OID registry" ); + monitor.oidDoesNotExist( oid, fault ); + throw fault; + } + + if ( value instanceof String ) + { + List list = Collections.singletonList( value ); + monitor.namesResolved( oid, list ); + return list; + } + + monitor.namesResolved( oid, ( List ) value ); + return ( List ) value; + } + + + /** + * @see OidRegistry#list() + */ + public Iterator list() + { + return Collections.unmodifiableSet( byOid.keySet() ).iterator(); + } + + + /** + * @see OidRegistry#register(String, String) + */ + public void register( String name, String oid ) + { + if ( ! Character.isDigit( oid.charAt( 0 ) ) ) + { + throw new RuntimeException( "Swap the parameter order: the oid " + + "does not start with a digit!" ); + } + + /* + * Add the entry for the given name as is and its lowercased version if + * the lower cased name is different from the given name name. + */ + String lowerCase = name.toLowerCase(); + if ( ! lowerCase.equals( name ) ) + { + byName.put( lowerCase, oid ); + } + + // Put both the name and the oid as names + byName.put( name, oid ); + byName.put( oid, oid ); + + /* + * Update OID Map + * + * 1). Check if we already have a value[s] stored + * 1a). Value is a single value and is a String + * Replace value with list containing old and new values + * 1b). More than one value stored in a list + * Add new value to the list + * 2). If we do not have a value then we just add it as a String + */ + Object value = null; + if ( ! byOid.containsKey( oid ) ) + { + value = name; + } + else + { + ArrayList list = null; + value = byOid.get( oid ); + + if ( value instanceof String ) + { + String existingName = ( String ) value; + + // if the existing name is already there we don't readd it + if ( existingName.equalsIgnoreCase( name ) ) + { + return; + } + + list = new ArrayList(); + list.add( value ); + value = list; + } + else if ( value instanceof ArrayList ) + { + list = ( ArrayList ) value; + + for ( int ii = 0; ii < list.size(); ii++ ) + { + // One form or another of the name already exists in list + if ( ! name.equalsIgnoreCase( ( String ) list.get( ii ) ) ) + { + return; + } + } + + list.add( name ); + } + } + + byOid.put( oid, value ); + monitor.registered( name, oid ); + } +} + Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalSyntaxCheckerRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalSyntaxCheckerRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,164 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.SyntaxChecker; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapSyntaxCheckerRegistry; + + +/** + * A simple POJO implementation of the SyntaxCheckerRegistry service interface. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalSyntaxCheckerRegistry implements SyntaxCheckerRegistry +{ + /** the syntaxCheckers in this registry */ + private final Map syntaxCheckers; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the monitor for delivering callback events */ + private SyntaxCheckerRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapSyntaxCheckerRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates a default SyntaxCheckerRegistry by initializing the map and the + * montior. + */ + public GlobalSyntaxCheckerRegistry( SystemPartition systemPartition, + BootstrapSyntaxCheckerRegistry bootstrap ) + { + this.oidToSchema = new HashMap(); + this.syntaxCheckers = new HashMap(); + this.monitor = new SyntaxCheckerRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor used by this registry. + * + * @param monitor the monitor to set for registry event callbacks + */ + public void setMonitor( SyntaxCheckerRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, String oid, SyntaxChecker syntaxChecker ) + throws NamingException + { + if ( syntaxCheckers.containsKey( oid ) || bootstrap.hasSyntaxChecker( oid ) ) + { + NamingException e = new NamingException( "SyntaxChecker with OID " + + oid + " already registered!" ); + monitor.registerFailed( oid, syntaxChecker, e ); + throw e; + } + + oidToSchema.put( oid, schema ); + syntaxCheckers.put( oid, syntaxChecker ); + monitor.registered( oid, syntaxChecker ); + } + + + public SyntaxChecker lookup( String oid ) throws NamingException + { + SyntaxChecker c; + NamingException e; + + if ( syntaxCheckers.containsKey( oid ) ) + { + c = ( SyntaxChecker ) syntaxCheckers.get( oid ); + monitor.lookedUp( oid, c ); + return c; + } + + if ( bootstrap.hasSyntaxChecker( oid ) ) + { + c = ( SyntaxChecker ) bootstrap.lookup( oid ); + monitor.lookedUp( oid, c ); + return c; + } + + e = new NamingException( "SyntaxChecker not found for OID: " + oid ); + monitor.lookupFailed( oid, e ); + throw e; + } + + + public boolean hasSyntaxChecker( String oid ) + { + return syntaxCheckers.containsKey( oid ) || bootstrap.hasSyntaxChecker( oid ); + } + + + public String getSchemaName( String oid ) throws NamingException + { + if ( ! Character.isDigit( oid.charAt( 0 ) ) ) + { + throw new NamingException( "OID " + oid + " is not a numeric OID" ); + } + + if ( oidToSchema.containsKey( oid ) ) + { + return ( String ) oidToSchema.get( oid ); + } + + if ( bootstrap.hasSyntaxChecker( oid ) ) + { + return bootstrap.getSchemaName( oid ); + } + + throw new NamingException( "OID " + oid + " not found in oid to " + + "schema name map!" ); + } +} Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalSyntaxRegistry.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/GlobalSyntaxRegistry.java Thu Oct 28 00:46:28 2004 @@ -0,0 +1,177 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.schema; + + +import java.util.Map; +import java.util.HashMap; +import javax.naming.NamingException; + +import org.apache.ldap.common.schema.Syntax; + +import org.apache.eve.SystemPartition; +import org.apache.eve.schema.bootstrap.BootstrapSyntaxRegistry; + + +/** + * A plain old java object implementation of an SyntaxRegistry. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a> + * @version $Rev$ + */ +public class GlobalSyntaxRegistry implements SyntaxRegistry +{ + /** maps an OID to an Syntax */ + private final Map byOid; + /** maps an OID to a schema name*/ + private final Map oidToSchema; + /** the registry used to resolve names to OIDs */ + private final OidRegistry oidRegistry; + /** monitor notified via callback events */ + private SyntaxRegistryMonitor monitor; + /** the underlying bootstrap registry to delegate on misses to */ + private BootstrapSyntaxRegistry bootstrap; + /** the system partition where we keep attributeType updates */ + private SystemPartition systemPartition; + + + // ------------------------------------------------------------------------ + // C O N S T R U C T O R S + // ------------------------------------------------------------------------ + + + /** + * Creates an empty BootstrapSyntaxRegistry. + */ + public GlobalSyntaxRegistry( SystemPartition systemPartition, + BootstrapSyntaxRegistry bootstrap, OidRegistry oidRegistry ) + { + this.byOid = new HashMap(); + this.oidToSchema = new HashMap(); + this.oidRegistry = oidRegistry; + this.monitor = new SyntaxRegistryMonitorAdapter(); + + this.bootstrap = bootstrap; + if ( this.bootstrap == null ) + { + throw new NullPointerException( "the bootstrap registry cannot be null" ) ; + } + + this.systemPartition = systemPartition; + if ( this.systemPartition == null ) + { + throw new NullPointerException( "the system partition cannot be null" ) ; + } + } + + + /** + * Sets the monitor that is to be notified via callback events. + * + * @param monitor the new monitor to notify of notable events + */ + public void setMonitor( SyntaxRegistryMonitor monitor ) + { + this.monitor = monitor; + } + + + // ------------------------------------------------------------------------ + // Service Methods + // ------------------------------------------------------------------------ + + + public void register( String schema, Syntax dITContentRule ) throws NamingException + { + if ( byOid.containsKey( dITContentRule.getOid() ) || + bootstrap.hasSyntax( dITContentRule.getOid() ) ) + { + NamingException e = new NamingException( "dITContentRule w/ OID " + + dITContentRule.getOid() + " has already been registered!" ); + monitor.registerFailed( dITContentRule, e ); + throw e; + } + + oidRegistry.register( dITContentRule.getName(), dITContentRule.getOid() ) ; + byOid.put( dITContentRule.getOid(), dITContentRule ); + oidToSchema.put( dITContentRule.getOid(), schema ); + monitor.registered( dITContentRule ); + } + + + public Syntax lookup( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( byOid.containsKey( id ) ) + { + Syntax dITContentRule = ( Syntax ) byOid.get( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + if ( bootstrap.hasSyntax( id ) ) + { + Syntax dITContentRule = bootstrap.lookup( id ); + monitor.lookedUp( dITContentRule ); + return dITContentRule; + } + + NamingException e = new NamingException( "dITContentRule w/ OID " + + id + " not registered!" ); + monitor.lookupFailed( id, e ); + throw e; + } + + + public boolean hasSyntax( String id ) + { + if ( oidRegistry.hasOid( id ) ) + { + try + { + return byOid.containsKey( oidRegistry.getOid( id ) ) || + bootstrap.hasSyntax( id ); + } + catch ( NamingException e ) + { + return false; + } + } + + return false; + } + + + public String getSchemaName( String id ) throws NamingException + { + id = oidRegistry.getOid( id ); + + if ( oidToSchema.containsKey( id ) ) + { + return ( String ) oidToSchema.get( id ); + } + + if ( bootstrap.hasSyntax( id ) ) + { + return bootstrap.getSchemaName( id ); + } + + throw new NamingException( "OID " + id + " not found in oid to " + + "schema name map!" ); + } +} Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapAttributeTypeRegistry.java ============================================================================== --- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapAttributeTypeRegistry.java (original) +++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/bootstrap/BootstrapAttributeTypeRegistry.java Thu Oct 28 00:46:28 2004 @@ -151,8 +151,7 @@ } - - Iterator list() + public Iterator list() { return byOid.values().iterator(); }
