Search in sources :

Example 21 with DescriptorException

use of org.eclipse.persistence.exceptions.DescriptorException in project eclipselink by eclipse-ee4j.

the class DBWSBuilderModelProject method buildDBWSBuilderModelDescriptor.

protected ClassDescriptor buildDBWSBuilderModelDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(DBWSBuilderModel.class);
    descriptor.setDefaultRootElement("dbws-builder");
    XMLCompositeCollectionMapping propertiesMapping = new XMLCompositeCollectionMapping();
    propertiesMapping.setReferenceClass(Association.class);
    propertiesMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public String getAttributeName() {
            return "properties";
        }

        @Override
        public Object getAttributeValueFromObject(Object object) throws DescriptorException {
            DBWSBuilderModel model = (DBWSBuilderModel) object;
            Vector<Association> associations = new Vector<Association>();
            for (Map.Entry<String, String> me : model.properties.entrySet()) {
                associations.add(new Association(me.getKey(), me.getValue()));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) throws DescriptorException {
            DBWSBuilderModel model = (DBWSBuilderModel) object;
            Vector<Association> associations = (Vector<Association>) value;
            for (Association a : associations) {
                model.properties.put((String) a.getKey(), (String) a.getValue());
            }
        }
    });
    propertiesMapping.setXPath("properties/property");
    descriptor.addMapping(propertiesMapping);
    XMLChoiceCollectionMapping operationsMapping = new XMLChoiceCollectionMapping();
    operationsMapping.setAttributeName("operations");
    operationsMapping.setContainerPolicy(new ListContainerPolicy(ArrayList.class));
    operationsMapping.addChoiceElement("table", TableOperationModel.class);
    operationsMapping.addChoiceElement("procedure", ProcedureOperationModel.class);
    operationsMapping.addChoiceElement("plsql-procedure", PLSQLProcedureOperationModel.class);
    operationsMapping.addChoiceElement("sql", SQLOperationModel.class);
    operationsMapping.addChoiceElement("batch-sql", BatchSQLOperationModel.class);
    descriptor.addMapping(operationsMapping);
    return descriptor;
}
Also used : DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) ListContainerPolicy(org.eclipse.persistence.internal.queries.ListContainerPolicy) ArrayList(java.util.ArrayList) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Association(org.eclipse.persistence.mappings.Association) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) Vector(java.util.Vector)

Aggregations

DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)21 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)7 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)6 InputStream (java.io.InputStream)4 ValidationException (org.eclipse.persistence.exceptions.ValidationException)4 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)4 JAXBException (jakarta.xml.bind.JAXBException)3 HashMap (java.util.HashMap)3 Vector (java.util.Vector)3 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)3 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)3 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2