001    package edu.nrao.sss.model.project.scheduling.constraint;
002    
003    import org.apache.log4j.Logger;
004    
005    
006    public class ConstraintFactory {
007            
008            private static final Logger log = Logger.getLogger( ConstraintFactory.class );
009            
010            private ConstraintFactory(){
011                    
012            }
013            
014            public static Constraint copy( Constraint c ){
015                    Constraint copy = null;
016                    if ( c != null ){
017                            ConstraintType cType = c.getConstraintType();
018                            if ( ConstraintType.API.equals( cType )){
019                                    copy = new ConstraintApi( (ConstraintApi) c );
020                            }
021                            else if ( ConstraintType.WIND.equals( cType )){
022                                    copy = new ConstraintWind( (ConstraintWind) c );
023                            }
024                            else if ( ConstraintType.POSITION_ELEVATION.equals( cType )){
025                                    copy = new ConstraintPositionElevation( (ConstraintPositionElevation) c );
026                            }
027                            else if ( ConstraintType.POSITION_MAXIMUM.equals( cType )){
028                                    copy = new ConstraintPositionMaximum( (ConstraintPositionMaximum) c );
029                            }
030                            else {
031                                    String errorStr = "Unrecognized constraint type: "+cType;
032                                    log.error( errorStr );
033                                    throw new IllegalArgumentException( errorStr );
034                            }
035                    }
036                    return copy;
037            }
038            
039            public static Constraint getConstraint( ConstraintType ct ){
040                    Constraint constraint = null;
041                    if ( ct != null ){
042                            if ( ConstraintType.API.equals( ct )){
043                                    constraint = new ConstraintApi();
044                            }
045                            else if ( ConstraintType.WIND.equals( ct )){
046                                    constraint = new ConstraintWind();
047                            }
048                            else if ( ConstraintType.POSITION_ELEVATION.equals( ct )){
049                                    constraint = new ConstraintPositionElevation();
050                            }
051                            else if ( ConstraintType.POSITION_MAXIMUM.equals( ct )){
052                                    constraint = new ConstraintPositionMaximum();
053                            }
054                            else {
055                                    String errorStr = "Unrecognized constraint type: "+ct;
056                                    log.error( errorStr );
057                                    throw new IllegalArgumentException( errorStr );
058                            }
059                    }
060                    return constraint;
061            }
062            
063    }