Example usage for javax.xml.registry.infomodel RegistryObject setKey

List of usage examples for javax.xml.registry.infomodel RegistryObject setKey

Introduction

In this page you can find the example usage for javax.xml.registry.infomodel RegistryObject setKey.

Prototype

void setKey(Key key) throws JAXRException;

Source Link

Document

Sets the key representing the universally unique ID (UUID) for this object.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.InfomodelFactoryTest.java

/**
 * Test lcm.create, lcm.save and query of extended Association
 *///w  w w .  ja v a2 s .  c  o m
public void testExtendedAssociationLCM() throws Exception {
    System.out.println("\ntestExtendedAssociationLCM");

    Object o;
    @SuppressWarnings("unused")
    InfomodelFactory extUtil = InfomodelFactory.getInstance();

    Concept parentConcept = (Concept) bqm.getRegistryObject(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Association,
            "ClassificationNode");
    Concept myAssociationType = lcm.createConcept(parentConcept, "MyAssociation", "MyAssociation");
    myAssociationType.setKey(lcm.createKey(ASS_EXT_UUID));

    try {
        BulkResponse br;
        // Save concept and update it, to get the path
        br = lcm.saveObjects(Collections.singleton(myAssociationType));
        assertResponseSuccess(br);
        Query q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from ClassificationNode where id = '" + ASS_EXT_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        myAssociationType = (Concept) br.getCollection().iterator().next();

        // test lcm.createObject(Concept)
        o = lcm.createObject(myAssociationType);
        assertNotNull(o);
        assertTrue("Association extensions must extend AssociationImpl", o instanceof AssociationImpl);
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyAssociation", myAssociationType,
                ((Association) o).getAssociationType());

        // test lcm.createObject(String)
        o = lcm.createObject(ASS_NICKNAME);
        assertNotNull(o);
        assertTrue("Association extensions must extend AssociationImpl", o instanceof AssociationImpl);
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyAssociation", myAssociationType,
                ((Association) o).getAssociationType());

        // test lcm.createAssociation
        o = lcm.createAssociation(myAssociationType);
        assertNotNull(o);
        assertTrue("Association extensions must extend AssociationImpl", o instanceof AssociationImpl);
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyAssociation", myAssociationType,
                ((Association) o).getAssociationType());
        ((RegistryObject) o).setKey(lcm.createKey(ASS_TEST_UUID));

        // Association needs a source and a target
        RegistryObject target = lcm.createExtrinsicObject();
        target.setKey(lcm.createKey(EO_TEST_UUID));
        assertNotNull(target);
        ((AssociationImpl) o).setTargetObject(target);
        ((AssociationImpl) o).setSourceObject(parentConcept);

        ArrayList<Object> objects = new ArrayList<Object>();
        objects.add(o);
        objects.add(target);
        br = lcm.saveObjects(objects);
        assertResponseSuccess(br);
        q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from Association where id = '" + ASS_TEST_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        o = br.getCollection().iterator().next();
        assertEquals("Should have been default class", ASS_EXT_CLASSNAME, o.getClass().getName());
    } finally {
        // cleanup
        deleteIfExist(ASS_EXT_UUID, LifeCycleManager.ASSOCIATION);
        deleteIfExist(EO_TEST_UUID, LifeCycleManager.EXTRINSIC_OBJECT);
        deleteIfExist(ASS_TEST_UUID, LifeCycleManager.ASSOCIATION);
    }
}