/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.carlomicieli.rest.representations;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MultivaluedMap;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.github.carlomicieli.entities.Railway;
@XmlRootElement(name = "railway",
namespace = "http://schemas.trenako.com/2012/05")
@XmlAccessorType(XmlAccessType.FIELD)
public class RailwayRepresentation {
private final Railway railway;
/**
* Creates a new railway representation.
*/
public RailwayRepresentation() {
this.railway = new Railway();
}
/**
* Creates a new railway representation.
* @param railway the inner railway entity object.
*/
public RailwayRepresentation(Railway railway) {
this.railway = railway;
}
public RailwayRepresentation(MultivaluedMap<String, String> formValues) {
this();
long id = 0;
try {
id = Long.parseLong(formValues.getFirst("id"));
}
catch( NumberFormatException ex ) {}
setId(id);
setName(formValues.getFirst("name"));
setFullName(formValues.getFirst("fullName"));
}
/**
* Returns the inner railway entity object.
* @return the entity object.
*/
public Railway getInner() {
return railway;
}
/**
* Returns the unique id for the <em>Railway</em>.
* @return the unique id.
*/
public long getId() {
return getInner().getId();
}
/**
* Sets the unique id for the <em>Railway</em>.
* @param id the unique id.
*/
public void setId(long id) {
getInner().setId(id);
}
/**
* Returns the railway name.
* @return the railway name.
*/
public String getName() {
return getInner().getName();
}
/**
* Sets the railway name
* @param name the railway name.
*/
public void setName(String name) {
getInner().setName(name);
}
/**
* Returns the full company name.
* @return the full company name.
*/
public String getFullName() {
return getInner().getFullName();
}
/**
* Sets the full company name.
* @param fullName the full company name.
*/
public void setFullName(String fullName) {
getInner().setFullName(fullName);
}
/**
* Compute the ETag for the current player representation.
* @return the ETag value.
*/
public EntityTag tag() {
return new EntityTag(Long.toHexString(this.hashCode()));
}
/**
* Returns a string representation of this <em>BrandRepresentation</em>.
* @return a string representation of the object.
*/
@Override
public int hashCode() {
return new HashCodeBuilder(15, 37)
.append(getName())
.append(getFullName())
.toHashCode();
}
}