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