All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.compiler.lang.api.impl.PatternDescrBuilderImpl Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
/*
 * Copyright 2011 Red Hat, Inc. and/or its affiliates.
 *
 * 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.compiler.lang.api.impl;

import org.drools.compiler.lang.api.AnnotationDescrBuilder;
import org.drools.compiler.lang.api.BehaviorDescrBuilder;
import org.drools.compiler.lang.api.DescrBuilder;
import org.drools.compiler.lang.api.PatternDescrBuilder;
import org.drools.compiler.lang.api.SourceDescrBuilder;
import org.drools.compiler.lang.descr.BindingDescr;
import org.drools.compiler.lang.descr.ExprConstraintDescr;
import org.drools.compiler.lang.descr.PatternDescr;

/**
 * A descr builder implementation for Patterns
 */
public class PatternDescrBuilderImpl

> extends BaseDescrBuilderImpl implements PatternDescrBuilder

{ protected PatternDescrBuilderImpl(P parent) { this( parent, null ); } protected PatternDescrBuilderImpl(P parent, String type) { super( parent, new PatternDescr( type ) ); this.parent = parent; } public PatternDescrBuilder

id( String id, boolean isUnification ) { descr.setIdentifier( id ); descr.setUnification( isUnification ); return this; } public PatternDescrBuilder

type( String type ) { descr.setObjectType( type ); return this; } public PatternDescrBuilder

isQuery( boolean query ) { descr.setQuery( query ); return this; } public PatternDescrBuilder

constraint( String constraint ) { ExprConstraintDescr constr = new ExprConstraintDescr( constraint ); constr.setType( ExprConstraintDescr.Type.NAMED ); constr.setPosition( descr.getConstraint().getDescrs().size() ); constr.setResource(descr.getResource()); descr.addConstraint( constr ); return this; } public PatternDescrBuilder

constraint( String constraint, boolean positional ) { ExprConstraintDescr constr = new ExprConstraintDescr( constraint ); constr.setType( positional ? ExprConstraintDescr.Type.POSITIONAL : ExprConstraintDescr.Type.NAMED ); constr.setPosition( descr.getConstraint().getDescrs().size() ); constr.setResource(descr.getResource()); descr.addConstraint( constr ); return this; } public PatternDescrBuilder

bind( String var, String target, boolean isUnification ) { BindingDescr bindDescr = new BindingDescr( var, target, isUnification ); bindDescr.setResource(descr.getResource()); descr.addConstraint( bindDescr ); return this; } public SourceDescrBuilder> from() { return new SourceDescrBuilderImpl>( this ); } public BehaviorDescrBuilder> behavior() { return new BehaviorDescrBuilderImpl>( this ); } public AnnotationDescrBuilder> newAnnotation(String name) { AnnotationDescrBuilder> annotation = new AnnotationDescrBuilderImpl>( this, name ); descr.addAnnotation( annotation.getDescr() ); return annotation; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy