001    /*
002     * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved.
003     *
004     * Project and contact information: http://www.cascading.org/
005     *
006     * This file is part of the Cascading project.
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     *     http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing, software
015     * distributed under the License is distributed on an "AS IS" BASIS,
016     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017     * See the License for the specific language governing permissions and
018     * limitations under the License.
019     */
020    
021    package cascading.flow;
022    
023    import java.util.Map;
024    import java.util.Properties;
025    
026    import cascading.operation.AssertionLevel;
027    import cascading.operation.DebugLevel;
028    import cascading.property.Props;
029    import cascading.scheme.Scheme;
030    
031    /**
032     * The class FlowConnectorProps is a fluent helper class for setting {@link FlowConnector} specific
033     * properties through the {@link FlowConnector} constructor.
034     *
035     * @see cascading.property.AppProps
036     * @see cascading.cascade.CascadeProps
037     * @see FlowProps
038     */
039    public class FlowConnectorProps extends Props
040      {
041      public static final String ASSERTION_LEVEL = "cascading.flowconnector.assertionlevel";
042      public static final String DEBUG_LEVEL = "cascading.flowconnector.debuglevel";
043      public static final String INTERMEDIATE_SCHEME_CLASS = "cascading.flowconnector.intermediateschemeclass";
044    
045      AssertionLevel assertionLevel;
046      DebugLevel debugLevel;
047      String intermediateSchemeClassName;
048    
049      /**
050       * Method setAssertionLevel sets the target planner {@link cascading.operation.AssertionLevel}.
051       *
052       * @param properties     of type Map<Object, Object>
053       * @param assertionLevel of type AssertionLevel
054       */
055      public static void setAssertionLevel( Map<Object, Object> properties, AssertionLevel assertionLevel )
056        {
057        if( assertionLevel != null )
058          properties.put( ASSERTION_LEVEL, assertionLevel.toString() );
059        }
060    
061      /**
062       * Method setDebugLevel sets the target planner {@link cascading.operation.DebugLevel}.
063       *
064       * @param properties of type Map<Object, Object>
065       * @param debugLevel of type DebugLevel
066       */
067      public static void setDebugLevel( Map<Object, Object> properties, DebugLevel debugLevel )
068        {
069        if( debugLevel != null )
070          properties.put( DEBUG_LEVEL, debugLevel.toString() );
071        }
072    
073      /**
074       * Method setIntermediateSchemeClass is used for debugging.
075       *
076       * @param properties              of type Map<Object, Object>
077       * @param intermediateSchemeClass of type Class
078       */
079      public static void setIntermediateSchemeClass( Map<Object, Object> properties, Class<? extends Scheme> intermediateSchemeClass )
080        {
081        properties.put( INTERMEDIATE_SCHEME_CLASS, intermediateSchemeClass );
082        }
083    
084      /**
085       * Method setIntermediateSchemeClass is used for debugging.
086       *
087       * @param properties              of type Map<Object, Object>
088       * @param intermediateSchemeClass of type String
089       */
090      public static void setIntermediateSchemeClass( Map<Object, Object> properties, String intermediateSchemeClass )
091        {
092        properties.put( INTERMEDIATE_SCHEME_CLASS, intermediateSchemeClass );
093        }
094    
095      public FlowConnectorProps()
096        {
097        }
098    
099      public AssertionLevel getAssertionLevel()
100        {
101        return assertionLevel;
102        }
103    
104      public FlowConnectorProps setAssertionLevel( AssertionLevel assertionLevel )
105        {
106        this.assertionLevel = assertionLevel;
107    
108        return this;
109        }
110    
111      public DebugLevel getDebugLevel()
112        {
113        return debugLevel;
114        }
115    
116      public FlowConnectorProps setDebugLevel( DebugLevel debugLevel )
117        {
118        this.debugLevel = debugLevel;
119    
120        return this;
121        }
122    
123      public String getIntermediateSchemeClassName()
124        {
125        return intermediateSchemeClassName;
126        }
127    
128      public FlowConnectorProps setIntermediateSchemeClassName( String intermediateSchemeClassName )
129        {
130        this.intermediateSchemeClassName = intermediateSchemeClassName;
131    
132        return this;
133        }
134    
135      public FlowConnectorProps setIntermediateSchemeClassName( Class<Scheme> intermediateSchemeClass )
136        {
137        if( intermediateSchemeClass != null )
138          this.intermediateSchemeClassName = intermediateSchemeClass.getName();
139    
140        return this;
141        }
142    
143      @Override
144      protected void addPropertiesTo( Properties properties )
145        {
146        setAssertionLevel( properties, assertionLevel );
147        setDebugLevel( properties, debugLevel );
148        setIntermediateSchemeClass( properties, intermediateSchemeClassName );
149        }
150    
151      }