001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 * * 019 */ 020 021package org.nuxeo.ecm.platform.computedgroups; 022 023import java.io.Serializable; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.ecm.core.api.NuxeoException; 028 029/** 030 * @author Thierry Delprat 031 */ 032@XObject("groupComputer") 033public class GroupComputerDescriptor implements Serializable { 034 035 private static final long serialVersionUID = 1L; 036 037 @XNode("computer") 038 protected Class<GroupComputer> computerClass; 039 040 protected GroupComputer groupComputer; 041 042 @XNode("@name") 043 protected String name; 044 045 @XNode("@enabled") 046 protected boolean enabled = true; 047 048 public String getName() { 049 if (name != null) { 050 return name; 051 } 052 return computerClass.getSimpleName(); 053 } 054 055 public boolean isEnabled() { 056 return enabled; 057 } 058 059 public GroupComputer getComputer() { 060 if (groupComputer == null) { 061 if (computerClass != null) { 062 try { 063 groupComputer = computerClass.newInstance(); 064 } catch (ReflectiveOperationException e) { 065 throw new NuxeoException(e); 066 } 067 } else { 068 groupComputer = null; 069 } 070 } 071 return groupComputer; 072 } 073 074}