当前位置: 首页>>代码示例>>Java>>正文


Java XMLObjectBuilder.buildObject方法代码示例

本文整理汇总了Java中org.opensaml.xml.XMLObjectBuilder.buildObject方法的典型用法代码示例。如果您正苦于以下问题:Java XMLObjectBuilder.buildObject方法的具体用法?Java XMLObjectBuilder.buildObject怎么用?Java XMLObjectBuilder.buildObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opensaml.xml.XMLObjectBuilder的用法示例。


在下文中一共展示了XMLObjectBuilder.buildObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Constructs the XMLObject that the given DOM Element will be unmarshalled into. If the DOM element has an XML
 * Schema type defined this method will attempt to retrieve an XMLObjectBuilder, from the factory given at
 * construction time, using the schema type. If no schema type is present or no builder is registered with the
 * factory for the schema type, the elements QName is used. Once the builder is found the XMLObject is create by
 * invoking {@link XMLObjectBuilder#buildObject(String, String, String)}. Extending classes may wish to override
 * this logic if more than just schema type or element name (e.g. element attributes or content) need to be used to
 * determine which XMLObjectBuilder should be used to create the XMLObject.
 * 
 * @param domElement the DOM Element the created XMLObject will represent
 * 
 * @return the empty XMLObject that DOM Element can be unmarshalled into
 * 
 * @throws UnmarshallingException thrown if there is now XMLObjectBuilder registered for the given DOM Element
 */
protected XMLObject buildXMLObject(Element domElement) throws UnmarshallingException {
    if (log.isTraceEnabled()) {
        log.trace("Building XMLObject for {}", XMLHelper.getNodeQName(domElement));
    }
    XMLObjectBuilder xmlObjectBuilder;

    xmlObjectBuilder = xmlObjectBuilderFactory.getBuilder(domElement);
    if (xmlObjectBuilder == null) {
        xmlObjectBuilder = xmlObjectBuilderFactory.getBuilder(Configuration.getDefaultProviderQName());
        if (xmlObjectBuilder == null) {
            String errorMsg = "Unable to locate builder for " + XMLHelper.getNodeQName(domElement);
            log.error(errorMsg);
            throw new UnmarshallingException(errorMsg);
        } else {
            if (log.isTraceEnabled()) {
                log.trace("No builder was registered for {} but the default builder {} was available, using it.",
                        XMLHelper.getNodeQName(domElement), xmlObjectBuilder.getClass().getName());
            }
        }
    }

    return xmlObjectBuilder.buildObject(domElement);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:AbstractXMLObjectUnmarshaller.java

示例2: createXSString

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Utility method for creating an OpenSAML object given its type and assigns the value.
 * 
 * @param clazz
 *          the class to create
 * @param value
 *          the string value to assign
 * @return the XML object or {@code null} if value is {@code null}
 */
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<?> builder = Configuration.getBuilderFactory().getBuilder(elementName);
  XMLObject object = builder.buildObject(new QName(this.getElementQName().getNamespaceURI(), localName, this.getElementQName().getPrefix()));
  T xsstring = clazz.cast(object);
  xsstring.setValue(value);
  return xsstring;
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:29,代码来源:CurrentAddressStructuredTypeImpl.java

示例3: createAttributeStatement

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
private static AttributeStatement createAttributeStatement() {

		AttributeStatement attributeStatement = create(AttributeStatement.DEFAULT_ELEMENT_NAME);

		for (AttributeData attributeData : samlResponseData.getAttributes()) {
			Attribute attribute = create(Attribute.DEFAULT_ELEMENT_NAME);
			attribute.setFriendlyName(attributeData.getFriendlyName());
			attribute.setName(attributeData.getName());
			attribute.setNameFormat(attributeData.getNameFormat());

			XMLObjectBuilder<XSAny> builder = getXMLObjectBuilder(XSAny.TYPE_NAME);

			for (String values : attributeData.getValue().split(";", -1)) {
				XSAny value = builder
						.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);

				value.setTextContent(values);

				attribute.getAttributeValues().add(value);
			}

			attributeStatement.getAttributes().add(attribute);
		}
		return attributeStatement;
	}
 
开发者ID:vetsin,项目名称:SamlSnort,代码行数:26,代码来源:SamlTool.java

示例4: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Create XMLObject from a given QName
 *
 * @param objectQName: QName of the object to be built into a XMLObject
 * @return built xmlObject
 * @throws EntitlementException
 */
private static XMLObject buildXMLObject(QName objectQName) throws EntitlementException {

    XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(objectQName);
    if (builder == null) {
        throw new EntitlementException("Unable to retrieve builder for object QName "
                + objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
            objectQName.getPrefix());
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:18,代码来源:WSXACMLMessageReceiver.java

示例5: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Builds SAML Elements
 *
 * @param objectQName
 * @return
 * @throws SSOAgentException
 */
private static XMLObject buildXMLObject(QName objectQName) throws SSOAgentException {
    doBootstrap();
    XMLObjectBuilder builder =
            org.opensaml.xml.Configuration.getBuilderFactory()
                    .getBuilder(objectQName);
    if (builder == null) {
        throw new SSOAgentException("Unable to retrieve builder for object QName " +
                objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
            objectQName.getPrefix());
}
 
开发者ID:wso2-extensions,项目名称:identity-agent-sso,代码行数:20,代码来源:SSOAgentUtils.java

示例6: createSamlObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Utility method for creating an OpenSAML object given its element name.
 * 
 * @param clazz
 *          the class to create
 * @param elementName
 *          the element name for the XML object to create
 * @return the XML object
 */
public static <T extends XMLObject> T createSamlObject(Class<T> clazz, QName elementName) {
  if (!XMLObject.class.isAssignableFrom(clazz)) {
    throw new RuntimeException(String.format("%s is not a XMLObject class", clazz.getName()));
  }
  XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
  XMLObjectBuilder<?> builder = builderFactory.getBuilder(elementName);
  if (builder == null) {
    // No builder registered for the given element name. Try creating a builder for the default element name.
    builder = builderFactory.getBuilder(getDefaultElementName(clazz));
  }
  Object object = builder.buildObject(elementName);
  return clazz.cast(object);
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:23,代码来源:OpenSAMLTestBase.java

示例7: testTransliteratedAttribute

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Test creating and marshalling/unmarshalling an attribute with a name represented in two ways.
 * 
 * @throws Exception
 *           for errors
 */
@Test
public void testTransliteratedAttribute() throws Exception {
  Attribute attribute = OpenSAMLTestBase.createSamlObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME);
  attribute.setName(AttributeConstants.EIDAS_CURRENT_FAMILY_NAME_ATTRIBUTE_NAME);
  attribute.setNameFormat(Attribute.URI_REFERENCE);

  XMLObjectBuilder<CurrentFamilyNameType> builder = OpenSAMLTestBase.getBuilder(CurrentFamilyNameType.TYPE_NAME);

  CurrentFamilyNameType name1 = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, CurrentFamilyNameType.TYPE_NAME);
  name1.setValue("Onasis");

  CurrentFamilyNameType name2 = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, CurrentFamilyNameType.TYPE_NAME);
  name2.setValue("Ωνασης");
  name2.setLatinScript(false);

  attribute.getAttributeValues().add(name1);
  attribute.getAttributeValues().add(name2);

  Element xml = OpenSAMLTestBase.marshall(attribute);

  Attribute attribute2 = OpenSAMLTestBase.unmarshall(xml, Attribute.class);
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(0)).getValue(), ((CurrentFamilyNameType) attribute2
    .getAttributeValues().get(0)).getValue());
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(1)).getValue(), ((CurrentFamilyNameType) attribute2
    .getAttributeValues().get(1)).getValue());

  // Unmarshall again, but this time from the XML string ...
  String xmlString = XMLHelper.prettyPrintXML(xml);

  Attribute attribute3 = (Attribute) OpenSAMLTestBase.unmarshallFromInputStream(Configuration.getParserPool(),
    new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(0)).getValue(), ((CurrentFamilyNameType) attribute3
    .getAttributeValues().get(0)).getValue());
  Assert.assertEquals(((CurrentFamilyNameType) attribute.getAttributeValues().get(1)).getValue(), ((CurrentFamilyNameType) attribute3
    .getAttributeValues().get(1)).getValue());
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:43,代码来源:CurrentFamilyNameTypeTest.java

示例8: testAttributeCreate

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Test that creates an attribute and places a CurrentAddessType as a value.
 * 
 * @throws Exception
 *           for errors
 */
@Test
public void testAttributeCreate() throws Exception {

  Attribute attribute = OpenSAMLTestBase.createSamlObject(Attribute.class, Attribute.DEFAULT_ELEMENT_NAME);
  attribute.getNamespaceManager().registerNamespaceDeclaration(new Namespace(EidasConstants.EIDAS_NP_NS, "eidas"));
  attribute.setName(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME);
  attribute.setFriendlyName(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME);
  attribute.setNameFormat(Attribute.URI_REFERENCE);

  XMLObjectBuilder<CurrentAddressType> builder = OpenSAMLTestBase.getBuilder(CurrentAddressType.TYPE_NAME);
  CurrentAddressType address = builder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, 
    new QName(EidasConstants.EIDAS_NP_NS, CurrentAddressType.TYPE_NAME.getLocalPart(), "eidas"));
  fill(address);

  attribute.getAttributeValues().add(address);

  Element attrElement = OpenSAMLTestBase.marshall(attribute);

  System.out.println(XMLHelper.prettyPrintXML(attrElement));

  // Make sure we inserted the correct namespace prefix while marshalling the CurrentAddressType
  Assert.assertTrue((new String(Base64.decode(attrElement.getFirstChild().getFirstChild().getNodeValue()))).startsWith("<eidas:"));

  // Unmarshall
  Attribute attribute2 = OpenSAMLTestBase.unmarshall(attrElement, Attribute.class);

  Assert.assertNotNull(attribute2);
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_NAME, attribute2.getName());
  Assert.assertEquals(AttributeConstants.EIDAS_CURRENT_ADDRESS_ATTRIBUTE_FRIENDLY_NAME, attribute2.getFriendlyName());

  List<XMLObject> values = attribute.getAttributeValues();
  Assert.assertTrue(values.size() == 1);
  Assert.assertTrue(values.get(0) instanceof CurrentAddressType);
  CurrentAddressType address2 = (CurrentAddressType) values.get(0);
  verify(address, address2);
}
 
开发者ID:litsec,项目名称:eidas-opensaml,代码行数:43,代码来源:CurrentAddressTypeTest.java

示例9: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Build a new empty object of the requested type.
 * 
 * The requested type must have a DEFAULT_ELEMENT_NAME attribute describing the element type as a QName.
 * 
 * @param <T> SAML Object type
 */
@SuppressWarnings("unchecked")
public static <T extends XMLObject> T buildXMLObject(Class<T> type) {
	try {
		QName objectQName = getElementQName(type);
		XMLObjectBuilder<T> builder = Configuration.getBuilderFactory().getBuilder(objectQName);
		if (builder == null) {
			throw new InvalidParameterException("No builder exists for object: " + objectQName.getLocalPart());
		}
		return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(), objectQName.getPrefix());
	} catch (SecurityException e) {
		throw new RuntimeException(e);
	}				
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:21,代码来源:SAMLUtil.java

示例10: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Builds SAML Objects for a given QName
 *
 * @param pQName Element QName for the SAML Object
 * @return SAML Object
 */
private static XMLObject buildXMLObject(QName pQName) {
  XMLObjectBuilder lObjectBuilder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(pQName);

  if (lObjectBuilder == null) {
    throw new ExInternal("Cannot get builder for QName: " + pQName);
  }

  return lObjectBuilder.buildObject(pQName.getNamespaceURI(), pQName.getLocalPart(), pQName.getPrefix());
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:16,代码来源:SAMLResponseCommand.java

示例11: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
protected static XMLObject buildXMLObject(QName objectQName) throws IdentityProviderException {
    XMLObjectBuilder builder = Configuration.getBuilderFactory().getBuilder(objectQName);
    if (builder == null) {
        throw new IdentityProviderException("Unable to retrieve builder for object QName " + objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(), objectQName.getPrefix());
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:8,代码来源:SAML2TokenBuilder.java

示例12: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Builds SAML Elements
 *
 * @param objectQName
 * @return
 * @throws SAMLSSOException
 */
private static XMLObject buildXMLObject(QName objectQName) throws SAMLSSOException {
    XMLObjectBuilder builder =
            org.opensaml.xml.Configuration.getBuilderFactory()
                    .getBuilder(objectQName);
    if (builder == null) {
        throw new SAMLSSOException("Unable to retrieve builder for object QName " +
                objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
            objectQName.getPrefix());
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:19,代码来源:SSOUtils.java

示例13: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
public static XMLObject buildXMLObject(QName objectQName) throws Exception {

        XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(
                objectQName);
        if (builder == null) {
            throw new Exception("Unable to retrieve builder for object QName " + objectQName);
        }
        return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
                objectQName.getPrefix());
    }
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:11,代码来源:Util.java

示例14: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Builds SAML Elements
 *
 * @param objectQName
 * @return
 * @throws IdentityException
 */
private XMLObject buildXMLObject(QName objectQName) throws IdentityException {
    XMLObjectBuilder builder =
            org.opensaml.xml.Configuration.getBuilderFactory()
                    .getBuilder(objectQName);
    if (builder == null) {
        throw IdentityException.error("Unable to retrieve builder for object QName " +
                                    objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
                               objectQName.getPrefix());
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:19,代码来源:DefaultSSOSigner.java

示例15: buildXMLObject

import org.opensaml.xml.XMLObjectBuilder; //导入方法依赖的package包/类
/**
 * Create XMLObject from a given QName
 *
 * @param objectQName: QName of the object to be built into a XMLObject
 * @return built xmlObject
 * @throws EntitlementProxyException
 */
private XMLObject buildXMLObject(QName objectQName) throws EntitlementProxyException {

    XMLObjectBuilder builder = org.opensaml.xml.Configuration.getBuilderFactory().getBuilder(objectQName);
    if (builder == null) {
        throw new EntitlementProxyException("Unable to retrieve builder for object QName "
                + objectQName);
    }
    return builder.buildObject(objectQName.getNamespaceURI(), objectQName.getLocalPart(),
            objectQName.getPrefix());
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:18,代码来源:WSXACMLEntitlementServiceClient.java


注:本文中的org.opensaml.xml.XMLObjectBuilder.buildObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。