View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.core.api.entry;
21  
22  
23  import org.apache.directory.api.ldap.model.entry.Entry;
24  import org.apache.directory.api.ldap.model.name.Dn;
25  
26  
27  /**
28   * Creates a wrapper around a SearchResult object so that we can use the Dn
29   * instead of parser it over and over
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class ServerSearchResult
34  {
35      /** Distinguished name for this result */
36      private Dn dn;
37  
38      /** The associated entry */
39      private Entry serverEntry;
40  
41      /** Tells if the name is relative to the target context */
42      private boolean isRelative;
43  
44      /** The bound object */
45      private Object object;
46  
47  
48      /**
49       * 
50       * Creates a new instance of ServerSearchResult.
51       *
52       * @param dn Distinguished name for this result
53       * @param serverEntry The associated entry 
54       * @param isRelative Tells if the name is relative to the target context
55       */
56      public ServerSearchResult( Dn dn, Entry serverEntry, boolean isRelative )
57      {
58          this.dn = dn;
59          this.serverEntry = serverEntry;
60          this.serverEntry.setDn( dn );
61          this.isRelative = isRelative;
62      }
63  
64  
65      /**
66       * 
67       * Creates a new instance of ServerSearchResult.
68       *
69       * @param dn Distinguished name for this result
70       * @param serverEntry The associated entry
71       */
72      public ServerSearchResult( Dn dn, Entry serverEntry )
73      {
74          this.dn = dn;
75          this.serverEntry = serverEntry;
76          this.serverEntry.setDn( dn );
77      }
78  
79  
80      /**
81       * @return The result Dn
82       */
83      public Dn getDn()
84      {
85          return dn;
86      }
87  
88  
89      /**
90       * @return The entry
91       */
92      public Entry getServerEntry()
93      {
94          return serverEntry;
95      }
96  
97  
98      public boolean isRelative()
99      {
100         return isRelative;
101     }
102 
103 
104     public void setRelative( boolean isRelative )
105     {
106         this.isRelative = isRelative;
107     }
108 
109 
110     public void setServerEntry( Entry serverEntry )
111     {
112         this.serverEntry = serverEntry;
113     }
114 
115 
116     public Object getObject()
117     {
118         return object;
119     }
120 
121 
122     public void setObject( Object object )
123     {
124         this.object = object;
125     }
126 
127 
128     /**
129      * @see Object#toString()
130      */
131     public String toString()
132     {
133         String name = ( dn == null ? "null" : ( dn == Dn.EMPTY_DN ? "\"\"" : dn.getName() ) );
134         return "ServerSearchResult : " + name + "\n" + serverEntry;
135     }
136 }