001// Copyright 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry.util; 016 017import org.apache.hivemind.Location; 018import org.apache.hivemind.Resource; 019import org.apache.hivemind.util.Defense; 020 021/** 022 * Implementation of {@link org.apache.hivemind.Location} that is used to describe a location within 023 * a resource. This is used when the location within the resource can't be expressed as a line and 024 * column. One example is for setting the location of an annotation. This is useful for line-precise 025 * exception reporting of errors related to annotations. 026 * 027 * @author Howard Lewis Ship 028 * @since 4.0 029 */ 030public class DescribedLocation implements Location 031{ 032 private final Resource _resource; 033 034 private final String _description; 035 036 public DescribedLocation(Resource resource, String description) 037 { 038 Defense.notNull(resource, "resource"); 039 Defense.notNull(description, "description"); 040 041 _resource = resource; 042 _description = description; 043 } 044 045 /** 046 * Returns the description provided in the constructor. 047 */ 048 049 public String toString() 050 { 051 return _description; 052 } 053 054 /** 055 * Returns the resource provided in the constructor. 056 */ 057 058 public Resource getResource() 059 { 060 return _resource; 061 } 062 063 /** 064 * Always returns 0. 065 */ 066 067 public int getLineNumber() 068 { 069 return 0; 070 } 071 072 /** 073 * Always returns 0. 074 */ 075 076 public int getColumnNumber() 077 { 078 return 0; 079 } 080 081 /** 082 * A DescribedLocation is equal to another only if their resources are equal, and their 083 * descriptions are equal. 084 */ 085 public boolean equals(Object other) 086 { 087 if (other instanceof DescribedLocation) 088 { 089 DescribedLocation otherLocation = (DescribedLocation) other; 090 091 return _resource.equals(otherLocation._resource) 092 && _description.equals(otherLocation._description); 093 } 094 095 return false; 096 } 097}