com.sun.xml.internal.xsom.XSRestrictionSimpleType Java Examples

The following examples show how to use com.sun.xml.internal.xsom.XSRestrictionSimpleType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Axis.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<XSFacet> simpleType(XSSimpleType type) {
    // TODO: it's not clear if "facets" mean all inherited facets or just declared facets
    XSRestrictionSimpleType r = type.asRestriction();
    if(r!=null)
        return r.iterateDeclaredFacets();
    else
        return empty();
}
 
Example #2
Source File: SchemaTreeTraverser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #3
Source File: SchemaTreeTraverser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #4
Source File: SchemaTreeTraverser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #5
Source File: SchemaWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #6
Source File: SchemaTreeTraverser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #7
Source File: SchemaWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #8
Source File: Axis.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<XSFacet> simpleType(XSSimpleType type) {
    // TODO: it's not clear if "facets" mean all inherited facets or just declared facets
    XSRestrictionSimpleType r = type.asRestriction();
    if(r!=null)
        return r.iterateDeclaredFacets();
    else
        return empty();
}
 
Example #9
Source File: SchemaWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #10
Source File: Axis.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<XSFacet> simpleType(XSSimpleType type) {
    // TODO: it's not clear if "facets" mean all inherited facets or just declared facets
    XSRestrictionSimpleType r = type.asRestriction();
    if(r!=null)
        return r.iterateDeclaredFacets();
    else
        return empty();
}
 
Example #11
Source File: SchemaWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #12
Source File: SchemaTreeTraverser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #13
Source File: Axis.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<XSFacet> simpleType(XSSimpleType type) {
    // TODO: it's not clear if "facets" mean all inherited facets or just declared facets
    XSRestrictionSimpleType r = type.asRestriction();
    if(r!=null)
        return r.iterateDeclaredFacets();
    else
        return empty();
}
 
Example #14
Source File: SchemaWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #15
Source File: SchemaTreeTraverser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #16
Source File: Axis.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<XSFacet> simpleType(XSSimpleType type) {
    // TODO: it's not clear if "facets" mean all inherited facets or just declared facets
    XSRestrictionSimpleType r = type.asRestriction();
    if(r!=null)
        return r.iterateDeclaredFacets();
    else
        return empty();
}
 
Example #17
Source File: SchemaWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #18
Source File: SchemaTreeTraverser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #19
Source File: Axis.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<XSFacet> simpleType(XSSimpleType type) {
    // TODO: it's not clear if "facets" mean all inherited facets or just declared facets
    XSRestrictionSimpleType r = type.asRestriction();
    if(r!=null)
        return r.iterateDeclaredFacets();
    else
        return empty();
}
 
Example #20
Source File: SchemaWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType( XSRestrictionSimpleType type ) {

        if(type.getBaseType()==null) {
            // don't print anySimpleType
            if(!type.getName().equals("anySimpleType"))
                throw new InternalError();
            if(!Const.schemaNamespace.equals(type.getTargetNamespace()))
                throw new InternalError();
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        println(MessageFormat.format("<restriction{0}>",
            baseType.isLocal()?"":" base=\"{"+
            baseType.getTargetNamespace()+'}'+
            baseType.getName()+'\"'));
        indent++;

        if(baseType.isLocal())
            simpleType(baseType);

        Iterator itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
        println("</restriction>");
    }
 
Example #21
Source File: SchemaTreeTraverser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {

        if (type.getBaseType() == null) {
            // don't print anySimpleType
            if (!type.getName().equals("anySimpleType")) {
                throw new InternalError();
            }
            if (!Const.schemaNamespace.equals(type.getTargetNamespace())) {
                throw new InternalError();
            }
            return;
        }

        XSSimpleType baseType = type.getSimpleBaseType();

        String str = MessageFormat.format("Restriction {0}",
                new Object[]{baseType.isLocal() ? "" : " base=\"{"
                + baseType.getTargetNamespace() + "}"
                + baseType.getName() + "\""});

        SchemaTreeNode newNode = new SchemaTreeNode(str, baseType.getLocator());
        this.currNode.add(newNode);
        this.currNode = newNode;

        if (baseType.isLocal()) {
            simpleType(baseType);
        }

        Iterator itr = type.iterateDeclaredFacets();
        while (itr.hasNext()) {
            facet((XSFacet) itr.next());
        }

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #22
Source File: UnusedCustomizationChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void restrictionSimpleType(XSRestrictionSimpleType type) {
    if(check(type))
        type.getBaseType().visit(this);
}
 
Example #23
Source File: SimpleTypeBuilder.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public TypeUse restrictionSimpleType(XSRestrictionSimpleType type) {
    // just process the base type.
    return compose(type.getSimpleBaseType());
}
 
Example #24
Source File: SimpleTypeBuilder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #25
Source File: SimpleTypeBuilder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if a type-safe enum should be created from
 * the given simple type by default without an explicit &lt;jaxb:enum> customization.
 */
private boolean shouldBeMappedToTypeSafeEnumByDefault( XSRestrictionSimpleType type ) {

    // if not, there will be a problem wrt the class name of this type safe enum type.
    if( type.isLocal() )    return false;

    // if redefined, we should map the new definition, not the old one.
    if( type.getRedefinedBy()!=null )   return false;

    List<XSFacet> facets = type.getDeclaredFacets(XSFacet.FACET_ENUMERATION);
    if( facets.isEmpty() )
        // if the type itself doesn't have the enumeration facet,
        // it won't be mapped to a type-safe enum.
        return false;

    if(facets.size() > builder.getGlobalBinding().getDefaultEnumMemberSizeCap()) {
        // if there are too many facets, it's not very useful
        // produce warning when simple type is not mapped to enum
        // see issue https://jaxb.dev.java.net/issues/show_bug.cgi?id=711

        if(reportedEnumMemberSizeWarnings == null)
            reportedEnumMemberSizeWarnings = new HashSet<XSRestrictionSimpleType>();

        if(!reportedEnumMemberSizeWarnings.contains(type)) {
            getErrorReporter().warning(type.getLocator(), Messages.WARN_ENUM_MEMBER_SIZE_CAP,
                    type.getName(), facets.size(), builder.getGlobalBinding().getDefaultEnumMemberSizeCap());

            reportedEnumMemberSizeWarnings.add(type);
        }

        return false;
    }

    if( !canBeMappedToTypeSafeEnum(type) )
        // we simply can't map this to an enumeration
        return false;

    // check for collisions among constant names. if a collision will happen,
    // don't try to bind it to an enum.

    // return true only when this type is derived from one of the "enum base type".
    for( XSSimpleType t = type; t!=null; t=t.getSimpleBaseType() )
        if( t.isGlobal() && builder.getGlobalBinding().canBeMappedToTypeSafeEnum(t) )
            return true;

    return false;
}
 
Example #26
Source File: SimpleTypeBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public TypeUse restrictionSimpleType(XSRestrictionSimpleType type) {
    // just process the base type.
    return compose(type.getSimpleBaseType());
}
 
Example #27
Source File: SimpleTypeBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if a type-safe enum should be created from
 * the given simple type by default without an explicit &lt;jaxb:enum> customization.
 */
private boolean shouldBeMappedToTypeSafeEnumByDefault( XSRestrictionSimpleType type ) {

    // if not, there will be a problem wrt the class name of this type safe enum type.
    if( type.isLocal() )    return false;

    // if redefined, we should map the new definition, not the old one.
    if( type.getRedefinedBy()!=null )   return false;

    List<XSFacet> facets = type.getDeclaredFacets(XSFacet.FACET_ENUMERATION);
    if( facets.isEmpty() )
        // if the type itself doesn't have the enumeration facet,
        // it won't be mapped to a type-safe enum.
        return false;

    if(facets.size() > builder.getGlobalBinding().getDefaultEnumMemberSizeCap()) {
        // if there are too many facets, it's not very useful
        // produce warning when simple type is not mapped to enum
        // see issue https://jaxb.dev.java.net/issues/show_bug.cgi?id=711

        if(reportedEnumMemberSizeWarnings == null)
            reportedEnumMemberSizeWarnings = new HashSet<XSRestrictionSimpleType>();

        if(!reportedEnumMemberSizeWarnings.contains(type)) {
            getErrorReporter().warning(type.getLocator(), Messages.WARN_ENUM_MEMBER_SIZE_CAP,
                    type.getName(), facets.size(), builder.getGlobalBinding().getDefaultEnumMemberSizeCap());

            reportedEnumMemberSizeWarnings.add(type);
        }

        return false;
    }

    if( !canBeMappedToTypeSafeEnum(type) )
        // we simply can't map this to an enumeration
        return false;

    // check for collisions among constant names. if a collision will happen,
    // don't try to bind it to an enum.

    // return true only when this type is derived from one of the "enum base type".
    for( XSSimpleType t = type; t!=null; t=t.getSimpleBaseType() )
        if( t.isGlobal() && builder.getGlobalBinding().canBeMappedToTypeSafeEnum(t) )
            return true;

    return false;
}
 
Example #28
Source File: SimpleTypeBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns true if a type-safe enum should be created from
 * the given simple type by default without an explicit {@code <jaxb:enum>} customization.
 */
private boolean shouldBeMappedToTypeSafeEnumByDefault( XSRestrictionSimpleType type ) {

    // if not, there will be a problem wrt the class name of this type safe enum type.
    if( type.isLocal() )    return false;

    // if redefined, we should map the new definition, not the old one.
    if( type.getRedefinedBy()!=null )   return false;

    List<XSFacet> facets = type.getDeclaredFacets(XSFacet.FACET_ENUMERATION);
    if( facets.isEmpty() )
        // if the type itself doesn't have the enumeration facet,
        // it won't be mapped to a type-safe enum.
        return false;

    if(facets.size() > builder.getGlobalBinding().getDefaultEnumMemberSizeCap()) {
        // if there are too many facets, it's not very useful
        // produce warning when simple type is not mapped to enum
        // see issue https://jaxb.dev.java.net/issues/show_bug.cgi?id=711

        if(reportedEnumMemberSizeWarnings == null)
            reportedEnumMemberSizeWarnings = new HashSet<XSRestrictionSimpleType>();

        if(!reportedEnumMemberSizeWarnings.contains(type)) {
            getErrorReporter().warning(type.getLocator(), Messages.WARN_ENUM_MEMBER_SIZE_CAP,
                    type.getName(), facets.size(), builder.getGlobalBinding().getDefaultEnumMemberSizeCap());

            reportedEnumMemberSizeWarnings.add(type);
        }

        return false;
    }

    if( !canBeMappedToTypeSafeEnum(type) )
        // we simply can't map this to an enumeration
        return false;

    // check for collisions among constant names. if a collision will happen,
    // don't try to bind it to an enum.

    // return true only when this type is derived from one of the "enum base type".
    for( XSSimpleType t = type; t!=null; t=t.getSimpleBaseType() )
        if( t.isGlobal() && builder.getGlobalBinding().canBeMappedToTypeSafeEnum(t) )
            return true;

    return false;
}
 
Example #29
Source File: SimpleTypeBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #30
Source File: SimpleTypeBuilder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public TypeUse restrictionSimpleType(XSRestrictionSimpleType type) {
    // just process the base type.
    return compose(type.getSimpleBaseType());
}