Fix for IZ93602: Added check for cyclic links after_merge_Apr23_nb-vw-integration
authoralexeyyarmolenko@netbeans.org
Mon, 23 Apr 2007 15:25:14 +0000
changeset 4080fd2d88aea9f
parent 407 d561c5ad50c7
child 409 1abb6d001af8
Fix for IZ93602: Added check for cyclic links
xslt.mapper/src/org/netbeans/modules/xslt/mapper/view/XsltMapper.java
xslt.mapper/src/org/netbeans/modules/xslt/mapper/view/XsltMapperRule.java
     1.1 --- a/xslt.mapper/src/org/netbeans/modules/xslt/mapper/view/XsltMapper.java	Mon Apr 23 12:36:05 2007 +0000
     1.2 +++ b/xslt.mapper/src/org/netbeans/modules/xslt/mapper/view/XsltMapper.java	Mon Apr 23 15:25:14 2007 +0000
     1.3 @@ -49,13 +49,14 @@
     1.4  import org.netbeans.modules.xslt.mapper.model.nodes.actions.DeleteAction;
     1.5  import org.netbeans.modules.xslt.mapper.model.targettree.TargetTreeModel;
     1.6  import org.netbeans.modules.xslt.model.XslModel;
     1.7 +import org.openide.util.HelpCtx;
     1.8  import org.openide.util.Lookup;
     1.9  
    1.10  /**
    1.11   *
    1.12   * @author Alexey
    1.13   */
    1.14 -public class XsltMapper extends BasicMapper {
    1.15 +public class XsltMapper extends BasicMapper implements HelpCtx.Provider{
    1.16      
    1.17      
    1.18      
    1.19 @@ -86,6 +87,7 @@
    1.20          xslModelBridge = new ModelBridge(this);
    1.21          diagramBuilder = new DiagramBuilder(this);
    1.22          super.addMapperListener(xslModelBridge);
    1.23 +        super.setMapperRule(new XsltMapperRule(this));
    1.24          
    1.25          if (context != null) {
    1.26              context.addMapperContextChangeListener(new MapperContextChangeListener() {
    1.27 @@ -353,6 +355,10 @@
    1.28              
    1.29          }
    1.30      }
    1.31 +
    1.32 +    public HelpCtx getHelpCtx() {
    1.33 +        return new HelpCtx("xslt_editor_design_about"); //NOI18N
    1.34 +    }
    1.35      
    1.36      
    1.37  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xslt.mapper/src/org/netbeans/modules/xslt/mapper/view/XsltMapperRule.java	Mon Apr 23 15:25:14 2007 +0000
     2.3 @@ -0,0 +1,100 @@
     2.4 +/*
     2.5 + * The contents of this file are subject to the terms of the Common Development
     2.6 + * and Distribution License (the License). You may not use this file except in
     2.7 + * compliance with the License.
     2.8 + *
     2.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    2.10 + * or http://www.netbeans.org/cddl.txt.
    2.11 + *
    2.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
    2.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
    2.14 + * If applicable, add the following below the CDDL Header, with the fields
    2.15 + * enclosed by brackets [] replaced by your own identifying information:
    2.16 + * "Portions Copyrighted [year] [name of copyright owner]"
    2.17 + *
    2.18 + * To change this template, choose Tools | Template Manager
    2.19 + * and open the template in the editor.
    2.20 + */
    2.21 +package org.netbeans.modules.xslt.mapper.view;
    2.22 +
    2.23 +import java.util.HashSet;
    2.24 +import java.util.LinkedList;
    2.25 +import java.util.Set;
    2.26 +import org.netbeans.modules.soa.mapper.basicmapper.BasicMapperRule;
    2.27 +import org.netbeans.modules.soa.mapper.common.IMapperGroupNode;
    2.28 +import org.netbeans.modules.soa.mapper.common.IMapperLink;
    2.29 +import org.netbeans.modules.soa.mapper.common.IMapperNode;
    2.30 +import org.netbeans.modules.soa.mapper.common.IMapperNode;
    2.31 +import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IFieldNode;
    2.32 +
    2.33 +/**
    2.34 + *
    2.35 + * @author Alexey
    2.36 + */
    2.37 +public class XsltMapperRule extends BasicMapperRule {
    2.38 +    
    2.39 +    
    2.40 +    /**
    2.41 +     *
    2.42 +     * @param mapper
    2.43 +     */
    2.44 +    public XsltMapperRule(XsltMapper mapper) {
    2.45 +        super(mapper);
    2.46 +        
    2.47 +    }
    2.48 +    
    2.49 +    @Override
    2.50 +    public boolean isAllowToCreate(IMapperLink link) {
    2.51 +        return !(new CheckCyclicLinks(link).isCycle());
    2.52 +    }
    2.53 +    
    2.54 +    
    2.55 +    private class CheckCyclicLinks{
    2.56 +        private IMapperGroupNode stopAt;
    2.57 +        private Set<IMapperNode> visited = new HashSet<IMapperNode>();
    2.58 +        
    2.59 +        private boolean cycleFound = false;
    2.60 +        public CheckCyclicLinks(IMapperLink link){
    2.61 +            
    2.62 +            if (link.getStartNode() instanceof IFieldNode &&
    2.63 +                    link.getEndNode() instanceof IFieldNode){
    2.64 +                this.stopAt = link.getStartNode().getGroupNode();
    2.65 +                checkRecursive(link.getEndNode());
    2.66 +            }
    2.67 +            
    2.68 +            
    2.69 +        }
    2.70 +        public boolean isCycle(){
    2.71 +            return this.cycleFound;
    2.72 +        }
    2.73 +        
    2.74 +        private void checkRecursive(IMapperNode node){
    2.75 +            
    2.76 +            
    2.77 +            if (node instanceof IFieldNode){
    2.78 +                IMapperGroupNode group = node.getGroupNode();
    2.79 +                if (group == stopAt){
    2.80 +                    cycleFound = true;
    2.81 +                    return;
    2.82 +                }
    2.83 +                if (group != null){
    2.84 +                    IMapperNode n = group.getFirstNode();
    2.85 +                    while (n != null){
    2.86 +                        
    2.87 +                        for (Object obj: n.getLinks()){
    2.88 +                            IMapperLink l = (IMapperLink) obj;
    2.89 +                            if(l.getStartNode() == n){
    2.90 +                                checkRecursive(l.getEndNode());
    2.91 +                            }
    2.92 +                        }
    2.93 +                        n = group.getNextNode(n);
    2.94 +                    }
    2.95 +                }
    2.96 +            }
    2.97 +        }
    2.98 +        
    2.99 +    }
   2.100 +     
   2.101 +
   2.102 +
   2.103 +}