You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/04/03 15:54:19 UTC
svn commit: r761679 - in
/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages:
ReferralImpl.java SearchRefResponse.java SearchRefResponseImpl.java
SearchReferenceResponse.java
Author: elecharny
Date: Fri Apr 3 13:54:19 2009
New Revision: 761679
URL: http://svn.apache.org/viewvc?rev=761679&view=rev
Log:
o Renamed the searchReferenceResponse to SearchRefResponse
o Implemented the ReferralImpl class
Added:
directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/ReferralImpl.java
directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponse.java
- copied, changed from r761646, directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchReferenceResponse.java
directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponseImpl.java
Removed:
directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchReferenceResponse.java
Added: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/ReferralImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/ReferralImpl.java?rev=761679&view=auto
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/ReferralImpl.java (added)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/ReferralImpl.java Fri Apr 3 13:54:19 2009
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.client.api.messages;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
+import org.apache.directory.shared.ldap.util.LdapURL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Represents a referral which is a set of alternative locations where an entry
+ * can be found. Here's what <a href="http://www.faqs.org/rfcs/rfc2251.html">
+ * RFC 2251 </a> has to say about it:
+ *
+ * <pre>
+ * 4.1.11. Referral
+ *
+ * The referral error indicates that the contacted server does not hold
+ * the target entry of the request. The referral field is present in an
+ * LDAPResult if the LDAPResult.resultCode field value is referral, and
+ * absent with all other result codes. It contains a reference to
+ * another server (or set of servers) which may be accessed via LDAP or
+ * other protocols. Referrals can be returned in response to any
+ * operation request (except unbind and abandon which do not have
+ * responses). At least one URL MUST be present in the Referral.
+ *
+ * The referral is not returned for a singleLevel or wholeSubtree search
+ * in which the search scope spans multiple naming contexts, and several
+ * different servers would need to be contacted to complete the
+ * operation. Instead, continuation references, described in section
+ * 4.5.3, are returned.
+ *
+ * Referral ::= SEQUENCE OF LDAPURL -- one or more
+ *
+ * LDAPURL ::= LDAPString -- limited to characters permitted in URLs
+ *
+ * If the client wishes to progress the operation, it MUST follow the
+ * referral by contacting any one of servers. All the URLs MUST be
+ * equally capable of being used to progress the operation. (The
+ * mechanisms for how this is achieved by multiple servers are outside
+ * the scope of this document.)
+ *
+ * URLs for servers implementing the LDAP protocol are written according
+ * to <a href="http://www.faqs.org/rfcs/rfc2255.html">[9]</a>. If an alias
+ * was dereferenced, the <dn> part of the URL MUST be present, with the new
+ * target object name. If the <dn> part is present, the client MUST use this
+ * name in its next request to progress the operation, and if it is not present
+ * the client will use the same name as in the original request. Some servers
+ * (e.g. participating in distributed indexing) may provide a different filter
+ * in a referral for a search operation. If the filter part of the URL
+ * is present in an LDAPURL, the client MUST use this filter in its next
+ * request to progress this search, and if it is not present the client
+ * MUST use the same filter as it used for that search. Other aspects
+ * of the new request may be the same or different as the request which
+ * generated the referral.
+ *
+ * Note that UTF-8 characters appearing in a DN or search filter may not
+ * be legal for URLs (e.g. spaces) and MUST be escaped using the %
+ * method in RFC 1738 <a href="http://www.faqs.org/rfcs/rfc1738.html">[7]</a>.
+ *
+ * Other kinds of URLs may be returned, so long as the operation could
+ * be performed using that protocol.
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ * @version $Rev: 761643 $
+ * TODO This interface should be located in a url package under common to be
+ * constructed from a LDAPv3 URL parser. The interface will eventually
+ * look very different once url support is added: for one it will add and
+ * remove LdapUrl objects instead of strings or provide both string and
+ * LdapUrl add/remove methods.
+ */
+public class ReferralImpl implements Referral
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( ReferralImpl.class );
+
+ /** The list of LDAPUrls */
+ private List<LdapURL> referrals;
+
+ /**
+ * Gets an unmodifiable set of alternative referral urls.
+ *
+ * @return the alternative url objects.
+ */
+ public Collection<String> getLdapUrls()
+ {
+ if ( referrals == null )
+ {
+ return new ArrayList<String>();
+ }
+
+ List<String> urls = new ArrayList<String>( referrals.size() );
+
+ for ( LdapURL referral:referrals )
+ {
+ urls.add( referral.toString() );
+ }
+
+ return urls;
+ }
+
+
+ /**
+ * Adds an LDAPv3 URL to this Referral.
+ *
+ * @param urls the LDAPv3 URLs to add
+ */
+ public void addLdapUrls( String... urls )
+ {
+ if ( ( urls == null ) || ( urls.length == 0 ) )
+ {
+ return;
+ }
+
+ if ( referrals == null )
+ {
+ referrals = new ArrayList<LdapURL>( urls.length );
+ }
+
+ for ( String url:urls )
+ {
+ try
+ {
+ LdapURL ldapUrl = new LdapURL( url );
+
+ referrals.add( ldapUrl );
+ }
+ catch ( LdapURLEncodingException luee )
+ {
+ LOG.warn( "The given URL '{}' is invalid", url );
+ }
+ }
+ }
+
+
+ /**
+ * Adds an LDAPv3 URL to this Referral.
+ *
+ * @param urls the LDAPv3 URLs to add
+ */
+ public void addLdapUrls( LdapURL... urls )
+ {
+ if ( ( urls == null ) || ( urls.length == 0 ) )
+ {
+ return;
+ }
+
+ if ( referrals == null )
+ {
+ referrals = new ArrayList<LdapURL>( urls.length );
+ }
+
+ for ( LdapURL url:urls )
+ {
+ referrals.add( url );
+ }
+ }
+
+
+ /**
+ * Removes an LDAPv3 URL to this Referral.
+ *
+ * @param urls the LDAPv3 URLs to remove
+ */
+ public void removeLdapUrl( String... urls )
+ {
+ if ( ( urls == null ) || ( urls.length == 0 ) )
+ {
+ return;
+ }
+
+ if ( ( referrals == null ) || ( referrals.size() == 0 ) )
+ {
+ return;
+ }
+
+ for ( String url:urls )
+ {
+ try
+ {
+ LdapURL ldapUrl = new LdapURL( url );
+
+ referrals.remove( ldapUrl );
+ }
+ catch ( LdapURLEncodingException luee )
+ {
+ LOG.warn( "The given URL '{}' is invalid", url );
+ }
+ }
+ }
+
+
+ /**
+ * Removes an LDAPv3 URL to this Referral.
+ *
+ * @param urls the LDAPv3 URLs to remove
+ */
+ public void removeLdapUrl( LdapURL... urls )
+ {
+ if ( ( urls == null ) || ( urls.length == 0 ) )
+ {
+ return;
+ }
+
+ if ( ( referrals == null ) || ( referrals.size() == 0 ) )
+ {
+ return;
+ }
+
+ for ( LdapURL url:urls )
+ {
+ referrals.remove( url );
+ }
+ }
+}
Copied: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponse.java (from r761646, directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchReferenceResponse.java)
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponse.java?p2=directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponse.java&p1=directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchReferenceResponse.java&r1=761646&r2=761679&rev=761679&view=diff
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchReferenceResponse.java (original)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponse.java Fri Apr 3 13:54:19 2009
@@ -30,7 +30,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Revision: 760984 $
*/
-public interface SearchReferenceResponse extends SearchResponse
+public interface SearchRefResponse extends SearchResponse
{
/**
* Gets the sequence of LdapUrls as a Referral instance.
@@ -45,7 +45,7 @@
*
* @param referrals the sequence of LdapUrls
*/
- void setReferral( Referral referrals );
+ void setReferral( Referral referral );
/**
Added: directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponseImpl.java?rev=761679&view=auto
==============================================================================
--- directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponseImpl.java (added)
+++ directory/shared/branches/shared-replication/client-api/src/main/java/org/apache/directory/shared/ldap/client/api/messages/SearchRefResponseImpl.java Fri Apr 3 13:54:19 2009
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.client.api.messages;
+
+import org.apache.directory.shared.ldap.util.LdapURL;
+
+
+/**
+ * Search reference protocol response message used to return referrals to the
+ * client in response to a search request message.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision: 760984 $
+ */
+public class SearchRefResponseImpl extends AbstractMessage implements SearchResponse
+{
+ /** The list of LdapURL referrals */
+ private Referral referral;
+
+ /**
+ * Gets the sequence of LdapUrls as a Referral instance.
+ *
+ * @return the sequence of LdapUrls
+ */
+ public Referral getReferrals()
+ {
+ return referral;
+ }
+
+
+ /**
+ * Sets the sequence of LdapUrls as a Referral instance.
+ *
+ * @param referral the sequence of LdapUrls
+ */
+ public void setReferral( Referral referral )
+ {
+ this.referral = referral;
+ }
+
+
+ /**
+ * Sets the sequence of LdapUrls as a Referral instance.
+ *
+ * @param referrals the sequence of LdapUrls
+ */
+ public void addReferrals( LdapURL... referrals )
+ {
+ if ( referral == null )
+ {
+ referral = new ReferralImpl();
+ }
+
+
+ }
+
+
+ /**
+ * Sets the sequence of LdapUrls as a Referral instance.
+ *
+ * @param referrals the sequence of LdapUrls
+ */
+ public void addReferrals( String... referrals )
+ {
+
+ }
+
+
+ /**
+ * Removes the sequence of LdapUrls from the Referral instance.
+ *
+ * @param referrals the sequence of LdapUrls
+ */
+ public void removeReferrals( LdapURL... referrals )
+ {
+
+ }
+
+
+ /**
+ * Removes the sequence of LdapUrls from the Referral instance.
+ *
+ * @param referrals the sequence of LdapUrls
+ */
+ public void removeReferrals( String... referrals )
+ {
+
+ }
+}