public Name getParent() { if (parent == null) { if (size == 1) { parent = EMPTY; } else if (size() > 1) { parent = new Name(value.substring(0, value.length() - 1 - identifiers[size - 1].length()), identifiers, size - 1); } } return parent; }
public Name getParent() { if (parent == null) { if (size == 1) { parent = EMPTY; } else if (size() > 1) { parent = new Name(value.substring(0, value.length() - 1 - identifiers[size - 1].length()), identifiers, size - 1); } } return parent; }
public String getCanonical() { if (canonical == null) { StringBuilder sb = new StringBuilder(); if (isAbsolute()) { sb.append('/'); } for (int i = 0;i < name.size();i++) { if (i > 0) { sb.append('/'); } sb.append(name.get(i)); } String ext = getExt(); if (ext != null) { sb.append('.').append(ext); } canonical = sb.toString(); } return canonical; }
public String getCanonical() { if (canonical == null) { StringBuilder sb = new StringBuilder(); if (isAbsolute()) { sb.append('/'); } for (int i = 0;i < name.size();i++) { if (i > 0) { sb.append('/'); } sb.append(name.get(i)); } String ext = getExt(); if (ext != null) { sb.append('.').append(ext); } canonical = sb.toString(); } return canonical; }
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 testSimple() { Name simple = Name.parse("a"); assertEquals(1, simple.size()); assertEquals(1, simple.length()); assertEquals(Collections.singletonList("a"), Tools.list(simple)); Name parent = simple.getParent(); assertEquals(0, parent.size()); assertEquals(0, parent.length()); assertEquals("a", simple.toString()); }
@Test public void testSimple() { Name simple = Name.parse("a"); assertEquals(1, simple.size()); assertEquals(1, simple.length()); assertEquals(Collections.singletonList("a"), Tools.list(simple)); Name parent = simple.getParent(); assertEquals(0, parent.size()); assertEquals(0, parent.length()); assertEquals("a", simple.toString()); }
@Test public void testEmpty() { Name empty = Name.parse(""); assertEquals(0, empty.size()); assertEquals(0, empty.length()); assertEquals(Collections.emptyList(), Tools.list(empty)); assertNull(empty.getParent()); assertEquals("", empty.toString()); }
@Test public void testEmpty() { Name empty = Name.parse(""); assertEquals(0, empty.size()); assertEquals(0, empty.length()); assertEquals(Collections.emptyList(), Tools.list(empty)); assertNull(empty.getParent()); assertEquals("", empty.toString()); }
@Test public void testParent() { Name abc = Name.parse("a.b.c"); Name ab = abc.getParent(); assertEquals(Name.parse("a.b"), ab); Name a = ab.getParent(); assertEquals(a, ab.getParent()); assertEquals(Name.parse("a"), a); Name empty = a.getParent(); assertEquals(Name.parse(""), empty); assertEquals(0, empty.size()); assertEquals(0, empty.length()); assertEquals((Object)null, empty.getParent()); }
@Test public void testParent() { Name abc = Name.parse("a.b.c"); Name ab = abc.getParent(); assertEquals(Name.parse("a.b"), ab); Name a = ab.getParent(); assertEquals(a, ab.getParent()); assertEquals(Name.parse("a"), a); Name empty = a.getParent(); assertEquals(Name.parse(""), empty); assertEquals(0, empty.size()); assertEquals(0, empty.length()); assertEquals((Object)null, empty.getParent()); }