如何使用 wso2 Governance 在 Governance Artifacts 中获取 AttributeValue?

How can I getAttributeValue in Governance Artifacts whith wso2 Governance?

情况是这样的我定义了一个Artifact Type是这样的:

<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>

同时我也定义了一个handler,mediaType是"application/vnd.wso2-tets+xml" handler代码是这样的:

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");
    }

}

问题来了,当我使用UI添加一个Artifact时,例如:

在上面的代码中,我可以获得名称、版本和描述的属性值。但我无法获得 Zcos 的属性值。在Artifact的定义中,字段类型的Zos是options,字段类型的其他属性是text或text-area。 为什么我无法获得 Zcos 属性 值?在此先感谢!

为了减少混淆,将字段引用设为小写,如下所示,

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

找到下面的代码获取cos值,

// 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();

要查找示例代码,请查找 this blog post