XCommonImpl.java
/*
** Module : XCommonImpl
** Abstract : SAX attributes, reader, writer common fatures iplementation.
**
** Copyright (c) 2013-2023, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description---------------------------------------
** 001 EVL 20130214 Created initial version. Implementation is limited to the stubs to get the
** converted java code compiled.
** 002 CA 20130221 Added Deletable support. This resource doesn't have NEXT/PREV-SIBLING support.
** 003 OM 20130304 Refactored isValid and isUnknown of WrappedResource to valid and unknown.
** 004 CA 20130603 resourceDelete must return a boolean value.
** 005 EVK 20130903 Made class abstract and move some methods to children. Cosmetic refactoring.
** 006 EVK 20131001 Moved from XEntityImpl next methods:
** invalidArgumentError, invalidArgumentAssignError.
** 007 EVK 20140113 Added method valid and resourceDelete to properly remove the object.
** 008 OM 20201030 Invalid attribute API support for getters/setters.
** 009 VVT 20221003 CommonHandle.getResourceType() method renamed to resourceType() to prevent conflicts
** with namesakes in DMO. See #6694.
** 010 CA 20230215 Improved other cases to reduce BDT usage from within FWD runtime.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program 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 Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
**
** Additional terms under GNU Affero GPL version 3 section 7:
**
** Under Section 7 of the GNU Affero GPL version 3, the following additional
** terms apply to the works covered under the License. These additional terms
** are non-permissive additional terms allowed under Section 7 of the GNU
** Affero GPL version 3 and may not be removed by you.
**
** 0. Attribution Requirement.
**
** You must preserve all legal notices or author attributions in the covered
** work or Appropriate Legal Notices displayed by works containing the covered
** work. You may not remove from the covered work any author or developer
** credit already included within the covered work.
**
** 1. No License To Use Trademarks.
**
** This license does not grant any license or rights to use the trademarks
** Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
** of Golden Code Development Corporation. You are not authorized to use the
** name Golden Code, FWD, or the names of any author or contributor, for
** publicity purposes without written authorization.
**
** 2. No Misrepresentation of Affiliation.
**
** You may not represent yourself as Golden Code Development Corporation or FWD.
**
** You may not represent yourself for publicity purposes as associated with
** Golden Code Development Corporation, FWD, or any author or contributor to
** the covered work, without written authorization.
**
** 3. No Misrepresentation of Source or Origin.
**
** You may not represent the covered work as solely your work. All modified
** versions of the covered work must be marked in a reasonable way to make it
** clear that the modified work is not originating from Golden Code Development
** Corporation or FWD. All modified versions must contain the notices of
** attribution required in this license.
*/
package com.goldencode.p2j.xml;
import com.goldencode.p2j.util.*;
/**
* Implementation the common features for XML related Progress objects.
*/
public abstract class XCommonImpl
extends HandleChain
implements XCommon
{
/** Validation flag. */
protected boolean isValid = true;
// Attributes
/**
* Gets the value of the XML schema file for elements with no namespaces.
*
* @return The value of the nonamespace-schema-location attribute.
* Default value is ""
*/
@Override
public character getNonamespaceSchemaLocation()
{
invalidAttribute("NONAMESPACE-SCHEMA-LOCATION", false);
return new character();
}
/**
* Setting the new value for the nonamespace-schema-location attribute.
*
* @param location
* New value of the nonamespace-schema-location attribute to set.
*/
@Override
public void setNonamespaceSchemaLocation(character location)
{
invalidAttribute("NONAMESPACE-SCHEMA-LOCATION", true);
}
/**
* Setting the new value for the nonamespace-schema-location attribute.
*
* @param location
* New value of the nonamespace-schema-location attribute to set.
*/
@Override
public void setNonamespaceSchemaLocation(String location)
{
setNonamespaceSchemaLocation(new character(location));
}
// Methods
/**
* Adding new match pair for namespace schema and physical file location.
*
* @param namespace
* Target namespace of the schema or am empty string or Unknown value.
* @param location
* Location of the XML schema file.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical addSchemaLocation(String namespace, character location)
{
return addSchemaLocation(new character(namespace), location);
}
/**
* Adding new match pair for namespace schema and physical file location.
*
* @param namespace
* Target namespace of the schema or am empty string or Unknown value.
* @param location
* Location of the XML schema file.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical addSchemaLocation(character namespace, String location)
{
return addSchemaLocation(namespace, new character(location));
}
/**
* Adding new match pair for namespace schema and physical file location.
*
* @param namespace
* Target namespace of the schema or am empty string or Unknown value.
* @param location
* Location of the XML schema file.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical addSchemaLocation(String namespace, String location)
{
return addSchemaLocation(new character(namespace), new character(location));
}
/**
* Adding new match pair for namespace schema and physical file location.
*
* @param namespace
* Target namespace of the schema or am empty string or Unknown value.
* @param location
* Location of the XML schema file.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical addSchemaLocation(character namespace, character location)
{
invalidAttribute("ADD-SCHEMA-LOCATION", false);
return new logical(true);
}
/**
* Removes the specified attribute.
*
* @param name
* The name of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(character name)
{
return removeAttribute(name, new character());
}
/**
* Removes the specified attribute.
*
* @param name
* The name of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(String name)
{
return removeAttribute(new character(name), new character());
}
/**
* Removes the specified attribute.
*
* @param index
* The 1-based index of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(NumberType index)
{
return removeAttribute(index, new character());
}
/**
* Removes the specified attribute.
*
* @param index
* The 1-based index of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(double index)
{
return removeAttribute(new integer(index), new character());
}
/**
* Removes the specified attribute.
*
* @param name
* The name of the attribute to remove.
* @param uri
* The URI of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(String name, String uri)
{
return removeAttribute(new character(name), new character(uri));
}
/**
* Removes the specified attribute.
*
* @param name
* The name of the attribute to remove.
* @param uri
* The URI of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(String name, character uri)
{
return removeAttribute(new character(name), uri);
}
/**
* Removes the specified attribute.
*
* @param index
* The 1-based index of the attribute to remove.
* @param uri
* The URI of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(double index, character uri)
{
return removeAttribute(new integer(index), uri);
}
/**
* Removes the specified attribute.
*
* @param name
* The name of the attribute to remove.
* @param uri
* The URI of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(character name, String uri)
{
return removeAttribute(name, new character(uri));
}
/**
* Removes the specified attribute.
*
* @param index
* The 1-based index of the attribute to remove.
* @param uri
* The URI of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(double index, String uri)
{
return removeAttribute(new integer(index), new character(uri));
}
/**
* Removes the specified attribute.
*
* @param index
* The 1-based index of the attribute to remove.
* @param uri
* The URI of the attribute to remove.
*
* @return The <code>true</code> in case of success <code>false</code> otherwise.
*/
@Override
public logical removeAttribute(NumberType index, String uri)
{
return removeAttribute(index, new character(uri));
}
/**
* Process and display invalid node error. It displays appropriate error message.
*
* @param attribute
* The read-only attribute.
*/
protected void invalidArgumentAssignError(String attribute)
{
if (attribute == null)
{
throw new IllegalArgumentException("The attribute is null !");
}
String msg = "Unable to assign UNKNOWN value to attribute %s on %s widget";
String type = type().toUpperCase();
String err = String.format(msg, attribute.toUpperCase(), type);
ErrorManager.recordOrShowError(4083, err, false, true, false);
}
/**
* Process and display invalid node error. It displays appropriate error message.
*
* @param attribute
* The read-only attribute.
*/
protected void invalidArgumentError(String attribute)
{
if (attribute == null)
{
throw new IllegalArgumentException("The attribute is null !");
}
String msg = "The %s attribute on the %s widget has invalid arguments";
String type = type().toUpperCase();
String err = String.format(msg, attribute.toUpperCase(), type);
ErrorManager.recordOrShowError(4065, err, false, true, false);
}
/**
* Reports if this object is valid for use.
*
* @return <code>true</code> if we are valid (can be used).
*/
@Override
public boolean valid()
{
return isValid;
}
/**
* Delete the resource.
*
* @return <code>true</code> if the resource was deleted.
*/
@Override
protected boolean resourceDelete()
{
isValid = false;
return true;
}
/**
* Check if this resource supports the PREV-SIBLING attribute.
*
* @return Always <code>false</code>.
*/
@Override
protected boolean hasPrevSibling()
{
return false;
}
/**
* Check if this resource supports the NEXT-SIBLING attribute.
*
* @return Always <code>false</code>.
*/
@Override
protected boolean hasNextSibling()
{
return false;
}
}