private < T extends XSString > T createXSString ( Class < T > clazz , String value ) { if ( value == null ) { return null ; } QName elementName = null ; String localName = null ; try { elementName = ( QName ) clazz . getDeclaredField ( "DEFAULT_ELEMENT_NAME" ) . get ( null ) ; localName = ( String ) clazz . getDeclaredField ( "DEFAULT_ELEMENT_LOCAL_NAME" ) . get ( null ) ; } catch ( NoSuchFieldException | IllegalArgumentException | IllegalAccessException | SecurityException e ) { throw new RuntimeException ( e ) ; } XMLObjectBuilder < ? extends XMLObject > builder = XMLObjectProviderRegistrySupport . getBuilderFactory ( ) . getBuilder ( elementName ) ; Object object = builder . buildObject ( new QName ( this . getElementQName ( ) . getNamespaceURI ( ) , localName , this . getElementQName ( ) . getPrefix ( ) ) ) ; T xsstring = clazz . cast ( object ) ; xsstring . setValue ( value ) ; return xsstring ; }
Utility method for creating an OpenSAML object given its type and assigns the value .