How to use the java.newInstanceSync function in java

To help you get started, we’ve selected a few java examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zuazo / node-jmx / test / adapters / helpers / conversions.js View on Github external
[ -2147483649,    "double"           ],
      [ 4294967295,     "int"              ],
      [ 4294967296,     "double"           ],
      [ 1.5,            "double"           ],
      [ [ "an array" ], "java.lang.Object" ], // TODO: test/fix this

      // java objects
      [ java.newInstanceSync("java.lang.String", "other string"), "java.lang.String" ],
      [ java.newInstanceSync("java.lang.Boolean", "false"),       "boolean"          ],
      [ java.newInstanceSync("java.lang.Integer", "2"),           "int"              ],
      [ java.newInstanceSync("java.lang.Long",    "2"),           "long"             ],
      [ java.newInstanceSync("java.lang.Float",   "2"),           "int"              ],
      [ java.newInstanceSync("java.lang.Float",   "1.5"),         "double"           ],
      [ java.newInstanceSync("java.lang.Double",  "2"),           "int"              ],
      [ java.newInstanceSync("java.lang.Double",  "1.5"),         "double"           ],
      [ java.newInstanceSync("javax.management.Attribute",  "name", "value"), "javax.management.Attribute" ]

    ].forEach(function(value) {
      var param = value[0];
      var javaClass = value[1];

      it("returns \"" + javaClass + "\" for argument value \"" + param + "\" and typeof \"" + typeof param + "\"", function() {
        assert.strictEqual(conversions.v8ToJavaClass(param), javaClass);
      });

    });

    it("throws an exception when the object cannot be converted", function() {
      assert.throws(
        function() {
          conversions.v8ToJavaClass(undefined);
        },
github zuazo / node-jmx / test / adapters / helpers / conversions.js View on Github external
[ "some string",  "java.lang.String" ],
      [ false,          "boolean"          ],
      [ 1,              "int"              ],
      [ -2147483648,    "int"              ],
      [ -2147483649,    "double"           ],
      [ 4294967295,     "int"              ],
      [ 4294967296,     "double"           ],
      [ 1.5,            "double"           ],
      [ [ "an array" ], "java.lang.Object" ], // TODO: test/fix this

      // java objects
      [ java.newInstanceSync("java.lang.String", "other string"), "java.lang.String" ],
      [ java.newInstanceSync("java.lang.Boolean", "false"),       "boolean"          ],
      [ java.newInstanceSync("java.lang.Integer", "2"),           "int"              ],
      [ java.newInstanceSync("java.lang.Long",    "2"),           "long"             ],
      [ java.newInstanceSync("java.lang.Float",   "2"),           "int"              ],
      [ java.newInstanceSync("java.lang.Float",   "1.5"),         "double"           ],
      [ java.newInstanceSync("java.lang.Double",  "2"),           "int"              ],
      [ java.newInstanceSync("java.lang.Double",  "1.5"),         "double"           ],
      [ java.newInstanceSync("javax.management.Attribute",  "name", "value"), "javax.management.Attribute" ]

    ].forEach(function(value) {
      var param = value[0];
      var javaClass = value[1];

      it("returns \"" + javaClass + "\" for argument value \"" + param + "\" and typeof \"" + typeof param + "\"", function() {
        assert.strictEqual(conversions.v8ToJavaClass(param), javaClass);
      });

    });

    it("throws an exception when the object cannot be converted", function() {
github zuazo / node-jmx / test / adapters / javaReflection.js View on Github external
it("emits an error when the object method does not exist", function(done) {
      var obj1 = java.newInstanceSync("javax.management.Attribute", "attributeName1", "value1");
      var paramsClass = [];
      var params = [];
      var methodName = "nonExistentMethod";
      javaReflection.emit = function(ev, data) {
        if (ev === "error" && data.toString().match(/java\.lang\.NoSuchMethodException/)) {
          done();
        }
      };
      javaReflection.invokeMethod(obj1, methodName, paramsClass, params, function() {
        assert(false, "no exception thrown");
      });
    });
github zuazo / node-jmx / test / adapters / mbeanServerConnection.js View on Github external
mbeanServerConnection.mbeanServerConnection.queryMBeans = function(objName, queryObject, callback) {
        var instance = java.newInstanceSync("javax.management.ObjectInstance", "MBean1:type=MBean1", "java.lang.Object");
        var instances = {
          toArray: function(callback) {
            callback(undefined, [instance]);
          }
        };
        callback(undefined, instances);
      };
    }
github mbejda / Nodejs-Stanford-Classifier / index.js View on Github external
});

            child.on('close', function(code){
                console.log('child process closed with code ' + code);
            });

            child.on('exit', function(code) {
              console.log('child process exited with code ' + code);
              self.columnDataClassifier = java.newInstanceSync('edu.stanford.nlp.classify.ColumnDataClassifier', self.properties);
            });

        }
    }

    self.useCDCClassifier = (self.properties.getPropertySync('loadClassifier', '') !== '' || self.properties.getPropertySync('trainFile', '') !== '') ? true : false;
    self.dataSet =   java.newInstanceSync("edu.stanford.nlp.classify.Dataset");

    if (!hasSpawned)
        self.columnDataClassifier = java.newInstanceSync('edu.stanford.nlp.classify.ColumnDataClassifier', self.properties);


};
github mbejda / Nodejs-Stanford-Classifier / index.js View on Github external
stanfordClassifier.prototype.syncClassifier = function() {
    var self = this;
    if(!self.dataSet){
        throw new Error('No dataset found');
    }
    self.classifier =  self.columnDataClassifier.makeClassifierSync(self.dataSet);

    if (self.properties.getPropertySync('serializeTo', '') !== ''){
      var fos = java.newInstanceSync('java.io.FileOutputStream', self.properties.getPropertySync('serializeTo'));
      var oos = java.newInstanceSync('java.io.ObjectOutputStream', fos);
      oos.writeObject(self.classifier, function(){
          oos.closeSync();
      });

    }
};
stanfordClassifier.prototype.classify = function(string) {
github cancerberoSgx / node-lucene / node-lucene / examples / example-7.0.4.js View on Github external
function createDocument(title, content) {
  var fieldStoreYes = java.callStaticMethodSync("org.apache.lucene.document.Field$Store", "valueOf", "YES");
  var doc = java.newInstanceSync("org.apache.lucene.document.Document");
  doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "title", title, fieldStoreYes));
  doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "content", content, fieldStoreYes));
  return doc;
}
github iboxdb / forjava / V171 / nodejdb.js View on Github external
}
    if (this.iteratorSync) {
        return DB.arraySync(this);
    }
    if (this instanceof Array) {
        /*
        if (this.length == 0) { return DB.arraySync(); }
        var r = DB.arraySync(this[0]);
        for (var i = 1; i < this.length; i++) {
            r = DB.arraySync(r, this[i]);
        }
        return r;
        */
        return this;
    }
    var o = java.newInstanceSync("java.util.HashMap");
    for (var f in this) {
        if (typeof (this[f]) == 'function') { continue; }
        o.putSync(f, this[f]);
    }
    return o;
}
function printObjectArray( list ){
github mbejda / Nodejs-Stanford-Classifier / index.js View on Github external
stanfordClassifier.prototype.syncClassifier = function() {
    var self = this;
    if(!self.dataSet){
        throw new Error('No dataset found');
    }
    self.classifier =  self.columnDataClassifier.makeClassifierSync(self.dataSet);

    if (self.properties.getPropertySync('serializeTo', '') !== ''){
      var fos = java.newInstanceSync('java.io.FileOutputStream', self.properties.getPropertySync('serializeTo'));
      var oos = java.newInstanceSync('java.io.ObjectOutputStream', fos);
      oos.writeObject(self.classifier, function(){
          oos.closeSync();
      });

    }
};
stanfordClassifier.prototype.classify = function(string) {
github cancerberoSgx / node-lucene / node-lucene / examples / example-6.0.0.js View on Github external
function createDocument(title, content) {
  var fieldStoreYes = java.callStaticMethodSync("org.apache.lucene.document.Field$Store", "valueOf", "YES");
  var doc = java.newInstanceSync("org.apache.lucene.document.Document");
  doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "title", title, fieldStoreYes));
  doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "content", content, fieldStoreYes));
  return doc;
}