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 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.runtime.deployment.preprocessor; 021 022import java.io.File; 023import java.io.IOException; 024import java.util.ArrayList; 025import java.util.HashMap; 026import java.util.List; 027import java.util.Map; 028 029import org.apache.commons.logging.Log; 030import org.apache.commons.logging.LogFactory; 031import org.nuxeo.common.xmap.annotation.XContent; 032import org.nuxeo.common.xmap.annotation.XNode; 033import org.nuxeo.common.xmap.annotation.XNodeList; 034import org.nuxeo.common.xmap.annotation.XNodeMap; 035import org.nuxeo.common.xmap.annotation.XObject; 036import org.nuxeo.runtime.deployment.preprocessor.install.CommandContext; 037import org.nuxeo.runtime.deployment.preprocessor.install.CommandProcessor; 038import org.nuxeo.runtime.deployment.preprocessor.install.DOMCommandsParser; 039import org.w3c.dom.DocumentFragment; 040 041/** 042 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 043 */ 044@XObject("container") 045public class ContainerDescriptor { 046 047 private static final Log log = LogFactory.getLog(ContainerDescriptor.class); 048 049 @XNode("@name") 050 public String name; 051 052 @XNodeMap(value = "template", key = "@name", type = HashMap.class, componentType = TemplateDescriptor.class) 053 public Map<String, TemplateDescriptor> templates; 054 055 @XNodeList(value = "directory", type = ArrayList.class, componentType = String.class) 056 public List<String> directories; 057 058 // the container directory 059 public File directory; 060 061 // registered fragments 062 public final FragmentRegistry fragments = new FragmentRegistry(); 063 064 // sub containers 065 public final List<ContainerDescriptor> subContainers = new ArrayList<ContainerDescriptor>(); 066 067 public CommandProcessor install; 068 069 public CommandProcessor uninstall; 070 071 public CommandContext context; 072 073 /** 074 * The files to process. If this is not null, directories specified in the configuration are ignored. 075 */ 076 public File[] files; 077 078 @XContent("install") 079 public void setInstallCommands(DocumentFragment df) { 080 try { 081 install = DOMCommandsParser.parse(df); 082 } catch (IOException e) { 083 log.error("Failed to set install commands"); 084 } 085 } 086 087 @XContent("uninstall") 088 public void setUninstallCommands(DocumentFragment df) { 089 try { 090 uninstall = DOMCommandsParser.parse(df); 091 } catch (IOException e) { 092 log.error("Failed to set uninstall commands"); 093 } 094 } 095 096}