<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FReflection%2FOSGI</id>
		<title>Java/Reflection/OSGI - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FReflection%2FOSGI"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Reflection/OSGI&amp;action=history"/>
		<updated>2026-04-22T18:50:12Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Reflection/OSGI&amp;diff=6081&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Reflection/OSGI&amp;diff=6081&amp;oldid=prev"/>
				<updated>2010-06-01T06:01:54Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:01, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Reflection/OSGI&amp;diff=6080&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Reflection/OSGI&amp;diff=6080&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Maintains a mapping of service names to an ordered set of service providers when running in an OSGi container. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
 * you may not use this file except in compliance with the License.&lt;br /&gt;
 * You may obtain a copy of the License at&lt;br /&gt;
 * &lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 * &lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.HashMap;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Map;&lt;br /&gt;
import java.util.concurrent.Callable;&lt;br /&gt;
/**&lt;br /&gt;
 * Maintains a mapping of service names to an ordered set of service providers&lt;br /&gt;
 * when running in an OSGi container. &amp;lt;p/&amp;gt; It is expected that a bundle using&lt;br /&gt;
 * Drools will populate this map with properties from its own ClassLoader. &amp;lt;p/&amp;gt;&lt;br /&gt;
 * This is an adaptation of the technique described by Guillaume Nodet in his&lt;br /&gt;
 * article&amp;lt;i&amp;gt; &amp;lt;/i&amp;gt;. The main changes were to add comments.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Guillaume Nodet&lt;br /&gt;
 * @author Faron Dutton&lt;br /&gt;
 * @see {@linkplain http://gnodet.blogspot.ru/2008/05/jee-specs-in-osgi.html}&lt;br /&gt;
 */&lt;br /&gt;
public final class OSGiLocator {&lt;br /&gt;
  /**&lt;br /&gt;
   * Maps a service name (the fully qualified name of the interface) to an&lt;br /&gt;
   * ordered set of factories. Each factory instantiating a specific service&lt;br /&gt;
   * provider (implementation).&lt;br /&gt;
   */&lt;br /&gt;
  private static Map&amp;lt;String, List&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt;&amp;gt; factories;&lt;br /&gt;
  /**&lt;br /&gt;
   * Private constructor used to prevent instantiation of this utility class&lt;br /&gt;
   * (i.e., Utility Pattern).&lt;br /&gt;
   */&lt;br /&gt;
  private OSGiLocator() {&lt;br /&gt;
    super();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Removes the given service provider factory from the set of providers for&lt;br /&gt;
   * the service.&lt;br /&gt;
   * &lt;br /&gt;
   * @param serviceName&lt;br /&gt;
   *          The fully qualified name of the service interface.&lt;br /&gt;
   * @param factory&lt;br /&gt;
   *          A factory for creating a specific type of service provider. May be&lt;br /&gt;
   *          &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt; in which case this method does nothing.&lt;br /&gt;
   * @throws IllegalArgumentException&lt;br /&gt;
   *           if serviceName is &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt;&lt;br /&gt;
   */&lt;br /&gt;
  public static synchronized void unregister(final String serviceName,&lt;br /&gt;
      final Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; factory) {&lt;br /&gt;
    if (serviceName == null) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;serviceName cannot be null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    if (factories != null) {&lt;br /&gt;
      List&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt; l = factories.get(serviceName);&lt;br /&gt;
      if (l != null) {&lt;br /&gt;
        l.remove(factory);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Adds the given service provider factory to the set of providers for the&lt;br /&gt;
   * service.&lt;br /&gt;
   * &lt;br /&gt;
   * @param serviceName&lt;br /&gt;
   *          The fully qualified name of the service interface.&lt;br /&gt;
   * @param factory&lt;br /&gt;
   *          A factory for creating a specific type of service provider. May be&lt;br /&gt;
   *          &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt; in which case this method does nothing.&lt;br /&gt;
   * @throws IllegalArgumentException&lt;br /&gt;
   *           if serviceName is &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt;&lt;br /&gt;
   */&lt;br /&gt;
  public static synchronized void register(final String serviceName,&lt;br /&gt;
      final Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; factory) {&lt;br /&gt;
    if (serviceName == null) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;serviceName cannot be null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    if (factory != null) {&lt;br /&gt;
      if (factories == null) {&lt;br /&gt;
        factories = new HashMap&amp;lt;String, List&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt;&amp;gt;();&lt;br /&gt;
      }&lt;br /&gt;
      List&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt; l = factories.get(serviceName);&lt;br /&gt;
      if (l == null) {&lt;br /&gt;
        l = new ArrayList&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt;();&lt;br /&gt;
        factories.put(serviceName, l);&lt;br /&gt;
      }&lt;br /&gt;
      l.add(factory);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Finds the preferred provider for the given service. The preferred provider&lt;br /&gt;
   * is the last one added to the set of providers.&lt;br /&gt;
   * &lt;br /&gt;
   * @param serviceName&lt;br /&gt;
   *          The fully qualified name of the service interface.&lt;br /&gt;
   * @return The last provider added for the service if any exists. Otherwise,&lt;br /&gt;
   *         it returns &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt;.&lt;br /&gt;
   * @throws IllegalArgumentException&lt;br /&gt;
   *           if serviceName is &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt;&lt;br /&gt;
   */&lt;br /&gt;
  public static synchronized Class&amp;lt;?&amp;gt; locate(final String serviceName) {&lt;br /&gt;
    if (serviceName == null) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;serviceName cannot be null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    if (factories != null) {&lt;br /&gt;
      List&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt; l = factories.get(serviceName);&lt;br /&gt;
      if (l != null &amp;amp;&amp;amp; !l.isEmpty()) {&lt;br /&gt;
        Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; c = l.get(l.size() - 1);&lt;br /&gt;
        try {&lt;br /&gt;
          return c.call();&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Finds all providers for the given service.&lt;br /&gt;
   * &lt;br /&gt;
   * @param serviceName&lt;br /&gt;
   *          The fully qualified name of the service interface.&lt;br /&gt;
   * @return The ordered set of providers for the service if any exists.&lt;br /&gt;
   *         Otherwise, it returns an empty list.&lt;br /&gt;
   * @throws IllegalArgumentException&lt;br /&gt;
   *           if serviceName is &amp;lt;tt&amp;gt;null&amp;lt;/tt&amp;gt;&lt;br /&gt;
   */&lt;br /&gt;
  public static synchronized List&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; locateAll(final String serviceName) {&lt;br /&gt;
    if (serviceName == null) {&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;serviceName cannot be null&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    List&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; classes = new ArrayList&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;();&lt;br /&gt;
    if (factories != null) {&lt;br /&gt;
      List&amp;lt;Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;&amp;gt; l = factories.get(serviceName);&lt;br /&gt;
      if (l != null) {&lt;br /&gt;
        for (Callable&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; c : l) {&lt;br /&gt;
          try {&lt;br /&gt;
            classes.add(c.call());&lt;br /&gt;
          } catch (Exception e) {&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return classes;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>