001    package com.saelist.command;
002    
003    import com.saelist.stx.*;
004    import com.saelist.stx.parser.*;
005    import com.saelist.util.*;
006    import java.io.*;
007    import java.util.*;
008    import org.apache.log4j.*;
009    
010    /**
011    
012       Provides a basic implementation for Commands. It accepts a set of arguments
013       which is takes to be name=value pairs in the root of the configuration.
014       If name starting with @ will be taken to be the path to a file with
015       additional configuration. [[ The combinde configuration structure is
016       validated against the schema return be getSchema(). The basic implementation
017       of getSchema() assumes a schema file with the name [classname].schema.ls.txt.
018       Descendants can override that. ]]
019    
020    */
021    public abstract class AbstractCommand implements Command {
022    
023      protected static Logger logger = Logger.getLogger("com.saelist.command.AbstractCommand");
024    
025      static {
026        logger.setLevel(Level.ERROR);
027      }
028    
029      protected Pair config;
030    
031      public void setArgs(String[] args) {
032        logger.setLevel(Level.INFO);
033        String text = Strings.join(Arrays.asList(args), " ");
034        logger.info("setArgs(): text='" + text + "'.");
035        try {
036          if(text == null || text.equals(""))
037            return;
038          if(text.charAt(0) == '@')
039            config = LstxParser.parse(Strings.loadFile(text.substring(1)));
040          else
041            config = LstxParser.parse(text);
042          LstxParser.applyBasicProfile(config);
043        } catch(IOException e) {
044          e.printStackTrace();
045        }
046      }
047    
048      public void setArg(String arg) {
049        setArgs(new String[] { arg });
050      }
051    
052      public void undo() {
053        throw new UnsupportedOperationException();
054      }
055    
056      public boolean undoable() {
057        return true;
058      }
059    
060    
061    }