Package org.jboss.managed.api

Examples of org.jboss.managed.api.ManagedObject


      ManagedCommon parent = component;
      while(parent.getParent() != null)
         parent = parent.getParent();

      // Get the managed object, as a component can also be a child of a managedObject
      ManagedObject managedObject = component.getDeployment().getManagedObject(parent.getName());
      if(managedObject == null && parent instanceof ManagedObject)
         managedObject = (ManagedObject) parent;

      // Get the current attachment
      String attachmentName = managedObject.getAttachmentName();
      List<AttachmentMetaData> attachments = repositoryMetaData.getAttachments();
      if(attachments == null)
      {
         attachments = new ArrayList<AttachmentMetaData>();
         repositoryMetaData.setAttachments(attachments);
      }
      // Extract the attachment
      AttachmentMetaData attachment = null;
      for(AttachmentMetaData a : attachments)
      {
         if(attachmentName.equals(a.getName()))
            attachment = a;
      }

      // Create a new one
      if(attachment == null)
      {
         // Create attachment meta data
         attachment = new AttachmentMetaData();
         // Add attachment meta data
         attachments.add(attachment);
      }

      // Is attachmentName the same as the className ?
      attachment.setName(attachmentName);
      attachment.setClassName(managedObject.getAttachment().getClass().getName());

      // Save the attachment
      String attachmentPath = deploymentPath + attachment.getName();
      // Create the persistence information
      PersistenceRoot persistenceRoot = getSerializer().loadAttachment(attachmentPath, PersistenceRoot.class);
View Full Code Here


   public void testNoTxDataSourceDeploymentMetaData()
   {
      enableTrace("org.jboss.managed.plugins.factory");
      ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
      mof.addInstanceClassFactory(new NoTxCFInstanceClassFactory());
      ManagedObject mo = mof.createManagedObject(NoTxDataSourceDeploymentMetaData.class);
      log.info(mo.getProperties());
      // Validate the expected property names
      Set<String> expectedPropertyNames = new TreeSet<String>();
      expectedPropertyNames.addAll(Arrays.asList(ManagedConnectionFactoryDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(DataSourceDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(NonXADataSourceDeploymentMetaData_NAMES));
      Set<String> propertyNames = mo.getPropertyNames();
      TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
      if(expectedPropertyNames.equals(sortedPropertyNames) == false)
      {
         Set<String> missingNames = new TreeSet<String>();
         Set<String> extraNames = new TreeSet<String>();
View Full Code Here

      enableTrace("org.jboss.managed.plugins.factory");
      ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
      TxInstanceClassFactory icf = new TxInstanceClassFactory();
      mof.setInstanceClassFactory(TxConnectionFactoryDeploymentMetaData.class, icf);
      TxConnectionFactoryDeploymentMetaData txcf = new TxConnectionFactoryDeploymentMetaData();
      ManagedObject mo = mof.initManagedObject(txcf, "TxConnectionFactoryDeploymentMetaData", null);
      // Validate the expected property names
      Set<String> expectedPropertyNames = new TreeSet<String>();
      expectedPropertyNames.addAll(Arrays.asList(ManagedConnectionFactoryDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(TxConnectionFactoryDeploymentMetaData_NAMES));
      Set<String> propertyNames = mo.getPropertyNames();
      TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
      if(expectedPropertyNames.equals(sortedPropertyNames) == false)
      {
         Set<String> missingNames = new TreeSet<String>();
         Set<String> extraNames = new TreeSet<String>();
         analyzeDiffs(expectedPropertyNames, sortedPropertyNames,
               missingNames, extraNames);
         fail("Extra properties: "+extraNames+", missing properties: "+missingNames);
      }
      ManagedProperty connectionProperties = mo.getProperty("config-property");
      MetaType cpType = connectionProperties.getMetaType();
      assertTrue("connection-properties.type="+cpType, cpType instanceof CompositeMetaType);
      Object cpValue = connectionProperties.getValue();
      assertTrue("connection-properties.value="+cpValue, cpValue instanceof CompositeValue);
      CompositeValue cvalue = (CompositeValue) cpValue;
      // Now update the values
      MapCompositeValueSupport map = (MapCompositeValueSupport) cvalue;

      // Test simple property types
      ManagedProperty xatx = mo.getProperty("xa-transaction");
      xatx.setValue(SimpleValueSupport.wrap(true));
      assertEquals(Boolean.TRUE, txcf.getXATransaction());
      ManagedProperty xart = mo.getProperty("xa-resource-timeout");
      xart.setValue(SimpleValueSupport.wrap(12345));
      assertEquals(12345, txcf.getXaResourceTimeout());
   }
View Full Code Here

      LocalDataSourceDeploymentMetaData lds = new LocalDataSourceDeploymentMetaData();
      // Set a SecurityMetaData to validate its MO
      SecurityMetaData smd = new ApplicationManagedSecurityMetaData();
      smd.setDomain("java:/jaas/SomeDomain");
      lds.setSecurityMetaData(smd);
      ManagedObject mo = mof.initManagedObject(lds, "LocalDataSourceDeploymentMetaData", null);
      // Validate the expected property names
      Set<String> expectedPropertyNames = new TreeSet<String>();
      expectedPropertyNames.addAll(Arrays.asList(ManagedConnectionFactoryDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(DataSourceDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(NonXADataSourceDeploymentMetaData_NAMES));
      Set<String> propertyNames = mo.getPropertyNames();
      TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
      if(expectedPropertyNames.equals(sortedPropertyNames) == false)
      {
         Set<String> missingNames = new TreeSet<String>();
         Set<String> extraNames = new TreeSet<String>();
         analyzeDiffs(expectedPropertyNames, sortedPropertyNames,
               missingNames, extraNames);
         fail("Extra properties: "+extraNames+", missing properties: "+missingNames);
      }
      // interleaving
      ManagedProperty interleaving = mo.getProperty("interleaving");
      assertNotNull(interleaving);
      MetaType interleavingType = interleaving.getMetaType();
      assertEquals("interleaving.type", SimpleMetaType.BOOLEAN, interleavingType);

      // Validate the connection-properties type
      ManagedProperty connectionProperties = mo.getProperty("connection-properties");
      MetaType cpType = connectionProperties.getMetaType();
      assertTrue("connection-properties.type="+cpType, cpType instanceof CompositeMetaType);
      Object cpValue = connectionProperties.getValue();
      assertTrue("connection-properties.value="+cpValue, cpValue instanceof CompositeValue);
      CompositeValue cvalue = (CompositeValue) cpValue;
      // Now update the values
      MapCompositeValueSupport map = (MapCompositeValueSupport) cvalue;
      map.put("key1", SimpleValueSupport.wrap("value1"));
      map.put("key2", SimpleValueSupport.wrap("value2"));
      connectionProperties.setValue(map);
      // Check the underlying values
      List<DataSourceConnectionPropertyMetaData> ldsProps = lds.getDataSourceConnectionProperties();
      assertEquals(2, ldsProps.size());
      DataSourceConnectionPropertyMetaData key1 = null;
      DataSourceConnectionPropertyMetaData key2 = null;
      for(DataSourceConnectionPropertyMetaData dspmd : ldsProps)
      {
         if(dspmd.getName().equals("key1"))
            key1 = dspmd;
         else if(dspmd.getName().equals("key2"))
            key2 = dspmd;
      }
      assertNotNull(key1);
      assertEquals("value1", key1.getValue());
      assertNotNull(key2);
      assertEquals("value2", key2.getValue());
      // Test a simple property
      ManagedProperty driverClass = mo.getProperty("driver-class");
      driverClass.setValue(SimpleValueSupport.wrap("org.jboss.jdbc.ClusteredDriver"));
      String driverClassName = lds.getDriverClass();
      assertEquals("org.jboss.jdbc.ClusteredDriver", driverClassName);
      // Validate the security-domain
      ManagedProperty secDomain = mo.getProperty("security-domain");
      assertNotNull("security-domain", secDomain);
      CompositeMetaType compType = (CompositeMetaType) secDomain.getMetaType();
      assertNotNull(compType);
      CompositeValue sdCV = (CompositeValue) secDomain.getValue();
      assertNotNull("security-domain.CV", sdCV);
View Full Code Here

      enableTrace("org.jboss.managed.plugins.factory");
      ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
      XADSInstanceClassFactory icf = new XADSInstanceClassFactory();
      mof.setInstanceClassFactory(XADataSourceDeploymentMetaData.class, icf);
      XADataSourceDeploymentMetaData xads = new XADataSourceDeploymentMetaData();
      ManagedObject mo = mof.initManagedObject(xads, "XADataSourceDeploymentMetaData", null);
      // Validate the expected property names
      Set<String> expectedPropertyNames = new TreeSet<String>();
      expectedPropertyNames.addAll(Arrays.asList(ManagedConnectionFactoryDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(DataSourceDeploymentMetaData_NAMES));
      expectedPropertyNames.addAll(Arrays.asList(XADataSourceDeploymentMetaData_NAMES));
      Set<String> propertyNames = mo.getPropertyNames();
      TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
      if(expectedPropertyNames.equals(sortedPropertyNames) == false)
      {
         Set<String> missingNames = new TreeSet<String>();
         Set<String> extraNames = new TreeSet<String>();
         analyzeDiffs(expectedPropertyNames, sortedPropertyNames,
               missingNames, extraNames);
         fail("Extra properties: "+extraNames+", missing properties: "+missingNames);
      }
      // Validate the xa-datasource-properties type
      ManagedProperty connectionProperties = mo.getProperty("xa-datasource-properties");
      MetaType cpType = connectionProperties.getMetaType();
      assertTrue("xa-datasource-properties.type="+cpType, cpType instanceof CompositeMetaType);
      Object cpValue = connectionProperties.getValue();
      assertTrue("xa-datasource-properties.value="+cpValue, cpValue instanceof CompositeValue);
      CompositeValue cvalue = (CompositeValue) cpValue;
      // Now update the values
      MapCompositeValueSupport map = (MapCompositeValueSupport) cvalue;
      map.put("key1", SimpleValueSupport.wrap("value1"));
      map.put("key2", SimpleValueSupport.wrap("value2"));
      connectionProperties.setValue(map);
      // Check the underlying values
      List<XAConnectionPropertyMetaData> xaProps = xads.getXADataSourceProperties();
      assertEquals(2, xaProps.size());
      DataSourceConnectionPropertyMetaData key1 = null;
      DataSourceConnectionPropertyMetaData key2 = null;
      for(XAConnectionPropertyMetaData dspmd : xaProps)
      {
         if(dspmd.getName().equals("key1"))
            key1 = dspmd;
         else if(dspmd.getName().equals("key2"))
            key2 = dspmd;
      }
      assertNotNull(key1);
      assertEquals("value1", key1.getValue());
      assertNotNull(key2);
      assertEquals("value2", key2.getValue());
      // Test a simple property
      ManagedProperty jndiName = mo.getProperty("jndi-name");
      jndiName.setValue(SimpleValueSupport.wrap("java:ClusteredDS"));
      String jndiNameTest = xads.getJndiName();
      assertEquals("java:ClusteredDS", jndiNameTest);
   }
View Full Code Here

      ServiceMetaDataICF icf = new ServiceMetaDataICF();
      mof.setInstanceClassFactory(ServiceMetaData.class, icf);
      ServiceMetaData smd = new ServiceMetaData();
      smd.setCode(JBossManagedConnectionPool.class.getName());
      smd.setObjectName(new ObjectName("jboss:service=Hypersonic,database=localDB"));
      ManagedObject mo = mof.initManagedObject(smd, null, null);
      // Validate the expected property names
      Set<String> expectedPropertyNames = new TreeSet<String>();
      expectedPropertyNames.addAll(Arrays.asList(JBossManagedConnectionPool_NAMES));
      Set<String> propertyNames = mo.getPropertyNames();
      TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
      if(expectedPropertyNames.equals(sortedPropertyNames) == false)
      {
         Set<String> missingNames = new TreeSet<String>();
         Set<String> extraNames = new TreeSet<String>();
View Full Code Here

      ManagementDeployment mdAnnotation = null;
      HashMap<String, ManagedObject> validUnitMOs = new HashMap<String, ManagedObject>();
      for(String name : unitMOs.keySet())
      {
         // TODO: why should there be null ManagedObjects?
         ManagedObject mo = unitMOs.get(name);
         if(mo == null)
            continue;
         validUnitMOs.put(name, mo);
         Map<String, Annotation> annotations = mo.getAnnotations();
         if(annotations != null && mdAnnotation == null)
            mdAnnotation = (ManagementDeployment) annotations.get(ManagementDeployment.class.getName());
      }
      String simpleName = unit.getSimpleName();
      String[] types = {};
View Full Code Here

      for(String name : attachments)
      {
         Object instance = unit.getAttachment(name);
         if (instance != null)
         {
            ManagedObject mo = factory.initManagedObject(instance, metaData);
            if (mo != null)
            {
               managedObjects.put(mo.getName(), mo);
            }
         }
      }
   }
View Full Code Here

         return;

      List<BeanMetaDataFactory> beanFactories = deployment.getBeanFactories();

      // Get the KernelDeployment ManagedObject
      ManagedObject deploymentMO = managedObjects.get(KernelDeployment.class.getName());
      if(deploymentMO == null)
      {
         // Check for the KernelDeployment impl name
         deploymentMO = managedObjects.get(AbstractKernelDeployment.class.getName());
         if(deploymentMO == null)
         {
            // Should not happen?
            deploymentMO = mof.createManagedObject(deployment.getClass());
         }
         else
         {
            // Put the MO under the attachment interface name
            managedObjects.remove(AbstractKernelDeployment.class.getName());
         }
         managedObjects.put(KernelDeployment.class.getName(), deploymentMO);
      }
      if(deploymentMO instanceof MutableManagedObject)
         ((MutableManagedObject) deploymentMO).setName(KernelDeployment.class.getName());
      if(deploymentMO instanceof ManagedObjectImpl)
         ((ManagedObjectImpl) deploymentMO).setAttachmentName(KernelDeployment.class.getName());

      MetaData metaData = unit.getMetaData();
      // Update the beanFactories value to a list of BeanMetaDataFactory with BeanMetaDatas
      ManagedProperty beanFactoriesMP = deploymentMO.getProperty("beanFactories");
      List<GenericValue> tmpBFs = new ArrayList<GenericValue>();
      CollectionMetaType beansFactoryType = new CollectionMetaType(BeanMetaDataFactory.class.getName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
      if(beanFactories != null)
      {
         List<GenericValue> tmpBeans = new ArrayList<GenericValue>();
         CollectionMetaType beansType = new CollectionMetaType(BeanMetaDataFactory.class.getName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
         for(BeanMetaDataFactory bmdf : beanFactories)
         {
           
            ManagedObject bmdfMO = mof.initManagedObject(bmdf, metaData);
            if(bmdfMO == null)
            {
               // Create a container managed object
               bmdfMO = createFactoryManagedObject(bmdf, deploymentMO, metaData);
            }

            if((bmdfMO instanceof MutableManagedObject) == false)
            {
               // Just go with the default ManagedObject
               GenericValueSupport gv = new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, bmdfMO);
               tmpBFs.add(gv);
               continue;
            }

            MutableManagedObject bmdfMMO = (MutableManagedObject) bmdfMO;
            bmdfMMO.setParent(deploymentMO);
            Map<String, ManagedProperty> oldProps = bmdfMMO.getProperties();
            ManagedProperty beansMPCheck = oldProps.get("beans");
            // If there already is a beans property assume it's correct
            if(beansMPCheck != null)
            {
               // Need to map
               continue;
            }

            Map<String, ManagedProperty> newProps = new HashMap<String, ManagedProperty>(oldProps);
            // Create a beans ManagedProperty, a list of BeanMetaData ManagedObjects
            Fields fields = getFields("beans", beansType);
            ManagedPropertyImpl beansMP = new ManagedPropertyImpl(bmdfMO, fields);
            newProps.put("beans", beansMP);

            // Create a ManagedObject for each of the beans BeanMetaData
            List<BeanMetaData> beans = bmdf.getBeans();
            if(beans != null)
            {
               for(BeanMetaData bmd : beans)
               {
                  DeploymentUnit compUnit = unit.getComponent(bmd.getName());
                  if(compUnit == null)
                  {
                     log.debug("Failed to find component for bean: "+bmd.getName());
                     continue;
                  }
                  MetaData compMetaData = compUnit.getMetaData();
                  GenericValue gv = getManagedObjectValue(bmd, compMetaData, bmdfMO);
                  if(gv != null)
                  {
                     // The component managed objects need to be in the root map
                     ManagedObject compMO = (ManagedObject) gv.getValue();
                     // Use the ManagedObject name if it's not the same as the attachmentName
                     String managedObjectName = compUnit.getName();
                     if(compMO != null && compMO.getAttachmentName() != null)
                     {
                        managedObjectName = compMO.getAttachmentName().equals(compMO.getName()) ?
                              compUnit.getName() : compMO.getName();
                     }
                     // Add the managed object
                     managedObjects.put(managedObjectName, compMO);
                     // Add the bean MO to the beans list
                     tmpBeans.add(gv);
View Full Code Here

    * @return
    */
   protected GenericValue getManagedObjectValue(BeanMetaData bmd, MetaData metaData, ManagedObject parentMO)
   {
      String name = bmd.getName();
      ManagedObject mo = mof.initManagedObject(bmd, null, metaData, name, null);
      if(parentMO != null && mo instanceof MutableManagedObject)
      {
         MutableManagedObject mmo = (MutableManagedObject) mo;
         mmo.setParent(parentMO);
         Map<String, ManagedProperty> oldProps = mmo.getProperties();
View Full Code Here

TOP

Related Classes of org.jboss.managed.api.ManagedObject

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.