You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/09/28 05:55:34 UTC
svn commit: rev 47383 - in incubator/directory/eve/trunk/backend: api/src/java/org/apache/eve/schema impl/src/java/org/apache/eve/schema
Author: akarasulu
Date: Mon Sep 27 20:55:32 2004
New Revision: 47383
Added:
incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultComparatorRegistry.java (contents, props changed)
Modified:
incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistry.java
incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistryMonitor.java
incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultMatchingRuleRegistry.java
Log:
More code cleanup and implemented the POJO for ComparatorRegistry service.
Modified: incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistry.java
==============================================================================
--- incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistry.java (original)
+++ incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistry.java Mon Sep 27 20:55:32 2004
@@ -33,11 +33,12 @@
/**
* Registers a Comparator with this registry.
*
+ * @param oid the object identifier
* @param comparator the Comparator to register
* @throws NamingException if the Comparator is already registered or the
* registration operation is not supported
*/
- void register( Comparator comparator, String oid ) throws NamingException;
+ void register( String oid, Comparator comparator ) throws NamingException;
/**
* Looks up a Comparator by its unique Object Identifier.
Modified: incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistryMonitor.java
==============================================================================
--- incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistryMonitor.java (original)
+++ incubator/directory/eve/trunk/backend/api/src/java/org/apache/eve/schema/ComparatorRegistryMonitor.java Mon Sep 27 20:55:32 2004
@@ -33,16 +33,18 @@
/**
* Monitors when a Comparator is registered successfully.
*
+ * @param oid OID key used for registration
* @param comparator the Comparator registered
*/
- void registered( Comparator comparator );
+ void registered( String oid, Comparator comparator );
/**
* Monitors when a Comparator is successfully looked up.
*
+ * @param oid OID key used for registration
* @param comparator the Comparator looked up
*/
- void lookedUp( Comparator comparator );
+ void lookedUp( String oid, Comparator comparator );
/**
* Monitors when a lookup attempt fails.
@@ -55,8 +57,9 @@
/**
* Monitors when a registration attempt fails.
*
+ * @param oid OID key used for registration
* @param comparator the Comparator which failed registration
* @param fault the exception to be thrown for the fault
*/
- void registerFailed( Comparator comparator, NamingException fault );
+ void registerFailed( String oid, Comparator comparator, NamingException fault );
}
Added: incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultComparatorRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultComparatorRegistry.java Mon Sep 27 20:55:32 2004
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+
+/**
+ * A simple POJO implementation of the ComparatorRegistry service interface.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultComparatorRegistry implements ComparatorRegistry
+{
+ /** the comparators in this registry */
+ private final Map comparators;
+ /** the monitor for delivering callback events */
+ private ComparatorRegistryMonitor monitor;
+
+
+ // ------------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Creates a default ComparatorRegistry by initializing the map and the
+ * montior.
+ */
+ public DefaultComparatorRegistry()
+ {
+ comparators = new HashMap();
+ monitor = new ComparatorRegistryMonitorAdapter();
+ }
+
+
+ /**
+ * 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 oid, Comparator comparator ) throws NamingException
+ {
+ if ( comparators.containsKey( oid ) )
+ {
+ NamingException e = new NamingException( "Comparator with OID "
+ + oid + " already registered!" );
+ monitor.registerFailed( oid, comparator, e );
+ throw e;
+ }
+
+ monitor.registered( oid, comparator );
+ comparators.put( oid, comparator );
+ }
+
+
+ public Comparator lookup( String oid ) throws NamingException
+ {
+ if ( ! comparators.containsKey( oid ) )
+ {
+ Comparator c = ( Comparator ) comparators.get( oid );
+ monitor.lookedUp( oid, c );
+ return c;
+ }
+
+
+ NamingException e = new NamingException( "Comparator not found for OID" );
+ monitor.lookupFailed( oid, e );
+ throw e;
+ }
+
+
+ public boolean hasComparator( String oid )
+ {
+ return comparators.containsKey( oid );
+ }
+}
Modified: incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultMatchingRuleRegistry.java
==============================================================================
--- incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultMatchingRuleRegistry.java (original)
+++ incubator/directory/eve/trunk/backend/impl/src/java/org/apache/eve/schema/DefaultMatchingRuleRegistry.java Mon Sep 27 20:55:32 2004
@@ -52,10 +52,9 @@
* @param matchingRules a map of OIDs to their respective MatchingRule objs
*/
public DefaultMatchingRuleRegistry( MatchingRule[] matchingRules,
- OidRegistry registry )
+ OidRegistry registry )
{
- this ( matchingRules, registry,
- new MatchingRuleRegistryMonitorAdapter() );
+ this ( matchingRules, registry, new MatchingRuleRegistryMonitorAdapter() );
}
@@ -66,8 +65,8 @@
* @param matchingRules a map of OIDs to their respective MatchingRule objs
*/
public DefaultMatchingRuleRegistry( MatchingRule[] matchingRules,
- OidRegistry registry,
- MatchingRuleRegistryMonitor monitor )
+ OidRegistry registry,
+ MatchingRuleRegistryMonitor monitor )
{
this.monitor = monitor;
this.matchingRules = new HashMap();
@@ -102,14 +101,12 @@
{
if ( matchingRules.containsKey( oid ) )
{
- MatchingRule MatchingRule = ( MatchingRule )
- matchingRules.get( oid );
+ MatchingRule MatchingRule = ( MatchingRule ) matchingRules.get( oid );
monitor.lookedUp( MatchingRule );
return MatchingRule;
}
- NamingException fault = new NamingException( "Unknown MatchingRule OID "
- + oid );
+ NamingException fault = new NamingException( "Unknown MatchingRule OID " + oid );
monitor.lookupFailed( oid, fault );
throw fault;
}