Re: 4.1 config file path migration question

Andrew Willerding <[email protected]>
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
I took the lazy way out and copied the FilesystemResourceLocator code to 
create my own non-deprecated version of it.  ;-)

On 2019-10-12 11:22 a.m., Andrew Willerding wrote:
> Thank you John.  This seems like a lot of work for something that 
> seems to work so simply now and is easy to read/implement in one line 
> of code.
>
> Does the FilesystemResourceLocator really need to be removed?  It 
> seems like a very nice "helper" object to me.
>
>
> On 2019-10-11 10:13 a.m., John Huss wrote:
>> You'll have to subclass ResourceLocator and implement it:
>>
>>      /**
>>
>>       * Finds a collection of matching resources for a given name. 
>> The name
>> components must
>>
>>       * be separated by forward slashes.
>>
>>       */
>>
>>      Collection<Resource> findResources(String name);
>>
>>
>>
>> For example, The name portion could just be the file name
>> "cayenne-blah.xml", and your subclass could hardcode the directory path.
>> The logic could be copied from FilesystemResourceLocator:
>>
>>
>>              File resourceFile = *new* File(root, name);
>>
>>              *if* (resourceFile.exists()) {
>>
>>                  *try* {
>>
>>                      resources.add(*new* URLResource(resourceFile
>> .toURI().toURL()));
>>
>>                  }
>>
>>                  *catch* (MalformedURLException e) {
>>
>>                      *throw* *new* CayenneRuntimeException("Can't 
>> convert
>> file to URL: %s", e,  resourceFile.getAbsolutePath());
>>
>>                  }
>>
>>              }
>>
>>
>>
>> Binding it using DI looks like this:
>>
>>
>>          // a locator of resources, such as XML descriptors
>>
>> binder.bind(ResourceLocator.*class*).to(MyResourceLocator.*class*);
>>
>>          binder.bind(Key.*get*(ResourceLocator.*class*, Constants.
>> *SERVER_RESOURCE_LOCATOR*)).to(MyResourceLocator.*class*);
>>
>>
>> On Fri, Oct 11, 2019 at 8:57 AM Andrew Willerding 
>> <[email protected]>
>> wrote:
>>
>>> I have hopefully a quick question on how Cayenne can be configured to
>>> use a configuration file outside of a JAR/WAR.
>>>
>>> I currently use this to reference an absolute file path for my Cayenne
>>> files but I see that FilesystemResourceLocator is now deprecated ...
>>>
>>>               Module myModule = (org.apache.cayenne.di.Binder 
>>> binder) -> {
>>> binder.bind(ResourceLocator.class).toInstance(new
>>> FilesystemResourceLocator(filePathForCayenne));
>>>                   ...
>>>
>>> What is the "new" way to replicate the same functionality. The
>>> deprecated notes just provide the same example I'm already using.
>>>
>>> Thanks,
>>>
>>> Andrew
>>>
>>>
>>>
>>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.