com.sun.xml.xsom.XSSchemaSet Java Examples

The following examples show how to use com.sun.xml.xsom.XSSchemaSet. 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: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private XSSchemaSet getSchemaSet()
	throws IOException, SAXException {
	if( schemaSet == null ) {
		XSOMParser schemaParser = new XSOMParser();
		ValueVector vec = getParameterVector( "schema" );
		if( vec.size() > 0 ) {
			for( Value v : vec ) {
				schemaParser.parse( new File( v.strValue() ) );
			}
		}
		parseWSDLTypes( schemaParser );
		schemaSet = schemaParser.getResult();
		String nsPrefix = "jolie";
		int i = 1;
		for( XSSchema schema : schemaSet.getSchemas() ) {
			if( !schema.getTargetNamespace().equals( XMLConstants.W3C_XML_SCHEMA_NS_URI ) ) {
				namespacePrefixMap.put( schema.getTargetNamespace(), nsPrefix + i++ );
			}
		}
	}

	return schemaSet;
}
 
Example #2
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void groupProcessing(
	Value value,
	XSElementDecl xsDecl,
	SOAPElement element,
	SOAPEnvelope envelope,
	boolean first,
	XSModelGroup modelGroup,
	XSSchemaSet sSet,
	String messageNamespace )
	throws SOAPException {

	XSParticle[] children = modelGroup.getChildren();
	XSTerm currTerm;
	for( XSParticle child : children ) {
		currTerm = child.getTerm();
		if( currTerm.isModelGroup() ) {
			groupProcessing( value, xsDecl, element, envelope, first, currTerm.asModelGroup(), sSet,
				messageNamespace );
		} else {
			termProcessing( value, element, envelope, first, currTerm, child.getMaxOccurs(), sSet,
				messageNamespace );
		}
	}
}
 
Example #3
Source File: SchemaHandler.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public Schema getSchema(String namespaceURI) {
	Schema schema = schemas.get(namespaceURI);
	if (schema != null)
		return schema;

	// CityGML 0.4.0
	if ("http://www.citygml.org/citygml/1/0/0".equals(namespaceURI)) {
		try {
			parse(schemaLocations.get(namespaceURI));
		} catch (SAXException e) {
			// 
		}
	}

	XSSchemaSet schemaSet = getXSSchemaSet(namespaceURI);
	if (schemaSet != null) {
		schema = new Schema(schemaSet, namespaceURI, this);
		schemas.put(namespaceURI, schema);
	}

	return schema;
}
 
Example #4
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void termProcessing( Value value, SOAPElement element, SOAPEnvelope envelope, boolean first,
	XSTerm currTerm, int getMaxOccur,
	XSSchemaSet sSet, String messageNamespace )
	throws SOAPException {
	Value currValue = value.clone();
	if( currTerm.isElementDecl() ) {
		ValueVector vec;
		XSElementDecl currElementDecl = currTerm.asElementDecl();
		String name = currElementDecl.getName();
		String prefix = (first) ? getPrefix( currElementDecl ) : getPrefixOrNull( currElementDecl );
		SOAPElement childElement;
		if( (vec = currValue.children().get( name )) != null ) {
			int k = 0;
			while( vec.size() > 0 && (getMaxOccur > k || getMaxOccur == XSParticle.UNBOUNDED) ) {
				if( prefix == null ) {
					childElement = element.addChildElement( name );
				} else {
					childElement = element.addChildElement( name, prefix );
				}
				Value v = vec.remove( 0 );
				valueToTypedSOAP(
					v,
					currElementDecl,
					childElement,
					envelope,
					false,
					sSet,
					messageNamespace );
				k++;
			}
		}
	}

}
 
Example #5
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private Map<String, XmlForm> parse(XSSchemaSet set) {
  Map<String, XmlForm> result = new HashMap<String, XmlForm>();
  
  /*
   * Accepts all element declarations in the Schema set
   */
  for (Iterator<XSElementDecl> elements = set.iterateElementDecls(); elements.hasNext();) {
    XSElementDecl decl = elements.next();
    XmlForm xmlForm = decl.apply(this);
    if (xmlForm != null)
      result.put(decl.getName(), xmlForm);
  }
  return result;
}
 
Example #6
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
public static XmlForm build(XSSchemaSet set, String element) {
  try {
    log.debug("\n\n\n-------- BUILDING XML FORM --------");
    
    XmlFormBuilder builder = new XmlFormBuilder();
    Map<String, XmlForm> xmlForms = builder.parse(set);
    XmlForm result = element == null ? getMainForm(xmlForms) : xmlForms.get(element);
    
    log.debug("\n-----------------------------------\n\n");
    
    return result;
  } catch (Exception e) {
    throw new RuntimeException("Failed to convert schema '" + set + "' into an XML form", e);
  }
}
 
Example #7
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void visit( XSSchemaSet s ) {
	Iterator<XSSchema> itr =  s.iterateSchema();
	while(itr.hasNext()) {
		schema((XSSchema)itr.next());
		println();
	}
}
 
Example #8
Source File: Schema.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public Schema(XSSchemaSet schemaSet, String namespaceURI, SchemaHandler handler) {
	this.schemaSet = schemaSet;
	this.handler = handler;
	this.namespaceURI = namespaceURI;

	schema = schemaSet.getSchema(namespaceURI);
	if (schema == null)
		throw new IllegalStateException("no XSSchema associated with the namespace '" + namespaceURI + "'.");

	uniqueElements = new HashMap<String, ElementDecl>();
	multipleElements = new HashMap<String, List<ElementDecl>>();
	localElements = new HashMap<ElementDecl, HashMap<String,ElementDecl>>();
}
 
Example #9
Source File: SchemaHandler.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
private XSSchemaSet getXSSchemaSet(String namespaceURI) {
	for (XSSchemaSet schemaSet : schemaSets)
		for (XSSchema schema : schemaSet.getSchemas())
			if (schema.getTargetNamespace().equals(namespaceURI))
				return schemaSet;

	return null;
}
 
Example #10
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void visit( XSSchemaSet s ) {
    Iterator<XSSchema> itr =  s.iterateSchema();
    while(itr.hasNext()) {
        schema(itr.next());
        println();
    }
}
 
Example #11
Source File: SimpleTypesAnalyzerTest.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public XSSchemaSet parse(String resource) throws Exception {
	final XSOMParser parser = new XSOMParser();
	parser.setErrorHandler(null);
	parser.setEntityResolver(null);

	final URL resourceUrl = getClass().getClassLoader().getResource(
			resource);
	// parser.parseSchema(
	//				
	// new File("myschema.xsd"));
	// parser.parseSchema( new File("XHTML.xsd"));
	parser.parse(resourceUrl);
	XSSchemaSet sset = parser.getResult();
	return sset;
}
 
Example #12
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void visit( XSSchemaSet s ) {
    Iterator itr =  s.iterateSchema();
    while(itr.hasNext()) {
        schema((XSSchema)itr.next());
        println();
    }
}
 
Example #13
Source File: ParserContext.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public XSSchemaSet getResult() throws SAXException {
    // run all the patchers
    for (Patch patcher : patchers)
        patcher.run();
    patchers.clear();

    // build the element substitutability map
    Iterator itr = schemaSet.iterateElementDecls();
    while(itr.hasNext())
        ((ElementDecl)itr.next()).updateSubstitutabilityMap();

    if(hadError)    return null;
    else            return schemaSet;
}
 
Example #14
Source File: WSDLConverter.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void convertTypes()
	throws IOException {
	Types types = definition.getTypes();
	if( types != null ) {
		List< ExtensibilityElement > list = types.getExtensibilityElements();
		for( ExtensibilityElement element : list ) {
			if( element instanceof SchemaImpl ) {
				Element schemaElement = ((SchemaImpl) element).getElement();
				// We need to inject the namespaces declared in parent nodes into the schema element
				Map< String, String > namespaces = definition.getNamespaces();
				for( Entry< String, String > entry : namespaces.entrySet() ) {
					if( schemaElement.getAttribute( "xmlns:" + entry.getKey() ).isEmpty() ) {
						schemaElement.setAttribute( "xmlns:" + entry.getKey(), entry.getValue() );
					}
				}
				parseSchemaElement( schemaElement );
			}
		}

		try {
			XSSchemaSet schemaSet = schemaParser.getResult();
			if( schemaSet == null ) {
				throw new IOException( "An error occurred while parsing the WSDL types section" );
			}
			XsdToJolieConverter schemaConverter = new XsdToJolieConverterImpl( schemaSet, false, null );
			typeDefinitions.addAll( schemaConverter.convert() );
		} catch( SAXException | XsdToJolieConverter.ConversionException e ) {
			throw new IOException( e );
		}
	}
}
 
Example #15
Source File: XJCCMModelInfoOrigin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public XSSchemaSet getSchemaComponent() {
	return getSource().schemaComponent;
}
 
Example #16
Source File: XmlUtils.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void valueToDocument(
	Value value,
	Document document,
	String schemaFilename ) throws IOException {


	String rootName = value.children().keySet().iterator().next();
	Value root = value.children().get( rootName ).get( 0 );
	String rootNameSpace = "";
	if( root.hasChildren( jolie.xml.XmlUtils.NAMESPACE_ATTRIBUTE_NAME ) ) {
		rootNameSpace = root.getFirstChild( jolie.xml.XmlUtils.NAMESPACE_ATTRIBUTE_NAME ).strValue();
	}

	XSType type = null;
	if( schemaFilename != null ) {
		try {
			XSOMParser parser = new XSOMParser();
			parser.parse( schemaFilename );
			XSSchemaSet schemaSet = parser.getResult();
			if( schemaSet != null && schemaSet.getElementDecl( rootNameSpace, rootName ) != null ) {
				type = schemaSet.getElementDecl( rootNameSpace, rootName ).getType();
			} else if( schemaSet != null && schemaSet.getElementDecl( rootNameSpace, rootName ) == null ) {
				Interpreter.getInstance().logWarning( "Root element " + rootName + " with namespace "
					+ rootNameSpace + " not found in the schema " + schemaFilename );
			}
		} catch( SAXException e ) {
			throw new IOException( e );
		}
	}


	if( type == null ) {
		valueToDocument(
			value.getFirstChild( rootName ),
			rootName,
			document );
	} else {
		valueToDocument(
			value.getFirstChild( rootName ),
			rootName,
			document,
			type );
	}

}
 
Example #17
Source File: XsdToJolieConverterImpl.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
public XsdToJolieConverterImpl( XSSchemaSet schemaSet, boolean strict, Logger logger ) {
	this.strict = strict;
	this.schemaSet = schemaSet;
	this.logger = logger;
}
 
Example #18
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 4 votes vote down vote up
public static XmlForm build(XSSchemaSet set) {
  return build(set, null);
}
 
Example #19
Source File: SchemaCompilerEx.java    From mwsc with MIT License 4 votes vote down vote up
public JAXBModelImpl bind() {
        // this has been problematic. turn it off.
//        if(!forest.checkSchemaCorrectness(this))
//            return null;

        // parse all the binding files given via XJC -b options.
        // this also takes care of the binding files given in the -episode option.
        for (InputSource is : opts.getBindFiles())
            parseSchema(is);
        
        // internalization
        SCDBasedBindingSet scdBasedBindingSet = forest.transform(opts.isExtensionMode());

        if(!NO_CORRECTNESS_CHECK) {
            // correctness check
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            sf.setErrorHandler(new DowngradingErrorHandler(this));
            forest.weakSchemaCorrectnessCheck(sf);
            if(hadError)
                return null;    // error in the correctness check. abort now
        }

        JCodeModel codeModel = new JCodeModel();

        ModelLoader gl = new ModelLoader(opts,codeModel,this);

        try {
            XSSchemaSet result = gl.createXSOM(forest, scdBasedBindingSet);
            if(result==null)
                return null;


            // we need info about each field, so we go ahead and generate the
            // skeleton at this point.
            // REVISIT: we should separate FieldRenderer and FieldAccessor
            // so that accessors can be used before we build the code.
            Model model = gl.annotateXMLSchema(result);
            if(model==null)   return null;

            if(hadError)        return null;    // if we have any error by now, abort

            context = model.generateCode(opts,this);
            if(context==null)   return null;

            if(hadError)        return null;

            return new JAXBModelImpl(context);
        } catch( SAXException e ) {
            // since XSOM uses our parser that scans DOM,
            // no parser error is possible.
            // all the other errors will be directed to ErrorReceiver
            // before it's thrown, so when the exception is thrown
            // the error should have already been reported.

            // thus ignore.
            return null;
        }
    }
 
Example #20
Source File: Schema.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public XSSchemaSet getXSSchemaSet() {
	return schemaSet;
}
 
Example #21
Source File: SchemaWalker.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void visit(XSSchemaSet schemas) {
	for (XSSchema schema : schemas.getSchemas())
		if (shouldWalk && visited.add(schema))
			schema(schema);
}
 
Example #22
Source File: ComponentImpl.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
public XSSchemaSet getRoot() {
    if(ownerDocument==null)
        return null;
    else
        return getOwnerSchema().getRoot();
}
 
Example #23
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Visits the root schema set.
 *
 * @param s Root schema set.
 */
public void visit(XSSchemaSet s) {
    for (XSSchema schema : s.getSchemas()) {
        schema(schema);
    }
}
 
Example #24
Source File: SimpleTypesAnalyzerTest.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public XSSchemaSet getSchemaSet() {
	return schemaSet;
}
 
Example #25
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 #26
Source File: SchemaGenerator.java    From jumbune with GNU Lesser General Public License v3.0 3 votes vote down vote up
public boolean updateSchema(String schemaPath, Map<String, XmlElementBean> elementMap) throws SAXException, ParserConfigurationException{
 
 File file = new File(schemaPath);
 try {
	 
	 Map<String,String> uriMapping = new HashMap<String,String>();
	 
	 SAXParserFactory spf = SAXParserFactory.newInstance();
		spf.setNamespaceAware(true);
		XMLReader xr = spf.newSAXParser().getXMLReader();
		xr.setContentHandler(new LocalContentHandler(uriMapping));
	 
		xr.parse(file.getPath());	
	
	 XSOMParser parser = new XSOMParser();
	 
	 parser.parse(file);
	 XSSchemaSet schemaSet = parser.getResult();
	 
	 XSSchema xsSchema = schemaSet.getSchema(1);
	 
	 StringWriter string = new StringWriter();
	 
	//TODO - list to map 
	 
	 JumbuneSchemaWriter schemaWriter = new JumbuneSchemaWriter(string,elementMap,uriMapping);
	 
	 schemaWriter.schema(xsSchema);
	
	 FileWriter fw = new FileWriter(schemaPath);
	 fw.write(string.toString());
	 fw.close();
     return true ;
 }
 catch (FactoryConfigurationError | IOException e) {
	 LOGGER.error(e.getMessage());
	 return false;
 }

}
 
Example #27
Source File: XSOMParser.java    From jolie with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Gets the parsed result. Don't call this method until
 * you parse all the schemas.
 * 
 * @return
 *      If there was any parse error, this method returns null.
 *      To receive error information, specify your error handler
 *      through the setErrorHandler method.
 * @exception SAXException
 *      This exception will never be thrown unless it is thrown
 *      by an error handler.
 */
public XSSchemaSet getResult() throws SAXException {
    return context.getResult();
}
 
Example #28
Source File: SchemaUtil.java    From dynaform with Artistic License 2.0 2 votes vote down vote up
/**
 * Converts an XML Schema into an abstract form with XML data.
 * 
 * @param set XML Schema representation.
 * @return an abstract form with XML data.
 */
public static XmlForm toXmlForm(XSSchemaSet set) {
  return XmlFormBuilder.build(set);
}
 
Example #29
Source File: SchemaUtil.java    From dynaform with Artistic License 2.0 2 votes vote down vote up
/**
 * Converts an XML Schema into an abstract form with XML data.
 * 
 * @param set XML Schema representation.
 * @return an abstract form with XML data.
 */
public static XmlForm toXmlForm(XSSchemaSet set, String element) {
  return XmlFormBuilder.build(set, element);
}