001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id: ResourceImpl.java 20796 2007-06-19 09:52:03Z sfermigier $
020 */
021
022package org.nuxeo.ecm.platform.relations.api.impl;
023
024import org.nuxeo.ecm.platform.relations.api.NodeType;
025import org.nuxeo.ecm.platform.relations.api.Resource;
026
027/**
028 * Resource.
029 *
030 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
031 */
032public class ResourceImpl extends AbstractNode implements Resource {
033
034    private static final long serialVersionUID = 1L;
035
036    protected String uri;
037
038    public ResourceImpl() {
039    }
040
041    public ResourceImpl(String uri) {
042        this.uri = uri;
043    }
044
045    public String getUri() {
046        return uri;
047    }
048
049    public void setUri(String uri) {
050        this.uri = uri;
051    }
052
053    public NodeType getNodeType() {
054        return NodeType.RESOURCE;
055    }
056
057    @Override
058    public boolean isResource() {
059        return true;
060    }
061
062    @Override
063    public String toString() {
064        return String.format("%s('%s')", getClass().getSimpleName(), uri);
065    }
066
067    @Override
068    public boolean equals(Object other) {
069        if (this == other) {
070            return true;
071        }
072        if (!(other instanceof ResourceImpl)) {
073            return false;
074        }
075        ResourceImpl otherResource = (ResourceImpl) other;
076        return uri == null ? otherResource.uri == null : uri.equals(otherResource.uri);
077    }
078
079    @Override
080    public int hashCode() {
081        return uri.hashCode();
082    }
083
084}