Author: akarasulu
Date: Tue Sep 28 21:11:22 2004
New Revision: 47454
Added:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/DefaultObjectClassRegistry.java
(contents, props changed)
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistry.java
(contents, props changed)
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistryMonitor.java
(contents, props changed)
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistryMonitorAdapter.java
(contents, props changed)
Log:
Commit changes ...
o added interface for an ObjectClass lookup service
o added a reusable default POJO implementation for the service
o added monitor interface for the service
o added a do nothing adapter for monitor interface
Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/DefaultObjectClassRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/DefaultObjectClassRegistry.java
Tue Sep 28 21:11:22 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 javax.naming.NamingException;
+
+import org.apache.ldap.common.schema.ObjectClass;
+
+
+/**
+ * A plain old java object implementation of an ObjectClassRegistry.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultObjectClassRegistry implements ObjectClassRegistry
+{
+ /** maps an OID to an ObjectClass */
+ private final Map byOid;
+ /** monitor notified via callback events */
+ private ObjectClassRegistryMonitor monitor;
+
+
+ // ------------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Creates an empty DefaultObjectClassRegistry.
+ */
+ public DefaultObjectClassRegistry()
+ {
+ byOid = new HashMap();
+ monitor = new ObjectClassRegistryMonitorAdapter();
+ }
+
+
+ /**
+ * 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( ObjectClass objectClass ) throws NamingException
+ {
+ if ( byOid.containsKey( objectClass.getOid() ) )
+ {
+ NamingException e = new NamingException( "objectClass w/ OID " +
+ objectClass.getOid() + " has already been registered!" );
+ monitor.registerFailed( objectClass, e );
+ throw e;
+ }
+
+ byOid.put( objectClass.getOid(), objectClass );
+ monitor.registered( objectClass );
+ }
+
+
+ public ObjectClass lookup( String oid ) throws NamingException
+ {
+ if ( ! byOid.containsKey( oid ) )
+ {
+ NamingException e = new NamingException( "objectClass w/ OID "
+ + oid + " not registered!" );
+ monitor.lookupFailed( oid, e );
+ throw e;
+ }
+
+ ObjectClass objectClass = ( ObjectClass ) byOid.get( oid );
+ monitor.lookedUp( objectClass );
+ return objectClass;
+ }
+
+
+ public boolean hasObjectClass( String oid )
+ {
+ return byOid.containsKey( oid );
+ }
+}
Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistry.java
Tue Sep 28 21:11:22 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.ObjectClass;
+
+
+/**
+ * ObjectClass registry service interface.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ObjectClassRegistry
+{
+ /**
+ * Registers an ObjectClass with this registry.
+ *
+ * @param objectClass the objectClass to register
+ * @throws NamingException if the ObjectClass is already registered or the
+ * registration operation is not supported
+ */
+ void register( ObjectClass objectClass ) throws NamingException;
+
+ /**
+ * Looks up an objectClass by its unique Object Identifier.
+ *
+ * @param oid the object identifier
+ * @return the ObjectClass instance for the oid
+ * @throws NamingException if the ObjectClass does not exist
+ */
+ ObjectClass lookup( String oid ) throws NamingException;
+
+ /**
+ * Checks to see if an objectClass exists.
+ *
+ * @param oid the object identifier
+ * @return true if an objectClass definition exists for the oid, false
+ * otherwise
+ */
+ boolean hasObjectClass( String oid );
+}
Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistryMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistryMonitor.java
Tue Sep 28 21:11:22 2004
@@ -0,0 +1,60 @@
+/*
+ * 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.ObjectClass;
+
+
+/**
+ * Interface for ObjectClassRegitery callback event monitors.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ObjectClassRegistryMonitor
+{
+ /**
+ * Monitors when a ObjectClass is registered successfully.
+ *
+ * @param objectClass the ObjectClass successfully registered
+ */
+ void registered( ObjectClass objectClass );
+
+ /**
+ * Monitors when a Comparator is successfully looked up.
+ *
+ * @param objectClass the ObjectClass successfully lookedup
+ */
+ void lookedUp( ObjectClass objectClass );
+
+ /**
+ * Monitors when a lookup attempt fails.
+ *
+ * @param oid the OID for the ObjectClass 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 objectClass the ObjectClass which failed registration
+ * @param fault the exception to be thrown for the fault
+ */
+ void registerFailed( ObjectClass objectClass, Throwable fault );
+}
Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistryMonitorAdapter.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/schema/ObjectClassRegistryMonitorAdapter.java
Tue Sep 28 21:11:22 2004
@@ -0,0 +1,58 @@
+/*
+ * 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.ObjectClass;
+
+
+/**
+ * A do nothing adapter for an ObjectClassMonitor. As a precaution so
+ * exceptions are not lost exception based callback print stacks to stderr.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ObjectClassRegistryMonitorAdapter implements ObjectClassRegistryMonitor
+{
+ public void registered( ObjectClass objectClass )
+ {
+ }
+
+
+ public void lookedUp( ObjectClass objectClass )
+ {
+ }
+
+
+ public void lookupFailed( String oid, Throwable fault )
+ {
+ if ( fault != null )
+ {
+ fault.printStackTrace();
+ }
+ }
+
+
+ public void registerFailed( ObjectClass objectClass, Throwable fault )
+ {
+ if ( fault != null )
+ {
+ fault.printStackTrace();
+ }
+ }
+}
|