/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
{
//
// Instance variables
//
// index either points to the discriminator or the named member is it exists.
// The currently active member, which is of the same type as the discriminator.
//
// Constructors
//
private DynUnionImpl() {
}
// We can be sure that typeCode is of kind tk_union
}
// We can be sure that typeCode is of kind tk_union
}
protected boolean initializeComponentsFromAny() {
try {
}
return true;
}
// Sets the current position to zero.
// The discriminator value is set to a value consistent with the first named member
// of the union. That member is activated and (recursively) initialized to its default value.
protected boolean initializeComponentsFromTypeCode() {
//System.out.println(this + " initializeComponentsFromTypeCode");
try {
// We can be sure that memberCount() > 0 according to the IDL language spec
index = 0;
currentMemberIndex = 0;
}
return true;
}
//
// Convenience methods
//
try {
}
return discriminatorType;
}
private int memberCount() {
int memberCount = 0;
try {
}
return memberCount;
}
try {
}
return memberLabel;
}
try {
}
return memberType;
}
try {
}
return memberName;
}
private int defaultIndex() {
int defaultIndex = -1;
try {
}
return defaultIndex;
}
int memberCount = memberCount();
for (int i=0; i<memberCount; i++) {
memberLabel = memberLabel(i);
return i;
}
}
if (defaultIndex() != -1) {
return defaultIndex();
}
return NO_INDEX;
}
protected void clearData() {
super.clearData();
// Necessary to guarantee OBJECT_NOT_EXIST in member()
}
//
// DynAny interface methods
//
// _REVISIT_ More efficient copy operation
//
// DynUnion interface methods
//
/**
* Returns the current discriminator value.
*/
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
}
// Sets the discriminator of the DynUnion to the specified value.
// If the TypeCode of the parameter is not equivalent
// to the TypeCode of the unions discriminator, the operation raises TypeMismatch.
//
// Setting the discriminator to a value that is consistent with the currently
// active union member does not affect the currently active member.
// Setting the discriminator to a value that is inconsistent with the currently
// active member deactivates the member and activates the member that is consistent
// with the new discriminator value (if there is a member for that value)
// by initializing the member to its default value.
//
// If the discriminator value indicates a non-existent union member
// this operation sets the current position to 0
// (has_no_active_member returns true in this case).
// Otherwise the current position is set to 1 (has_no_active_member returns false and
// component_count returns 2 in this case).
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
throw new TypeMismatch();
}
if (newCurrentMemberIndex == NO_INDEX) {
clearData();
index = 0;
} else {
// _REVISIT_ Could possibly optimize here if we don't need to initialize components
clearData();
index = 1;
try {
} catch (InconsistentTypeCode ictc) {}
}
}
}
// Sets the discriminator to a value that is consistent with the value
// of the default case of a union; it sets the current position to
// zero and causes component_count to return 2.
// Calling set_to_default_member on a union that does not have an explicit
// default case raises TypeMismatch.
public void set_to_default_member ()
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
int defaultIndex = defaultIndex();
if (defaultIndex == -1) {
throw new TypeMismatch();
}
try {
clearData();
index = 1;
} catch (InconsistentTypeCode ictc) {}
}
// Sets the discriminator to a value that does not correspond
// to any of the unions case labels.
// It sets the current position to zero and causes component_count to return 1.
// Calling set_to_no_active_member on a union that has an explicit default case
// or on a union that uses the entire range of discriminator values
// for explicit case labels raises TypeMismatch.
public void set_to_no_active_member ()
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
// _REVISIT_ How does one check for "entire range of discriminator values"?
if (defaultIndex() != -1) {
throw new TypeMismatch();
}
// erase the discriminators value so that it does not correspond
// to any of the unions case labels
index = 0;
// Necessary to guarantee OBJECT_NOT_EXIST in member()
}
// Returns true if the union has no active member
// (that is, the unions value consists solely of its discriminator because the
// discriminator has a value that is not listed as an explicit case label).
// Calling this operation on a union that has a default case returns false.
// Calling this operation on a union that uses the entire range of discriminator
// values for explicit case labels returns false.
public boolean has_no_active_member () {
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
// _REVISIT_ How does one check for "entire range of discriminator values"?
if (defaultIndex() != -1) {
return false;
}
}
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
return discriminatorType().kind();
}
// Returns the currently active member.
// If the union has no active member, the operation raises InvalidValue.
// Note that the returned reference remains valid only for as long
// as the currently active member does not change.
// Using the returned reference beyond the life time
// of the currently active member raises OBJECT_NOT_EXIST.
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
throw new InvalidValue();
return currentMember;
}
// Returns the name of the currently active member.
// If the unions TypeCode does not contain a member name for the currently active member,
// the operation returns an empty string.
// Calling member_name on a union without an active member raises InvalidValue.
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
throw new InvalidValue();
}
// Returns the TCKind value of the TypeCode of the currently active member.
// If the union has no active member, the operation raises InvalidValue.
{
if (status == STATUS_DESTROYED) {
throw wrapper.dynAnyDestroyed() ;
}
throw new InvalidValue();
}
}