Example usage for javax.xml.registry.infomodel Association getSourceObject

List of usage examples for javax.xml.registry.infomodel Association getSourceObject

Introduction

In this page you can find the example usage for javax.xml.registry.infomodel Association getSourceObject.

Prototype

RegistryObject getSourceObject() throws JAXRException;

Source Link

Document

Gets the Object that is the source of this Association.

Usage

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

/**
 * Test that removeRegistryObject really does remove the
 * association between this RegistryPackage and the member
 * RegistryObject./*from w ww  .j a  v a  2s.c  o  m*/
 *
 * @exception Exception if an error occurs
 */
@SuppressWarnings("static-access")
public void testRemoveRegistryObject() throws Exception {
    HashMap<String, String> saveObjectsSlots = new HashMap<String, String>();

    //The bulk loader MUST turn off versioning because it updates
    //objects in its operations which would incorrectly be created as
    //new objects if versioning is ON when the object is updated.
    saveObjectsSlots.put(bu.CANONICAL_SLOT_LCM_DONT_VERSION, "true");
    saveObjectsSlots.put(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT, "true");

    String testName = "testRemoveRegistryObject";

    String uuid1 = it.cnr.icar.eric.common.Utility.getInstance().createId();

    RegistryPackage pkg1 = getLCM().createRegistryPackage(uuid1);
    pkg1.setKey(getLCM().createKey(uuid1));
    pkg1.setDescription(getLCM().createInternationalString(testName));

    // -- Save the Object
    ArrayList<Object> objects = new ArrayList<Object>();
    objects.add(pkg1);
    BulkResponse resp = ((LifeCycleManagerImpl) getLCM()).saveObjects(objects, saveObjectsSlots);
    JAXRUtility.checkBulkResponse(resp);
    System.out.println("Created Registry Package with Id " + uuid1);

    String uuid2 = it.cnr.icar.eric.common.Utility.getInstance().createId();

    RegistryPackage pkg2 = getLCM().createRegistryPackage(uuid2);
    pkg2.setKey(getLCM().createKey(uuid2));
    pkg2.setDescription(getLCM().createInternationalString(testName));

    // -- Add pkg2 to Registry Package and save
    pkg1.addRegistryObject(pkg2);

    // -- Save the Object
    objects = new ArrayList<Object>();
    objects.add(pkg1);
    objects.add(pkg2);

    resp = ((LifeCycleManagerImpl) getLCM()).saveObjects(objects, saveObjectsSlots);
    JAXRUtility.checkBulkResponse(resp);
    System.out.println("Added Registry Package with Id " + uuid2);

    // Remove the package.
    pkg1.removeRegistryObject(pkg2);
    // -- Save the Object
    objects = new ArrayList<Object>();
    objects.add(pkg1);

    resp = ((LifeCycleManagerImpl) getLCM()).saveObjects(objects, saveObjectsSlots);
    JAXRUtility.checkBulkResponse(resp);
    System.out.println("Removed Registry Package with Id " + uuid2);

    // Get 'HasMember' associations of pkg1.
    ArrayList<String> associationTypes = new ArrayList<String>();
    associationTypes.add(bu.CANONICAL_ASSOCIATION_TYPE_ID_HasMember);

    resp = getBQM().findAssociations(null, uuid1, null, associationTypes);
    JAXRUtility.checkBulkResponse(resp);

    Collection<?> coll = resp.getCollection();

    if (coll.size() != 0) {
        Iterator<?> iter = coll.iterator();

        while (iter.hasNext()) {
            Association ass = (Association) iter.next();

            System.err.println("Association: " + ass.getKey().getId() + "; sourceObject: "
                    + ass.getSourceObject().getKey().getId() + "; targetObject: "
                    + ass.getTargetObject().getKey().getId());
        }
    }

    assertEquals("uuid1 should not be the sourceObject in any HasMember associations.", 0, coll.size());

    objects = new ArrayList<Object>();
    objects.add(pkg1.getKey());
    objects.add(pkg2.getKey());
    if (coll.size() != 0) {
        Iterator<?> itr = coll.iterator();
        while (itr.hasNext()) {
            RegistryObject ro = (RegistryObject) itr.next();
            objects.add(ro.getKey());
        }
    }
    resp = getLCM().deleteObjects(objects);
    JAXRUtility.checkBulkResponse(resp);
}

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

public void addExternalLink(ExternalLink extLink) throws JAXRException {
    getExternalLinks();//from  w  w w. j  av  a2  s.c  om

    // If the external link is not in this object's in-memory-cache of
    // external links, add it.
    if (!(externalLinks.contains(extLink))) {
        // Check that an ExternallyLinks association exists between this
        // object and its external link.
        boolean associationExists = false;
        BusinessQueryManagerImpl bqm = (BusinessQueryManagerImpl) (lcm.getRegistryService()
                .getBusinessQueryManager());
        Concept assocType = bqm
                .findConceptByPath("/" + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_AssociationType
                        + "/" + BindingUtility.CANONICAL_ASSOCIATION_TYPE_CODE_ExternallyLinks);
        @SuppressWarnings("unchecked")
        Collection<Association> linkAssociations = extLink.getAssociations();

        if (linkAssociations != null) {
            Iterator<Association> assIter = linkAssociations.iterator();

            while (assIter.hasNext()) {
                Association ass = assIter.next();

                if (ass.getSourceObject().equals(extLink) && ass.getTargetObject().equals(this)
                        && ass.getAssociationType().equals(assocType)) {
                    associationExists = true;

                    break;
                }
            }
        }

        // Create the association between the external link and this object,
        // if necessary.
        if (!associationExists) {
            Association ass = lcm.createAssociation(this, assocType);
            extLink.addAssociation(ass);
        }

        externalLinks.add(extLink);

        // Note: There is no need to call setModified(true) since
        // the RIM modified object is an Association
    }
}

From source file:it.cnr.icar.eric.client.ui.swing.graph.JBGraph.java

/**
 * DOCUMENT ME!//from w ww  .j  av a  2s  .c o  m
 *
 * @param cell DOCUMENT ME!
 * @param ro DOCUMENT ME!
 *
 * @return ArrayList of GraphCell for the related objects.
 */
private ArrayList<Object> showRelatedObjects(JBGraphCell cell, RegistryObject ro) {
    ArrayList<Object> relatedCells = new ArrayList<Object>();

    if (ro == null) {
        return relatedCells;
    }

    try {
        CellView cellView = getView().getMapping(cell, false);
        Rectangle bounds = cellView.getBounds();

        //Classifications
        Collection<?> classifications = ro.getClassifications();
        DefaultGraphCell groupCell = createGroupFromObjectCollection(classifications);

        if (groupCell != null) {
            connectCells(cell, groupCell, "classifications", false);
            relatedCells.add(groupCell);
        }

        //ExternalIdentifiers
        Collection<?> extIds = ro.getExternalIdentifiers();
        groupCell = createGroupFromObjectCollection(extIds);

        if (groupCell != null) {
            connectCells(cell, groupCell, "externalIdentifiers", false);
            relatedCells.add(groupCell);
        }

        //ExternalLinks
        Collection<?> extLinks = ro.getExternalLinks();
        groupCell = createGroupFromObjectCollection(extLinks);

        if (groupCell != null) {
            connectCells(cell, groupCell, "externalLinks", false);
            relatedCells.add(groupCell);
        }

        /*
           //RegistryPackages
           try {
           Collection pkgs = ro.getRegistryPackages();
           Iterator iter = pkgs.iterator();
           while (iter.hasNext()) {
               RegistryPackage pkg = (RegistryPackage)iter.next();
               if (pkg != null) {
                   JBGraphCell newCell = addRelatedObject(cell, pkg, new Rectangle(0, 0, 50, 50), "HasMember", true);
                   relatedCells.add(newCell);
               }
           }
           } catch (UnsupportedCapabilityException e) {
           }
         **/

        try {
            //Associations
            Collection<?> assocs = ((RegistryObjectImpl) ro).getAllAssociations();
            Iterator<?> iter = assocs.iterator();

            while (iter.hasNext()) {
                Association assoc = (Association) iter.next();
                RegistryObject srcObj = assoc.getSourceObject();
                RegistryObject targetObj = assoc.getTargetObject();
                Concept concept = assoc.getAssociationType();

                String label = "associatedWith";

                if (concept != null) {
                    label = concept.getValue();
                }

                if ((srcObj != null) && (targetObj != null)) {
                    JBGraphCell newCell = null;

                    if (srcObj.getKey().getId().equalsIgnoreCase(ro.getKey().getId())) {
                        //ro is the source, newCell is the target
                        newCell = addRelatedObject(cell, targetObj,
                                new Rectangle(bounds.x + 100, bounds.y, 50, 50), label, false);
                    } else {
                        //ro is the target, newCell is the source
                        newCell = addRelatedObject(cell, srcObj,
                                new Rectangle(bounds.x + 100, bounds.y, 50, 50), label, true);
                    }

                    relatedCells.add(newCell);
                } else {
                    System.err.println(
                            "Invalid association. Source or target is null: " + assoc.getKey().getId());
                }
            }

        } catch (UnsupportedCapabilityException e) {
        }
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }

    return relatedCells;
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectCollectionBean.java

private List<RegistryObjectBean> getAssociationsSearchResultsBeans(RegistryObjectBean roBean)
        throws ClassNotFoundException, NoSuchMethodException, ExceptionInInitializerError, Exception {
    // The objectTypeRefs map is normally populated by a call to ro.getComposedObjects().
    // However, the getComposedObjects() method retrieves all composed objects for the 
    // inspected RO. In terms of Associations, only those where the RO is the source object 
    // are returned. In order to get all Associations, including those where the RO is the
    // target of an Association, you must call RegistryObjectImpl.getAllAssociations().
    Collection<RegistryObject> associations = ((RegistryObjectImpl) roBean.getRegistryObject())
            .getAllAssociations();/*from   www  .  j a  v  a  2 s . c  o  m*/
    // check if association is valid to list in association tab of
    // details panel.
    if (associations != null) {
        associations = this.filterValidAssociation(associations);
    }
    if (associations == null) {
        return null;
    }
    int numAssociations = associations.size();
    @SuppressWarnings("unused")
    ArrayList<Object> list = new ArrayList<Object>(numAssociations);

    Iterator<RegistryObject> roItr = associations.iterator();
    if (log.isDebugEnabled()) {
        log.debug("Query results: ");
    }

    String objectType = "Association";
    int numCols = 2;
    // Replace ObjectType with Id. TODO - formalize this convention
    List<RegistryObjectBean> roBeans = new ArrayList<RegistryObjectBean>(numAssociations);
    for (@SuppressWarnings("unused")
    int i = 0; roItr.hasNext(); i++) {
        Association association = (Association) roItr.next();
        String header = null;
        Object columnValue = null;
        @SuppressWarnings("unused")
        ArrayList<Object> srvbHeader = new ArrayList<Object>(numCols);
        ArrayList<SearchResultValueBean> searchResultValueBeans = new ArrayList<SearchResultValueBean>(numCols);

        header = WebUIResourceBundle.getInstance().getString("Details");
        columnValue = association.getKey().getId();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        header = WebUIResourceBundle.getInstance().getString("Source Object");
        columnValue = association.getSourceObject().getKey().getId();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        header = WebUIResourceBundle.getInstance().getString("Target Object");
        columnValue = association.getTargetObject().getKey().getId();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        header = WebUIResourceBundle.getInstance().getString("Type");
        columnValue = association.getAssociationType();
        searchResultValueBeans.add(new SearchResultValueBean(header, columnValue));

        RegistryObjectBean srb = new RegistryObjectBean(searchResultValueBeans, roBean.getRegistryObject(),
                objectType, association, false);
        roBeans.add(srb);
    }
    return roBeans;
}

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();
        PublisherAssertion pa = ScoutJaxrUddiHelper.getPubAssertionFromJAXRAssociation(association);
        sarr[currLoc] = pa;/*from  ww  w.  j  a v  a  2s.c o  m*/
        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();
        PublisherAssertion pa = ScoutJaxrUddiV3Helper.getPubAssertionFromJAXRAssociation(association);
        sarr[currLoc] = pa;/*from w  ww.ja v  a 2  s.c  o m*/
        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.util.ScoutJaxrUddiHelper.java

public static PublisherAssertion getPubAssertionFromJAXRAssociation(Association association)
        throws JAXRException {
    PublisherAssertion pa = objectFactory.createPublisherAssertion();
    try {//from w  w  w .j a v a  2s  .com
        if (association.getSourceObject().getKey() != null
                && association.getSourceObject().getKey().getId() != null) {
            pa.setFromKey(association.getSourceObject().getKey().getId());
        }

        if (association.getTargetObject().getKey() != null
                && association.getTargetObject().getKey().getId() != null) {
            pa.setToKey(association.getTargetObject().getKey().getId());
        }
        Concept c = association.getAssociationType();
        String v = c.getValue();
        KeyedReference kr = objectFactory.createKeyedReference();
        Key key = c.getKey();
        if (key == null) {
            // TODO:Need to check this. If the concept is a predefined
            // enumeration, the key can be the parent classification scheme
            key = c.getClassificationScheme().getKey();
        }
        if (key != null && key.getId() != null) {
            kr.setTModelKey(key.getId());
        }
        kr.setKeyName("Concept");

        if (v != null) {
            kr.setKeyValue(v);
        }

        pa.setKeyedReference(kr);
    } catch (Exception ud) {
        throw new JAXRException("Apache JAXR Impl:", ud);
    }
    return pa;
}