Search in sources :

Example 1 with InteractionArgument

use of org.eclipse.persistence.internal.descriptors.InteractionArgument in project eclipselink by eclipse-ee4j.

the class EISObjectPersistenceXMLProject method buildXMLInteractionDescriptor.

protected ClassDescriptor buildXMLInteractionDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(XMLInteraction.class);
    descriptor.descriptorIsAggregate();
    descriptor.getInheritancePolicy().setParentClass(Call.class);
    XMLDirectMapping functionNameMapping = new XMLDirectMapping();
    functionNameMapping.setAttributeName("functionName");
    functionNameMapping.setGetMethodName("getFunctionName");
    functionNameMapping.setSetMethodName("setFunctionName");
    functionNameMapping.setXPath(getPrimaryNamespaceXPath() + "function-name/text()");
    functionNameMapping.setNullValue("");
    descriptor.addMapping(functionNameMapping);
    XMLDirectMapping inputRecordNameMapping = new XMLDirectMapping();
    inputRecordNameMapping.setAttributeName("inputRecordName");
    inputRecordNameMapping.setGetMethodName("getInputRecordName");
    inputRecordNameMapping.setSetMethodName("setInputRecordName");
    inputRecordNameMapping.setXPath(getPrimaryNamespaceXPath() + "input-record-name/text()");
    inputRecordNameMapping.setNullValue("");
    descriptor.addMapping(inputRecordNameMapping);
    XMLDirectMapping inputRootElementNameMapping = new XMLDirectMapping();
    inputRootElementNameMapping.setAttributeName("inputRootElementName");
    inputRootElementNameMapping.setGetMethodName("getInputRootElementName");
    inputRootElementNameMapping.setSetMethodName("setInputRootElementName");
    inputRootElementNameMapping.setXPath(getPrimaryNamespaceXPath() + "input-root-element-name/text()");
    inputRootElementNameMapping.setNullValue("");
    descriptor.addMapping(inputRootElementNameMapping);
    XMLDirectMapping inputResultPathMapping = new XMLDirectMapping();
    inputResultPathMapping.setAttributeName("inputResultPath");
    inputResultPathMapping.setGetMethodName("getInputResultPath");
    inputResultPathMapping.setSetMethodName("setInputResultPath");
    inputResultPathMapping.setXPath(getPrimaryNamespaceXPath() + "input-result-path/text()");
    inputResultPathMapping.setNullValue("");
    descriptor.addMapping(inputResultPathMapping);
    XMLDirectMapping outputResultPathMapping = new XMLDirectMapping();
    outputResultPathMapping.setAttributeName("outputResultPath");
    outputResultPathMapping.setGetMethodName("getOutputResultPath");
    outputResultPathMapping.setSetMethodName("setOutputResultPath");
    outputResultPathMapping.setXPath(getPrimaryNamespaceXPath() + "output-result-path/text()");
    outputResultPathMapping.setNullValue("");
    descriptor.addMapping(outputResultPathMapping);
    XMLCompositeCollectionMapping argumentsMapping = new XMLCompositeCollectionMapping();
    // Handle translation of argument lists to interaction-arguments.
    argumentsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            XMLInteraction interaction = (XMLInteraction) object;
            Vector<String> argumentNames = interaction.getArgumentNames();
            Vector<?> arguments = interaction.getArguments();
            Vector<InteractionArgument> interactionArguments = new Vector<>(arguments.size());
            for (int index = 0; index < arguments.size(); index++) {
                InteractionArgument interactionArgument = new InteractionArgument();
                interactionArgument.setArgumentName(argumentNames.get(index));
                Object argument = arguments.get(index);
                if (argument instanceof DatabaseField) {
                    interactionArgument.setKey(argument);
                } else {
                    interactionArgument.setValue(argument);
                }
                interactionArguments.add(interactionArgument);
            }
            return interactionArguments;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            XMLInteraction interaction = (XMLInteraction) object;
            @SuppressWarnings({ "unchecked" }) Vector<InteractionArgument> interactionArguments = (Vector<InteractionArgument>) value;
            Vector<DatabaseField> arguments = new Vector<>(interactionArguments.size());
            Vector<String> argumentNames = new Vector<>(interactionArguments.size());
            Vector<Object> values = new Vector<>(interactionArguments.size());
            for (int index = 0; index < interactionArguments.size(); index++) {
                InteractionArgument interactionArgument = interactionArguments.get(index);
                if (interactionArgument.getKey() != null) {
                    arguments.add(new DatabaseField((String) interactionArgument.getKey()));
                }
                if (interactionArgument.getValue() != null) {
                    values.add(interactionArgument.getValue());
                }
                if (interactionArgument.getArgumentName() != null) {
                    argumentNames.add(interactionArgument.getArgumentName());
                }
            }
            if (!arguments.isEmpty()) {
                interaction.setArguments(arguments);
            } else if (!values.isEmpty()) {
                interaction.setArguments(values);
            }
            if (!argumentNames.isEmpty()) {
                interaction.setArgumentNames(argumentNames);
            }
        }
    });
    argumentsMapping.setAttributeName("arguments");
    argumentsMapping.setXPath(getPrimaryNamespaceXPath() + "input-arguments/" + getPrimaryNamespaceXPath() + "argument");
    argumentsMapping.setReferenceClass(InteractionArgument.class);
    descriptor.addMapping(argumentsMapping);
    XMLCompositeCollectionMapping outputArgumentsMapping = new XMLCompositeCollectionMapping();
    // Handle translation of argument lists to interaction-arguments.
    outputArgumentsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            XMLInteraction interaction = (XMLInteraction) object;
            Vector<DatabaseField> arguments = interaction.getOutputArguments();
            Vector<String> argumentNames = interaction.getOutputArgumentNames();
            Vector<InteractionArgument> interactionArguments = new Vector<>(arguments.size());
            for (int index = 0; index < arguments.size(); index++) {
                InteractionArgument interactionArgument = new InteractionArgument();
                interactionArgument.setKey(arguments.get(index).getName());
                interactionArgument.setArgumentName(argumentNames.get(index));
                interactionArguments.add(interactionArgument);
            }
            return interactionArguments;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            XMLInteraction interaction = (XMLInteraction) object;
            @SuppressWarnings({ "unchecked" }) Vector<InteractionArgument> interactionArguments = (Vector<InteractionArgument>) value;
            Vector<DatabaseField> arguments = new Vector<>(interactionArguments.size());
            Vector<String> argumentNames = new Vector<>(interactionArguments.size());
            for (int index = 0; index < interactionArguments.size(); index++) {
                InteractionArgument interactionArgument = interactionArguments.get(index);
                arguments.add(new DatabaseField((String) interactionArgument.getKey()));
                argumentNames.add(interactionArgument.getArgumentName());
            }
            interaction.setOutputArguments(arguments);
            interaction.setOutputArgumentNames(argumentNames);
        }
    });
    outputArgumentsMapping.setAttributeName("outputArguments");
    outputArgumentsMapping.setXPath(getPrimaryNamespaceXPath() + "output-arguments/" + getPrimaryNamespaceXPath() + "argument");
    outputArgumentsMapping.setReferenceClass(InteractionArgument.class);
    descriptor.addMapping(outputArgumentsMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) InteractionArgument(org.eclipse.persistence.internal.descriptors.InteractionArgument) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction) Vector(java.util.Vector)

Aggregations

Vector (java.util.Vector)1 XMLInteraction (org.eclipse.persistence.eis.interactions.XMLInteraction)1 InteractionArgument (org.eclipse.persistence.internal.descriptors.InteractionArgument)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1