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 @Override 046 public String getUri() { 047 return uri; 048 } 049 050 @Override 051 public void setUri(String uri) { 052 this.uri = uri; 053 } 054 055 @Override 056 public NodeType getNodeType() { 057 return NodeType.RESOURCE; 058 } 059 060 @Override 061 public boolean isResource() { 062 return true; 063 } 064 065 @Override 066 public String toString() { 067 return String.format("%s('%s')", getClass().getSimpleName(), uri); 068 } 069 070 @Override 071 public boolean equals(Object other) { 072 if (this == other) { 073 return true; 074 } 075 if (!(other instanceof ResourceImpl)) { 076 return false; 077 } 078 ResourceImpl otherResource = (ResourceImpl) other; 079 return uri == null ? otherResource.uri == null : uri.equals(otherResource.uri); 080 } 081 082 @Override 083 public int hashCode() { 084 return uri.hashCode(); 085 } 086 087}