Как я могу получитьAttributeValue в артефактах управления с помощью wso2 Governance?

Ситуация такая. Я определяю тип артефакта следующим образом:

<artifactType type="application/vnd.wso2-tets+xml" shortName="test" singularLabel="tests" pluralLabel="tests" hasNamespace="false" iconSet="9">
    <storagePath>/applications/@{name}/@{overview_version}</storagePath>
    <nameAttribute>overview_name</nameAttribute>
    <ui>
        <list>
            <column name="Name">
                <data type="path" value="overview_name" href="/applications/@{name}"/>
            </column>
            <column name="Version">
                <data type="path" value="overview_version" href="@{storagePath}"/>
            </column>
        </list>
    </ui>
    <content>
        <table name="Overview">
            <field type="text" required="true">
                <name>Name</name>
            </field>
            <field type="text" required="true">
                <name>Version</name>
            </field>
            <field type="text-area">
                <name>Description</name>
            </field>
            <field type="options">
         <name label="Zcos">Zcos</name>
         <values class="cn.oge.wso2.populator.AlgPopulator"/>
       </field>
        </table>
    </content>
</artifactType>

В то же время я также определяю обработчик, mediaType — «application/vnd.wso2-tets+xml», код обработчика выглядит следующим образом:

public class XcosMediaTypeHandler extends Handler {

    public Resource get(RequestContext requestContext) throws RegistryException {
        return null;
    }

    public void put(RequestContext requestContext) throws RegistryException {
        Resource resource = requestContext.getResource();
        String name = "";
        String version = "";
        String description = "";
        String zcos = "";

        byte[] content = (byte[]) resource.getContent();
        ByteArrayInputStream in = new ByteArrayInputStream(content);
        OMElement docElement = null;
        try {
            StAXOMBuilder builder = new StAXOMBuilder(in);
            docElement = builder.getDocumentElement();
        } catch (Exception ae) {
            throw new RegistryException(
                    "Failed to parse the propject proposal. "
                            + "All project proposals should be in XML format.");
        }
        System.out.println("==========================================");
        OMElement firstElement = docElement.getFirstElement();
        System.out.println(firstElement);
        Iterator<OMElement> ite = firstElement.getChildElements();
        for (OMElement e = ite.next(); ite.hasNext(); e = ite.next()) {
            if (e.getLocalName().equals("name")) {
                name = e.getText();
            } else if (e.getLocalName().equals("version")) {
                version = e.getText();
            } else if (e.getLocalName().equals("description")) {
                description = e.getText();
            } else if (e.getLocalName().equals("zcos")) {
                zcos = e.getText();
            }
        }

        System.out.println("Name:" + name);
        System.out.println("Version:" + version);
        System.out.println("Description:" + description);
        System.out.println("zcos:" + zcos);         
    }

    public void importResource(RequestContext requestContext)
            throws RegistryException {
        System.out.println("importResource");
    }

    public void delete(RequestContext requestContext) throws RegistryException {

    }

    public void putChild(RequestContext requestContext)
            throws RegistryException {
        System.out.println("putChild");
    }

    public void importChild(RequestContext requestContext)
            throws RegistryException {
        System.out.println("importChild");
    }

}

Возникает вопрос: когда я использую пользовательский интерфейс для добавления артефакта, например: введите здесь описание изображения

В приведенном выше коде я могу получить значение атрибута для имени, версии и описания. но я не могу получить значение атрибута для Zcos. В определении Артефакта Zos полевого типа - это параметры. Другие атрибуты полевого типа - это текст или текстовая область. Почему я не могу получить стоимость имущества Zcos? Заранее спасибо!


person Pourquoi    schedule 02.04.2016    source источник
comment
Можете ли вы отладить обработчик и посмотреть?   -  person harsha89    schedule 03.04.2016
comment
спасибо за ответ, буду пробовать   -  person Pourquoi    schedule 06.04.2016
comment
@pourquoi помог ли вам приведенный ниже ответ? если нет, пожалуйста, дайте мне знать, что случилось?   -  person tk_    schedule 13.04.2016


Ответы (1)


чтобы избежать путаницы, сделайте ссылку в нижнем регистре, как показано ниже,

<field type="options">
  <name label="Zcos">zcos</name>
  <values class="cn.oge.wso2.populator.AlgPopulator"/>
</field>

найдите ниже код, чтобы получить значение zcos,

// Get the first OMElement child with name 'overview'
OMElement elementOverview = getFirstChild(docElement, "overview");
// Get the first OMElement child with name 'zcos' and appending absolute path prefix.
String zcos = getFirstChild(elementOverview, "zcos").getText();

Пример кода можно найти в этой записи в блоге.

person tk_    schedule 08.04.2016