List of usage examples for javax.xml.registry.infomodel RegistryPackage addRegistryObject
void addRegistryObject(RegistryObject registryObject) throws JAXRException;
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./* www . j av a2s. co 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.admin.function.Cp.java
/** * Load the contents of baseDir into rp using pathname as base for * locators of loaded objects./*from ww w .j a va 2s. c o m*/ * * @param baseDir Directory in local file system from which to load * @param rp Existing RegistryPackage to which to add */ protected void scanDir(File baseDir, RegistryPackage rootRP) throws Exception { ArrayList<RegistryObject> repositoryObjects = new ArrayList<RegistryObject>(); LinkedList<DirInfo> dirInfoList = new LinkedList<DirInfo>(); dirInfoList.add(new DirInfo(baseDir, rootRP)); /* * Loop through the list of directories (and corresponding * RegistryPackages and pathnames). Child directories of * curDir are added to the end of the list, so the list isn't * finished until all descendant directories have been * processed. */ while (!dirInfoList.isEmpty()) { DirInfo curDirInfo = dirInfoList.removeFirst(); File curDir = curDirInfo.getDir(); RegistryPackage curRP = curDirInfo.getRegistryPackage(); if (!curDir.exists()) { throw new AdminException(format(rb, "nonexistentLocalDir", new Object[] { curDir })); } if (!curDir.isDirectory()) { throw new AdminException(format(rb, "nondirectoryLocalDir", new Object[] { curDir })); } if (!curDir.canRead()) { throw new AdminException(format(rb, "unreadableLocalDir", new Object[] { curDir })); } File[] childFiles = curDir.listFiles(); for (int i = 0; i < childFiles.length; i++) { String childName = childFiles[i].getName(); boolean canInclude = checkIncludesExcludes(childName); RegistryObject childObject; if (!canInclude) { if (verbose || debug) { context.printMessage(format(rb, "notIncluding", new Object[] { childFiles[i] })); } continue; } if (childFiles[i].isFile()) { if (verbose || debug) { context.printMessage(format(rb, "including", new Object[] { "ExtrinsicObject", childFiles[i], childName })); } childObject = context.getService().createExtrinsicObject(childFiles[i]); } else if (childFiles[i].isDirectory()) { if (verbose || debug) { context.printMessage(format(rb, "including", new Object[] { "RegistryPackage", childFiles[i], childName })); } childObject = context.getService().createRegistryPackage(childName); dirInfoList.addLast(new DirInfo(childFiles[i], (RegistryPackage) childObject)); } else { childObject = null; throw new AdminException(format(rb, "notFileOrDir", new Object[] { childFiles[i] })); } if (curRP != null) { curRP.addRegistryObject(childObject); } repositoryObjects.add(childObject); } } if (!repositoryObjects.isEmpty()) { if (rootRP != null) { repositoryObjects.add(rootRP); } BulkResponse response = ((LifeCycleManagerImpl) context.getService().getLCM()) .saveObjects(repositoryObjects, saveObjectsSlots); JAXRUtility.checkBulkResponse(response); } }