事件调度程序在c ++ 11中使用std :: unique_ptr和std :: deque

时间:2016-11-03 16:03:29

标签: c++ c++11 std unique-ptr deque

我刚刚编写了下面的源代码,通过使用std :: unique_ptr和std :: deque来正确派遣事件,但我不确定它是多么准确。我知道这不是一个好问题,但有人可以评估它,有什么奇怪的问题吗?此外,我没有任何性能问题。

提前致谢。

- Volkan

package com.myproject.dialog;

import javax.jcr.Node;
import javax.jcr.nodetype.NodeType;
import javax.jcr.Property;
import javax.jcr.RepositoryException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.data.Item;

import info.magnolia.cms.core.Path;
import info.magnolia.jcr.util.NodeUtil;
import info.magnolia.ui.admincentral.dialog.action.SaveDialogAction;
import info.magnolia.ui.api.action.ActionExecutionException;
import info.magnolia.ui.form.EditorCallback;
import info.magnolia.ui.form.EditorValidator;
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter;
import info.magnolia.ui.vaadin.integration.jcr.ModelConstants;


public class MyProjectUrltransSaveAction<T extends MyProjectUrltransSaveActionDefinition> extends SaveDialogAction {

    private static final Logger log = LoggerFactory.getLogger(MyProjectUrltransSaveAction.class);

    public MyProjectUrltransSaveAction(T definition, Item item, EditorValidator validator, EditorCallback callback) {
        super(definition, item, validator, callback);
    }

    public void execute() throws ActionExecutionException {
        if (validateForm()) {
            final JcrNodeAdapter item = (JcrNodeAdapter) this.item;
            try {
                final Node node = item.applyChanges();
                final Node parentNode = node.getParent();
                final String parentNodeType = parentNode.getPrimaryNodeType().getName();
                if(!parentNodeType.equals("mgnl:variant")){
                    setNodeName(node, item);
                }
                node.getSession().save();
            } catch (final RepositoryException e) {
                throw new ActionExecutionException(e);
            }
            callback.onSuccess(getDefinition().getName());
        }
    }

    /**
     * Set the node Name.
     * Node name is set to: <br>
     * the value of the property 'name' if it is present.
     */
    protected void setNodeName(Node node, JcrNodeAdapter item) throws RepositoryException {
        String propertyName = "name";
        if (node.hasProperty(propertyName) && !node.hasProperty(ModelConstants.JCR_NAME)) {
            Property property = node.getProperty(propertyName);
            String newNodeName = property.getString();
            if (!node.getName().equals(Path.getValidatedLabel(newNodeName))) {
                newNodeName = Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), Path.getValidatedLabel(newNodeName));
                item.setNodeName(newNodeName);
                NodeUtil.renameNode(node, newNodeName);
            }
        }
    }

}

0 个答案:

没有答案