// Path: src/main/java/org/jsoftware/tjconsole/TJContext.java
// public class TJContext extends Observable {
//     private MBeanServerConnection serverConnection;
//     private ObjectName objectName;
//     private final Map<String, Object> environment;
//     private Object serverURL;
//     private int exitCode = 0;
// 
//     public TJContext() {
//         environment = new LinkedHashMap<String, Object>();
//     }
// 
//     public Map<String, Object> getEnvironment() {
//         return Collections.unmodifiableMap(environment);
//     }
// 
//     public void setEnvironmentVariable(String key, Object value, boolean check) {
//         if (check) {
//             if (!environment.containsKey(key)) {
//                 throw new IllegalArgumentException("Invalid key - " + key);
//             }
//             Object old = environment.get(key);
//             if (!old.getClass().equals(value.getClass())) {
//                 value = ConvertUtils.convert(value, old.getClass());
//                 if (!old.getClass().equals(value.getClass())) {
//                     throw new IllegalArgumentException("Invalid value type - " + value.getClass().getName() + " should be " + old.getClass().getName());
//                 }
//             }
//         }
//         Object prev = environment.get(key);
//         if ((value != null && !value.equals(prev)) || (value == null && prev != null)) {
//             setChanged();
//         }
//         notifyObservers(new UpdateEnvironmentEvent(key, prev, value));
//         environment.put(key, value);
//     }
// 
//     public MBeanServerConnection getServer() {
//         return serverConnection;
//     }
// 
//     public void setServer(MBeanServerConnection serverConnection, String url) {
//         this.serverConnection = serverConnection;
//         this.serverURL = url;
//         this.objectName = null;
//     }
// 
//     public ObjectName getObjectName() {
//         return objectName;
//     }
// 
//     public void setObjectName(ObjectName objectName) {
//         this.objectName = objectName;
//     }
// 
//     public boolean isConnected() {
//         return serverConnection != null;
//     }
// 
//     public List<MBeanAttributeInfo> getAttributes() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
//         if (serverConnection == null || objectName == null) {
//             return Collections.emptyList();
//         }
//         MBeanInfo beanInfo = serverConnection.getMBeanInfo(objectName);
//         return Arrays.asList(beanInfo.getAttributes());
//     }
// 
//     public boolean isBeanSelected() {
//         return objectName != null;
//     }
// 
// 
//     public Object getServerURL() {
//         return serverURL;
//     }
// 
//     public void fail(CommandAction action, int code) {
//         if (exitCode == 0) {
//             exitCode = code;
//         }
//     }
// 
//     public int getExitCode() {
//         return exitCode;
//     }
// }
// 
// Path: src/main/java/org/jsoftware/tjconsole/command/CmdDescription.java
// public class CmdDescription implements Serializable {
//     private static final long serialVersionUID = 974727180626249506L;
//     private final String description;
//     private final String full;
//     private final String prefix;
//     private final boolean requiresBean;
// 
//     public CmdDescription(String description, String full, String prefix, boolean requiresBean) {
//         super();
//         this.description = description;
//         this.full = full;
//         this.prefix = prefix;
//         this.requiresBean = requiresBean;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public String getFull() {
//         return full;
//     }
// 
//     public String getPrefix() {
//         return prefix;
//     }
// 
//     public boolean canBeUsed(TJContext tjContext) {
//         return !requiresBean || tjContext.isBeanSelected();
//     }
// 
// 
// }


import jline.console.completer.Completer;
import org.jsoftware.tjconsole.TJContext;
import org.jsoftware.tjconsole.command.CmdDescription;
import java.util.Observable;
package org.jsoftware.tjconsole.command.definition;



/**
 * @author szalik
 */
abstract class AbstractCommandDefinition extends Observable implements CommandDefinition {
    private final CmdDescription description;
    final String prefix;


    AbstractCommandDefinition(String description, String full, String prefix, boolean requiresBean) {
        this.description = new CmdDescription(description, full, prefix, requiresBean);
        this.prefix = prefix;
    }

    @Override
    public boolean matches(String input) {
        return input.trim().startsWith(prefix);
    }

    @Override
    public CmdDescription getDescription() {
        return description;
    }

    @Override
// Path: src/main/java/org/jsoftware/tjconsole/TJContext.java
// public class TJContext extends Observable {
//     private MBeanServerConnection serverConnection;
//     private ObjectName objectName;
//     private final Map<String, Object> environment;
//     private Object serverURL;
//     private int exitCode = 0;
// 
//     public TJContext() {
//         environment = new LinkedHashMap<String, Object>();
//     }
// 
//     public Map<String, Object> getEnvironment() {
//         return Collections.unmodifiableMap(environment);
//     }
// 
//     public void setEnvironmentVariable(String key, Object value, boolean check) {
//         if (check) {
//             if (!environment.containsKey(key)) {
//                 throw new IllegalArgumentException("Invalid key - " + key);
//             }
//             Object old = environment.get(key);
//             if (!old.getClass().equals(value.getClass())) {
//                 value = ConvertUtils.convert(value, old.getClass());
//                 if (!old.getClass().equals(value.getClass())) {
//                     throw new IllegalArgumentException("Invalid value type - " + value.getClass().getName() + " should be " + old.getClass().getName());
//                 }
//             }
//         }
//         Object prev = environment.get(key);
//         if ((value != null && !value.equals(prev)) || (value == null && prev != null)) {
//             setChanged();
//         }
//         notifyObservers(new UpdateEnvironmentEvent(key, prev, value));
//         environment.put(key, value);
//     }
// 
//     public MBeanServerConnection getServer() {
//         return serverConnection;
//     }
// 
//     public void setServer(MBeanServerConnection serverConnection, String url) {
//         this.serverConnection = serverConnection;
//         this.serverURL = url;
//         this.objectName = null;
//     }
// 
//     public ObjectName getObjectName() {
//         return objectName;
//     }
// 
//     public void setObjectName(ObjectName objectName) {
//         this.objectName = objectName;
//     }
// 
//     public boolean isConnected() {
//         return serverConnection != null;
//     }
// 
//     public List<MBeanAttributeInfo> getAttributes() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
//         if (serverConnection == null || objectName == null) {
//             return Collections.emptyList();
//         }
//         MBeanInfo beanInfo = serverConnection.getMBeanInfo(objectName);
//         return Arrays.asList(beanInfo.getAttributes());
//     }
// 
//     public boolean isBeanSelected() {
//         return objectName != null;
//     }
// 
// 
//     public Object getServerURL() {
//         return serverURL;
//     }
// 
//     public void fail(CommandAction action, int code) {
//         if (exitCode == 0) {
//             exitCode = code;
//         }
//     }
// 
//     public int getExitCode() {
//         return exitCode;
//     }
// }
// 
// Path: src/main/java/org/jsoftware/tjconsole/command/CmdDescription.java
// public class CmdDescription implements Serializable {
//     private static final long serialVersionUID = 974727180626249506L;
//     private final String description;
//     private final String full;
//     private final String prefix;
//     private final boolean requiresBean;
// 
//     public CmdDescription(String description, String full, String prefix, boolean requiresBean) {
//         super();
//         this.description = description;
//         this.full = full;
//         this.prefix = prefix;
//         this.requiresBean = requiresBean;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public String getFull() {
//         return full;
//     }
// 
//     public String getPrefix() {
//         return prefix;
//     }
// 
//     public boolean canBeUsed(TJContext tjContext) {
//         return !requiresBean || tjContext.isBeanSelected();
//     }
// 
// 
// }


// Path: src/main/java/org/jsoftware/tjconsole/command/definition/AbstractCommandDefinition.java
import jline.console.completer.Completer;
import org.jsoftware.tjconsole.TJContext;
import org.jsoftware.tjconsole.command.CmdDescription;
import java.util.Observable;

package org.jsoftware.tjconsole.command.definition;



/**
 * @author szalik
 */
abstract class AbstractCommandDefinition extends Observable implements CommandDefinition {
    private final CmdDescription description;
    final String prefix;


    AbstractCommandDefinition(String description, String full, String prefix, boolean requiresBean) {
        this.description = new CmdDescription(description, full, prefix, requiresBean);
        this.prefix = prefix;
    }

    @Override
    public boolean matches(String input) {
        return input.trim().startsWith(prefix);
    }

    @Override
    public CmdDescription getDescription() {
        return description;
    }

    @Override
    public Completer getCompleter(TJContext tjContext) {