1 package org.antmod.descriptor; 2 3 import java.util.Iterator ; 4 5 import org.antmod.conf.AntmodProperties; 6 7 13 public class DescriptorStoreFactory { 14 15 public static DescriptorStore getConfiguredDescriptorStore() { 16 return getDescriptorStoreByType(AntmodProperties.getProperty("antmod.descriptor.provider")); 17 } 18 19 public static DescriptorStore getDescriptorStoreByType(String descType) { 20 String providerPropStart = "antmod.descriptor.providers."; 21 Iterator descriptorProviders = AntmodProperties.getPropertyNamesStartingWith(providerPropStart); 22 while (descriptorProviders.hasNext()) { 23 String providerPropName = (String )descriptorProviders.next(); 24 if (providerPropName.substring(providerPropStart.length()).equals(descType)) { 25 String providerImpl = AntmodProperties.getProperty(providerPropName); 26 try { 27 return (DescriptorStore)Class.forName(providerImpl).newInstance(); 28 } catch (InstantiationException e) { 29 e.printStackTrace(); 30 } catch (IllegalAccessException e) { 31 e.printStackTrace(); 32 } catch (ClassNotFoundException e) { 33 e.printStackTrace(); 34 } 35 } 36 } 37 throw new IllegalArgumentException ("Unknown descriptor store type: \"" + descType + "\""); 38 } 39 40 } 41 | Popular Tags |