Java Code Examples for javax.management.relation.RelationTypeSupport

Following code examples demonstrate how to use javax.management.relation.RelationTypeSupportfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use javax.management.relation.RelationTypeSupportand various code implementation of this class.

        if (generic) {
            Attribute a = new Attribute("foo", "bar");
            AttributeList al1 = new AttributeList();
            al1.add(a);
            AttributeList al2 =
                new AttributeList(Arrays.asList(new Attribute[] {a}));
            check("new AttributeList(List<Attribute>)", al1.equals(al2));
            List<Attribute> al3 = checked(al1.asList(), Attribute.class);
            al3.remove(a);
            check("List<Attribute> AttributeList.asList()",
                  al1.equals(al3) && al1.isEmpty());
        } 


    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to RelationTypeSupport.class!",
                   RelationTypeSupport.class.isAssignableFrom(sut));
    } 

  
  public void testBasic()
  {
    RoleInfo roleInfo1 = null;
    RoleInfo roleInfo2 = null;
    RoleInfo[] roleInfos = null;
    RelationTypeSupport support = null;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfo2 = new RoleInfo("roleInfo2", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
      support = new RelationTypeSupport("name", roleInfos);
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    assertEquals("name", support.getRelationTypeName());

    ArrayList result = (ArrayList) support.getRoleInfos();
    assertEquals(2, result.size());

    try
    {
      assertEquals(roleInfo1.toString(), support.getRoleInfo("roleInfo1").toString());
      assertEquals(roleInfo2.toString(), support.getRoleInfo("roleInfo2").toString());
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    MyRelationTypeSupport mySupport = new MyRelationTypeSupport("myName");

    assertEquals("myName", mySupport.getRelationTypeName());
    result = (ArrayList) mySupport.getRoleInfos();
    assertEquals(0, result.size());

    try
    {
      mySupport.addRoleInfo(roleInfo1);
      result = (ArrayList) mySupport.getRoleInfos();
      assertEquals(1, result.size());
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
  } 

    }
    catch (ClassNotFoundException cnfe)
    {
      fail(cnfe.toString());
    } 

  
  public void testSerialization()
  {
    RoleInfo roleInfo1 = null;
    RoleInfo roleInfo2 = null;
    RoleInfo[] roleInfos = null;
    RelationTypeSupport support = null;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfo2 = new RoleInfo("roleInfo2", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
      support = new RelationTypeSupport("name", roleInfos);
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    RelationTypeSupport support2 = null;

    try
    {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(support);
    
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bais);
      support2 = (RelationTypeSupport) ois.readObject();
    }
    catch (IOException ioe)
    {
      fail(ioe.toString());
    }
    catch (ClassNotFoundException cnfe)
    {
      fail(cnfe.toString());
    }

    assertEquals("name", support2.getRelationTypeName());
    ArrayList result = (ArrayList) support2.getRoleInfos();
    assertEquals(2, result.size());
  } 

    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    } 

    }
    catch (InvalidRelationTypeException e)
    {
      caught = true;
    } 

    public Result testGetAllRelationTypeNames() throws Exception {

        MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

        RelationService relationService = new RelationService(true);
        ObjectName relationServiceName = new ObjectName(
                "mBeanServer:type=RelationService,name=rs");
        mBeanServer.registerMBean(relationService, relationServiceName);

        RoleInfo[] roleInfo = { new RoleInfo("JustRole", classPath) };

        relationService.createRelationType("RelationType0", roleInfo);
        relationService.addRelationType(new RelationTypeSupport(
                "RelationType1", roleInfo));
        relationService.addRelationType(new ERelationType("RelationType2",
                roleInfo));
        try {
            relationService.addRelationType(new ERelationType("RelationType3"));
        } catch (Exception e) {
            
        }

        for (int i = 0; i < 3; i++) {
            if (!relationService.getAllRelationTypeNames().contains(
                    "RelationType" + i)) {
                return failed("getAllRelationTypeNames missed data");
            }
        }
        if (relationService.getAllRelationTypeNames().contains(
                "RelationType" + 3)) {
            return failed("Incorrect Relation Type Added");
        }
        return passed();

    } 

Advertisement
Javadoc
A RelationTypeSupport object implements the RelationType interface. It represents a relation type, p

roviding role information for each role expected to be supported in every relation of that type. A relation type includes a relation type name and a list of role infos (represented by RoleInfo objects). A relation type has to be declared in the Relation Service: - either using the createRelationType() method, where a RelationTypeSupport object will be created and kept in the Relation Service - either using the addRelationType() method where the user has to create an object implementing the RelationType interface, and this object will be used as representing a relation type in the Relation Service.

The serialVersionUID of this class is 4611072955724144607L. @since 1.5

Read More
Advertisement