Source Code Cross Referenced for RawTypeSet.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » tools » xjc » reader » 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 
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:
037:        package com.sun.tools.xjc.reader;
038:
039:        import java.util.HashSet;
040:        import java.util.List;
041:        import java.util.Set;
042:
043:        import javax.activation.MimeType;
044:
045:        import com.sun.tools.xjc.model.CElementPropertyInfo;
046:        import static com.sun.tools.xjc.model.CElementPropertyInfo.CollectionMode.*;
047:        import com.sun.tools.xjc.model.CReferencePropertyInfo;
048:        import com.sun.tools.xjc.model.CTypeRef;
049:        import com.sun.tools.xjc.model.Multiplicity;
050:        import com.sun.tools.xjc.model.nav.NType;
051:        import com.sun.xml.bind.v2.model.core.Element;
052:        import com.sun.xml.bind.v2.model.core.ID;
053:
054:        /**
055:         * Set of {@link Ref}.
056:         *
057:         * @author Kohsuke Kawaguchi
058:         */
059:        public final class RawTypeSet {
060:
061:            public final Set<Ref> refs;
062:
063:            /**
064:             * True if this type set can form references to types.
065:             */
066:            public final Mode canBeTypeRefs;
067:
068:            /**
069:             * The occurence of the whole references.
070:             */
071:            public final Multiplicity mul;
072:
073:            // computed inside canBeTypeRefs()
074:            private CElementPropertyInfo.CollectionMode collectionMode;
075:
076:            /**
077:             * Should be called from one of the raw type set builders.
078:             */
079:            public RawTypeSet(Set<Ref> refs, Multiplicity m) {
080:                this .refs = refs;
081:                mul = m;
082:                canBeTypeRefs = canBeTypeRefs();
083:            }
084:
085:            public CElementPropertyInfo.CollectionMode getCollectionMode() {
086:                return collectionMode;
087:            }
088:
089:            public boolean isRequired() {
090:                return mul.min > 0;
091:            }
092:
093:            /**
094:             * Represents the possible binding option for this {@link RawTypeSet}.
095:             */
096:            public enum Mode {
097:                /**
098:                 * This {@link RawTypeSet} can be either an reference property or
099:                 * an element property, and XJC recommends element property.
100:                 */
101:                SHOULD_BE_TYPEREF(0),
102:                /**
103:                 * This {@link RawTypeSet} can be either an reference property or
104:                 * an element property, and XJC recommends reference property.
105:                 */
106:                CAN_BE_TYPEREF(1),
107:                /**
108:                 * This {@link RawTypeSet} can be only bound to a reference property.
109:                 */
110:                MUST_BE_REFERENCE(2);
111:
112:                private final int rank;
113:
114:                Mode(int rank) {
115:                    this .rank = rank;
116:                }
117:
118:                Mode or(Mode that) {
119:                    switch (Math.max(this .rank, that.rank)) {
120:                    case 0:
121:                        return SHOULD_BE_TYPEREF;
122:                    case 1:
123:                        return CAN_BE_TYPEREF;
124:                    case 2:
125:                        return MUST_BE_REFERENCE;
126:                    }
127:                    throw new AssertionError();
128:                }
129:            }
130:
131:            /**
132:             * Returns true if {@link #refs} can form refs of types.
133:             *
134:             * If there are multiple {@link Ref}s with the same type,
135:             * we cannot make them into type refs. Or if any of the {@link Ref}
136:             * says they cannot be in type refs, we cannot do that either.
137:             *
138:             * TODO: just checking if the refs are the same is not suffice.
139:             * If two refs derive from each other, they cannot form a list of refs
140:             * (because of a possible ambiguity).
141:             */
142:            private Mode canBeTypeRefs() {
143:                Set<NType> types = new HashSet<NType>();
144:
145:                collectionMode = mul.isAtMostOnce() ? NOT_REPEATED
146:                        : REPEATED_ELEMENT;
147:
148:                // the way we compute this is that we start from the most optimistic value,
149:                // and then gradually degrade as we find something problematic.
150:                Mode mode = Mode.SHOULD_BE_TYPEREF;
151:
152:                for (Ref r : refs) {
153:                    mode = mode.or(r.canBeType(this ));
154:                    if (mode == Mode.MUST_BE_REFERENCE)
155:                        return mode; // no need to continue the processing
156:
157:                    if (!types.add(r.toTypeRef(null).getTarget().getType()))
158:                        return Mode.MUST_BE_REFERENCE; // collision
159:                    if (r.isListOfValues()) {
160:                        if (refs.size() > 1 || !mul.isAtMostOnce())
161:                            return Mode.MUST_BE_REFERENCE; // restriction on @XmlList
162:                        collectionMode = REPEATED_VALUE;
163:                    }
164:                }
165:                return mode;
166:            }
167:
168:            public void addTo(CElementPropertyInfo prop) {
169:                assert canBeTypeRefs != Mode.MUST_BE_REFERENCE;
170:                if (mul.isZero())
171:                    return; // the property can't have any value
172:
173:                List<CTypeRef> dst = prop.getTypes();
174:                for (Ref t : refs)
175:                    dst.add(t.toTypeRef(prop));
176:            }
177:
178:            public void addTo(CReferencePropertyInfo prop) {
179:                if (mul.isZero())
180:                    return; // the property can't have any value
181:                for (Ref t : refs)
182:                    t.toElementRef(prop);
183:            }
184:
185:            public ID id() {
186:                for (Ref t : refs) {
187:                    ID id = t.id();
188:                    if (id != ID.NONE)
189:                        return id;
190:                }
191:                return ID.NONE;
192:            }
193:
194:            public MimeType getExpectedMimeType() {
195:                for (Ref t : refs) {
196:                    MimeType mt = t.getExpectedMimeType();
197:                    if (mt != null)
198:                        return mt;
199:                }
200:                return null;
201:            }
202:
203:            /**
204:             * A reference to something.
205:             *
206:             * <p>
207:             * A {@link Ref} can be either turned into {@link CTypeRef} to form
208:             * an element property, or {@link Element} to form a reference property.
209:             */
210:            public static abstract class Ref {
211:                /**
212:                 * @param ep
213:                 *      the property to which the returned {@link CTypeRef} will be
214:                 *      added to.
215:                 */
216:                protected abstract CTypeRef toTypeRef(CElementPropertyInfo ep);
217:
218:                protected abstract void toElementRef(CReferencePropertyInfo prop);
219:
220:                /**
221:                 * Can this {@link Ref} be a type ref?
222:                 * @return false to veto.
223:                 * @param parent
224:                 */
225:                protected abstract Mode canBeType(RawTypeSet parent);
226:
227:                protected abstract boolean isListOfValues();
228:
229:                /**
230:                 * When this {@link RawTypeSet} binds to a {@link CElementPropertyInfo},
231:                 * this method is used to determine if the property is ID or not.
232:                 */
233:                protected abstract ID id();
234:
235:                /**
236:                 * When this {@link RawTypeSet} binds to a {@link CElementPropertyInfo},
237:                 * this method is used to determine if the property has an associated expected MIME type or not.
238:                 */
239:                protected MimeType getExpectedMimeType() {
240:                    return null;
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.