org.apache.cayenne.util.Util.getPackagePath()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(182)

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

Util.getPackagePath介绍

[英]Returns package name for the Java class as a path separated with forward slash ("/"). Method is used to lookup resources that are located in package subdirectories. For example, a String "a/b/c" will be returned for class name "a.b.c.ClassName".
[中]以正斜杠(“/”)分隔的路径返回Java类的包名。方法用于查找位于包子目录中的资源。例如,将为类名“a.b.c.ClassName”返回字符串“a/b/c”。

代码示例

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

/**
 * Locates and returns a named adapter resource. A resource can be an XML file, etc.
 * <p>
 * This implementation is based on the premise that each adapter is located in its own
 * Java package and all resources are in the same package as well. Resource lookup is
 * recursive, so that if DbAdapter is a subclass of another adapter, parent adapter
 * package is searched as a failover.
 * </p>
 * 
 * @since 1.1
 */
public URL findAdapterResource(String name) {
  Class adapterClass = this.getClass();
  while (adapterClass != null && JdbcAdapter.class.isAssignableFrom(adapterClass)) {
    String path = Util.getPackagePath(adapterClass.getName()) + name;
    URL url = ResourceLocator.findURLInClasspath(path);
    if (url != null) {
      return url;
    }
    adapterClass = adapterClass.getSuperclass();
  }
  return null;
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Locates and returns a named adapter resource. A resource can be an XML
 * file, etc.
 * <p>
 * This implementation is based on the premise that each adapter is located
 * in its own Java package and all resources are in the same package as
 * well. Resource lookup is recursive, so that if DbAdapter is a subclass of
 * another adapter, parent adapter package is searched as a failover.
 * </p>
 *
 * @since 3.0
 */
protected URL findResource(String name) {
  Class<?> adapterClass = getClass();
  while (adapterClass != null && JdbcAdapter.class.isAssignableFrom(adapterClass)) {
    String path = Util.getPackagePath(adapterClass.getName()) + name;
    Collection<Resource> resources = resourceLocator.findResources(path);
    if (!resources.isEmpty()) {
      return resources.iterator().next().getURL();
    }
    adapterClass = adapterClass.getSuperclass();
  }
  return null;
}

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

/**
 * Constructor with a named domain configuration resource. Simply calls
 * {@link Configuration#Configuration(String)}.
 * 
 * @throws ConfigurationException when <code>domainConfigurationName</code> is
 *             <code>null</code>.
 * @see Configuration#Configuration(String)
 */
public DefaultConfiguration(String domainConfigurationName) {
  super(domainConfigurationName);
  if (domainConfigurationName == null) {
    throw new ConfigurationException("cannot use null as domain file name.");
  }
  logObj.debug("using domain file name: " + domainConfigurationName);
  // configure CLASSPATH-only locator
  ResourceLocator locator = new ResourceLocator();
  locator.setSkipAbsolutePath(true);
  locator.setSkipClasspath(false);
  locator.setSkipCurrentDirectory(true);
  locator.setSkipHomeDirectory(true);
  // add the current Configuration subclass' package as additional path.
  if (!(this.getClass().equals(DefaultConfiguration.class))) {
    locator.addClassPath(Util.getPackagePath(this.getClass().getName()));
  }
  setResourceLocator(locator);
}

相关文章