javax.naming.Reference类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(245)

本文整理了Java中javax.naming.Reference类的一些代码示例,展示了Reference类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Reference类的具体详情如下:
包路径:javax.naming.Reference
类名称:Reference

Reference介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

/**
* Create a Reference instance from a JNDIStorable object
*
* @param instanceClassName
*     The name of the class that is being created.
* @param po
*     The properties object to use when configuring the new instance.
*
* @return Reference
*
* @throws NamingException if an error occurs while creating the new instance.
*/
public static Reference createReference(String instanceClassName, JNDIStorable po) throws NamingException {
 Reference result = new Reference(instanceClassName, JNDIReferenceFactory.class.getName(), null);
 try {
   Properties props = po.getProperties();
   for (Enumeration iter = props.propertyNames(); iter.hasMoreElements();) {
    String key = (String)iter.nextElement();
    result.add(new StringRefAddr(key, props.getProperty(key)));
   }
 } catch (Exception e) {
   throw new NamingException(e.getMessage());
 }
 return result;
}

代码示例来源:origin: alibaba/druid

@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 "javax.sql.DataSource"
  if ((obj == null) || !(obj instanceof Reference)) {
    return null;
  }
  Reference ref = (Reference) obj;
  if ((!"javax.sql.DataSource".equals(ref.getClassName())) //
      && (!"com.alibaba.druid.pool.DruidDataSource".equals(ref.getClassName())) //
  ) {
    return null;
  }
  Properties properties = new Properties();
  for (int i = 0; i < ALL_PROPERTIES.length; i++) {
    String propertyName = ALL_PROPERTIES[i];
    RefAddr ra = ref.get(propertyName);
    if (ra != null) {
      String propertyValue = ra.getContent().toString();
      properties.setProperty(propertyName, propertyValue);
    }
  }
  return createDataSourceInternal(properties);
}

代码示例来源:origin: wildfly/wildfly

public static Properties getProperties(Reference reference) {
 Properties properties = new Properties();
 for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) {
   StringRefAddr addr = (StringRefAddr)iter.nextElement();
   properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent());
 }
 return properties;
}

代码示例来源:origin: alibaba/druid

public Reference getReference() throws NamingException {
  final String className = getClass().getName();
  final String factoryName = className + "Factory"; // XXX: not robust
  Reference ref = new Reference(className, factoryName, null);
  ref.add(new StringRefAddr("instanceKey", instanceKey));
  ref.add(new StringRefAddr("url", this.getUrl()));
  ref.add(new StringRefAddr("username", this.getUsername()));
  ref.add(new StringRefAddr("password", this.getPassword()));
  // TODO ADD OTHER PROPERTIES
  return ref;
}

代码示例来源:origin: wildfly/wildfly

static ObjectFactory lookForURLs(Reference ref, Hashtable environment)
    throws NamingException {
  for (int i = 0; i < ref.size(); i++) {
    RefAddr addr = ref.get(i);
    if (addr instanceof StringRefAddr &&
        addr.getType().equalsIgnoreCase("URL")) {
      String url = (String) addr.getContent();
      ObjectFactory answer = processURL(url, environment);
      if (answer != null) {
        return answer;
      }
    }
  }
  return null;
}

代码示例来源:origin: com.zaxxer/HikariCP

@Override
synchronized 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> that specify a class name of "javax.sql.DataSource"
 if (obj instanceof Reference && "javax.sql.DataSource".equals(((Reference) obj).getClassName())) {
   Reference ref = (Reference) obj;
   Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class);
   Properties properties = new Properties();
   Enumeration<RefAddr> enumeration = ref.getAll();
   while (enumeration.hasMoreElements()) {
    RefAddr element = enumeration.nextElement();
    String type = element.getType();
    if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) {
      properties.setProperty(type, element.getContent().toString());
    }
   }
   return createDataSource(properties, nameCtx);
 }
 return null;
}

代码示例来源:origin: org.apache.sentry/sentry-shaded-miscellaneous

public Object getObjectInstance(Object object, Name name, Context context, Hashtable<?, ?> table) throws Exception {
  Reference ref = (Reference) object;
  Enumeration<RefAddr> addrs = ref.getAll();
  Properties props = new Properties();
  while (addrs.hasMoreElements()) {
    RefAddr addr = addrs.nextElement();
    if (addr.getType().equals("driverClassName")){
      Class.forName((String) addr.getContent());
    } else {
      props.put(addr.getType(), addr.getContent());
    }
  }        
  BoneCPConfig config = new BoneCPConfig(props);
  return new BoneCPDataSource(config);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

Enumeration<RefAddr> props = ((Reference) obj).getAll();
while (props.hasMoreElements()) {
  RefAddr addr = props.nextElement();
  if (addr != null) {
    if (CONNECTION_STRING.equals(addr.getType())) {
      if (addr.getContent() instanceof String) {
        connectionString = (String) addr.getContent();
        break;

代码示例来源:origin: io.snappydata/gemfirexd-client

throws SqlException {
  Properties properties = new Properties();
    for (Enumeration e = ref.getAll(); e.hasMoreElements();) {
      RefAddr attribute = (RefAddr) e.nextElement();
      String propertyKey = attribute.getType();
      String value = (String) attribute.getContent();
        properties.setProperty(propertyKey, value);
      e.getClass().getName(), e.getMessage(), e);

代码示例来源:origin: apache/activemq-artemis

public Reference from(Properties properties) {
   String type = (String) properties.remove("type");
   String factory = (String) properties.remove("factory");
   Reference result = new Reference(type, factory, null);
   for (Enumeration iter = properties.propertyNames(); iter.hasMoreElements();) {
     String key = (String)iter.nextElement();
     result.add(new StringRefAddr(key, properties.getProperty(key)));
   }
   return result;
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

/**
 * 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;
}

代码示例来源:origin: internetarchive/heritrix3

/**
   * Testing code.
   * @param args Command line arguments.
   * @throws NullPointerException 
   * @throws MalformedObjectNameException 
   * @throws NamingException 
   * @throws InvalidNameException 
   */
  public static void main(String[] args)
  throws MalformedObjectNameException, NullPointerException,
  InvalidNameException, NamingException {
    final ObjectName on = new ObjectName("org.archive.crawler:" +
        "type=Service,name=Heritrix00,host=debord.archive.org");
    Context c = getSubContext(getCompoundName(on.getDomain()));
    CompoundName key = bindObjectName(c, on);
    Reference r = (Reference)c.lookup(key);
    for (Enumeration<RefAddr> e = r.getAll(); e.hasMoreElements();) {
      System.out.println(e.nextElement());
    }
    unbindObjectName(c, on);
  }
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr2spi

/**
 * @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;
  }
  else {
    throw new javax.naming.OperationNotSupportedException("Contained RepositoryConfig needs to implement javax.naming.Referenceable");
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

@Override
  protected Object getLinked(Reference ref) throws NamingException {
    // If ejb-link has been specified, resolving the link using JNDI
    RefAddr linkRefAddr = ref.get(EjbRef.LINK);
    if (linkRefAddr != null) {
      // Retrieving the EJB link
      String ejbLink = linkRefAddr.getContent().toString();
      Object beanObj = (new InitialContext()).lookup(ejbLink);
      return beanObj;
    }
    return null;
  }
}

代码示例来源:origin: com.enioka.jqm/jqm-providers

@Override
  public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
  {
    Reference resource = (Reference) obj;
    if (resource.get("STRING") != null)
    {
      String res = (String) resource.get("STRING").getContent();
      return res;
    }
    else
    {
      throw new NamingException("Resource does not have a valid STRING parameter");
    }
  }
}

代码示例来源:origin: org.jboss.jbossas/jboss-as-server

private void bind() throws NamingException
{
 Context ctx = new InitialContext();
 // Ah ! We aren't serializable, so we use a helper class
 NonSerializableFactory.bind(JNDI_NAME, this);
 
 // The helper class NonSerializableFactory uses address type nns, we go on to
 // use the helper class to bind ourselves in JNDI
 StringRefAddr addr = new StringRefAddr("nns", JNDI_NAME);
 Reference ref = new Reference(EntityLockMonitor.class.getName(), addr, NonSerializableFactory.class.getName(), null);
 ctx.bind(JNDI_NAME, ref);
}

代码示例来源:origin: hector-client/hector

@Test
 public void getObjectInstance() throws Exception {
  Reference resource = new Reference("CassandraClientFactory");

  resource.add(new StringRefAddr("hosts", cassandraUrl));
  resource.add(new StringRefAddr("clusterName", clusterName));
  resource.add(new StringRefAddr("keyspace", "Keyspace1"));
  resource.add(new StringRefAddr("autoDiscoverHosts", "true"));
  

  Name jndiName = mock(Name.class);
  Context context = new InitialContext();
  Hashtable<String, String> environment = new Hashtable<String, String>();

  Keyspace keyspace = (Keyspace) factory.getObjectInstance(resource, jndiName, context, environment);

  assertNotNull(keyspace);
  assertEquals("Keyspace1",keyspace.getKeyspaceName());
 }
}

代码示例来源:origin: org.jboss.naming/jnpserver

public void start() throws Exception
  {
   initialContext();
   ClassLoader topLoader = Thread.currentThread().getContextClassLoader();
   ENCFactory.setTopClassLoader(topLoader);
   RefAddr refAddr = new StringRefAddr("nns", "ENC");
   Reference envRef = new Reference("javax.naming.Context", refAddr, ENCFactory.class.getName(), null);
   Context ctx = (Context)iniCtx.lookup("java:");
   ctx.rebind("comp", envRef);
  }
}

代码示例来源:origin: org.postgresql/postgresql

private static String getReferenceProperty(Reference ref, String propertyName) {
 RefAddr addr = ref.get(propertyName);
 if (addr == null) {
  return null;
 }
 return (String) addr.getContent();
}

代码示例来源:origin: org.switchyard/switchyard-deploy-jboss-as6

public void visit(DeploymentUnit unit) throws DeploymentException {
  if (unit.isTopLevel()) {
    Context javaComp = getJavaComp(unit);
    try {
      Reference reference = new Reference("javax.enterprise.inject.spi.BeanManager", "org.jboss.weld.integration.deployer.jndi.JBossBeanManagerObjectFactory", null);
      reference.add(new StringRefAddr("id", IdFactory.getIdFromClassLoader(unit.getClassLoader())));
      javaComp.bind("BeanManager", reference);
      _logger.debug("CDI BeanManager successfully bound into JNDI (java:comp) for SwitchYard deployment '" + unit.getName() + "'.");
    } catch (NamingException e) {
      throw new DeploymentException("Error binding BeanManager.", e);
    }
  }
}

相关文章