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

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

Introduction

In this page you can find the example usage for javax.xml.registry.infomodel Concept 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
 *//*from  ww  w  .j a  v a  2s. 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);
    }
}

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

/**
 * Test lcm.create, lcm.save and query of extended ExtrinsicObject
 *///from  w w w .j a va2s. c om
public void testExtendedExtrinsicObjectLCM() throws Exception {
    System.out.println("\ntestExtendedExtrinsicObjectLCM");

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

    Concept parentConcept = (Concept) bqm
            .getRegistryObject(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ExtrinsicObject, "ClassificationNode");
    Concept myExtrinsicObjectType = lcm.createConcept(parentConcept, "MyExtrinsicObject", "MyExtrinsicObject");
    myExtrinsicObjectType.setKey(lcm.createKey(EO_EXT_UUID));

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

        // test lcm.createObject(Concept)
        o = lcm.createObject(myExtrinsicObjectType);
        assertNotNull(o);
        assertTrue("ExtrinsicObject extensions must extend ExtrinsicObjectImpl",
                o instanceof ExtrinsicObjectImpl);
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyExtrinsicObject", myExtrinsicObjectType,
                ((ExtrinsicObject) o).getObjectType());

        // test lcm.createObject(String)
        o = lcm.createObject(EO_NICKNAME);
        assertNotNull(o);
        assertTrue("ExtrinsicObject extensions must extend ExtrinsicObjectImpl",
                o instanceof ExtrinsicObjectImpl);
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyExtrinsicObject", myExtrinsicObjectType,
                ((ExtrinsicObject) o).getObjectType());

        // test lcm.createExtrinsicObject
        o = lcm.createExtrinsicObject(myExtrinsicObjectType);
        assertNotNull(o);
        assertTrue("ExtrinsicObject extensions must extend ExtrinsicObjectImpl",
                o instanceof ExtrinsicObjectImpl);
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
        assertEquals("Should be of type MyExtrinsicObject", myExtrinsicObjectType,
                ((ExtrinsicObject) o).getObjectType());
        ((RegistryObject) o).setKey(lcm.createKey(EO_TEST_UUID));

        br = lcm.saveObjects(Collections.singleton(myExtrinsicObjectType));
        assertResponseSuccess(br);

        br = lcm.saveObjects(Collections.singleton(o));
        assertResponseSuccess(br);
        q = dqm.createQuery(QueryImpl.QUERY_TYPE_SQL,
                "select * from ExtrinsicObject where id = '" + EO_TEST_UUID + "'");
        br = dqm.executeQuery(q);
        assertResponseSuccess(br);
        o = br.getCollection().iterator().next();
        assertEquals("Should have been default class", EO_EXT_CLASSNAME, o.getClass().getName());
    } finally {
        // cleanup
        deleteIfExist(EO_EXT_UUID, LifeCycleManager.EXTRINSIC_OBJECT);
        deleteIfExist(EO_TEST_UUID, LifeCycleManager.EXTRINSIC_OBJECT);
    }
}

From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java

public BulkResponse saveAssociations(Collection associations, boolean replace) throws JAXRException {
    BulkResponseImpl bulk = new BulkResponseImpl();
    PublisherAssertion[] sarr = new PublisherAssertion[associations.size()];

    Collection<Key> coll = new ArrayList<Key>();
    Collection<Exception> exceptions = new ArrayList<Exception>();

    Iterator iter = associations.iterator();
    int currLoc = 0;
    while (iter.hasNext()) {

        Association association = (Association) iter.next();
        association.getSourceObject();/*w  w w . j a v  a2 s . com*/
        PublisherAssertion pa = ScoutJaxrUddiHelper.getPubAssertionFromJAXRAssociation(association);
        sarr[currLoc] = pa;
        currLoc++;

        // Save PublisherAssertion
        PublisherAssertions bd = null;
        try {
            bd = (PublisherAssertions) executeOperation(sarr, "SAVE_ASSOCIATION");
        } catch (RegistryException e) {
            exceptions.add(new SaveException(e));
            bulk.setExceptions(exceptions);
            bulk.setStatus(JAXRResponse.STATUS_FAILURE);
            return bulk;
        }
        if (bd != null) {
            List<PublisherAssertion> publisherAssertionList = bd.getPublisherAssertion();
            PublisherAssertion[] keyarr = new PublisherAssertion[publisherAssertionList.size()];
            publisherAssertionList.toArray(keyarr);

            for (int i = 0; keyarr != null && i < keyarr.length; i++) {
                PublisherAssertion result = (PublisherAssertion) keyarr[i];
                KeyedReference keyr = result.getKeyedReference();
                Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
                c.setName(new InternationalStringImpl(keyr.getKeyName()));
                c.setKey(new KeyImpl(keyr.getTModelKey()));
                c.setValue(keyr.getKeyValue());
                association.setAssociationType(c);
                coll.add(association.getKey());
            }
        }
    }
    bulk.setCollection(coll);
    bulk.setExceptions(exceptions);

    return bulk;
}

From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerV3Impl.java

public BulkResponse saveAssociations(Collection associations, boolean replace) throws JAXRException {
    BulkResponseImpl bulk = new BulkResponseImpl();
    PublisherAssertion[] sarr = new PublisherAssertion[associations.size()];

    Collection<Key> coll = new ArrayList<Key>();
    Collection<Exception> exceptions = new ArrayList<Exception>();

    Iterator iter = associations.iterator();
    int currLoc = 0;
    while (iter.hasNext()) {

        Association association = (Association) iter.next();
        association.getSourceObject();//from  w w  w. j  a v  a2s.  co  m
        PublisherAssertion pa = ScoutJaxrUddiV3Helper.getPubAssertionFromJAXRAssociation(association);
        sarr[currLoc] = pa;
        currLoc++;

        // Save PublisherAssertion
        PublisherAssertions bd = null;
        try {
            bd = (PublisherAssertions) executeOperation(sarr, "SAVE_ASSOCIATION");
        } catch (RegistryV3Exception e) {
            exceptions.add(new SaveException(e));
            bulk.setExceptions(exceptions);
            bulk.setStatus(JAXRResponse.STATUS_FAILURE);
            return bulk;
        }
        if (bd != null) {
            List<PublisherAssertion> publisherAssertionList = bd.getPublisherAssertion();
            PublisherAssertion[] keyarr = new PublisherAssertion[publisherAssertionList.size()];
            publisherAssertionList.toArray(keyarr);

            for (int i = 0; keyarr != null && i < keyarr.length; i++) {
                PublisherAssertion result = (PublisherAssertion) keyarr[i];
                KeyedReference keyr = result.getKeyedReference();
                Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
                c.setName(new InternationalStringImpl(keyr.getKeyName()));
                c.setKey(new KeyImpl(keyr.getTModelKey()));
                c.setValue(keyr.getKeyValue());
                association.setAssociationType(c);
                coll.add(association.getKey());
            }
        }
    }
    bulk.setCollection(coll);
    bulk.setExceptions(exceptions);

    return bulk;
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerImpl.java

public BulkResponse findAssociations(Collection findQualifiers, String sourceObjectId, String targetObjectId,
        Collection associationTypes) throws JAXRException {
    //TODO: Currently we just return all the Association objects owned by the caller
    IRegistry registry = (IRegistry) registryService.getRegistry();
    try {/*from   w w w .j  ava  2 s  .c o m*/
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);
        PublisherAssertions result = null;
        try {
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        } catch (RegistryException rve) {
            String username = getUsernameFromCredentials(con.getCredentials());
            if (AuthTokenSingleton.getToken(username) != null) {
                AuthTokenSingleton.deleteAuthToken(username);
            }
            auth = getAuthToken(con, registry);
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        }

        List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion();
        LinkedHashSet<Association> col = new LinkedHashSet<Association>();
        for (PublisherAssertion pas : publisherAssertionList) {
            String sourceKey = pas.getFromKey();
            String targetKey = pas.getToKey();

            if ((sourceObjectId == null || sourceObjectId.equals(sourceKey))
                    && (targetObjectId == null || targetObjectId.equals(targetKey))) {
                Collection<Key> orgcol = new ArrayList<Key>();
                orgcol.add(new KeyImpl(sourceKey));
                orgcol.add(new KeyImpl(targetKey));
                BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
                Association asso = ScoutUddiJaxrHelper.getAssociation(bl.getCollection(),
                        registryService.getBusinessLifeCycleManager());
                KeyedReference keyr = pas.getKeyedReference();
                Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
                c.setName(new InternationalStringImpl(keyr.getKeyName()));
                c.setKey(new KeyImpl(keyr.getTModelKey()));
                c.setValue(keyr.getKeyValue());
                asso.setAssociationType(c);
                col.add(asso);
            }

        }
        return new BulkResponseImpl(col);
    } catch (RegistryException e) {
        throw new JAXRException(e);
    }
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerImpl.java

public BulkResponse findCallerAssociations(Collection findQualifiers, Boolean confirmedByCaller,
        Boolean confirmedByOtherParty, Collection associationTypes) throws JAXRException {
    //TODO: Currently we just return all the Association objects owned by the caller
    IRegistry registry = (IRegistry) registryService.getRegistry();
    try {//from   w w w  .j a  v  a  2 s .  c  o m
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);

        AssertionStatusReport report = null;
        String confirm = "";
        boolean caller = confirmedByCaller.booleanValue();
        boolean other = confirmedByOtherParty.booleanValue();

        if (caller && other)
            confirm = Constants.COMPLETION_STATUS_COMPLETE;
        else if (!caller && other)
            confirm = Constants.COMPLETION_STATUS_FROMKEY_INCOMPLETE;
        else if (caller && !other)
            confirm = Constants.COMPLETION_STATUS_TOKEY_INCOMPLETE;

        report = null;
        try {
            report = registry.getAssertionStatusReport(auth.getAuthInfo(), confirm);
        } catch (RegistryException rve) {
            String username = getUsernameFromCredentials(con.getCredentials());
            if (AuthTokenSingleton.getToken(username) != null) {
                AuthTokenSingleton.deleteAuthToken(username);
            }
            auth = getAuthToken(con, registry);
            report = registry.getAssertionStatusReport(auth.getAuthInfo(), confirm);
        }

        List<AssertionStatusItem> assertionStatusItemList = report.getAssertionStatusItem();
        LinkedHashSet<Association> col = new LinkedHashSet<Association>();
        for (AssertionStatusItem asi : assertionStatusItemList) {
            String sourceKey = asi.getFromKey();
            String targetKey = asi.getToKey();
            Collection<Key> orgcol = new ArrayList<Key>();
            orgcol.add(new KeyImpl(sourceKey));
            orgcol.add(new KeyImpl(targetKey));
            BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
            Association asso = ScoutUddiJaxrHelper.getAssociation(bl.getCollection(),
                    registryService.getBusinessLifeCycleManager());
            //Set Confirmation
            ((AssociationImpl) asso).setConfirmedBySourceOwner(caller);
            ((AssociationImpl) asso).setConfirmedByTargetOwner(other);

            if (confirm != Constants.COMPLETION_STATUS_COMPLETE)
                ((AssociationImpl) asso).setConfirmed(false);

            Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
            KeyedReference keyr = asi.getKeyedReference();
            c.setKey(new KeyImpl(keyr.getTModelKey()));
            c.setName(new InternationalStringImpl(keyr.getKeyName()));
            c.setValue(keyr.getKeyValue());
            asso.setKey(new KeyImpl(keyr.getTModelKey())); //TODO:Validate this
            asso.setAssociationType(c);
            col.add(asso);
        }

        return new BulkResponseImpl(col);
    } catch (RegistryException e) {
        throw new JAXRException(e);
    }
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerV3Impl.java

public BulkResponse findAssociations(Collection findQualifiers, String sourceObjectId, String targetObjectId,
        Collection associationTypes) throws JAXRException {
    //TODO: Currently we just return all the Association objects owned by the caller
    IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
    try {/* w ww .ja v  a 2  s.  c o m*/
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);
        PublisherAssertions result = null;
        try {
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        } catch (RegistryV3Exception rve) {
            String username = getUsernameFromCredentials(con.getCredentials());
            if (AuthTokenV3Singleton.getToken(username) != null) {
                AuthTokenV3Singleton.deleteAuthToken(username);
            }
            auth = getAuthToken(con, registry);
            result = registry.getPublisherAssertions(auth.getAuthInfo());
        }

        List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion();
        LinkedHashSet<Association> col = new LinkedHashSet<Association>();
        for (PublisherAssertion pas : publisherAssertionList) {
            String sourceKey = pas.getFromKey();
            String targetKey = pas.getToKey();
            Collection<Key> orgcol = new ArrayList<Key>();
            orgcol.add(new KeyImpl(sourceKey));
            orgcol.add(new KeyImpl(targetKey));
            BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
            Association asso = ScoutUddiV3JaxrHelper.getAssociation(bl.getCollection(),
                    registryService.getBusinessLifeCycleManager());
            KeyedReference keyr = pas.getKeyedReference();
            Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
            c.setName(new InternationalStringImpl(keyr.getKeyName()));
            c.setKey(new KeyImpl(keyr.getTModelKey()));
            c.setValue(keyr.getKeyValue());
            asso.setAssociationType(c);
            col.add(asso);
        }
        return new BulkResponseImpl(col);
    } catch (RegistryV3Exception e) {
        throw new JAXRException(e);
    }
}

From source file:org.apache.ws.scout.registry.BusinessQueryManagerV3Impl.java

public BulkResponse findCallerAssociations(Collection findQualifiers, Boolean confirmedByCaller,
        Boolean confirmedByOtherParty, Collection associationTypes) throws JAXRException {
    //TODO: Currently we just return all the Association objects owned by the caller
    IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
    try {//  ww w.ja v  a 2 s .c  o m
        ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection();
        AuthToken auth = this.getAuthToken(con, registry);

        AssertionStatusReport report = null;
        String confirm = "";
        boolean caller = confirmedByCaller.booleanValue();
        boolean other = confirmedByOtherParty.booleanValue();

        if (caller && other)
            confirm = Constants.COMPLETION_STATUS_COMPLETE;
        else if (!caller && other)
            confirm = Constants.COMPLETION_STATUS_FROMKEY_INCOMPLETE;
        else if (caller && !other)
            confirm = Constants.COMPLETION_STATUS_TOKEY_INCOMPLETE;

        try {
            report = registry.getAssertionStatusReport(auth.getAuthInfo(), confirm);
        } catch (RegistryV3Exception rve) {
            String username = getUsernameFromCredentials(con.getCredentials());
            if (AuthTokenV3Singleton.getToken(username) != null) {
                AuthTokenV3Singleton.deleteAuthToken(username);
            }
            auth = getAuthToken(con, registry);
            report = registry.getAssertionStatusReport(auth.getAuthInfo(), confirm);
        }

        List<AssertionStatusItem> assertionStatusItemList = report.getAssertionStatusItem();
        LinkedHashSet<Association> col = new LinkedHashSet<Association>();
        for (AssertionStatusItem asi : assertionStatusItemList) {
            String sourceKey = asi.getFromKey();
            String targetKey = asi.getToKey();
            Collection<Key> orgcol = new ArrayList<Key>();
            orgcol.add(new KeyImpl(sourceKey));
            orgcol.add(new KeyImpl(targetKey));
            BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
            Association asso = ScoutUddiV3JaxrHelper.getAssociation(bl.getCollection(),
                    registryService.getBusinessLifeCycleManager());
            //Set Confirmation
            ((AssociationImpl) asso).setConfirmedBySourceOwner(caller);
            ((AssociationImpl) asso).setConfirmedByTargetOwner(other);

            if (confirm != Constants.COMPLETION_STATUS_COMPLETE)
                ((AssociationImpl) asso).setConfirmed(false);

            Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
            KeyedReference keyr = asi.getKeyedReference();
            c.setKey(new KeyImpl(keyr.getTModelKey()));
            c.setName(new InternationalStringImpl(keyr.getKeyName()));
            c.setValue(keyr.getKeyValue());
            asso.setKey(new KeyImpl(keyr.getTModelKey())); //TODO:Validate this
            asso.setAssociationType(c);
            col.add(asso);
        }

        return new BulkResponseImpl(col);
    } catch (RegistryV3Exception e) {
        throw new JAXRException(e);
    }
}

From source file:org.apache.ws.scout.util.EnumerationHelper.java

/**
 * /*www  .j  a v  a2  s.  c  o  m*/
 * @param firstToken
 * @param secondToken
 * @return Concept
 * @throws JAXRException
 */
private static Concept createConcept(String firstToken, String secondToken)
        throws JAXRException, IllegalArgumentException {
    if (!TYPES_LIST.contains(firstToken))
        throw new IllegalArgumentException("Expected the path to " + "start with one of " + TYPES);

    //get the predefined classificationscheme
    ClassificationScheme cs = new ClassificationSchemeImpl(null);
    cs.setName(new InternationalStringImpl(firstToken));
    cs.setKey(new KeyImpl(firstToken));

    ArrayList<String> conceptStrings = typesMap.get(firstToken);
    if (!conceptStrings.contains(secondToken))
        throw new IllegalArgumentException(
                "Expected the path to " + "end with one of " + conceptStrings.toArray());

    Concept concept = new ConceptImpl(null);
    concept.setName(new InternationalStringImpl(secondToken.toLowerCase()));
    concept.setValue(secondToken);
    concept.setKey(new KeyImpl(UDDI_ORG_TYPES));
    ((ConceptImpl) concept).setScheme(((ClassificationSchemeImpl) cs));
    return concept;
}