1 20 21 package org.apache.directory.ldapstudio.browser.core.model.schema; 22 23 24 import java.io.Serializable ; 25 import java.util.Arrays ; 26 import java.util.Set ; 27 import java.util.TreeSet ; 28 29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 30 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 31 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 32 33 34 public class Subschema implements Serializable 35 { 36 37 private static final long serialVersionUID = 7821844589084867562L; 38 39 private String [] objectClassNames; 40 41 private Schema schema; 42 43 private Set allAttributeNameSet; 44 45 46 protected Subschema() 47 { 48 } 49 50 51 public Subschema( IEntry entry ) 52 { 53 if ( entry.getAttribute( IAttribute.OBJECTCLASS_ATTRIBUTE ) != null ) 54 { 55 this.objectClassNames = entry.getAttribute( IAttribute.OBJECTCLASS_ATTRIBUTE ).getStringValues(); 56 } 57 else 58 { 59 this.objectClassNames = new String [0]; 60 } 61 this.schema = entry.getConnection().getSchema(); 62 } 63 64 65 public Subschema( String [] objectClassNames, IConnection connection ) 66 { 67 this.objectClassNames = objectClassNames; 68 this.schema = connection.getSchema(); 69 } 70 71 72 77 public String [] getObjectClassNames() 78 { 79 return this.objectClassNames; 80 } 81 82 83 89 public String [] getMustAttributeNames() 90 { 91 Set mustAttrSet = new TreeSet (); 92 for ( int i = 0; i < this.objectClassNames.length; i++ ) 93 { 94 this.fetchMust( this.objectClassNames[i], mustAttrSet ); 95 } 96 return ( String [] ) mustAttrSet.toArray( new String [0] ); 97 } 98 99 100 106 public AttributeTypeDescription[] getMustAttributeTypeDescriptions() 107 { 108 String [] musts = getMustAttributeNames(); 109 AttributeTypeDescription[] atds = new AttributeTypeDescription[musts.length]; 110 for ( int i = 0; i < musts.length; i++ ) 111 { 112 AttributeTypeDescription atd = getSchema().getAttributeTypeDescription( musts[i] ); 113 atds[i] = atd; 114 } 115 return atds; 116 } 117 118 119 private void fetchMust( String ocName, Set attributeSet ) 120 { 121 ObjectClassDescription ocd = this.getSchema().getObjectClassDescription( ocName ); 123 attributeSet.addAll( Arrays.asList( ocd.getMustAttributeTypeDescriptionNames() ) ); 124 125 if ( ocd.getSuperiorObjectClassDescriptionNames() != null ) 127 { 128 for ( int k = 0; k < ocd.getSuperiorObjectClassDescriptionNames().length; k++ ) 129 { 130 fetchMust( ocd.getSuperiorObjectClassDescriptionNames()[k], attributeSet ); 131 } 132 } 133 } 134 135 136 141 public String [] getMayAttributeNames() 142 { 143 Set mayAttrSet = new TreeSet (); 144 for ( int i = 0; i < this.objectClassNames.length; i++ ) 145 { 146 this.fetchMay( this.objectClassNames[i], mayAttrSet ); 147 } 148 return ( String [] ) mayAttrSet.toArray( new String [0] ); 149 } 150 151 152 157 public AttributeTypeDescription[] getMayAttributeTypeDescriptions() 158 { 159 String [] mays = getMayAttributeNames(); 160 AttributeTypeDescription[] atds = new AttributeTypeDescription[mays.length]; 161 for ( int i = 0; i < mays.length; i++ ) 162 { 163 AttributeTypeDescription atd = getSchema().getAttributeTypeDescription( mays[i] ); 164 atds[i] = atd; 165 } 166 return atds; 167 } 168 169 170 private void fetchMay( String ocName, Set attributeSet ) 171 { 172 ObjectClassDescription ocd = this.getSchema().getObjectClassDescription( ocName ); 174 attributeSet.addAll( Arrays.asList( ocd.getMayAttributeTypeDescriptionNames() ) ); 175 176 if ( ocd.getSuperiorObjectClassDescriptionNames() != null ) 178 { 179 for ( int k = 0; k < ocd.getSuperiorObjectClassDescriptionNames().length; k++ ) 180 { 181 fetchMay( ocd.getSuperiorObjectClassDescriptionNames()[k], attributeSet ); 182 } 183 } 184 } 185 186 187 193 public String [] getAllAttributeNames() 194 { 195 return ( String [] ) getAllAttributeNameSet().toArray( new String [0] ); 196 } 197 198 199 public Set getAllAttributeNameSet() 200 { 201 if ( this.allAttributeNameSet == null ) 202 { 203 this.allAttributeNameSet = new TreeSet (); 204 this.allAttributeNameSet.addAll( Arrays.asList( this.getMustAttributeNames() ) ); 205 this.allAttributeNameSet.addAll( Arrays.asList( this.getMayAttributeNames() ) ); 206 } 207 208 return this.allAttributeNameSet; 209 } 210 211 212 private Schema getSchema() 213 { 214 return schema; 215 } 218 219 } 220 | Popular Tags |