Hi, since you are using uimaFIT, did you look at the documentation here
https://code.google.com/p/uimafit/wiki/ExternalResources In particular, it makes a difference if the component you want to inject the resource into uses the uimaFIT @ExternalResource annotation and inherits from the uimaFIT base classes for resource or invokes ExternalResourceInitializer itself. If that is the case, the uimaFIT factory create* factory methdos already create the ExternalResourceDependency for you. If you are using a non-uimaFIT-aware component, you need to use createDependencyAndBind. That said, you seem to try to instantiate the external resource yourself (maybe as a test?), normally the UIMA ResourceManager should do that for you when you run a pipeline. At appears to me that ResourceManager_impl is not using UIMAFramework.produceResource() instantiate the resource (cf. UIMA 2.4.0 ResourceManager_impl lines 520ff and 290ff). So I suppose there is a chance it works if you just don't try to instantiate the resource yourself and leave it to UIMA. Cheers, -- Richard Am 30.05.2013 um 09:43 schrieb Mansi verma <[email protected]>: > Hi > > I have to load a set of files as external resources in uima. The annotator > reads a file containing the list of files to load in the engine as shared > resource. Since the number of files may change, I cannot bind them in the > descriptor. > > To accomplish this I used the following snippet of code. However it throws > an exception of invalid class cast. > > ExternalResourceDescription extDesc = ExternalResourceFactory. > createExternalResourceDescription(key,MyResource_impl.class, > fileName); > Map<String, Object> initParams = new HashMap<String, Object>() ; > MyResource file = > (MyResource_impl)UIMAFramework.produceResource(extDep..getResourceSpecifier(), > initParams); > > Now the error is as follows : > Caused by: java.lang.ClassCastException: > org.apache.uima.resource.impl.ConfigurableDataResource_impl cannot be cast > to org.my.project.resource.MyResource_impl > > I tried an alternate approach too wherein I declared > ExternalResourceDependency but I do not know how to create an external > resource object using this dependency. The code is as follows > > ExternalResourceDependency extDep = > UIMAFramework.getResourceSpecifierFactory().createExternalResourceDependency(); > extDep.setDescription("file for "+key); > extDep.setInterfaceName(MyResource_impl.class.toString()); > extDep.setKey(key+"File"); > extDep.setOptional(false); > extDep.setSourceUrl(new URL(fileName)); > > Thanks > Manisha
