Java Code Examples for org.apache.axiom.om.OMFactory#createOMAttribute()

The following examples show how to use org.apache.axiom.om.OMFactory#createOMAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLToJsonTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNsa = fac.createOMNamespace("testns1", "a");
    OMNamespace omNsb = fac.createOMNamespace("testns2", "b");
    OMNamespace omNsc = fac.createOMNamespace("testns3", "c");
    OMElement payload = fac.createOMElement("test", omNsa);
    OMElement p1 = fac.createOMElement("testb", omNsb);
    OMAttribute a1 = fac.createOMAttribute("attrb1", omNsa, "a");
    a1.setAttributeValue("v1");
    p1.addAttribute(a1);
    OMAttribute a2 = fac.createOMAttribute("attrb2", omNsb, "b");
    a2.setAttributeValue("v2");
    p1.addAttribute(a2);
    OMElement p2 = fac.createOMElement("testc", omNsc);
    p1.addChild(p2);
    payload.addChild(p1);
    return payload;
}
 
Example 2
Source File: UserStoreConfigXMLProcessor.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Add all the user store property elements
 *
 * @param factory
 * @param parent
 * @param className
 * @param properties
 */
private static void addPropertyElements(OMFactory factory, OMElement parent, String className,
                                        Map<String, String> properties) {
    if (className != null) {
        parent.addAttribute(UserCoreConstants.RealmConfig.ATTR_NAME_CLASS, className, null);
    }
    Iterator<Map.Entry<String, String>> ite = properties.entrySet().iterator();
    while (ite.hasNext()) {
        Map.Entry<String, String> entry = ite.next();
        String name = entry.getKey();
        String value = entry.getValue();
        OMElement propElem = factory.createOMElement(new QName(
                UserCoreConstants.RealmConfig.LOCAL_NAME_PROPERTY));
        OMAttribute propAttr = factory.createOMAttribute(
                UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME, null, name);
        propElem.addAttribute(propAttr);
        propElem.setText(value);
        parent.addChild(propElem);
    }
}
 
Example 3
Source File: RealmConfigXMLProcessor.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static void addPropertyElements(OMFactory factory, OMElement parent, String className,
                                        String description, Map<String, String> properties) {
    if (className != null) {
        parent.addAttribute(UserCoreConstants.RealmConfig.ATTR_NAME_CLASS, className, null);
    }
    if (description != null) {
        parent.addAttribute(UserCoreConstants.RealmConfig.CLASS_DESCRIPTION, description, null);
    }
    Iterator<Map.Entry<String, String>> ite = properties.entrySet().iterator();
    while (ite.hasNext()) {
        Map.Entry<String, String> entry = ite.next();
        String name = entry.getKey();
        String value = entry.getValue();
        if (value != null) {
            value = resolveSystemProperty(value);
        }
        OMElement propElem = factory.createOMElement(new QName(
                UserCoreConstants.RealmConfig.LOCAL_NAME_PROPERTY));
        OMAttribute propAttr = factory.createOMAttribute(
                UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME, null, name);
        propElem.addAttribute(propAttr);
        propElem.setText(value);
        parent.addChild(propElem);
    }
}
 
Example 4
Source File: RealmConfigXMLProcessor.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static void addPropertyElements(OMFactory factory, OMElement parent, String className, String description, Map<String, String> properties) {
    if (className != null) {
        parent.addAttribute("class", className, (OMNamespace) null);
    }

    if (description != null) {
        parent.addAttribute("Description", description, (OMNamespace) null);
    }

    Iterator ite = properties.entrySet().iterator();

    while (ite.hasNext()) {
        Entry<String, String> entry = (Entry) ite.next();
        String name = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (value != null) {
            value = resolveSystemProperty(value);
        }
        OMElement propElem = factory.createOMElement(new QName("Property"));
        OMAttribute propAttr = factory.createOMAttribute("name", (OMNamespace) null, name);
        propElem.addAttribute(propAttr);
        propElem.setText(value);
        parent.addChild(propElem);
    }

}
 
Example 5
Source File: XMLToJsonTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNsa = fac.createOMNamespace("testns1", "a");
    OMNamespace omNsb = fac.createOMNamespace("testns2", "b");
    OMNamespace omNsc = fac.createOMNamespace("testns3", "c");
    OMElement payload = fac.createOMElement("test", omNsa);          
    OMElement p1 = fac.createOMElement("testb", omNsb);
    OMAttribute a1 = fac.createOMAttribute("attrb1", omNsa, "a");
    a1.setAttributeValue("v1");
    p1.addAttribute(a1);
    OMAttribute a2 = fac.createOMAttribute("attrb2", omNsb, "b");
    a2.setAttributeValue("v2");
    p1.addAttribute(a2);        
    OMElement p2 = fac.createOMElement("testc", omNsc);
    p1.addChild(p2);
    payload.addChild(p1);
    return payload;
}
 
Example 6
Source File: PolicyUtil.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static OMElement getWrapper(String name) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace namespace = fac.createOMNamespace("", name);
    OMElement element = fac.createOMElement("Policy", namespace);
    OMAttribute attribute = fac.createOMAttribute("name", namespace, name);
    element.addAttribute(attribute);

    return element;
}
 
Example 7
Source File: RealmConfigXMLProcessor.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public static OMElement serialize(RealmConfiguration realmConfig) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement rootElement = factory.createOMElement(new QName("UserManager"));
    OMElement realmElement = factory.createOMElement(new QName("Realm"));
    String realmName = realmConfig.getRealmClassName();
    OMAttribute propAttr = factory.createOMAttribute("name", (OMNamespace) null, realmName);
    realmElement.addAttribute(propAttr);
    rootElement.addChild(realmElement);
    OMElement mainConfig = factory.createOMElement(new QName("Configuration"));
    realmElement.addChild(mainConfig);
    OMElement addAdmin = factory.createOMElement(new QName("AddAdmin"));
    OMElement adminUser = factory.createOMElement(new QName("AdminUser"));
    OMElement adminUserNameElem = factory.createOMElement(new QName("UserName"));
    adminUserNameElem.setText(realmConfig.getAdminUserName());
    OMElement adminPasswordElem = factory.createOMElement(new QName("Password"));
    addAdmin.setText(UserCoreUtil.removeDomainFromName(realmConfig.getAddAdmin()));
    adminPasswordElem.setText(realmConfig.getAdminPassword());
    adminUser.addChild(adminUserNameElem);
    adminUser.addChild(adminPasswordElem);
    mainConfig.addChild(addAdmin);
    mainConfig.addChild(adminUser);
    OMElement adminRoleNameElem = factory.createOMElement(new QName("AdminRole"));
    adminRoleNameElem.setText(UserCoreUtil.removeDomainFromName(realmConfig.getAdminRoleName()));
    mainConfig.addChild(adminRoleNameElem);
    OMElement systemUserNameElem = factory.createOMElement(new QName("SystemUserName"));
    mainConfig.addChild(systemUserNameElem);
    OMElement anonymousUserEle = factory.createOMElement(new QName("AnonymousUser"));
    OMElement anonymousUserNameElem = factory.createOMElement(new QName("UserName"));
    OMElement anonymousPasswordElem = factory.createOMElement(new QName("Password"));
    anonymousUserEle.addChild(anonymousUserNameElem);
    anonymousUserEle.addChild(anonymousPasswordElem);
    mainConfig.addChild(anonymousUserEle);
    OMElement everyoneRoleNameElem = factory.createOMElement(new QName("EveryOneRoleName"));
    everyoneRoleNameElem.setText(UserCoreUtil.removeDomainFromName(realmConfig.getEveryOneRoleName()));
    mainConfig.addChild(everyoneRoleNameElem);
    addPropertyElements(factory, mainConfig, (String) null, realmConfig.getDescription(), realmConfig.getRealmProperties());
    OMElement userStoreManagerElement = factory.createOMElement(new QName("UserStoreManager"));
    realmElement.addChild(userStoreManagerElement);
    addPropertyElements(factory, userStoreManagerElement, realmConfig.getUserStoreClass(), realmConfig.getDescription(), realmConfig.getUserStoreProperties());

    return rootElement;
}