// Create the policy cache.
PolicyCache policyCache = createPolicyCache(
defaultRemoteCacheControlConstraints);
RemoteReadersFactory remoteReadersFactory =
createRemoteReadersFactory();
// Create the ProjectManager.
ProjectLoader projectLoader = createProjectLoader();
RepositoryContainer repositoryContainer =
new RepositoryContainer(jdbcRepository, xmlRepository);
// Create the remote project specific constraints.
CacheControlConstraintsMap defaultRemoteCacheControlConstraintsMap
= createRemoteCacheControlConstraintsMap(
defaultRemoteCacheControlConstraints);
// Create the local project specific constraints.
CacheControlConstraintsMap defaultLocalCacheControlConstraintsMap
= createLocalCacheControlConstraintsMap();
PopulatableProjectManager projectManager =
new ProjectManagerImpl(projectLoader,
new RuntimeProjectConfiguratorImpl(
defaultLocalCacheControlConstraintsMap,
defaultRemoteCacheControlConstraintsMap,
pathURLMapper, policyCache),
repositoryContainer,
remoteReadersFactory);
// Create the activator.
PolicyReferenceFactory referenceFactory =
new PolicyReferenceFactoryImpl(projectManager);
PolicyActivator policyActivator =
initializeRepositoryObjectActivators(referenceFactory);
// Create the retriever to use to retrieve activated policies from
// any source.
RuntimePolicyFactory runtimePolicyFactory =
RuntimePolicyFactory.getDefaultInstance();
ActivatedPolicyRetriever activatedPolicyRetriever =
runtimePolicyFactory.createCachingRetriever(
policyActivator, projectManager, policyCache);
policyFetcher = new PolicyFetcherImpl(activatedPolicyRetriever);
// Initialize the projects
projectManager.createPredefinedProjects(projects, configContext,
defaultLocalCacheControlConstraintsMap,
policyCache.getLocalDefaultGroup());
RuntimeProject defaultProject = projectManager.getDefaultProject();
// Determine the repository within which the default project
// resides.
LocalRepository defaultRepository;
PolicySource defaultPolicySource = defaultProject.getPolicySource();
if (defaultPolicySource instanceof JDBCPolicySource) {
defaultRepository = jdbcRepository;
} else if (defaultPolicySource instanceof XMLPolicySource) {
defaultRepository = xmlRepository;
} else {
throw new IllegalStateException(
"Unknown policy source for the default project: " +
defaultPolicySource);
}
// Initialize repository managers;
initializeDeprecatedManagers(defaultRepository, defaultProject,
policyCache);
initializeDeviceManager(deviceRepository, deviceRepositoryLocation);
// If we were asked to preload the default project policies...
if (defaultProject.isPreloaded()) {
// ... then preload the policy caches, syncronously.
// In future we may wish to do this asyncronously.
// NOTE: this will only load policies from the default
// project! The accessor API does not currently allow us
// to iterate over non-default projects.
PolicyCachePreloader preloader =
new PolicyCachePreloader(defaultRepository,
defaultProject,
deviceRepositoryAccessor);
preloader.run();
}
RemotePolicyBuildersReader policyBuildersReader =
remoteReadersFactory.createPolicyBuildersReader(
projectManager);
this.remotePolicyPreloader = new RemotePolicyPreloader(
policyBuildersReader, policyActivator, policyCache);
this.jdbcRepository = jdbcRepository;