Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.drools.workbench.screens.guided.dtable.client.widget;
 
 
 import java.util.Map;


A Rule Model Visitor to create a clone TODO Clone LHS of model...
 
 public class RuleModelCloneVisitor {
 
     private Object visitObject o ) {
         if ( o == null ) {
             return null;
         }
         if ( o instanceof RuleModel) {
             return visitRuleModel( (RuleModelo );
         } else if ( o instanceof RuleAttribute) {
             return visitRuleAttribute( (RuleAttributeo );
         } else if ( o instanceof RuleMetadata ) {
             return visitRuleMetadata( (RuleMetadatao );
         } else if ( o instanceof FactPattern) {
             return visitFactPattern( (FactPatterno );
         } else if ( o instanceof CompositeFieldConstraint) {
             return visitCompositeFieldConstraint( (CompositeFieldConstrainto );
         } else if ( o instanceof SingleFieldConstraintEBLeftSide) {
             return visitSingleFieldConstraint( (SingleFieldConstraintEBLeftSideo );
         } else if ( o instanceof SingleFieldConstraint) {
             return visitSingleFieldConstraint( (SingleFieldConstrainto );
         } else if ( o instanceof ExpressionFormLine) {
             return visitExpressionFormLine( (ExpressionFormLineo );
         } else if ( o instanceof ConnectiveConstraint) {
             return visitConnectiveConstraint( (ConnectiveConstrainto );
         } else if ( o instanceof CompositeFactPattern) {
             return visitCompositeFactPattern( (CompositeFactPatterno );
         } else if ( o instanceof FreeFormLine) {
             return visitFreeFormLine( (FreeFormLineo );
         } else if ( o instanceof FromAccumulateCompositeFactPattern) {
         } else if ( o instanceof FromCollectCompositeFactPattern) {
             return visitFromCollectCompositeFactPattern( (FromCollectCompositeFactPatterno );
         } else if ( o instanceof FromCompositeFactPattern) {
             return visitFromCompositeFactPattern( (FromCompositeFactPatterno );
         } else if ( o instanceof DSLSentence) {
             return visitDSLSentence( (DSLSentenceo );
         } else if ( o instanceof DSLVariableValue) {
             return visitDSLVariableValue( (DSLVariableValueo );
         } else if ( o instanceof ActionInsertFact ) {
             return visitActionFieldList( (ActionInsertFacto );
         } else if ( o instanceof ActionUpdateField ) {
             return visitActionFieldList( (ActionUpdateFieldo );
         } else if ( o instanceof ActionSetField ) {
             return visitActionFieldList( (ActionSetFieldo );
         } else if ( o instanceof ActionRetractFact) {
             return visitActionRetractFact( (ActionRetractFacto );
         }
         throw new IllegalArgumentException"Class " + o.getClass().getName() + " is not recognised" );
    }
    private RuleAttribute visitRuleAttributeRuleAttribute attr ) {
        RuleAttribute clone = new RuleAttribute();
        clone.setAttributeNameattr.getAttributeName() );
        clone.setValueattr.getValue() );
        return clone;
    }
    private RuleMetadata visitRuleMetadataRuleMetadata md ) {
        RuleMetadata clone = new RuleMetadata();
        clone.setAttributeNamemd.getAttributeName() );
        clone.setValuemd.getValue() );
        return clone;
    }
    //ActionInsertFact, ActionSetField, ActionpdateField
        ActionInsertFact clone = new ActionInsertFact();
        clone.setFactTypeafl.getFactType() );
        clone.setBoundNameafl.getBoundName() );
        for ( ActionFieldValue afv : afl.getFieldValues() ) {
            ActionFieldValue afvClone = new ActionFieldValue();
            afvClone.setFieldafv.getField() );
            afvClone.setNatureafv.getNature() );
            afvClone.setTypeafv.getType() );
            afvClone.setValueafv.getValue() );
            clone.addFieldValueafvClone );
        }
        return clone;
    }
        ActionSetField clone = new ActionSetField();
        clone.setVariableafl.getVariable() );
        for ( ActionFieldValue afv : afl.getFieldValues() ) {
            ActionFieldValue afvClone = new ActionFieldValue();
            afvClone.setFieldafv.getField() );
            afvClone.setNatureafv.getNature() );
            afvClone.setTypeafv.getType() );
            afvClone.setValueafv.getValue() );
            clone.addFieldValueafvClone );
        }
        return clone;
    }
        ActionUpdateField clone = new ActionUpdateField();
        clone.setVariableafl.getVariable() );
        for ( ActionFieldValue afv : afl.getFieldValues() ) {
            ActionFieldValue afvClone = new ActionFieldValue();
            afvClone.setFieldafv.getField() );
            afvClone.setNatureafv.getNature() );
            afvClone.setTypeafv.getType() );
            afvClone.setValueafv.getValue() );
            clone.addFieldValueafvClone );
        }
        return clone;
    }
        ActionRetractFact clone = new ActionRetractFact();
        clone.setVariableNamearf.getVariableName() );
        return clone;
    }
        CompositeFactPattern clone = new CompositeFactPattern();
        clone.setTypepattern.getType() );
        if ( pattern.getPatterns() != null ) {
            for ( IFactPattern fp : pattern.getPatterns() ) {
                clone.addFactPattern( (IFactPatternvisitfp ) );
            }
        }
        return clone;
    }
        CompositeFieldConstraint clone = new CompositeFieldConstraint();
        clone.setCompositeJunctionTypecfc.getCompositeJunctionType() );
        if ( cfc.getConstraints() != null ) {
            clone.setConstraintsnew FieldConstraintcfc.getConstraints().length ] );
            for ( int i = 0; i < cfc.getConstraints().lengthi++ ) {
                FieldConstraint fc = cfc.getConstraints()[ i ];
                clone.getConstraints()[ i ] = (FieldConstraintvisitfc );
            }
        }
        return clone;
    }
    private DSLSentence visitDSLSentencefinal DSLSentence sentence ) {
        DSLSentence clone = new DSLSentence();
        clone.setDefinitionsentence.getDefinition() );
        for ( DSLVariableValue value : sentence.getValues() ) {
            clone.getValues().add( (DSLVariableValuevisitvalue ) );
        }
        return clone;
    }
        DSLVariableValue clone = new DSLVariableValue();
        clone.setValuevalue.getValue() );
        return clone;
    }
    private FactPattern visitFactPatternFactPattern pattern ) {
        FactPattern clone = new FactPattern();
        clone.setBoundNamepattern.getBoundName() );
        clone.setFactTypepattern.getFactType() );
        clone.setNegatedpattern.isNegated() );
        CEPWindow cloneCEPWindow = new CEPWindow();
        cloneCEPWindow.setOperatorpattern.getWindow().getOperator() );
        cloneCEPWindow.setParameterscloneCEPWindowParameterspattern.getWindow() ) );
        clone.setWindowcloneCEPWindow );
        for ( FieldConstraint fc : pattern.getFieldConstraints() ) {
            clone.addConstraint( (FieldConstraintvisitfc ) );
        }
        return clone;
    }
    private Map<StringStringcloneCEPWindowParametersCEPWindow window ) {
        Map<StringStringclone = new HashMap<StringString>();
        for ( Map.Entry<StringStringentry : window.getParameters().entrySet() ) {
            clone.putentry.getKey(),
                       entry.getValue() );
        }
        return clone;
    }
    private FreeFormLine visitFreeFormLineFreeFormLine ffl ) {
        FreeFormLine clone = new FreeFormLine();
        clone.setTextffl.getText() );
        return clone;
    }
        clone.setActionCodepattern.getActionCode() );
        clone.setExpression( (ExpressionFormLinevisitpattern.getExpression() ) );
        clone.setFactPattern( (FactPatternvisitpattern.getFactPattern() ) );
        clone.setFunctionpattern.getFunction() );
        clone.setInitCodepattern.getInitCode() );
        clone.setResultCodepattern.getResultCode() );
        clone.setReverseCodepattern.getReverseCode() );
        clone.setSourcePattern( (IPatternvisitpattern.getSourcePattern() ) );
        return clone;
    }
        clone.setExpression( (ExpressionFormLinevisitpattern.getExpression() ) );
        clone.setFactPattern( (FactPatternvisitpattern.getFactPattern() ) );
        clone.setRightPattern( (IPatternvisitpattern.getRightPattern() ) );
        return clone;
    }
        FromCompositeFactPattern clone = new FromCompositeFactPattern();
        clone.setExpression( (ExpressionFormLinevisitpattern.getExpression() ) );
        clone.setFactPattern( (FactPatternvisitpattern.getFactPattern() ) );
        return clone;
    }
    public RuleModel visitRuleModelRuleModel model ) {
        RuleModel clone = new RuleModel();
        clone.modelVersion = model.modelVersion;
        clone.name = model.name;
        clone.parentName = model.parentName;
        clone.setNegatedmodel.isNegated() );
        if ( model.attributes != null ) {
            clone.attributes = new RuleAttributemodel.attributes.length ];
            for ( int i = 0; i < model.attributes.lengthi++ ) {
                RuleAttribute attr = model.attributesi ];
                clone.attributesi ] = (RuleAttributevisitattr );
            }
        }
        if ( model.metadataList != null ) {
            clone.metadataList = new RuleMetadatamodel.metadataList.length ];
            for ( int i = 0; i < model.metadataList.lengthi++ ) {
                RuleMetadata md = model.metadataListi ];
                clone.metadataListi ] = (RuleMetadatavisitmd );
            }
        }
        if ( model.lhs != null ) {
            clone.lhs = new IPatternmodel.lhs.length ];
            for ( int i = 0; i < model.lhs.lengthi++ ) {
                IPattern pattern = model.lhsi ];
                clone.lhsi ] = (IPatternvisitpattern );
            }
        }
        if ( model.rhs != null ) {
            clone.rhs = new IActionmodel.rhs.length ];
            for ( int i = 0; i < model.rhs.lengthi++ ) {
                IAction action = model.rhsi ];
                clone.rhsi ] = (IActionvisitaction );
            }
        }
        return clone;
    }
        SingleFieldConstraint clone = new SingleFieldConstraint();
        clone.setConstraintValueTypesfc.getConstraintValueType() );
        clone.setExpressionValue( (ExpressionFormLinevisitsfc.getExpressionValue() ) );
        clone.setFieldBindingsfc.getFieldBinding() );
        clone.setFactTypesfc.getFactType() );
        clone.setFieldNamesfc.getFieldName() );
        clone.setFieldTypesfc.getFieldType() );
        clone.setOperatorsfc.getOperator() );
        for ( Map.Entry<StringStringentry : sfc.getParameters().entrySet() ) {
            clone.setParameterentry.getKey(),
                                entry.getValue() );
        }
        clone.setValuesfc.getValue() );
        if ( sfc.getConnectives() != null ) {
            clone.setConnectivesnew ConnectiveConstraintsfc.getConnectives().length ] );
            for ( int i = 0; i < sfc.getConnectives().lengthi++ ) {
                clone.getConnectives()[ i ] = (ConnectiveConstraintvisitsfc.getConnectives()[ i ] );
            }
        }
        return clone;
    }
        ExpressionFormLine clone = new ExpressionFormLineefl );
        clone.setBindingefl.getBinding() );
        return clone;
    }
        ConnectiveConstraint clone = new ConnectiveConstraint();
        clone.setConstraintValueTypecc.getConstraintValueType() );
        clone.setExpressionValue( (ExpressionFormLinevisitcc.getExpressionValue() ) );
        clone.setFieldNamecc.getFieldName() );
        clone.setFieldTypecc.getFieldType() );
        clone.setOperatorcc.getOperator() );
        for ( Map.Entry<StringStringentry : cc.getParameters().entrySet() ) {
            clone.setParameterentry.getKey(),
                                entry.getValue() );
        }
        clone.setValuecc.getValue() );
        return clone;
    }
        clone.setConstraintValueTypesfexp.getConstraintValueType() );
        clone.setExpressionLeftSide( (ExpressionFormLinevisitsfexp.getExpressionLeftSide() ) );
        clone.setExpressionValue( (ExpressionFormLinevisitsfexp.getExpressionValue() ) );
        clone.setFieldBindingsfexp.getFieldBinding() );
        clone.setFactTypesfexp.getFactType() );
        clone.setFieldNamesfexp.getFieldName() );
        clone.setFieldTypesfexp.getFieldType() );
        clone.setOperatorsfexp.getOperator() );
        for ( Map.Entry<StringStringentry : sfexp.getParameters().entrySet() ) {
            clone.setParameterentry.getKey(),
                                entry.getValue() );
        }
        clone.setParentsfexp.getParent() );
        clone.setValuesfexp.getValue() );
        if ( sfexp.getConnectives() != null ) {
            clone.setConnectivesnew ConnectiveConstraintsfexp.getConnectives().length ] );
            for ( int i = 0; i < sfexp.getConnectives().lengthi++ ) {
                clone.getConnectives()[ i ] = (ConnectiveConstraintvisitsfexp.getConnectives()[ i ] );
            }
        }
        return clone;
    }
New to GrepCode? Check out our FAQ X