1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
451 }
452 }
453
454 /**
455 * Common finalization of {@link CPropertyInfo} for the create***Property methods.
456 */
457 private <T extends CPropertyInfo> T wrapUp(T prop, XSComponent source) {
458 prop.javadoc = concat(javadoc,
459 getBuilder().getBindInfo(source).getDocumentation());
460 if(prop.javadoc==null)
461 prop.javadoc="";
462
463 // decide the realization.
464 FieldRenderer r;
465 OptionalPropertyMode opm = getOptionalPropertyMode();
466 if(prop.isCollection()) {
467 CollectionTypeAttribute ct = getCollectionType();
468 r = ct.get(getBuilder().model);
469 } else {
470 FieldRendererFactory frf = getBuilder().fieldRendererFactory;
471
472 if(prop.isOptionalPrimitive()) {
473 // the property type can be primitive type if we are to ignore absence
474 switch(opm) {
475 case PRIMITIVE:
476 r = frf.getRequiredUnboxed();
477 break;
478 case WRAPPER:
479 // force the wrapper type
480 r = frf.getSingle();
481 break;
482 case ISSET:
483 r = frf.getSinglePrimitiveAccess();
484 break;
485 default:
486 throw new Error();
487 }
488 } else {
489 r = frf.getDefault();
490 }
491 }
492 if(opm==OptionalPropertyMode.ISSET) {
493 // only isSet is allowed on a collection. these 3 modes aren't really symmetric.
494
495 // if the property is a primitive type, we need an explicit unset because
496 // we can't overload the meaning of set(null).
497 // if it's a collection, we need to be able to unset it so that we can distinguish
498 // null list and empty list.
499 r = new IsSetFieldRenderer( r, prop.isOptionalPrimitive()||prop.isCollection(), true );
500 }
501
502 prop.realization = r;
503
504 JType bt = getBaseType();
505 if(bt!=null)
506 prop.baseType = bt;
507
508 return prop;
509 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
451 }
452 }
453
454 /**
455 * Common finalization of {@link CPropertyInfo} for the create***Property methods.
456 */
457 private <T extends CPropertyInfo> T wrapUp(T prop, XSComponent source) {
458 prop.javadoc = concat(javadoc,
459 getBuilder().getBindInfo(source).getDocumentation());
460 if(prop.javadoc==null)
461 prop.javadoc="";
462
463 // decide the realization.
464 FieldRenderer r;
465 OptionalPropertyMode opm = getOptionalPropertyMode();
466 if(prop.isCollection()) {
467 CollectionTypeAttribute ct = getCollectionType();
468 r = ct.get(getBuilder().model);
469 } else {
470 FieldRendererFactory frf = getBuilder().fieldRendererFactory;
471 // according to the spec we should bahave as in jaxb1. So we ignore possiblity that property could be nullable
472 switch(opm) {
473 // the property type can be primitive type if we are to ignore absence
474 case PRIMITIVE:
475 r = frf.getRequiredUnboxed();
476 break;
477 case WRAPPER:
478 // force the wrapper type
479 r = prop.isOptionalPrimitive() ? frf.getSingle() : frf.getDefault();
480 break;
481 case ISSET:
482 r = prop.isOptionalPrimitive() ? frf.getSinglePrimitiveAccess() : frf.getDefault();
483 break;
484 default:
485 throw new Error();
486
487 }
488 }
489 if(opm==OptionalPropertyMode.ISSET) {
490 // only isSet is allowed on a collection. these 3 modes aren't really symmetric.
491
492 // if the property is a primitive type, we need an explicit unset because
493 // we can't overload the meaning of set(null).
494 // if it's a collection, we need to be able to unset it so that we can distinguish
495 // null list and empty list.
496 r = new IsSetFieldRenderer( r, prop.isOptionalPrimitive()||prop.isCollection(), true );
497 }
498
499 prop.realization = r;
500
501 JType bt = getBaseType();
502 if(bt!=null)
503 prop.baseType = bt;
504
505 return prop;
506 }
|