com.sage.orion.sdata.servlet.accpac
Class ReferencedResource

java.lang.Object
  extended by com.sage.orion.sdata.servlet.accpac.JiBXConfigurationAbstractResource
      extended by com.sage.orion.sdata.servlet.accpac.ReferencedResource
All Implemented Interfaces:
JiBXConfigurationResource

public final class ReferencedResource
extends JiBXConfigurationAbstractResource

The ReferencedResource class defines how a Resource references some other Resource. This is in terms of what SData calls a "reference" relationship, and is sometimes known as a 'foreign' relationship.

The class is intended for use by the JiBX parser during the parsing of the configuration files. As such it will be constructed and populated during the parsing phase, and the configuration errors will then be retrieved. Only then will it be queried. This means that the setters can only be called during the parsing phase, and any getter, including JiBXConfigurationAbstractResource.getConfigurationErrors(), ends that phase.

The class is used in two different ways (perhaps at the same time). It is used to provide "lookup fields" and it is used to provide "related resources".

In both cases the ReferencedResource will have a name, available via the getName() getter. Also in both cases the getReferencedKeyFields() method returns which fields in this resource map to the primary key of the referenced resource.

When used for lookup fields the getLookupFields() returns the information to allow the caller to map fields of the related resource to mirroring fields in this resource.

When used for "related resources" the getProperty() method returns the name of the property in this resource which corresponds to the referenced resource. In this case the getDescription() provides a description for the property, for use as a label.


Constructor Summary
ReferencedResource()
           
 
Method Summary
 void addLookupField(LookupField field)
          adds the given field to the list of lookup fields.
 void addReferencedKeyField(ReferencedKeyField field)
          adds the given field to the list of lookup fields.
 java.lang.String getDescription()
          returns the description of the referenced resource, the value that can be used as a label for the property in schemas.
 java.util.Collection<? extends java.lang.String> getLookupFieldNames()
          returns a collection view of all the exposed SData names of the lookup fields in this referenced resource.
 java.util.Collection<LookupField> getLookupFields()
          returns an unmodifiable view of the lookup fields defined for the referenced resource
 java.lang.String getName()
          returns the name of the referenced resource.
 java.lang.String getProperty()
          gets the 'property', the name that this referenced resource has in the resource referring to it.
 java.util.List<ReferencedKeyField> getReferencedKeyFields()
          returns an unmodifiable view of the referenced key fields defined for the referenced resource.
 boolean isForRelatedResource()
          returns whether this instance is configured to support a related resource.
 boolean keyUsesField(java.lang.String name)
          gets whether the given field name is in the key to a related resource
 boolean keyUsesFields(java.util.Set<java.lang.String> fieldNames)
          checks to see if this reference uses any of the specified fields.
protected  void onEndBuilding()
          change from building mode into querying mode.
 void setDescription(java.lang.String description)
          sets the description of the referenced resource, the value that can be used as a label for the property in schemas.
 void setName(java.lang.String name)
          sets the name of the referenced resource.
 void setProperty(java.lang.String property)
          sets the property, the name that this referenced resource has in the resource referring to it.
 
Methods inherited from class com.sage.orion.sdata.servlet.accpac.JiBXConfigurationAbstractResource
addConfigurationError, endBuilding, ensureStillBuilding, getConfigurationErrors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReferencedResource

public ReferencedResource()
Method Detail

addLookupField

public void addLookupField(LookupField field)
adds the given field to the list of lookup fields.

This list is returned by getLookupFields().

Parameters:
field - the non-null field to add

addReferencedKeyField

public void addReferencedKeyField(ReferencedKeyField field)
adds the given field to the list of lookup fields.

This list is returned by getReferencedKeyFields().

Parameters:
field - the non-null field to add

getLookupFields

public java.util.Collection<LookupField> getLookupFields()
returns an unmodifiable view of the lookup fields defined for the referenced resource

Returns:
an unmodifiable view of the lookup fields defined for the referenced resource

getName

public java.lang.String getName()
returns the name of the referenced resource.

This is the same as provided to setName(String), except trimmed.

Returns:
a String containing the trimmed name.

keyUsesFields

public boolean keyUsesFields(java.util.Set<java.lang.String> fieldNames)
checks to see if this reference uses any of the specified fields. This is particularly useful for deciding if the reference has changed due to a change in the referring fields

Parameters:
fieldNames - the names of the fields to check for. The set will not be modified.
Returns:
true if the key uses at least one of the specified fields
See Also:
keyUsesField(String)

keyUsesField

public boolean keyUsesField(java.lang.String name)
gets whether the given field name is in the key to a related resource

Parameters:
name - the internal name of the field which might be in the key
Returns:
true if the named field is in the key
See Also:
ReferencedKeyField.getViewFieldName(), keyUsesFields(Set)

getReferencedKeyFields

public java.util.List<ReferencedKeyField> getReferencedKeyFields()
returns an unmodifiable view of the referenced key fields defined for the referenced resource.

These fields map in the order defined to the key fields of the related resource.

Returns:
an unmodifiable view of the referenced key fields defined for the referenced resource

setName

public void setName(java.lang.String name)
sets the name of the referenced resource.

Parameters:
name - the name of the referenced resource. This must be non-null and non-empty (after trimming)

onEndBuilding

protected void onEndBuilding()
change from building mode into querying mode.

Specified by:
onEndBuilding in class JiBXConfigurationAbstractResource

getLookupFieldNames

public java.util.Collection<? extends java.lang.String> getLookupFieldNames()
returns a collection view of all the exposed SData names of the lookup fields in this referenced resource.

Returns:
a non-null Collection of Strings containing the names of the lookup fields.

getProperty

public java.lang.String getProperty()
gets the 'property', the name that this referenced resource has in the resource referring to it. This will be null if this ReferencedResource is not providing a reference to a related resource.

Returns:
the property
See Also:
isForRelatedResource()

isForRelatedResource

public boolean isForRelatedResource()
returns whether this instance is configured to support a related resource. It returns false if the instance is configured only for lookup fields.

when this is true getProperty() will return a non-null value.

Returns:
true if this instance can be used to support related resources

setProperty

public void setProperty(java.lang.String property)
sets the property, the name that this referenced resource has in the resource referring to it.

Parameters:
property - the property to set, which may be null or non-blank, but must not be blank
See Also:
getDescription(), getProperty(), isForRelatedResource()

getDescription

public java.lang.String getDescription()
returns the description of the referenced resource, the value that can be used as a label for the property in schemas.

This is equal to the trimmed version of the value passed to setDescription(String), and will be null if a null value was passed.

Returns:
the description
See Also:
getDescription(), getProperty()

setDescription

public void setDescription(java.lang.String description)
sets the description of the referenced resource, the value that can be used as a label for the property in schemas.

Setting the description when the property is not set results in a configuration error.

Parameters:
description - the description to set, which may be null or blank.
See Also:
getDescription()


Copyright © 2011 Sage Software, Inc. All rights reserved.