001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.dsmlv2.reponse; 021 022 023import java.util.Collection; 024 025import org.apache.directory.api.ldap.codec.api.LdapApiService; 026import org.apache.directory.api.ldap.model.message.MessageTypeEnum; 027import org.apache.directory.api.ldap.model.message.Referral; 028import org.apache.directory.api.ldap.model.message.SearchResultReference; 029import org.apache.directory.api.ldap.model.message.SearchResultReferenceImpl; 030import org.apache.directory.api.ldap.model.url.LdapUrl; 031import org.dom4j.Element; 032import org.dom4j.tree.DefaultElement; 033 034 035/** 036 * DSML Decorator for SearchResultReference 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public class SearchResultReferenceDsml 041 extends AbstractResponseDsml<SearchResultReference> 042 implements SearchResultReference 043{ 044 private static final String SEARCH_RESULT_REFERENCE_TAG = "searchResultReference"; 045 046 047 /** 048 * Creates a new getDecoratedMessage() of SearchResultReferenceDsml. 049 */ 050 public SearchResultReferenceDsml( LdapApiService codec ) 051 { 052 super( codec, new SearchResultReferenceImpl() ); 053 } 054 055 056 /** 057 * Creates a new getDecoratedMessage() of SearchResultReferenceDsml. 058 * 059 * @param ldapMessage 060 * the message to decorate 061 */ 062 public SearchResultReferenceDsml( LdapApiService codec, SearchResultReference ldapMessage ) 063 { 064 super( codec, ldapMessage ); 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 public MessageTypeEnum getType() 072 { 073 return getDecorated().getType(); 074 } 075 076 077 /** 078 * {@inheritDoc} 079 */ 080 public Element toDsml( Element root ) 081 { 082 Element element = null; 083 084 if ( root != null ) 085 { 086 element = root.addElement( SEARCH_RESULT_REFERENCE_TAG ); 087 } 088 else 089 { 090 element = new DefaultElement( SEARCH_RESULT_REFERENCE_TAG ); 091 } 092 093 // Adding References 094 for ( String url : getDecorated().getReferral().getLdapUrls() ) 095 { 096 element.addElement( "ref" ).addText( url ); 097 } 098 099 return element; 100 } 101 102 103 /** 104 * Add a new reference to the list. 105 * 106 * @param searchResultReference The search result reference 107 */ 108 public void addSearchResultReference( LdapUrl searchResultReference ) 109 { 110 getDecorated().getReferral().addLdapUrl( searchResultReference.toString() ); 111 } 112 113 114 /** 115 * Get the list of references 116 * 117 * @return An ArrayList of SearchResultReferences 118 */ 119 public Collection<String> getSearchResultReferences() 120 { 121 return getDecorated().getReferral().getLdapUrls(); 122 } 123 124 125 /** 126 * {@inheritDoc} 127 */ 128 public Referral getReferral() 129 { 130 return getDecorated().getReferral(); 131 } 132 133 134 /** 135 * {@inheritDoc} 136 */ 137 public void setReferral( Referral referral ) 138 { 139 getDecorated().setReferral( referral ); 140 } 141}