1   /*
2    * Copyright 2000-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.wsrp4j.consumer.driver;
18  
19  import oasis.names.tc.wsrp.v1.types.PortletContext;
20  
21  import org.apache.wsrp4j.consumer.PortletKey;
22  import org.apache.wsrp4j.consumer.WSRPPortlet;
23  import org.apache.wsrp4j.util.StateChangedServiceImpl;
24  
25  /**
26   * Implements the portlet interface
27   **/
28  public class WSRPPortletImpl extends StateChangedServiceImpl implements
29          WSRPPortlet {
30  
31      private PortletKey portletKey = null;
32  
33      private PortletContext portletContext = null;
34  
35      private String parentHandle = null;
36  
37      // for castor persistence
38      public WSRPPortletImpl() {
39      }
40  
41      public WSRPPortletImpl(PortletKey portletKey) {
42          this.portletKey = portletKey;
43          this.parentHandle = portletKey.getPortletHandle();
44      }
45  
46      public PortletKey getPortletKey() {
47          return this.portletKey;
48      }
49  
50      public void setPortletKey(PortletKey portletKey) {
51          if (portletKey != null) {
52              this.portletKey = portletKey;
53  
54              if (this.portletContext != null) {
55                  this.portletContext.setPortletHandle(portletKey
56                          .getPortletHandle());
57              }
58  
59              if (parentHandle == null) {
60                  parentHandle = portletKey.getPortletHandle();
61              }
62  
63              stateChanged();
64          }
65      }
66  
67      public void setPortletContext(PortletContext portletContext) {
68          if (portletContext != null) {
69              this.portletContext = portletContext;
70              this.portletKey.setPortletHandle(portletContext.getPortletHandle());
71  
72              stateChanged();
73          }
74      }
75  
76      public PortletContext getPortletContext() {
77          return this.portletContext;
78      }
79  
80      public String getParent() {
81          return this.parentHandle;
82      }
83  
84      public void setParent(String portletHandle) {
85          this.parentHandle = portletHandle;
86  
87          stateChanged();
88      }
89  
90      public boolean isConsumerConfigured() {
91  
92          return !getParent().equals(portletKey.getPortletHandle());
93      }
94  }