本文整理汇总了Java中com.opensymphony.xwork2.config.PackageProvider类的典型用法代码示例。如果您正苦于以下问题:Java PackageProvider类的具体用法?Java PackageProvider怎么用?Java PackageProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageProvider类属于com.opensymphony.xwork2.config包,在下文中一共展示了PackageProvider类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadConfigFromBundle
import com.opensymphony.xwork2.config.PackageProvider; //导入依赖的package包/类
/**
* Loads XML config as well as Convention config from a bundle. Limitation: Constants and Beans are ignored on XML
* config
*
* @param bundle bundle to load from
*/
@SuppressWarnings("PMD.ExcessiveMethodLength")
protected void loadConfigFromBundle(Bundle bundle) {
final String bundleName = bundle.getSymbolicName();
if (LOG.isDebugEnabled()) {
LOG.debug("Loading packages from bundle " + bundleName);
}
// init action context
ActionContext ctx = ActionContext.getContext();
if (ctx == null) {
ctx = new ActionContext(new HashMap());
ActionContext.setContext(ctx);
}
try {
// the Convention plugin will use BundleClassLoaderInterface from the ActionContext to find resources
// and load classes
ctx.put(ClassLoaderInterface.CLASS_LOADER_INTERFACE, new BundleClassLoaderInterface());
ctx.put(DefaultBundleAccessor.CURRENT_BUNDLE_NAME, bundleName);
LOG.debug("Loading XML config from bundle " + bundleName);
// XML config
final BundlePackageLoader loader = new BundlePackageLoader();
for (final PackageConfig pkg : loader.loadPackages(bundle, this.objectFactory,
this.configuration.getPackageConfigs())) {
this.configuration.addPackageConfig(pkg.getName(), pkg);
this.bundleAccessor.addPackageFromBundle(bundle, pkg.getName());
}
// Convention
// get the existing packages before reloading the provider (se we can figure out what are the new packages)
final Set<String> packagesBeforeLoading = new HashSet(this.configuration.getPackageConfigNames());
final PackageProvider conventionPackageProvider =
this.configuration.getContainer().getInstance(PackageProvider.class, "convention.packageProvider");
if (conventionPackageProvider != null) {
LOG.debug("Loading Convention config from bundle " + bundleName);
conventionPackageProvider.loadPackages();
}
final Set<String> packagesAfterLoading = new HashSet(this.configuration.getPackageConfigNames());
packagesAfterLoading.removeAll(packagesBeforeLoading);
if (!packagesAfterLoading.isEmpty()) {
// add the new packages to the map of bundle -> package
for (final String packageName : packagesAfterLoading) {
this.bundleAccessor.addPackageFromBundle(bundle, packageName);
}
}
if (this.configuration.getRuntimeConfiguration() != null) {
// if there is a runtime config, it meas that this method was called froma bundle start event
// instead of the initial load, in that case, reload the config
this.configuration.rebuildRuntimeConfiguration();
}
} finally {
ctx.put(DefaultBundleAccessor.CURRENT_BUNDLE_NAME, null);
ctx.put(ClassLoaderInterface.CLASS_LOADER_INTERFACE, null);
}
}
示例2: setOsgiConfigurationProvider
import com.opensymphony.xwork2.config.PackageProvider; //导入依赖的package包/类
/**
* @param osgiConfigurationProvider the OSGi aware configuration provider
*/
@Inject("osgi")
public void setOsgiConfigurationProvider(PackageProvider osgiConfigurationProvider) {
this.osgiConfigurationProvider = (OsgiConfigurationProvider) osgiConfigurationProvider;
}