001: package org.apache.ws.scout;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006:
007: import javax.xml.registry.BulkResponse;
008: import javax.xml.registry.BusinessLifeCycleManager;
009: import javax.xml.registry.JAXRException;
010: import javax.xml.registry.JAXRResponse;
011: import javax.xml.registry.infomodel.Association;
012: import javax.xml.registry.infomodel.Classification;
013: import javax.xml.registry.infomodel.ClassificationScheme;
014: import javax.xml.registry.infomodel.Concept;
015: import javax.xml.registry.infomodel.EmailAddress;
016: import javax.xml.registry.infomodel.InternationalString;
017: import javax.xml.registry.infomodel.Organization;
018: import javax.xml.registry.infomodel.PersonName;
019: import javax.xml.registry.infomodel.PostalAddress;
020: import javax.xml.registry.infomodel.RegistryObject;
021: import javax.xml.registry.infomodel.Service;
022: import javax.xml.registry.infomodel.ServiceBinding;
023: import javax.xml.registry.infomodel.TelephoneNumber;
024: import javax.xml.registry.infomodel.User;
025:
026: /**
027: * Creator for JAXR Registry Objects to faciliate the writing of unittests.
028: *
029: * @author kstam
030: *
031: */
032: public class Creator {
033:
034: BusinessLifeCycleManager blm;
035: public static String ORGANIZATION_NAME = "TestOrganization";
036:
037: public Creator(BusinessLifeCycleManager blm) {
038: super ();
039: this .blm = blm;
040: }
041:
042: /**
043: * Creates a JAXR Organization.
044: *
045: * @return JAXR Organization
046: * @throws JAXRException
047: */
048: protected InternationalString getIString(String str)
049: throws JAXRException {
050: return blm.createInternationalString(str);
051: }
052:
053: /**
054: * Creates an dummy organization.
055: *
056: * @return JAXR Organization
057: * @throws JAXRException
058: */
059: public Organization createOrganization(String name)
060: throws JAXRException {
061: Organization org = blm.createOrganization(getIString(name));
062: org.setDescription(getIString(name + ":description"));
063: User user = blm.createUser();
064: org.setPrimaryContact(user);
065: PersonName personName = blm.createPersonName("John AXel Rose");
066: TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
067: telephoneNumber.setNumber("111-222-333");
068: telephoneNumber.setType(null);
069: PostalAddress address = blm.createPostalAddress("1",
070: "UDDI Drive", "Apache Town", "OS", "USA", "00000-1111",
071: "");
072:
073: Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
074: postalAddresses.add(address);
075: Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
076: EmailAddress emailAddress = blm
077: .createEmailAddress("jaxr@apache.org");
078: emailAddresses.add(emailAddress);
079:
080: Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
081: numbers.add(telephoneNumber);
082: user.setPersonName(personName);
083: user.setPostalAddresses(postalAddresses);
084: user.setEmailAddresses(emailAddresses);
085: user.setTelephoneNumbers(numbers);
086:
087: return org;
088: }
089:
090: /**
091: * Creates a dummy Service.
092: *
093: * @return JAXR Service
094: * @throws JAXRException
095: */
096: public Service createService(String name) throws JAXRException {
097: Service service = blm.createService(getIString(name));
098: service
099: .setDescription(getIString("Test Services of UDDI Registry"));
100: return service;
101: }
102:
103: /**
104: * Creates a dummy ServiceBinding.
105: *
106: * @return JAXR ServiceBinding
107: * @throws JAXRException
108: */
109: public ServiceBinding createServiceBinding() throws JAXRException {
110: ServiceBinding serviceBinding = blm.createServiceBinding();
111: serviceBinding
112: .setName(blm
113: .createInternationalString("JBossESB Test ServiceBinding"));
114: serviceBinding.setDescription(blm
115: .createInternationalString("Binding Description"));
116: serviceBinding
117: .setAccessURI("http://www.jboss.com/services/TestService");
118: return serviceBinding;
119: }
120:
121: /**
122: * Creates a dummy Classification Scheme.
123: *
124: * @return JAXR ClassificationScheme
125: * @throws JAXRException
126: */
127: public ClassificationScheme createClassificationScheme(String name)
128: throws JAXRException {
129: ClassificationScheme cs = blm.createClassificationScheme(
130: getIString(name), getIString(""));
131: return cs;
132: }
133:
134: /**
135: * Creates a Classficiation for the default dummy classificationScheme.
136: *
137: * @param classificationScheme
138: * @return
139: * @throws JAXRException
140: */
141: public Classification createClassification(
142: ClassificationScheme classificationScheme)
143: throws JAXRException {
144: Classification classification = blm.createClassification(
145: classificationScheme,
146: "Java Api for Xml Registries Services", "1234");
147: return classification;
148: }
149:
150: /**
151: * Creates an association.
152: * @param type association type
153: * @param registryObject to which the association is built
154: * @throws JAXRException
155: */
156: public void createAssociation(Concept type,
157: RegistryObject registryObject) throws JAXRException {
158: Association association = blm.createAssociation(registryObject,
159: type);
160:
161: ArrayList<Association> associations = new ArrayList<Association>();
162: associations.add(association);
163:
164: BulkResponse br = blm.saveAssociations(associations, true);
165: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
166: System.out.println("Association Saved");
167: Collection coll = br.getCollection();
168: Iterator iter = coll.iterator();
169: while (iter.hasNext()) {
170: System.out.println("Saved Key=" + iter.next());
171: }// end while
172: } else {
173: System.err.println("JAXRExceptions "
174: + "occurred during save:");
175: Collection exceptions = br.getExceptions();
176: Iterator iter = exceptions.iterator();
177: while (iter.hasNext()) {
178: Exception e = (Exception) iter.next();
179: System.err.println(e.toString());
180: }
181: }
182: }
183:
184: }
|