javax.naming.RefAddr Java Examples

The following examples show how to use javax.naming.RefAddr. 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: InVMNamingContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public Object lookup(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   String tok = i == -1 ? name : name.substring(0, i);
   Object value = map.get(tok);
   if (value == null) {
      throw new NameNotFoundException("Name not found: " + tok);
   }
   if (value instanceof InVMNamingContext && i != -1) {
      return ((InVMNamingContext) value).lookup(name.substring(i));
   }
   if (value instanceof Reference) {
      Reference ref = (Reference) value;
      RefAddr refAddr = ref.get("nns");

      // we only deal with references create by NonSerializableFactory
      String key = (String) refAddr.getContent();
      return NonSerializableFactory.lookup(key);
   } else {
      return value;
   }
}
 
Example #2
Source File: DataSourceLinkFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Create a new DataSource instance.
 *
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result!=null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
            result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
 
Example #3
Source File: ResourceRef.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder("ResourceRef[");
    sb.append("className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return (sb.toString());

}
 
Example #4
Source File: HandlerRef.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder("HandlerRef[");
    sb.append("className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return (sb.toString());

}
 
Example #5
Source File: DataSourceLinkFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new DataSource instance.
 * 
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result!=null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
            result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
 
Example #6
Source File: ServiceRef.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder("ServiceRef[");
    sb.append("className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return (sb.toString());

}
 
Example #7
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 #8
Source File: JNDIReferenceFactory.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * This will be called by a JNDIprovider when a Reference is retrieved from
 * a JNDI store - and generates the original instance
 *
 * @param object
 *        the Reference object
 * @param name
 *        the JNDI name
 * @param nameCtx
 *        the context
 * @param environment
 *        the environment settings used by JNDI
 *
 * @return the instance built from the Reference object
 *
 * @throws Exception
 *         if building the instance from Reference fails (usually class not found)
 */
@Override
public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Object result = null;
    if (object instanceof Reference) {
        Reference reference = (Reference) object;
        Class<?> theClass = loadClass(this, reference.getClassName());
        if (JNDIStorable.class.isAssignableFrom(theClass)) {
            JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance();
            Map<String, String> properties = new HashMap<String, String>();
            for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) {
                StringRefAddr addr = (StringRefAddr) iter.nextElement();
                properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString());
            }
            store.setProperties(properties);
            result = store;
        }
    } else {
        throw new RuntimeException("Object " + object + " is not a reference");
    }
    return result;
}
 
Example #9
Source File: JtdsObjectFactory.java    From jTDS with GNU Lesser General Public License v2.1 6 votes vote down vote up
private HashMap loadProps( Reference ref, String[] props )
{
   HashMap config = new HashMap();
   HashMap values = new HashMap();

   Enumeration c = ref.getAll();

   while( c.hasMoreElements() )
   {
      RefAddr ra = (RefAddr) c.nextElement();
      values.put( ra.getType().toLowerCase(), ra.getContent() );
   }

   for( int i = 0; i < props.length; i ++ )
   {
      String value = (String) values.get( props[i] );
      value = value == null && props[i] != JtdsDataSource.DESCRIPTION ? (String) values.get( Messages.get( props[i] ).toLowerCase() ) : value;

      if( value != null )
      {
         config.put( props[i], value );
      }
   }

   return config;
}
 
Example #10
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 #11
Source File: ResourceRef.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder("ResourceRef[");
    sb.append("className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return (sb.toString());

}
 
Example #12
Source File: HandlerRef.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder("HandlerRef[");
    sb.append("className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return (sb.toString());

}
 
Example #13
Source File: InVMContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public Object lookup(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   String tok = i == -1 ? name : name.substring(0, i);
   Object value = map.get(tok);
   if (value == null) {
      throw new NameNotFoundException("Name not found: " + tok);
   }
   if (value instanceof InVMContext && i != -1) {
      return ((InVMContext) value).lookup(name.substring(i));
   }
   if (value instanceof Reference) {
      Reference ref = (Reference) value;
      RefAddr refAddr = ref.get("nns");

      // we only deal with references create by NonSerializableFactory
      String key = (String) refAddr.getContent();
      return NonSerializableFactory.lookup(key);
   } else {
      return value;
   }
}
 
Example #14
Source File: DataSourceLinkFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new DataSource instance.
 * 
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
    Object result = super.getObjectInstance(obj, name, nameCtx, environment);
    // Can we process this request?
    if (result!=null) {
        Reference ref = (Reference) obj;
        RefAddr userAttr = ref.get("username");
        RefAddr passAttr = ref.get("password");
        if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
            result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
        }
    }
    return result;
}
 
Example #15
Source File: ServiceRef.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder("ServiceRef[");
    sb.append("className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return (sb.toString());

}
 
Example #16
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 #17
Source File: InVMContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public Object lookup(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   String tok = i == -1 ? name : name.substring(0, i);
   Object value = map.get(tok);
   if (value == null) {
      throw new NameNotFoundException("Name not found: " + tok);
   }
   if (value instanceof InVMContext && i != -1) {
      return ((InVMContext) value).lookup(name.substring(i));
   }
   if (value instanceof Reference) {
      Reference ref = (Reference) value;
      RefAddr refAddr = ref.get("nns");

      // we only deal with references create by NonSerializableFactory
      String key = (String) refAddr.getContent();
      return NonSerializableFactory.lookup(key);
   } else {
      return value;
   }
}
 
Example #18
Source File: InVMNamingContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public Object lookup(String name) throws NamingException {
   name = trimSlashes(name);
   int i = name.indexOf("/");
   String tok = i == -1 ? name : name.substring(0, i);
   Object value = map.get(tok);
   if (value == null) {
      throw new NameNotFoundException("Name not found: " + tok);
   }
   if (value instanceof InVMNamingContext && i != -1) {
      return ((InVMNamingContext) value).lookup(name.substring(i));
   }
   if (value instanceof Reference) {
      Reference ref = (Reference) value;
      RefAddr refAddr = ref.get("nns");

      // we only deal with references create by NonSerializableFactory
      String key = (String) refAddr.getContent();
      return NonSerializableFactory.lookup(key);
   } else {
      return value;
   }
}
 
Example #19
Source File: AbstractRef.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Return a String rendering of this object.
 */
@Override
public final String toString() {
    StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
    sb.append("[className=");
    sb.append(getClassName());
    sb.append(",factoryClassLocation=");
    sb.append(getFactoryClassLocation());
    sb.append(",factoryClassName=");
    sb.append(getFactoryClassName());
    Enumeration<RefAddr> refAddrs = getAll();
    while (refAddrs.hasMoreElements()) {
        RefAddr refAddr = refAddrs.nextElement();
        sb.append(",{type=");
        sb.append(refAddr.getType());
        sb.append(",content=");
        sb.append(refAddr.getContent());
        sb.append("}");
    }
    sb.append("]");
    return sb.toString();
}
 
Example #20
Source File: NonSerializableFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectInstance(final Object obj,
                                final Name name,
                                final Context nameCtx,
                                final Hashtable<?, ?> env) throws Exception {
   Reference ref = (Reference) obj;
   RefAddr addr = ref.get("nns");
   String key = (String) addr.getContent();
   return NonSerializableFactory.getWrapperMap().get(key);
}
 
Example #21
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 #22
Source File: DecryptingDataSourceFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private int find( final String addrType, final Reference ref ) {
  final Enumeration enu = ref.getAll();
  for ( int i = 0; enu.hasMoreElements(); i++ ) {
    final RefAddr addr = (RefAddr) enu.nextElement();
    if ( addr.getType().compareTo( addrType ) == 0 ) {
      return i;
    }
  }

  throw new IllegalArgumentException(
    "The '" + addrType + "' name/value pair was not found in the Reference object. The reference Object is"
      + " " + ref.toString() );
}
 
Example #23
Source File: NonSerializableFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObjectInstance(final Object obj,
                                final Name name,
                                final Context nameCtx,
                                final Hashtable<?, ?> env) throws Exception {
   Reference ref = (Reference) obj;
   RefAddr addr = ref.get("nns");
   String key = (String) addr.getContent();
   return NonSerializableFactory.getWrapperMap().get(key);
}
 
Example #24
Source File: OpenEjbFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new EJB instance using OpenEJB.
 * 
 * @param obj The reference object describing the DataSource
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable<?,?> environment)
    throws Exception {

    Object beanObj = null;

    if (obj instanceof EjbRef) {

        Reference ref = (Reference) obj;

        String factory = DEFAULT_OPENEJB_FACTORY;
        RefAddr factoryRefAddr = ref.get("openejb.factory");
        if (factoryRefAddr != null) {
            // Retrieving the OpenEJB factory
            factory = factoryRefAddr.getContent().toString();
        }

        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, factory);

        RefAddr linkRefAddr = ref.get("openejb.link");
        if (linkRefAddr != null) {
            String ejbLink = linkRefAddr.getContent().toString();
            beanObj = (new InitialContext(env)).lookup(ejbLink);
        }

    }

    return beanObj;

}
 
Example #25
Source File: MemoryUserDatabaseFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Create and return a new <code>MemoryUserDatabase</code> instance
 * that has been configured according to the properties of the
 * specified <code>Reference</code>.  If you instance can be created,
 * return <code>null</code> instead.</p>
 *
 * @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 <code>nameCtx</code>
 * @param nameCtx The context relative to which the <code>name</code>
 *  parameter is specified, or <code>null</code> if <code>name</code>
 *  is relative to the default initial context
 * @param environment The possibly null environment that is used in
 *  creating this object
 */
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                Hashtable<?,?> environment)
    throws Exception {

    // We only know how to deal with <code>javax.naming.Reference</code>s
    // that specify a class name of "org.apache.catalina.UserDatabase"
    if ((obj == null) || !(obj instanceof Reference)) {
        return (null);
    }
    Reference ref = (Reference) obj;
    if (!"org.apache.catalina.UserDatabase".equals(ref.getClassName())) {
        return (null);
    }

    // Create and configure a MemoryUserDatabase instance based on the
    // RefAddr values associated with this Reference
    MemoryUserDatabase database = new MemoryUserDatabase(name.toString());
    RefAddr ra = null;

    ra = ref.get("pathname");
    if (ra != null) {
        database.setPathname(ra.getContent().toString());
    }

    ra = ref.get("readonly");
    if (ra != null) {
        database.setReadonly(Boolean.parseBoolean(ra.getContent().toString()));
    }

    // Return the configured database instance
    database.open();
    // Don't try something we know won't work
    if (!database.getReadonly())
        database.save();
    return (database);

}
 
Example #26
Source File: TomcatJndiBuilder.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * LinkRef addresses need to be prefixed with java: or they won't resolve
 *
 * OpenEJB is fine with this, but Tomcat needs them
 *
 * @param value
 * @return
 */
private static Object normalize(final Object value) {
    try {

        if (!(value instanceof LinkRef)) {
            return value;
        }

        final LinkRef ref = (LinkRef) value;

        final RefAddr refAddr = ref.getAll().nextElement();

        final String address = refAddr.getContent().toString();

        if (address.startsWith("openejb:")) {
            return value;
        }

        if (!address.startsWith("java:")) {
            return new LinkRef("java:" + address);
        }

    } catch (final Exception e) {
        // no-op
    }

    return value;
}
 
Example #27
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 #28
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 #29
Source File: ConnectionPropertiesImpl.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
void initializeFrom(Reference ref, ExceptionInterceptor exceptionInterceptor) throws SQLException {
    RefAddr refAddr = ref.get(getPropertyName());

    if (refAddr != null) {
        String refContentAsString = (String) refAddr.getContent();

        initializeFrom(refContentAsString, exceptionInterceptor);
    }
}
 
Example #30
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 });
    }
}