1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.directory.server.core.schema;
23
24
25 import javax.naming.NamingException;
26 import javax.naming.directory.InvalidAttributeValueException;
27
28 import org.apache.directory.server.core.entry.ServerAttribute;
29 import org.apache.directory.server.core.entry.ServerBinaryValue;
30 import org.apache.directory.shared.ldap.entry.EntryAttribute;
31 import org.apache.directory.shared.ldap.entry.Value;
32
33
34
35
36
37
38
39
40 public class AttributeClassLoader extends ClassLoader
41 {
42 public ServerAttribute attribute;
43
44
45 public AttributeClassLoader()
46 {
47 super( AttributeClassLoader.class.getClassLoader() );
48 }
49
50
51 public void setAttribute( EntryAttribute attribute ) throws NamingException
52 {
53 if ( ((ServerAttribute)attribute).getAttributeType().getSyntax().isHumanReadable() )
54 {
55 throw new InvalidAttributeValueException( "The attribute must be binary" );
56 }
57
58 this.attribute = (ServerAttribute)attribute;
59 }
60
61
62 public Class<?> findClass( String name ) throws ClassNotFoundException
63 {
64 byte[] classBytes = null;
65
66 Value<?> value = attribute.get();
67
68 if ( value instanceof ServerBinaryValue )
69 {
70 classBytes = ((ServerBinaryValue)value).get();
71
72 return defineClass( name, classBytes, 0, classBytes.length );
73 }
74 else
75 {
76 throw new ClassNotFoundException( "Failed to access attribute bytes." );
77 }
78 }
79 }