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

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

本文整理了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

  1. /**
  2. * Locates and returns a named adapter resource. A resource can be an XML file, etc.
  3. * <p>
  4. * This implementation is based on the premise that each adapter is located in its own
  5. * Java package and all resources are in the same package as well. Resource lookup is
  6. * recursive, so that if DbAdapter is a subclass of another adapter, parent adapter
  7. * package is searched as a failover.
  8. * </p>
  9. *
  10. * @since 1.1
  11. */
  12. public URL findAdapterResource(String name) {
  13. Class adapterClass = this.getClass();
  14. while (adapterClass != null && JdbcAdapter.class.isAssignableFrom(adapterClass)) {
  15. String path = Util.getPackagePath(adapterClass.getName()) + name;
  16. URL url = ResourceLocator.findURLInClasspath(path);
  17. if (url != null) {
  18. return url;
  19. }
  20. adapterClass = adapterClass.getSuperclass();
  21. }
  22. return null;
  23. }

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

  1. /**
  2. * Locates and returns a named adapter resource. A resource can be an XML
  3. * file, etc.
  4. * <p>
  5. * This implementation is based on the premise that each adapter is located
  6. * in its own Java package and all resources are in the same package as
  7. * well. Resource lookup is recursive, so that if DbAdapter is a subclass of
  8. * another adapter, parent adapter package is searched as a failover.
  9. * </p>
  10. *
  11. * @since 3.0
  12. */
  13. protected URL findResource(String name) {
  14. Class<?> adapterClass = getClass();
  15. while (adapterClass != null && JdbcAdapter.class.isAssignableFrom(adapterClass)) {
  16. String path = Util.getPackagePath(adapterClass.getName()) + name;
  17. Collection<Resource> resources = resourceLocator.findResources(path);
  18. if (!resources.isEmpty()) {
  19. return resources.iterator().next().getURL();
  20. }
  21. adapterClass = adapterClass.getSuperclass();
  22. }
  23. return null;
  24. }

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

  1. /**
  2. * Constructor with a named domain configuration resource. Simply calls
  3. * {@link Configuration#Configuration(String)}.
  4. *
  5. * @throws ConfigurationException when <code>domainConfigurationName</code> is
  6. * <code>null</code>.
  7. * @see Configuration#Configuration(String)
  8. */
  9. public DefaultConfiguration(String domainConfigurationName) {
  10. super(domainConfigurationName);
  11. if (domainConfigurationName == null) {
  12. throw new ConfigurationException("cannot use null as domain file name.");
  13. }
  14. logObj.debug("using domain file name: " + domainConfigurationName);
  15. // configure CLASSPATH-only locator
  16. ResourceLocator locator = new ResourceLocator();
  17. locator.setSkipAbsolutePath(true);
  18. locator.setSkipClasspath(false);
  19. locator.setSkipCurrentDirectory(true);
  20. locator.setSkipHomeDirectory(true);
  21. // add the current Configuration subclass' package as additional path.
  22. if (!(this.getClass().equals(DefaultConfiguration.class))) {
  23. locator.addClassPath(Util.getPackagePath(this.getClass().getName()));
  24. }
  25. setResourceLocator(locator);
  26. }

相关文章