KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.net.URL JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.core.model.DN;
29 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
30 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
31 import org.apache.directory.ldapstudio.browser.core.model.IRootDSE;
32 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
33
34
35 public final class RootDSE extends BaseDNEntry implements IRootDSE
36 {
37
38     private static final long serialVersionUID = -8445018787232919754L;
39
40     public static Properties JavaDoc oidMap = new Properties JavaDoc();
41     static
42     {
43
44         try
45         {
46             URL JavaDoc url = RootDSE.class.getClassLoader().getResource(
47                 "org/apache/directory/ldapstudio/browser/core/model/ldap_oids.txt" ); //$NON-NLS-1$
48
if(url != null)
49             {
50                 oidMap.load( url.openStream() );
51             }
52         }
53         catch ( Exception JavaDoc e )
54         {
55             e.printStackTrace();
56         }
57     }
58
59
60     protected RootDSE()
61     {
62     }
63
64
65     public RootDSE( IConnection connection ) throws ModelModificationException
66     {
67         super( new DN(), connection );
68     }
69
70     
71     public IEntry getParententry()
72     {
73         return null;
74     }
75     
76
77     public String JavaDoc[] getSupportedExtensions()
78     {
79         if ( getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION ) != null )
80         {
81             return get( getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION ).getStringValues() );
82         }
83         else
84         {
85             return new String JavaDoc[0];
86         }
87     }
88
89
90     public String JavaDoc[] getSupportedControls()
91     {
92         if ( getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ) != null )
93         {
94             return get( getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL ).getStringValues() );
95         }
96         else
97         {
98             return new String JavaDoc[0];
99         }
100     }
101
102
103     public String JavaDoc[] getSupportedFeatures()
104     {
105         if ( getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES ) != null )
106         {
107             return get( getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES ).getStringValues() );
108         }
109         else
110         {
111             return new String JavaDoc[0];
112         }
113     }
114
115
116     private String JavaDoc[] get( String JavaDoc[] a )
117     {
118         for ( int i = 0; i < a.length; i++ )
119         {
120             if ( oidMap.containsKey( a[i] ) )
121             {
122                 String JavaDoc s = ( String JavaDoc ) oidMap.get( a[i] );
123                 a[i] = s;
124                 if ( s.matches( "^\".*\"" ) ) { //$NON-NLS-1$
125
a[i] = s.substring( 1, s.indexOf( "\"", 1 ) ); //$NON-NLS-1$
126
}
127             }
128         }
129         Arrays.sort( a );
130         return a;
131     }
132
133 }
134
Popular Tags