001/*
002 * (C) Copyright 2006-2010 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 *     bstefanescu
018 */
019package org.nuxeo.connect.update.task.standalone.commands;
020
021import java.io.File;
022import java.util.Map;
023
024import org.nuxeo.connect.update.PackageException;
025import org.nuxeo.connect.update.ValidationStatus;
026import org.nuxeo.connect.update.task.Command;
027import org.nuxeo.connect.update.task.Task;
028import org.nuxeo.connect.update.xml.XmlWriter;
029import org.w3c.dom.Element;
030
031/**
032 * Install bundle, flush any application cache and perform Nuxeo preprocessing on the bundle. The inverse of this
033 * command is Undeploy.
034 *
035 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
036 */
037public class UnloadJarPlaceholder extends AbstractCommand {
038
039    public static final String ID = "unload-jar";
040
041    protected File file;
042
043    public UnloadJarPlaceholder() {
044        super(ID);
045    }
046
047    public UnloadJarPlaceholder(File file) {
048        super(ID);
049        this.file = file;
050    }
051
052    @Override
053    protected void doValidate(Task task, ValidationStatus status) throws PackageException {
054        // nothing to do
055    }
056
057    @Override
058    protected Command doRun(Task task, Map<String, String> prefs) throws PackageException {
059        // standalone mode: nothing to do
060        return new LoadJarPlaceholder(file);
061    }
062
063    public void readFrom(Element element) throws PackageException {
064        String v = element.getAttribute("file");
065        if (v.length() > 0) {
066            file = new File(v);
067            guardVars.put("file", file);
068        }
069    }
070
071    public void writeTo(XmlWriter writer) {
072        writer.start(ID);
073        if (file != null) {
074            writer.attr("file", file.getAbsolutePath());
075        }
076        writer.end();
077    }
078}