Java Code Examples for com.sun.xml.xsom.XSSimpleType#asRestriction()

The following examples show how to use com.sun.xml.xsom.XSSimpleType#asRestriction() . 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: 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 4
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;
}