class JobRegistryBeanPostProcessor
		implements BeanPostProcessor, BeanFactoryAware, InitializingBean, DisposableBean {

	private static final Log logger = LogFactory.getLog(JobRegistryBeanPostProcessor.class);

	// It doesn't make sense for this to have a default value...
	private JobRegistry jobRegistry = null;

	private final Collection<String> jobNames = new HashSet<>();

	private String groupName = null;

	private DefaultListableBeanFactory beanFactory;

	/**
	 * The group name for jobs registered by this component. Optional (defaults to null,
	 * which means that jobs are registered with their bean names). Useful where there is
	 * a hierarchy of application contexts all contributing to the same
	 * {@link JobRegistry}: child contexts can then define an instance with a unique group
	 * name to avoid clashes between job names.
	 * @param groupName the groupName to set
	 */
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	/**
	 * Injection setter for {@link JobRegistry}.
	 * @param jobRegistry the jobConfigurationRegistry to set
	 */
	public void setJobRegistry(JobRegistry jobRegistry) {
		this.jobRegistry = jobRegistry;
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		if (beanFactory instanceof DefaultListableBeanFactory) {
			this.beanFactory = (DefaultListableBeanFactory) beanFactory;
		}
	}

	/**
	 * Make sure the registry is set before use.
	 *
	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.state(jobRegistry != null, "JobRegistry must not be null");
	}

	/**
	 * Unregister all the {@link Job} instances that were registered by this post
	 * processor.
	 * @see org.springframework.beans.factory.DisposableBean#destroy()
	 */
	@Override
	public void destroy() throws Exception {<FILL_FUNCTION_BODY>}

	/**
	 * If the bean is an instance of {@link Job}, then register it.
	 * @throws FatalBeanException if there is a {@link DuplicateJobException}.
	 *
	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
	 * java.lang.String)
	 */
	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof Job job) {
			try {
				String groupName = this.groupName;
				if (beanFactory != null && beanFactory.containsBean(beanName)) {
					groupName = getGroupName(beanFactory.getBeanDefinition(beanName), job);
				}
				job = groupName == null ? job : new GroupAwareJob(groupName, job);
				ReferenceJobFactory jobFactory = new ReferenceJobFactory(job);
				String name = jobFactory.getJobName();
				if (logger.isDebugEnabled()) {
					logger.debug("Registering job: " + name);
				}
				jobRegistry.register(jobFactory);
				jobNames.add(name);
			}
			catch (DuplicateJobException e) {
				throw new FatalBeanException("Cannot register job configuration", e);
			}
			return job;
		}
		return bean;
	}

	/**
	 * Determine a group name for the job to be registered. The default implementation
	 * returns the {@link #setGroupName(String) groupName} configured. Provides an
	 * extension point for specialised subclasses.
	 * @param beanDefinition the bean definition for the job
	 * @param job the job
	 * @return a group name for the job (or null if not needed)
	 */
	protected String getGroupName(BeanDefinition beanDefinition, Job job) {
		return groupName;
	}

	/**
	 * Do nothing.
	 *
	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
	 * java.lang.String)
	 */
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		return bean;
	}

}

		for (String name : jobNames) {
			if (logger.isDebugEnabled()) {
				logger.debug("Unregistering job: " + name);
			}
			jobRegistry.unregister(name);
		}
		jobNames.clear();
	
<no_super_class>