Source Code Cross Referenced for BIProperty.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » tools » xjc » reader » xmlschema » bindinfo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb xjc » com.sun.tools.xjc.reader.xmlschema.bindinfo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common Development
008:         * and Distribution License("CDDL") (collectively, the "License").  You
009:         * may not use this file except in compliance with the License. You can obtain
010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         * language governing permissions and limitations under the License.
013:         * 
014:         * When distributing the software, include this License Header Notice in each
015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         * Sun designates this particular file as subject to the "Classpath" exception
017:         * as provided by Sun in the GPL Version 2 section of the License file that
018:         * accompanied this code.  If applicable, add the following below the License
019:         * Header, with the fields enclosed by brackets [] replaced by your own
020:         * identifying information: "Portions Copyrighted [year]
021:         * [name of copyright owner]"
022:         * 
023:         * Contributor(s):
024:         * 
025:         * If you wish your version of this file to be governed by only the CDDL or
026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         * elects to include this software in this distribution under the [CDDL or GPL
028:         * Version 2] license."  If you don't indicate a single choice of license, a
029:         * recipient has the option to distribute your version of this file under
030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         * its licensees as provided above.  However, if you add GPL Version 2 code
032:         * and therefore, elected the GPL Version 2 license, then the option applies
033:         * only if the new code is made subject to such option by the copyright
034:         * holder.
035:         */
036:        package com.sun.tools.xjc.reader.xmlschema.bindinfo;
037:
038:        import java.util.Collection;
039:        import java.util.Collections;
040:
041:        import javax.xml.bind.annotation.XmlAttribute;
042:        import javax.xml.bind.annotation.XmlElement;
043:        import javax.xml.bind.annotation.XmlElementRef;
044:        import javax.xml.bind.annotation.XmlRootElement;
045:        import javax.xml.namespace.QName;
046:
047:        import com.sun.codemodel.JJavaName;
048:        import com.sun.codemodel.JType;
049:        import com.sun.tools.xjc.ErrorReceiver;
050:        import com.sun.tools.xjc.generator.bean.field.FieldRenderer;
051:        import com.sun.tools.xjc.generator.bean.field.FieldRendererFactory;
052:        import com.sun.tools.xjc.generator.bean.field.IsSetFieldRenderer;
053:        import com.sun.tools.xjc.model.CAttributePropertyInfo;
054:        import com.sun.tools.xjc.model.CCustomizations;
055:        import com.sun.tools.xjc.model.CElementPropertyInfo;
056:        import com.sun.tools.xjc.model.CPropertyInfo;
057:        import com.sun.tools.xjc.model.CReferencePropertyInfo;
058:        import com.sun.tools.xjc.model.CValuePropertyInfo;
059:        import com.sun.tools.xjc.model.TypeUse;
060:        import com.sun.tools.xjc.reader.Const;
061:        import com.sun.tools.xjc.reader.RawTypeSet;
062:        import com.sun.tools.xjc.reader.Ring;
063:        import com.sun.tools.xjc.reader.TypeUtil;
064:        import com.sun.tools.xjc.reader.xmlschema.BGMBuilder;
065:        import com.sun.xml.bind.api.impl.NameConverter;
066:        import com.sun.xml.xsom.XSAnnotation;
067:        import com.sun.xml.xsom.XSAttGroupDecl;
068:        import com.sun.xml.xsom.XSAttributeDecl;
069:        import com.sun.xml.xsom.XSAttributeUse;
070:        import com.sun.xml.xsom.XSComplexType;
071:        import com.sun.xml.xsom.XSComponent;
072:        import com.sun.xml.xsom.XSContentType;
073:        import com.sun.xml.xsom.XSElementDecl;
074:        import com.sun.xml.xsom.XSFacet;
075:        import com.sun.xml.xsom.XSIdentityConstraint;
076:        import com.sun.xml.xsom.XSModelGroup;
077:        import com.sun.xml.xsom.XSModelGroupDecl;
078:        import com.sun.xml.xsom.XSNotation;
079:        import com.sun.xml.xsom.XSParticle;
080:        import com.sun.xml.xsom.XSSchema;
081:        import com.sun.xml.xsom.XSSimpleType;
082:        import com.sun.xml.xsom.XSWildcard;
083:        import com.sun.xml.xsom.XSXPath;
084:        import com.sun.xml.xsom.util.XSFinder;
085:        import com.sun.xml.xsom.visitor.XSFunction;
086:
087:        import org.xml.sax.Locator;
088:
089:        /**
090:         * Property customization.
091:         * 
092:         * This customization turns an arbitrary schema component
093:         * into a Java property (some restrictions apply.)
094:         * 
095:         * <p>
096:         * All the getter methods (such as <code>getBaseType</code> or
097:         * <code>getBindStyle</code>) honors the delegation chain of
098:         * property customization specified in the spec. Namely,
099:         * if two property customizations are attached to an attribute
100:         * use and an attribute decl, then anything unspecified in the
101:         * attribute use defaults to attribute decl.
102:         * 
103:         * <p>
104:         * Property customizations are acknowledged
105:         * (1) when they are actually used, and
106:         * (2) when they are given at the component, which is mapped to a class.
107:         *     (so-called "point of declaration" customization)
108:         * 
109:         * @author
110:         *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
111:         */
112:        @XmlRootElement(name="property")
113:        public final class BIProperty extends AbstractDeclarationImpl {
114:
115:            // can be null
116:            @XmlAttribute
117:            private String name = null;
118:
119:            // can be null
120:            @XmlElement
121:            private String javadoc = null;
122:
123:            // can be null
124:            @XmlElement
125:            private BaseTypeBean baseType = null;
126:
127:            // TODO: report 'unsupported' error if this is true
128:            @XmlAttribute
129:            private boolean generateFailFastSetterMethod = false;
130:
131:            public BIProperty(Locator loc, String _propName, String _javadoc,
132:                    BaseTypeBean _baseType,
133:                    CollectionTypeAttribute collectionType, Boolean isConst,
134:                    OptionalPropertyMode optionalProperty, Boolean genElemProp) {
135:                super (loc);
136:
137:                this .name = _propName;
138:                this .javadoc = _javadoc;
139:                this .baseType = _baseType;
140:                this .collectionType = collectionType;
141:                this .isConstantProperty = isConst;
142:                this .optionalProperty = optionalProperty;
143:                this .generateElementProperty = genElemProp;
144:            }
145:
146:            protected BIProperty() {
147:            }
148:
149:            @Override
150:            public Collection<BIDeclaration> getChildren() {
151:                BIConversion conv = getConv();
152:                if (conv == null)
153:                    return super .getChildren();
154:                else
155:                    return Collections.<BIDeclaration> singleton(conv);
156:            }
157:
158:            public void setParent(BindInfo parent) {
159:                super .setParent(parent);
160:                if (baseType != null && baseType.conv != null)
161:                    baseType.conv.setParent(parent);
162:            }
163:
164:            /**
165:             * Returns the customized property name.
166:             * 
167:             * This method honors the "enableJavaNamingConvention" customization
168:             * and formats the property name accordingly if necessary.
169:             * 
170:             * Thus the caller should <em>NOT</em> apply the XML-to-Java name
171:             * conversion algorithm to the value returned from this method.
172:             * 
173:             * @param forConstant
174:             *      If the property name is intended for a constant property name,
175:             *      set to true. This will change the result
176:             * 
177:             * @return
178:             *      This method can return null if the customization doesn't
179:             *      specify the name.
180:             */
181:            public String getPropertyName(boolean forConstant) {
182:                if (name != null) {
183:                    BIGlobalBinding gb = getBuilder().getGlobalBinding();
184:                    NameConverter nc = getBuilder().model.getNameConverter();
185:
186:                    if (gb.isJavaNamingConventionEnabled() && !forConstant)
187:                        // apply XML->Java conversion
188:                        return nc.toPropertyName(name);
189:                    else
190:                        return name; // ... or don't change the value
191:                }
192:                BIProperty next = getDefault();
193:                if (next != null)
194:                    return next.getPropertyName(forConstant);
195:                else
196:                    return null;
197:            }
198:
199:            /**
200:             * Gets the associated javadoc.
201:             * 
202:             * @return
203:             *      null if none is specfieid.
204:             */
205:            public String getJavadoc() {
206:                return javadoc;
207:            }
208:
209:            // can be null
210:            public JType getBaseType() {
211:                if (baseType != null && baseType.name != null) {
212:                    return TypeUtil.getType(getCodeModel(), baseType.name, Ring
213:                            .get(ErrorReceiver.class), getLocation());
214:                }
215:                BIProperty next = getDefault();
216:                if (next != null)
217:                    return next.getBaseType();
218:                else
219:                    return null;
220:            }
221:
222:            // can be null
223:            @XmlAttribute
224:            private CollectionTypeAttribute collectionType = null;
225:
226:            /**
227:             * Gets the realization of this field.
228:             * @return Always return non-null.
229:             */
230:            CollectionTypeAttribute getCollectionType() {
231:                if (collectionType != null)
232:                    return collectionType;
233:                return getDefault().getCollectionType();
234:            }
235:
236:            @XmlAttribute
237:            private OptionalPropertyMode optionalProperty = null;
238:
239:            // virtual property for @generateIsSetMethod
240:            @XmlAttribute
241:            void setGenerateIsSetMethod(boolean b) {
242:                optionalProperty = b ? OptionalPropertyMode.ISSET
243:                        : OptionalPropertyMode.WRAPPER;
244:            }
245:
246:            public OptionalPropertyMode getOptionalPropertyMode() {
247:                if (optionalProperty != null)
248:                    return optionalProperty;
249:                return getDefault().getOptionalPropertyMode();
250:            }
251:
252:            // null if delegated
253:            @XmlAttribute
254:            private Boolean generateElementProperty = null;
255:
256:            /**
257:             * If true, the property will automatically be a reference property.
258:             * (Talk about confusing names!)
259:             */
260:            private Boolean generateElementProperty() {
261:                if (generateElementProperty != null)
262:                    return generateElementProperty;
263:                BIProperty next = getDefault();
264:                if (next != null)
265:                    return next.generateElementProperty();
266:
267:                return null;
268:            }
269:
270:            // true, false, or null (which means the value should be inherited.)
271:            @XmlAttribute(name="fixedAttributeAsConstantProperty")
272:            private Boolean isConstantProperty;
273:
274:            /**
275:             * Gets the inherited value of the "fixedAttrToConstantProperty" customization.
276:             * 
277:             * <p>
278:             * Note that returning true from this method doesn't necessarily mean
279:             * that a property needs to be mapped to a constant property.
280:             * It just means that it's mapped to a constant property
281:             * <b>if an attribute use carries a fixed value.</b>
282:             * 
283:             * <p>
284:             * I don't like this semantics but that's what the spec implies.
285:             */
286:            public boolean isConstantProperty() {
287:                if (isConstantProperty != null)
288:                    return isConstantProperty;
289:
290:                BIProperty next = getDefault();
291:                if (next != null)
292:                    return next.isConstantProperty();
293:
294:                // globalBinding always has true or false in this property,
295:                // so this can't happen
296:                throw new AssertionError();
297:            }
298:
299:            public CValuePropertyInfo createValueProperty(String defaultName,
300:                    boolean forConstant, XSComponent source, TypeUse tu,
301:                    QName typeName) {
302:
303:                markAsAcknowledged();
304:                constantPropertyErrorCheck();
305:
306:                String name = getPropertyName(forConstant);
307:                if (name == null) {
308:                    name = defaultName;
309:                    if (tu.isCollection()
310:                            && getBuilder().getGlobalBinding().isSimpleMode())
311:                        name = JJavaName.getPluralForm(name);
312:                }
313:
314:                CValuePropertyInfo prop = wrapUp(new CValuePropertyInfo(name,
315:                        source, getCustomizations(source), source.getLocator(),
316:                        tu, typeName), source);
317:                BIInlineBinaryData.handle(source, prop);
318:                return prop;
319:            }
320:
321:            public CAttributePropertyInfo createAttributeProperty(
322:                    XSAttributeUse use, TypeUse tu) {
323:
324:                boolean forConstant = getCustomization(use)
325:                        .isConstantProperty()
326:                        && use.getFixedValue() != null;
327:
328:                String name = getPropertyName(forConstant);
329:                if (name == null) {
330:                    NameConverter conv = getBuilder().getNameConverter();
331:                    if (forConstant)
332:                        name = conv.toConstantName(use.getDecl().getName());
333:                    else
334:                        name = conv.toPropertyName(use.getDecl().getName());
335:                    if (tu.isCollection()
336:                            && getBuilder().getGlobalBinding().isSimpleMode())
337:                        name = JJavaName.getPluralForm(name);
338:                }
339:
340:                markAsAcknowledged();
341:                constantPropertyErrorCheck();
342:
343:                return wrapUp(new CAttributePropertyInfo(name, use,
344:                        getCustomizations(use), use.getLocator(), BGMBuilder
345:                                .getName(use.getDecl()), tu, BGMBuilder
346:                                .getName(use.getDecl().getType()), use
347:                                .isRequired()), use);
348:            }
349:
350:            /**
351:             * 
352:             *
353:             * @param defaultName
354:             *      If the name is not customized, this name will be used
355:             *      as the default. Note that the name conversion <b>MUST</b>
356:             *      be applied before this method is called if necessary.
357:             * @param source
358:             *      Source schema component from which a field is built.
359:             */
360:            public CElementPropertyInfo createElementProperty(
361:                    String defaultName, boolean forConstant, XSParticle source,
362:                    RawTypeSet types) {
363:
364:                if (!types.refs.isEmpty())
365:                    // if this property is empty, don't acknowleedge the customization
366:                    // this allows pointless property customization to be reported as an error
367:                    markAsAcknowledged();
368:                constantPropertyErrorCheck();
369:
370:                String name = getPropertyName(forConstant);
371:                if (name == null)
372:                    name = defaultName;
373:
374:                CElementPropertyInfo prop = wrapUp(new CElementPropertyInfo(
375:                        name, types.getCollectionMode(), types.id(), types
376:                                .getExpectedMimeType(), source,
377:                        getCustomizations(source), source.getLocator(), types
378:                                .isRequired()), source);
379:
380:                types.addTo(prop);
381:
382:                BIInlineBinaryData.handle(source.getTerm(), prop);
383:                return prop;
384:            }
385:
386:            public CReferencePropertyInfo createReferenceProperty(
387:                    String defaultName, boolean forConstant,
388:                    XSComponent source, RawTypeSet types, boolean isMixed) {
389:
390:                if (!types.refs.isEmpty())
391:                    // if this property is empty, don't acknowleedge the customization
392:                    // this allows pointless property customization to be reported as an error
393:                    markAsAcknowledged();
394:                constantPropertyErrorCheck();
395:
396:                String name = getPropertyName(forConstant);
397:                if (name == null)
398:                    name = defaultName;
399:
400:                CReferencePropertyInfo prop = wrapUp(
401:                        new CReferencePropertyInfo(name, types
402:                                .getCollectionMode().isRepeated()
403:                                || isMixed, isMixed, source,
404:                                getCustomizations(source), source.getLocator()),
405:                        source);
406:
407:                types.addTo(prop);
408:
409:                BIInlineBinaryData.handle(source, prop);
410:                return prop;
411:            }
412:
413:            public CPropertyInfo createElementOrReferenceProperty(
414:                    String defaultName, boolean forConstant, XSParticle source,
415:                    RawTypeSet types) {
416:
417:                boolean generateRef;
418:
419:                switch (types.canBeTypeRefs) {
420:                case CAN_BE_TYPEREF:
421:                case SHOULD_BE_TYPEREF:
422:                    // it's up to the use
423:                    Boolean b = generateElementProperty();
424:                    if (b == null) // follow XJC recommendation
425:                        generateRef = types.canBeTypeRefs == RawTypeSet.Mode.CAN_BE_TYPEREF;
426:                    else
427:                        // use the value user gave us
428:                        generateRef = b;
429:                    break;
430:                case MUST_BE_REFERENCE:
431:                    generateRef = true;
432:                    break;
433:                default:
434:                    throw new AssertionError();
435:                }
436:
437:                if (generateRef) {
438:                    return createReferenceProperty(defaultName, forConstant,
439:                            source, types, false);
440:                } else {
441:                    return createElementProperty(defaultName, forConstant,
442:                            source, types);
443:                }
444:            }
445:
446:            /**
447:             * Common finalization of {@link CPropertyInfo} for the create***Property methods.
448:             */
449:            private <T extends CPropertyInfo> T wrapUp(T prop,
450:                    XSComponent source) {
451:                prop.javadoc = concat(javadoc, getBuilder().getBindInfo(source)
452:                        .getDocumentation());
453:                if (prop.javadoc == null)
454:                    prop.javadoc = "";
455:
456:                // decide the realization.
457:                FieldRenderer r;
458:                OptionalPropertyMode opm = getOptionalPropertyMode();
459:                if (prop.isCollection()) {
460:                    CollectionTypeAttribute ct = getCollectionType();
461:                    r = ct.get(getBuilder().model);
462:                } else {
463:                    FieldRendererFactory frf = getBuilder().fieldRendererFactory;
464:
465:                    if (prop.isOptionalPrimitive()) {
466:                        // the property type can be primitive type if we are to ignore absence
467:                        switch (opm) {
468:                        case PRIMITIVE:
469:                            r = frf.getRequiredUnboxed();
470:                            break;
471:                        case WRAPPER:
472:                            // force the wrapper type
473:                            r = frf.getSingle();
474:                            break;
475:                        case ISSET:
476:                            r = frf.getSinglePrimitiveAccess();
477:                            break;
478:                        default:
479:                            throw new Error();
480:                        }
481:                    } else {
482:                        r = frf.getDefault();
483:                    }
484:                }
485:                if (opm == OptionalPropertyMode.ISSET) {
486:                    // only isSet is allowed on a collection. these 3 modes aren't really symmetric.
487:
488:                    // if the property is a primitive type, we need an explicit unset because
489:                    // we can't overload the meaning of set(null).
490:                    // if it's a collection, we need to be able to unset it so that we can distinguish
491:                    // null list and empty list.
492:                    r = new IsSetFieldRenderer(r, prop.isOptionalPrimitive()
493:                            || prop.isCollection(), true);
494:                }
495:
496:                prop.realization = r;
497:
498:                JType bt = getBaseType();
499:                if (bt != null)
500:                    prop.baseType = bt;
501:
502:                return prop;
503:            }
504:
505:            private CCustomizations getCustomizations(XSComponent src) {
506:                return getBuilder().getBindInfo(src).toCustomizationList();
507:            }
508:
509:            private CCustomizations getCustomizations(XSComponent... src) {
510:                CCustomizations c = null;
511:                for (XSComponent s : src) {
512:                    CCustomizations r = getCustomizations(s);
513:                    if (c == null)
514:                        c = r;
515:                    else
516:                        c = CCustomizations.merge(c, r);
517:                }
518:                return c;
519:            }
520:
521:            private CCustomizations getCustomizations(XSAttributeUse src) {
522:                // customizations for an attribute use should include those defined in the local attribute.
523:                // this is so that the schema like:
524:                //
525:                // <xs:attribute name="foo" type="xs:int">
526:                //   <xs:annotation><xs:appinfo>
527:                //     <hyperjaxb:... />
528:                //
529:                // would be picked up
530:                if (src.getDecl().isLocal())
531:                    return getCustomizations(src, src.getDecl());
532:                else
533:                    return getCustomizations((XSComponent) src);
534:            }
535:
536:            private CCustomizations getCustomizations(XSParticle src) {
537:                // customizations for a particle  should include those defined in the term unless it's global
538:                // this is so that the schema like:
539:                //
540:                // <xs:sequence>
541:                //   <xs:element name="foo" type="xs:int">
542:                //     <xs:annotation><xs:appinfo>
543:                //       <hyperjaxb:... />
544:                //
545:                // would be picked up
546:                if (src.getTerm().isElementDecl()) {
547:                    XSElementDecl xed = src.getTerm().asElementDecl();
548:                    if (xed.isGlobal())
549:                        return getCustomizations((XSComponent) src);
550:                }
551:
552:                return getCustomizations(src, src.getTerm());
553:            }
554:
555:            public void markAsAcknowledged() {
556:                if (isAcknowledged())
557:                    return;
558:
559:                // mark the parent as well.
560:                super .markAsAcknowledged();
561:
562:                BIProperty def = getDefault();
563:                if (def != null)
564:                    def.markAsAcknowledged();
565:            }
566:
567:            private void constantPropertyErrorCheck() {
568:                if (isConstantProperty != null && getOwner() != null) {
569:                    // run additional check on the isCOnstantProperty value.
570:                    // this value is not allowed if the schema component doesn't have
571:                    // a fixed value constraint.
572:                    //
573:                    // the setParent method associates a customization with the rest of
574:                    // XSOM object graph, so this is the earliest possible moment where
575:                    // we can test this.
576:
577:                    if (!hasFixedValue.find(getOwner())) {
578:                        Ring.get(ErrorReceiver.class).error(getLocation(),
579:                                Messages.ERR_ILLEGAL_FIXEDATTR.format());
580:                        // set this value to null to avoid the same error to be reported more than once.
581:                        isConstantProperty = null;
582:                    }
583:                }
584:            }
585:
586:            /**
587:             * Function object that returns true if a component has
588:             * a fixed value constraint.
589:             */
590:            private final XSFinder hasFixedValue = new XSFinder() {
591:                public Boolean attributeDecl(XSAttributeDecl decl) {
592:                    return decl.getFixedValue() != null;
593:                }
594:
595:                public Boolean attributeUse(XSAttributeUse use) {
596:                    return use.getFixedValue() != null;
597:                }
598:
599:                public Boolean schema(XSSchema s) {
600:                    // we allow globalBindings to have isConstantProperty==true,
601:                    // so this method returns true to allow this.
602:                    return true;
603:                }
604:            };
605:
606:            /**
607:             * Finds a BIProperty which this object should delegate to.
608:             * 
609:             * @return
610:             *      always return non-null for normal BIProperties.
611:             *      If this object is contained in the BIGlobalBinding, then
612:             *      this method returns null to indicate that there's no more default.
613:             */
614:            protected BIProperty getDefault() {
615:                if (getOwner() == null)
616:                    return null;
617:                BIProperty next = getDefault(getBuilder(), getOwner());
618:                if (next == this )
619:                    return null; // global.
620:                else
621:                    return next;
622:            }
623:
624:            private static BIProperty getDefault(BGMBuilder builder,
625:                    XSComponent c) {
626:                while (c != null) {
627:                    c = c.apply(defaultCustomizationFinder);
628:                    if (c != null) {
629:                        BIProperty prop = builder.getBindInfo(c).get(
630:                                BIProperty.class);
631:                        if (prop != null)
632:                            return prop;
633:                    }
634:                }
635:
636:                // default to the global one
637:                return builder.getGlobalBinding().getDefaultProperty();
638:            }
639:
640:            /**
641:             * Finds a property customization that describes how the given
642:             * component should be mapped to a property (if it's mapped to
643:             * a property at all.)
644:             * 
645:             * <p>
646:             * Consider an attribute use that does NOT carry a property
647:             * customization. This schema component is nonetheless considered
648:             * to carry a (sort of) implicit property customization, whose values
649:             * are defaulted.
650:             * 
651:             * <p>
652:             * This method can be think of the method that returns this implied
653:             * property customization.
654:             * 
655:             * <p>
656:             * Note that this doesn't mean the given component needs to be
657:             * mapped to a property. But if it does map to a property, it needs
658:             * to follow this customization.
659:             * 
660:             * I think this semantics is next to non-sense but I couldn't think
661:             * of any other way to follow the spec.
662:             * 
663:             * @param c
664:             *      A customization effective on this component will be returned.
665:             *      Can be null just to get the global customization.
666:             * @return
667:             *      Always return non-null valid object.
668:             */
669:            public static BIProperty getCustomization(XSComponent c) {
670:                BGMBuilder builder = Ring.get(BGMBuilder.class);
671:
672:                // look for a customization on this component
673:                if (c != null) {
674:                    BIProperty prop = builder.getBindInfo(c).get(
675:                            BIProperty.class);
676:                    if (prop != null)
677:                        return prop;
678:                }
679:
680:                // if no such thing exists, defeault.
681:                return getDefault(builder, c);
682:            }
683:
684:            private final static XSFunction<XSComponent> defaultCustomizationFinder = new XSFunction<XSComponent>() {
685:
686:                public XSComponent attributeUse(XSAttributeUse use) {
687:                    return use.getDecl(); // inherit from the declaration
688:                }
689:
690:                public XSComponent particle(XSParticle particle) {
691:                    return particle.getTerm(); // inherit from the term
692:                }
693:
694:                public XSComponent schema(XSSchema schema) {
695:                    // no more delegation
696:                    return null;
697:                }
698:
699:                // delegates to the context schema object
700:                public XSComponent attributeDecl(XSAttributeDecl decl) {
701:                    return decl.getOwnerSchema();
702:                }
703:
704:                public XSComponent wildcard(XSWildcard wc) {
705:                    return wc.getOwnerSchema();
706:                }
707:
708:                public XSComponent modelGroupDecl(XSModelGroupDecl decl) {
709:                    return decl.getOwnerSchema();
710:                }
711:
712:                public XSComponent modelGroup(XSModelGroup group) {
713:                    return group.getOwnerSchema();
714:                }
715:
716:                public XSComponent elementDecl(XSElementDecl decl) {
717:                    return decl.getOwnerSchema();
718:                }
719:
720:                public XSComponent complexType(XSComplexType type) {
721:                    return type.getOwnerSchema();
722:                }
723:
724:                public XSComponent simpleType(XSSimpleType st) {
725:                    return st.getOwnerSchema();
726:                }
727:
728:                // property customizations are not allowed on these components.
729:                public XSComponent attGroupDecl(XSAttGroupDecl decl) {
730:                    throw new IllegalStateException();
731:                }
732:
733:                public XSComponent empty(XSContentType empty) {
734:                    throw new IllegalStateException();
735:                }
736:
737:                public XSComponent annotation(XSAnnotation xsAnnotation) {
738:                    throw new IllegalStateException();
739:                }
740:
741:                public XSComponent facet(XSFacet xsFacet) {
742:                    throw new IllegalStateException();
743:                }
744:
745:                public XSComponent notation(XSNotation xsNotation) {
746:                    throw new IllegalStateException();
747:                }
748:
749:                public XSComponent identityConstraint(XSIdentityConstraint x) {
750:                    throw new IllegalStateException();
751:                }
752:
753:                public XSComponent xpath(XSXPath xsxPath) {
754:                    throw new IllegalStateException();
755:                }
756:            };
757:
758:            private static String concat(String s1, String s2) {
759:                if (s1 == null)
760:                    return s2;
761:                if (s2 == null)
762:                    return s1;
763:                return s1 + "\n\n" + s2;
764:            }
765:
766:            public QName getName() {
767:                return NAME;
768:            }
769:
770:            /** Name of this declaration. */
771:            public static final QName NAME = new QName(Const.JAXB_NSURI,
772:                    "property");
773:
774:            public BIConversion getConv() {
775:                if (baseType != null)
776:                    return baseType.conv;
777:                else
778:                    return null;
779:            }
780:
781:            private static final class BaseTypeBean {
782:                /**
783:                 * If there's a nested javaType customization, this field
784:                 * will keep that customization. Otherwise null.
785:                 *
786:                 * This customization, if present, is used to customize
787:                 * the simple type mapping at the point of reference.
788:                 */
789:                @XmlElementRef
790:                BIConversion conv;
791:
792:                /**
793:                 * Java type name.
794:                 */
795:                @XmlAttribute
796:                String name;
797:            }
798:        }
ww__w___.__j_av_a_2__s__.c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.