获得JNDI数据源

@param jndiName JNDI名称
@return 数据源
967654
public static DataSource getJndiDsWithLog(String jndiName) {
		try {
			return getJndiDs(jndiName);
		} catch (DbRuntimeException e) {
			log.error(e.getCause(), "Find JNDI datasource error!");
		}
		return null;
	}
509568
public JCRName parseJCRName(String name) throws RepositoryException
   {
      JCRPath path = parsePathEntry(JCRPath.createJCRPath(), name);
      JCRPath.PathElement entry = path.getName();
      return new JCRName(entry);
   }
916551
public static boolean isJavaIdentifier(String name) {
        if (name.length() == 0 || INVALID_JAVA_IDENTIFIERS.contains(name)) return false;
        char[] chars = name.toCharArray();
        if (!Character.isJavaIdentifierStart(chars[0])) return false;
        for (int i = 1; i < chars.length; i++ ) {
            if (!Character.isJavaIdentifierPart(chars[i])) return false;
        }
        return true;
    }
159348
public static boolean hasJNDIScheme(String jndiName) {
        int colonIndex = jndiName.indexOf(':');
        int slashIndex = jndiName.indexOf('/');
        return colonIndex != -1 && (slashIndex == -1 || colonIndex < slashIndex);
    }
773344
public static JSPCache getJspCache(String cacheName) {
        final String methodName = "getJspCache()";
        JSPCache cacheOut = null;
        if (servletCacheEnabled == false) {
            // DYNA1059W=DYNA1059W: WebSphere Dynamic Cache instance named {0} cannot be used because of Dynamic Servlet
            // cache service has not be started.
            Tr.error(tc, "DYNA1059W", new Object[] { cacheName });
        } else {
            if (cacheName != null) {
                try {
                    cacheOut = cacheUnit.getJSPCache(cacheName);
                } catch (Exception e) {
                    // DYNA1003E=DYNA1003E: WebSphere Dynamic Cache instance named {0} can not be initialized because of
                    // error {1}.
                    Tr.error(tc, "DYNA1003E", new Object[] { cacheName, e });
                }
            } else {
                cacheOut = ServerCache.jspCache;
            }
        }
        if (cacheOut == null && TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, methodName + " could not find JSPCache for cacheName=" + cacheName);
        }
        return cacheOut;
    }
11902
public Collection<JndiObjectResourceParameter> getParameters(DbConn cnx)
    {
        ResultSet rs = cnx.runSelect("jndiprm_select_all_in_jndisrc", this.id);
        List<JndiObjectResourceParameter> res = new ArrayList<>();
        JndiObjectResourceParameter tmp = null;
        try
        {
            while (rs.next())
            {
                tmp = new JndiObjectResourceParameter();
                tmp.setId(rs.getInt(1));
                tmp.setKey(rs.getString(2));
                tmp.setLastModified(cnx.getCal(rs, 3));
                tmp.setValue(rs.getString(4));

                res.add(tmp);
            }
        }
        catch (Exception e)
        {
            throw new DatabaseException(e);
        }
        return res;
    }
14410
public static DataResource fromName(String name)
    {
        String[] parts = StringUtils.split(name, '/');

        if (!parts[0].equals(ROOT_NAME) || parts.length > 3)
            throw new IllegalArgumentException(String.format("%s is not a valid data resource name", name));

        if (parts.length == 1)
            return root();

        if (parts.length == 2)
            return keyspace(parts[1]);

        return columnFamily(parts[1], parts[2]);
    }
458796
public synchronized JNDIResourceModel createUnique(Set<ProjectModel> applications, String jndiName)
    {
        JNDIResourceModel jndiResourceModel = getUniqueByProperty(JNDIResourceModel.JNDI_LOCATION, jndiName);
        if (jndiResourceModel == null)
        {
            jndiResourceModel = super.create();
            jndiResourceModel.setJndiLocation(jndiName);
            jndiResourceModel.setApplications(applications);
        }
        else
        {
            for (ProjectModel application : applications)
            {
                if (!jndiResourceModel.isAssociatedWithApplication(application))
                    jndiResourceModel.addApplication(application);
            }
        }
        return jndiResourceModel;
    }
1212637
static JndiContext createJndiContext() throws NamingException
    {
        try
        {
            if (!NamingManager.hasInitialContextFactoryBuilder())
            {
                JndiContext ctx = new JndiContext();
                NamingManager.setInitialContextFactoryBuilder(ctx);
                return ctx;
            }
            else
            {
                return (JndiContext) NamingManager.getInitialContext(null);
            }
        }
        catch (Exception e)
        {
            jqmlogger.error("Could not create JNDI context: " + e.getMessage());
            NamingException ex = new NamingException("Could not initialize JNDI Context");
            ex.setRootCause(e);
            throw ex;
        }
    }
792203
public Connection getConnection(String name) throws ExecutionException {
        Connection connection = null;
        synchronized (connections) {
            if (connections.containsKey(name)) {
                connection = connections.get(name);
            } else {

                String msg = "The connection [" + name + "] does not exist";
                logger.error(msg);
                throw new ExecutionException(msg);
            }
        }
        return connection;
    }
546646
@Nonnull
  public static String ensureEncodingName(@Nullable final String charsetName) {
    final Charset defaultCharset = Charset.defaultCharset();
    try {
      return (charsetName == null) ? defaultCharset.name() : Charset.forName(charsetName.trim()).name();
    } catch (IllegalCharsetNameException ex) {
      throw new IllegalArgumentException("Can't recognize charset for name '" + charsetName + '\'');
    }
  }
653197
public static String jvmNameToCanonicalName(String jvmName) {
        boolean isArray = jvmName.charAt(0) == '[';
        if (isArray) {
            String cnName = StringUtils.EMPTY; // 计数，看上几维数组
            int i = 0;
            for (; i < jvmName.length(); i++) {
                if (jvmName.charAt(i) != '[') {
                    break;
                }
                cnName += "[]";
            }
            String componentType = jvmName.substring(i, jvmName.length());
            if ("Z".equals(componentType)) {
                cnName = "boolean" + cnName;
            } else if ("B".equals(componentType)) {
                cnName = "byte" + cnName;
            } else if ("C".equals(componentType)) {
                cnName = "char" + cnName;
            } else if ("D".equals(componentType)) {
                cnName = "double" + cnName;
            } else if ("F".equals(componentType)) {
                cnName = "float" + cnName;
            } else if ("I".equals(componentType)) {
                cnName = "int" + cnName;
            } else if ("J".equals(componentType)) {
                cnName = "long" + cnName;
            } else if ("S".equals(componentType)) {
                cnName = "short" + cnName;
            } else {
                cnName = componentType.substring(1, componentType.length() - 1) + cnName; // 对象的 去掉L
            }
            return cnName;
        }
        return jvmName;
    }
295589
public static String extName(String fileName) {
		if (fileName == null) {
			return null;
		}
		int index = fileName.lastIndexOf(StrUtil.DOT);
		if (index == -1) {
			return StrUtil.EMPTY;
		} else {
			String ext = fileName.substring(index + 1);
			// 扩展名中不能包含路径相关的符号
			return StrUtil.containsAny(ext, UNIX_SEPARATOR, WINDOWS_SEPARATOR) ? StrUtil.EMPTY : ext;
		}
	}
1084492
private static String getJmxResult(MBeanServerConnection connetion, String url) throws Exception {
        ObjectName name = new ObjectName(DruidStatService.MBEAN_NAME);

        return (String) conn.invoke(name, "service", new String[]{url},
                new String[]{String.class.getName()});
    }
1022606
@SuppressWarnings("unchecked")
  public static Object getMBean(final Class c,
                                final String name) throws Throwable {
    final MBeanServer server = getMbeanServer();

//    return MBeanProxyExt.create(c, name, server);
    return JMX.newMBeanProxy(server, new ObjectName(name), c);
  }
443553
public static String simpleName(String name) {
		if (name == null) {
			return null;
		}
		final int index = name.lastIndexOf('.');
		if (index > 0) {
			return name.substring(index + 1);
		}
		return name;
	}
853781
public static DataSource getJndiDs(String jndiName) {
		try {
			return (DataSource) new InitialContext().lookup(jndiName);
		} catch (NamingException e) {
			throw new DbRuntimeException(e);
		}
	}