Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2014, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * 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 CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.bootstrap;
 
 import java.util.Set;
 
 
Loads Service implementations using ServiceLoader. This can be used e.g. by a JTA library in weld-servlet environment to provide TransactionServices implementation which would not otherwise be provided by weld-servlet. Deployment classloaders, TCCL and Weld's classloader are used to discover service implementations. Service implementation may specify their priority using Priority. Services with higher priority have precedence. Services that do not specify priority have the default priority of 4500. See https://issues.jboss.org/browse/WELD-1495 for details.

Author(s):
Jozef Hartinger
 
 
     private static final int DEFAULT_PLATFORM_PRIORITY = 4500;
 
     private final Deployment deployment;
 
     AdditionalServiceLoader(Deployment deployment) {
         this. = deployment;
     }

    
Discovers additional services using ServiceLoader and appends them to the given service registry.

Parameters:
registry the given service registry
 
     void loadAdditionalServices(ServiceRegistry registry) {
         for (ResourceLoader loader : getResourceLoaders()) {
             for (Metadata<Servicemetadata : ServiceLoader.load(Service.classloader)) {
                 Service service = metadata.getValue();
                 for (Class<? extends ServiceserviceInterface : identifyServiceInterfaces(service.getClass(), new HashSet<Class<? extends Service>>())) {
                     put(registryserviceInterfaceservice);
                 }
             }
         }
     }

    
Identifies service views for a service implementation class. A service view is either: - an interface that directly extends Service or BootstrapService - a clazz that directly implements Service or BootstrapService

Parameters:
clazz the given class
serviceInterfaces a set that this method populates with service views
Returns:
serviceInterfaces
 
     private Set<Class<? extends Service>> identifyServiceInterfaces(Class<?> clazzSet<Class<? extends Service>> serviceInterfaces) {
         if (clazz == null || Object.class.equals(clazz) || BootstrapService.class.equals(clazz)) {
             return serviceInterfaces;
         }
         for (Class<?> interfac3 : clazz.getInterfaces()) {
             if (Service.class.equals(interfac3) || BootstrapService.class.equals(interfac3)) {
                 serviceInterfaces.add(Reflections.<Class<? extends Service>>cast(clazz));
             }
         }
         for (Class<?> interfac3 : clazz.getInterfaces()) {
             identifyServiceInterfaces(interfac3serviceInterfaces);
         }
         identifyServiceInterfaces(clazz.getSuperclass(), serviceInterfaces);
         return serviceInterfaces;
     }
 
     private <T extends Servicevoid put(ServiceRegistry registryClass<T> keyService value) {
         Service previous = registry.get(key);
        if (previous == null) {
            ..debugv("Installing additional service {0} ({1})"key.getName(), value.getClass());
            registry.add(key, Reflections.<T>cast(value));
        } else if (shouldOverride(keypreviousvalue)) {
            ..debugv("Overriding service implementation for {0}. Previous implementation {1} is replaced with {2}"key.getName(), previous
                    .getClass().getName(), value.getClass().getName());
            registry.add(key, Reflections.<T>cast(value));
        }
    }
    protected boolean shouldOverride(Class<? extends ServicekeyService previousService next) {
        return getPriority(next) > getPriority(previous);
    }
    private int getPriority(Service service) {
        Priority priority = service.getClass().getAnnotation(Priority.class);
        if (priority != null) {
            return priority.value();
        }
        return ;
    }
    private Set<ResourceLoadergetResourceLoaders() {
        Set<ResourceLoaderresourceLoaders = new HashSet<ResourceLoader>();
        for (BeanDeploymentArchive archive : .getBeanDeploymentArchives()) {
            ResourceLoader resourceLoader = archive.getServices().get(ResourceLoader.class);
            if (resourceLoader != null) {
                resourceLoaders.add(resourceLoader);
            }
        }
        resourceLoaders.add(.);
        resourceLoaders.add(.);
        return resourceLoaders;
    }
New to GrepCode? Check out our FAQ X