001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright 2005-2011 The ConQAT Project                                   |
004|                                                                          |
005| Licensed under the Apache License, Version 2.0 (the "License");          |
006| you may not use this file except in compliance with the License.         |
007| You may obtain a copy of the License at                                  |
008|                                                                          |
009|    http://www.apache.org/licenses/LICENSE-2.0                            |
010|                                                                          |
011| Unless required by applicable law or agreed to in writing, software      |
012| distributed under the License is distributed on an "AS IS" BASIS,        |
013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
014| See the License for the specific language governing permissions and      |
015| limitations under the License.                                           |
016+-------------------------------------------------------------------------*/
017package org.conqat.engine.commons.findings.location;
018
019import java.io.Serializable;
020
021import org.conqat.lib.commons.js_export.ExportToJavaScript;
022
023import com.fasterxml.jackson.annotation.JsonCreator;
024import com.fasterxml.jackson.annotation.JsonProperty;
025import com.fasterxml.jackson.annotation.JsonSubTypes;
026import com.fasterxml.jackson.annotation.JsonTypeInfo;
027
028/**
029 * Base class for locations. Locations are immutable and thus return this at
030 * deep cloning.
031 */
032@ExportToJavaScript
033@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = ElementLocation.class)
034@JsonSubTypes({ @JsonSubTypes.Type(value = TextRegionLocation.class, name = "TextRegionLocation"),
035                @JsonSubTypes.Type(value = QualifiedNameLocation.class, name = "QualifiedNameLocation"), })
036public class ElementLocation implements Serializable {
037
038        /** Version used for serialization. */
039        private static final long serialVersionUID = 1;
040
041        /** The name of the JSON property name for {@link #location}. */
042        protected static final String LOCATION_PROPERTY = "location";
043
044        /** The name of the JSON property name for {@link #uniformPath}. */
045        protected static final String UNIFORM_PATH_PROPERTY = "uniformPath";
046
047        /** The location (see {@link #getLocation()}). */
048        @JsonProperty(LOCATION_PROPERTY)
049        private final String location;
050
051        /** The uniform path (see {@link #getUniformPath()}). */
052        @JsonProperty(UNIFORM_PATH_PROPERTY)
053        private final String uniformPath;
054
055        @JsonCreator
056        public ElementLocation(@JsonProperty(LOCATION_PROPERTY) String location,
057                        @JsonProperty(UNIFORM_PATH_PROPERTY) String uniformPath) {
058                this.location = location;
059                this.uniformPath = uniformPath;
060        }
061
062        public ElementLocation(String uniformPath) {
063                this(uniformPath, uniformPath);
064        }
065
066        /**
067         * Get a string that identifies the location of the element, e.g. a file system
068         * path. This location is specific to the running analysis, i.e. depends on time
069         * and the concrete machine ConQAT is running on.
070         */
071        public String getLocation() {
072                return location;
073        }
074
075        /**
076         * Returns the uniform path. This is an artificial path that uniquely defines a
077         * resource across machine boundaries. This should be used for persisted
078         * information.
079         */
080        public String getUniformPath() {
081                return uniformPath;
082        }
083
084        /**
085         * Returns a single line description of the location that is meaningful to the
086         * user.
087         */
088        public String toLocationString() {
089                return getUniformPath();
090        }
091
092        /** {@inheritDoc} */
093        @Override
094        public String toString() {
095                return toLocationString();
096        }
097}