com.sun.xml.xsom.XSSimpleType Java Examples

The following examples show how to use com.sun.xml.xsom.XSSimpleType. 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: XmlFormBuilder.java    From dynaform with Artistic License 2.0 6 votes vote down vote up
private XmlForm elementDeclSimple(XSElementDecl decl, XSSimpleType simpleType) {
  FormElement element = declSimple(simpleType, decl.getName(), decl.getDefaultValue(), decl.getFixedValue());
  if (element == null)
    return null;
  
  XmlWriter writer = new XmlElementWriter(decl.getName(), null,
      new TextXmlWriter(new FormElementWriter(element)));
  
  XmlReader reader = new XmlElementReader(decl.getName(), null,
      new TextXmlReader(new FormElementHandler(element)));
  
  if (ignoreWhitespace)
    reader = WhitespaceReader.appendTo(reader);

  return new XmlFormImpl(element, writer, reader);
}
 
Example #2
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates node for attribute declaration with additional attributes.
 *
 * @param decl           Attribute declaration.
 * @param additionalAtts Additional attributes.
 */
private void dump(XSAttributeDecl decl, String additionalAtts) {
    XSSimpleType type = decl.getType();

    String str = MessageFormat.format("Attribute \"{0}\"{1}{2}{3}{4}",
            new Object[]{
                decl.getName(),
                additionalAtts,
                type.isLocal() ? "" : MessageFormat.format(
                        " type=\"'{'{0}'}'{1}\"", new Object[]{
                            type.getTargetNamespace(),
                            type.getName()}),
                decl.getFixedValue() == null ? "" : " fixed=\""
            + decl.getFixedValue() + "\"",
                decl.getDefaultValue() == null ? "" : " default=\""
            + decl.getDefaultValue() + "\""});

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

    if (type.isLocal()) {
        simpleType(type);
    }
    this.currNode = (SchemaTreeNode) this.currNode.getParent();
}
 
Example #3
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
private void dump( XSAttributeDecl decl, String additionalAtts ) {
	XSSimpleType type=decl.getType();

	println(MessageFormat.format("<attribute name=\"{0}\"{1}{2}{3}{4}{5}>",
			decl.getName(),
			additionalAtts,
			type.isLocal()?"":
				MessageFormat.format(" type=\"'{'{0}'}'{1}\"", type.getTargetNamespace(), type.getName()),
				decl.getFixedValue()==null ?
						"":" fixed=\""+decl.getFixedValue()+'\"',
						decl.getDefaultValue()==null ?
								"":" default=\""+decl.getDefaultValue()+'\"',
								type.isLocal()?"":" /"));

	if(type.isLocal()) {
		indent++;
		simpleType(type);
		indent--;
		println("</attribute>");
	}
}
 
Example #4
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 #5
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void listSimpleType( XSListSimpleType type ) {
    XSSimpleType itemType = type.getItemType();

    if(itemType.isLocal()) {
        println("<list>");
        indent++;
        simpleType(itemType);
        indent--;
        println("</list>");
    } else {
        // global type
        println(MessageFormat.format("<list itemType=\"'{'{0}'}'{1}\" />",
            new Object[]{
                itemType.getTargetNamespace(),
                itemType.getName()
            }));
    }
}
 
Example #6
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void dump( XSAttributeDecl decl, String additionalAtts ) {
    XSSimpleType type=decl.getType();

    println(MessageFormat.format("<attribute name=\"{0}\"{1}{2}{3}{4}{5}>",
        decl.getName(),
        additionalAtts,
        type.isLocal()?"":
            MessageFormat.format(" type=\"'{'{0}'}'{1}\"", type.getTargetNamespace(), type.getName()),
        decl.getFixedValue()==null ?
            "":" fixed=\""+decl.getFixedValue()+'\"',
        decl.getDefaultValue()==null ?
            "":" default=\""+decl.getDefaultValue()+'\"',
        type.isLocal()?"":" /"));

    if(type.isLocal()) {
        indent++;
        simpleType(type);
        indent--;
        println("</attribute>");
    }
}
 
Example #7
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 #8
Source File: UnionSimpleTypeImpl.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Iterator<XSSimpleType> iterator() {
    return new Iterator<XSSimpleType>() {
        int idx=0;
        public boolean hasNext() {
            return idx<memberTypes.length;
        }

        public XSSimpleType next() {
            return memberTypes[idx++].getType();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #9
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private static Object readXmlValue(XSSimpleType type, String value) {
  Data data = createData(type);
  try {
    data.setXmlValue(value);
  } catch (Exception e) {
    log.error("Could not convert value '" + value + "'");
    return null;
  }
  return data.getValue();
}
 
Example #10
Source File: NGCCRuntimeEx.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean ignorableDuplicateComponent(XSDeclaration c) {
    if(c.getTargetNamespace().equals(Const.schemaNamespace)) {
        if(c instanceof XSSimpleType)
            // hide artificial "double definitions" on simple types
            return true;
        if(c.isGlobal() && c.getName().equals("anyType"))
            return true; // ditto for anyType
    }
    return false;
}
 
Example #11
Source File: SchemaSetImpl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Iterator<XSSimpleType> iterateSimpleTypes() {
    return new Iterators.Map<XSSimpleType,XSSchema>(iterateSchema()) {
        protected Iterator<XSSimpleType> apply(XSSchema u) {
            return u.iterateSimpleTypes();
        }
    };
}
 
Example #12
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void schema(XSSchema s) {
    // QUICK HACK: don't print the built-in components
    if (s.getTargetNamespace().equals(Const.schemaNamespace)) {
        return;
    }

    SchemaTreeNode newNode = new SchemaTreeNode("Schema "
            + s.getLocator().getSystemId(), s.getLocator());
    this.currNode = newNode;
    this.model.addSchemaNode(newNode);

    for (XSAttGroupDecl groupDecl : s.getAttGroupDecls().values()) {
        attGroupDecl(groupDecl);
    }

    for (XSAttributeDecl attrDecl : s.getAttributeDecls().values()) {
        attributeDecl(attrDecl);
    }

    for (XSComplexType complexType : s.getComplexTypes().values()) {
        complexType(complexType);
    }

    for (XSElementDecl elementDecl : s.getElementDecls().values()) {
        elementDecl(elementDecl);
    }

    for (XSModelGroupDecl modelGroupDecl : s.getModelGroupDecls().values()) {
        modelGroupDecl(modelGroupDecl);
    }

    for (XSSimpleType simpleType : s.getSimpleTypes().values()) {
        simpleType(simpleType);
    }
}
 
Example #13
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void simpleType(XSSimpleType type) {

        String str = MessageFormat.format("Simple type {0}",
                new Object[]{type.isLocal() ? "" : " name=\""
                + type.getName() + "\""});

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

        type.visit((XSSimpleTypeVisitor) this);

        this.currNode = (SchemaTreeNode) this.currNode.getParent();
    }
 
Example #14
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void dump( XSAttributeDecl decl, String additionalAtts ) {
    XSSimpleType type=decl.getType();

    println(MessageFormat.format("<attribute name=\"{0}\"{1}{2}{3}{4}{5}>",
        new Object[]{
            decl.getName(),
            additionalAtts,
            type.isLocal()?"":
            MessageFormat.format(" type=\"'{'{0}'}'{1}\"",
            new Object[]{
                type.getTargetNamespace(),
                type.getName()
            }),
            decl.getFixedValue()==null ?
                "":" fixed=\""+decl.getFixedValue()+'\"',
            decl.getDefaultValue()==null ?
                "":" default=\""+decl.getDefaultValue()+'\"',
            type.isLocal()?"":" /"
        }));

    if(type.isLocal()) {
        indent++;
        simpleType(type);
        indent--;
        println("</attribute>");
    }
}
 
Example #15
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void simpleType( XSSimpleType type ) {
    println(MessageFormat.format("<simpleType{0}>",
        new Object[]{
            type.isLocal()?"":" name=\""+type.getName()+'\"'
        }));
    indent++;

    type.visit((XSSimpleTypeVisitor)this);

    indent--;
    println("</simpleType>");
}
 
Example #16
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 #17
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 #18
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void simpleType( XSSimpleType type ) {
      println(MessageFormat.format("<simpleType{0}>", type.isLocal()?"":" name=\""+type.getName()+'\"'));
      indent++;

      type.visit((XSSimpleTypeVisitor)this);

      indent--;
if (type.getBaseType().isLocal())
	println("</simpleType>");
  }
 
Example #19
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void listSimpleType( XSListSimpleType type ) {
    XSSimpleType itemType = type.getItemType();

    if(itemType.isLocal()) {
        println("<list>");
        indent++;
        simpleType(itemType);
        indent--;
        println("</list>");
    } else {
        // global type
        println(MessageFormat.format("<list itemType=\"'{'{0}'}'{1}\" />",
            itemType.getTargetNamespace(), itemType.getName()));
    }
}
 
Example #20
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 #21
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
@Override
public QName simpleType(final XSSimpleType type) {
	if (type.getName() == null) {
		return new QName(type.getTargetNamespace(), "anonymousSimpleType");
	} else {
		return new QName(type.getTargetNamespace(), type.getName());
	}
}
 
Example #22
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void schema( XSSchema s ) {

		// QUICK HACK: don't print the built-in components
		if(s.getTargetNamespace().equals(Const.schemaNamespace))
			return;

		println(MessageFormat.format("<schema targetNamespace=\"{0}\">", s.getTargetNamespace()));
		indent++;

		Iterator<?> itr;

		itr = s.iterateAttGroupDecls();
		while(itr.hasNext())
			attGroupDecl( (XSAttGroupDecl)itr.next() );

		itr = s.iterateAttributeDecls();
		while(itr.hasNext())
			attributeDecl( (XSAttributeDecl)itr.next() );

		itr = s.iterateComplexTypes();
		while(itr.hasNext())
			complexType( (XSComplexType)itr.next() );

		itr = s.iterateElementDecls();
		while(itr.hasNext())
			elementDecl( (XSElementDecl)itr.next() );

		itr = s.iterateModelGroupDecls();
		while(itr.hasNext())
			modelGroupDecl( (XSModelGroupDecl)itr.next() );

		itr = s.iterateSimpleTypes();
		while(itr.hasNext())
			simpleType( (XSSimpleType)itr.next() );

		indent--;
		println("</schema>");
	}
 
Example #23
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void simpleType( XSSimpleType type ) {
	println(MessageFormat.format("<simpleType{0}>", type.isLocal()?"":" name=\""+type.getName()+'\"'));
	indent++;

	type.visit((XSSimpleTypeVisitor)this);

	indent--;
	println("</simpleType>");
}
 
Example #24
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void listSimpleType( XSListSimpleType type ) {
	XSSimpleType itemType = type.getItemType();

	if(itemType.isLocal()) {
		println("<list>");
		indent++;
		simpleType(itemType);
		indent--;
		println("</list>");
	} else {
		// global type
		println(MessageFormat.format("<list itemType=\"'{'{0}'}'{1}\" />",
				itemType.getTargetNamespace(), itemType.getName()));
	}
}
 
Example #25
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 #26
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private static Data createData(XSSimpleType type) {
  Data data = DataUtil.newData(type.getName());
  if (data != null)
    return data;
  
  XSSimpleType baseType = type.getSimpleBaseType();
  if (baseType == null)
    return null; // This is xs:anySimpleType
  
  if (log.isDebugEnabled())
    log.debug("Base Type: " + baseType);
  
  return createData(baseType);
}
 
Example #27
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 #28
Source File: XMLSchemaProcessor.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
private XSSimpleType parse ( SchemaSimpleType schemaSimpleType ) {

        ClassLoader cldr = this.getClass().getClassLoader();

        InputStream resourceXMLSchema = cldr.getResourceAsStream( schemaSimpleType.getSchemaFilePath() );

        File localXMLSchema = new File( schemaSimpleType.getTypeName() + ".xsd" );
        try {
            InputStream in = resourceXMLSchema;
            // Overwrite the file.
            OutputStream out = new FileOutputStream( localXMLSchema );

            while (in.available() > 0) {
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read( buf )) > 0) {
                    out.write( buf, 0, len );
                }
            }
            in.close();
            out.close();

        } catch (IOException iOException) {
        }


        XSSimpleType st = null;
        try {
            XSOMParser parser = new XSOMParser();
            parser.parse( localXMLSchema );
            XSSchemaSet schemaSet = parser.getResult();
            XSSchema xsSchema = schemaSet.getSchema( 1 );

            st = xsSchema.getSimpleType( schemaSimpleType.getTypeName() );

        } catch (Exception exp) {
            exp.printStackTrace( System.out );
        }

        localXMLSchema.delete();

        return st;
    }
 
Example #29
Source File: Axis.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Iterator<XSSimpleType> simpleType(XSSimpleType type) {
    XSUnionSimpleType baseUnion = type.getBaseUnionType();
    if(baseUnion ==null)      return empty();
    return baseUnion.iterator();
}
 
Example #30
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void schema( XSSchema s) {
	
	if(this.elementsMap.size() != 0){

	StringBuffer sb = new StringBuffer();
     
     for(String prefix : uriMapping.keySet()){
    	 
    	 String uri = uriMapping.get(prefix);
    	 if(Const.schemaNamespace.equalsIgnoreCase(uri)) rootPrefix = prefix+":";
    	 sb.append("xmlns:"+prefix+"=\""+uri+"\" " );
    	 
     }
     
     if(!s.getTargetNamespace().isEmpty()){
    	 println(MessageFormat.format("<schema {0} targetNamespace=\"{1}\">",sb.toString(),s.getTargetNamespace()));
     }else{
    	 println(MessageFormat.format("<schema {0} >",sb.toString()));
     }
     
      indent++;

      Iterator<XSAttGroupDecl> itrAGD = s.iterateAttGroupDecls();
      while (itrAGD.hasNext()) {
    	  attGroupDecl(itrAGD.next());
      }

      Iterator<XSAttributeDecl> itrAD = s.iterateAttributeDecls();
      while(itrAD.hasNext()) {
    	  attributeDecl(itrAD.next());
      }

      Iterator<XSComplexType> itrCT = s.iterateComplexTypes();
      while(itrCT.hasNext()) {
    	  complexType(itrCT.next());
      }
      
      Iterator<XSElementDecl> itrED = s.iterateElementDecls();
      while(itrED.hasNext()) {
    	  elementDecl(itrED.next());
      } 
      
      Iterator<XSModelGroupDecl> itrMGD = s.iterateModelGroupDecls();
      while(itrMGD.hasNext()) {
    	  modelGroupDecl(itrMGD.next()); 
      }

      Iterator<XSSimpleType> itrST = s.iterateSimpleTypes();
      while(itrST.hasNext()) {
    	  simpleType(itrST.next());
      }

      indent--;
      println("</schema>");
	}
	//}

   
}