1 package org.exoplatform.services.xml.querying.impl.xtas.resource; 2 3 import java.net.MalformedURLException ; 4 import java.util.Collection ; 5 import java.util.Iterator ; 6 import org.exoplatform.services.xml.querying.ConfigException; 7 import org.exoplatform.services.xml.querying.impl.xtas.XMLConfig; 8 import org.exoplatform.services.xml.querying.impl.xtas.resource.plugins.LocalFile; 9 10 11 16 public class ResourceResolver { 17 18 private static ResourceResolver resolver = null; 19 private Collection descriptors; 20 21 23 24 25 protected ResourceResolver() throws ConfigException 26 { 27 descriptors = XMLConfig.getInstance().getResources(); 28 } 29 30 public static ResourceResolver getInstance() throws ConfigException 31 { 32 if (resolver == null) { 33 resolver = new ResourceResolver(); 34 } 35 return resolver; 36 } 37 38 41 public Resource getResource(String resourceId) throws MalformedURLException , ConfigException 42 { 43 44 Iterator iter = descriptors.iterator(); 45 Resource res = null; 46 47 while(iter.hasNext()) { 48 ResourceDescriptor descr = (ResourceDescriptor) iter.next(); 49 String prefix = descr.getPrefix(); 50 51 if(prefix != null && prefix.length() <= resourceId.length()){ 52 53 if ( prefix.equals( resourceId.substring( 0, prefix.length() ) ) ) { 54 try { 55 res = (Resource)Class.forName(descr.getClassname()).newInstance(); 56 } catch (Exception e) { 57 throw new ConfigException("XTAS Resource Config Exception - can not instantiate: "+e.getMessage()); 58 } 59 res.init( resourceId ); 60 return res; 61 } 62 } 63 } 64 69 return new LocalFile( resourceId ); 70 } 71 } 72 | Popular Tags |