Package org.osgi.service.blueprint.reflect

Examples of org.osgi.service.blueprint.reflect.BeanMetadata


  }
 
  @Test
  public void testContextWithProps_110() {
    Element e = getTestElement("contextWithProps", root_110);
    BeanMetadata bean =
      (BeanMetadata) sut.decorate(e, new BeanMetadataImpl(), parserCtx);
    BeanMetadata innerBean = (BeanMetadata) ((BeanProperty) bean.getProperties().get(0)).getValue();
   
    assertEquals("createEntityManager", innerBean.getFactoryMethod());
   
    assertEquals(1, registeredComponents.size());
    ReferenceMetadata reference = (ReferenceMetadata) registeredComponents.get(0);
   
    assertEquals(EntityManagerFactory.class.getName(), reference.getInterface());
View Full Code Here


  }
 
  @Test
  public void testNoMoreProxying() {
      Element e = getTestElement("contextWithProps", root);
      BeanMetadata input = new BeanMetadataImpl();
      Object output = sut.decorate(e, input, parserCtx);
      assertTrue(input == output);
  }
View Full Code Here

  }
 
  @Test
  public void testNoMoreProxying_110() {
      Element e = getTestElement("contextWithProps", root_110);
      BeanMetadata input = new BeanMetadataImpl();
      Object output = sut.decorate(e, input, parserCtx);
      assertTrue(input == output);
  }
View Full Code Here

  }
 
  @Test
  public void testNonIndexedArgs_110() {
      Element e = getTestElement("withUnitArg", root_110);
      BeanMetadata input = new BeanMetadataImpl();
      Object output = sut.decorate(e, input, parserCtx);
      assertEquals("Wrong number of arguments",
          1 ,input.getArguments().size());
      assertEquals("Wrong class type", "javax.persistence.EntityManagerFactory",
          ((BeanArgument)input.getArguments().get(0)).getValueType());
      assertEquals("Wrong index", -1,
          ((BeanArgument)input.getArguments().get(0)).getIndex());
     
      ReferenceMetadata reference = (ReferenceMetadata) ((BeanArgument)input.getArguments().get(0)).getValue();
      assertEquals(EntityManagerFactory.class.getName(), reference.getInterface());
      assertEquals("(&(!(org.apache.aries.jpa.proxy.factory=*))(osgi.unit.name=myUnit))", reference.getFilter());
     
      Skeleton.getSkeleton(manager).assertSkeletonNotCalled();
      assertTrue(registeredComponents.isEmpty());
     
      e = getTestElement("withContextArg", root_110);
      input = new BeanMetadataImpl();
      output = sut.decorate(e, input, parserCtx);
     
      assertEquals("Wrong number of arguments",
          1 ,input.getArguments().size());
      assertEquals("Wrong type", "javax.persistence.EntityManager",
          ((BeanArgument)input.getArguments().get(0)).getValueType());
      assertEquals("Wrong index", -1,
          ((BeanArgument)input.getArguments().get(0)).getIndex());
     
      BeanMetadata innerBean = (BeanMetadata) ((BeanArgument)input.getArguments().get(0)).getValue();

      assertEquals("createEntityManager", innerBean.getFactoryMethod());
      assertEquals("internalClose", innerBean.getDestroyMethod());

      assertEquals(1, registeredComponents.size());
      reference = (ReferenceMetadata) registeredComponents.get(0);
     
      assertEquals(EntityManagerFactory.class.getName(), reference.getInterface());
View Full Code Here

  }
 
  @Test
  public void testIndexedArgs_110() {
      Element e = getTestElement("withIndexedUnitArg", root_110);
      BeanMetadata input = new BeanMetadataImpl();
      Object output = sut.decorate(e, input, parserCtx);
      assertEquals("Wrong number of arguments",
          1 ,input.getArguments().size());
      assertEquals("Wrong class type", "javax.persistence.EntityManagerFactory",
          ((BeanArgument)input.getArguments().get(0)).getValueType());
      assertEquals("Wrong index", 0,
          ((BeanArgument)input.getArguments().get(0)).getIndex());
     
      ReferenceMetadata reference = (ReferenceMetadata) ((BeanArgument)input.getArguments().get(0)).getValue();
      assertEquals(EntityManagerFactory.class.getName(), reference.getInterface());
      assertEquals("(&(!(org.apache.aries.jpa.proxy.factory=*))(osgi.unit.name=myUnit))", reference.getFilter());
     
      Skeleton.getSkeleton(manager).assertSkeletonNotCalled();
      assertTrue(registeredComponents.isEmpty());
     
      e = getTestElement("withIndexedContextArg", root_110);
      input = new BeanMetadataImpl();
      output = sut.decorate(e, input, parserCtx);
     
      assertEquals("Wrong number of arguments",
          1 ,input.getArguments().size());
      assertEquals("Wrong type", "javax.persistence.EntityManager",
          ((BeanArgument)input.getArguments().get(0)).getValueType());
      assertEquals("Wrong index", 1,
          ((BeanArgument)input.getArguments().get(0)).getIndex());
     
      BeanMetadata innerBean = (BeanMetadata) ((BeanArgument)input.getArguments().get(0)).getValue();

      assertEquals("createEntityManager", innerBean.getFactoryMethod());
      assertEquals("internalClose", innerBean.getDestroyMethod());

      assertEquals(1, registeredComponents.size());
      reference = (ReferenceMetadata) registeredComponents.get(0);
     
      assertEquals(EntityManagerFactory.class.getName(), reference.getInterface());
View Full Code Here

  }
 
  @Test
  public void testInvalidIndex_110() {
      Element e = getTestElement("withInvalidIndexArg", root_110);
      BeanMetadata input = new BeanMetadataImpl();
      try {
          Object output = sut.decorate(e, input, parserCtx);
          fail("Should throw an exception");
      } catch (IllegalArgumentException iae) {
          assertTrue("Wrong cause type", iae.getCause() instanceof NumberFormatException);
View Full Code Here

    }
   
    static Class<?> getClassForMetaData(BlueprintContainer container, ComponentMetadata cmd) {
        Class<?> cls = null;
        if (cmd instanceof BeanMetadata) {
            BeanMetadata bm = (BeanMetadata)cmd;
            if (bm instanceof ExtendedBeanMetadata) {
                cls = ((ExtendedBeanMetadata)bm).getRuntimeClass();
            }
            if (cls == null && bm.getClassName() != null) {
                try {
                    Method m = ReflectionUtil.findMethod(container.getClass(), "loadClass", String.class);
                    cls = (Class<?>)ReflectionUtil.setAccessible(m).invoke(container, bm.getClassName());
                } catch (Exception e) {
                    //ignore
                }
            }
        }
View Full Code Here

    }

    public boolean hasConfiguredPropertyValue(String beanName, String propertyName, String value) {
        ComponentMetadata cmd = getComponentMetadata(beanName);
        if (cmd instanceof BeanMetadata) {
            BeanMetadata br = (BeanMetadata)cmd;
            for (BeanProperty s : br.getProperties()) {
                if (propertyName.equals(s.getName())) {
                    return true;
                }
            }
            return false;
View Full Code Here

        for (String id : ids) {
            try {
                ComponentMetadata metadata = blueprintContainer.getComponentMetadata(id);
                Class<?> cl = null;
                if (metadata instanceof BeanMetadata) {
                    BeanMetadata beanMetadata = (BeanMetadata)metadata;
                    cl = bundle.loadClass(beanMetadata.getClassName());
                } else if (metadata instanceof ReferenceMetadata) {
                    ReferenceMetadata referenceMetadata = (ReferenceMetadata)metadata;
                    cl = bundle.loadClass(referenceMetadata.getInterface());
                }
                if (cl != null && type.isAssignableFrom(cl)) {
View Full Code Here

    /**
     * Allows for ignoring beans that are explicitly configured in the Spring XML files
     */
    protected boolean shouldIgnoreBean(Class<?> type) {
        for (Object metadataObject : blueprintContainer.getMetadata(BeanMetadata.class)) {
            BeanMetadata metadata = (BeanMetadata) metadataObject;
            if (BeanMetadata.SCOPE_SINGLETON.equals(metadata.getScope())) {
                Object bean = blueprintContainer.getComponentInstance(metadata.getId());
                if (type.isInstance(bean)) {
                    return true;
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.osgi.service.blueprint.reflect.BeanMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.