@Override public ServiceDescriptor init(ServiceContext context) throws Exception { if (context.getConfig() != null) { List<? extends JSON> routesConfig = context.getConfig().getList("routes", JSON.class); RouterDescriptor routerDescriptor = new RouterDescriptor(); for (JSON routeConfig : routesConfig) { RouteDescriptor routeDescriptor = new RouteDescriptor(routeConfig); routerDescriptor.routes.add(routeDescriptor); } descriptor = routerDescriptor; } return descriptor; }
@Override public ServiceDescriptor init(ServiceContext context) throws Exception { if (context.getConfig() != null) { List<? extends JSON> routesConfig = context.getConfig().getList("routes", JSON.class); RouterDescriptor routerDescriptor = new RouterDescriptor(); for (JSON routeConfig : routesConfig) { RouteDescriptor routeDescriptor = new RouteDescriptor(routeConfig); routerDescriptor.routes.add(routeDescriptor); } descriptor = routerDescriptor; } return descriptor; }
for (String fqn : config.getList("controllers", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR");
for (String fqn : config.getList("controllers", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR");
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }
@Test public void testUnwrapArray() throws Exception { JSON json = new JSON().set("foo", (Object)new String[]{"bar_1", "bar_2"}); assertEquals(Arrays.asList("bar_1", "bar_2"), json.getList("foo")); }
List<? extends JSON> bindings = config.getList("bindings", JSON.class); for (JSON binding : bindings) { String value = binding.getString("value");
List<? extends JSON> bindings = config.getList("bindings", JSON.class); for (JSON binding : bindings) { String value = binding.getString("value");
@Test public void testUnwrapArray() throws Exception { JSON json = new JSON().set("foo", (Object)new String[]{"bar_1", "bar_2"}); assertEquals(Arrays.asList("bar_1", "bar_2"), json.getList("foo")); }
@Test public void testCastToList() throws Exception { assertEquals(Arrays.asList("bar"), new JSON().map("foo", Arrays.asList("bar")).getList("foo")); assertEquals(Arrays.asList("bar"), new JSON().map("foo", Arrays.asList("bar")).getList("foo", String.class)); assertNull(new JSON().getList("foo")); assertNull(new JSON().getList("foo", Boolean.class)); try { new JSON().set("foo", true).getList("foo"); fail(); } catch (ClassCastException ignore) { } try { new JSON().set("foo", true).getList("foo", String.class); fail(); } catch (ClassCastException ignore) { } try { new JSON().map("foo", Arrays.asList("String")).getList("foo", Boolean.class); fail(); } catch (ClassCastException ignore) { } }
@Test public void testCastToList() throws Exception { assertEquals(Arrays.asList("bar"), new JSON().map("foo", Arrays.asList("bar")).getList("foo")); assertEquals(Arrays.asList("bar"), new JSON().map("foo", Arrays.asList("bar")).getList("foo", String.class)); assertNull(new JSON().getList("foo")); assertNull(new JSON().getList("foo", Boolean.class)); try { new JSON().set("foo", true).getList("foo"); fail(); } catch (ClassCastException ignore) { } try { new JSON().set("foo", true).getList("foo", String.class); fail(); } catch (ClassCastException ignore) { } try { new JSON().map("foo", Arrays.asList("String")).getList("foo", Boolean.class); fail(); } catch (ClassCastException ignore) { } }
Map<String, String[]> parameters = new HashMap<String, String[]>(); for (String name : jsonParams.names()) { List<? extends String> value = jsonParams.getList(name, String.class); parameters.put(name, value.toArray(new String[value.size()]));
Map<String, String[]> parameters = new HashMap<String, String[]>(); for (String name : jsonParams.names()) { List<? extends String> value = jsonParams.getList(name, String.class); parameters.put(name, value.toArray(new String[value.size()]));