com.genologics.ri.configuration.FieldLink.java Source code

Java tutorial

Introduction

Here is the source code for com.genologics.ri.configuration.FieldLink.java

Source

/*
 * CRUK-CI Genologics REST API Java Client.
 * Copyright (C) 2013 Cancer Research UK Cambridge Institute.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.genologics.ri.configuration;

import java.io.Serializable;
import java.net.URI;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.beanutils.PropertyUtils;

import com.genologics.ri.LimsLink;
import com.genologics.ri.Linkable;

/**
 *
 * Field definition represents a user-defined field configured in the parent
 * entity. It includes the name and a URI linking to the detailed representation
 * of the configuration of a user defined field.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "field-link")
public class FieldLink implements LimsLink<Field>, Serializable {
    private static final long serialVersionUID = 5031274064780081067L;

    @XmlAttribute(name = "name")
    protected String name;

    @XmlAttribute(name = "uri")
    @XmlSchemaType(name = "anyURI")
    protected URI uri;

    public FieldLink() {
    }

    public FieldLink(URI uri) {
        this.uri = uri;
    }

    public FieldLink(URI uri, String name) {
        this.name = name;
        this.uri = uri;
    }

    public FieldLink(Linkable<Field> link) {
        uri = link.getUri();
        try {
            this.name = (String) PropertyUtils.getProperty(link, "name");
        } catch (Exception e) {
            // Ignore.
        }
    }

    @Override
    public Class<Field> getEntityClass() {
        return Field.class;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public URI getUri() {
        return uri;
    }

    public void setUri(URI uri) {
        this.uri = uri;
    }

    @Override
    public String toString() {
        return name;
    }
}