com.sun.xml.xsom.XSRestrictionSimpleType Java Examples

The following examples show how to use com.sun.xml.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: XsdToJolieConverterImpl.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private TypeDefinition loadSimpleType( XSSimpleType simpleType, boolean lazy, TypeDefinition lazyType ) {
	// processing restrictions
	TypeInlineDefinition jolietype;

	if( lazy ) {
		jolietype = (TypeInlineDefinition) lazyType;
	} else {
		if( simpleType.isRestriction() ) {
			XSRestrictionSimpleType restriction = simpleType.asRestriction();
			checkType( restriction.getBaseType() );
			jolietype =
				new TypeInlineDefinition( PARSING_CONTEXT, simpleType.getName().replace( "-", "_" ) + TYPE_SUFFIX,
					XsdUtils.xsdToNativeType( restriction.getBaseType().getName() ), Constants.RANGE_ONE_TO_ONE );

		} else {
			log( Level.WARNING, "SimpleType not processed:" + simpleType.getName() );
			jolietype = new TypeInlineDefinition( PARSING_CONTEXT, simpleType.getName().replace( "-", "_" ),
				NativeType.VOID, Constants.RANGE_ONE_TO_ONE );

		}
	}
	return jolietype;
}
 
Example #2
Source File: XMLSchemaProcessor.java    From ET_Redux with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param schemaSimpleType
 * @return
 */
public Vector<String> getSimpleTypeEnumeration ( SchemaSimpleType schemaSimpleType ) {

    Vector<String> enumeration = new Vector<String>();
    XSSimpleType st = parse( schemaSimpleType );

    XSRestrictionSimpleType restriction = st.asRestriction();

    if ( restriction != null ) {

        Iterator<? extends XSFacet> i = restriction.getDeclaredFacets().iterator();
        while (i.hasNext()) {
            XSFacet facet = i.next();

            if ( facet.getName().equals( XSFacet.FACET_ENUMERATION ) ) {
                enumeration.add( facet.getValue().value );
            }
        }
    }
    return enumeration;

}
 
Example #3
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private static boolean hasMinLength(XSRestrictionSimpleType xsRrestriction) {
  Iterator<XSFacet> facets = xsRrestriction.iterateDeclaredFacets();
  while (facets.hasNext()) {
    XSFacet facet = facets.next();
    String name = facet.getName();
    if ((XSFacet.FACET_LENGTH.equals(name) || XSFacet.FACET_MINLENGTH.equals(name))
        && Integer.parseInt(facet.getValue().toString()) > 0)
      return true;
  }
  return false;
}
 
Example #4
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private static boolean isEnumeration(XSRestrictionSimpleType xsRrestriction) {
  Iterator<XSFacet> facets = xsRrestriction.iterateDeclaredFacets();
  while (facets.hasNext())
    if (XSFacet.FACET_ENUMERATION.equals(facets.next().getName()))
      return true;
  return false;
}
 
Example #5
Source File: SchemaWriter.java    From citygml4j with Apache License 2.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<XSFacet> itr = type.iterateDeclaredFacets();
		while(itr.hasNext())
			facet( (XSFacet)itr.next() );

		indent--;
		println("</restriction>");
	}
 
Example #6
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 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 jolie with GNU Lesser General Public License v2.1 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}>",
            new Object[]{
                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 jolie with GNU Lesser General Public License v2.1 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: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.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<XSFacet> itr = type.iterateDeclaredFacets();
        while(itr.hasNext())
            facet( (XSFacet)itr.next() );

        indent--;
		if (baseType.isLocal())
			println("</restriction>");
    }
 
Example #10
Source File: CollectEnumerationValuesVisitor.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void restrictionSimpleType(XSRestrictionSimpleType type) {
	final List<XSFacet> facets = type.getFacets(XSFacet.FACET_ENUMERATION);
	if (facets != null) {
		for (XSFacet facet : facets) {
			final XmlString value = facet.getValue();
			if (value != null) {
				this.values.add(value);
			}
		}
	}
}
 
Example #11
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 4 votes vote down vote up
private static void processRestrictions(XSRestrictionSimpleType xsRrestriction, Restrictions restrictions) {
  if (log.isDebugEnabled())
    log.debug("Restriction: " + xsRrestriction);

  Iterator<XSFacet> facets = xsRrestriction.iterateDeclaredFacets();
  while (facets.hasNext()) {
    XSFacet facet = facets.next();

    if (log.isDebugEnabled())
      log.debug("Facet: " + facet + " " + facet.getValue() + " Fixed: " + facet.isFixed());

    String facetName = facet.getName();
    String facetValue = facet.getValue().toString();
    
    // Enumeration
    
    if (XSFacet.FACET_ENUMERATION.equals(facetName))
      restrictions.getChoices().add(new ChoiceImpl(facetValue));
    
    // Length
    
    else if (XSFacet.FACET_LENGTH.equals(facetName))
      restrictions.setLength(Integer.parseInt(facetValue));
    else if (XSFacet.FACET_MINLENGTH.equals(facetName))
      restrictions.setMinLength(Integer.parseInt(facetValue));
    else if (XSFacet.FACET_MAXLENGTH.equals(facetName))
      restrictions.setMaxLength(Integer.parseInt(facetValue));
    
    // Number Range
    
    else if (XSFacet.FACET_MININCLUSIVE.equals(facetName))
      restrictions.setMinInclusive(readXmlValue(xsRrestriction, facetValue));
    else if (XSFacet.FACET_MINEXCLUSIVE.equals(facetName))
      restrictions.setMinExclusive(readXmlValue(xsRrestriction, facetValue));
    else if (XSFacet.FACET_MAXINCLUSIVE.equals(facetName))
      restrictions.setMaxInclusive(readXmlValue(xsRrestriction, facetValue));
    else if (XSFacet.FACET_MAXEXCLUSIVE.equals(facetName))
      restrictions.setMaxExclusive(readXmlValue(xsRrestriction, facetValue));
    
    else
      log.warn("Unsupported Facet: " + facetName);
  }
}
 
Example #12
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 4 votes vote down vote up
private FormElement declSimple(XSSimpleType simpleType,
    String name,
    XmlString defaultValue,
    XmlString fixedValue) {
  
  if (log.isDebugEnabled()) {
    log.debug("Simple Type: " + simpleType);
    log.debug("Primitive: " + simpleType.isPrimitive());
  }
  
  Data data = null;
  Control control = null;
  boolean required = false;
  
  if (simpleType.isRestriction()) {
    XSRestrictionSimpleType restriction = simpleType.asRestriction();
    
    if (isEnumeration(restriction)) {
      control = new Controls.SelectOneImpl();
      if (log.isDebugEnabled())
        log.debug("Control: " + control);
    }
    
    required = hasMinLength(restriction);
    
    data = createData(simpleType);
    if (data == null) {
      log.warn("Unsupported Primitive Type: " + simpleType);
      return null;
    }
  }
  
  else if (simpleType.isList()) {
    XSListSimpleType list = simpleType.asList();
    XSSimpleType itemType = list.getItemType();
    
    if (log.isDebugEnabled()) {
      log.debug("List: " + list);
      log.debug("Item type: " + itemType);
    }
    
    data = new StringData();
  }
  
  else if (simpleType.isUnion()) {
    log.warn("Unsupported Simple Type: " + simpleType);
    return null;
  }
  
  else
    throw new AssertionError("Unknown Simple Type: " + simpleType);
  
  if (control == null)
    control = new Controls.InputImpl();
  
  String value = null;
  boolean readOnly = false;
  
  if (defaultValue != null) {
    if (log.isDebugEnabled())
      log.debug("Default Value: " + defaultValue);
    
    value = defaultValue.toString();
  }
  
  if (fixedValue != null) {
    if (log.isDebugEnabled())
      log.debug("Fixed Value: " + fixedValue);
    
    value = fixedValue.toString();
    readOnly = true;
  }
  
  FormElement element = new FormElementImpl(name, control, data);
  
  if (value != null) {
    try {
      element.setXmlValue(value);
    } catch (Exception e) {
      log.warn("Failed to inject XML value: " + value, e);
    }
  }
  
  if (simpleType.isRestriction())
    processRestrictions(simpleType.asRestriction(), element.getRestrictions());
  
  element.setReadOnly(readOnly);
  element.setRequired(required);
  
  return element;
}
 
Example #13
Source File: SimpleTypeImpl.java    From jolie with GNU Lesser General Public License v2.1 votes vote down vote up
public XSRestrictionSimpleType asRestriction() { return null; } 
Example #14
Source File: RestrictionSimpleTypeImpl.java    From jolie with GNU Lesser General Public License v2.1 votes vote down vote up
public XSRestrictionSimpleType asRestriction() { return this; } 
Example #15
Source File: SchemaSetImpl.java    From jolie with GNU Lesser General Public License v2.1 votes vote down vote up
public XSRestrictionSimpleType asRestriction() { return this; } 
Example #16
Source File: XSSimpleTypeVisitor.java    From jolie with GNU Lesser General Public License v2.1 votes vote down vote up
void restrictionSimpleType( XSRestrictionSimpleType type ); 
Example #17
Source File: XSSimpleTypeFunction.java    From jolie with GNU Lesser General Public License v2.1 votes vote down vote up
T restrictionSimpleType( XSRestrictionSimpleType type );