KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > cms > factories > PublicAddressFactory


1 /**
2  * Copyright (c) 2000-2004 Liferay, LLC. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */

22
23 package com.dotmarketing.cms.factories;
24
25 import java.util.List JavaDoc;
26
27 import org.apache.commons.logging.LogFactory;
28
29 import com.dotmarketing.exception.DotRuntimeException;
30 import com.liferay.counter.ejb.CounterManagerUtil;
31 import com.liferay.portal.NoSuchAddressException;
32 import com.liferay.portal.SystemException;
33 import com.liferay.portal.ejb.AddressUtil;
34 import com.liferay.portal.model.Address;
35
36 /**
37  * <a HREF="AddressUtil.java.htm"><b><i>View Source</i></b></a>
38  *
39  * @author Brian Wing Shun Chan
40  * @version $Revision: 1.1 $
41  *
42  */

43 public class PublicAddressFactory extends AddressUtil{
44
45     public static List JavaDoc getAddressesByUserId(String JavaDoc p0) throws SystemException {
46         
47         
48             return findByUserId(p0);
49
50     }
51     
52     
53     public static Address getAddressById(String JavaDoc p0) throws SystemException {
54         
55             try{
56                 return findByPrimaryKey(p0);
57             }
58             catch(NoSuchAddressException nsae){
59                 
60                 return getInstance();
61             }
62             catch(SystemException se){
63                 throw new DotRuntimeException("Can't get Address");
64             }
65
66     }
67     
68     
69     
70     
71     
72     
73     /*
74     public static Address getPrimaryAddress(String user) throws SystemException {
75         
76             List addresses = findByUserId(user);
77             try{
78                 return (Address) addresses.get(0);
79             }
80             catch(Exception e){
81                 return new Amode;
82                 
83             }
84
85     }
86     */

87     public static Address getInstance(){
88         String JavaDoc addressId = null;
89         try{
90             addressId = Long.toString(CounterManagerUtil.increment( Address.class.getName() ));
91         
92         }
93         catch(SystemException e){
94             throw new DotRuntimeException("Can't get a counter");
95         }
96         return new Address(addressId);
97     }
98     
99     
100     public static void save(Address a) {
101         
102         try{
103             update(a);
104         }
105         catch(SystemException e){
106             throw new DotRuntimeException("Can't save the address");
107         }
108
109     }
110     public static void delete(Address a ){
111         try{
112             remove(a.getAddressId());
113             
114         }
115         catch (NoSuchAddressException e) {
116             LogFactory.getLog(PublicAddressFactory.class).error("No such Address to delete");
117         }
118         catch (SystemException e) {
119             LogFactory.getLog(PublicAddressFactory.class).error("Deleting Address", e);
120         }
121         
122         
123         
124     }
125     
126     
127     
128     
129 }
Popular Tags