com.ibm.portal.streaming.json.xml.helper
Class DefaultJsonSchema

java.lang.Object
  extended by com.ibm.portal.streaming.json.xml.helper.DefaultJsonSchema
All Implemented Interfaces:
JsonSchema

public class DefaultJsonSchema
extends java.lang.Object
implements JsonSchema

Default implementation for JsonSchema that can be used as a convenient superclass for custom implementations

Since:
8.0

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.ibm.portal.streaming.json.xml.JsonSchema
JsonSchema.CARDINALITY, JsonSchema.TYPE
 
Constructor Summary
DefaultJsonSchema()
           
 
Method Summary
 javax.xml.namespace.QName getAssociationKey(java.lang.String uri, java.lang.String localName)
          Returns the key for an association if the cardinality is an assication.
 java.lang.String getAttributeMemberName(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Returns the name of the JSON member for an XML attribute.
 JsonSchema.TYPE getAttributeType(java.lang.String elementUri, java.lang.String elementLocalName, java.lang.String attrUri, java.lang.String attrLocalName)
          Returns the type of an element.
 JsonSchema.CARDINALITY getCardinality(java.lang.String uri, java.lang.String localName)
          Returns the cardinality of an item.
 java.lang.String getElementMemberName(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Returns the name of the JSON member for an XML element.
 JsonSchema.TYPE getElementType(java.lang.String uri, java.lang.String localName)
          Returns the type of an element.
 java.lang.String getTextMemberName(java.lang.Integer idx)
          Returns the name of the JSON member for textual content.
 JsonSchema.TYPE getType(java.lang.String uri, java.lang.String localName)
          Returns the type based on a type identifier.
 java.lang.String getValue(java.lang.String uri, java.lang.String localName, JsonSchema.TYPE type, org.xml.sax.Attributes attr)
          Returns the value of the element for a given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultJsonSchema

public DefaultJsonSchema()
Method Detail

getAssociationKey

public javax.xml.namespace.QName getAssociationKey(java.lang.String uri,
                                                   java.lang.String localName)
Description copied from interface: JsonSchema
Returns the key for an association if the cardinality is an assication. Consider the QName constants defined in com.ibm.portal.resolver.xml.Constants. If the method returns null the json mapping assumes that the attribute xml:id exists and identifies the key.

Specified by:
getAssociationKey in interface JsonSchema
Parameters:
uri - URI of the element
localName - local name of the element
Returns:
the QName for the key, may be null

getAttributeMemberName

public java.lang.String getAttributeMemberName(java.lang.String uri,
                                               java.lang.String localName,
                                               java.lang.String qName)
Description copied from interface: JsonSchema
Returns the name of the JSON member for an XML attribute. If the method returns null the member name will per default be mapped to the qname prefixed by the '@' character.

Specified by:
getAttributeMemberName in interface JsonSchema
Parameters:
uri - the URI
localName - the local name
qName - the qname
Returns:
the name of the JSON member or null

getAttributeType

public JsonSchema.TYPE getAttributeType(java.lang.String elementUri,
                                        java.lang.String elementLocalName,
                                        java.lang.String attrUri,
                                        java.lang.String attrLocalName)
Description copied from interface: JsonSchema
Returns the type of an element.

Specified by:
getAttributeType in interface JsonSchema
Parameters:
elementUri - the URI of the element
elementLocalName - the local name of the element
attrUri - the URI of the attribute
attrLocalName - the local name of the attribute
Returns:
the data type of the element or null if not known

getCardinality

public JsonSchema.CARDINALITY getCardinality(java.lang.String uri,
                                             java.lang.String localName)
Description copied from interface: JsonSchema
Returns the cardinality of an item. If the method returns null the json mapping assume a sequence.

Specified by:
getCardinality in interface JsonSchema
Parameters:
uri - URI of the element
localName - local name of the element
Returns:
the cardinality or null

getElementMemberName

public java.lang.String getElementMemberName(java.lang.String uri,
                                             java.lang.String localName,
                                             java.lang.String qName)
Description copied from interface: JsonSchema
Returns the name of the JSON member for an XML element. If the method returns null, the member name will per default be mapped to the qname

Specified by:
getElementMemberName in interface JsonSchema
Parameters:
uri - the URI
localName - the local name
qName - the qname
Returns:
the name of the JSON member or null

getElementType

public JsonSchema.TYPE getElementType(java.lang.String uri,
                                      java.lang.String localName)
Description copied from interface: JsonSchema
Returns the type of an element.

Specified by:
getElementType in interface JsonSchema
Parameters:
uri - the URI of the element
localName - the local name of the element
Returns:
the data type of the element or null if not known

getTextMemberName

public java.lang.String getTextMemberName(java.lang.Integer idx)
Description copied from interface: JsonSchema
Returns the name of the JSON member for textual content. If multiple text sequences occur that are interruped by an element, each occurrence needs to get its own name. The index counts these occurrences. If the method returns null the name of the first occurrence will be '$t', of the next '$u' and so on.

Specified by:
getTextMemberName in interface JsonSchema
Parameters:
idx - zero based index of the occurrence, not null
Returns:
the name of the JSON member or null

getType

public JsonSchema.TYPE getType(java.lang.String uri,
                               java.lang.String localName)
Description copied from interface: JsonSchema
Returns the type based on a type identifier. Typically this is the value of the xsi:type attribute. If the method returns null the json mapping assumes string.

Specified by:
getType in interface JsonSchema
Parameters:
uri - the URI of the type
localName - the local name of the type
Returns:
the data type of the element or null if not known

getValue

public java.lang.String getValue(java.lang.String uri,
                                 java.lang.String localName,
                                 JsonSchema.TYPE type,
                                 org.xml.sax.Attributes attr)
Description copied from interface: JsonSchema
Returns the value of the element for a given type. If the method returns null the json mapping assumes that the value is stored as CDATA of the element.

Specified by:
getValue in interface JsonSchema
Parameters:
uri - URI of the element
localName - local name of the element
type - type of the element as determined by #getElementType(String, String, Attributes) or JsonSchema.getType(String, String).
attr - the attributes
Returns:
the string value or null to fall back to CDATA