Java 类org.springframework.stereotype.Component 实例源码

项目:EasyFXML    文件:PrivateConstructorTest.java   
@Test
public void assertExistsPrivateCtor() {
    reflections.getSubTypesOf(Object.class).stream()
        .filter(clazz -> !clazz.isAnnotationPresent(Configuration.class))
        .filter(clazz -> !clazz.isAnnotationPresent(Component.class))
        .filter(clazz -> !clazz.isAnnotationPresent(SpringBootApplication.class))
        .filter(clazz -> !clazz.getName().endsWith("Test"))
        .filter(clazz -> !clazz.isInterface())
        .filter(clazz ->
            Arrays.stream(clazz.getDeclaredFields())
                .allMatch(field -> Modifier.isStatic(field.getModifiers())))
        .forEach(clazz -> {
            System.out.println("Expecting class "+clazz.getName()+" to :");
            System.out.print("\t-> be final ");
            assertThat(clazz).isFinal();
            System.out.println("[*]");
            System.out.print("\t-> have exactly one constructor ");
            Constructor<?>[] constructors = clazz.getDeclaredConstructors();
            assertThat(constructors).hasSize(1);
            System.out.println("[*]");
            System.out.print("\t-> and that this constructor is private ");
            assertThat(Modifier.isPrivate(constructors[0].getModifiers()));
            System.out.println("[*]");
        });
}
项目:spring-data-generator    文件:ManagerStructure.java   
public ManagerStructure(String managerPackage, String entityName, String postfix, String repositoryPackage, String repositoryPostfix) {

        String managerName = entityName + postfix;
        String repositoryName = entityName + repositoryPostfix;
        String repositoryNameAttribute = GeneratorUtils.decapitalize(repositoryName);

        this.objectBuilder = new ObjectBuilder(new ObjectStructure(managerPackage, ScopeValues.PUBLIC, ObjectTypeValues.CLASS, managerName)
                .addImport(repositoryPackage + "." + repositoryName)
                .addImport(Autowired.class)
                .addImport(Component.class)
                .addAnnotation(Component.class)
                .addAttribute(repositoryName, repositoryNameAttribute)
                .addConstructor(new ObjectStructure.ObjectConstructor(ScopeValues.PUBLIC, managerName)
                        .addAnnotation(Autowired.class)
                        .addArgument(repositoryName, repositoryNameAttribute)
                        .addBodyLine(ObjectValues.THIS.getValue() + repositoryNameAttribute + ExpressionValues.EQUAL.getValue() + repositoryNameAttribute)
                )
        ).setAttributeBottom(false);

    }
项目:bdf2    文件:AutoFormBuilder.java   
public void build(Object control, ViewComponent parentViewComponent) {
    AutoForm autoForm = (AutoForm) control;
    String id = autoForm.getId();
    ViewComponent component = generateViewComponent(id,AutoForm.class);
    if (StringUtils.isEmpty(id)) {
        component.setEnabled(false);
    }
    parentViewComponent.addChildren(component);
    for (com.bstek.dorado.view.widget.Component c : autoForm.getElements()) {
        for (IControlBuilder builder : builders) {
            if (builder.support(c)) {
                builder.build(c, component);
                break;
            }
        }
    }
}
项目:bdf2    文件:ContainerBuilder.java   
public void build(Object control, ViewComponent parentViewComponent) {
    Container container=(Container)control;
    String id=container.getId();
    ViewComponent component=new ViewComponent();
    component.setId(id);
    component.setIcon(">dorado/res/"+Container.class.getName().replaceAll("\\.", "/")+".png");
    component.setName(container.getClass().getSimpleName());
    if(StringUtils.isEmpty(id)){
        component.setEnabled(false);
    }
    parentViewComponent.addChildren(component);
    for(com.bstek.dorado.view.widget.Component c:container.getChildren()){
        for(IControlBuilder builder:builders){
            if(builder.support(c)){
                builder.build(c, component);
                break;
            }
        }
    }
}
项目:bdf2    文件:ContainerBuilder.java   
public void build(Object control, ViewComponent parentViewComponent) {
    Container container=(Container)control;
    String id=container.getId();
    ViewComponent component=new ViewComponent();
    component.setId(id);
    component.setIcon(">dorado/res/"+container.getClass().getName().replaceAll("\\.", "/")+".png");
    component.setName(container.getClass().getSimpleName());
    if(StringUtils.isEmpty(id)){
        component.setEnabled(false);
    }
    parentViewComponent.addChildren(component);
    for(com.bstek.dorado.view.widget.Component c:container.getChildren()){
        for(IControlBuilder builder:builders){
            if(builder.support(c)){
                builder.build(c, component);
                break;
            }
        }
    }
}
项目:tephra    文件:ClassReloaderImpl.java   
private String getBeanName(Class<?> clazz) {
    Component component = clazz.getAnnotation(Component.class);
    if (component != null)
        return component.value();

    Repository repository = clazz.getAnnotation(Repository.class);
    if (repository != null)
        return repository.value();

    Service service = clazz.getAnnotation(Service.class);
    if (service != null)
        return service.value();

    Controller controller = clazz.getAnnotation(Controller.class);
    if (controller != null)
        return controller.value();

    return null;
}
项目:spring4-understanding    文件:GroovyScriptFactoryTests.java   
@Test
// Test for SPR-6268
public void testRefreshableFromTagProxyTargetClass() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml",
            getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));

    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");

    assertTrue(AopUtils.isAopProxy(messenger));
    assertTrue(messenger instanceof Refreshable);
    assertEquals("Hello World!", messenger.getMessage());

    assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));

    // Check that AnnotationUtils works with concrete proxied script classes
    assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
项目:spring4-understanding    文件:AnnotationUtilsTests.java   
@Test
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {

    // 1) Get an annotation
    Component component = WebController.class.getAnnotation(Component.class);
    assertNotNull(component);

    // 2) Convert the annotation into AnnotationAttributes
    AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
    assertNotNull(attributes);

    // 3) Synthesize the AnnotationAttributes back into an annotation
    Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
    assertNotNull(synthesizedComponent);

    // 4) Verify that the original and synthesized annotations are equivalent
    assertNotSame(component, synthesizedComponent);
    assertEquals(component, synthesizedComponent);
    assertEquals("value from component: ", "webController", component.value());
    assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
private void doTestSubClassAnnotationInfo(AnnotationMetadata metadata) {
    assertThat(metadata.getClassName(), is(AnnotatedComponentSubClass.class.getName()));
    assertThat(metadata.isInterface(), is(false));
    assertThat(metadata.isAnnotation(), is(false));
    assertThat(metadata.isAbstract(), is(false));
    assertThat(metadata.isConcrete(), is(true));
    assertThat(metadata.hasSuperClass(), is(true));
    assertThat(metadata.getSuperClassName(), is(AnnotatedComponent.class.getName()));
    assertThat(metadata.getInterfaceNames().length, is(0));
    assertThat(metadata.isAnnotated(Component.class.getName()), is(false));
    assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
    assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
    assertThat(metadata.hasAnnotation(Component.class.getName()), is(false));
    assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
    assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
    assertThat(metadata.getAnnotationTypes().size(), is(0));
    assertThat(metadata.getAnnotationAttributes(Component.class.getName()), nullValue());
    assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size(), equalTo(0));
    assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()), equalTo(false));
    assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()), nullValue());
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
    assertThat(metadata.getClassName(), is(Component.class.getName()));
    assertThat(metadata.isInterface(), is(true));
    assertThat(metadata.isAnnotation(), is(true));
    assertThat(metadata.isAbstract(), is(true));
    assertThat(metadata.isConcrete(), is(false));
    assertThat(metadata.hasSuperClass(), is(false));
    assertThat(metadata.getSuperClassName(), nullValue());
    assertThat(metadata.getInterfaceNames().length, is(1));
    assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
    assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
    assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
    assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
    assertThat(metadata.hasAnnotation(Documented.class.getName()), is(true));
    assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
    assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
    assertThat(metadata.getAnnotationTypes().size(), is(3));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PropertyMappingContextCustomizer.java   
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
        throws BeansException {
    Class<?> beanClass = bean.getClass();
    Set<Class<?>> components = new LinkedHashSet<Class<?>>();
    Set<Class<?>> propertyMappings = new LinkedHashSet<Class<?>>();
    while (beanClass != null) {
        for (Annotation annotation : AnnotationUtils.getAnnotations(beanClass)) {
            if (isAnnotated(annotation, Component.class)) {
                components.add(annotation.annotationType());
            }
            if (isAnnotated(annotation, PropertyMapping.class)) {
                propertyMappings.add(annotation.annotationType());
            }
        }
        beanClass = beanClass.getSuperclass();
    }
    if (!components.isEmpty() && !propertyMappings.isEmpty()) {
        throw new IllegalStateException("The @PropertyMapping "
                + getAnnotationsDescription(propertyMappings)
                + " cannot be used in combination with the @Component "
                + getAnnotationsDescription(components));
    }
    return bean;
}
项目:singular-server    文件:SingularServerSpringMockitoTestConfig.java   
public void resetAndReconfigure(boolean debug) {
    SingularContextSetup.reset();
    ApplicationContextMock applicationContext = new ApplicationContextMock();
    ServiceRegistryLocator.setup(new SpringServiceRegistry());
    new ApplicationContextProvider().setApplicationContext(applicationContext);
    registerBeanFactories(applicationContext);
    registerAnnotated(applicationContext, Named.class);
    registerAnnotated(applicationContext, Service.class);
    registerAnnotated(applicationContext, Component.class);
    registerAnnotated(applicationContext, Repository.class);
    registerMockitoTestClassMocksAndSpies(applicationContext);
    getLogger().info("Contexto configurado com os beans: ");
    if (debug) {
        applicationContext.listAllBeans().forEach(
                b -> getLogger().info(b)
        );
    }
}
项目:spring-boot-concourse    文件:PropertyMappingContextCustomizer.java   
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
        throws BeansException {
    Class<?> beanClass = bean.getClass();
    Set<Class<?>> components = new LinkedHashSet<Class<?>>();
    Set<Class<?>> propertyMappings = new LinkedHashSet<Class<?>>();
    while (beanClass != null) {
        for (Annotation annotation : AnnotationUtils.getAnnotations(beanClass)) {
            if (isAnnotated(annotation, Component.class)) {
                components.add(annotation.annotationType());
            }
            if (isAnnotated(annotation, PropertyMapping.class)) {
                propertyMappings.add(annotation.annotationType());
            }
        }
        beanClass = beanClass.getSuperclass();
    }
    if (!components.isEmpty() && !propertyMappings.isEmpty()) {
        throw new IllegalStateException("The @PropertyMapping "
                + getAnnotationsDescription(propertyMappings)
                + " cannot be used in combination with the @Component "
                + getAnnotationsDescription(components));
    }
    return bean;
}
项目:moebooru-viewer    文件:MoebooruViewer.java   
public void showPostById(int id, java.awt.Component dialogParent){
    JOptionPane optionPane = new JOptionPane(Localization.format("retrieval_format", String.valueOf(id)), JOptionPane.INFORMATION_MESSAGE);
    JButton button = new JButton(Localization.getString("cancel"));
    optionPane.setOptions(new Object[]{button});
    JDialog dialog = optionPane.createDialog(dialogParent, Localization.getString("retrieving"));
    button.addActionListener(event -> dialog.dispose());
    dialog.setModalityType(ModalityType.MODELESS);
    dialog.setVisible(true);
    executor.execute(() -> {
        List<Post> searchPosts = mapi.listPosts(1, 1, "id:" + id);
        SwingUtilities.invokeLater(() -> {
            if (dialog.isDisplayable()){
                dialog.dispose();
                if (!searchPosts.isEmpty()){
                    showPostFrame.showPost(searchPosts.get(0));
                }else{
                    JOptionPane.showMessageDialog(null, Localization.getString("id_doesnot_exists"),
                        Localization.getString("error"), JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    });
}
项目:mybatis-spring-1.2.2    文件:MapperScannerConfigurerTest.java   
@Test
public void testMarkerInterfaceAndAnnotationScan() {
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "markerInterface", MapperInterface.class);
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "annotationClass", Component.class);

  startContext();

  // everything should be loaded but the marker interface
  applicationContext.getBean("annotatedMapper");
  applicationContext.getBean("mapperSubinterface");
  applicationContext.getBean("mapperChildInterface");

  assertBeanNotLoaded("mapperInterface");
}
项目:zstack    文件:ConfigurationManagerImpl.java   
private void generateApiMessageGroovyClass(StringBuilder sb, List<String> basePkgs) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(APIMessage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIReply.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIEvent.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                //classToApiMessageGroovyClass(sb, clazz);
                classToApiMessageGroovyInformation(sb, clazz);
            } catch (ClassNotFoundException e) {
                logger.warn(String.format("Unable to generate groovy class for %s", bd.getBeanClassName()), e);
            }
        }
    }
}
项目:zstack    文件:ConfigurationManagerImpl.java   
private void generateInventoryPythonClass(StringBuilder sb, List<String> basePkgs) {
    List<String> inventoryPython = new ArrayList<>();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(PythonClassInventory.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg).stream().sorted((bd1, bd2) -> {
            return bd1.getBeanClassName().compareTo(bd2.getBeanClassName());
        }).collect(Collectors.toList())) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                if (isPythonClassGenerated(clazz)) {
                    /* This class was generated as other's parent class */
                    continue;
                }
                inventoryPython.add(classToInventoryPythonClass(clazz));
            } catch (Exception e) {
                logger.warn(String.format("Unable to generate python class for %s", bd.getBeanClassName()), e);
            }
        }
    }

    for (String invstr : inventoryPython) {
        sb.append(invstr);
    }
}
项目:spring-dynamic    文件:Commons.java   
public static String getBeanName(Class<?> beanClass) {
    String beanName = null;
    Named nameAnn = beanClass.getAnnotation(Named.class);
    //todo 如果没有named标注,则不加入bean;
    if (nameAnn != null) {
        if (Utils.hasLength(nameAnn.value()))
            beanName = nameAnn.value();
    }
    else {
        Component componentAnn = beanClass.getAnnotation(Component.class);
        if (componentAnn != null) {
            if (Utils.hasLength(componentAnn.value()))
                beanName = componentAnn.value();
        }
    }

    if (!Utils.hasLength(beanName)) {
        beanName = Utils.beanName(beanClass.getSimpleName());
    }
    return beanName;
}
项目:swing    文件:StyleProfilePanel.java   
private void decorateLabelWithHighestValue(JPanel panel) {
    JLabel labelWithHigestValue = new JLabel("0.0");
    for (java.awt.Component component : panel.getComponents()) {
        if (component instanceof JLabel) {
            JLabel label = (JLabel) component;
            try {
                double value = Double.parseDouble(label.getText());
                if (value > Double.parseDouble(labelWithHigestValue.getText())) {
                    labelWithHigestValue = label;
                }
            } catch (NumberFormatException ignore) {}
        }
    }
    labelWithHigestValue.setOpaque(true);
    labelWithHigestValue.setBackground(Color.lightGray);
}
项目:swing    文件:EntityList.java   
@Override
@SuppressWarnings("unchecked")
public java.awt.Component getListCellRendererComponent(JList list,
                                                       Object value,
                                                       int index,
                                                       boolean isSelected,
                                                       boolean cellHasFocus) {
    E entity = (E) entityListModel.getElementAt(index);
    if (entity != null && entity.toString() != null && !entity.toString().isEmpty()) {
        setText(entity.toString());
    } else {
        setText("");
    }
    if (entityIcon != null) {
        setIcon(entityIcon);
    }
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    return this;
}
项目:swing    文件:ReturnsSummaryTable.java   
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    if (isSelected) {
        setForeground(table.getSelectionForeground());
        setBackground(table.getSelectionBackground());
    } else {
        setForeground(table.getForeground());
        setBackground(table.getBackground());
    }
    if (row == table.getSelectedRow() && column == table.getSelectedColumn()) {
        setBorder(selectedBorder);       
    } else {
        setBorder(defaultBorder);
    }
    setText((value == null) ? "" : value.toString());
    return this;
}
项目:swing    文件:ReturnsSummaryTable.java   
@Override
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    String text = value.toString();
    setText(text + " ");
    if (isSelected) {
        setBackground(table.getSelectionBackground());
        setForeground(table.getSelectionForeground());
    } else {
        setBackground(table.getBackground());
        setForeground(table.getForeground());
    }
    return this;
}
项目:swing    文件:BenchmarkPortfolioStatisticsTable.java   
@Override
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    setForeground(Color.black);
    String category = (String) value;
    setText(category);
    if (categories.contains(category) || category.isEmpty()) {
        setBackground(Colors.tableRowColor);
    } else {
        setBackground(Color.white);
    }
    if (isSelected) {
        setBackground(Colors.navy);
        setForeground(Color.white);
    }
    return this;
}
项目:swing    文件:StockTable.java   
@Override
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    String text = value.toString();
    try {
        Double.parseDouble(text);
        setHorizontalAlignment(JLabel.RIGHT);
        setText(text + " ");
    } catch (NumberFormatException e) {
        setHorizontalAlignment(JLabel.LEFT);
        setText(text);
    }
    if (isSelected) {
        setBackground(table.getSelectionBackground());
        setForeground(table.getSelectionForeground());
    } else {
        setBackground(table.getBackground());
        setForeground(table.getForeground());
    }
    return this;
}
项目:swing    文件:RegimeComboBox.java   
@Override
public java.awt.Component getListCellRendererComponent(JList list,
                                                             Object value,
                                                             int index,
                                                             boolean isSelected,
                                                             boolean cellHasFocus) {
          Regime regime = (Regime) value;
          setText(regime.getName());
          if (isSelected) {
              setBackground(list.getSelectionBackground());
              setForeground(list.getSelectionForeground());
          } else {
              setBackground(list.getBackground());
              setForeground(list.getForeground());
          }
          return this;
      }
项目:SocialDataImporter    文件:ClassUtilTest.java   
/**
 * Test method for {@link ch.sdi.core.util.ClassUtil#findCandidatesByAnnotation(java.lang.Class, java.lang.String)}.
 */
@Test
public void testFindCandidatesByAnnotationAndType()
{
    myLog.debug( "we parse all classes which are below the top level package" );
    String pack = this.getClass().getPackage().getName();
    myLog.debug( "found package: " + pack );
    pack = pack.replace( '.', '/' );
    String root = pack.split( "/" )[0];

    Collection<? extends Class<?>> received = ClassUtil.findCandidatesByAnnotation( ConverterFactory.class,
                                                                                    Component.class,
                                                                                    root );

    Assert.assertNotNull( received );
    Assert.assertEquals( 1, received.size() );
    received.forEach( c -> myLog.debug( "Found class with annotation @Component and type 'ConverterFactory': "
                + c.getName() ) );

}
项目:class-guard    文件:GroovyScriptFactoryTests.java   
@Test
// Test for SPR-6268
public void testRefreshableFromTagProxyTargetClass() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml",
            getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));

    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");

    assertTrue(AopUtils.isAopProxy(messenger));
    assertTrue(messenger instanceof Refreshable);
    assertEquals("Hello World!", messenger.getMessage());

    assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));

    // Check that AnnotationUtils works with concrete proxied script classes
    assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
项目:mybatis-spring    文件:MapperScannerConfigurerTest.java   
@Test
public void testMarkerInterfaceAndAnnotationScan() {
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "markerInterface", MapperInterface.class);
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "annotationClass", Component.class);

  startContext();

  // everything should be loaded but the marker interface
  applicationContext.getBean("annotatedMapper");
  applicationContext.getBean("mapperSubinterface");
  applicationContext.getBean("mapperChildInterface");

  assertBeanNotLoaded("mapperInterface");
}
项目:super-csv-annotation    文件:SpringBeanFactory.java   
private String getBeanName(final Class<?> clazz) {

    final Component componentAnno = clazz.getAnnotation(Component.class);
    if(componentAnno != null && !componentAnno.value().isEmpty()) {
        return componentAnno.value();
    }

    final Service serviceAnno = clazz.getAnnotation(Service.class);
    if(serviceAnno != null && !serviceAnno.value().isEmpty()) {
        return serviceAnno.value();
    }

    final Repository repositoryAnno = clazz.getAnnotation(Repository.class);
    if(repositoryAnno != null && !repositoryAnno.value().isEmpty()) {
        return repositoryAnno.value();
    }

    final Controller controllerAnno = clazz.getAnnotation(Controller.class);
    if(controllerAnno != null && !controllerAnno.value().isEmpty()) {
        return controllerAnno.value();
    }

    // ステレオタイプのアノテーションでBean名の指定がない場合は、クラス名の先頭を小文字にした名称とする。
    return uncapitalize(clazz.getSimpleName());
}
项目:parkingfriends    文件:SpringReloader.java   
private Annotation getSpringClassAnnotation(Class clazz) {
    Annotation classAnnotation = AnnotationUtils.findAnnotation(clazz, Component.class);

    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, Controller.class);
    }
    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, RestController.class);
    }
    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, Service.class);
    }
    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, Repository.class);
    }

    return classAnnotation;
}
项目:terminal-recall    文件:GamepadInputDeviceServiceFactory.java   
GamepadInputDevice(Controller controller){
if(controller==null)
    throw new NullPointerException("Passed Controller intolerably null.");
this.controller = controller;
controller.setEventQueueSize(256);
eventQueue = controller.getEventQueue();
System.out.println("CONTROLLER: "+controller.getClass().getName());
controllerSources = new ArrayList<GamepadControllerSource>(controller.getComponents().length);
//System.out.println("Rumblers: "+controller.getRumblers().length);
//controller.getRumblers()[0].rumble(1f);
for(net.java.games.input.Component comp : controller.getComponents()){
    GamepadControllerSource gcs = new GamepadControllerSource(comp);
    controllerSources.add(gcs);
    controllerSourceMap.put(comp, gcs);
    nameMap.put(comp.getName(),gcs);
    System.out.println("Component found: "+comp.getName());
}//end for(components)
gamepadEventThread.start();
   }
项目:poi-visualizer    文件:POITopMenuBar.java   
private void editApply() {
    java.awt.Component comp = contentArea.getSelectedComponent();
    if (comp instanceof CodeArea) {
        treeObservable.setBinarySource(() -> {
            // workaround bug in ByteArrayDataInputStream.read(byte[] output, int off, int len)
            final BinaryData bad = ((CodeArea)comp).getData();
            final long size = bad.getDataSize();
            ByteArrayEditableData data = new ByteArrayEditableData();
            try (InputStream is = new BoundedInputStream(bad.getDataInputStream(),size)) {
                data.loadFromStream(is);
            }
            return data;
        });
    } else if (comp instanceof XMLEditor) {
        ((XMLEditor)comp).saveXml();
    } else {
        return;
    }
    treeObservable.notifyObservers(MENU_EDIT_APPLY);    
}
项目:springboot-addon    文件:RestNewEndpointDecorator.java   
public static JavaClassSource createGreetingPropertiesClass(JavaClassSource current) {
   JavaClassSource source = Roaster.create(JavaClassSource.class).setName("GreetingProperties").setPackage(current.getPackage());
   source.addAnnotation(Component.class);
   source.addAnnotation(ConfigurationProperties.class).setStringValue("greeting");
   source.addProperty(String.class, "message").getField().setStringInitializer("Hello, %s!");
   return source;
}
项目:homunculus    文件:SPRComponentWidget.java   
@Nullable
@Override
public <T> AnnotatedComponent<T> process(Scope scope, Class<T> clazz) {
    Component widget = clazz.getAnnotation(Component.class);
    if (widget != null) {
        return new AnnotatedComponent(clazz, widget.value(), ComponentType.BEAN);
    }
    return null;
}
项目:bdf2    文件:AutoFormBuilder.java   
public void build(Object control, ViewComponent parentViewComponent) {
    AutoForm autoForm = (AutoForm) control;
    String id = autoForm.getId();
    ViewComponent component = generateViewComponent(id,AutoForm.class);
    if (StringUtils.isEmpty(id)) {
        component.setEnabled(false);
    }
    parentViewComponent.addChildren(component);
    for (com.bstek.dorado.view.widget.Component c : autoForm.getElements()) {
        for (IControlBuilder builder : builders) {
            if (builder.support(c)) {
                builder.build(c, component);
                break;
            }
        }
    }
}
项目:dwr    文件:DwrClassPathBeanDefinitionScanner.java   
public DwrClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry)
{
    super(registry, false);
    addExcludeFilter(new AnnotationTypeFilter(Component.class));
    addExcludeFilter(new AnnotationTypeFilter(Service.class));
    addExcludeFilter(new AnnotationTypeFilter(Repository.class));
    addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    setScopedProxyMode(ScopedProxyMode.INTERFACES);
}
项目:spring4-understanding    文件:ClassPathScanningCandidateComponentProviderTests.java   
@Test
public void testWithComponentAnnotationOnly() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
    provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
    provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
    provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
    assertEquals(2, candidates.size());
    assertTrue(containsBeanClass(candidates, NamedComponent.class));
    assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
    assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
    assertFalse(containsBeanClass(candidates, StubFooDao.class));
    assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
项目:spring4-understanding    文件:ClassPathScanningCandidateComponentProviderTests.java   
@Test
public void testWithMultipleMatchingFilters() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
    provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
    assertEquals(6, candidates.size());
    assertTrue(containsBeanClass(candidates, NamedComponent.class));
    assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
    assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
}
项目:spring4-understanding    文件:ClassPathScanningCandidateComponentProviderTests.java   
@Test
public void testExcludeTakesPrecedence() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
    provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
    provider.addExcludeFilter(new AssignableTypeFilter(FooService.class));
    Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
    assertEquals(5, candidates.size());
    assertTrue(containsBeanClass(candidates, NamedComponent.class));
    assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
    assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
}
项目:spring4-understanding    文件:AnnotationUtilsTests.java   
/** @since 4.2 */
@Test
public void findMethodAnnotationWithMetaMetaAnnotationOnLeaf() throws Exception {
    Method m = Leaf.class.getMethod("metaMetaAnnotatedOnLeaf");
    assertNull(m.getAnnotation(Component.class));
    assertNull(getAnnotation(m, Component.class));
    assertNotNull(findAnnotation(m, Component.class));
}