Package javax.naming

Examples of javax.naming.Referenceable


    public Object getValue() throws IllegalStateException, IllegalArgumentException {
        final ClassLoader oldCL = getContextClassLoader();
        try {
            final ClassLoader integrationCL = new DelegateClassLoader(getClassLoader(), classLoader);
            setContextClassLoader(integrationCL);
            final Referenceable referenceable = getReferenceable(integrationCL);
            final Class<?> clazz = Class.forName(referenceable.getReference().getFactoryClassName(), true, integrationCL);
            final ObjectFactory factory = (ObjectFactory)clazz.newInstance();
            return factory.getObjectInstance(referenceable.getReference(), null, null, null);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        } finally {
            setContextClassLoader(oldCL);
        }
View Full Code Here


            final E annotated, final UnifiedVirtualFile vfs, final Module duModule, final String name,
            final String className) {
        UnifiedServiceRefMetaData ref = processor.process(annotation, annotated, vfs);
        // FIXME SPIProviderResolver won't require a TCCL in the future
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        final Referenceable referenceable;
        try {
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
            final ServiceRefHandler serviceRefHandler = spiProvider.getSPI(ServiceRefHandlerFactory.class).getServiceRefHandler();
            referenceable = serviceRefHandler.createReferenceable(ref);
View Full Code Here

            assertEquals(
                expectedValues[expectedArrayIndex+1][i][0], properties[i]);
            println("  " + properties[i]);
        }
       
        Referenceable refDS = (Referenceable) ds;
       
        Reference dsAsReference = refDS.getReference();
       
        String factoryClassName = dsAsReference.getFactoryClassName();
       
        ObjectFactory factory =
            (ObjectFactory) Class.forName(factoryClassName).newInstance()
       
        Object recreatedDS =
            factory.getObjectInstance(dsAsReference, null, null, null);
       
        // DERBY-2559 - with jdk16, this recreatedDS will be null.
        // bailing out
        if (JDBC.vmSupportsJDBC4())
            return;
       
        println(" empty DataSource recreated using Reference as " +
            recreatedDS.getClass().getName());
        // empty DataSource recreated using Reference should not be
        // the same as the original
        assertNotSame(recreatedDS, ds);
       
        compareDS(expectedArrayIndex, properties, ds, recreatedDS);
       
        // now serialize and recreate
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos)
        oos.writeObject(ds);
        oos.flush();
        oos.close();
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        recreatedDS = ois.readObject();
        println(" empty DataSource recreated using serialization");
        compareDS(expectedArrayIndex, properties, ds, recreatedDS);
       
        // now populate the data source
        for (int i = 0; i < properties.length; i++)
        {
            String property = properties[i];
            Method getMethod = getGet(property, ds);
           
            Method setMethod = getSet(getMethod, ds);
           
            Class pt = getMethod.getReturnType();
           
            // generate a somewhat unique value for a property
            int val = 0;
            for (int j = 0; j < property.length(); j++)
                val += property.charAt(j);
           
            if (pt.equals(Integer.TYPE))
            {
                setMethod.invoke(ds, new Object[] {new Integer(val)});
                continue;
            }
            if (pt.equals(String.class))
            {
                String value;
                if (property.equals("createDatabase"))
                    value = "create";
                else if (property.equals("shutdownDatabase"))
                    value = "shutdown";
                else if (property.equals("ssl"))
                    value = "basic";
                else
                    value = "XX_" + property + "_" + val;
                   
                setMethod.invoke(ds, new Object[] {value});
                continue;
            }
            if (pt.equals(Boolean.TYPE))
            {
                // set the opposite value
                Object gbv = getMethod.invoke(ds, null);
                Boolean sbv =
                    Boolean.FALSE.equals(gbv) ? Boolean.TRUE : Boolean.FALSE;
                setMethod.invoke(ds, new Object[] {sbv});
                continue;
            }          
            if (pt.equals(Short.TYPE))
            {
                setMethod.invoke(ds, new Object[] {new Short((short)val)});
                continue;
            }
            if (pt.equals(Long.TYPE))
            {
                setMethod.invoke(ds, new Object[] {new Long(val)});
                continue;
            }
            fail ( property + " not settable - update test!!");
        }
       
        dsAsReference = refDS.getReference();
        recreatedDS =
            factory.getObjectInstance(dsAsReference, null, null, null);
        println(" populated DataSource recreated using Reference as "
            + recreatedDS.getClass().getName());
        // again, recreated should not be same instance
View Full Code Here

    /**
     * @see Referenceable#getReference()
     */
    public Reference getReference() throws NamingException {
        if (config instanceof Referenceable) {
            Referenceable confref = (Referenceable)config;
            if (reference == null) {
                reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
                // carry over all addresses from referenceable config
                for (Enumeration en = confref.getReference().getAll(); en.hasMoreElements(); ) {
                    reference.add((RefAddr)(en.nextElement()));
                }

                // also add the information required by factory class
                reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
                reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
            }

            return reference;
        }
View Full Code Here

    /**
     * @see Referenceable#getReference()
     */
    public Reference getReference() throws NamingException {
        if (config instanceof Referenceable) {
            Referenceable confref = (Referenceable)config;
            if (reference == null) {
                reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
                // carry over all addresses from referenceable config
                for (Enumeration en = confref.getReference().getAll(); en.hasMoreElements(); ) {
                    reference.add((RefAddr)(en.nextElement()));
                }

                // also add the information required by factory class
                reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
                reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
            }

            return reference;
        }
View Full Code Here

    /**
     * @see Referenceable#getReference()
     */
    public Reference getReference() throws NamingException {
        if (config instanceof Referenceable) {
            Referenceable confref = (Referenceable)config;
            if (reference == null) {
                reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
                // carry over all addresses from referenceable config
                for (Enumeration en = confref.getReference().getAll(); en.hasMoreElements(); ) {
                    reference.add((RefAddr)(en.nextElement()));
                }

                // also add the information required by factory class
                reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
                reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
            }

            return reference;
        }
View Full Code Here

    /**
     * @see Referenceable#getReference()
     */
    public Reference getReference() throws NamingException {
        if (config instanceof Referenceable) {
            Referenceable confref = (Referenceable)config;
            if (reference == null) {
                reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
                // carry over all addresses from referenceable config
                for (Enumeration<RefAddr> en = confref.getReference().getAll(); en.hasMoreElements(); ) {
                    reference.add(en.nextElement());
                }

                // also add the information required by factory class
                reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
                reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
            }

            return reference;
        }
View Full Code Here

                                                String className)
            throws Exception {
        println("Testing recreated empty data source.");
        // Create an empty data source.
        Object ds = Class.forName(className).newInstance();
        Referenceable refDs = (Referenceable)ds;
        Reference dsAsReference = refDs.getReference();
        String factoryClassName = dsAsReference.getFactoryClassName();
        ObjectFactory factory =
            (ObjectFactory)Class.forName(factoryClassName).newInstance();
        Object recreatedDs =
            factory.getObjectInstance(dsAsReference, null, null, null);
View Full Code Here

            } else {
                fail("'" + property + "' not settable - update test!!");
            }
        }

        Referenceable refDs = (Referenceable)ds;
        Reference dsAsReference = refDs.getReference();
        String factoryClassName = dsAsReference.getFactoryClassName();
        ObjectFactory factory =
            (ObjectFactory)Class.forName(factoryClassName).newInstance();
        Object recreatedDs =
            factory.getObjectInstance(dsAsReference, null, null, null);
View Full Code Here

    /**
     * @see Referenceable#getReference()
     */
    public Reference getReference() throws NamingException {
        if (config instanceof Referenceable) {
            Referenceable confref = (Referenceable)config;
            if (reference == null) {
                reference = new Reference(RepositoryImpl.class.getName(), RepositoryImpl.Factory.class.getName(), null);
                // carry over all addresses from referenceable config
                for (Enumeration<RefAddr> en = confref.getReference().getAll(); en.hasMoreElements(); ) {
                    reference.add(en.nextElement());
                }

                // also add the information required by factory class
                reference.add(new StringRefAddr(Factory.RCF, confref.getReference().getFactoryClassName()));
                reference.add(new StringRefAddr(Factory.RCC, config.getClass().getName()));
            }

            return reference;
        }
View Full Code Here

TOP

Related Classes of javax.naming.Referenceable

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.