Java Code Examples for javax.resource.spi.ActivationSpec#validate()

The following examples show how to use javax.resource.spi.ActivationSpec#validate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceAdapterImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void endpointActivation(MessageEndpointFactory mef, ActivationSpec as) throws Exception
{
   if (mef == null)
      throw new Exception("MessageEndpointFactory is null");

   if (as == null)
      throw new Exception("ActivationSpec is null");

   as.setResourceAdapter(resourceAdapter);
   
   try
   {
      as.validate();
   }
   catch (UnsupportedOperationException uoe)
   {
      // Ignore
   }

   if (is16)
   {
      verifyBeanValidation(as);
   }
   
   resourceAdapter.endpointActivation(mef, as);

   InflowRecovery ir = null;
   if (transactionIntegration != null && transactionIntegration.getRecoveryRegistry() != null)
   {
      XAResourceRecovery xar = transactionIntegration.createXAResourceRecovery(resourceAdapter,
                                                                               as,
                                                                               productName, productVersion);

      ir = new InflowRecoveryImpl(mef, as, xar, transactionIntegration.getRecoveryRegistry());
      ir.activate();
   }

   activeEndpoints.put(new Endpoint(mef, as), ir);
}
 
Example 2
Source File: EndpointImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public void activate(MessageEndpointFactory endpointFactory,
                     ActivationSpec spec) throws ResourceException
{
   if (endpointFactory == null)
      throw new IllegalArgumentException("MessageEndpointFactory is null");

   if (spec == null)
      throw new IllegalArgumentException("ActivationSpec is null");

   ResourceAdapter rar = ra.get();

   if (rar == null)
      throw new ResourceException(bundle.resourceAdapterInstanceNotActive());

   if (is16 && bvEnabled)
   {
      ClassLoader oldTCCL = SecurityActions.getThreadContextClassLoader();
      try
      {
         SecurityActions.setThreadContextClassLoader(SecurityActions.getClassLoader(rar.getClass()));
         
         List<Class<?>> groups = new ArrayList<Class<?>>(1);

         if (beanValidationGroups != null)
         {
            for (String group : beanValidationGroups)
            {
               try
               {
                  Class<?> clz = Class.forName(group, true, SecurityActions.getClassLoader(rar.getClass()));
                  groups.add(clz);
               }
               catch (Throwable t)
               {
                  log.debugf(t, "Unable to load bean validation group: %s", group);
               }
            }
         }

         if (groups.isEmpty())
            groups.add(Default.class);

         Validator validator = BeanValidationUtil.createValidator();
         Class[] vargs = groups.toArray(new Class[groups.size()]);

         Set errors = validator.validate(spec, vargs);

         if (errors != null && errors.size() > 0)
         {
            throw new ResourceException(bundle.validationException(), new ConstraintViolationException(errors));
         }
      }
      catch (RuntimeException re)
      {
         throw new ResourceException(bundle.validationException(), re);
      }
      finally
      {
         SecurityActions.setThreadContextClassLoader(oldTCCL);
      }
   }

   try
   {
      spec.validate();
   }
   catch (UnsupportedOperationException uoe)
   {
      // Ignore
   }

   rar.endpointActivation(endpointFactory, spec);

   if (transactionIntegration != null && transactionIntegration.getRecoveryRegistry() != null && xa)
   {
      XAResourceRecovery xrr = transactionIntegration.createXAResourceRecovery(rar, spec,
                                                                               productName, productVersion);

      log.tracef("Adding %s for recovery", xrr);

      try
      {
         xrr.initialize();
         transactionIntegration.getRecoveryRegistry().addXAResourceRecovery(xrr);
         recovery.put(spec, xrr);
      }
      catch (Exception e)
      {
         throw new ResourceException(bundle.errorDuringRecoveryInitialization(), e);
      }
   }
}