1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import java.io.Serializable ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 30 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; 31 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; 32 33 34 public class AttributeDescription implements Serializable 35 { 36 37 private static final long serialVersionUID = 1L; 38 39 private String description; 40 41 private String parsedAttributeType; 42 43 private List parsedLangList; 44 45 private List parsedOptionList; 46 47 48 public AttributeDescription( String description ) 49 { 50 51 this.description = description; 52 53 String [] attributeDescriptionComponents = description.split( IAttribute.OPTION_DELIMITER ); 54 this.parsedAttributeType = attributeDescriptionComponents[0]; 55 this.parsedLangList = new ArrayList (); 56 this.parsedOptionList = new ArrayList (); 57 for ( int i = 1; i < attributeDescriptionComponents.length; i++ ) 58 { 59 if ( attributeDescriptionComponents[i].startsWith( IAttribute.OPTION_LANG_PREFIX ) ) 60 { 61 this.parsedLangList.add( attributeDescriptionComponents[i] ); 62 } 63 else 64 { 65 this.parsedOptionList.add( attributeDescriptionComponents[i] ); 66 } 67 } 68 } 69 70 71 public String getDescription() 72 { 73 return description; 74 } 75 76 77 public String getParsedAttributeType() 78 { 79 return parsedAttributeType; 80 } 81 82 83 public List getParsedLangList() 84 { 85 return parsedLangList; 86 } 87 88 89 public List getParsedOptionList() 90 { 91 return parsedOptionList; 92 } 93 94 95 public String toOidString( Schema schema ) 96 { 97 98 if ( schema == null ) 99 { 100 return description; 101 } 102 103 AttributeTypeDescription atd = schema.getAttributeTypeDescription( parsedAttributeType ); 104 String oidString = atd.getNumericOID(); 105 106 if ( !parsedLangList.isEmpty() ) 107 { 108 for ( Iterator it = parsedLangList.iterator(); it.hasNext(); ) 109 { 110 String element = ( String ) it.next(); 111 oidString += element; 112 113 if ( it.hasNext() || !parsedOptionList.isEmpty() ) 114 { 115 oidString += IAttribute.OPTION_DELIMITER; 116 } 117 } 118 } 119 if ( !parsedOptionList.isEmpty() ) 120 { 121 for ( Iterator it = parsedOptionList.iterator(); it.hasNext(); ) 122 { 123 String element = ( String ) it.next(); 124 oidString += element; 125 126 if ( it.hasNext() ) 127 { 128 oidString += IAttribute.OPTION_DELIMITER; 129 } 130 } 131 } 132 133 return oidString; 134 } 135 136 137 public boolean isSubtypeOf( AttributeDescription other, Schema schema ) 138 { 139 140 148 if ( this.toOidString( schema ).equals( other.toOidString( schema ) ) ) 150 { 151 return false; 152 } 153 154 AttributeTypeDescription myAtd = schema.getAttributeTypeDescription( this.getParsedAttributeType() ); 156 AttributeTypeDescription otherAtd = schema.getAttributeTypeDescription( other.getParsedAttributeType() ); 157 if ( myAtd != otherAtd ) 158 { 159 AttributeTypeDescription superiorAtd = null; 160 String superiorName = myAtd.getSuperiorAttributeTypeDescriptionName(); 161 while ( superiorName != null ) 162 { 163 superiorAtd = schema.getAttributeTypeDescription( superiorName ); 164 if ( superiorAtd == otherAtd ) 165 { 166 break; 167 } 168 superiorName = superiorAtd.getSuperiorAttributeTypeDescriptionName(); 169 } 170 if ( superiorAtd != otherAtd ) 171 { 172 return false; 173 } 174 } 175 176 List myOptionsList = new ArrayList ( this.getParsedOptionList() ); 178 List otherOptionsList = new ArrayList ( other.getParsedOptionList() ); 179 otherOptionsList.removeAll( myOptionsList ); 180 if ( !otherOptionsList.isEmpty() ) 181 { 182 return false; 183 } 184 185 List myLangList = new ArrayList ( this.getParsedLangList() ); 187 List otherLangList = new ArrayList ( other.getParsedLangList() ); 188 for ( Iterator myIt = myLangList.iterator(); myIt.hasNext(); ) 189 { 190 String myLang = ( String ) myIt.next(); 191 for ( Iterator otherIt = otherLangList.iterator(); otherIt.hasNext(); ) 192 { 193 String otherLang = ( String ) otherIt.next(); 194 if ( otherLang.endsWith( "-" ) ) 195 { 196 if ( myLang.toLowerCase().startsWith( otherLang.toLowerCase() ) ) 197 { 198 otherIt.remove(); 199 } 200 } 201 else 202 { 203 if ( myLang.equalsIgnoreCase( otherLang ) ) 204 { 205 otherIt.remove(); 206 } 207 } 208 } 209 } 210 if ( !otherLangList.isEmpty() ) 211 { 212 return false; 213 } 214 215 return true; 216 } 217 218 } 219 | Popular Tags |