View Javadoc

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.jetspeed.om.registry.base;
18  
19  import org.apache.jetspeed.om.registry.RegistryEntry;
20  import org.apache.jetspeed.om.registry.InvalidEntryException;
21  import org.apache.jetspeed.om.registry.RegistryException;
22  import org.apache.jetspeed.services.Registry;
23  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
24  import org.apache.jetspeed.services.logging.JetspeedLogger;
25  
26  
27  /***
28   * Extends BaseRegistry implementation to override object creation
29   * method and ensure Registry object is synchronized with its
30   * persistence backend by delegating actual addition/deletion of objects
31   * to the registry service.
32   * <p>To avoid loops, a RegistryService implementation using this class
33   * nees to call the addLocalEntry/removeLocalEntry methods to modify
34   * the in memory state of this Registry</p>
35   *
36   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
37   * @version $Id: BasePortletControlRegistry.java,v 1.4 2004/02/23 03:08:26 jford Exp $
38   */
39  public class BasePortletControlRegistry extends BaseRegistry
40  {
41  
42      /***
43       * Static initialization of the logger for this class
44       */    
45      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BasePortletControlRegistry.class.getName());    
46      
47      /***
48      @see Registry#setEntry
49      */
50      public void setEntry( RegistryEntry entry ) throws InvalidEntryException
51      {
52  		// Delegate to the RegistryService to ensure correct handling of
53  		// persistence if using file fragments
54  
55  		try
56  		{
57  			Registry.addEntry(Registry.PORTLET_CONTROL, entry);
58  		}
59  		catch (RegistryException e)
60  		{
61  			logger.error("Exception", e);
62  		}
63      }
64  
65      /***
66      @see Registry#addEntry
67      */
68      public void addEntry( RegistryEntry entry ) throws InvalidEntryException
69      {
70  		// Delegate to the RegistryService to ensure correct handling of
71  		// persistence if using file fragments
72  
73  		try
74  		{
75  			Registry.addEntry(Registry.PORTLET_CONTROL, entry);
76  		}
77  		catch (RegistryException e)
78  		{
79  			logger.error("Exception", e);
80  		}
81      }
82  
83      /***
84      @see Registry#removeEntry
85      */
86      public void removeEntry( String name )
87      {
88  		// Delegate to the RegistryService to ensure correct handling of
89  		// persistence if using file fragments
90  
91  		Registry.removeEntry(Registry.PORTLET_CONTROL, name);
92      }
93  
94      /***
95      @see Registry#removeEntry
96      */
97      public void removeEntry( RegistryEntry entry )
98      {
99  		// Delegate to the RegistryService to ensure correct handling of
100 		// persistence if using file fragments
101 
102 		if (entry != null)
103 		{
104 			Registry.removeEntry(Registry.PORTLET_CONTROL, entry.getName());
105 		}
106     }
107 
108     /***
109      * Creates a new RegistryEntry instance compatible with the current
110      * Registry instance implementation
111      *
112      * @return the newly created RegistryEntry
113      */
114     public RegistryEntry createEntry()
115     {
116 		return new BasePortletControlEntry();
117 	}
118 }