本文整理汇总了Java中org.mozilla.javascript.annotations.JSConstructor类的典型用法代码示例。如果您正苦于以下问题:Java JSConstructor类的具体用法?Java JSConstructor怎么用?Java JSConstructor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSConstructor类属于org.mozilla.javascript.annotations包,在下文中一共展示了JSConstructor类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jsConstructor
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
/**
* The Java method defining the JavaScript File constructor.
*
* If the constructor has one or more arguments, and the
* first argument is not undefined, the argument is converted
* to a string as used as the filename.<p>
*
* Otherwise System.in or System.out is assumed as appropriate
* to the use.
*/
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
Function ctorObj,
boolean inNewExpr)
{
File result = new File();
if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
result.name = "";
result.file = null;
} else {
result.name = Context.toString(args[0]);
result.file = new java.io.File(result.name);
}
return result;
}
示例2: Egg
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
/** Creates a Hadoop job with a default configuration of
* TextInputFormat and TextOutputFormat. If invoked with no
* parameters, uses the initially created job as the parent to
* spawn a new job. The name of the parent job is used as the name
* of the child job. The object is used a the 'this' object of the
* eggshell function
* @param o The Hadoop Job
*/
@JSConstructor
public Egg (Object o)
throws IOException
{
Configuration cf = conf; // new Configuration(conf);
job = new Job(cf, name);
job.setJarByClass(this.getClass()); // set jar file
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setOutputKeyClass(Tuple.class); // K2
job.setOutputValueClass(Tuple.class); // V2
job.setMapperClass(Payload.TextMap.class);
job.setReducerClass(Reducer.class);
job.setCombinerClass(Reducer.class);
}
示例3: JSRequestContext
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
@JSConstructor
public JSRequestContext(Context cx, Object[] args,
Function ctorObj,
boolean inNewExpr) {
this.cx = (JSContext) cx;
this.scope = this.cx.getScope();
this.javaContext = (AbstractRequest) args[0];
}
示例4: wrapConstructor
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
/**
* JavaScript constructor.
*
* @param ctx the JavaScript context
* @param args the constructor arguments
* @param ctorObj the constructor function
* @param newExpr if a new expression caused the call
*
* @return the newly constructed configuration wrapper
*/
@JSConstructor
public static Object wrapConstructor(final Context ctx, final Object[] args, final Function ctorObj,
final boolean newExpr) {
Configuration conf;
if (args.length == 0 || !JavaScriptUtils.isDefined(args[0])) {
conf = new Configuration();
} else if (args.length == 1) {
final Object arg0 = args[0];
if (arg0 instanceof Boolean) {
conf = new Configuration((boolean)arg0);
} else if (arg0 instanceof ConfigurationWrap) {
conf = ((ConfigurationWrap)args[0]).conf;
} else {
throw Utils.makeError(ctx, ctorObj, LembosMessages.FIRST_ARG_MUST_BE_BOOL_OR_CONF);
}
} else {
throw Utils.makeError(ctx, ctorObj, LembosMessages.ZERO_OR_ONE_ARG_EXPECTED);
}
ConfigurationWrap wrapper;
if (newExpr) {
wrapper = new ConfigurationWrap();
} else {
wrapper = (ConfigurationWrap)ctx.newObject(ctorObj, CLASS_NAME);
}
wrapper.conf = conf;
return wrapper;
}
示例5: constructor
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
/**
* {@link org.mozilla.javascript.FunctionObject.FunctionObject}
*/
@JSConstructor
public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
if (!inNewExpr)
throw ScriptRuntime.constructError("Range Error", "Call constructor using the \"new\" keyword.");
if (args.length == 1)
return new Range( (int)Context.toNumber(args[0]));
if (args.length == 2)
return new Range( (int)Context.toNumber(args[0]), (int)Context.toNumber(args[1]));
throw ScriptRuntime.constructError("Range Error", "Call constructor with one or two numbers.");
}
示例6: constructor
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
@JSConstructor
public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
if (!inNewExpr)
throw ScriptRuntime.constructError("TagItr Error", "Call constructor using the \"new\" keyword.");
if (args.length == 1)
return new TagItr((TAG_List)Context.jsToJava(args[0], TAG_List.class));
throw ScriptRuntime.constructError("TagItr Error", "Call constructor with a single TAG_List.");
}
示例7: jsConstructorMethod
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
@JSConstructor
public void jsConstructorMethod() {
put("initialized", this, Boolean.TRUE);
}
示例8: Counter
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
@JSConstructor
public Counter(int a) { count = a; }
示例9: wrapConstructor
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
/**
* JavaScript constructor.
*
* @param ctx the JavaScript context
* @param args the constructor arguments
* @param ctorObj the constructor function
* @param newExpr if a new expression caused the call
*
* @return the newly constructed time wrapper
*/
@JSConstructor
public static Object wrapConstructor(final Context ctx, final Object[] args, final Function ctorObj,
final boolean newExpr) {
Job job;
ConfigurationWrap jsConf = null;
try {
if (args.length == 0 || !JavaScriptUtils.isDefined(args[0])) {
job = new Job();
} else if (args.length >= 1) {
if (args[0] instanceof ConfigurationWrap) {
jsConf = (ConfigurationWrap)args[0];
job = new Job(jsConf.getConf());
} else {
throw Utils.makeError(ctx, ctorObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
}
if (args.length >= 2 && JavaScriptUtils.isDefined(args[1])) {
job = new Job(jsConf.getConf(), args[1].toString());
}
} else {
throw Utils.makeError(ctx, ctorObj, LembosMessages.ZERO_ONE_OR_TWO_ARGS_EXPECTED);
}
} catch (IOException e) {
throw Utils.makeError(ctx, ctorObj, e.getMessage());
}
if (!JavaScriptUtils.isDefined(jsConf)) {
jsConf = ConfigurationWrap.getInstance((ScriptRunner)ctx.getThreadLocal(ScriptRunner.RUNNER),
job.getConfiguration());
}
final JobWrap wrapper;
if (newExpr) {
wrapper = new JobWrap();
} else {
wrapper = (JobWrap)ctx.newObject(ctorObj, CLASS_NAME);
}
wrapper.job = job;
wrapper.jsConf = jsConf;
wrapper.runtime = (ScriptRunner)ctx.getThreadLocal(ScriptRunner.RUNNER);
return wrapper;
}
示例10: EggIterator
import org.mozilla.javascript.annotations.JSConstructor; //导入依赖的package包/类
/** Called when a new object is instantiated from this class.
* The new object encapsulates the passed Java iterator object.
* @param o The Java Iterator
* @return The new object
*/
@JSConstructor
public EggIterator (Object o)
{
iterator = (Iterator) o;
}