📄 jaxr3.html
字号:
// Find organizations that use this concept Collection specConcepts1 = new ArrayList(); specConcepts1.add(concept); br = bqm.findOrganizations(null, null, null, specConcepts1, null, null); // Display information about organizations ...}<a name="wp78207"> </a></pre></div><a name="wp77891"> </a><p class="pBody">If you find an organization that offers a service you wish to use, you can invoke the service using the JAX-RPC API.</p><a name="wp76394"> </a><h4 class="pHeading3">Finding Services and ServiceBindings</h4><a name="wp66373"> </a><p class="pBody">After a client has located an organization, it can find that organization's services and the service bindings associated with those services.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Iterator orgIter = orgs.iterator();while (orgIter.hasNext()) { Organization org = (Organization) orgIter.next(); Collection services = org.getServices(); Iterator svcIter = services.iterator(); while (svcIter.hasNext()) { Service svc = (Service) svcIter.next(); Collection serviceBindings = svc.getServiceBindings(); Iterator sbIter = serviceBindings.iterator(); while (sbIter.hasNext()) { ServiceBinding sb = (ServiceBinding) sbIter.next(); } }}<a name="wp68048"> </a></pre></div><a name="wp66325"> </a><h3 class="pHeading2">Managing Registry Data</h3><a name="wp64118"> </a><p class="pBody">If a client has authorization to do so, it can submit data to a registry, modify it, and remove it. It uses the <code class="cCode">BusinessLifeCycleManager</code> interface to perform these tasks.</p><a name="wp70769"> </a><p class="pBody">Registries usually allow a client to modify or remove data only if the data is being modified or removed by the same user who first submitted the data.</p><a name="wp115444"> </a><p class="pBody">Managing registry data involves the following tasks:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp115445"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp68356">Getting Authorization from the Registry</a></li></div><a name="wp115450"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp68373">Creating an Organization</a></li></div><a name="wp115455"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp68755">Adding Classifications</a></li></div><a name="wp115460"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp67394">Adding Services and Service Bindings to an Organization</a></li></div><a name="wp115465"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp68743">Publishing an Organization</a></li></div><a name="wp140679"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp140680">Publishing a Specification Concept</a></li></div><a name="wp115470"> </a><div class="pSmartList1"><li><a href="JAXR3.html#wp64166">Removing Data from the Registry</a></li></div></ul></div><a name="wp68356"> </a><h4 class="pHeading3">Getting Authorization from the Registry</h4><a name="wp68371"> </a><p class="pBody">Before it can submit data, the client must send its user name and password to the registry in a set of credentials. The following code fragment shows how to do this.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">String username = "myUserName";String password = "myPassword";// Get authorization from the registryPasswordAuthentication passwdAuth = new PasswordAuthentication(username, password.toCharArray());Set creds = new HashSet();creds.add(passwdAuth);connection.setCredentials(creds);<a name="wp68377"> </a></pre></div><a name="wp68373"> </a><h4 class="pHeading3">Creating an Organization</h4><a name="wp68541"> </a><p class="pBody">The client creates the organization and populates it with data before publishing it.</p><a name="wp66569"> </a><p class="pBody">An <code class="cCode">Organization</code> object is one of the more complex data items in the JAXR API. It normally includes the following:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp66572"> </a><div class="pSmartList1"><li>A <code class="cCode">Name</code> object</li></div><a name="wp66615"> </a><div class="pSmartList1"><li>A <code class="cCode">Description</code> object</li></div><a name="wp66616"> </a><div class="pSmartList1"><li>A <code class="cCode">Key</code> object, representing the ID by which the organization is known to the registry. This key is created by the registry, not by the user, and is returned after the organization is submitted to the registry.</li></div><a name="wp66617"> </a><div class="pSmartList1"><li>A <code class="cCode">PrimaryContact</code> object, which is a <code class="cCode">User</code> object that refers to an authorized user of the registry. A <code class="cCode">User</code> object normally includes a <code class="cCode">PersonName</code> object and collections of <code class="cCode">TelephoneNumber</code>, <code class="cCode">EmailAddress</code>, and/or <code class="cCode">PostalAddress</code> objects.</li></div><a name="wp66582"> </a><div class="pSmartList1"><li>A collection of <code class="cCode">Classification</code> objects</li></div><a name="wp67402"> </a><div class="pSmartList1"><li><code class="cCode">Service</code> objects and their associated <code class="cCode">ServiceBinding</code> objects</li></div></ul></div><a name="wp66598"> </a><p class="pBody">For example, the following code fragment creates an organization and specifies its name, description, and primary contact. When a client creates an organization, it does not include a key; the registry returns the new key when it accepts the newly created organization. The <code class="cCode">blcm</code> object in this code fragment is the <code class="cCode">BusinessLifeCycleManager</code> object returned in <a href="JAXR3.html#wp84847">Obtaining and Using a RegistryService Object</a>. An <code class="cCode">InternationalString</code> object is used for string values that may need to be localized.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">// Create organization name and descriptionOrganization org = blcm.createOrganization("The Coffee Break");InternationalString s = blcm.createInternationalString("Purveyor of " + "the finest coffees. Established 1914");org.setDescription(s);// Create primary contact, set nameUser primaryContact = blcm.createUser();PersonName pName = blcm.createPersonName("Jane Doe");primaryContact.setPersonName(pName);// Set primary contact phone numberTelephoneNumber tNum = blcm.createTelephoneNumber();tNum.setNumber("(800) 555-1212");Collection phoneNums = new ArrayList();phoneNums.add(tNum);primaryContact.setTelephoneNumbers(phoneNums);// Set primary contact email addressEmailAddress emailAddress = blcm.createEmailAddress("jane.doe@TheCoffeeBreak.com");Collection emailAddresses = new ArrayList();emailAddresses.add(emailAddress);primaryContact.setEmailAddresses(emailAddresses);// Set primary contact for organizationorg.setPrimaryContact(primaryContact);<a name="wp68543"> </a></pre></div><a name="wp68755"> </a><h4 class="pHeading3">Adding Classifications</h4><a name="wp68756"> </a><p class="pBody">Organizations commonly belong to one or more classifications based on one or more classification schemes (taxonomies). To establish a classification for an organization using a taxonomy, the client first locates the taxonomy it wants to use. It uses the <code class="cCode">BusinessQueryManager</code> to find the taxonomy. The <code class="cCode">findClassificationSchemeByName</code> method takes a set of <code class="cCode">FindQualifier</code> objects as its first argument, but this argument can be null.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">// Set classification scheme to NAICSClassificationScheme cScheme = bqm.findClassificationSchemeByName(null, "ntis-gov:naics");<a name="wp68565"> </a></pre></div><a name="wp86142"> </a><p class="pBody">The client then creates a classification using the classification scheme and a concept (a taxonomy element) within the classification scheme. For example, the following code sets up a classification for the organization within the NAICS taxonomy. The second and third arguments of the <code class="cCode">createClassification</code> method are the name and value of the concept.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">// Create and add classificationClassification classification = blcm.createClassification(cScheme, "Snack and Nonalcoholic Beverage Bars", "722213");Collection classifications = new ArrayList();classifications.add(classification);org.addClassifications(classifications);<a name="wp86141"> </a></pre></div><a name="wp68563"> </a><p class="pBody">Services also use classifications, so you can use similar code to add a classification to a <code class="cCode">Service</code> object.</p><a name="wp67394"> </a><h4 class="pHeading3">Adding Services and Service Bindings to an Organization</h4><a name="wp64128"> </a><p class="pBody">Most organizations add themselves to a registry in order to offer services, so the JAXR API has facilities to add services and service bindings to an organization. </p><a name="wp67364"> </a><p class="pBody">Like an <code class="cCode">Organization</code> object, a <code class="cCode">Service</code> object has a name and a description. Also like an <code class="cCode">Organization</code> object, it has a unique key that is generated by the registry when the service is registered. It may also have classifications associated with it. </p><a name="wp71103"> </a><p class="pBody">A service also commonly has service bindings, which provide information about how to access the service. A <code class="cCode">ServiceBinding</code> object normally has a description, an access URI, and a specification link, which provides the linkage between a service binding and a technical specification that describes how to use the service using the service binding.</p><a name="wp71131"> </a><p class="pBody">The following code fragment shows how to create a collection of services, add service bindings to a service, then add the services to the organization. It specifies an access URI but not a specification link. Because the access URI is not real and because JAXR by default checks for the validity of any published URI, the binding sets its <code class="cCode">validateURI</code> property to false.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">// Create services and serviceCollection services = new ArrayList();Service service = blcm.createService("My Service Name");InternationalString is = blcm.createInternationalString("My Service Description");service.setDescription(is);// Create service bindingsCollection serviceBindings = new ArrayList();ServiceBinding binding = blcm.createServiceBinding();is = blcm.createInternationalString("My Service Binding " + "Description");binding.setDescription(is);// allow us to publish a bogus URL without an errorbinding.setValidateURI(false);binding.setAccessURI("http://TheCoffeeBreak.com:8080/sb/");serviceBindings.add(binding);// Add service bindings to serviceservice.addServiceBindings(serviceBindings);// Add service to services, then add services to organizationservices.add(service);org.addServices(services);<a name="wp85439"> </a></pre></div><a name="wp68743"> </a><h4 class="pHeading3">Publishing an Organization</h4><a name="wp68750"> </a><p class="pBody">The primary method a client uses to add or modify organization data is the <code class="cCode">saveOrganizations</code> method, which creates one or more new organizations in a registry if they did not exist previously. If one of the organizations exists but some of the data have changed, the <code class="cCode">saveOrganizations</code> method updates and replaces the data.</p><a name="wp68763"> </a><p class="pBody">After a client populates an organization with the information it wants to make public, it saves the organization. The registry returns the key in its response, and the client retrieves it.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">// Add organization and submit to registry// Retrieve key if successfulCollection orgs = new ArrayList();orgs.add(org);BulkResponse response = blcm.saveOrganizations(orgs);Collection exceptions = response.getException();if (exceptions == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -