View | Details | Raw Unified | Return to bug 283453
Collapse All | Expand All

(-)foundation/org.eclipse.persistence.core/resource/xsd/eclipselink_persistence_map_1.1.xsd (+1 lines)
Lines 3424-3429 Link Here
3424
      <xsd:extension base="abstract-composite-direct-collection-mapping">
3424
      <xsd:extension base="abstract-composite-direct-collection-mapping">
3425
        <xsd:sequence>
3425
        <xsd:sequence>
3426
          <xsd:element minOccurs="0" name="is-cdata" type="xsd:boolean" />
3426
          <xsd:element minOccurs="0" name="is-cdata" type="xsd:boolean" />
3427
          <xsd:element minOccurs="0" name="null-policy" type="abstract-null-policy" />
3427
        </xsd:sequence>
3428
        </xsd:sequence>
3428
      </xsd:extension>
3429
      </xsd:extension>
3429
    </xsd:complexContent>
3430
    </xsd:complexContent>
(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XMLCompositeDirectCollectionMappingNodeValue.java (-2 / +44 lines)
Lines 22-28 Link Here
22
import org.eclipse.persistence.oxm.XMLConstants;
22
import org.eclipse.persistence.oxm.XMLConstants;
23
import org.eclipse.persistence.oxm.XMLField;
23
import org.eclipse.persistence.oxm.XMLField;
24
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
24
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
25
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
25
import org.eclipse.persistence.oxm.mappings.converters.XMLConverter;
26
import org.eclipse.persistence.oxm.mappings.converters.XMLConverter;
27
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
26
import org.eclipse.persistence.oxm.record.MarshalRecord;
28
import org.eclipse.persistence.oxm.record.MarshalRecord;
27
import org.eclipse.persistence.oxm.record.UnmarshalRecord;
29
import org.eclipse.persistence.oxm.record.UnmarshalRecord;
28
import org.xml.sax.Attributes;
30
import org.xml.sax.Attributes;
Lines 131-136 Link Here
131
    public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
133
    public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
132
        XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField();
134
        XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField();
133
        if (xmlField.getLastXPathFragment().nameIsText()) {
135
        if (xmlField.getLastXPathFragment().nameIsText()) {
136
134
            String type = atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
137
            String type = atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
135
            if (null != type) {
138
            if (null != type) {
136
                String namespaceURI = null;
139
                String namespaceURI = null;
Lines 142-147 Link Here
142
                }
145
                }
143
                unmarshalRecord.setTypeQName(new QName(namespaceURI, type));
146
                unmarshalRecord.setTypeQName(new QName(namespaceURI, type));
144
            }
147
            }
148
149
            if (xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByXsiNil() && xmlCompositeDirectCollectionMapping.getNullPolicy().valueIsNull(atts)) {
150
                getContainerPolicy().addInto(null, unmarshalRecord.getContainerInstance(this), unmarshalRecord.getSession());
151
            }
152
145
        } else if (xmlField.getLastXPathFragment().isAttribute()) {
153
        } else if (xmlField.getLastXPathFragment().isAttribute()) {
146
            if (!this.xmlCompositeDirectCollectionMapping.usesSingleNode()) {
154
            if (!this.xmlCompositeDirectCollectionMapping.usesSingleNode()) {
147
                String namespaceURI = xmlField.getLastXPathFragment().getNamespaceURI();
155
                String namespaceURI = xmlField.getLastXPathFragment().getNamespaceURI();
Lines 157-162 Link Here
157
    }
165
    }
158
166
159
    public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) {
167
    public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) {
168
        XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField();
169
        if (!xmlField.getLastXPathFragment().nameIsText()) {
170
            return;
171
        }
172
        
160
        Object value = unmarshalRecord.getStringBuffer().toString();
173
        Object value = unmarshalRecord.getStringBuffer().toString();
161
        Object collection = unmarshalRecord.getContainerInstance(this);
174
        Object collection = unmarshalRecord.getContainerInstance(this);
162
        unmarshalRecord.resetStringBuffer();
175
        unmarshalRecord.resetStringBuffer();
Lines 167-172 Link Here
167
                addUnmarshalValue(unmarshalRecord, stringTokenizer.nextToken(), collection);
180
                addUnmarshalValue(unmarshalRecord, stringTokenizer.nextToken(), collection);
168
            }
181
            }
169
        } else {
182
        } else {
183
            if (value.equals(EMPTY_STRING)) {
184
                if (xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByEmptyNode() ||
185
                        xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByXsiNil()) {
186
                    return;
187
                }
188
            }
170
            addUnmarshalValue(unmarshalRecord, value, collection);
189
            addUnmarshalValue(unmarshalRecord, value, collection);
171
        }
190
        }
172
    }
191
    }
Lines 186-194 Link Here
186
    }
205
    }
187
206
188
    private void addUnmarshalValue(UnmarshalRecord unmarshalRecord, Object value, Object collection) {
207
    private void addUnmarshalValue(UnmarshalRecord unmarshalRecord, Object value, Object collection) {
189
        if ((null == value) || EMPTY_STRING.equals(value)) {
208
        if (null == value) {
190
            return;
209
            return;
191
        }
210
        }
211
212
        if (xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByXsiNil() && xmlCompositeDirectCollectionMapping.getNullPolicy().valueIsNull(unmarshalRecord.getAttributes())) {
213
            return;
214
        }
215
216
        if ((!isWhitespaceAware() && EMPTY_STRING.equals(value))) {
217
            return;
218
        }
219
192
        XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField();
220
        XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField();
193
221
194
        XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager();
222
        XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager();
Lines 206-211 Link Here
206
                value = xmlCompositeDirectCollectionMapping.getValueConverter().convertDataValueToObjectValue(value, unmarshalRecord.getSession());
234
                value = xmlCompositeDirectCollectionMapping.getValueConverter().convertDataValueToObjectValue(value, unmarshalRecord.getSession());
207
            }
235
            }
208
        }
236
        }
237
        
209
        unmarshalRecord.addAttributeValue(this, value, collection);
238
        unmarshalRecord.addAttributeValue(this, value, collection);
210
    }
239
    }
211
240
Lines 254-259 Link Here
254
                }
283
                }
255
            }
284
            }
256
            marshalRecord.endElement(xPathFragment, namespaceResolver);
285
            marshalRecord.endElement(xPathFragment, namespaceResolver);
286
        } else {
287
            if (xmlCompositeDirectCollectionMapping.getNullPolicy().getMarshalNullRepresentation() != XMLNullRepresentationType.ABSENT_NODE) {
288
                marshalRecord.openStartElement(xPathFragment, namespaceResolver);
289
                XPathFragment nextFragment = xPathFragment.getNextFragment();
290
291
                xmlCompositeDirectCollectionMapping.getNullPolicy().directMarshal(nextFragment, marshalRecord, object, session, namespaceResolver);
292
293
                marshalRecord.endElement(nextFragment, namespaceResolver);
294
            }
257
        }
295
        }
258
296
259
    }
297
    }
Lines 262-265 Link Here
262
        return xmlCompositeDirectCollectionMapping;
300
        return xmlCompositeDirectCollectionMapping;
263
    }
301
    }
264
302
265
}
303
    public boolean isWhitespaceAware() {
304
        return !xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByEmptyNode();
305
    }
306
307
}
(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/sessions/factories/EclipseLinkObjectPersistenceRuntimeXMLProject.java (-2 / +22 lines)
Lines 19-24 Link Here
19
//EclipseLink imports
19
//EclipseLink imports
20
import org.eclipse.persistence.descriptors.ClassDescriptor;
20
import org.eclipse.persistence.descriptors.ClassDescriptor;
21
import org.eclipse.persistence.internal.helper.NonSynchronizedVector;
21
import org.eclipse.persistence.internal.helper.NonSynchronizedVector;
22
import org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceRuntimeXMLProject_11_1_1.NullPolicyAttributeAccessor;
23
import org.eclipse.persistence.mappings.DatabaseMapping;
22
import org.eclipse.persistence.mappings.converters.Converter;
24
import org.eclipse.persistence.mappings.converters.Converter;
23
import org.eclipse.persistence.mappings.converters.EnumTypeConverter;
25
import org.eclipse.persistence.mappings.converters.EnumTypeConverter;
24
import org.eclipse.persistence.mappings.transformers.ConstantTransformer;
26
import org.eclipse.persistence.mappings.transformers.ConstantTransformer;
Lines 28-33 Link Here
28
import org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping;
30
import org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping;
29
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
31
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
30
import org.eclipse.persistence.oxm.mappings.converters.XMLListConverter;
32
import org.eclipse.persistence.oxm.mappings.converters.XMLListConverter;
33
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
31
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
34
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
32
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
35
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
33
import org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference;
36
import org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference;
Lines 305-309 Link Here
305
        //NULL_SQL_TYPE
308
        //NULL_SQL_TYPE
306
        descriptor.addMapping(colDefMapping);
309
        descriptor.addMapping(colDefMapping);
307
        return descriptor;
310
        return descriptor;
308
    } 
311
    }
309
}
312
313
    
314
    
315
    @Override
316
    protected ClassDescriptor buildXMLCompositeDirectCollectionMappingDescriptor() {
317
        XMLDescriptor descriptor = (XMLDescriptor) super.buildXMLCompositeDirectCollectionMappingDescriptor();
318
319
        XMLCompositeObjectMapping aMapping = new XMLCompositeObjectMapping();
320
        aMapping.setReferenceClass(AbstractNullPolicy.class);
321
        aMapping.setAttributeName("nullPolicy");
322
        aMapping.setXPath(getPrimaryNamespaceXPath() + "null-policy");
323
        ((DatabaseMapping)aMapping).setAttributeAccessor(new NullPolicyAttributeAccessor());
324
        descriptor.addMapping(aMapping);
325
        
326
        return descriptor;
327
    }
328
329
}
(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/oxm/mappings/XMLCompositeDirectCollectionMapping.java (-3 / +16 lines)
Lines 25-30 Link Here
25
import org.eclipse.persistence.mappings.converters.TypeConversionConverter;
25
import org.eclipse.persistence.mappings.converters.TypeConversionConverter;
26
import org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping;
26
import org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping;
27
import org.eclipse.persistence.oxm.mappings.converters.XMLConverter;
27
import org.eclipse.persistence.oxm.mappings.converters.XMLConverter;
28
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
29
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
28
import org.eclipse.persistence.oxm.record.XMLRecord;
30
import org.eclipse.persistence.oxm.record.XMLRecord;
29
import org.eclipse.persistence.queries.ObjectBuildingQuery;
31
import org.eclipse.persistence.queries.ObjectBuildingQuery;
30
32
Lines 214-225 Link Here
214
 *
216
 *
215
 * @since Oracle TopLink 10<i>g</i> Release 2 (10.1.3)
217
 * @since Oracle TopLink 10<i>g</i> Release 2 (10.1.3)
216
 */
218
 */
217
public class XMLCompositeDirectCollectionMapping extends AbstractCompositeDirectCollectionMapping implements XMLMapping {
219
public class XMLCompositeDirectCollectionMapping extends AbstractCompositeDirectCollectionMapping implements XMLMapping, XMLNillableMapping {
218
    private boolean isCDATA;
220
    private boolean isCDATA;
219
    private boolean isWriteOnly;
221
    private boolean isWriteOnly;
222
    private AbstractNullPolicy nullPolicy;
220
223
221
    public XMLCompositeDirectCollectionMapping() {
224
    public XMLCompositeDirectCollectionMapping() {
222
        super();
225
        super();
226
        this.nullPolicy = new NullPolicy();
227
        this.nullPolicy.setNullRepresentedByEmptyNode(true);
223
    }
228
    }
224
229
225
    /**
230
    /**
Lines 383-387 Link Here
383
        getAttributeAccessor().setIsReadOnly(this.isReadOnly());
388
        getAttributeAccessor().setIsReadOnly(this.isReadOnly());
384
        super.preInitialize(session);
389
        super.preInitialize(session);
385
    }
390
    }
386
    
391
387
}
392
    public AbstractNullPolicy getNullPolicy() {
393
        return this.nullPolicy;
394
    }
395
396
    public void setNullPolicy(AbstractNullPolicy value) {
397
        this.nullPolicy = value;
398
    }
399
400
}
(-)moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyAttribute.xml (-1 / +3 lines)
Lines 1-2 Link Here
1
<?xml version="1.0"?>
1
<?xml version="1.0"?>
2
<employee id="123" task="write code" last-name="Doe"/>
2
<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="123" last-name="Doe">
3
    <tasks task="write code"/>
4
</employee>
(-)moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyElement.xml (-5 / +5 lines)
Lines 1-6 Link Here
1
<?xml version="1.0"?>
1
<?xml version="1.0"?>
2
<employee>
2
<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
	<id>123</id>
3
    <id>123</id>
4
	<task>write code</task>
4
    <task>write code</task>
5
	<last-name>Doe</last-name>
5
    <last-name>Doe</last-name>
6
</employee>
6
</employee>
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/DirectCollectionMappingTestSuite.java (-14 lines)
Lines 100-119 Link Here
100
        suite.addTestSuite(DirectCollectionErrorTestCases.class);
100
        suite.addTestSuite(DirectCollectionErrorTestCases.class);
101
        suite.addTest(UnionTestCases.suite());
101
        suite.addTest(UnionTestCases.suite());
102
102
103
        // NodeNullPolicy test cases see: TopLinkOXM-Nillable4_blaise.doc
104
        // see: TopLink_OX_Nillable_TestDesignSpec_v20061026.doc
105
        // UC2a
106
        suite.addTestSuite(DirectCollectionOptionalNodeNullPolicyElementTestCases.class);// 6 of 6 pass by default
107
        // UC2b
108
        //suite.addTestSuite(DirectCollectionOptionalNodeNullPolicyAttributeTestCases.class);// 6 of 6 pass by default
109
        // UC3
110
        // see #5876860: we are turning off failing Nillable tests for collections until the feature is implemented
111
        //suite.addTestSuite(DirectCollectionNillableNodeNullPolicyTestCases.class);// 3 of 6 pass until implementation set
112
        // UC4-true
113
        // see #5876860: we are turning off failing Nillable tests for collections until the feature is implemented
114
        //suite.addTestSuite(DirectCollectionIsSetNodeNullPolicyTrueTestCases.class);// 3 of 6 pass until implementation set
115
        // UC4-false - n/a
116
117
        suite.addTestSuite(XMLDirectCollectionOfListsTestCases.class);
103
        suite.addTestSuite(XMLDirectCollectionOfListsTestCases.class);
118
104
119
        return suite;
105
        return suite;
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionIsSetNodeNullPolicyTrueTestCases.java (-25 / +24 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution. 
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
Lines 14-62 Link Here
14
14
15
import java.util.Vector;
15
import java.util.Vector;
16
16
17
import org.eclipse.persistence.descriptors.ClassDescriptor;
18
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
17
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
18
import org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy;
20
import org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
21
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
20
21
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
22
import org.eclipse.persistence.sessions.Project;
22
import org.eclipse.persistence.sessions.Project;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
24
24
25
public class DirectCollectionIsSetNodeNullPolicyTrueTestCases extends XMLMappingTestCases {
25
public class DirectCollectionIsSetNodeNullPolicyTrueTestCases extends XMLMappingTestCases {
26
    private final static String XML_RESOURCE = //
27
    	"org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionIsSetNodeNullPolicyTrue.xml";
28
26
27
    private final static String XML_RESOURCE = "org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionIsSetNodeNullPolicyTrue.xml";
28
29
    public DirectCollectionIsSetNodeNullPolicyTrueTestCases(String name) throws Exception {
29
    public DirectCollectionIsSetNodeNullPolicyTrueTestCases(String name) throws Exception {
30
        super(name);
30
        super(name);
31
        setControlDocument(XML_RESOURCE);
31
        setControlDocument(XML_RESOURCE);
32
32
33
        AbstractNullPolicy aNullPolicy = new IsSetNullPolicy();
33
        AbstractNullPolicy aNullPolicy = new IsSetNullPolicy();
34
    	// alter unmarshal policy state
34
        // alter unmarshal policy state
35
    	aNullPolicy.setNullRepresentedByEmptyNode(false);
35
        aNullPolicy.setNullRepresentedByXsiNil(true);
36
    	aNullPolicy.setNullRepresentedByXsiNil(false);
36
        // alter marshal policy state
37
    	// alter marshal policy state
37
        aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
38
    	aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);
38
39
        ((IsSetNullPolicy)aNullPolicy).setIsSetMethodName("isSetFirstName");
39
        ((IsSetNullPolicy) aNullPolicy).setIsSetMethodName("isSetTasks");
40
40
        Project aProject = new DirectCollectionNodeNullPolicyProject(true);
41
        Project aProject = new DirectCollectionNodeNullPolicyProject(true);
41
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping)aProject.getDescriptor(Employee.class)//
42
        ClassDescriptor aDescriptor = aProject.getDescriptor(Employee.class);
42
        .getMappingForAttributeName("tasks");
43
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping) aDescriptor.getMappingForAttributeName("tasks");
43
        // TODO: renable after we implement NullPolicy for this mapping
44
        aMapping.setNullPolicy(aNullPolicy);
44
        //aMapping.setNullPolicy(aNullPolicy);
45
        setProject(aProject);
45
        setProject(aProject);
46
    }
46
    }
47
47
48
    protected Object getControlObject() {
48
    protected Object getControlObject() {
49
        Employee anEmployee = new Employee();
49
        Employee anEmployee = new Employee();
50
        anEmployee.setId(123);
50
        anEmployee.setId(123);
51
        //anEmployee.setFirstName(null);
51
        anEmployee.setFirstName(null);
52
        Vector aVector = new Vector();
52
        Vector aVector = new Vector();
53
        //aVector.add(null);
53
        aVector.add(null);
54
        aVector.add("write code");
54
        aVector.add("write code");
55
        //aVector.add(null);
55
        aVector.add(null);
56
        anEmployee.setTasks(aVector);        
56
        anEmployee.setTasks(aVector);
57
        // (the isSet method is set=true when we set tasks=null or tasks=new Vector()?) 
58
        //anEmployee.setTasks(null);
59
        anEmployee.setLastName("Doe");
57
        anEmployee.setLastName("Doe");
60
        return anEmployee;
58
        return anEmployee;
61
    }
59
    }
62
}
60
61
}
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionMappingNillableTestSuite.java (+38 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation from Oracle TopLink
12
 ******************************************************************************/  
13
package org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable;
14
15
import junit.framework.Test;
16
import junit.framework.TestCase;
17
import junit.framework.TestSuite;
18
19
public class DirectCollectionMappingNillableTestSuite extends TestCase {
20
    public static Test suite() {
21
        TestSuite suite = new TestSuite("DirectCollection Mapping Nillable Test Suite");
22
23
        // NodeNullPolicy test cases see: TopLinkOXM-Nillable4_blaise.doc
24
        // see: TopLink_OX_Nillable_TestDesignSpec_v20061026.doc
25
        suite.addTestSuite(DirectCollectionOptionalNodeNullPolicyElementTestCases.class);
26
        suite.addTestSuite(DirectCollectionOptionalNodeNullPolicyAttributeTestCases.class);
27
        suite.addTestSuite(DirectCollectionNillableNodeNullPolicyTestCases.class);
28
        suite.addTestSuite(DirectCollectionIsSetNodeNullPolicyTrueTestCases.class);
29
30
        return suite;
31
    }
32
33
    public static void main(String[] args) {
34
        String[] arguments = { "-c", "org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable.DirectCollectionMappingNillableTestSuite" };
35
        junit.textui.TestRunner.main(arguments);
36
    }
37
38
}
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionNillableNodeNullPolicyTestCases.java (-22 / +22 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution. 
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
Lines 12-60 Link Here
12
 ******************************************************************************/
12
 ******************************************************************************/
13
package org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable;
13
package org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable;
14
14
15
16
import java.util.Vector;
15
import java.util.Vector;
17
16
17
import org.eclipse.persistence.descriptors.ClassDescriptor;
18
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
18
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
20
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
20
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
21
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
21
22
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
23
import org.eclipse.persistence.sessions.Project;
22
import org.eclipse.persistence.sessions.Project;
24
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
25
24
26
public class DirectCollectionNillableNodeNullPolicyTestCases extends XMLMappingTestCases {
25
public class DirectCollectionNillableNodeNullPolicyTestCases extends XMLMappingTestCases {
27
    private final static String XML_RESOURCE = //
28
    	"org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionNillableNodeNullPolicy.xml";
29
26
27
    private final static String XML_RESOURCE = "org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionNillableNodeNullPolicy.xml";
28
30
    public DirectCollectionNillableNodeNullPolicyTestCases(String name) throws Exception {
29
    public DirectCollectionNillableNodeNullPolicyTestCases(String name) throws Exception {
31
        super(name);
30
        super(name);
32
        setControlDocument(XML_RESOURCE);
31
        setControlDocument(XML_RESOURCE);
33
32
34
        AbstractNullPolicy aNullPolicy = new NullPolicy();
33
        AbstractNullPolicy aNullPolicy = new NullPolicy();
35
    	// alter unmarshal policy state
34
        // alter unmarshal policy state
36
    	aNullPolicy.setNullRepresentedByEmptyNode(false);
35
        aNullPolicy.setNullRepresentedByEmptyNode(false);
37
    	aNullPolicy.setNullRepresentedByXsiNil(true);
36
        aNullPolicy.setNullRepresentedByXsiNil(true);
38
    	// alter marshal policy state
37
        // alter marshal policy state
39
    	aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);//.ABSENT_NODE);
38
        aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);//.ABSENT_NODE);
39
40
        Project aProject = new DirectCollectionNodeNullPolicyProject(true);
40
        Project aProject = new DirectCollectionNodeNullPolicyProject(true);
41
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping)aProject.getDescriptor(Employee.class)//
41
        ClassDescriptor aDescriptor = aProject.getDescriptor(Employee.class);
42
        .getMappingForAttributeName("tasks");
42
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping) aDescriptor.getMappingForAttributeName("tasks");
43
        // TODO: renable after we implement NullPolicy for this mapping
43
        aMapping.setNullPolicy(aNullPolicy);
44
        //aMapping.setNullPolicy(aNullPolicy);
45
        setProject(aProject);
44
        setProject(aProject);
46
    }
45
    }
47
46
48
    protected Object getControlObject() {
47
    protected Object getControlObject() {
49
        Employee anEmployee = new Employee();
48
        Employee anEmployee = new Employee();
50
        anEmployee.setId(123);
49
        anEmployee.setId(123);
51
        //anEmployee.setFirstName(null);
50
        anEmployee.setFirstName(null);
52
        Vector aVector = new Vector();
51
        Vector aVector = new Vector();
53
        //aVector.add(null);
52
        aVector.add(null);
54
        aVector.add("write code");
53
        aVector.add("write code");
55
        //aVector.add(null);
54
        aVector.add(null);
56
        anEmployee.setTasks(aVector);
55
        anEmployee.setTasks(aVector);
57
        anEmployee.setLastName("Doe");
56
        anEmployee.setLastName("Doe");
58
        return anEmployee;
57
        return anEmployee;
59
    }
58
    }
60
}
59
60
}
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionNodeNullPolicyProject.java (-12 / +22 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution. 
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
Lines 12-17 Link Here
12
 ******************************************************************************/
12
 ******************************************************************************/
13
package org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable;
13
package org.eclipse.persistence.testing.oxm.mappings.directcollection.nillable;
14
14
15
import org.eclipse.persistence.oxm.NamespaceResolver;
16
import org.eclipse.persistence.oxm.XMLConstants;
15
import org.eclipse.persistence.oxm.XMLDescriptor;
17
import org.eclipse.persistence.oxm.XMLDescriptor;
16
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
18
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
17
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
19
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
Lines 27-33 Link Here
27
    public DirectCollectionNodeNullPolicyProject(boolean fieldsAsElements) {
29
    public DirectCollectionNodeNullPolicyProject(boolean fieldsAsElements) {
28
        XMLDescriptor aDescriptor = getEmployeeDescriptor(fieldsAsElements);
30
        XMLDescriptor aDescriptor = getEmployeeDescriptor(fieldsAsElements);
29
31
30
        //aDescriptor.addMapping(aMapping);
31
        addDescriptor(aDescriptor);
32
        addDescriptor(aDescriptor);
32
    }
33
    }
33
34
Lines 58-78 Link Here
58
        idMapping.setXPath(xPathPrepend + "id" + xPathAppend);
59
        idMapping.setXPath(xPathPrepend + "id" + xPathAppend);
59
        descriptor.addMapping(idMapping);
60
        descriptor.addMapping(idMapping);
60
61
61
        //XMLDirectMapping firstNameMapping = new XMLDirectMapping();
62
        XMLDirectMapping firstNameMapping = new XMLDirectMapping();
62
        //firstNameMapping.setAttributeName("firstName");
63
        firstNameMapping.setAttributeName("firstName");
63
        //firstNameMapping.setXPath(xPathPrepend + "first-name" + xPathAppend);
64
        firstNameMapping.setXPath(xPathPrepend + "first-name" + xPathAppend);
64
        //descriptor.addMapping(firstNameMapping);
65
        descriptor.addMapping(firstNameMapping);
65
66
66
        XMLCompositeDirectCollectionMapping taskMapping = new XMLCompositeDirectCollectionMapping();
67
        XMLCompositeDirectCollectionMapping taskMapping = new XMLCompositeDirectCollectionMapping();
67
        taskMapping.setAttributeName("tasks");
68
        taskMapping.setAttributeName("tasks");
68
        taskMapping.setXPath(xPathPrepend + "task" + xPathAppend);
69
        if (fieldsAsElements) {
70
            taskMapping.setXPath(xPathPrepend + "task" + xPathAppend);
71
        } else {
72
            taskMapping.setXPath("tasks/" + xPathPrepend + "task" + xPathAppend);
73
        }
69
        descriptor.addMapping(taskMapping);
74
        descriptor.addMapping(taskMapping);
70
75
71
        XMLDirectMapping lastNameMapping = new XMLDirectMapping();
76
        XMLDirectMapping lastNameMapping = new XMLDirectMapping();
72
        lastNameMapping.setAttributeName("lastName");
77
        lastNameMapping.setAttributeName("lastName");
73
        lastNameMapping.setXPath(xPathPrepend + "last-name" + xPathAppend);
78
        lastNameMapping.setXPath(xPathPrepend + "last-name" + xPathAppend);
74
        descriptor.addMapping(lastNameMapping);
79
        descriptor.addMapping(lastNameMapping);
75
        
80
81
        NamespaceResolver nsr = new NamespaceResolver();
82
        nsr.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL);
83
        descriptor.setNamespaceResolver(nsr);
84
76
        return descriptor;
85
        return descriptor;
77
    }
86
    }
78
}
87
88
}
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyAttributeTestCases.java (-21 / +33 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution. 
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
Lines 14-59 Link Here
14
14
15
import java.util.Vector;
15
import java.util.Vector;
16
16
17
import org.eclipse.persistence.descriptors.ClassDescriptor;
18
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
17
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
18
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
20
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
21
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
20
21
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
22
import org.eclipse.persistence.sessions.Project;
22
import org.eclipse.persistence.sessions.Project;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
24
24
25
public class DirectCollectionOptionalNodeNullPolicyAttributeTestCases extends XMLMappingTestCases {
25
public class DirectCollectionOptionalNodeNullPolicyAttributeTestCases extends XMLMappingTestCases {
26
    private final static String XML_RESOURCE = //
27
    	"org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyAttribute.xml";
28
26
27
    private final static String XML_RESOURCE = "org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyAttribute.xml";
28
29
    public DirectCollectionOptionalNodeNullPolicyAttributeTestCases(String name) throws Exception {
29
    public DirectCollectionOptionalNodeNullPolicyAttributeTestCases(String name) throws Exception {
30
        super(name);
30
        super(name);
31
        setControlDocument(XML_RESOURCE);
31
        setControlDocument(XML_RESOURCE);
32
32
33
        AbstractNullPolicy aNullPolicy = new NullPolicy();
33
        AbstractNullPolicy aNullPolicy = new NullPolicy();
34
    	// alter unmarshal policy state
34
        // alter unmarshal policy state
35
    	aNullPolicy.setNullRepresentedByEmptyNode(false);
35
        aNullPolicy.setNullRepresentedByEmptyNode(false);
36
    	aNullPolicy.setNullRepresentedByXsiNil(false);
36
        aNullPolicy.setNullRepresentedByXsiNil(false);
37
    	// alter marshal policy state
37
        // alter marshal policy state
38
    	aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);
38
        aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);
39
39
        Project aProject = new DirectCollectionNodeNullPolicyProject(false);
40
        Project aProject = new DirectCollectionNodeNullPolicyProject(false);
40
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping)aProject.getDescriptor(Employee.class)//
41
        ClassDescriptor aDescriptor = aProject.getDescriptor(Employee.class);
41
        .getMappingForAttributeName("tasks");
42
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping) aDescriptor.getMappingForAttributeName("tasks");
42
        // TODO: renable after we implement NullPolicy for this mapping
43
        aMapping.setNullPolicy(aNullPolicy);
43
        //aMapping.setNullPolicy(aNullPolicy);
44
        setProject(aProject);
44
        setProject(aProject);
45
    }
45
    }
46
46
47
    protected Object getControlObject() {
47
    protected Object getControlObject() {
48
        Employee anEmployee = new Employee();
48
        Employee anEmployee = new Employee();
49
        anEmployee.setId(123);
49
        anEmployee.setId(123);
50
        //anEmployee.setFirstName(null);
50
        anEmployee.setFirstName(null);
51
        Vector aVector = new Vector();
51
        Vector aVector = new Vector();
52
        //aVector.add(null);
52
        aVector.add(null);
53
        aVector.add("write code");
53
        aVector.add("write code");
54
        //aVector.add(null);
54
        aVector.add(null);
55
        anEmployee.setTasks(aVector);
55
        anEmployee.setTasks(aVector);
56
        anEmployee.setLastName("Doe");
56
        anEmployee.setLastName("Doe");
57
        return anEmployee;
57
        return anEmployee;
58
    }
58
    }
59
}
59
60
    public Object getReadControlObject() {
61
        Employee anEmployee = new Employee();
62
        anEmployee.setId(123);
63
        anEmployee.setFirstName(null);
64
        Vector aVector = new Vector();
65
        aVector.add("write code");
66
        anEmployee.setTasks(aVector);
67
        anEmployee.setLastName("Doe");
68
        return anEmployee;
69
    }
70
71
}
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyElementTestCases.java (-21 / +33 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution. 
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
Lines 14-59 Link Here
14
14
15
import java.util.Vector;
15
import java.util.Vector;
16
16
17
import org.eclipse.persistence.descriptors.ClassDescriptor;
18
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
17
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
18
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
20
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
19
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
21
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
20
21
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
22
import org.eclipse.persistence.sessions.Project;
22
import org.eclipse.persistence.sessions.Project;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
23
import org.eclipse.persistence.testing.oxm.mappings.XMLMappingTestCases;
24
24
25
public class DirectCollectionOptionalNodeNullPolicyElementTestCases extends XMLMappingTestCases {
25
public class DirectCollectionOptionalNodeNullPolicyElementTestCases extends XMLMappingTestCases {
26
    private final static String XML_RESOURCE = //
27
    	"org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyElement.xml";
28
26
27
    private final static String XML_RESOURCE = "org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/DirectCollectionOptionalNodeNullPolicyElement.xml";
28
29
    public DirectCollectionOptionalNodeNullPolicyElementTestCases(String name) throws Exception {
29
    public DirectCollectionOptionalNodeNullPolicyElementTestCases(String name) throws Exception {
30
        super(name);
30
        super(name);
31
        setControlDocument(XML_RESOURCE);
31
        setControlDocument(XML_RESOURCE);
32
32
33
        AbstractNullPolicy aNullPolicy = new NullPolicy();
33
        AbstractNullPolicy aNullPolicy = new NullPolicy();
34
    	// alter unmarshal policy state
34
        // alter unmarshal policy state
35
    	aNullPolicy.setNullRepresentedByEmptyNode(false);
35
        aNullPolicy.setNullRepresentedByEmptyNode(false);
36
    	aNullPolicy.setNullRepresentedByXsiNil(false);
36
        aNullPolicy.setNullRepresentedByXsiNil(false);
37
    	// alter marshal policy state
37
        // alter marshal policy state
38
    	aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);
38
        aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);
39
39
        Project aProject = new DirectCollectionNodeNullPolicyProject(true);
40
        Project aProject = new DirectCollectionNodeNullPolicyProject(true);
40
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping)aProject.getDescriptor(Employee.class)//
41
        ClassDescriptor aDescriptor = aProject.getDescriptor(Employee.class);
41
        .getMappingForAttributeName("tasks");
42
        XMLCompositeDirectCollectionMapping aMapping = (XMLCompositeDirectCollectionMapping) aDescriptor.getMappingForAttributeName("tasks");
42
        // TODO: renable after we implement NullPolicy for this mapping
43
        aMapping.setNullPolicy(aNullPolicy);
43
        //aMapping.setNullPolicy(aNullPolicy);
44
        setProject(aProject);
44
        setProject(aProject);
45
    }
45
    }
46
46
47
    protected Object getControlObject() {
47
    protected Object getControlObject() {
48
        Employee anEmployee = new Employee();
48
        Employee anEmployee = new Employee();
49
        anEmployee.setId(123);
49
        anEmployee.setId(123);
50
        //anEmployee.setFirstName(null);
50
        anEmployee.setFirstName(null);
51
        Vector aVector = new Vector();
51
        Vector aVector = new Vector();
52
        //aVector.add(null);
52
        aVector.add(null);
53
        aVector.add("write code");
53
        aVector.add("write code");
54
        //aVector.add(null);
54
        aVector.add(null);
55
        anEmployee.setTasks(aVector);
55
        anEmployee.setTasks(aVector);
56
        anEmployee.setLastName("Doe");
56
        anEmployee.setLastName("Doe");
57
        return anEmployee;
57
        return anEmployee;
58
    }
58
    }
59
}
59
60
    public Object getReadControlObject() {
61
        Employee anEmployee = new Employee();
62
        anEmployee.setId(123);
63
        anEmployee.setFirstName(null);
64
        Vector aVector = new Vector();
65
        aVector.add("write code");
66
        anEmployee.setTasks(aVector);
67
        anEmployee.setLastName("Doe");
68
        return anEmployee;
69
    }
70
71
}
(-)moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/mappings/directcollection/nillable/Employee.java (-83 / +78 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
2
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
5
 * which accompanies this distribution. 
5
 * which accompanies this distribution.
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
7
 * and the Eclipse Distribution License is available at
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
Lines 15-152 Link Here
15
import java.util.Vector;
15
import java.util.Vector;
16
16
17
public class Employee {
17
public class Employee {
18
18
    public static final int DEFAULT_ID = 123;
19
    public static final int DEFAULT_ID = 123;
19
    
20
20
    // Factory method
21
    public static Employee getInstance() {
22
        return new Employee(DEFAULT_ID, new Vector(), "Doe");
23
    }
24
    
25
    private int id;
21
    private int id;
26
    private Vector tasks;	// of type <String>
22
    private Vector tasks;
27
    //private String firstName;
23
    private String firstName;
28
    private String lastName;
24
    private String lastName;
29
25
30
    //public String getFirstName() {
31
    //    return firstName;
32
    //}
33
34
    private boolean isSetTasks = false;
26
    private boolean isSetTasks = false;
35
27
36
    //public void setFirstName(String firstName) {
28
    // ==============================================
37
        // no unset for now
38
    //    isSetFirstName = true;
39
    //    this.firstName = firstName;
40
    //}
41
29
42
    public Employee() {
30
    public Employee() {
43
        super();        
31
        super();
44
        //tasks = new Vector();
32
        setTasks(new Vector());
33
        isSetTasks = true;
45
    }
34
    }
46
35
47
    public Employee(int id) {
36
    public Employee(int id) {
48
        super();
37
        super();
49
        //tasks = new Vector();
50
        //isSetTasks = true;
51
        this.id = id;
38
        this.id = id;
39
        setTasks(new Vector());
52
    }
40
    }
53
41
54
    public Employee(int id, Vector aVector, String lastName) {
42
    public Employee(int id, Vector aVector, String lastName) {
55
        super();
43
        super();
56
        this.id = id;
44
        this.id = id;
57
        setTasks(aVector);
45
        setTasks(aVector);
58
        //this.firstName = firstName;
59
        this.lastName = lastName;
46
        this.lastName = lastName;
60
    }
47
    }
61
48
49
    // Factory method
50
    public static Employee getInstance() {
51
        return new Employee(DEFAULT_ID, new Vector(), "Doe");
52
    }
53
54
    // ==============================================
55
56
    public int getId() {
57
        return id;
58
    }
59
60
    public void setId(int id) {
61
        this.id = id;
62
    }
63
64
    public String getFirstName() {
65
        return firstName;
66
    }
67
68
    public void setFirstName(String firstName) {
69
        this.firstName = firstName;
70
    }
71
72
    public String getLastName() {
73
        return lastName;
74
    }
75
76
    public void setLastName(String lastName) {
77
        this.lastName = lastName;
78
    }
79
80
    public Vector getTasks() {
81
        return tasks;
82
    }
83
84
    public void setTasks(Vector tasks) {
85
        this.tasks = tasks;
86
        isSetTasks = (tasks == null) ? false : true;
87
    }
88
89
    public boolean isSetTasks() {
90
        return isSetTasks;
91
    }
92
62
    // override default equals
93
    // override default equals
63
    public boolean equals(Object object) {
94
    public boolean equals(Object object) {
64
        if (!(object instanceof Employee)) {
95
        if (!(object instanceof Employee)) {
65
            return false;
96
            return false;
66
        }
97
        }
67
        Employee employeeObject = (Employee)object;
98
        Employee employeeObject = (Employee) object;
68
        if (getId() != employeeObject.getId()) {
99
        if (getId() != employeeObject.getId()) {
69
            return false;
100
            return false;
70
        }
101
        }
71
        if ((employeeObject.getLastName() == null) && (getLastName() != null)) {
102
        if ((employeeObject.getLastName() == null) && (getLastName() != null)) {
72
            return false;
103
            return false;
73
        }
104
        }
74
        //if ((employeeObject.getFirstName() == null) && (getFirstName() != null)) {
105
        if ((employeeObject.getFirstName() == null) && (getFirstName() != null)) {
75
        //    return false;
106
            return false;
76
        //}
107
        }
77
        if ((employeeObject.getLastName() != null) && (getLastName() == null)) {
108
        if ((employeeObject.getLastName() != null) && (getLastName() == null)) {
78
            return false;
109
            return false;
79
        }
110
        }
80
        //if ((employeeObject.getFirstName() != null) && (getFirstName() == null)) {
111
        if ((employeeObject.getFirstName() != null) && (getFirstName() == null)) {
81
        //    return false;
82
        //}
83
        //if ((getFirstName() != null) && (employeeObject.getFirstName() != null) && !getFirstName().equals(employeeObject.getFirstName())) {
84
        //    return false;
85
        //}
86
        if ((getLastName() != null) && (employeeObject.getLastName() != null) && // 
87
        		!getLastName().equals(employeeObject.getLastName())) {
88
            return false;
112
            return false;
89
        }
113
        }
114
        if ((getFirstName() != null) && (employeeObject.getFirstName() != null) && !getFirstName().equals(employeeObject.getFirstName())) {
115
            return false;
116
        }
117
        if ((getLastName() != null) && (employeeObject.getLastName() != null) && !getLastName().equals(employeeObject.getLastName())) {
118
            return false;
119
        }
90
        if ((employeeObject.getTasks() == null) && (getTasks() != null)) {
120
        if ((employeeObject.getTasks() == null) && (getTasks() != null)) {
91
            return false;
121
            return false;
92
        }
122
        }
93
        if ((employeeObject.getTasks() != null) && (getTasks() == null)) {
123
        if ((employeeObject.getTasks() != null) && (getTasks() == null)) {
94
            return false;
124
            return false;
95
        }
125
        }
96
        if ((employeeObject.getTasks() != null) && (getTasks() != null) && //
126
        if ((employeeObject.getTasks() != null) && (getTasks() != null) && (!(employeeObject.getTasks() instanceof Vector) || !(getTasks() instanceof Vector))) {
97
        		(!(employeeObject.getTasks() instanceof Vector) || !(getTasks() instanceof Vector))) {
98
            return false;
127
            return false;
99
        }
128
        }
100
129
101
        if((this.getId() == employeeObject.getId()) && //
130
        if((this.getId() == employeeObject.getId()) && //
102
        	      ((this.getTasks()==null && employeeObject.getTasks()==null) || //
131
                ((this.getTasks()==null && employeeObject.getTasks()==null) || //
103
        	    		  (this.getTasks().isEmpty() && employeeObject.getTasks().isEmpty()) || //
132
                        (this.getTasks().isEmpty() && employeeObject.getTasks().isEmpty()) || //
104
        	    		  (this.getTasks().containsAll(employeeObject.getTasks()))) && //
133
                        (this.getTasks().containsAll(employeeObject.getTasks()))) && //
105
        	    		  (this.getTasks().size() == employeeObject.getTasks().size())) {
134
                        (this.getTasks().size() == employeeObject.getTasks().size())) {
106
        	return true;
135
        	return true;
107
        }
136
        }
108
        
137
109
        // todo handle :
110
        /*Expected:
111
        	Employee(123,[null, write code, null],Doe)
112
        	Actual:
113
        	Employee(123,[write code],Doe)
114
        */
115
        return false;
138
        return false;
116
    }
139
    }
117
140
118
    public int getId() {
141
    // ==============================================
119
        return id;
120
    }
121
142
122
    public String getLastName() {
143
    public String toString() {
123
        return lastName;
144
        return "Employee(" + getId() + "," + firstName + "," + tasks +  "," + lastName + ")";
124
    }
145
    }
125
146
126
    public Vector getTasks() {
147
}
127
		return tasks;
128
	}
129
130
    public boolean isSetTasks() {
131
        return isSetTasks;
132
    }
133
134
    public void setId(int id) {
135
        this.id = id;
136
    }
137
138
    public void setLastName(String lastName) {
139
        this.lastName = lastName;
140
    }
141
142
	public void setTasks(Vector tasks) {
143
		this.tasks = tasks;
144
		isSetTasks = true;
145
	}
146
147
	public String toString() {
148
        return "Employee(" + getId() + "," + //firstName + "," +
149
        	tasks +  "," +
150
        	lastName + ")";
151
    }
152
}
(-)moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/MappingsGenerator.java (-1 / +4 lines)
Lines 1115-1121 Link Here
1115
            ((XMLField) mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
1115
            ((XMLField) mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
1116
        }
1116
        }
1117
        
1117
        
1118
       	
1118
        if (property.getActualType() == null || property.getActualType().getRawName().equals("java.lang.String")) {
1119
            mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
1120
        }     
1121
        
1119
        if(property.isXmlElementType() && property.getGenericType()!=null ){           	
1122
        if(property.isXmlElementType() && property.getGenericType()!=null ){           	
1120
        	Class theClass = helper.getClassForJavaClass(property.getGenericType());
1123
        	Class theClass = helper.getClassForJavaClass(property.getGenericType());
1121
        	mapping.setAttributeElementClass(theClass);
1124
        	mapping.setAttributeElementClass(theClass);

Return to bug 283453