Package javax.validation

Examples of javax.validation.ValidatorFactory


    }
    return property;
  }

  private static ValidatorFactory getValidatorFactory(Map<Object, Object> properties) {
    ValidatorFactory factory = null;
    if ( properties != null ) {
      Object unsafeProperty = properties.get( FACTORY_PROPERTY );
      if (unsafeProperty != null) {
        try {
          factory = ValidatorFactory.class.cast( unsafeProperty );
View Full Code Here


                // so it has to be constructed before
                final List<CommonInfoObject> vfs = listCommonInfoObjectsForAppInfo(appInfo);

                final Map<String, ValidatorFactory> validatorFactories = new HashMap<String, ValidatorFactory>();
                for (final CommonInfoObject info : vfs) {
                    ValidatorFactory factory = null;
                    try {
                        factory = ValidatorBuilder.buildFactory(classLoader, info.validationInfo);
                    } catch (final ValidationException ve) {
                        logger.warning("can't build the validation factory for module " + info.uniqueId, ve);
                    }
                    if (factory != null) {
                        validatorFactories.put(info.uniqueId, factory);
                    }
                }

                // validators bindings
                for (final Entry<String, ValidatorFactory> validatorFactory : validatorFactories.entrySet()) {
                    final String id = validatorFactory.getKey();
                    final ValidatorFactory factory = validatorFactory.getValue();
                    try {
                        containerSystemContext.bind(VALIDATOR_FACTORY_NAMING_CONTEXT + id, factory);

                        Validator validator;
                        try {
                            validator = factory.usingContext().getValidator();
                        } catch (final Exception e) {
                            validator = (Validator) Proxy.newProxyInstance(appContext.getClassLoader(), new Class<?>[]{Validator.class}, new LazyValidator(factory));
                        }

                        containerSystemContext.bind(VALIDATOR_NAMING_CONTEXT + id, validator);
                    } catch (final NameAlreadyBoundException e) {
                        throw new OpenEJBException("ValidatorFactory already exists for module " + id, e);
                    } catch (final Exception e) {
                        throw new OpenEJBException(e);
                    }
                }
            }

            // JPA - Persistence Units MUST be processed first since they will add ClassFileTransformers
            // to the class loader which must be added before any classes are loaded
            final Map<String, String> units = new HashMap<String, String>();
            final PersistenceBuilder persistenceBuilder = new PersistenceBuilder(persistenceClassLoaderHandler);
            for (final PersistenceUnitInfo info : appInfo.persistenceUnits) {
                final ReloadableEntityManagerFactory factory;
                try {
                    factory = persistenceBuilder.createEntityManagerFactory(info, classLoader);
                    containerSystem.getJNDIContext().bind(PERSISTENCE_UNIT_NAMING_CONTEXT + info.id, factory);
                    units.put(info.name, PERSISTENCE_UNIT_NAMING_CONTEXT + info.id);
                } catch (final NameAlreadyBoundException e) {
                    throw new OpenEJBException("PersistenceUnit already deployed: " + info.persistenceUnitRootUrl);
                } catch (final Exception e) {
                    throw new OpenEJBException(e);
                }

                factory.register();
            }

            logger.debug("Loaded peristence units: " + units);

            // Connectors
View Full Code Here

        this.configuration = configuration;
        this.classLoader = classLoader;
    }

    private ValidatorFactory getDelegate() {
        ValidatorFactory result = delegate;
        if (result == null) {
            synchronized (this) {
                result = delegate;
                if (result == null) {
                    delegate = result = initFactory();
View Full Code Here

            SecurityActions.setContextClassLoader(oldTCCL);
            if (configuration == null) {
                ConstraintMapping mapping = new ConstraintMapping();
                HibernateValidatorConfiguration config = Validation.byProvider(HibernateValidator.class).providerResolver(new JbossProviderResolver()).configure();
                config.addMapping(mapping);
                ValidatorFactory factory = config.buildValidatorFactory();
                return factory;

            } else {
                return configuration.buildValidatorFactory();
            }
View Full Code Here

            return;
        }
        String valueProperty = (String) referenceProperty;

        // Initialize Bean Validation.
        ValidatorFactory validatorFactory = createValidatorFactory(context);
        javax.validation.Validator validator = createValidator(validatorFactory, context);
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(valueBaseClass);
        if (!beanDescriptor.isBeanConstrained())
        {
            return;
View Full Code Here

        {
            synchronized (this)
            {
                if (_ExternalSpecifications.isBeanValidationAvailable())
                {
                    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
                    applicationMap.put(VALIDATOR_FACTORY_KEY, factory);
                    return factory;
                }
                else
                {
View Full Code Here

            assertEquals(1, constraintViolationException.getConstraintViolations().size());
        }
    }

    @Test public void lookupValidatorFactory() throws Exception {
        ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory");
        assertNotNull(validatorFactory);
    }
View Full Code Here

        Validator validator = (Validatornew InitialContext().lookup("java:comp/Validator");
        assertNotNull(validator);
    }

    @Test public void injectionValidatorFactory() {
        ValidatorFactory validatorFactory = persistManager.getValidatorFactory();
        assertNotNull(validatorFactory);
    }
View Full Code Here

        }
        return info;
    }

    public static ValidatorFactory buildFactory(ValidationInfo config, ClassLoader classLoader) {
        ValidatorFactory factory = null;
        ClassLoader oldContextLoader = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(classLoader);
            if (config == null) {
                factory = Validation.buildDefaultValidatorFactory();
View Full Code Here

                moduleIds.addAll(validatorFactories.keySet());

                // validators bindings
                for (Entry<String, ValidatorFactory> validatorFactory : validatorFactories.entrySet()) {
                    String id = validatorFactory.getKey();
                    ValidatorFactory factory = validatorFactory.getValue();
                    try {
                        containerSystemContext.bind(VALIDATOR_FACTORY_NAMING_CONTEXT + id, factory);
                        containerSystemContext.bind(VALIDATOR_NAMING_CONTEXT + id, factory.usingContext().getValidator());
                    } catch (NameAlreadyBoundException e) {
                        throw new OpenEJBException("ValidatorFactory already exists for module " + id, e);
                    } catch (Exception e) {
                        throw new OpenEJBException(e);
                    }
View Full Code Here

TOP

Related Classes of javax.validation.ValidatorFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.