001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thierry Delprat 016 * * 017 */ 018 019package org.nuxeo.ecm.platform.computedgroups; 020 021import java.io.Serializable; 022 023import org.nuxeo.common.xmap.annotation.XNode; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.ecm.core.api.NuxeoException; 026 027/** 028 * @author Thierry Delprat 029 */ 030@XObject("groupComputer") 031public class GroupComputerDescriptor implements Serializable { 032 033 private static final long serialVersionUID = 1L; 034 035 @XNode("computer") 036 protected Class<GroupComputer> computerClass; 037 038 protected GroupComputer groupComputer; 039 040 @XNode("@name") 041 protected String name; 042 043 @XNode("@enabled") 044 protected boolean enabled = true; 045 046 public String getName() { 047 if (name != null) { 048 return name; 049 } 050 return computerClass.getSimpleName(); 051 } 052 053 public boolean isEnabled() { 054 return enabled; 055 } 056 057 public GroupComputer getComputer() { 058 if (groupComputer == null) { 059 if (computerClass != null) { 060 try { 061 groupComputer = computerClass.newInstance(); 062 } catch (ReflectiveOperationException e) { 063 throw new NuxeoException(e); 064 } 065 } else { 066 groupComputer = null; 067 } 068 } 069 return groupComputer; 070 } 071 072}