This project has retired. For details please refer to its Attic page.
Creator xref
View Javadoc
1   package org.apache.ws.scout;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.Iterator;
6   
7   import javax.xml.registry.BulkResponse;
8   import javax.xml.registry.BusinessLifeCycleManager;
9   import javax.xml.registry.JAXRException;
10  import javax.xml.registry.JAXRResponse;
11  import javax.xml.registry.infomodel.Association;
12  import javax.xml.registry.infomodel.Classification;
13  import javax.xml.registry.infomodel.ClassificationScheme;
14  import javax.xml.registry.infomodel.Concept;
15  import javax.xml.registry.infomodel.EmailAddress;
16  import javax.xml.registry.infomodel.InternationalString;
17  import javax.xml.registry.infomodel.Organization;
18  import javax.xml.registry.infomodel.PersonName;
19  import javax.xml.registry.infomodel.PostalAddress;
20  import javax.xml.registry.infomodel.RegistryObject;
21  import javax.xml.registry.infomodel.Service;
22  import javax.xml.registry.infomodel.ServiceBinding;
23  import javax.xml.registry.infomodel.TelephoneNumber;
24  import javax.xml.registry.infomodel.User;
25  
26  /**
27   * Creator for JAXR Registry Objects to faciliate the writing of unittests.
28   * 
29   * @author kstam
30   *
31   */
32  public class Creator {
33      
34      BusinessLifeCycleManager blm;
35      public static String ORGANIZATION_NAME = "TestOrganization";
36      
37      public Creator(BusinessLifeCycleManager blm) {
38          super();
39          this.blm = blm;
40      }
41      /**
42       * Creates a JAXR Organization.
43       * 
44       * @return JAXR Organization
45       * @throws JAXRException
46       */
47      protected InternationalString getIString(String str)
48      throws JAXRException
49      {
50          return blm.createInternationalString(str);
51      }
52      /**
53       * Creates an dummy organization.
54       * 
55       * @return JAXR Organization
56       * @throws JAXRException
57       */
58      public Organization createOrganization(String name) throws JAXRException
59      {
60          Organization org = blm.createOrganization(getIString(name));
61          org.setDescription(getIString(name + ":description"));
62          User user = blm.createUser();
63          org.setPrimaryContact(user);
64          PersonName personName = blm.createPersonName("John AXel Rose");
65          TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
66          telephoneNumber.setNumber("111-222-3333");
67          telephoneNumber.setType(null);
68          PostalAddress address = blm.createPostalAddress("1",
69              "Uddi Drive", "Apache Town","CA", "USA", "00000-1111", "");
70          
71          Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
72          postalAddresses.add(address);
73          Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
74          EmailAddress emailAddress = blm.createEmailAddress("jaxr@apache.org");
75          emailAddresses.add(emailAddress);
76          
77          Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
78          numbers.add(telephoneNumber);
79          user.setPersonName(personName);
80          user.setPostalAddresses(postalAddresses);
81          user.setEmailAddresses(emailAddresses);
82          user.setTelephoneNumbers(numbers);
83          
84          return org;
85      }
86      /**
87       * Creates a dummy Service.
88       * 
89       * @return JAXR Service
90       * @throws JAXRException
91       */
92      public Service createService(String name) throws JAXRException
93      {
94          Service service = blm.createService(getIString(name));
95          service.setDescription(getIString("Test Services of UDDI Registry"));
96          return service;
97      }
98      /**
99       * Creates a dummy ServiceBinding.
100      * 
101      * @return JAXR ServiceBinding
102      * @throws JAXRException
103      */
104     public ServiceBinding createServiceBinding() throws JAXRException 
105     {
106         ServiceBinding serviceBinding = blm.createServiceBinding();
107         serviceBinding.setName(blm.createInternationalString("JBossESB Test ServiceBinding"));
108         serviceBinding.setDescription(blm.createInternationalString("Binding Description"));
109         serviceBinding.setAccessURI("http://www.jboss.com/services/TestService");
110         return serviceBinding;
111     }
112     /**
113      * Creates a dummy Classification Scheme.
114      * 
115      * @return JAXR ClassificationScheme
116      * @throws JAXRException
117      */
118     public ClassificationScheme createClassificationScheme(String name) throws JAXRException
119     {
120         ClassificationScheme cs = blm.createClassificationScheme(getIString(name),
121                 getIString(""));
122         return cs;
123     }
124     /**
125      * Creates a Classficiation for the default dummy classificationScheme.
126      * 
127      * @param classificationScheme
128      * @return JAXR Classification
129      * @throws JAXRException
130      */
131     public Classification createClassification(ClassificationScheme classificationScheme) throws JAXRException
132     {
133         Classification classification = blm.createClassification(classificationScheme,
134                 "Java Api for Xml Registries Services","1234");
135         return classification;
136     }
137     /**
138      * Creates an association.
139      * @param type association type
140      * @param registryObject to which the association is built
141      * @throws JAXRException
142      */
143     public void createAssociation(Concept type, RegistryObject registryObject)
144     throws JAXRException 
145     {
146     Association association = blm.createAssociation(registryObject, type);
147     
148     ArrayList<Association> associations = new ArrayList<Association>();
149     associations.add(association);
150     
151     BulkResponse br = blm.saveAssociations(associations, true);
152     if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
153         System.out.println("Association Saved");
154         Collection coll = br.getCollection();
155         Iterator iter = coll.iterator();
156         while (iter.hasNext()) {
157             System.out.println("Saved Key=" + iter.next());
158         }// end while
159     } else {
160         System.err.println("JAXRExceptions " + "occurred during save:");
161         Collection exceptions = br.getExceptions();
162         Iterator iter = exceptions.iterator();
163         while (iter.hasNext()) {
164             Exception e = (Exception) iter.next();
165             System.err.println(e.toString());
166         }
167     }
168 }
169     
170     
171 
172    
173 }