View Javadoc
1   /*
2    * *************************************************************************************************************************************************************
3    *
4    * TheseFoolishThings: Miscellaneous utilities
5    * http://tidalwave.it/projects/thesefoolishthings
6    *
7    * Copyright (C) 2009 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8    *
9    * *************************************************************************************************************************************************************
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   *
14   *     http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17   * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
18   *
19   * *************************************************************************************************************************************************************
20   *
21   * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
22   * git clone https://github.com/tidalwave-it/thesefoolishthings-src
23   *
24   * *************************************************************************************************************************************************************
25   */
26  package it.tidalwave.actor.impl;
27  
28  import javax.annotation.Nonnull;
29  import javax.inject.Provider;
30  
31  /***************************************************************************************************************************************************************
32   *
33   * A trimmed down replacement for OpenBlueSky Locator, in order to avoid depending on OpenBlueSky.
34   *
35   * @author  Fabrizio Giudici
36   *
37   **************************************************************************************************************************************************************/
38  public class Locator
39    {
40      public static class NotFoundException extends RuntimeException
41        {
42          NotFoundException (@Nonnull final Class<?> serviceClass)
43            {
44              super("Not found: " + serviceClass);
45            }
46  
47          NotFoundException (@Nonnull final String name)
48            {
49              super("Not found: " + name);
50            }
51        }
52  
53      @Nonnull
54      public static <T> Provider<T> createProviderFor (@Nonnull final Class<? extends T> serviceClass)
55        {
56          return new Provider<>()
57            {
58              @Override @Nonnull
59              public T get ()
60                {
61                  return find(serviceClass);
62                }
63            };
64        }
65  
66      /***********************************************************************************************************************************************************
67       **********************************************************************************************************************************************************/
68      @Nonnull
69      private static <T> T find (@Nonnull final Class<T> serviceClass)
70        {
71  //        final T service = Lookup.getDefault().lookup(serviceClass); FIXME
72  //
73  //        if (service == null)
74  //          {
75              throw new NotFoundException(serviceClass);
76  //          }
77  //
78  //        return service;
79        }
80    }