1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.util.Validator;
22  import com.liferay.portal.model.Role;
23  import com.liferay.portal.model.RoleConstants;
24  import com.liferay.portal.model.Team;
25  import com.liferay.portal.service.TeamLocalServiceUtil;
26  import com.liferay.portal.util.PortalUtil;
27  
28  /**
29   * <a href="RoleImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Jorge Ferrer
33   */
34  public class RoleImpl extends RoleModelImpl implements Role {
35  
36      public RoleImpl() {
37      }
38  
39      public String getDescriptiveName() throws PortalException, SystemException {
40          String name = getName();
41  
42          if (isTeam()) {
43              Team team = TeamLocalServiceUtil.getTeam(getClassPK());
44  
45              name = team.getName();
46          }
47  
48          return name;
49      }
50  
51      public String getTitle(String languageId) {
52          String value = super.getTitle(languageId);
53  
54          if (Validator.isNull(value)) {
55              try {
56                  value = getDescriptiveName();
57              }
58              catch (Exception e) {
59                  _log.error(e, e);
60              }
61          }
62  
63          return value;
64      }
65  
66      public String getTitle(String languageId, boolean useDefault) {
67          String value = super.getTitle(languageId, useDefault);
68  
69          if (Validator.isNull(value)) {
70              try {
71                  value = getDescriptiveName();
72              }
73              catch (Exception e) {
74                  _log.error(e, e);
75              }
76          }
77  
78          return value;
79      }
80  
81      public String getTypeLabel() {
82          return RoleConstants.getTypeLabel(getType());
83      }
84  
85      public boolean isTeam() {
86          return hasClassName(Team.class);
87      }
88  
89      protected boolean hasClassName(Class<?> classObj) {
90          long classNameId = getClassNameId();
91  
92          if (classNameId == PortalUtil.getClassNameId(classObj)) {
93              return true;
94          }
95          else {
96              return false;
97          }
98      }
99  
100     private static Log _log = LogFactoryUtil.getLog(RoleImpl.class);
101 
102 }