@Test public void testPointcutEvents() throws Exception { this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT); ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); assertEquals("Incorrect number of events fired", 1, componentDefinitions.length); assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; assertEquals("aop:config", compositeDef.getName()); ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); PointcutComponentDefinition pcd = null; for (int i = 0; i < nestedComponentDefs.length; i++) { ComponentDefinition componentDefinition = nestedComponentDefs[i]; if (componentDefinition instanceof PointcutComponentDefinition) { pcd = (PointcutComponentDefinition) componentDefinition; break; } } assertNotNull("PointcutComponentDefinition not found", pcd); assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length); }
public boolean containsComponentDefinition(String name) { for (ComponentDefinition cd : this.registeredComponents) { if (cd instanceof CompositeComponentDefinition) { ComponentDefinition[] innerCds = ((CompositeComponentDefinition) cd).getNestedComponents(); for (ComponentDefinition innerCd : innerCds) { if (innerCd.getName().equals(name)) { return true; } } } else { if (cd.getName().equals(name)) { return true; } } } return false; }
/** * Register default TablePanel Actions * @param element current element * @param parserContext parserContext * @return a new ComponentDefinition with default table action list. */ private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) { ManagedList<Object> actions = new ManagedList<Object>(7); actions.add(createBeanDefinition(AddAction.class, parserContext)); actions.add(createBeanDefinition(RefreshAction.class, parserContext)); actions.add(createBeanDefinition(RemoveAction.class, parserContext)); actions.add(createBeanDefinition(FindAction.class, parserContext)); actions.add(createBeanDefinition(ClearFilterAction.class, parserContext)); BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class); bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element)); bdb.addPropertyValue("sourceList", actions); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), DEFAULT_TABLE_ACTIONS); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * @return */ private ComponentDefinition registerAccessorFactory(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition( ConfigurableControlAccessorFactory.class); Map<Class<?>, Class<?extends ControlAccessor>> accessors = new ManagedMap<Class<?>,Class<?extends ControlAccessor>>(); accessors.put(JTextComponent.class, TextComponentAccessor.class); accessors.put(JList.class, ListAccessor.class); accessors.put(Selector.class, SelectorAccessor.class); accessors.put(JToggleButton.class, ToggleButtonAccessor.class); accessors.put(JComboBox.class, ComboAccessor.class); accessors.put(View.class, ViewAccessor.class); accessors.put(JLabel.class, LabelAccessor.class); accessors.put(TablePanel.class, TablePanelAccessor.class); bdb.addPropertyValue("accessors", accessors); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), ACCESSOR_FACTORY_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * Register default TablePanel Actions * @param element current element * @param parserContext parserContext * @return a new ComponentDefinition with default table action list. */ private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) { ManagedList<Object> actions = new ManagedList<Object>(7); actions.add(createBeanDefinition(AddAction.class, parserContext)); actions.add(createBeanDefinition(SelectAllAction.class, parserContext)); actions.add(createBeanDefinition(DeselectAllAction.class, parserContext)); actions.add(createBeanDefinition(RemoveAllAction.class, parserContext)); actions.add(createBeanDefinition(HideShowFilterAction.class, parserContext)); actions.add(createBeanDefinition(ApplyFilterAction.class, parserContext)); actions.add(createBeanDefinition(ClearFilterAction.class, parserContext)); BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class); bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element)); bdb.addPropertyValue("sourceList", actions); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), DEFAULT_TABLE_ACTIONS); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
public void componentRegistered( ComponentDefinition paramComponentDefinition) { String name = paramComponentDefinition.getName(); for(BeanDefinition bd : paramComponentDefinition.getBeanDefinitions()) { processBeanDefinition(name, bd); } }
public void registerComponent(ComponentDefinition component) { CompositeComponentDefinition containingComponent = getContainingComponent(); if (containingComponent != null) { containingComponent.addNestedComponent(component); } else { this.readerContext.fireComponentRegistered(component); } }
@Test public void testAdvisorEventsWithPointcutRef() throws Exception { this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT); ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); assertEquals("Incorrect number of events fired", 2, componentDefinitions.length); assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; assertEquals("aop:config", compositeDef.getName()); ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length); AdvisorComponentDefinition acd = null; for (int i = 0; i < nestedComponentDefs.length; i++) { ComponentDefinition componentDefinition = nestedComponentDefs[i]; if (componentDefinition instanceof AdvisorComponentDefinition) { acd = (AdvisorComponentDefinition) componentDefinition; break; } } assertNotNull("AdvisorComponentDefinition not found", acd); assertEquals(1, acd.getBeanDefinitions().length); assertEquals(2, acd.getBeanReferences().length); assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition); BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1]; assertEquals("countingAdvice", adviceDef.getBeanName()); }
@Test public void testAdvisorEventsWithDirectPointcut() throws Exception { this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT); ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); assertEquals("Incorrect number of events fired", 2, componentDefinitions.length); assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; assertEquals("aop:config", compositeDef.getName()); ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); AdvisorComponentDefinition acd = null; for (int i = 0; i < nestedComponentDefs.length; i++) { ComponentDefinition componentDefinition = nestedComponentDefs[i]; if (componentDefinition instanceof AdvisorComponentDefinition) { acd = (AdvisorComponentDefinition) componentDefinition; break; } } assertNotNull("AdvisorComponentDefinition not found", acd); assertEquals(2, acd.getBeanDefinitions().length); assertEquals(1, acd.getBeanReferences().length); assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition); BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1]; assertEquals("countingAdvice", adviceDef.getBeanName()); }
@Test public void testSourceExtraction() { Iterator<ComponentDefinition> iterator = context.getRegisteredComponents(); while (iterator.hasNext()) { ComponentDefinition compDef = iterator.next(); assertNotNull("CompositeComponentDefinition '" + compDef.getName() + "' has no source attachment", compDef.getSource()); validateComponentDefinition(compDef); } }
@Test public void beanEventReceived() throws Exception { ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean"); assertTrue(componentDefinition1 instanceof BeanComponentDefinition); assertEquals(1, componentDefinition1.getBeanDefinitions().length); BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0]; assertEquals(new TypedStringValue("Rob Harrop"), beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue()); assertEquals(1, componentDefinition1.getBeanReferences().length); assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName()); assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length); BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0]; assertEquals(new TypedStringValue("ACME"), innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue()); assertTrue(componentDefinition1.getSource() instanceof Element); ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2"); assertTrue(componentDefinition2 instanceof BeanComponentDefinition); assertEquals(1, componentDefinition1.getBeanDefinitions().length); BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0]; assertEquals(new TypedStringValue("Juergen Hoeller"), beanDefinition2.getPropertyValues().getPropertyValue("name").getValue()); assertEquals(0, componentDefinition2.getBeanReferences().length); assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length); BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0]; assertEquals(new TypedStringValue("Eva Schallmeiner"), innerBd2.getPropertyValues().getPropertyValue("name").getValue()); assertTrue(componentDefinition2.getSource() instanceof Element); }
@Test public void testEvents() { ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties"); assertNotNull("Event for 'myProperties' not sent", propertiesComponent); AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0]; assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass()); ComponentDefinition constantComponent = this.listener.getComponentDefinition("min"); assertNotNull("Event for 'min' not sent", propertiesComponent); AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0]; assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass()); }
@Test public void testSourceExtraction() { Iterator iterator = context.getRegisteredComponents(); while (iterator.hasNext()) { ComponentDefinition compDef = (ComponentDefinition) iterator.next(); assertNotNull("CompositeComponentDefinition '" + compDef.getName()+ "' has no source attachment", compDef.getSource()); validateComponentDefinition(compDef); } }
public void testBeanEventReceived() throws Exception { ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean"); assertTrue(componentDefinition1 instanceof BeanComponentDefinition); assertEquals(1, componentDefinition1.getBeanDefinitions().length); BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0]; assertEquals(new TypedStringValue("Rob Harrop"), beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue()); assertEquals(1, componentDefinition1.getBeanReferences().length); assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName()); assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length); BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0]; assertEquals(new TypedStringValue("ACME"), innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue()); assertTrue(componentDefinition1.getSource() instanceof Element); ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2"); assertTrue(componentDefinition2 instanceof BeanComponentDefinition); assertEquals(1, componentDefinition1.getBeanDefinitions().length); BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0]; assertEquals(new TypedStringValue("Juergen Hoeller"), beanDefinition2.getPropertyValues().getPropertyValue("name").getValue()); assertEquals(0, componentDefinition2.getBeanReferences().length); assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length); BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0]; assertEquals(new TypedStringValue("Eva Schallmeiner"), innerBd2.getPropertyValues().getPropertyValue("name").getValue()); assertTrue(componentDefinition2.getSource() instanceof Element); }
public void testEvents() throws Exception { ComponentDefinition propertiesComponent = this.listener.getComponentDefinition("myProperties"); assertNotNull("Event for 'myProperties' not sent", propertiesComponent); AbstractBeanDefinition propertiesBean = (AbstractBeanDefinition) propertiesComponent.getBeanDefinitions()[0]; assertEquals("Incorrect BeanDefinition", PropertiesFactoryBean.class, propertiesBean.getBeanClass()); ComponentDefinition constantComponent = this.listener.getComponentDefinition("min"); assertNotNull("Event for 'min' not sent", propertiesComponent); AbstractBeanDefinition constantBean = (AbstractBeanDefinition) constantComponent.getBeanDefinitions()[0]; assertEquals("Incorrect BeanDefinition", FieldRetrievingFactoryBean.class, constantBean.getBeanClass()); }
@Override public void componentRegistered(ComponentDefinition componentDefinition) { log.info("Registered component [" + componentDefinition.getName() + "]"); for (BeanDefinition bd : componentDefinition.getBeanDefinitions()) { String name = bd.getBeanClassName(); if (bd instanceof BeanComponentDefinition) { name = ((BeanComponentDefinition) bd).getBeanName(); } log.info("Registered bean definition: [" + name + "]" + " from " + bd.getResourceDescription()); } }
/** * @return */ private ComponentDefinition registerPaginatorView(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(VaadinPaginator.class); bdb.addPropertyValue("pageSizes", "10,20,30,40,50,100,All"); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), PAGINATOR_VIEW_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * Register default CustomEditorConfigurer * @return default CustomEditorComfigurer ComponentDefinition */ private ComponentDefinition registerPropertyEditors(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition( CustomEditorConfigurer.class); Map<String, String> map = new HashMap<String, String>(); map.put("com.vaadin.server.Resource", "org.jdal.vaadin.beans.VaadinResourcePropertyEditor"); bdb.addPropertyValue("customEditors", map); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), CUSTOM_EDITOR_CONFIGURER_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * @param element * @param parserContext * @return */ private ComponentDefinition registerDefaultGuiFactory(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition( ApplicationContextGuiFactory.class); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), DEFAULT_GUI_FACTORY); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * Register CollectionTableCellRenderer * @param element * @param parserContext * @return */ private ComponentDefinition registerCollectionTableCellRenderer(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(CollectionTableCellRenderer.class); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), COLLECTION_TABLE_CELL_RENDERER_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * @return */ private ComponentDefinition registerPaginatorView(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(PaginatorView.class); bdb.addPropertyValue("pageSizes", "10,20,30,40,50,100,All"); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), PAGINATOR_VIEW_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * @return */ private ComponentDefinition registerBinderFactory(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition( ConfigurableBinderFactory.class); bdb.addPropertyReference(ACCESSOR_FACTORY_BEAN_NAME, ACCESSOR_FACTORY_BEAN_NAME); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), BINDER_FACTORY_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * @return */ private ComponentDefinition registerPropertyEditors(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition( CustomEditorConfigurer.class); Map<String, String> map = new HashMap<String, String>(); map.put("java.awt.Image", "org.jdal.beans.ImagePropertyEditor"); map.put("javax.swing.Icon", "org.jdal.beans.IconPropertyEditor"); bdb.addPropertyValue("customEditors", map); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), CUSTOM_EDITOR_CONFIGURER_BEAN_NAME); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
/** * @param element * @param parserContext * @return */ @SuppressWarnings("unused") private ComponentDefinition registerControlInitializer(Element element, ParserContext parserContext) { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition( AnnotationControlInitializer.class); bdb.addPropertyReference(PERSISTENT_SERVICE, PERSISTENT_SERVICE); BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), CONTROL_INITIALIZER); registerBeanComponentDefinition(element, parserContext, bcd); return bcd; }
@Test public void testAspectEvent() throws Exception { this.reader.loadBeanDefinitions(CONTEXT); ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); assertEquals("Incorrect number of events fired", 5, componentDefinitions.length); assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; assertEquals("aop:config", compositeDef.getName()); ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); AspectComponentDefinition acd = null; for (int i = 0; i < nestedComponentDefs.length; i++) { ComponentDefinition componentDefinition = nestedComponentDefs[i]; if (componentDefinition instanceof AspectComponentDefinition) { acd = (AspectComponentDefinition) componentDefinition; break; } } assertNotNull("AspectComponentDefinition not found", acd); BeanDefinition[] beanDefinitions = acd.getBeanDefinitions(); assertEquals(5, beanDefinitions.length); BeanReference[] beanReferences = acd.getBeanReferences(); assertEquals(6, beanReferences.length); Set<String> expectedReferences = new HashSet<String>(); expectedReferences.add("pc"); expectedReferences.add("countingAdvice"); for (int i = 0; i < beanReferences.length; i++) { BeanReference beanReference = beanReferences[i]; expectedReferences.remove(beanReference.getBeanName()); } assertEquals("Incorrect references found", 0, expectedReferences.size()); for (int i = 1; i < componentDefinitions.length; i++) { assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition); } ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents(); assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length); assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition); PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0]; assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length); }
@Test public void testJndiLookupComponentEventReceived() { ComponentDefinition component = this.eventListener.getComponentDefinition("simple"); assertTrue(component instanceof BeanComponentDefinition); }
@Test public void testLocalSlsbComponentEventReceived() { ComponentDefinition component = this.eventListener.getComponentDefinition("simpleLocalEjb"); assertTrue(component instanceof BeanComponentDefinition); }
@Test public void testRemoteSlsbComponentEventReceived() { ComponentDefinition component = this.eventListener.getComponentDefinition("simpleRemoteEjb"); assertTrue(component instanceof BeanComponentDefinition); }
@Test public void componentEventReceived() { ComponentDefinition component = this.eventListener.getComponentDefinition("txAdvice"); assertThat(component, instanceOf(BeanComponentDefinition.class)); }
private void validateComponentDefinition(ComponentDefinition compDef) { BeanDefinition[] beanDefs = compDef.getBeanDefinitions(); for (BeanDefinition beanDef : beanDefs) { assertNotNull("BeanDefinition has no source attachment", beanDef.getSource()); } }