KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > internal > model > Bookmark


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
21 package org.apache.directory.ldapstudio.browser.core.internal.model;
22
23
24 import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent;
25 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
26 import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer;
27 import org.apache.directory.ldapstudio.browser.core.model.BookmarkParameter;
28 import org.apache.directory.ldapstudio.browser.core.model.DN;
29 import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
30 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
31 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
32 import org.eclipse.search.ui.ISearchPageScoreComputer;
33
34
35 /**
36  * Default implementation if IBookmark.
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class Bookmark implements IBookmark
42 {
43
44     /** The serialVersionUID. */
45     private static final long serialVersionUID = 2914726541167255499L;
46
47     /** The connection. */
48     private IConnection connection;
49
50     /** The bookmark parameter. */
51     private BookmarkParameter bookmarkParameter;
52
53     /** The bookmark entry. */
54     private DelegateEntry bookmarkEntry;
55
56
57     /**
58      * Creates a new instance of Bookmark.
59      */

60     protected Bookmark()
61     {
62     }
63
64
65     /**
66      * Creates a new instance of Bookmark.
67      *
68      * @param connection the connection
69      * @param bookmarkParameter the bookmark parameter
70      */

71     public Bookmark( IConnection connection, BookmarkParameter bookmarkParameter )
72     {
73         this.connection = connection;
74         this.bookmarkParameter = bookmarkParameter;
75         this.bookmarkEntry = new DelegateEntry( connection, bookmarkParameter.getDn() );
76     }
77
78
79     /**
80      * Creates a new instance of Bookmark.
81      *
82      * @param connection the connection
83      * @param dn the target DN
84      * @param name the symbolic name
85      */

86     public Bookmark( IConnection connection, DN dn, String JavaDoc name )
87     {
88         this.connection = connection;
89         this.bookmarkParameter = new BookmarkParameter( dn, name );
90         this.bookmarkEntry = new DelegateEntry( connection, dn );
91     }
92
93
94     /**
95      * {@inheritDoc}
96      */

97     public DN getDn()
98     {
99         return this.bookmarkParameter.getDn();
100     }
101
102
103     /**
104      * {@inheritDoc}
105      */

106     public void setDn( DN dn )
107     {
108         this.bookmarkParameter.setDn( dn );
109         this.fireBookmarkUpdated( BookmarkUpdateEvent.Detail.BOOKMARK_UPDATED );
110     }
111
112
113     /**
114      * {@inheritDoc}
115      */

116     public String JavaDoc getName()
117     {
118         return this.bookmarkParameter.getName();
119     }
120
121
122     /**
123      * {@inheritDoc}
124      */

125     public void setName( String JavaDoc name )
126     {
127         this.bookmarkParameter.setName( name );
128         this.fireBookmarkUpdated( BookmarkUpdateEvent.Detail.BOOKMARK_UPDATED );
129     }
130
131
132     /**
133      * {@inheritDoc}
134      */

135     public Object JavaDoc getAdapter( Class JavaDoc adapter )
136     {
137         Class JavaDoc<?> clazz = ( Class JavaDoc<?> ) adapter;
138         if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) )
139         {
140             return new LdapSearchPageScoreComputer();
141         }
142         if ( clazz.isAssignableFrom( IConnection.class ) )
143         {
144             return getConnection();
145         }
146         if ( clazz.isAssignableFrom( IEntry.class ) )
147         {
148             return getEntry();
149         }
150         if ( clazz.isAssignableFrom( IBookmark.class ) )
151         {
152             return this;
153         }
154
155         return null;
156     }
157
158
159     private void fireBookmarkUpdated( BookmarkUpdateEvent.Detail detail )
160     {
161         if ( this.getName() != null && !"".equals( this.getName() ) ) { //$NON-NLS-1$
162
EventRegistry.fireBookmarkUpdated( new BookmarkUpdateEvent( this, detail ), this );
163         }
164     }
165
166
167     /**
168      * {@inheritDoc}
169      */

170     public BookmarkParameter getBookmarkParameter()
171     {
172         return bookmarkParameter;
173     }
174
175
176     /**
177      * {@inheritDoc}
178      */

179     public void setBookmarkParameter( BookmarkParameter bookmarkParameter )
180     {
181         this.bookmarkParameter = bookmarkParameter;
182     }
183
184
185     /**
186      * {@inheritDoc}
187      */

188     public IConnection getConnection()
189     {
190         return this.connection;
191     }
192
193
194     /**
195      * {@inheritDoc}
196      */

197     public IEntry getEntry()
198     {
199         return this.bookmarkEntry;
200     }
201
202
203     /**
204      * {@inheritDoc}
205      */

206     public String JavaDoc toString()
207     {
208         return this.getName();
209     }
210
211 }
212
Popular Tags