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/29 03:46:21 UTC

svn commit: rev 47439 - incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema

Author: akarasulu
Date: Tue Sep 28 18:46:20 2004
New Revision: 47439

Added:
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistry.java   (contents, props changed)
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistryMonitor.java   (contents, props changed)
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistryMonitorAdapter.java   (contents, props changed)
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/DefaultAttributeTypeRegistry.java   (contents, props changed)
Log:
copied over and refactored for attributeType registry service

Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistry.java	Tue Sep 28 18:46:20 2004
@@ -0,0 +1,59 @@
+/*
+ *   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 javax.naming.NamingException;
+
+import org.apache.ldap.common.schema.AttributeType;
+
+
+/**
+ * An AttributeType registry's service interface.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface AttributeTypeRegistry
+{
+    /**
+     * Registers a Comparator with this registry.
+     * 
+     * @param attributeType the attributeType to register
+     * @throws javax.naming.NamingException if the AttributeType is already
+     * registered or the registration operation is not supported
+     */
+    void register( AttributeType attributeType ) throws NamingException;
+    
+    /**
+     * Looks up an attributeType by its unique Object Identifier.
+     * 
+     * @param oid the object identifier
+     * @return the AttributeType instance for the oid
+     * @throws javax.naming.NamingException if the AttributeType does not exist
+     */
+    AttributeType lookup( String oid ) throws NamingException;
+
+    /**
+     * Checks to see if an attributeType exists.
+     * 
+     * @param oid the object identifier
+     * @return true if an attributeType definition exists for the oid, false
+     * otherwise
+     */
+    boolean hasAttributeType( String oid );
+}

Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistryMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistryMonitor.java	Tue Sep 28 18:46:20 2004
@@ -0,0 +1,61 @@
+/*
+ *   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 org.apache.ldap.common.schema.AttributeType;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Interface for AttributeTypeRegitery callback event monitors.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface AttributeTypeRegistryMonitor
+{
+    /**
+     * Monitors when a AttributeType is registered successfully.
+     *
+     * @param attributeType the AttributeType successfully registered
+     */
+    void registered( AttributeType attributeType );
+
+    /**
+     * Monitors when a Comparator is successfully looked up.
+     *
+     * @param attributeType the AttributeType successfully lookedup
+     */
+    void lookedUp( AttributeType attributeType );
+
+    /**
+     * Monitors when a lookup attempt fails.
+     *
+     * @param oid the OID for the AttributeType to lookup
+     * @param fault the exception to be thrown for the fault
+     */
+    void lookupFailed( String oid, Throwable fault );
+
+    /**
+     * Monitors when a registration attempt fails.
+     *
+     * @param attributeType the AttributeType which failed registration
+     * @param fault the exception to be thrown for the fault
+     */
+    void registerFailed( AttributeType attributeType, Throwable fault );
+}

Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistryMonitorAdapter.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/AttributeTypeRegistryMonitorAdapter.java	Tue Sep 28 18:46:20 2004
@@ -0,0 +1,61 @@
+/*
+ *   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 org.apache.ldap.common.schema.AttributeType;
+
+import javax.naming.NamingException;
+
+
+/**
+ * A simple do nothing monitor adapter for AttributeTypeRegistries.  Note for
+ * safty exception based callback print the stack tract to stderr.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AttributeTypeRegistryMonitorAdapter
+    implements AttributeTypeRegistryMonitor
+{
+    public void registered( AttributeType attributeType )
+    {
+    }
+
+
+    public void lookedUp( AttributeType attributeType )
+    {
+    }
+
+
+    public void lookupFailed( String oid, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace();
+        }
+    }
+
+
+    public void registerFailed( AttributeType attributeType, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace();
+        }
+    }
+}

Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/DefaultAttributeTypeRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/DefaultAttributeTypeRegistry.java	Tue Sep 28 18:46:20 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 org.apache.ldap.common.schema.AttributeType;
+
+import java.util.Map;
+import java.util.HashMap;
+import javax.naming.NamingException;
+
+
+/**
+ * A plain old java object implementation of an AttributeTypeRegistry.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultAttributeTypeRegistry implements AttributeTypeRegistry
+{
+    /** maps an OID to an AttributeType */
+    private final Map byOid;
+    /** monitor notified via callback events */
+    private AttributeTypeRegistryMonitor monitor;
+
+
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Creates an empty DefaultAttributeTypeRegistry.
+     */
+    public DefaultAttributeTypeRegistry()
+    {
+        byOid = new HashMap();
+        monitor = new AttributeTypeRegistryMonitorAdapter();
+    }
+
+
+    /**
+     * 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( AttributeType attributeType ) throws NamingException
+    {
+        if ( byOid.containsKey( attributeType.getOid() ) )
+        {
+            NamingException e = new NamingException( "attributeType w/ OID " +
+                attributeType.getOid() + " has already been registered!" );
+            monitor.registerFailed( attributeType, e );
+            throw e;
+        }
+
+        byOid.put( attributeType.getOid(), attributeType );
+        monitor.registered( attributeType );
+    }
+
+
+    public AttributeType lookup( String oid ) throws NamingException
+    {
+        if ( ! byOid.containsKey( oid ) )
+        {
+            NamingException e = new NamingException( "attributeType w/ OID "
+                + oid + " not registered!" );
+            monitor.lookupFailed( oid, e );
+            throw e;
+        }
+
+        AttributeType attributeType = ( AttributeType ) byOid.get( oid );
+        monitor.lookedUp( attributeType );
+        return attributeType;
+    }
+
+
+    public boolean hasAttributeType( String oid )
+    {
+        return byOid.containsKey( oid );
+    }
+}