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

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

Introduction

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

Prototype

RegistryObject getTargetObject() throws JAXRException;

Source Link

Document

Gets the Object that is the target 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.  jav  a2  s  .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 removeExternalLink(ExternalLink extLink) throws JAXRException {
    getExternalLinks();//w  w w  . j  av  a  2  s . co  m

    if (externalLinks.contains(extLink)) {
        externalLinks.remove(extLink);

        //Now remove the ExternallyLinks association that has extLink as src and this object as target
        // We make a copy of this.externalLinks to avoid a
        // concurrent modification exception in the removeExternalLinks
        @SuppressWarnings("unchecked")
        Collection<Association> linkAssociations = new ArrayList<Association>(extLink.getAssociations());

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

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

                if (ass.getTargetObject().equals(this)) {
                    if (ass.getAssociationType().getValue()
                            .equalsIgnoreCase(BindingUtility.CANONICAL_ASSOCIATION_TYPE_ID_ExternallyLinks)) {
                        extLink.removeAssociation(ass);
                    }
                }
            }
        }

        //No need to call setModified(true) since RIM modified object is an Assoociation
        //setModified(true);
    }
}

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

@SuppressWarnings("unchecked")
public Collection<RegistryObject> getAssociatedObjects() throws JAXRException {
    Collection<RegistryObject> assObjects = null;
    if (isNew()) {
        assObjects = new ArrayList<RegistryObject>();
        if (associations != null) {
            Iterator<Association> iter = associations.iterator();
            while (iter.hasNext()) {
                Association ass = iter.next();
                assObjects.add(ass.getTargetObject());
            }//  w  ww  .  ja  v  a2  s.c om
        }
    } else {
        String id = getKey().getId();
        //            String queryStr = "SELECT ro.* FROM RegistryObject ro, Association ass WHERE ass.sourceObject = '" +
        //                id + "' AND ass.targetObject = ro.id";
        //            Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

        Query query = SQLQueryProvider.getAssociatedObjects(dqm, id);

        BulkResponse response = dqm.executeQuery(query);
        checkBulkResponseExceptions(response);
        assObjects = response.getCollection();
    }

    return assObjects;
}

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

public void addExternalLink(ExternalLink extLink) throws JAXRException {
    getExternalLinks();/* w w w  .j  ava  2  s  .  com*/

    // 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  a v a2s .  co 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  w ww . j ava2  s .  c om*/
    // 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.util.ScoutJaxrUddiHelper.java

public static PublisherAssertion getPubAssertionFromJAXRAssociation(Association association)
        throws JAXRException {
    PublisherAssertion pa = objectFactory.createPublisherAssertion();
    try {/* w w w .j av a2s  .c o  m*/
        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;
}