This project has retired. For details please refer to its Attic page.
ServiceImpl xref
View Javadoc
1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.ws.scout.registry.infomodel;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  
23  import javax.xml.registry.BusinessQueryManager;
24  import javax.xml.registry.JAXRException;
25  import javax.xml.registry.LifeCycleManager;
26  import javax.xml.registry.RegistryService;
27  import javax.xml.registry.UnexpectedObjectException;
28  import javax.xml.registry.infomodel.Organization;
29  import javax.xml.registry.infomodel.Service;
30  import javax.xml.registry.infomodel.ServiceBinding;
31  
32  /**
33   * Implements JAXR Interface.
34   * For futher details, look into the JAXR API Javadoc.
35   *
36   * @author Anil Saldhana  <anil@apache.org>
37   */
38  public class ServiceImpl extends RegistryEntryImpl implements Service
39  {
40  
41      private Organization org = null;
42      private Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
43      private String orgKey = null;
44      
45      /**
46       * Creates a new instance of ServiceImpl
47       */
48      public ServiceImpl(LifeCycleManager lifeCycleManager)
49      {
50          super(lifeCycleManager);
51      }
52  
53      public void addServiceBinding(ServiceBinding sb)
54              throws JAXRException
55      {
56          serviceBindings.add(sb);
57          ((ServiceBindingImpl)sb).setService(this);
58      }
59  
60      public void addServiceBindings(Collection col)
61              throws JAXRException
62      {
63         try{
64          Iterator iter = col.iterator();
65          while(iter.hasNext())
66          {
67              addServiceBinding((ServiceBinding)iter.next());
68          }
69         }catch(ClassCastException ce)
70         {
71             throw new UnexpectedObjectException(ce.getLocalizedMessage());
72         }
73      }
74  
75      public Organization getProvidingOrganization()
76              throws JAXRException
77      {
78          if (org == null) {
79          	if (super.getSubmittingOrganization() != null) {
80          		return super.getSubmittingOrganization();
81          	} else {
82          		RegistryService rs = super.getLifeCycleManager().getRegistryService();
83          		BusinessQueryManager bqm = rs.getBusinessQueryManager();
84          		if (orgKey==null) return null;
85                  Organization o = (Organization) bqm.getRegistryObject(orgKey,
86                          LifeCycleManager.ORGANIZATION);
87                  setProvidingOrganization(o);	
88                  return o;
89          	}
90          }
91          return org;
92      }
93  
94      public Collection getServiceBindings() throws JAXRException
95      {
96          return serviceBindings;
97      }
98  
99      public void removeServiceBinding(ServiceBinding serviceBinding)
100             throws JAXRException
101     {
102         serviceBindings.remove(serviceBinding);
103     }
104 
105     public void removeServiceBindings(Collection collection)
106             throws JAXRException
107     {
108         serviceBindings.removeAll(collection);
109     }
110 
111     public void setProvidingOrganization(Organization organization)
112             throws JAXRException
113     {
114         this.org = organization;
115     }
116     
117     public void setSubmittingOrganizationKey(String key) {
118     	orgKey = key;
119     }
120     
121     public String getSubmittingOrganizationKey() {
122     	return orgKey;
123     }   
124 }