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 2005/06/03 18:02:05 UTC
svn commit: r179822 -
/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
Author: akarasulu
Date: Fri Jun 3 09:02:04 2005
New Revision: 179822
URL: http://svn.apache.org/viewcvs?rev=179822&view=rev
Log:
adding method that was begining to be implemented in multiple places
Modified:
directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java?rev=179822&r1=179821&r2=179822&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java (original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java Fri Jun 3 09:02:04 2005
@@ -1,19 +1,19 @@
-/*
- * 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.
- *
- */
+/*
+ * 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.
+ *
+ */
/*
* $Id: NamespaceTools.java,v 1.6 2003/09/23 07:13:26 akarasulu Exp $
@@ -26,9 +26,9 @@
package org.apache.ldap.common.util ;
-import javax.naming.Name ;
-import javax.naming.CompositeName ;
-import javax.naming.InvalidNameException ;
+import org.apache.ldap.common.name.LdapName;
+
+import javax.naming.*;
/**
@@ -402,6 +402,40 @@
public static boolean isDescendant( Name a_ancestor, Name a_descendant )
{
return a_descendant.startsWith( a_ancestor ) ;
+ }
+
+
+ /**
+ * Gets the relative name between a context and the distinguished name of a
+ * descendant context below the base.
+ *
+ * @param base the context containing the entry referred to by the dn
+ * @param dn the distinguished name of the descendant context
+ * @return the relatve name between the base and the descendant entry
+ * @throws javax.naming.NamingException if the base is not an ancestor of the entry
+ * specified by the dn parameter
+ */
+ public static Name getRelativeName( Context base, String dn ) throws NamingException
+ {
+ LdapName rdn = new LdapName( dn );
+
+ LdapName baseDn = new LdapName( base.getNameInNamespace() );
+
+ if ( rdn.startsWith( baseDn ) )
+ {
+ for ( int ii = 0; ii < baseDn.size(); ii++ )
+ {
+ rdn.remove( 0 );
+ }
+ }
+ else
+ {
+ NamingException e = new NamingException( dn + " is not a subordinate of context:" + baseDn.toString() );
+
+ throw e;
+ }
+
+ return rdn;
}
}