`

Preferences -- Registry

阅读更多
package org.jboss.seam.wiki.preferences.metamodel;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
import org.jboss.seam.wiki.preferences.PreferenceVisibility;
import org.jboss.seam.wiki.preferences.annotations.Preferences;
import org.jboss.seam.wiki.util.AnnotationDeploymentHelper;

import java.util.*;

@Name("preferenceRegistry")
@Scope(ScopeType.APPLICATION)
@Startup(depends = "pluginI18NBinder")
@BypassInterceptors
public class PreferenceRegistry {

    private static final LogProvider log = Logging.getLogProvider(PreferenceRegistry.class);

    Set<PreferenceEntity> preferenceEntities = new HashSet<PreferenceEntity>();
    Map<String, PreferenceEntity> preferenceEntitiesByName = new HashMap<String, PreferenceEntity>();

    Set<PreferenceEntity> preferenceEntitiesSystem = new HashSet<PreferenceEntity>();
    Set<PreferenceEntity> preferenceEntitiesUser = new HashSet<PreferenceEntity>();
    Set<PreferenceEntity> preferenceEntitiesInstance = new HashSet<PreferenceEntity>();

    @Create
    public void startup() {
        log.debug("initializing preferences registry");

        Set<Class<?>> preferencesClasses = AnnotationDeploymentHelper.getAnnotatedClasses(Preferences.class);

        if (preferencesClasses == null)
            throw new RuntimeException("No preference entities found, add @Preferences annotation to META-INF/seam-deployment.properties");

        for (Class preferencesClass : preferencesClasses) {
            PreferenceEntity preferenceEntity = new PreferenceEntity(preferencesClass);

            log.debug("adding '" + preferenceEntity.getEntityName() + "', " + preferenceEntity);

            if (preferenceEntitiesByName.containsKey(preferenceEntity.getEntityName())) {
                throw new RuntimeException("Duplicate preference entity name: " + preferenceEntity.getEntityName());
            }

            preferenceEntities.add(preferenceEntity);
            preferenceEntitiesByName.put(preferenceEntity.getEntityName(), preferenceEntity);

            if (preferenceEntity.isSystemPropertiesVisible())
                preferenceEntitiesSystem.add(preferenceEntity);
            if (preferenceEntity.isUserPropertiesVisible())
                preferenceEntitiesUser.add(preferenceEntity);
            if (preferenceEntity.isInstancePropertiesVisible())
                preferenceEntitiesInstance.add(preferenceEntity);
        }

        log.info("registered preference entities: " + preferenceEntities.size());

    }

    public Set<PreferenceEntity> getPreferenceEntities() {
        return preferenceEntities;
    }

    public Map<String, PreferenceEntity> getPreferenceEntitiesByName() {
        return preferenceEntitiesByName;
    }

    public Set<PreferenceEntity> getPreferenceEntitiesSystem() {
        return preferenceEntitiesSystem;
    }

    public Set<PreferenceEntity> getPreferenceEntitiesUser() {
        return preferenceEntitiesUser;
    }

    public Set<PreferenceEntity> getPreferenceEntitiesInstance() {
        return preferenceEntitiesInstance;
    }

    public SortedSet<PreferenceEntity> getPreferenceEntities(PreferenceVisibility... visibilities) {
        if (visibilities == null) return null;
        SortedSet<PreferenceEntity> entities = new TreeSet<PreferenceEntity>();
        List<PreferenceVisibility> visibilityList = Arrays.asList(visibilities);
        if (visibilityList.contains(PreferenceVisibility.SYSTEM)) entities.addAll(getPreferenceEntitiesSystem());
        if (visibilityList.contains(PreferenceVisibility.USER)) entities.addAll(getPreferenceEntitiesUser());
        if (visibilityList.contains(PreferenceVisibility.INSTANCE)) entities.addAll(getPreferenceEntitiesInstance());
        return entities;
    }

    public static PreferenceRegistry instance() {
        return (PreferenceRegistry) Component.getInstance(PreferenceRegistry.class);
    }

}

/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.seam.wiki.util;

import org.jboss.seam.deployment.AnnotationDeploymentHandler;
import org.jboss.seam.deployment.DeploymentStrategy;
import org.jboss.seam.Component;

import java.util.Set;

/**
 * A convenience class that allows us to access Seam deployment handlers without @In'jecting them.
 * <p>
 * This is useful because we can optimize things such as registries with @BypassInterceptors.
 * </p>
 *
 * @author Christian Bauer
 */
public class AnnotationDeploymentHelper {

    public static Set<Class<?>> getAnnotatedClasses(String annotationFQN) {
        DeploymentStrategy deployment = (DeploymentStrategy) Component.getInstance("deploymentStrategy");
        AnnotationDeploymentHandler handler =
                (AnnotationDeploymentHandler)deployment.getDeploymentHandlers().get(AnnotationDeploymentHandler.NAME);
        return handler.getClassMap().get(annotationFQN);
    }

    public static Set<Class<?>> getAnnotatedClasses(Class annotationType) {
        return getAnnotatedClasses(annotationType.getName());
    }

}

1.从ClassLoader中塞选所有Preferences Annotation Class.
2.Registry there prefernece class to seession scope.
3.That registry class it is plugin install,real have power is Preferences class @see Preferences
分享到:
评论

相关推荐

    docker-micro-service1

    IntelliJ编辑器中的Spring Boot DevTools + Live Reload问题首先启用自动构建IntelliJ -&gt; Preferences -&gt; Build Execution Deployment -&gt; Compiler -&gt; Build Project Automatically 第二次使用以下命令Command + Alt...

    InstantClient

    InstantClient安装使用 新安装系统,从未安装过任何版本... 打开pl sql-tools-preferences-connection设置Oracle Home为 C:\instantclient11.2;OCI Library为 C:\instantclient11.2\oci.dll (一般为空手动输入)

    JavaSE-6.0-英文手册(2008/11/30_FullUpdate)

    java.rmi.registry java.rmi.server java.security java.security.acl java.security.cert java.security.interfaces java.security.spec java.sql java.text java.text.spi java.util java.util....

    Group Policy Fundamentals - Security and ...

    Troubleshoot Group Policy using tools, logs, Resource Kit utilities, Registry hacks, and third-party tools Manage printers, restrict hardware, and configure Internet Explorer Deploy software to your ...

    Docker–Mac下配置阿里云容器镜像、测试运行hello-world镜像

    右键点击桌面顶栏的 docker 图标,选择 Preferences ,在 Daemon 标签(Docker 17.03 之前版本为 Advanced 标签)下的 Registry mirrors 列表中将复制的地址加到”registry-mirrors”的数组里,点击 Apply & Restart...

    xplite_trial

    to remove core system files, services and deeply rooted registry trees. We have grouped some of the more "serious" components into an Advanced Features section of the Add\Remove options tree. To ...

    Java2核心技术卷I+卷2:基础知识(第8版) 代码

    Java 核心技术 卷1 Index Chapter 1: An Introduction to Java 1 Java As a Programming Platform 2 The Java “White Paper” Buzzwords...A Complete Example: Accessing the Windows Registry 975 Index 991

    ORACLE OSB开发指南

    ORACLE OSB开发指南,英文版。 目录: Part I IDE Help for Oracle Service Bus 1 Introduction to Oracle Service Bus 2 Tasks Working with Projects, Folders, Resources, and Configurations .....................

    Docker版本 18.1.1 (53328) for Mac不支持m1芯片

    右键点击桌面顶栏的 docker 图标,选择 Preferences ,在 Daemon 标签(Docker 17.03 之前版本为 Advanced 标签)下的 Registry mirrors 列表中加入下面的镜像地址: http://f1361db2.m.daocloud.io 点击 Apply & ...

    VB编程资源大全(英文源码 API)

    For clarity's sake I made it write user color preferences. &lt;END&gt;&lt;br&gt;63,capture.zip This program captures the active window and displays it to a Picture box. &lt;END&gt;&lt;br&gt;64,TransIco.zip An update ...

Global site tag (gtag.js) - Google Analytics