1 /* 2 * (c) Copyright 2006-2020 by rapiddweller GmbH & Volker Bergmann. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, is permitted under the terms of the 6 * GNU General Public License. 7 * 8 * For redistributing this software or a derivative work under a license other 9 * than the GPL-compatible Free Software License as defined by the Free 10 * Software Foundation or approved by OSI, you must first obtain a commercial 11 * license to this software product from rapiddweller GmbH & Volker Bergmann. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS, 15 * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE 17 * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 package com.rapiddweller.model.data; 28 29 import com.rapiddweller.common.operation.FirstArgSelector; 30 31 /** 32 * Describes a reference to an instance of a complex type (see {@link ComplexTypeDescriptor}).<br/> 33 * <br/> 34 * Created: 27.02.2008 16:28:22 35 * 36 * @author Volker Bergmann 37 * @since 0.5.0 38 */ 39 public class ReferenceDescriptor extends ComponentDescriptor { 40 41 private static final String TARGET_TYPE = "targetType"; 42 private static final String TARGET_COMPONENT = "targetComponent"; 43 44 // constructors ---------------------------------------------------------------------------------------------------- 45 46 /** 47 * Instantiates a new Reference descriptor. 48 * 49 * @param name the name 50 * @param provider the provider 51 * @param typeName the type name 52 */ 53 public ReferenceDescriptor(String name, DescriptorProvider provider, 54 String typeName) { 55 this(name, provider, typeName, null, null); 56 } 57 58 /** 59 * Instantiates a new Reference descriptor. 60 * 61 * @param name the name 62 * @param provider the provider 63 * @param typeName the type name 64 * @param targetType the target type 65 * @param targetComponent the target component 66 */ 67 public ReferenceDescriptor(String name, DescriptorProvider provider, 68 String typeName, String targetType, 69 String targetComponent) { 70 // TODO v0.7.2 test non-PK reference 71 super(name, provider, typeName); 72 addConstraint(TARGET_TYPE, String.class, new FirstArgSelector<>()); 73 addConstraint(TARGET_COMPONENT, String.class, new FirstArgSelector<>()); 74 setTargetType(targetType); 75 } 76 77 // properties ------------------------------------------------------------------------------------------------------ 78 79 /** 80 * Gets target type. 81 * 82 * @return the target type 83 */ 84 public String getTargetType() { 85 return (String) getDetailValue(TARGET_TYPE); 86 } 87 88 /** 89 * Sets target type. 90 * 91 * @param targetType the target type 92 */ 93 public void setTargetType(String targetType) { 94 setDetailValue(TARGET_TYPE, targetType); 95 } 96 97 /** 98 * Gets target component. 99 * 100 * @return the target component 101 */ 102 public String getTargetComponent() { 103 return (String) getDetailValue(TARGET_COMPONENT); 104 } 105 106 /** 107 * Sets target component. 108 * 109 * @param targetComponent the target component 110 */ 111 public void setTargetComponent(String targetComponent) { 112 setDetailValue(TARGET_COMPONENT, targetComponent); 113 } 114 115 // convenience-with-methods for construction ----------------------------------------------------------------------- 116 117 /** 118 * With target type reference descriptor. 119 * 120 * @param targetType the target type 121 * @return the reference descriptor 122 */ 123 public ReferenceDescriptor withTargetType(String targetType) { 124 setTargetType(targetType); 125 return this; 126 } 127 128 /** 129 * With target component reference descriptor. 130 * 131 * @param targetComponent the target component 132 * @return the reference descriptor 133 */ 134 public ReferenceDescriptor withTargetComponent(String targetComponent) { 135 setTargetComponent(targetComponent); 136 return this; 137 } 138 139 }