1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * @LastModified: Oct 2017
4 */
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package com.sun.org.apache.xerces.internal.impl.xs;
23
267 // substitution group for this one is empty
268 if (subGroup == null) {
269 fSubGroupsB.put(element, EMPTY_VECTOR);
270 return EMPTY_VECTOR;
271 }
272
273 // we've already calculated the element, just return.
274 if (subGroup instanceof OneSubGroup[])
275 return (OneSubGroup[])subGroup;
276
277 // we only have the *direct* substitutions
278 @SuppressWarnings("unchecked")
279 List<XSElementDecl> group = (ArrayList<XSElementDecl>)subGroup;
280 List<OneSubGroup> newGroup = new ArrayList<>();
281 OneSubGroup[] group1;
282 // then for each of the direct substitutions, get its substitution
283 // group, and combine the groups together.
284 short dMethod, bMethod, dSubMethod, bSubMethod;
285 for (int i = group.size()-1, j; i >= 0; i--) {
286 // Check whether this element is blocked. If so, ignore it.
287 XSElementDecl sub = (XSElementDecl)group.get(i);
288 if (!getDBMethods(sub.fType, element.fType, methods))
289 continue;
290 // Remember derivation methods and blocks from the types
291 dMethod = methods.dMethod;
292 bMethod = methods.bMethod;
293 // Add this one to potential group
294 newGroup.add(new OneSubGroup(sub, methods.dMethod, methods.bMethod));
295 // Get potential group for this element
296 group1 = getSubGroupB(sub, methods);
297 for (j = group1.length-1; j >= 0; j--) {
298 // For each of them, check whether it's blocked (by type)
299 dSubMethod = (short)(dMethod | group1[j].dMethod);
300 bSubMethod = (short)(bMethod | group1[j].bMethod);
301 // Ignore it if it's blocked
302 if ((dSubMethod & bSubMethod) != 0)
303 continue;
304 newGroup.add(new OneSubGroup(group1[j].sub, dSubMethod, bSubMethod));
305 }
306 }
307 // Convert to an array
308 OneSubGroup[] ret = new OneSubGroup[newGroup.size()];
309 for (int i = newGroup.size()-1; i >= 0; i--) {
310 ret[i] = (OneSubGroup)newGroup.get(i);
311 }
312 // Store the potential sub group
313 fSubGroupsB.put(element, ret);
314
315 return ret;
316 }
317
318 private boolean getDBMethods(XSTypeDefinition typed, XSTypeDefinition typeb,
319 OneSubGroup methods) {
320 short dMethod = 0, bMethod = 0;
321 while (typed != typeb && typed != SchemaGrammar.fAnyType) {
322 if (typed.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
323 dMethod |= ((XSComplexTypeDecl)typed).fDerivedBy;
324 else
325 dMethod |= XSConstants.DERIVATION_RESTRICTION;
326 typed = typed.getBaseType();
327 // type == null means the current type is anySimpleType,
328 // whose base type should be anyType
329 if (typed == null)
330 typed = SchemaGrammar.fAnyType;
|
1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * @LastModified: Nov 2017
4 */
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements. See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package com.sun.org.apache.xerces.internal.impl.xs;
23
267 // substitution group for this one is empty
268 if (subGroup == null) {
269 fSubGroupsB.put(element, EMPTY_VECTOR);
270 return EMPTY_VECTOR;
271 }
272
273 // we've already calculated the element, just return.
274 if (subGroup instanceof OneSubGroup[])
275 return (OneSubGroup[])subGroup;
276
277 // we only have the *direct* substitutions
278 @SuppressWarnings("unchecked")
279 List<XSElementDecl> group = (ArrayList<XSElementDecl>)subGroup;
280 List<OneSubGroup> newGroup = new ArrayList<>();
281 OneSubGroup[] group1;
282 // then for each of the direct substitutions, get its substitution
283 // group, and combine the groups together.
284 short dMethod, bMethod, dSubMethod, bSubMethod;
285 for (int i = group.size()-1, j; i >= 0; i--) {
286 // Check whether this element is blocked. If so, ignore it.
287 XSElementDecl sub = group.get(i);
288 if (!getDBMethods(sub.fType, element.fType, methods))
289 continue;
290 // Remember derivation methods and blocks from the types
291 dMethod = methods.dMethod;
292 bMethod = methods.bMethod;
293 // Add this one to potential group
294 newGroup.add(new OneSubGroup(sub, methods.dMethod, methods.bMethod));
295 // Get potential group for this element
296 group1 = getSubGroupB(sub, methods);
297 for (j = group1.length-1; j >= 0; j--) {
298 // For each of them, check whether it's blocked (by type)
299 dSubMethod = (short)(dMethod | group1[j].dMethod);
300 bSubMethod = (short)(bMethod | group1[j].bMethod);
301 // Ignore it if it's blocked
302 if ((dSubMethod & bSubMethod) != 0)
303 continue;
304 newGroup.add(new OneSubGroup(group1[j].sub, dSubMethod, bSubMethod));
305 }
306 }
307 // Convert to an array
308 OneSubGroup[] ret = new OneSubGroup[newGroup.size()];
309 for (int i = newGroup.size()-1; i >= 0; i--) {
310 ret[i] = newGroup.get(i);
311 }
312 // Store the potential sub group
313 fSubGroupsB.put(element, ret);
314
315 return ret;
316 }
317
318 private boolean getDBMethods(XSTypeDefinition typed, XSTypeDefinition typeb,
319 OneSubGroup methods) {
320 short dMethod = 0, bMethod = 0;
321 while (typed != typeb && typed != SchemaGrammar.fAnyType) {
322 if (typed.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
323 dMethod |= ((XSComplexTypeDecl)typed).fDerivedBy;
324 else
325 dMethod |= XSConstants.DERIVATION_RESTRICTION;
326 typed = typed.getBaseType();
327 // type == null means the current type is anySimpleType,
328 // whose base type should be anyType
329 if (typed == null)
330 typed = SchemaGrammar.fAnyType;
|