1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.schemaloader;
21
22
23 import org.apache.directory.api.i18n.I18n;
24 import org.apache.directory.api.ldap.model.entry.Attribute;
25 import org.apache.directory.api.ldap.model.entry.Value;
26 import org.apache.directory.api.ldap.model.exception.LdapException;
27 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
28 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
29
30
31
32
33
34
35
36 public class AttributeClassLoader extends ClassLoader
37 {
38
39
40 private Attribute attribute;
41
42
43
44
45
46 public AttributeClassLoader()
47 {
48 super( AttributeClassLoader.class.getClassLoader() );
49 }
50
51
52
53
54
55
56
57
58 public void setAttribute( Attribute attribute ) throws LdapException
59 {
60 if ( attribute.isHumanReadable() )
61 {
62 throw new LdapInvalidAttributeValueException( ResultCodeEnum.CONSTRAINT_VIOLATION,
63 I18n.err( I18n.ERR_10001 ) );
64 }
65
66 this.attribute = attribute;
67 }
68
69
70
71
72
73 public Class<?> findClass( String name ) throws ClassNotFoundException
74 {
75 byte[] classBytes = null;
76
77 Value<?> value = attribute.get();
78
79 if ( value.isHumanReadable() )
80 {
81 throw new ClassNotFoundException( I18n.err( I18n.ERR_10002 ) );
82 }
83
84 classBytes = value.getBytes();
85
86 return defineClass( name, classBytes, 0, classBytes.length );
87 }
88 }