1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.indirection;
import java.io.Serializable;
/**
* <p>
* <b>Purpose</b>: Act as a place holder for a variable that required a value holder interface.
* This class should be used to initialze an objects attributes that are using indirection is their mappings.
*/
public class ValueHolder implements WeavedAttributeValueHolderInterface, Cloneable, Serializable {
/**
* Stores the wrapped object.
*/
protected Object value;
/**
* The two variable below are used as part of the implementation of WeavedAttributeValueHolderInterface
* They are used to track whether a valueholder that has been weaved into a class is coordinated
* with the underlying property
*/
// Set internally in TopLink when the state of coordination between a weaved valueholder and the underlying property is known
private boolean isCoordinatedWithProperty = false;
// Used to determine if this ValueHolder was added instantiated as part of the constructor of a weaved class
private boolean isNewlyWeavedValueHolder = false;
/**
* PUBLIC:
* Initialize the holder.
*/
public ValueHolder() {
super();
}
/**
* PUBLIC:
* Initialize the holder with an object.
*/
public ValueHolder(Object value) {
this.value = value;
}
/**
* INTERNAL:
*/
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException exception) {
;
}
return null;
}
/**
* PUBLIC:
* Return the wrapped object.
*/
public Object getValue() {
return value;
}
/**
* Used as part of the implementation of WeavedAttributeValueHolderInterface
* Used to track whether a valueholder that has been weaved into a class is coordinated
* with the underlying property
*/
public boolean isCoordinatedWithProperty(){
return isCoordinatedWithProperty;
}
/**
* Used as part of the implementation of WeavedAttributeValueHolderInterface
* Used to determine if this ValueHolder was added instantiated as part of
* the constructor of a weaved class
*/
public boolean isNewlyWeavedValueHolder(){
return isNewlyWeavedValueHolder;
}
/**
* PUBLIC:
* Return a boolean indicating whether the
* wrapped object has been set or not.
*/
public boolean isInstantiated() {
// Always return true since we consider
// null to be a valid wrapped object.
return true;
}
/**
* Used as part of the implementation of WeavedAttributeValueHolderInterface
* Used to track whether a valueholder that has been weaved into a class is coordinated
* with the underlying property
*
* This method will be called internall when the state of Coordination between the
* weaved valueholder and the underlying value is known
*/
public void setIsCoordinatedWithProperty(boolean coordinated){
this.isCoordinatedWithProperty = coordinated;
// this is not a newly weaved valueholder any more since we have done some coordination work
isNewlyWeavedValueHolder = false;
}
/**
* Used as part of the implementation of WeavedAttributeValueHolderInterface
* Used to determine if this ValueHolder was added instantiated as part of
* the constructor of a weaved class
*
* This method will be called when a ValueHolder is instantiated in a weaved class
*/
public void setIsNewlyWeavedValueHolder(boolean isNew){
this.isNewlyWeavedValueHolder = isNew;
}
/**
* PUBLIC:
* Set the wrapped object.
*/
public void setValue(Object value) {
this.value = value;
}
/**
* INTERNAL:
* Return if add/remove should trigger instantiation or avoid.
* Current instantiation is avoided is using change tracking.
*/
public boolean shouldAllowInstantiationDeferral() {
return false;
}
/**
* INTERNAL:
*/
public String toString() {
if (getValue() == null) {
return "{" + null + "}";
}
return "{" + getValue().toString() + "}";
}
}
|