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.util.ArrayList; 020import java.util.Collections; 021import java.util.List; 022 023import org.conqat.lib.commons.assertion.CCSMAssert; 024import org.conqat.lib.commons.js_export.ExportToJavaScript; 025 026import com.fasterxml.jackson.annotation.JsonCreator; 027import com.fasterxml.jackson.annotation.JsonProperty; 028 029/** 030 * Location identified by a qualified name, which usually is some kind of path 031 * expression. 032 */ 033@ExportToJavaScript 034public class QualifiedNameLocation extends ElementLocation { 035 036 /** Version used for serialization. */ 037 private static final long serialVersionUID = 1; 038 039 /** The name of the JSON property name for {@link #qualifiedName}. */ 040 private static final String QUALIFIED_NAME_PROPERTY = "qualifiedName"; 041 042 /** The name of the JSON property name for {@link #abbreviated}. */ 043 private static final String ABBREVIATED_PROPERTY = "abbreviated"; 044 045 /** The name of the JSON property name for {@link #signalNames}. */ 046 private static final String SIGNAL_NAMES_PROPERTY = "signalNames"; 047 048 /** The qualified name. */ 049 @JsonProperty(QUALIFIED_NAME_PROPERTY) 050 private final String qualifiedName; 051 052 /** 053 * Indicates whether this is abbreviated, i.e. the qualified name is not 054 * expanded to full depth (e.g. because the reference can not be fully 055 * resolved). 056 */ 057 @JsonProperty(ABBREVIATED_PROPERTY) 058 private final boolean abbreviated; 059 060 /** List of signal full names that are going into the location. */ 061 @JsonProperty(SIGNAL_NAMES_PROPERTY) 062 private final List<String> signalNames; 063 064 public QualifiedNameLocation(String qualifiedName, String location, String uniformPath) { 065 this(qualifiedName, location, uniformPath, false); 066 } 067 068 public QualifiedNameLocation(String qualifiedName, String location, String uniformPath, boolean abbreviated) { 069 this(qualifiedName, location, uniformPath, abbreviated, Collections.emptyList()); 070 } 071 072 @JsonCreator 073 public QualifiedNameLocation(@JsonProperty(QUALIFIED_NAME_PROPERTY) String qualifiedName, 074 @JsonProperty(LOCATION_PROPERTY) String location, @JsonProperty(UNIFORM_PATH_PROPERTY) String uniformPath, 075 @JsonProperty(ABBREVIATED_PROPERTY) boolean abbreviated, 076 @JsonProperty(SIGNAL_NAMES_PROPERTY) List<String> signalNames) { 077 super(location, uniformPath); 078 CCSMAssert.isNotNull(qualifiedName); 079 this.qualifiedName = qualifiedName; 080 this.abbreviated = abbreviated; 081 this.signalNames = new ArrayList<>(signalNames); 082 } 083 084 /** Returns the qualified name. */ 085 public String getQualifiedName() { 086 return qualifiedName; 087 } 088 089 @Override 090 public String toLocationString() { 091 return super.toLocationString() + ":" + qualifiedName; 092 } 093 094 /** @see #abbreviated */ 095 public boolean isAbbreviated() { 096 return abbreviated; 097 } 098 099 /** @see #signalNames */ 100 public List<String> getSignalNames() { 101 return signalNames; 102 } 103 104}