1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.api.ldap.trigger;
22
23
24 import javax.naming.NamingException;
25 import javax.naming.directory.Attribute;
26 import javax.naming.directory.Attributes;
27 import javax.naming.directory.BasicAttribute;
28 import javax.naming.directory.BasicAttributes;
29 import javax.naming.directory.DirContext;
30 import javax.naming.ldap.LdapContext;
31
32 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
33 import org.apache.directory.api.ldap.model.entry.AttributeUtils;
34
35
36
37
38
39
40
41
42 public final class TriggerUtils
43 {
44
45
46
47 private TriggerUtils()
48 {
49 }
50
51
52
53
54
55
56
57 public static void defineTriggerExecutionSpecificPoint( LdapContext apCtx ) throws NamingException
58 {
59 Attributes ap = apCtx.getAttributes( "", new String[] { SchemaConstants.ADMINISTRATIVE_ROLE_AT } );
60 Attribute administrativeRole = ap.get( SchemaConstants.ADMINISTRATIVE_ROLE_AT );
61
62 if ( ( administrativeRole == null )
63 || !AttributeUtils.containsValueCaseIgnore( administrativeRole, SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA ) )
64 {
65 Attributes changes = new BasicAttributes( SchemaConstants.ADMINISTRATIVE_ROLE_AT,
66 SchemaConstants.TRIGGER_EXECUTION_SPECIFIC_AREA, true );
67 apCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
68 }
69 }
70
71
72
73
74
75
76
77
78
79
80
81 public static void createTriggerExecutionSubentry(
82 LdapContext apCtx,
83 String subentryCN,
84 String subtreeSpec,
85 String prescriptiveTriggerSpec ) throws NamingException
86 {
87 Attributes subentry = new BasicAttributes( SchemaConstants.CN_AT, subentryCN, true );
88 Attribute objectClass = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT );
89 subentry.put( objectClass );
90 objectClass.add( SchemaConstants.TOP_OC );
91 objectClass.add( SchemaConstants.SUBENTRY_OC );
92 objectClass.add( SchemaConstants.TRIGGER_EXECUTION_SUBENTRY_OC );
93 subentry.put( SchemaConstants.SUBTREE_SPECIFICATION_AT, subtreeSpec );
94 subentry.put( SchemaConstants.PRESCRIPTIVE_TRIGGER_SPECIFICATION_AT, prescriptiveTriggerSpec );
95 apCtx.createSubcontext( "cn=" + subentryCN, subentry );
96 }
97
98
99
100
101
102
103
104
105
106
107 public static void loadPrescriptiveTriggerSpecification(
108 LdapContext apCtx,
109 String subentryCN,
110 String triggerSpec ) throws NamingException
111 {
112 Attributes changes = new BasicAttributes( SchemaConstants.PRESCRIPTIVE_TRIGGER_SPECIFICATION_AT, triggerSpec, true );
113 apCtx.modifyAttributes( "cn=" + subentryCN, DirContext.ADD_ATTRIBUTE, changes );
114 }
115
116
117
118
119
120
121
122
123
124 public static void loadEntryTriggerSpecification(
125 LdapContext ctx,
126 String triggerSpec ) throws NamingException
127 {
128 Attributes changes = new BasicAttributes( SchemaConstants.ENTRY_TRIGGER_SPECIFICATION_AT, triggerSpec, true );
129 ctx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
130 }
131 }