use of org.apache.xerces.xs.XSNamedMap in project jena by apache.
the class XSDDatatype method loadUserDefined.
/**
* Internal implementation of loadUserDefined
*
* @param uri the absolute uri of the schema file to be loaded
* @param reader the Reader stream onto the file (useful if you wish to load a cached copy of the schema file)
* @param encoding the encoding of the source file (can be null)
* @param tm the type mapper into which to load the definitions
* @return a List of strings giving the uri's of the newly defined datatypes
* @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
* in default mode for load which may provide diagnostic output direct to stderr)
*/
private static List<String> loadUserDefined(XMLInputSource source, TypeMapper tm) throws DatatypeFormatException {
XMLGrammarPreparser parser = new XMLGrammarPreparser();
parser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
try {
XSGrammar xsg = (XSGrammar) parser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, source);
org.apache.xerces.xs.XSModel xsm = xsg.toXSModel();
XSNamedMap map = xsm.getComponents(XSTypeDefinition.SIMPLE_TYPE);
int numDefs = map.getLength();
ArrayList<String> names = new ArrayList<>(numDefs);
for (int i = 0; i < numDefs; i++) {
XSSimpleType xstype = (XSSimpleType) map.item(i);
// Filter built in types - only needed for 2.6.0
if (!XSD.equals(xstype.getNamespace())) {
//xstype.derivedFrom()
XSDDatatype definedType = new XSDGenericType(xstype, source.getSystemId());
tm.registerDatatype(definedType);
names.add(definedType.getURI());
}
}
return names;
} catch (Exception e) {
// Temp
e.printStackTrace();
throw new DatatypeFormatException(e.toString());
}
}
use of org.apache.xerces.xs.XSNamedMap in project iaf by ibissource.
the class XmlTypeToJsonSchemaConverter method getDefinitions.
public JsonObject getDefinitions() {
JsonObjectBuilder definitionsBuilder = Json.createObjectBuilder();
for (XSModel model : models) {
XSNamedMap elements = model.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int i = 0; i < elements.getLength(); i++) {
XSElementDeclaration elementDecl = (XSElementDeclaration) elements.item(i);
handleElementDeclaration(definitionsBuilder, elementDecl, false, false);
}
XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
for (int i = 0; i < types.getLength(); i++) {
XSTypeDefinition typeDefinition = (XSTypeDefinition) types.item(i);
String typeNamespace = typeDefinition.getNamespace();
if (typeNamespace == null || !typeDefinition.getNamespace().equals(XML_SCHEMA_NS)) {
definitionsBuilder.add(typeDefinition.getName(), getDefinition(typeDefinition, false));
}
}
}
return definitionsBuilder.build();
}
use of org.apache.xerces.xs.XSNamedMap in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathTest method addUserDefinedSimpleTypes.
protected void addUserDefinedSimpleTypes(XSModel schema) {
XSNamedMap xstypes = schema.getComponents(XSConstants.TYPE_DEFINITION);
if (xstypes.getLength() == 0) {
return;
}
addNamespace("myType", "http://www.w3.org/XQueryTest/userDefinedTypes");
UserDefinedCtrLibrary udl = new UserDefinedCtrLibrary("http://www.w3.org/XQueryTest/userDefinedTypes");
for (int i = 0; i < xstypes.getLength(); i++) {
XSObject xsobject = xstypes.item(i);
if ("http://www.w3.org/XQueryTest/userDefinedTypes".equals(xsobject.getNamespace())) {
if (xsobject instanceof XSSimpleTypeDefinition) {
XSSimpleTypeDefinition typeDef = (XSSimpleTypeDefinition) xsobject;
if (typeDef.getNumeric()) {
if (xsobject.getName().equals("floatBased") || xsobject.getName().equals("shoesize")) {
XercesFloatUserDefined fudt = new XercesFloatUserDefined(xsobject);
udl.add_type(fudt);
} else {
XercesIntegerUserDefined iudt = new XercesIntegerUserDefined(xsobject);
udl.add_type(iudt);
}
} else {
if (xsobject.getName().equals("QNameBased")) {
XercesQNameUserDefined qudt = new XercesQNameUserDefined(xsobject);
udl.add_type(qudt);
} else {
XercesUserDefined udt = new XercesUserDefined(typeDef);
udl.add_type(udt);
}
}
}
}
}
addFunctionLibrary(udl);
}
use of org.apache.xerces.xs.XSNamedMap in project winery by eclipse.
the class RepositoryBasedXsdImportManager method getAllDefinedLocalNames.
// we need "unchecked", because of the parsing of the cache
@SuppressWarnings("unchecked")
private List<String> getAllDefinedLocalNames(final XSDImportId id, final boolean getTypes) {
Objects.requireNonNull(id);
Optional<RepositoryFileReference> ref = this.getXsdFileReference(id);
if (!ref.isPresent()) {
return Collections.emptyList();
}
short type = getTypes ? XSConstants.TYPE_DEFINITION : XSConstants.ELEMENT_DECLARATION;
Date lastUpdate = owner.getLastUpdate(ref.get());
@NonNull final String cacheFileName = "definedLocalNames " + Integer.toString(type) + ".cache";
@NonNull final RepositoryFileReference cacheRef = new RepositoryFileReference(id, cacheFileName);
boolean cacheNeedsUpdate = true;
if (owner.exists(cacheRef)) {
Date lastUpdateCache = owner.getLastUpdate(cacheRef);
if (lastUpdate.compareTo(lastUpdateCache) <= 0) {
cacheNeedsUpdate = false;
}
}
List<String> result;
if (cacheNeedsUpdate) {
final Optional<XSModel> model = BackendUtils.getXSModel(ref.get(), owner);
if (!model.isPresent()) {
return Collections.emptyList();
}
XSNamedMap components = model.get().getComponents(type);
// @SuppressWarnings("unchecked")
int len = components.getLength();
result = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
XSObject item = components.item(i);
// We want to return only types defined in the namespace of this resource
if (id.getNamespace().getDecoded().equals(item.getNamespace())) {
result.add(item.getName());
}
}
String cacheContent = null;
try {
cacheContent = JacksonProvider.mapper.writeValueAsString(result);
} catch (JsonProcessingException e) {
LOGGER.error("Could not generate cache content", e);
}
try {
owner.putContentToFile(cacheRef, cacheContent, MediaTypes.MEDIATYPE_APPLICATION_JSON);
} catch (IOException e) {
LOGGER.error("Could not update cache", e);
}
} else {
// cache should contain most recent information
try (InputStream is = owner.newInputStream(cacheRef)) {
result = JacksonProvider.mapper.readValue(is, java.util.List.class);
} catch (IOException e) {
LOGGER.error("Could not read from cache", e);
result = Collections.emptyList();
}
}
return result;
}
Aggregations