Package org.drools.verifier.components

Examples of org.drools.verifier.components.ObjectType


                objectTypeName = typeDeclaration.getTypeName();
            } else {
                objectTypeName = objectImport.getName();
            }

            ObjectType objectType = this.data.getObjectTypeByFullName( objectTypeName );

            if ( objectType == null ) {
                objectType = new ObjectType();
                objectType.setName( typeDeclaration.getTypeName() );
                objectType.setFullName( typeDeclaration.getTypeName() );
                data.add( objectType );
            }

            for ( String fieldName : typeDeclaration.getFields().keySet() ) {

                Field field = data.getFieldByObjectTypeAndFieldName( objectType.getFullName(),
                                                                     fieldName );
                if ( field == null ) {
                    field = ObjectTypeFactory.createField( fieldName,
                                                           objectType );
                    field.setFieldType( typeDeclaration.getFields().get( fieldName ).getPattern().getObjectType() );
                    data.add( field );
                }
            }
            for ( String metadata : typeDeclaration.getMetaAttributes().keySet() ) {
                objectType.getMetadata().put( metadata,
                                              typeDeclaration.getMetaAttribute( metadata ) );
            }
        }
    }
View Full Code Here


        return field;
    }

    static ObjectType createObjectType(Import objectImport) {
        ObjectType objectType = new ObjectType();

        objectType.setName( objectImport.getShortName() );
        objectType.setFullName( objectImport.getName() );

        return objectType;
    }
View Full Code Here

        return objectType;
    }

    static ObjectType createObjectType(String shortName) {
        ObjectType objectType = new ObjectType();

        objectType.setName( shortName );
        objectType.setFullName( shortName );

        return objectType;
    }
View Full Code Here

        Pattern pattern = VerifierComponentMockFactory.createPattern1();
        saveVerifierComponentAndGet( pattern );

        saveVerifierComponentAndGet( new InlineEvalDescr( pattern ) );
        saveVerifierComponentAndGet( new ObjectType(new PackageDescr("testPackage1")) );
        saveVerifierComponentAndGet( new RuleOperatorDescr( new AndDescr(), rule,
                                                            OperatorDescrType.AND ) );
        saveVerifierComponentAndGet( new PatternOperatorDescr( pattern,
                                                               OperatorDescrType.AND ) );
        saveVerifierComponentAndGet( new SubPattern( pattern,
View Full Code Here

        VerifierRule rule = VerifierComponentMockFactory.createRule1();
        assertNotNull( rule.getName() );
        assertEquals( "testRule1",
                      rule.getName() );

        ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));
        Pattern pattern = VerifierComponentMockFactory.createPattern1();

        assertNotNull( pattern.getRulePath() );
        assertEquals( rule.getPath(),
                      pattern.getRulePath() );

        assertNotNull( pattern.getName() );
        assertEquals( rule.getName(),
                      pattern.getRuleName() );

        pattern.setObjectTypePath( objectType.getPath() );
        assertNotNull( pattern.getObjectTypePath() );
        assertEquals( objectType.getPath(),
                      pattern.getObjectTypePath() );

        data.add( rule );
        data.add( objectType );
        data.add( pattern );

        Collection<VerifierComponent> all = data.getAll();

        assertEquals( 3,
                      all.size() );
        assertTrue( all.contains( pattern ) );
        assertTrue( all.contains( objectType ) );
        assertTrue( all.contains( rule ) );

        Collection<VerifierComponent> components = data.getAll( pattern.getVerifierComponentType() );

        assertEquals( 1,
                      components.size() );
        assertEquals( pattern,
                      components.toArray()[0] );

        VerifierComponent objectType2 = data.getVerifierObject( objectType.getVerifierComponentType(),
                                                                objectType.getPath() );

        assertNotNull( objectType2 );
        assertEquals( objectType,
                      objectType2 );
View Full Code Here

    }

    private void saveVerifierComponentAndGet(Field field) {
        VerifierData data = VerifierReportFactory.newVerifierData();

        ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));

        field.setObjectTypePath( objectType.getPath() );

        data.add( objectType );
        data.add( field );

        Collection<VerifierComponent> all = data.getAll();

        assertEquals( 2,
                      all.size() );
        assertTrue( all.contains( objectType ) );
        assertTrue( all.contains( field ) );

        Collection<VerifierComponent> fields = data.getAll( field.getVerifierComponentType() );

        assertEquals( 1,
                      fields.size() );
        assertEquals( field,
                      fields.toArray()[0] );

        VerifierComponent field2 = data.getVerifierObject( field.getVerifierComponentType(),
                                                           field.getPath() );

        assertNotNull( field2 );
        assertEquals( field,
                      field2 );

        Collection<VerifierComponent> objectTypes = data.getAll( objectType.getVerifierComponentType() );

        assertEquals( 1,
                      objectTypes.size() );
        assertEquals( objectType,
                      objectTypes.toArray()[0] );

        VerifierComponent objectType2 = data.getVerifierObject( objectType.getVerifierComponentType(),
                                                                objectType.getPath() );

        assertNotNull( objectType2 );
        assertEquals( objectType,
                      objectType2 );
    }
View Full Code Here

    }

    private void saveVerifierComponentAndGet(Restriction component) {
        VerifierData data = VerifierReportFactory.newVerifierData();

        ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));

        Field field = new Field(new PackageDescr("testPackage1"));
        field.setObjectTypePath( objectType.getPath() );

        component.setFieldPath( field.getPath() );

        assertNotNull( component.getFieldPath() );

        data.add( objectType );
        data.add( field );
        data.add( component );

        Collection<VerifierComponent> all = data.getAll();

        assertEquals( 3,
                      all.size() );
        assertTrue( all.contains( objectType ) );
        assertTrue( all.contains( field ) );
        assertTrue( all.contains( component ) );

        Collection<VerifierComponent> components = data.getAll( component.getVerifierComponentType() );

        assertEquals( 1,
                      components.size() );
        assertEquals( component,
                      components.toArray()[0] );

        VerifierComponent component2 = data.getVerifierObject( component.getVerifierComponentType(),
                                                               component.getPath() );

        assertNotNull( component2 );
        assertEquals( component,
                      component2 );

        Collection<VerifierComponent> fields = data.getAll( field.getVerifierComponentType() );

        assertEquals( 1,
                      fields.size() );
        assertEquals( field,
                      fields.toArray()[0] );

        VerifierComponent field2 = data.getVerifierObject( field.getVerifierComponentType(),
                                                           field.getPath() );

        assertNotNull( field2 );
        assertEquals( field,
                      field2 );

        Collection<VerifierComponent> objectTypes = data.getAll( objectType.getVerifierComponentType() );

        assertEquals( 1,
                      objectTypes.size() );
        assertEquals( objectType,
                      objectTypes.toArray()[0] );

        VerifierComponent objectType2 = data.getVerifierObject( objectType.getVerifierComponentType(),
                                                                objectType.getPath() );

        assertNotNull( objectType2 );
        assertEquals( objectType,
                      objectType2 );
    }
View Full Code Here

  }

  private int flatten(PatternDescr descr, VerifierComponent parent,
      int orderNumber) throws UnknownDescriptionException {

    ObjectType objectType = findOrCreateNewObjectType(descr.getObjectType());
    currentObjectType = objectType;

    Pattern pattern = new Pattern();
    pattern.setRuleId(currentRule.getId());
    pattern.setRuleName(currentRule.getRuleName());
    pattern.setClassId(objectType.getId());
    pattern.setName(objectType.getName());
    pattern.setPatternNot(solvers.getRuleSolver().isChildNot());
    pattern.setPatternExists(solvers.getRuleSolver().isExists());
    pattern.setPatternForall(solvers.getRuleSolver().isForall());
    pattern.setOrderNumber(orderNumber);
    pattern.setParent(parent);

    data.add(pattern);
    currentPattern = pattern;

    if (descr.getIdentifier() != null) {
      Variable variable = new Variable();
      variable.setRuleId(currentRule.getId());
      variable.setRuleName(currentRule.getRuleName());
      variable.setName(descr.getIdentifier());

      variable.setObjectType(VerifierComponentType.CLASS);
      variable.setObjectId(objectType.getId());
      variable.setObjectName(descr.getObjectType());

      data.add(variable);
    }
View Full Code Here

    } else {

      EnumField enumField = (EnumField) data
          .getFieldByObjectTypeAndFieldName(base, fieldName);
      if (enumField == null) {
        ObjectType objectType = findOrCreateNewObjectType(base);

        enumField = new EnumField();
        enumField.setObjectTypeId(objectType.getId());
        enumField.setClassName(objectType.getName());
        enumField.setName(fieldName);

        objectType.getFields().add(enumField);

        data.add(enumField);
      }

      EnumRestriction restriction = new EnumRestriction();
View Full Code Here

      solvers.addRestriction(restriction);
    }
  }

  private ObjectType findOrCreateNewObjectType(String name) {
    ObjectType objectType = data.getObjectTypeByName(name);
    if (objectType == null) {
      objectType = new ObjectType();
      objectType.setName(name);
      data.add(objectType);
    }
    return objectType;
  }
View Full Code Here

TOP

Related Classes of org.drools.verifier.components.ObjectType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.