Search in sources :

Example 1 with PropertySchema

use of jp.ossc.nimbus.beans.dataset.PropertySchema in project nimbus by nimbus-org.

the class SharedContextRecord method updateProperty.

/**
 * 指定された名前のプロパティに、指定された値を更新した場合の差分情報を取得する。<p>
 *
 * @param name プロパティ名
 * @param val プロパティの値
 * @param diff 差分
 * @return 差分
 * @exception PropertySetException プロパティの設定に失敗した場合
 * @exception SharedContextUpdateException 差分情報の取得に失敗した場合
 */
public SharedContextValueDifference updateProperty(String name, Object val, SharedContextValueDifference diff) throws PropertySetException, SharedContextUpdateException {
    RecordSchema recordSchema = getRecordSchema();
    if (recordSchema == null) {
        throw new PropertySetException(null, "Schema is not initialized.");
    }
    final PropertySchema propertySchema = recordSchema.getPropertySchema(name);
    if (propertySchema == null) {
        throw new PropertySetException(null, "No such property : " + name);
    }
    return updateProperty(recordSchema.getPropertyIndex(name), val, diff);
}
Also used : PropertySetException(jp.ossc.nimbus.beans.dataset.PropertySetException) PropertySchema(jp.ossc.nimbus.beans.dataset.PropertySchema) RecordSchema(jp.ossc.nimbus.beans.dataset.RecordSchema)

Example 2 with PropertySchema

use of jp.ossc.nimbus.beans.dataset.PropertySchema in project nimbus by nimbus-org.

the class DataSetXpathConverter method createRecord.

private void createRecord(Document document, DataSet dataSet, Object target, RecordSchema recordSchema) {
    PropertySchema[] propertySchemata = recordSchema.getPropertySchemata();
    for (int i = 0; i < propertySchemata.length; i++) {
        if (propertySchemata[i] instanceof XpathPropertySchema) {
            // PropertySchemaからXPath取得
            XpathPropertySchema xmlBindingPropertySchema = (XpathPropertySchema) propertySchemata[i];
            XPathExpression expression = xmlBindingPropertySchema.getXpathExpression();
            // XPathによりXML要素を抽出
            NodeList nodeList = null;
            try {
                nodeList = (NodeList) expression.evaluate(document, XPathConstants.NODESET);
            } catch (XPathExpressionException e) {
                throw new ConvertException("The converter failed to evaluate a XML. ", e);
            }
            // DataSetへ変換
            int length = nodeList.getLength();
            if (target instanceof Record) {
                if (length > 0) {
                    Object nodeValue = nodeList.item(0).getNodeValue();
                    ((Record) target).setParseProperty(xmlBindingPropertySchema.getName(), nodeValue);
                }
            } else if (target instanceof RecordList) {
                RecordList targetRecordList = (RecordList) target;
                int offset = length - targetRecordList.size();
                if (offset > 0) {
                    for (int j = 0; j < offset; j++) {
                        Record record = targetRecordList.createRecord();
                        targetRecordList.addRecord(record);
                    }
                }
                for (int j = 0; j < length; j++) {
                    Object nodeValue = nodeList.item(j).getNodeValue();
                    Record record = targetRecordList.getRecord(j);
                    record.setParseProperty(xmlBindingPropertySchema.getName(), nodeValue);
                }
            }
        } else if (propertySchemata[i] instanceof RecordPropertySchema) {
            RecordPropertySchema recordPropertySchema = (RecordPropertySchema) propertySchemata[i];
            RecordSchema nestedRecordSchema = dataSet.getNestedRecordSchema(recordPropertySchema.getName());
            Record nestedRecord = dataSet.createNestedRecord(recordPropertySchema.getRecordName());
            createRecord(document, dataSet, target, nestedRecordSchema);
            ((Record) target).setProperty(recordPropertySchema.getName(), nestedRecord);
        } else if (propertySchemata[i] instanceof RecordListPropertySchema) {
            RecordListPropertySchema recordListPropertySchema = (RecordListPropertySchema) propertySchemata[i];
            RecordSchema nestedRecordSchema = dataSet.getNestedRecordListSchema(recordListPropertySchema.getRecordListName());
            RecordList nestedRecordList = dataSet.createNestedRecordList(recordListPropertySchema.getRecordListName());
            createRecord(document, dataSet, nestedRecordList, nestedRecordSchema);
            ((Record) target).setProperty(recordListPropertySchema.getName(), nestedRecordList);
        }
    }
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XpathPropertySchema(jp.ossc.nimbus.beans.dataset.XpathPropertySchema) PropertySchema(jp.ossc.nimbus.beans.dataset.PropertySchema) RecordPropertySchema(jp.ossc.nimbus.beans.dataset.RecordPropertySchema) RecordListPropertySchema(jp.ossc.nimbus.beans.dataset.RecordListPropertySchema) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) Record(jp.ossc.nimbus.beans.dataset.Record) RecordPropertySchema(jp.ossc.nimbus.beans.dataset.RecordPropertySchema) RecordSchema(jp.ossc.nimbus.beans.dataset.RecordSchema) RecordListPropertySchema(jp.ossc.nimbus.beans.dataset.RecordListPropertySchema) XpathPropertySchema(jp.ossc.nimbus.beans.dataset.XpathPropertySchema)

Example 3 with PropertySchema

use of jp.ossc.nimbus.beans.dataset.PropertySchema in project nimbus by nimbus-org.

the class RecordJournalEditorService method makePropertiesFormat.

protected StringBuilder makePropertiesFormat(EditorFinder finder, Object key, Record bean, StringBuilder buf) {
    buf.append(PROPERTIES_HEADER);
    final RecordSchema schema = bean.getRecordSchema();
    final PropertySchema[] props = schema.getPropertySchemata();
    if (props == null || props.length == 0) {
        buf.append(NULL_STRING);
        return buf;
    } else {
        buf.append(getLineSeparator());
    }
    final StringBuilder subBuf = new StringBuilder();
    if (isOutputCSVProperties) {
        for (int i = 0, max = props.length; i < max; i++) {
            final String name = props[i].getName();
            if (!enabledPropertySet.isEmpty() && !enabledPropertySet.contains(name)) {
                continue;
            }
            subBuf.append(name);
            if (i != max - 1) {
                subBuf.append(CSV_SEPARATOR);
            }
        }
        subBuf.append(getLineSeparator());
        for (int i = 0, max = props.length; i < max; i++) {
            final String name = props[i].getName();
            if (!enabledPropertySet.isEmpty() && !enabledPropertySet.contains(name)) {
                continue;
            }
            if (secretPropertySet.contains(name)) {
                subBuf.append(getSecretString());
            } else {
                makeObjectFormat(finder, null, bean.getProperty(name), subBuf);
            }
            if (i != max - 1) {
                subBuf.append(CSV_SEPARATOR);
            }
        }
    } else {
        for (int i = 0, max = props.length; i < max; i++) {
            final String name = props[i].getName();
            if (!enabledPropertySet.isEmpty() && !enabledPropertySet.contains(name)) {
                continue;
            }
            subBuf.append(name);
            subBuf.append(PROPERTY_SEPARATOR);
            if (secretPropertySet.contains(name)) {
                subBuf.append(getSecretString());
            } else {
                makeObjectFormat(finder, null, bean.getProperty(name), subBuf);
            }
            if (i != max - 1) {
                subBuf.append(getLineSeparator());
            }
        }
    }
    addIndent(subBuf);
    return buf.append(subBuf);
}
Also used : PropertySchema(jp.ossc.nimbus.beans.dataset.PropertySchema) RecordSchema(jp.ossc.nimbus.beans.dataset.RecordSchema)

Example 4 with PropertySchema

use of jp.ossc.nimbus.beans.dataset.PropertySchema in project nimbus by nimbus-org.

the class SharedContextRecord method updateParseProperty.

/**
 * 指定されたインデックスのプロパティに、指定された値をパースして更新した場合の差分情報を取得する。<p>
 *
 * @param index プロパティのインデックス
 * @param val プロパティの値
 * @param diff 差分
 * @return 差分
 * @exception PropertySetException プロパティの設定に失敗した場合
 * @exception SharedContextUpdateException 差分情報の取得に失敗した場合
 */
public SharedContextValueDifference updateParseProperty(int index, Object val, SharedContextValueDifference diff) throws PropertySetException, SharedContextUpdateException {
    RecordSchema recordSchema = getRecordSchema();
    if (recordSchema == null) {
        throw new PropertySetException(null, "Schema is not initialized.");
    }
    final PropertySchema propertySchema = recordSchema.getPropertySchema(index);
    if (propertySchema == null) {
        throw new PropertySetException(null, "No such property : " + index);
    }
    return updateProperty(index, propertySchema.parse(val), diff);
}
Also used : PropertySetException(jp.ossc.nimbus.beans.dataset.PropertySetException) PropertySchema(jp.ossc.nimbus.beans.dataset.PropertySchema) RecordSchema(jp.ossc.nimbus.beans.dataset.RecordSchema)

Example 5 with PropertySchema

use of jp.ossc.nimbus.beans.dataset.PropertySchema in project nimbus by nimbus-org.

the class SharedContextRecord method updateParseProperty.

/**
 * 指定された名前のプロパティに、指定された値をパースして更新した場合の差分情報を取得する。<p>
 *
 * @param name プロパティ名
 * @param val プロパティの値
 * @param diff 差分
 * @return 差分
 * @exception PropertySetException プロパティの設定に失敗した場合
 * @exception SharedContextUpdateException 差分情報の取得に失敗した場合
 */
public SharedContextValueDifference updateParseProperty(String name, Object val, SharedContextValueDifference diff) throws PropertySetException, SharedContextUpdateException {
    RecordSchema recordSchema = getRecordSchema();
    if (recordSchema == null) {
        throw new PropertySetException(null, "Schema is not initialized.");
    }
    final PropertySchema propertySchema = recordSchema.getPropertySchema(name);
    if (propertySchema == null) {
        throw new PropertySetException(null, "No such property : " + name);
    }
    return updateProperty(recordSchema.getPropertyIndex(name), propertySchema.parse(val), diff);
}
Also used : PropertySetException(jp.ossc.nimbus.beans.dataset.PropertySetException) PropertySchema(jp.ossc.nimbus.beans.dataset.PropertySchema) RecordSchema(jp.ossc.nimbus.beans.dataset.RecordSchema)

Aggregations

PropertySchema (jp.ossc.nimbus.beans.dataset.PropertySchema)5 RecordSchema (jp.ossc.nimbus.beans.dataset.RecordSchema)5 PropertySetException (jp.ossc.nimbus.beans.dataset.PropertySetException)3 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Record (jp.ossc.nimbus.beans.dataset.Record)1 RecordList (jp.ossc.nimbus.beans.dataset.RecordList)1 RecordListPropertySchema (jp.ossc.nimbus.beans.dataset.RecordListPropertySchema)1 RecordPropertySchema (jp.ossc.nimbus.beans.dataset.RecordPropertySchema)1 XpathPropertySchema (jp.ossc.nimbus.beans.dataset.XpathPropertySchema)1 NodeList (org.w3c.dom.NodeList)1