当前位置: 首页>>代码示例>>Java>>正文


Java Link类代码示例

本文整理汇总了Java中com.google.code.siren4j.component.Link的典型用法代码示例。如果您正苦于以下问题:Java Link类的具体用法?Java Link怎么用?Java Link使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Link类属于com.google.code.siren4j.component包,在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLinkByRel

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
/**
 * Retrieve a link by its relationship.
 * @param entity cannot be <code>null</code>.
 * @param rel cannot be <code>null</code> or empty.
 * @return the located link or <code>null</code> if not found.
 */
public static Link getLinkByRel(Entity entity, String... rel) {
    if(entity == null) {
        throw new IllegalArgumentException("entity cannot be null.");
    }
    if(ArrayUtils.isEmpty(rel)) {
        throw new IllegalArgumentException("rel cannot be null or empty");
    }
    List<Link> links = entity.getLinks();
    if (links == null)
        return null;
    Link link = null;
    for (Link l : links) {
        if (ArrayUtils.isNotEmpty(l.getRel()) && ArrayUtils.toString(rel).equals(ArrayUtils.toString(l.getRel()))) {
            link = l;
            break;
        }
    }
    return link;
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:26,代码来源:ComponentUtils.java

示例2: testNoResolveTokens

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Test
//@Ignore
public void testNoResolveTokens() throws Exception {
    // tokens with square brackets around the key should not be resolved to
    // the value
    // they should only end up as normal tokens themselves with square
    // brackets removed.
    Entity ent = ReflectingConverter.newInstance().toEntity(getTestCourse());
    Entity authorsEnt = ComponentUtils.getSubEntityByRel(ent, "authors2");
    // Check to be sure that both normal and parent. tokens get resolved
    // correctly.
    // Resolving: /authors?courseid={parent.courseid}/{offset} where
    // parent.courseid is the course object's field and offset is the
    // collection resources
    // field.
    String expected = "/authors?courseid=testCourseID1/{offset}";
    Link selfLink = ComponentUtils.getLinkByRel(authorsEnt, "self");
    assertEquals(expected, selfLink.getHref());
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:20,代码来源:ReflectingConverterTest.java

示例3: assemble

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
public Object assemble() {
    return EntityBuilder.newInstance().
            setComponentClass("entry-point").
            addLink(LinkBuilder.newInstance().
                    setHref(selfHref()).
                    setRelationship(Link.RELATIONSHIP_SELF).
                    build()).
            addLink(LinkBuilder.newInstance().
                    setHref(HotelsResource.selfURI(uriInfo).toString()).
                    setRelationship("hotels").
                    build()).
            addLink(LinkBuilder.newInstance().
                    setHref(BookingsResource.selfURI(uriInfo).toString()).
                    setRelationship("bookings").
                    build()).
            build();
}
 
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:18,代码来源:SirenEntryPointRepresentationAssembler.java

示例4: builder

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
protected EntityBuilder builder() {
    return EntityBuilder.newInstance().
            setComponentClass("booking").
            addProperty("roomType", booking.getPlace().getCategory().name()).
            addProperty("price", booking.getPrice()).
            addProperty("checkIn", booking.getCheckIn()).
            addProperty("checkOut", booking.getCheckOut()).
            addProperty("includeBreakfast", booking.isIncludeBreakfast()).
            addProperty("paid", booking.getPayment() != null).
            addLink(LinkBuilder.newInstance().
                    setHref(selfHref()).
                    setRelationship(Link.RELATIONSHIP_SELF).
                    build()).
            addLink(LinkBuilder.newInstance().
                    setHref(HotelResource.selfURI(booking.getPlace().getHotel(), uriInfo).toString()).
                    setRelationship("hotel").
                    build());
}
 
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:19,代码来源:BaseBookingRepresentationBuilder.java

示例5: handleSelfLink

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
/**
 * Add the self link to the entity.
 *
 * @param builder assumed not <code>null</code>.
 * @param resolvedUri the token resolved uri. Assumed not blank.
 */
private void handleSelfLink(EntityBuilder builder, String resolvedUri) {
    if (StringUtils.isBlank(resolvedUri)) {
        return;
    }
    Link link = LinkBuilder.newInstance().setRelationship(Link.RELATIONSHIP_SELF).setHref(resolvedUri).build();
    builder.addLink(link);
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:14,代码来源:ReflectingConverter.java

示例6: handleBaseUriLink

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
/**
 * Add the baseUri link to the entity if the baseUri is set on the entity.
 *
 * @param builder assumed not <code>null</code>.
 * @param baseUri the token resolved uri. Assumed not blank.
 */
private void handleBaseUriLink(EntityBuilder builder, String baseUri) {
    if (StringUtils.isBlank(baseUri)) {
        return;
    }
    Link link = LinkBuilder.newInstance().setRelationship(Link.RELATIONSHIP_BASEURI).setHref(baseUri).build();
    builder.addLink(link);
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:14,代码来源:ReflectingConverter.java

示例7: annotationToLink

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
/**
 * Convert a link annotation to an actual link. The href will not be resolved in the instantiated link, this will need
 * to be post processed.
 *
 * @param linkAnno assumed not <code>null</code>.
 * @return new link, never <code>null</code>.
 */
private Link annotationToLink(Siren4JLink linkAnno, EntityContext context) {
    LinkBuilder builder = LinkBuilder.newInstance().setRelationship(linkAnno.rel()).setHref(linkAnno.href());
    if (StringUtils.isNotBlank(linkAnno.title())) {
        builder.setTitle(linkAnno.title());
    }
    if (ArrayUtils.isNotEmpty(linkAnno.linkClass())) {
        builder.setComponentClass(linkAnno.linkClass());
    }
    return builder.build();
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:18,代码来源:ReflectingConverter.java

示例8: validate

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Override
protected void validate(Link obj) {
    String requiredMsg = "Required property.";
    if (obj.getRel() == null || ArrayUtils.isEmpty(obj.getRel())) {
        throw new Siren4JBuilderValidationException("rel", obj.getClass(), requiredMsg);
    }
    if (obj.getHref() == null) {
        throw new Siren4JBuilderValidationException("href", obj.getClass(), requiredMsg);
    }
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:11,代码来源:LinkBuilder.java

示例9: addLink

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
/**
 * Add a link to the entity to be built. Links are optional according to the Siren specification, however
 * an entity should always have a 'self' link to be considered HATEAOS compliant.
 * @param link cannot be <code>null</code> or empty.
 * @return <code>this</code> builder, never <code>null</code>.
 */
public EntityBuilder addLink(Link link) {
	if(link == null) {
		throw new IllegalArgumentException("link cannot be null.");
	}
	addStep("_addLink", new Object[] { link }, true);
    return this;
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:14,代码来源:EntityBuilder.java

示例10: addLinks

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
/**
 * Adds list of links to the entity to be built. Links are optional according to the Siren specification, however
 * an entity should always have a 'self' link to be considered HATEAOS compliant.
 * @param links cannot be <code>null</code>, may be empty.
 * @return <code>this</code> builder, never <code>null</code>.
 */
public EntityBuilder addLinks(List<Link> links) {
	if(links == null) {
		throw new IllegalArgumentException("links cannot be null.");
	}
    for (Link link : links) {
        addLink(link);
    }
    return this;
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:16,代码来源:EntityBuilder.java

示例11: testSubEntityOverrideLinks

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Test
//@Ignore
public void testSubEntityOverrideLinks() throws Exception {
    Entity ent = ReflectingConverter.newInstance().toEntity(getTestCourse());
    Entity subEnt = ComponentUtils.getSubEntityByRel(ent, "firstComment");

    assertNotNull("Should have found sub entity with rel equal to 'firstComment'", subEnt);

    Link courseLink = ComponentUtils.getLinkByRel(subEnt, "course");
    assertEquals("/courses/testCourseID1/overridden", courseLink.getHref());

    Link fooLink = ComponentUtils.getLinkByRel(subEnt, "foo");
    assertNotNull("Expected to find a link named 'foo'", fooLink);

}
 
开发者ID:eserating,项目名称:siren4j,代码行数:16,代码来源:ReflectingConverterTest.java

示例12: testDynamicLinksOverride

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Test
//@Ignore
public void testDynamicLinksOverride() throws Exception {
    Course course = getTestCourse();
    String overriddenHref = "/overridden";
    List<Link> dynamicLinks = new ArrayList<Link>();
    dynamicLinks.add(LinkBuilder.newInstance().setRelationship("reviews").setHref(overriddenHref).build());
    course.setEntityLinks(dynamicLinks);

    Entity ent = ReflectingConverter.newInstance().toEntity(course);

    Link reviewsLink = ComponentUtils.getLinkByRel(ent, "reviews");
    assertEquals(overriddenHref, reviewsLink.getHref());
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:15,代码来源:ReflectingConverterTest.java

示例13: testResolveTokens

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Test
//@Ignore
public void testResolveTokens() throws Exception {
    Entity ent = ReflectingConverter.newInstance().toEntity(getTestCourse());
    Entity authorsEnt = ComponentUtils.getSubEntityByRel(ent, "authors");
    // Check to be sure that both normal and parent. tokens get resolved
    // correctly.
    // Resolving: /authors?courseid={parent.courseid}/{offset} where
    // parent.courseid is the course object's field and offset is the
    // collection resources
    // field.
    String expected = "/authors?courseid=testCourseID1/10";
    Link selfLink = ComponentUtils.getLinkByRel(authorsEnt, "self");
    assertEquals(expected, selfLink.getHref());
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:16,代码来源:ReflectingConverterTest.java

示例14: testBuild

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Test
public void testBuild() throws Exception {
	Link selfLink = LinkBuilder.newInstance()
			.setRelationship(Link.RELATIONSHIP_SELF)
			.setHref("/self/link")
			.build();
	Collection<Integer> coll = new ArrayList<Integer>();
	coll.add(4);
	coll.add(5);
	coll.add(6);
	
	Map<String, String> map = new HashMap<String, String>();
	map.put("key1", "foo");
	map.put("key2", "bar");
	Entity result = builder
			.setComponentClass("test")
			.addProperty("foo", "hello")
			.addProperty("number", 1)
			.addProperty("array", new String[] {"hey", "this", "is", "array"})
			.addProperty("collection", coll)
			.addProperty("map", map)
			.addLink(selfLink)
			.build();
	assertEquals("test", result.getComponentClass()[0]);
	assertEquals(5, result.getProperties().size());
	assertTrue(result.getProperties().containsKey("number"));
	System.out.println(result.toString());
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:29,代码来源:EntityBuilderTest.java

示例15: testNormalBuild

import com.google.code.siren4j.component.Link; //导入依赖的package包/类
@Test
public void testNormalBuild() throws Exception {
	LinkBuilder builder = LinkBuilder.newInstance();
	
	String path = "/some/path";
	Link result = builder.setRelationship(Link.RELATIONSHIP_SELF)
	.setHref(path)
       .setTitle("someTitle")
	.build();
	
	assertEquals(Link.RELATIONSHIP_SELF, result.getRel()[0]);
       assertEquals("someTitle", result.getTitle());
	assertEquals(path, result.getHref());
	
}
 
开发者ID:eserating,项目名称:siren4j,代码行数:16,代码来源:LinkBuilderTest.java


注:本文中的com.google.code.siren4j.component.Link类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。