use of java.lang.Class in project ceylon by eclipse.
the class javaSerializationRoundTrip_ method javaSerializationRoundTrip.
public static void javaSerializationRoundTrip() throws Exception {
Class cls = Class.forName("org.eclipse.ceylon.compiler.java.test.interop.sdk.javaSerialization_");
Method meth = cls.getMethod("javaSerialization");
final Object o = meth.invoke(null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(o);
oos.close();
System.err.println("wrote: " + o);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
ObjectInputStream ois = new ObjectInputStream(is);
final Object read = ois.readObject();
System.err.println("read: " + read);
cls = Class.forName("org.eclipse.ceylon.compiler.java.test.interop.sdk.javaSerializationCompare_");
meth = cls.getMethod("javaSerializationCompare", Object.class, Object.class);
meth.invoke(null, o, read);
}
use of java.lang.Class in project javaee7-samples by javaee-samples.
the class TestClient method processRequest.
/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TestServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
List<Class<? extends Encoder>> encoders = new ArrayList<>();
encoders.add(MyMessageEncoder.class);
List<Class<? extends Decoder>> decoders = new ArrayList<>();
decoders.add(MyMessageDecoder.class);
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
String uri = "ws://localhost:" + request.getLocalPort() + request.getContextPath() + "/websocket";
out.println("Connecting to " + uri);
container.connectToServer(MyClient.class, ClientEndpointConfig.Builder.create().encoders(encoders).decoders(decoders).build(), URI.create(uri));
out.println("<br><br>Look in server.log for message exchange between client/server.");
out.println("</body>");
out.println("</html>");
} catch (DeploymentException ex) {
Logger.getLogger(TestClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of java.lang.Class in project groovy-core by groovy.
the class GroovyScriptEngineImpl method eval.
public Object eval(String script, ScriptContext ctx) throws ScriptException {
try {
String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE);
ReferenceBundle bundle = ReferenceBundle.getHardBundle();
if (val != null && val.length() > 0) {
if (val.equalsIgnoreCase("soft")) {
bundle = ReferenceBundle.getSoftBundle();
} else if (val.equalsIgnoreCase("weak")) {
bundle = ReferenceBundle.getWeakBundle();
} else if (val.equalsIgnoreCase("phantom")) {
bundle = ReferenceBundle.getPhantomBundle();
}
}
globalClosures.setBundle(bundle);
} catch (ClassCastException cce) {
/*ignore.*/
}
try {
Class clazz = getScriptClass(script);
if (clazz == null)
throw new ScriptException("Script class is null");
return eval(clazz, ctx);
} catch (SyntaxException e) {
throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine());
} catch (Exception e) {
if (debug)
e.printStackTrace();
throw new ScriptException(e);
}
}
use of java.lang.Class in project groovy-core by groovy.
the class GroovyScriptEngineImpl method getScriptClass.
Class getScriptClass(String script) throws SyntaxException, CompilationFailedException, IOException {
Class clazz = classMap.get(script);
if (clazz != null) {
return clazz;
}
clazz = loader.parseClass(script, generateScriptName());
classMap.put(script, clazz);
return clazz;
}
use of java.lang.Class in project vespa by vespa-engine.
the class DocumentGenPluginTest method pack.
/**
* Packs the given doc to Book
* @param d doc, never null
* @return a Book object or null if input doc isn't a Book
*/
private Book pack(Document d) {
if (!Book.type.getName().equals(d.getDataType().getName()))
return null;
String dataType = d.getDataType().getName();
Class generated;
try {
generated = Class.forName("com.yahoo.vespa.documentgen.test." + className(dataType));
} catch (ClassNotFoundException e) {
return null;
}
if (generated.getAnnotation(com.yahoo.document.Generated.class) == null)
return null;
Book book = new Book(d.getId());
for (Iterator<Map.Entry<Field, FieldValue>> i = d.iterator(); i.hasNext(); ) {
Map.Entry<Field, FieldValue> e = i.next();
Field f = e.getKey();
FieldValue fv = e.getValue();
book.setFieldValue(f, fv);
}
return book;
}
Aggregations