|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.mdrshell;
import java.util.*;
import java.io.*;
import org.openide.util.Lookup;
import org.netbeans.api.mdr.*;
import javax.jmi.reflect.*;
import javax.jmi.model.ModelElement;
import org.netbeans.mdr.storagemodel.*;
import org.netbeans.mdr.handlers.BaseObjectHandler;
/** Shell for metadata repository.
*
* @author Petr Hrebejk
* @version
*/
public class Shell extends Object {
private static final char CONTINUE_CHAR = '\\';
private static final char NEW_LINE = '\n';
/** Holds the preprocesor for this Shell */
private Preprocessor preprocessor;
/** Value indicating wether shell should exit */
private boolean exit;
/** Stack of streams to read from */
private Stack ioStack;
/** Print stream used for this shell. Note that this variable can be
* changed from inside the shell.
*/
public PrintStream out;
/** Says wether the result of commands should be printed */
private boolean resultPrint;
/** Should the commands be echoed */
private boolean commandEcho;
/** String used for prompting the user */
private String prompt;
private Object current;
/** Creates new shell
*/
public Shell() {
preprocessor = new Preprocessor( this );
exit = false;
out = System.out;
ioStack = new Stack();
resultPrint = false;
commandEcho = true;
current = null;
}
private void execCommand(String command) throws Exception {
String preprocessedLine = preprocessor.processLine( command.toString() );
//Support.defaultPrint( 0, Interpreter.processLine( preprocessedLine ) );
if ( commandEcho ) {
out.println( preprocessedLine );
}
Object result = Interpreter.processLine( preprocessedLine );
if ( resultPrint ) {
Support.defaultPrint( out, result );
}
}
// Methods to be used from inside the shell --------------------------------
/** Exits the shell
*/
public void exit() {
System.out.println( "Exiting" );
exit = true;
}
/** Prints object in default format
*/
public void print( Object o ) {
Support.defaultPrint( out, o );
}
public void print( boolean what ) {
out.println( what );
}
public void print( byte what ) {
out.println( what );
}
public void print( short what ) {
out.println( what );
}
public void print( char what ) {
out.println( what );
}
public void print( int what ) {
out.println( what );
}
public void print( long what ) {
out.println( what );
}
public void print( float what ) {
out.println( what );
}
public void print( double what ) {
out.println( what );
}
public Object setActive(Object object) throws Exception {
retype(object);
return object;
}
public void retype(Object object) throws Exception {
execCommand("#define C$ ((" + object.getClass().getName() + ")CurrentObject)");
}
public MDRepository getRepository() throws Exception {
return MDRManager.getDefault().getDefaultRepository();
}
/** get the current prompt
*/
public String getPrompt() {
return prompt;
}
/** Set the string for prompting
*/
public void setPrompt( String prompt ) {
this.prompt = prompt;
}
/** Gets the of current command echoing
*/
public boolean isCommandEcho() {
return commandEcho;
}
/** Sets the command echo
*/
public void setCommandEcho( boolean commandEcho ) {
this.commandEcho = commandEcho;
}
/** Gets the value of result printing
*/
public boolean isResultPrint() {
return resultPrint;
}
/** Sets the command echo
*/
public void setResultPrint( boolean resultPrint ) {
this.resultPrint = resultPrint;
}
// Public methods ----------------------------------------------------------
/** Starts interpretting commands in the InputStream.
* @param is InputStream to read commands from. If
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.