Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt 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.weld.services.bootstrap;
 
 
 
 
 
     private static final String USER_TRANSACTION_LOCATION = "java:comp/UserTransaction";
     private static final String USER_TRANSACTION_CLASS_NAME = "javax.transaction.UserTransaction";
     private static final String HANDLE_DELEGATE_CLASS_NAME = "javax.ejb.spi.HandleDelegate";
     private static final String TIMER_SERVICE_CLASS_NAME = "javax.ejb.TimerService";
     private static final String ORB_CLASS_NAME = "org.omg.CORBA.ORB";
 
     private final Context context;
 
     protected static String getEJBResourceName(InjectionPoint injectionPointString proposedName) {
         if (injectionPoint.getType() instanceof Class<?>) {
             Class<?> type = (Class<?>) injectionPoint.getType();
             if (.equals(type.getName())) {
                 return ;
             } else if (.equals(type.getName())) {
                 ..injectionTypeNotValue(HandleDelegate.classinjectionPoint.getMember());
                 return proposedName;
             } else if (.equals(type.getName())) {
                 ..injectionTypeNotValue(org.omg.CORBA.ORB.classinjectionPoint.getMember());
                 return proposedName;
             } else if (.equals(type.getName())) {
                 ..injectionTypeNotValue(TimerService.classinjectionPoint.getMember());
                 return proposedName;
             }
         }
         return proposedName;
     }
 
     public WeldResourceInjectionServices(final ServiceRegistry serviceRegistryfinal EEModuleDescription moduleDescription) {
         super(serviceRegistrymoduleDescription);
         try {
             this. = new InitialContext();
         } catch (NamingException e) {
             throw new RuntimeException(e);
         }
     }
 
     protected String getResourceName(InjectionPoint injectionPoint) {
         Resource resource = injectionPoint.getAnnotated().getAnnotation(Resource.class);
         String mappedName = resource.mappedName();
         String lookup = resource.lookup();
         if (!lookup.isEmpty()) {
             return lookup;
         }
         if (!mappedName.isEmpty()) {
             return mappedName;
         }
         String proposedName = ResourceInjectionUtilities.getResourceName(injectionPoint);
         return getEJBResourceName(injectionPointproposedName);
     }
 
     @Override
         final String result = getResourceName(injectionPoint);
        if (isKnownNamespace(result)) {
            return handleServiceLookup(resultinjectionPoint);
        } else {
            return new ResourceReferenceFactory<Object>() {
                @Override
                public ResourceReference<ObjectcreateResource() {
                    return new SimpleResourceReference<Object>(resolveResource(injectionPoint));
                }
            };
        }
    }
    @Override
    public ResourceReferenceFactory<ObjectregisterResourceInjectionPoint(final String jndiNamefinal String mappedName) {
        final String result = ResourceInjectionUtilities.getResourceName(jndiNamemappedName);
        if (isKnownNamespace(result)) {
            return handleServiceLookup(resultnull);
        } else {
            return new ResourceReferenceFactory<Object>() {
                @Override
                public ResourceReference<ObjectcreateResource() {
                    return new SimpleResourceReference<Object>(resolveResource(jndiNamemappedName));
                }
            };
        }
    }
    private boolean isKnownNamespace(String name) {
        return name.startsWith("java:global") || name.startsWith("java:app") || name.startsWith("java:module")
                || name.startsWith("java:comp") || name.startsWith("java:jboss");
    }
    @Override
    public void cleanup() {
    }
    @Override
    protected BindInfo getBindInfo(String result) {
                .getModuleName(), falseresult);
    }
    @Override
    public Object resolveResource(InjectionPoint injectionPoint) {
        if (!injectionPoint.getAnnotated().isAnnotationPresent(Resource.class)) {
            throw new IllegalArgumentException("No @Resource annotation found on injection point " + injectionPoint);
        }
        if (injectionPoint.getMember() instanceof Method
                && ((MethodinjectionPoint.getMember()).getParameterTypes().length != 1) {
            throw new IllegalArgumentException(
                    "Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) "
                            + injectionPoint);
        }
        String name = getResourceName(injectionPoint);
        try {
            return .lookup(name);
        } catch (NamingException e) {
            throw new RuntimeException("Error looking up " + name + " in JNDI"e);
        }
    }
    @Override
    public Object resolveResource(String jndiNameString mappedName) {
        String name = ResourceInjectionUtilities.getResourceName(jndiNamemappedName);
        try {
            return .lookup(name);
        } catch (NamingException e) {
            throw new RuntimeException("Error looking up " + name + " in JNDI"e);
        }
    }
New to GrepCode? Check out our FAQ X