To search for objects by name, you normally use a combination of find qualifiers and name patterns. Find qualifiers affect sorting and pattern matching. Name patterns specify the strings to be searched. The BusinessQueryManagerImpl.findObjects method takes a collection of FindQualifier objects as its second argument and takes a collection of name patterns as its third argument. The method signature is as follows:
public BulkResponse findObjects(java.lang.String objectType, java.util.Collection findQualifiers, java.util.Collection namePatterns, java.util.Collection classifications, java.util.Collection specifications, java.util.Collection externalIdentifiers, java.util.Collection externalLinks) throws JAXRException
For the first argument, the object type, you normally specify one of a set of string constants that are defined in the LifeCycleManager interface.
You can use wildcards in a name pattern. Use percent signs (%) to specify that the search string occurs at the beginning, middle, or end of the object name. Here are some examples:
Specify nor% to return strings that start with Nor or nor, such as North and northern.
Specify %off% to return strings that contain the string off, such as Coffee.
Specify %ica to return strings that end with ica, such as America.
You can also use an underscore (_) as a wildcard to match a single character. For example, the search string _us_ would match objects named Aus1 and Bus3.
For example, the following code fragment finds all the organizations in the Registry whose names begin with a specified string, searchString, and sorts them in alphabetical order.
// Define find qualifiers and name patterns Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC); Collection namePatterns = new ArrayList(); namePatterns.add(searchString + "%"); // Find organizations with name that starts with searchString BulkResponse response = bqm.findObjects("Organization", findQualifiers, namePatterns, null, null, null, null); Collection orgs = response.getCollection();
The findObjects method is not case-sensitive, unless you specify FindQualifier.CASE_SENSITIVE_MATCH. In the previous fragment, the first argument could be either "Organization" or "organization", and the name pattern matches names regardless of case.
The following code fragment performs a case-sensitive search for all registry objects whose names contain the string searchString and sorts the objects in alphabetical order.
Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC); Collection namePatterns = new ArrayList(); namePatterns.add("%" + searchString + "%"); // Find objects with name that contains searchString BulkResponse response = bqm.findObjects("RegistryObject", findQualifiers, namePatterns, null, null, null, null); Collection objects = response.getCollection();
To locate a particular object, search by unique identifier if possible. Searching by name is less efficient and more likely to lead to errors, since names are not unique.
For an example of finding objects by name, see JAXRSearchByName.java in the directory install/registry-samples/search-name/src.
Go to the directory install/registry-samples/search-name.
Type the following command, specifying a string value:
Ant-base/ant run -Dname=string |
The program performs a case-insensitive search, returning all objects whose names contain the specified string. The program also displays the object’s classifications, external identifiers, external links, slots, and audit trail.
For example, if you specify the argument ebxml, the output of the run target looks something like this
run: [java] Name string is ebxml [java] Query URL is http://localhost:6480/soar/registry/soap [java] Created connection to registry [java] Got registry service and query manager [java] Object type is Federation [java] Object name: freebXMLRegistryFederation [java] Object description: freebXML Registry Federation [java] Object key id: urn:uuid:cb5039c1-85b2-4512-839a-893cb882c981 [java] Object version: 1.1 [java] freebXMLRegistryFederation created 2007-07-13 15:43:11.0 [java] --- [java] Object type is Organization [java] Object name: freebXMLRegistry [java] Object description: freebXML Registry [java] Object key id: urn:freebxml:registry:Organization:freebXMLRegistry [java] Object version: 1.1 [java] freebXMLRegistry created 2007-07-13 15:43:11.0 [java] --- [java] Object type is Registry [java] Object name: freebXMLRegistry [java] Object description: freebXML Registry [java] Object key id: urn:uuid:e3f4eef0-7144-49a9-a791-8a1ff5b3b916 [java] Object version: 1.1 [java] freebXMLRegistry updated 2007-07-13 15:43:11.0 [java] freebXMLRegistry created 2007-07-13 15:43:11.0 [java] --- |