1 20 21 package org.apache.directory.ldapstudio.schemas.model; 22 23 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 28 import org.apache.commons.configuration.XMLConfiguration; 29 import org.apache.directory.ldapstudio.schemas.Activator; 30 import org.eclipse.core.runtime.Platform; 31 32 33 40 public class MatchingRules 41 { 42 43 private static final ArrayList <MatchingRule> equalityMatchingRules; 44 45 46 private static final ArrayList <MatchingRule> orderingMatchingRules; 47 48 49 private static final ArrayList <MatchingRule> substringMatchingRules; 50 51 static 53 { 54 try 55 { 56 equalityMatchingRules = new ArrayList <MatchingRule>(); 57 URL url = Platform.getBundle( Activator.PLUGIN_ID ).getResource( "ressources/utils/matching_rules.xml" ); XMLConfiguration config = new XMLConfiguration( url ); 59 60 Object matchingRules = config.getProperty( "equality.matchingRule.name" ); if ( matchingRules instanceof Collection ) 63 { 64 for ( int i = 0; i < ( ( Collection ) matchingRules ).size(); i++ ) 65 { 66 String name = config.getString( "equality.matchingRule(" + i + ").name" ); String oid = config.getString( "equality.matchingRule(" + i + ").oid" ); String syntax = config.getString( "equality.matchingRule(" + i + ").syntax" ); 71 MatchingRule matchingRule = new MatchingRule( name, oid, syntax ); 73 equalityMatchingRules.add( matchingRule ); 74 } 75 } 76 } 77 catch ( Throwable e ) 78 { 79 throw new RuntimeException ( e.getMessage() ); 80 } 81 } 82 83 static 85 { 86 try 87 { 88 orderingMatchingRules = new ArrayList <MatchingRule>(); 89 90 URL url = Platform.getBundle( Activator.PLUGIN_ID ).getResource( "ressources/utils/matching_rules.xml" ); XMLConfiguration config = new XMLConfiguration( url ); 92 93 Object matchingRules = config.getProperty( "ordering.matchingRule.name" ); if ( matchingRules instanceof Collection ) 96 { 97 for ( int i = 0; i < ( ( Collection ) matchingRules ).size(); i++ ) 98 { 99 String name = config.getString( "ordering.matchingRule(" + i + ").name" ); String oid = config.getString( "ordering.matchingRule(" + i + ").oid" ); String syntax = config.getString( "ordering.matchingRule(" + i + ").syntax" ); 104 MatchingRule matchingRule = new MatchingRule( name, oid, syntax ); 106 orderingMatchingRules.add( matchingRule ); 107 } 108 } 109 } 110 catch ( Throwable e ) 111 { 112 throw new RuntimeException ( e.getMessage() ); 113 } 114 } 115 116 static 118 { 119 try 120 { 121 substringMatchingRules = new ArrayList <MatchingRule>(); 122 URL url = Platform.getBundle( Activator.PLUGIN_ID ).getResource( "ressources/utils/matching_rules.xml" ); XMLConfiguration config = new XMLConfiguration( url ); 124 125 Object matchingRules = config.getProperty( "substring.matchingRule.name" ); if ( matchingRules instanceof Collection ) 128 { 129 for ( int i = 0; i < ( ( Collection ) matchingRules ).size(); i++ ) 130 { 131 String name = config.getString( "substring.matchingRule(" + i + ").name" ); String oid = config.getString( "substring.matchingRule(" + i + ").oid" ); String syntax = config.getString( "substring.matchingRule(" + i + ").syntax" ); 136 MatchingRule matchingRule = new MatchingRule( name, oid, syntax ); 138 substringMatchingRules.add( matchingRule ); 139 } 140 } 141 } 142 catch ( Throwable e ) 143 { 144 throw new RuntimeException ( e.getMessage() ); 145 } 146 } 147 148 149 154 public static ArrayList <MatchingRule> getEqualityMatchingRules() 155 { 156 return equalityMatchingRules; 157 } 158 159 160 166 public static ArrayList <MatchingRule> getOrderingMatchingRules() 167 { 168 return orderingMatchingRules; 169 } 170 171 172 178 public static ArrayList <MatchingRule> getSubstringMatchingRules() 179 { 180 return substringMatchingRules; 181 } 182 183 184 192 public static MatchingRule getMatchingRule( String name ) 193 { 194 if ( name == null ) 195 { 196 return null; 197 } 198 199 for ( MatchingRule matchingRule : equalityMatchingRules ) 200 { 201 if ( name.equalsIgnoreCase( matchingRule.getName() ) ) 202 { 203 return matchingRule; 204 } 205 } 206 207 for ( MatchingRule matchingRule : orderingMatchingRules ) 208 { 209 if ( name.equalsIgnoreCase( matchingRule.getName() ) ) 210 { 211 return matchingRule; 212 } 213 } 214 215 for ( MatchingRule matchingRule : substringMatchingRules ) 216 { 217 if ( name.equalsIgnoreCase( matchingRule.getName() ) ) 218 { 219 return matchingRule; 220 } 221 } 222 223 return null; 224 } 225 } 226 | Popular Tags |