Java Code Examples for javax.naming.RefAddr#getType()

The following examples show how to use javax.naming.RefAddr#getType() . 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: GenericNamingResourcesFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    Enumeration<RefAddr> refs = ref.getAll();

    String type = ref.getClassName();
    Object o = Class.forName(type).newInstance();

    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent()!=null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value,false)) {

        } else {
            log.debug("Property not configured["+param+"]. No setter found on["+o+"].");
        }
    }
    return o;
}
 
Example 2
Source File: GenericNamingResourcesFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    Enumeration<RefAddr> refs = ref.getAll();

    String type = ref.getClassName();
    Object o = Class.forName(type).newInstance();

    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent()!=null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value,false)) {

        } else {
            log.debug("Property not configured["+param+"]. No setter found on["+o+"].");
        }
    }
    return o;
}
 
Example 3
Source File: ViburDBCPObjectFactory.java    From vibur-dbcp with Apache License 2.0 6 votes vote down vote up
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
    throws ViburDBCPException {

    Reference reference = (Reference) obj;
    Enumeration<RefAddr> enumeration = reference.getAll();
    Properties props = new Properties();
    while (enumeration.hasMoreElements()) {
        RefAddr refAddr = enumeration.nextElement();
        String pName = refAddr.getType();
        String pValue = (String) refAddr.getContent();
        props.setProperty(pName, pValue);
    }

    ViburDBCPDataSource dataSource = new ViburDBCPDataSource(props);
    dataSource.start();
    return dataSource;
}
 
Example 4
Source File: GenericNamingResourcesFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    if ((obj == null) || !(obj instanceof Reference)) {
        return null;
    }
    Reference ref = (Reference) obj;
    Enumeration<RefAddr> refs = ref.getAll();

    String type = ref.getClassName();
    Object o =
        ClassLoaderUtil.loadClass(
            type,
            GenericNamingResourcesFactory.class.getClassLoader(),
            Thread.currentThread().getContextClassLoader()).getConstructor().newInstance();

    while (refs.hasMoreElements()) {
        RefAddr addr = refs.nextElement();
        String param = addr.getType();
        String value = null;
        if (addr.getContent()!=null) {
            value = addr.getContent().toString();
        }
        if (setProperty(o, param, value)) {

        } else {
            log.debug("Property not configured["+param+"]. No setter found on["+o+"].");
        }
    }
    return o;
}
 
Example 5
Source File: BurlapProxyFactory.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
/**
 * JNDI object factory so the proxy can be used as a resource.
 */
public Object getObjectInstance(Object obj, Name name,
                                Context nameCtx,
                                Hashtable<?, ?> environment)
    throws Exception
{
    Reference ref = (Reference) obj;

    String api = null;
    String url = null;
    String user = null;
    String password = null;

    for (int i = 0; i < ref.size(); i++) {
        RefAddr addr = ref.get(i);

        String type = addr.getType();
        String value = (String) addr.getContent();

        if (type.equals("type"))
            api = value;
        else if (type.equals("url"))
            url = value;
        else if (type.equals("user"))
            setUser(value);
        else if (type.equals("password"))
            setPassword(value);
    }

    if (url == null)
        throw new NamingException("`url' must be configured for BurlapProxyFactory.");
    // XXX: could use meta protocol to grab this
    if (api == null)
        throw new NamingException("`type' must be configured for BurlapProxyFactory.");

    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Class apiClass = Class.forName(api, false, loader);

    return create(apiClass, url);
}
 
Example 6
Source File: HessianProxyFactory.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
/**
 * JNDI object factory so the proxy can be used as a resource.
 */
public Object getObjectInstance(Object obj, Name name,
                                Context nameCtx, Hashtable<?, ?> environment)
    throws Exception
{
    Reference ref = (Reference) obj;

    String api = null;
    String url = null;

    for (int i = 0; i < ref.size(); i++) {
        RefAddr addr = ref.get(i);

        String type = addr.getType();
        String value = (String) addr.getContent();

        if (type.equals("type"))
            api = value;
        else if (type.equals("url"))
            url = value;
        else if (type.equals("user"))
            setUser(value);
        else if (type.equals("password"))
            setPassword(value);
    }

    if (url == null)
        throw new NamingException("`url' must be configured for HessianProxyFactory.");
    // XXX: could use meta protocol to grab this
    if (api == null)
        throw new NamingException("`type' must be configured for HessianProxyFactory.");

    Class apiClass = Class.forName(api, false, _loader);

    return create(apiClass, url);
}
 
Example 7
Source File: ClientDataSourceFactory.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Set the Java bean properties for an object from its Reference. The
 * Reference contains a set of StringRefAddr values with the key being the
 * bean name and the value a String representation of the bean's value. This
 * code looks for setXXX() method where the set method corresponds to the
 * standard bean naming scheme and has a single parameter of type String,
 * int, boolean or short.
 */
private static void setBeanProperties(Object ds, Reference ref)
        throws Exception {

    for (Enumeration e = ref.getAll(); e.hasMoreElements();) {

        RefAddr attribute = (RefAddr) e.nextElement();

        String propertyName = attribute.getType();

        String value = (String) attribute.getContent();

        String methodName = "set"
                + propertyName.substring(0, 1).toUpperCase(
                        java.util.Locale.ENGLISH)
                + propertyName.substring(1);

        Method m;

        Object argValue;
        try {
            m = ds.getClass().getMethod(methodName, STRING_ARG);
            argValue = value;
        } catch (NoSuchMethodException nsme) {
            try {
                m = ds.getClass().getMethod(methodName, INT_ARG);
                argValue = Integer.valueOf(value);
            } catch (NoSuchMethodException nsme2) {
                try {
                    m = ds.getClass().getMethod(methodName, BOOLEAN_ARG);
                    argValue = Boolean.valueOf(value);
                } catch (NoSuchMethodException nsme3) {
                    m = ds.getClass().getMethod(methodName, SHORT_ARG);
                    argValue = Short.valueOf(value);
                }
            }
        }
        m.invoke(ds, new Object[] { argValue });
    }
}
 
Example 8
Source File: ClientDataSourceFactory.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Set the Java bean properties for an object from its Reference. The
 * Reference contains a set of StringRefAddr values with the key being the
 * bean name and the value a String representation of the bean's value. This
 * code looks for setXXX() method where the set method corresponds to the
 * standard bean naming scheme and has a single parameter of type String,
 * int, boolean or short.
 */
private static void setBeanProperties(Object ds, Reference ref)
        throws Exception {

    for (Enumeration e = ref.getAll(); e.hasMoreElements();) {

        RefAddr attribute = (RefAddr) e.nextElement();

        String propertyName = attribute.getType();

        String value = (String) attribute.getContent();

        String methodName = "set"
                + propertyName.substring(0, 1).toUpperCase(
                        java.util.Locale.ENGLISH)
                + propertyName.substring(1);

        Method m;

        Object argValue;
        try {
            m = ds.getClass().getMethod(methodName, STRING_ARG);
            argValue = value;
        } catch (NoSuchMethodException nsme) {
            try {
                m = ds.getClass().getMethod(methodName, INT_ARG);
                argValue = Integer.valueOf(value);
            } catch (NoSuchMethodException nsme2) {
                try {
                    m = ds.getClass().getMethod(methodName, BOOLEAN_ARG);
                    argValue = Boolean.valueOf(value);
                } catch (NoSuchMethodException nsme3) {
                    m = ds.getClass().getMethod(methodName, SHORT_ARG);
                    argValue = Short.valueOf(value);
                }
            }
        }
        m.invoke(ds, new Object[] { argValue });
    }
}
 
Example 9
Source File: ClientDataSourceFactory.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Set the Java bean properties for an object from its Reference. The
 * Reference contains a set of StringRefAddr values with the key being the
 * bean name and the value a String representation of the bean's value. This
 * code looks for setXXX() method where the set method corresponds to the
 * standard bean naming scheme and has a single parameter of type String,
 * int, boolean or short.
 */
private static void setBeanProperties(Object ds, Reference ref)
        throws Exception {

    for (Enumeration e = ref.getAll(); e.hasMoreElements();) {

        RefAddr attribute = (RefAddr) e.nextElement();

        String propertyName = attribute.getType();

        String value = (String) attribute.getContent();

        String methodName = "set"
                + propertyName.substring(0, 1).toUpperCase(
                        java.util.Locale.ENGLISH)
                + propertyName.substring(1);

        Method m;

        Object argValue;
        try {
            m = ds.getClass().getMethod(methodName, STRING_ARG);
            argValue = value;
        } catch (NoSuchMethodException nsme) {
            try {
                m = ds.getClass().getMethod(methodName, INT_ARG);
                argValue = Integer.valueOf(value);
            } catch (NoSuchMethodException nsme2) {
                try {
                    m = ds.getClass().getMethod(methodName, BOOLEAN_ARG);
                    argValue = Boolean.valueOf(value);
                } catch (NoSuchMethodException nsme3) {
                    m = ds.getClass().getMethod(methodName, SHORT_ARG);
                    argValue = Short.valueOf(value);
                }
            }
        }
        m.invoke(ds, new Object[] { argValue });
    }
}
 
Example 10
Source File: ReferenceableDataSource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
	Re-Create Derby datasource given a reference.

	@param obj The possibly null object containing location or reference
	information that can be used in creating an object. 
	@param name The name of this object relative to nameCtx, or null if no
	name is specified. 
	@param nameCtx The context relative to which the name parameter is
	specified, or null if name is relative to the default initial context. 
	@param environment The possibly null environment that is used in
	creating the object. 

	@return One of the Derby datasource object created; null if an
	object cannot be created. 

	@exception Exception  if this object factory encountered an exception
	while attempting to create an object, and no other object factories are
	to be tried. 
 */
public Object getObjectInstance(Object obj,
								Name name,
								Context nameCtx,
								Hashtable environment)
	 throws Exception
{
	Reference ref = (Reference)obj;
	String classname = ref.getClassName();

	Object ds = Class.forName(classname).newInstance();

	for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) {
		
		RefAddr attribute = (RefAddr) e.nextElement();

		String propertyName = attribute.getType();

		String value = (String) attribute.getContent();

		String methodName = "set" + propertyName.substring(0,1).toUpperCase(java.util.Locale.ENGLISH) + propertyName.substring(1);

		Method m;
		
		Object argValue;
		try {
			m = ds.getClass().getMethod(methodName, STRING_ARG);
			argValue = value;
		} catch (NoSuchMethodException nsme) {
			try {
				m = ds.getClass().getMethod(methodName, INT_ARG);
				argValue = Integer.valueOf(value);
			} catch (NoSuchMethodException nsme2) {
				m = ds.getClass().getMethod(methodName, BOOLEAN_ARG);
				argValue = Boolean.valueOf(value);
			}
		}
		m.invoke(ds, new Object[] { argValue });
	}

	return ds;
}
 
Example 11
Source File: ReferenceableDataSource.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
	Re-Create Derby datasource given a reference.

	@param obj The possibly null object containing location or reference
	information that can be used in creating an object. 
	@param name The name of this object relative to nameCtx, or null if no
	name is specified. 
	@param nameCtx The context relative to which the name parameter is
	specified, or null if name is relative to the default initial context. 
	@param environment The possibly null environment that is used in
	creating the object. 

	@return One of the Derby datasource object created; null if an
	object cannot be created. 

	@exception Exception  if this object factory encountered an exception
	while attempting to create an object, and no other object factories are
	to be tried. 
 */
public Object getObjectInstance(Object obj,
								Name name,
								Context nameCtx,
								Hashtable environment)
	 throws Exception
{
	Reference ref = (Reference)obj;
	String classname = ref.getClassName();

	Object ds = Class.forName(classname).newInstance();

	for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) {
		
		RefAddr attribute = (RefAddr) e.nextElement();

		String propertyName = attribute.getType();

		String value = (String) attribute.getContent();

		String methodName = "set" + propertyName.substring(0,1).toUpperCase(java.util.Locale.ENGLISH) + propertyName.substring(1);

		Method m;
		
		Object argValue;
		try {
			m = ds.getClass().getMethod(methodName, STRING_ARG);
			argValue = value;
		} catch (NoSuchMethodException nsme) {
			try {
				m = ds.getClass().getMethod(methodName, INT_ARG);
				argValue = Integer.valueOf(value);
			} catch (NoSuchMethodException nsme2) {
				m = ds.getClass().getMethod(methodName, BOOLEAN_ARG);
				argValue = Boolean.valueOf(value);
			}
		}
		m.invoke(ds, new Object[] { argValue });
	}

	return ds;
}
 
Example 12
Source File: ReferenceableDataSource.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
	Re-Create Derby datasource given a reference.

	@param obj The possibly null object containing location or reference
	information that can be used in creating an object. 
	@param name The name of this object relative to nameCtx, or null if no
	name is specified. 
	@param nameCtx The context relative to which the name parameter is
	specified, or null if name is relative to the default initial context. 
	@param environment The possibly null environment that is used in
	creating the object. 

	@return One of the Derby datasource object created; null if an
	object cannot be created. 

	@exception Exception  if this object factory encountered an exception
	while attempting to create an object, and no other object factories are
	to be tried. 
 */
public Object getObjectInstance(Object obj,
								Name name,
								Context nameCtx,
								Hashtable environment)
	 throws Exception
{
	Reference ref = (Reference)obj;
	String classname = ref.getClassName();

	Object ds = Class.forName(classname).newInstance();

	for (Enumeration e = ref.getAll(); e.hasMoreElements(); ) {
		
		RefAddr attribute = (RefAddr) e.nextElement();

		String propertyName = attribute.getType();

		String value = (String) attribute.getContent();

		String methodName = "set" + propertyName.substring(0,1).toUpperCase(java.util.Locale.ENGLISH) + propertyName.substring(1);

		Method m;
		
		Object argValue;
		try {
			m = ds.getClass().getMethod(methodName, STRING_ARG);
			argValue = value;
		} catch (NoSuchMethodException nsme) {
			try {
				m = ds.getClass().getMethod(methodName, INT_ARG);
				argValue = Integer.valueOf(value);
			} catch (NoSuchMethodException nsme2) {
				m = ds.getClass().getMethod(methodName, BOOLEAN_ARG);
				argValue = Boolean.valueOf(value);
			}
		}
		m.invoke(ds, new Object[] { argValue });
	}

	return ds;
}