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
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.webservices.injection;
 
 import java.util.Map;
 

Author(s):
Richard Opalka
 
 public final class InjectionDeploymentAspect extends AbstractDeploymentAspect {
 
     @Override
     public void start(final Deployment dep) {
         for (final Endpoint ep : dep.getService().getEndpoints()) {
             setInjectionAwareInstanceProvider(ep);
         }
     }
 
     private void setInjectionAwareInstanceProvider(final Endpoint ep) {
         final InstanceProvider stackInstanceProvider = ep.getInstanceProvider();
         final DeploymentUnit unit = ep.getService().getDeployment().getAttachment(DeploymentUnit.class);
         final InstanceProvider injectionAwareInstanceProvider = new InjectionAwareInstanceProvider(stackInstanceProviderepunit);
         ep.setInstanceProvider(injectionAwareInstanceProvider);
     }
 
     private static final class InjectionAwareInstanceProvider implements InstanceProvider {
         private final InstanceProvider delegate;
         private final String endpointName;
         private final String endpointClass;
         private final ServiceName componentPrefix;
         private static final String componentSuffix = "START";
         private final Map<StringReferencecache = new HashMap<StringReference>(8);
 
         private InjectionAwareInstanceProvider(final InstanceProvider delegatefinal Endpoint endpointfinal DeploymentUnit unit) {
             this. = delegate;
              = endpoint.getShortName();
              = endpoint.getTargetBeanName();
              = unit.getServiceName().append("component");
         }
 
         @Override
         public synchronized Reference getInstance(final String className) {
             Reference instance = .get(className);
             if (instance != nullreturn instance;
 
             if (!className.equals()) {
                 // handle JAXWS handler instantiation
                 final ServiceName handlerComponentName = getHandlerComponentServiceName(className);
                 final ServiceController<BasicComponenthandlerComponentController = getComponentController(handlerComponentName);
                 if (handlerComponentController != null) {
                     // we support initialization only on non system JAXWS handlers
                     final BasicComponent handlerComponent = handlerComponentController.getValue();
                     final ComponentInstance handlerComponentInstance = handlerComponent.createInstance(.getInstance(className).getValue());
                     final Object handlerInstance = handlerComponentInstance.getInstance();
                     // mark reference as initialized because JBoss server initialized it
                     final Reference handlerReference = ReferenceFactory.newInitializedReference(handlerInstance);
                     return cacheAndGet(handlerReference);
                 }
             }
             // fallback for system JAXWS handlers
             final Reference fallbackInstance = .getInstance(className);
             final Reference fallbackReference = ReferenceFactory.newUninitializedReference(fallbackInstance);
             return cacheAndGet(fallbackReference);
         }
        private Reference cacheAndGet(final Reference instance) {
            .put(instance.getValue().getClass().getName(), instance);
            return instance;
        }
        private ServiceName getHandlerComponentServiceName(final String handlerClassName) {
            return .append( + "-" + handlerClassName).append();
        }
        @SuppressWarnings("unchecked")
        private static ServiceController<BasicComponentgetComponentController(final ServiceName componentName) {
            return (ServiceController<BasicComponent>) currentServiceContainer().getService(componentName);
        }
    }
    private static ServiceContainer currentServiceContainer() {
        if(System.getSecurityManager() == null) {
            return CurrentServiceContainer.getServiceContainer();
        }
        return AccessController.doPrivileged(.);
    }
New to GrepCode? Check out our FAQ X