001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout;
017:
018: import java.util.Collection;
019: import java.util.Iterator;
020:
021: import javax.xml.registry.JAXRException;
022: import javax.xml.registry.infomodel.Classification;
023: import javax.xml.registry.infomodel.Concept;
024: import javax.xml.registry.infomodel.EmailAddress;
025: import javax.xml.registry.infomodel.ExternalLink;
026: import javax.xml.registry.infomodel.Organization;
027: import javax.xml.registry.infomodel.PersonName;
028: import javax.xml.registry.infomodel.RegistryObject;
029: import javax.xml.registry.infomodel.Service;
030: import javax.xml.registry.infomodel.ServiceBinding;
031: import javax.xml.registry.infomodel.TelephoneNumber;
032: import javax.xml.registry.infomodel.User;
033:
034: /**
035: * Print out code for Registry Objects
036: * @author <mailto:kstam@apache.org>Kurt Stam
037: */
038: public class Printer {
039:
040: public void printOrganisation(Organization org)
041: throws JAXRException {
042: System.out.println("Org name: " + getName(org));
043: System.out.println("Org description: " + getDescription(org));
044: System.out.println("Org key id: " + getKey(org));
045: printUser(org);
046: printServices(org);
047: printClassifications(org);
048: }
049:
050: public void printServices(Organization org) throws JAXRException {
051: // Display service and binding information
052: Collection services = org.getServices();
053: for (Iterator svcIter = services.iterator(); svcIter.hasNext();) {
054: Service svc = (Service) svcIter.next();
055: System.out.println(" Service name: " + getName(svc));
056: System.out.println(" Service description: "
057: + getDescription(svc));
058: Collection serviceBindings = svc.getServiceBindings();
059: for (Iterator sbIter = serviceBindings.iterator(); sbIter
060: .hasNext();) {
061: ServiceBinding sb = (ServiceBinding) sbIter.next();
062: System.out.println(" Binding Description: "
063: + getDescription(sb));
064: System.out
065: .println(" Access URI: " + sb.getAccessURI());
066: }
067: }
068: }
069:
070: public void printUser(Organization org) throws JAXRException {
071: // Display primary contact information
072: User pc = org.getPrimaryContact();
073: if (pc != null) {
074: PersonName pcName = pc.getPersonName();
075: System.out
076: .println(" Contact name: " + pcName.getFullName());
077: Collection phNums = pc.getTelephoneNumbers(pc.getType());
078: for (Iterator phIter = phNums.iterator(); phIter.hasNext();) {
079: TelephoneNumber num = (TelephoneNumber) phIter.next();
080: System.out
081: .println(" Phone number: " + num.getNumber());
082: }
083: Collection eAddrs = pc.getEmailAddresses();
084: for (Iterator eaIter = eAddrs.iterator(); eaIter.hasNext();) {
085: System.out.println(" Email Address: "
086: + (EmailAddress) eaIter.next());
087: }
088: }
089: }
090:
091: public void printExternalLinks(Concept concept)
092: throws JAXRException {
093: Collection links = concept.getExternalLinks();
094: for (Iterator lnkIter = links.iterator(); lnkIter.hasNext();) {
095: System.out.println("Link: "
096: + ((ExternalLink) lnkIter.next()).getExternalURI()
097: .charAt(0));
098: }
099: }
100:
101: public String getName(RegistryObject ro) throws JAXRException {
102: if (ro != null && ro.getName() != null) {
103: return ro.getName().getValue();
104: }
105: return "";
106: }
107:
108: public String getDescription(RegistryObject ro)
109: throws JAXRException {
110: if (ro != null && ro.getDescription() != null) {
111: return ro.getDescription().getValue();
112: }
113: return "";
114: }
115:
116: public String getKey(RegistryObject ro) throws JAXRException {
117: if (ro != null && ro.getKey() != null) {
118: return ro.getKey().getId();
119: }
120: return "";
121: }
122:
123: public void printClassifications(Organization ro)
124: throws JAXRException {
125: Collection c = ro.getClassifications();
126: Iterator i = c.iterator();
127:
128: System.out
129: .println("Classification: " + ro.getClassifications());
130: while (i.hasNext()) {
131: Classification cl = (Classification) i.next();
132: System.out.println("Classification: " + cl.getName());
133: }
134: }
135:
136: }
|