001/* 002 * (C) Copyright 2012 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 */ 019package org.nuxeo.template.api.descriptor; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XNodeList; 029import org.nuxeo.common.xmap.annotation.XObject; 030import org.nuxeo.template.api.context.ContextExtensionFactory; 031 032@XObject("contextFactory") 033public class ContextExtensionFactoryDescriptor implements Serializable { 034 035 private static final long serialVersionUID = 1L; 036 037 protected static final Log log = LogFactory.getLog(ContextExtensionFactoryDescriptor.class); 038 039 @XNode("@name") 040 protected String name; 041 042 @XNode("@class") 043 protected Class<? extends ContextExtensionFactory> factoryClass; 044 045 @XNode("@enabled") 046 protected boolean enabled = true; 047 048 @XNodeList(value = "aliasName", type = ArrayList.class, componentType = String.class) 049 protected List<String> aliasNames = new ArrayList<String>(); 050 051 protected ContextExtensionFactory factory; 052 053 public boolean isEnabled() { 054 return enabled; 055 } 056 057 public ContextExtensionFactory getExtensionFactory() { 058 if (factory == null) { 059 if (factoryClass != null) { 060 try { 061 factory = factoryClass.newInstance(); 062 } catch (ReflectiveOperationException e) { 063 log.error("Unable to instanciate Processor", e); 064 } 065 } 066 } 067 return factory; 068 } 069 070 public String getName() { 071 return name; 072 } 073 074 public ContextExtensionFactoryDescriptor clone() { 075 ContextExtensionFactoryDescriptor copy = new ContextExtensionFactoryDescriptor(); 076 copy.name = name; 077 copy.factoryClass = factoryClass; 078 copy.enabled = enabled; 079 copy.aliasNames = aliasNames; 080 return copy; 081 } 082 083 public void merge(ContextExtensionFactoryDescriptor src) { 084 if (src.factoryClass != null) { 085 factoryClass = src.factoryClass; 086 } 087 if (src.aliasNames != null) { 088 aliasNames.addAll(src.aliasNames); 089 } 090 enabled = src.enabled; 091 } 092 093 public List<String> getAliases() { 094 return aliasNames; 095 } 096 097}