Class JAXBUtil

java.lang.Object
wt.ixb.impl.jaxb.JAXBUtil

public class JAXBUtil extends Object
This class provides methods for operation on JAXB objects, includes: set/get attributes of JAXB object set necessary attributes value for describe element marshall the JAXB object

Supported API: true

Extendable: false
  • Method Details

    • getXmlTagName

      public static QName getXmlTagName(Object rootObject) throws WTException
      get QName of XmlType annotation by object

      Supported API: true
      Parameters:
      rootObject - the jaxb object
      Returns:
      qname
      Throws:
      WTException
    • getXmlTagName

      public static QName getXmlTagName(Object rootObject, boolean throwException) throws WTException
      get QName of XmlType annotation by object

      Supported API: true
      Parameters:
      rootObject - the jaxb object
      throwException - which to throw exception if not found
      Returns:
      qname
      Throws:
      WTException
    • getXmlTagName

      public static QName getXmlTagName(Class<?> clazz) throws WTException
      get QName of XmlType annotation by class

      Supported API: true
      Parameters:
      rootObject - the jaxb object
      Returns:
      qname
      Throws:
      WTException
    • getXmlTagName

      public static QName getXmlTagName(Class<?> clazz, boolean throwException) throws WTException
      get QName of XmlType annotation by class

      Supported API: true
      Parameters:
      rootObject - the jaxb object
      throwException - which to throw exception if not found
      Returns:
      qname
      Throws:
      WTException
    • getPropOrder

      public static String[] getPropOrder(Object rootObject) throws WTException
      get PropOrder of XmlType annotation by object

      Supported API: true
      Parameters:
      rootObject - the jaxb object
      Returns:
      PropOrder
      Throws:
      WTException
    • setObjectValue

      public static void setObjectValue(String type, Object rootObject, String prefix, String key, Object value) throws Exception
      set object value

      Supported API: true
      Parameters:
      format - format type
      rootObject - jaxb object
      prefix - root element name
      key - element name with '/' as seperator
      value - value to be set
      Throws:
      Exception - ,wt.util.WTException
    • setObjectValue

      public static void setObjectValue(String type, Object rootObject, String prefix, String key, Object value, boolean alwaysAdd) throws Exception, WTException
      set object value

      Supported API: true
      Parameters:
      format - format type
      rootObject - jaxb object
      prefix - root element name
      key - element name with '/' as seperator
      value - value to be set
      alwaysAdd - should be always added or replace old one
      Throws:
      Exception - ,wt.util.WTException
      WTException
    • setObjectValue

      public static void setObjectValue(String type, Object rootObject, String prefix, String key, Object value, boolean alwaysAdd, String xmlTagNameToCreateJAXBElement) throws Exception, WTException
      set object value

      Supported API: true
      Parameters:
      format - format type
      rootObject - jaxb object
      prefix - root element name
      key - element name with '/' as seperator
      value - value to be set
      alwaysAdd - should be always added or replace old one
      Throws:
      Exception - ,wt.util.WTException
      WTException
    • normalizeStringForId

      public static String normalizeStringForId(String str)
      normalize the string and set it as id or ref.

      Supported API: true
      Parameters:
      str -
      Returns:
      string
    • getObjectValue

      public static Object getObjectValue(String formatType, Object rootObject, String value) throws Exception
      get object value

      Supported API: true
      Parameters:
      rootObject - jaxb object
      value - element name with '/' as seperator
      Returns:
      object
      Throws:
      Exception
      Exception - ,wt.util.WTException
    • getObjectValue

      public static Object getObjectValue(String formatType, Object rootObject, String value, String tagName, boolean getAsMultiple) throws Exception
      get object value

      Supported API: true
      Parameters:
      rootObject - jaxb object
      value - element name with '/' as seperator
      Returns:
      object
      Throws:
      Exception - ,wt.util.WTException
    • xmlTagNameToClassName

      public static String xmlTagNameToClassName(String tagName)
      change xmlTagName into valid Class name

      Supported API: true
      Parameters:
      tagName - orginal tagName
      Returns:
      className
    • getValidJavaTypeName

      public static String getValidJavaTypeName(String tagName)
      change xmlTagName into valid Java Type Name

      Supported API: true
      Parameters:
      tagName - orginal tagName
      Returns:
      JavaTypeName
    • constructRealValue

      public static Object constructRealValue(String key, String seperator, Object realValue, Object oldValue)
      construct value for mapped attribute

      Supported API: true
      Parameters:
      key - key name
      seperator - seperator
      realValue - value
      oldValue - old key-value pair string
      Returns:
      JavaTypeName
    • getValueMap

      public static Map<String,Object> getValueMap(String seperator, Object oldValue)
      convert key-value pair string into map

      Supported API: true
      Parameters:
      seperator - seperator
      oldValue - old key-value pair string
      Returns:
      map
    • realMarshall

      public static void realMarshall(String type, javax.xml.bind.Marshaller marshaller, Node header, Object o) throws WTException, Exception, javax.xml.bind.JAXBException
      marshall the jaxb object

      Supported API: true
      Parameters:
      type - format type
      marshaller - marshaller instance
      header - the DOM node used to marshall
      o - the jaxb object
      Throws:
      Exception - , wt.util.WTException, javax.xml.bind.JAXBException
      WTException
      javax.xml.bind.JAXBException
    • normalize

      public static void normalize(Node header, Document doc, String formatType) throws WTException
      normalize the node, add xil:nil=true to the ref element

      Supported API: true
      Parameters:
      header - DOM node
      doc - document of the DOM node
      storeInCData - if need to store key-value pair in CData mode, not used now
      formatType - format type
      Throws:
      WTException
    • isSupportedWNCTag

      public static boolean isSupportedWNCTag(String format, String tagName) throws WTException
      check if the element name is a valid Windchill element tag

      Supported API: true
      Parameters:
      format - format type
      tagName - tag name
      Returns:
      boolean
      Throws:
      WTException
    • isSupportedCoreTag

      public static boolean isSupportedCoreTag(String format, String tagName) throws WTException
      check if the element name is a valid element tag

      Supported API: true
      Parameters:
      format - format type
      tagName - tag name
      Returns:
      boolean
      Throws:
      WTException
    • isWNCLinkCoreTag

      public static boolean isWNCLinkCoreTag(String format, String tagName) throws WTException
      check if the element name is a link element tag

      Supported API: true
      Parameters:
      format - format type
      tagName - tag name
      Returns:
      boolean
      Throws:
      WTException
    • isDescribeTagName

      public static boolean isDescribeTagName(String format, String tagName) throws WTException
      check if the element name is a describe element tag

      Supported API: true
      Parameters:
      format - format type
      tagName - tag name
      Returns:
      boolean
      Throws:
      WTException
    • getTagNameById

      public static String getTagNameById(String format, Object object) throws WTException
      try to get windchill tag name by the object

      Supported API: true
      Parameters:
      format - format type
      object - jaxb object
      Returns:
      tag name
      Throws:
      WTException
    • getTagNameById

      public static String getTagNameById(String format, Object object, Object parentObj) throws WTException
      try to get windchill tag name by the object and parent object (if existed)

      Supported API: true
      Parameters:
      format - format type
      object - jaxb object
      parentObj - parent jaxb object
      Returns:
      tag name
      Throws:
      WTException
    • getTagNameById

      public static String getTagNameById(String format, Object object, Object parentObj, boolean throwException) throws WTException
      try to get windchill tag name by the object and parent object (if existed)

      Supported API: true
      Parameters:
      format - format type
      object - jaxb object
      parentObj - parent jaxb object
      throwException - need to throw Exception
      Returns:
      tag name
      Throws:
      WTException
    • getTagNameById

      public static String getTagNameById(String id)
      try to get windchill tag name by the id (localID or ufid)

      Supported API: true
      Parameters:
      id -
      Returns:
      tag name
    • setIdIfNeeded

      public static void setIdIfNeeded(String format, String tagName, Object object, IxbJaxbElement element) throws WTException
      set id if we can't find one.

      Supported API: true
      Parameters:
      format - format type
      tagName - tag name of the jaxb object
      object - jaxb obejct
      Throws:
      WTException
    • setIdIfNeeded

      public static void setIdIfNeeded(String format, String tagName, String idPrefix, Object object) throws WTException
      set id if we can't find one.

      Supported API: true
      Parameters:
      format - format type
      tagName - tag name of the jaxb object
      idPrefix - used to generate id
      object - jaxb obejct
      Throws:
      WTException
    • getElementListFromMap

      public static List<Object> getElementListFromMap(Map<String,Map<String,List<Object>>> valueMap, String elementName, String attributeKey)
      get list from map, will create one if not found.

      Supported API: true
      Parameters:
      elementName -
      Returns:
      list
    • getElementListFromMapForRead

      public static List<Object> getElementListFromMapForRead(Map<String,Map<String,List<Object>>> rootValueMap, Map<String,Map<String,List<Object>>> valueMap, String elementName, String attributeKey, Object contextObject)
      get list from map, will create one if not found.

      Supported API: true
      Parameters:
      elementName -
      Returns:
      list
    • buildKey

      public static String buildKey(String refId, String kind)
      build key by id and kind

      Supported API: true
      Parameters:
      refId -
      kind -
      Returns:
      key
    • getId

      public static String getId(String format, Object rootObject, Object contextObject) throws WTException
      get id of the jaxb object, will generate one and set if no id is defined for the jaxb object

      Supported API: true
      Parameters:
      format - format type
      rootObject - jaxb object
      tagName - tag name of the jaxb object
      Throws:
      WTException
    • getId

      public static String getId(String format, Object rootObject, String tagName, boolean needSet) throws WTException
      get id of the jaxb object, will generate one and set if no id is defined for the jaxb object

      Supported API: true
      Parameters:
      format - format type
      rootObject - jaxb object
      tagName - tag name of the jaxb object
      needSet - if need to set id if no id found
      Throws:
      WTException
    • removeNilAttribute

      public static void removeNilAttribute(Node header)
      remove xil:nil=true attribute during import process.

      Supported API: true
      Parameters:
      header -
    • concatString

      public static String concatString(Object... strings)
      concat string by StringBuilder

      Supported API: true
      Parameters:
      header -
    • getKeyAndValue

      public static String[] getKeyAndValue(String str, String defaultValue, String prefix)
      parse string to key and value, also replace some pre-defined variables

      Supported API: true
      Parameters:
      header -
    • isValidSpecialElement

      public static boolean isValidSpecialElement(String type, String elementName) throws WTException
      check if the mapped element name is valid and special one (contains '||')

      Supported API: true
      Parameters:
      elementName -
      Returns:
      boolean
      Throws:
      WTException
    • setValueSpecially

      public static void setValueSpecially(IxbJaxbElement rootElement, String key, Object realValue) throws WTException
      set value to jaxb specially, may create outer element and add it in RootChildrenMap

      Supported API: true
      Parameters:
      rootElement -
      schemaType -
      rootObject -
      Throws:
      WTException
    • setValueSpecially

      public static void setValueSpecially(IxbJaxbElement rootElement, String key, Object realValue, String orginalKey) throws WTException
      set value to jaxb specially, may create outer element and add it in RootChildrenMap

      Supported API: true
      Parameters:
      rootElement -
      schemaType -
      rootObject -
      orginalKey -
      Throws:
      WTException
    • setValueSpecially

      public static void setValueSpecially(IxbJaxbElement rootElement, String key, Object realValue, String orginalKey, boolean alwaysAdd) throws WTException
      set value to jaxb specially, may create outer element and add it in RootChildrenMap

      Supported API: true
      Parameters:
      rootElement -
      schemaType -
      rootObject -
      orginalKey -
      Throws:
      WTException
    • getValueSpecially

      public static Object getValueSpecially(IxbJaxbElement rootElement, String key) throws WTException
      get value from jaxb specially, corresponding to setValueSpecially

      Supported API: true
      Parameters:
      rootElement -
      key -
      Returns:
      boolean
      Throws:
      WTException
    • getValueSpecially

      public static Object getValueSpecially(IxbJaxbElement rootElement, String key, String orginalKey) throws WTException
      get value from jaxb specially, corresponding to setValueSpecially

      Supported API: true
      Parameters:
      rootElement -
      key -
      orginalKey -
      Returns:
      boolean
      Throws:
      WTException
    • getValueSpecially

      public static Object getValueSpecially(IxbJaxbElement rootElement, String key, String orginalKey, boolean getAsList) throws WTException
      get value from jaxb specially, corresponding to setValueSpecially

      Supported API: true
      Parameters:
      rootElement -
      key -
      orginalKey -
      Returns:
      Throws:
      WTException
    • resolveValue

      public static Object resolveValue(String value, IxbJaxbElement rootElement) throws WTException
      resolve object value like {ROOT}/number

      Supported API: true
      Parameters:
      value -
      rootElement -
      Returns:
      object
      Throws:
      WTException
    • getRequiredAttributes

      public static List<String> getRequiredAttributes(String type, String requiredAttributes) throws WTException
      get root tag required attributes by format type, we will use it init root element during marshall

      Supported API: true
      Parameters:
      type - format type
      Returns:
      set
      Throws:
      WTException