KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > service > core > impl > LayoutManagerImpl


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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 package com.blandware.atleap.service.core.impl;
17
18 import com.blandware.atleap.common.util.PartialCollection;
19 import com.blandware.atleap.common.util.QueryInfo;
20 import com.blandware.atleap.model.core.Layout;
21 import com.blandware.atleap.persistence.core.LayoutDAO;
22 import com.blandware.atleap.persistence.exception.DeleteException;
23 import com.blandware.atleap.persistence.exception.UpdateException;
24 import com.blandware.atleap.service.core.LayoutManager;
25 import com.blandware.atleap.service.exception.BeanAlreadyExistsException;
26 import com.blandware.atleap.service.exception.BeanNotFoundException;
27
28 /**
29  * <p>Implementation of LayoutManager</p>
30  * <p><a HREF="LayoutManagerImpl.java.htm"><i>View Source</i></a>
31  * </p>
32  *
33  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
34  * @version $Revision: 1.11 $ $Date: 2005/11/28 15:56:41 $
35  */

36 public class LayoutManagerImpl extends BaseManagerImpl implements LayoutManager {
37
38     // ~ Instance variables ================================================================
39

40
41     /**
42      * DAO to use to get access to persistence layer
43      */

44     protected LayoutDAO layoutDAO;
45
46     //~ CRUD Methods ================================================================
47

48     /**
49      * Sets layout DAO
50      *
51      * @param layoutDAO Layout DAO to use
52      */

53     public void setLayoutDAO(LayoutDAO layoutDAO) {
54         this.layoutDAO = layoutDAO;
55     }
56
57     /**
58      * @see com.blandware.atleap.service.core.LayoutManager#createLayout(com.blandware.atleap.model.core.Layout)
59      */

60     public Long JavaDoc createLayout(Layout layout) throws BeanAlreadyExistsException {
61         if ( log.isDebugEnabled() ) {
62             log.debug("Creating new layout...");
63         }
64
65         if ( layoutDAO.hasDuplicates(layout) ) {
66             throw new BeanAlreadyExistsException("Layout with the same name or definition already exists");
67         }
68
69         Long JavaDoc layoutId = layoutDAO.createLayout(layout);
70         if ( log.isDebugEnabled() ) {
71             log.debug("Layout has been created successfully. Its ID is " + layoutId);
72         }
73         return layoutId;
74     }
75
76     /**
77      * @see com.blandware.atleap.service.core.LayoutManager#retrieveLayout(java.lang.Long)
78      */

79     public Layout retrieveLayout(Long JavaDoc layoutId) {
80         Layout layout = null;
81         layout = layoutDAO.retrieveLayout(layoutId);
82         return layout;
83     }
84
85     /**
86      * @see com.blandware.atleap.service.core.LayoutManager#updateLayout(com.blandware.atleap.model.core.Layout)
87      */

88     public void updateLayout(Layout layout) throws BeanAlreadyExistsException, BeanNotFoundException, UpdateException {
89         // remove layout from cache in order to prevent Hibernate from assigning new version number
90
layoutDAO.removeFromCache(layout);
91         if ( log.isDebugEnabled() ) {
92             log.debug("Updating layout with ID=" + layout.getId());
93         }
94
95         if ( layoutDAO.hasDuplicates(layout) ) {
96             throw new BeanAlreadyExistsException("Layout with the same name or definition already exists");
97         }
98
99         // update layout
100
layoutDAO.updateLayout(layout);
101
102
103     }
104
105     /**
106      * @see com.blandware.atleap.service.core.LayoutManager#deleteLayout(java.lang.Long)
107      */

108     public void deleteLayout(Long JavaDoc layoutId) throws DeleteException, BeanNotFoundException {
109         Layout layout = layoutDAO.retrieveLayout(layoutId);
110         if ( layout == null ) {
111             String JavaDoc errorMessage = "No content resource with ID=" + layout + "could be found";
112             throw new BeanNotFoundException(errorMessage);
113         }
114         layoutDAO.deleteLayout(layout);
115     }
116
117     // ~ Additional methods ================================================================
118

119     /**
120      * @see com.blandware.atleap.service.core.LayoutManager#listLayouts(com.blandware.atleap.common.util.QueryInfo)
121      */

122     public PartialCollection listLayouts(QueryInfo queryInfo) {
123         return layoutDAO.listLayouts(queryInfo);
124     }
125
126     // ~ Finders ================================================================
127

128     /**
129      * @see com.blandware.atleap.service.core.LayoutManager#findLayoutByContentPageUri(java.lang.String)
130      */

131     public Layout findLayoutByContentPageUri(String JavaDoc contentPageUri) {
132
133         // Find content page by specified uri
134

135         if ( log.isDebugEnabled() ) {
136             log.debug("Looking for layout by content page uri: " + contentPageUri);
137         }
138         Layout layout = null;
139         layout = layoutDAO.findLayoutByContentPageUri(contentPageUri);
140         return layout;
141     }
142
143     /**
144      * @see com.blandware.atleap.service.core.LayoutManager#findLayoutByDefinition(java.lang.String)
145      */

146     public Layout findLayoutByDefinition(String JavaDoc definitionName) {
147         Layout layout = null;
148         layout = layoutDAO.findLayoutByDefinition(definitionName);
149         return layout;
150     }
151
152     /**
153      * @see com.blandware.atleap.service.core.LayoutManager#findLayoutByName(java.lang.String)
154      */

155     public Layout findLayoutByName(String JavaDoc name) {
156         Layout layout = null;
157         layout = layoutDAO.findLayoutByName(name);
158         return layout;
159     }
160 }
161
Popular Tags