Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Generated *FactoryImpl is not an instance of Resource.Factory(Could the problem be in the source XSD?)
Generated *FactoryImpl is not an instance of Resource.Factory [message #1782066] |
Fri, 16 February 2018 17:11 |
Geoffry Roberts Messages: 16 Registered: May 2014 |
Junior Member |
|
|
All,
Is there any way code generated from an XSD can produce a *FactoryImpl class that is not an instance of Resource.Factory?
I am using an XSD developed by a third party.
I know about registering extensions and schemes. I don't believe that's the problem because correct *FactoryImpl class is found in the extension map. It just is not an instance of Resource.Factory.
I have included the XSD for good measure.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:arf="http://scap.nist.gov/schema/asset-reporting-format/1.1"
xmlns:ai="http://scap.nist.gov/schema/asset-identification/1.1"
xmlns:core="http://scap.nist.gov/schema/reporting-core/1.1" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
targetNamespace="http://scap.nist.gov/schema/asset-reporting-format/1.1" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.1.1">
<xs:annotation>
<xs:appinfo>
<schema>Asset Reporting Format</schema>
<author>David Waltermire, Adam Halbardier, John Wunder</author>
<version>1.1.1</version>
<date>2012-02-13</date>
<sch:schema queryBinding="xslt2" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:ns prefix="xml" uri="http://www.w3.org/XML/1998/namespace"/>
<sch:ns prefix="xsd" uri="http://www.w3.org/2001/XMLSchema"/>
<sch:ns prefix="arf" uri="http://scap.nist.gov/schema/asset-reporting-format/1.1"/>
<sch:ns prefix="core" uri="http://scap.nist.gov/schema/reporting-core/1.1"/>
<sch:ns prefix="ai" uri="http://scap.nist.gov/schema/asset-identification/1.1"/>
<sch:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
<sch:ns prefix="xcf" uri="nist:scap:arf:xslt:function"/>
<sch:pattern>
<!-- 2011-11-29 - Correcting defect. The namespace is updated to match the namespace specified in NIST IR 7694, Section 6.1 -->
<!-- <sch:let name="arf-namespace" value="string('http://scap.nist.gov/vocabulary/arf/relationships/1.0#')"/> -->
<sch:let name="arf-namespace" value="string('http://scap.nist.gov/specifications/arf/vocabulary/relationships/1.0#')"/>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'isAbout' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:assets/arf:asset[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'asset')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'retrievedFrom' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:assets/arf:asset[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'asset')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'createdBy' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:assets/arf:asset[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'asset')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'hasSource' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:assets/arf:asset[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'asset')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'recordedBy' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:assets/arf:asset[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'asset')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'initiatedBy' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:assets/arf:asset[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'asset')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'createdFor' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:report-requests/arf:report-request[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'report-request')"/>
</sch:assert>
</sch:rule>
<sch:rule context="core:relationship[fn:resolve-QName(@type, current()) eq fn:QName($arf-namespace,'hasMetadata' )]">
<sch:assert test="exists(ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq current()/@subject])">
<sch:value-of select="xcf:controlled-vocab-error-domain(current(),'report')"/>
</sch:assert>
<sch:assert test="every $m in core:ref satisfies current()/ancestor::arf:asset-report-collection/arf:reports/arf:report[@id eq $m]">
<sch:value-of select="xcf:controlled-vocab-error-range(current(),'report')"/>
</sch:assert>
</sch:rule>
</sch:pattern>
<xsl:function name="xcf:controlled-vocab-error-domain" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xcf="nist:scap:arf:xslt:function" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="node"/>
<xsl:param name="refName"/>
<xsl:value-of select="concat(concat(concat(concat(string('All @subject attribute in a relationship of type '),namespace-uri-from-QName(resolve-QName($node/@type, $node))),local-name-from-QName(resolve-QName($node/@type, $node))),string(' must reference a ')),$refName)"/>
</xsl:function>
<xsl:function name="xcf:controlled-vocab-error-range" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xcf="nist:scap:arf:xslt:function" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="node"/>
<xsl:param name="refName"/>
<xsl:value-of select="concat(concat(concat(concat(string('All <ref> elements in a relationship of type '),namespace-uri-from-QName(resolve-QName($node/@type, $node))),local-name-from-QName(resolve-QName($node/@type, $node))),string(' must reference a ')),$refName)"/>
</xsl:function>
</sch:schema>
</xs:appinfo>
</xs:annotation>
<xs:import namespace="http://scap.nist.gov/schema/asset-identification/1.1"
schemaLocation="https://scap.nist.gov/schema/asset-identification/1.1/asset-identification_1.1.0.xsd"/>
<xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="https://www.w3.org/1999/xlink.xsd"/>
<xs:import namespace="http://scap.nist.gov/schema/reporting-core/1.1"
schemaLocation="https://scap.nist.gov/schema/reporting-core/1.1/reporting-core_1.1.0.xsd"/>
<xs:element name="asset-report-collection">
<xs:annotation>
<xs:documentation>The top-level report element.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="core:relationships-container-type">
<xs:sequence>
<xs:element name="report-requests" minOccurs="0">
<xs:annotation>
<xs:documentation>Contains one or more requests for reports. Each report request must be referenced in a relationship on a report in the same asset-report-collection.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="report-request" type="arf:ReportRequestType" maxOccurs="unbounded"
> </xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="assets">
<xs:annotation>
<xs:documentation>Contains the representation of one or more assets represented using the Asset Identification format.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="asset">
<xs:complexType>
<xs:choice>
<xs:element ref="ai:asset"/>
<xs:element ref="arf:remote-resource"/>
</xs:choice>
<xs:attribute name="id" type="xs:NCName" use="required">
<xs:annotation>
<xs:documentation>An internal ID to identify this asset.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as
desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="reports">
<xs:annotation>
<xs:documentation>Contains one or more reports.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="report" type="arf:ReportType" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>Contains a report, which is composed of zero or more relationships and a content payload.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="extended-infos">
<xs:annotation>
<xs:documentation>Contain other information elements. Used as an extension point.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="extended-info">
<xs:annotation>
<xs:documentation>Contains other information. Use as an extension point for data that does not fall into the categories defined in asset-report-collection.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any namespace="##other" processContents="lax"/>
</xs:sequence>
<xs:attribute name="id" type="xs:NCName" use="required">
<xs:annotation>
<xs:documentation>An internal ID to identify this object.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:NCName">
<xs:annotation>
<xs:documentation>The id for this collection.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:key name="idKey">
<xs:selector xpath=".//arf:report-request|.//arf:asset|.//arf:report|.//arf:extended-info"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="relSubjKeyRef" refer="arf:idKey">
<xs:selector xpath="core:relationships/core:relationship"/>
<xs:field xpath="@subject"/>
</xs:keyref>
<xs:keyref name="relObjKeyRef" refer="arf:idKey">
<xs:selector xpath="core:relationships/core:relationship/core:ref"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>
<xs:complexType name="ReportRequestType">
<xs:choice>
<xs:element name="content">
<xs:annotation>
<xs:documentation>Contains the content of the report request.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any namespace="##other" processContents="lax">
<xs:annotation>
<xs:documentation>Holds the content of a report request.</xs:documentation>
</xs:annotation>
</xs:any>
</xs:sequence>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
</xs:element>
<xs:element ref="arf:remote-resource"/>
</xs:choice>
<xs:attribute name="id" type="xs:NCName" use="required">
<xs:annotation>
<xs:documentation>An internal ID to identify this report request.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
<xs:complexType name="ReportType">
<xs:choice>
<xs:element name="content">
<xs:annotation>
<xs:documentation>Contains the content of the report.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any namespace="##other" processContents="lax"/>
</xs:sequence>
<xs:attribute name="data-valid-start-date" type="xs:date"/>
<xs:attribute name="data-valid-end-date" type="xs:date"/>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
</xs:element>
<xs:element ref="arf:remote-resource"/>
</xs:choice>
<xs:attribute name="id" type="xs:NCName" use="required">
<xs:annotation>
<xs:documentation>An internal ID to identify this report.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
<xs:element name="object-ref">
<xs:annotation>
<xs:documentation>Report creators can embedding this element in a report with the @ref_id referencing the ID of an asset, report, or report request. This element effectively acts as a pointer, allowing content produces to reference higher level ARF constructs in a report, without duplicating the data in that ARF construct.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="ref-id" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="remote-resource">
<xs:annotation>
<xs:documentation>Links to content stored external to this report.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute ref="xlink:type" use="required" fixed="simple">
<xs:annotation>
<xs:documentation>Fixed as a simple XLink.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute ref="xlink:href" use="required">
<xs:annotation>
<xs:documentation>A URI to the remote content. Producers and consumers should both know how to resolve the URI in order to be interoperable.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:anyAttribute namespace="##other">
<xs:annotation>
<xs:documentation>A placeholder so that content creators can add attributes as desired.</xs:documentation>
</xs:annotation>
</xs:anyAttribute>
</xs:complexType>
</xs:element>
</xs:schema>
<!-- CHANGELOG
date change remarks
02/13/12 Update the version number Updated the schema version to 1.1.1 based on the change made on 11/29/11
Update the schema date Updated the schema date to 2012-02-13
11/29/11 changed relationship The namespace for relationships in the Schematron did not match the NIST IR 7694, Section 6.1
namespace in Schematron
-->
|
|
| |
Re: Generated *FactoryImpl is not an instance of Resource.Factory [message #1782078 is a reply to message #1782073] |
Fri, 16 February 2018 19:16 |
Geoffry Roberts Messages: 16 Registered: May 2014 |
Junior Member |
|
|
Ed,
Thanks for a quick response.
When I try to read an XML file that conforms to said schema, (uploaded) I get a class cast exception. Upon investigation, I see that my factory class is found in the registry but when I test it with an "instanceof" it is not of type Resource.Factory, which is what the error message says.
You say you've generated code from the schema I posted. and you're telling me it appears normal. I believe you.
In the past, I only had the class cast exception when things were not registered properly. I am under the impression I am registering correctly in this case. So why the cast problem?
Here's where the error is thrown:
public class ResourceFactoryRegistryImpl implements Resource.Factory.Registry
... <more code> ...
public static Resource.Factory convert(Object resourceFactory)
{
return
resourceFactory instanceof Resource.Factory.Descriptor ?
((Resource.Factory.Descriptor)resourceFactory).createFactory() :
(Resource.Factory)resourceFactory; // This cast worketh not.
}
... <more code> ...
Here's me registering the class in question and everything else:
getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new gov.nist.scap.schema.asset.reporting.format._1.impl._1FactoryImpl()); resourceSet.getPackageRegistry().put(gov.nist.scap.schema.asset.identification._1._1Package.eNS_URI, gov.nist.scap.schema.asset.identification._1._1Package.eINSTANCE);
resourceSet.getPackageRegistry().put(gov.nist.scap.schema.asset.reporting.format._1._1Package.eNS_URI, gov.nist.scap.schema.asset.reporting.format._1._1Package.eINSTANCE);
resourceSet.getPackageRegistry().put(gov.nist.scap.schema.reporting.core._1._1Package.eNS_URI, gov.nist.scap.schema.reporting.core._1._1Package.eINSTANCE);
resourceSet.getPackageRegistry().put(oasis.names.tc.ciq.xsdschema.xAL._2._0._0Package.eNS_URI, oasis.names.tc.ciq.xsdschema.xAL._2._0._0Package.eINSTANCE);
resourceSet.getPackageRegistry().put(oasis.names.tc.ciq.xsdschema.xNL._2._0._0Package.eNS_URI, oasis.names.tc.ciq.xsdschema.xNL._2._0._0Package.eINSTANCE);
Registrar.registerPackage(org.mitre.cpe.naming._2._2Package.eNS_URI, org.mitre.cpe.naming._2._2Package.eINSTANCE);
resourceSet.getPackageRegistry().put(org.w3.xml._1998.namespace.NamespacePackage.eNS_URI, org.w3.xml._1998.namespace.NamespacePackage.eINSTANCE);
-
Attachment: arf.xml
(Size: 5.02MB, Downloaded 309 times)
|
|
| |
Re: Generated *FactoryImpl is not an instance of Resource.Factory [message #1782093 is a reply to message #1782090] |
Sat, 17 February 2018 06:23 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
My guess would be that you are (or something is) mixing up two different factories. In the impl package there should be an XyzPackageImpl and an XyzFactoryImpl that extends EFactoryImpl. In your util package there is an XyzResourceFactoryImpl. The latter should be registered with the URI converter. If you generated the *.test project, there will be an XyzExample.java that shows how to do the registrations correctly for a stand-alone application.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Wed Sep 25 11:59:55 GMT 2024
Powered by FUDForum. Page generated in 0.04615 seconds
|