use of org.apache.ws.commons.schema.XmlSchemaCollection in project tdi-studio-se by Talend.
the class ComponentBuilder method createschemafromtype.
private XmlSchema createschemafromtype(org.w3c.dom.Element schemaElement, Definition wsdlDefinition, String documentBase) throws WSDLException {
if (schemaElement == null) {
throw new WSDLException(WSDLException.INVALID_WSDL, "Unable to find schema extensibility element in WSDL");
}
XmlSchema xmlSchema = null;
XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
xmlSchemaCollection.setBaseUri(fixDocumentBase(documentBase));
xmlSchema = xmlSchemaCollection.read(schemaElement);
return xmlSchema;
}
use of org.apache.ws.commons.schema.XmlSchemaCollection in project tomee by apache.
the class SchemaInfoBuilderTest method loadSchemaInfo.
private XmlSchemaInfo loadSchemaInfo(String fileName) throws Exception {
InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
xmlSchemaCollection.read(new InputStreamReader(in), null);
CommonsSchemaInfoBuilder schemaInfoBuilder = new CommonsSchemaInfoBuilder(xmlSchemaCollection);
XmlSchemaInfo schemaInfo = schemaInfoBuilder.createSchemaInfo();
return schemaInfo;
}
use of org.apache.ws.commons.schema.XmlSchemaCollection in project ddf by codice.
the class TestWfsSource method getWfsSource.
public WfsSource getWfsSource(final String schema, final FilterCapabilities filterCapabilities, final String srsName, final int numFeatures, final boolean throwExceptionOnDescribeFeatureType, boolean prefix, int numReturned) throws WfsException, SecurityServiceException {
mockFactory = mock(SecureCxfClientFactory.class);
when(mockFactory.getClient()).thenReturn(mockWfs);
// GetCapabilities Response
when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilites);
when(mockFeatureCollection.getMembers()).thenAnswer(new Answer<List<Metacard>>() {
@Override
public List<Metacard> answer(InvocationOnMock invocation) {
// Create as many metacards as there are features
List<Metacard> metacards = new ArrayList<Metacard>(numFeatures);
for (int i = 0; i < numFeatures; i++) {
MetacardImpl mc = new MetacardImpl();
mc.setId("ID_" + String.valueOf(i + 1));
metacards.add(mc);
}
return metacards;
}
});
if (numReturned != NULL_NUM_RETURNED) {
when(mockFeatureCollection.getNumberReturned()).thenReturn(BigInteger.valueOf(numReturned));
} else {
when(mockFeatureCollection.getNumberReturned()).thenReturn(null);
}
when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
mockCapabilites.setFilterCapabilities(filterCapabilities);
when(mockAvailabilityTask.isAvailable()).thenReturn(true);
mockCapabilites.setFeatureTypeList(new FeatureTypeListType());
for (int ii = 0; ii < numFeatures; ii++) {
FeatureTypeType feature = new FeatureTypeType();
QName qName;
if (prefix) {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii, "Prefix" + ii);
} else {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii);
}
feature.setName(qName);
feature.setDefaultCRS(GeospatialUtil.EPSG_4326_URN);
mockCapabilites.getFeatureTypeList().getFeatureType().add(feature);
}
XmlSchema xmlSchema = null;
if (StringUtils.isNotBlank(schema)) {
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
WfsUriResolver wfsUriResolver = new WfsUriResolver();
wfsUriResolver.setGmlNamespace(Wfs20Constants.GML_3_2_NAMESPACE);
wfsUriResolver.setWfsNamespace(Wfs20Constants.WFS_2_0_NAMESPACE);
schemaCollection.setSchemaResolver(wfsUriResolver);
xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
}
if (throwExceptionOnDescribeFeatureType) {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenThrow(new WfsException(""));
} else {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
}
WfsSource wfsSource = new WfsSource(new GeotoolsFilterAdapterImpl(), mockContext, mockAvailabilityTask, mockFactory, encryptionService);
wfsSource.setFeatureCollectionReader(mockReader);
return wfsSource;
}
use of org.apache.ws.commons.schema.XmlSchemaCollection in project ddf by codice.
the class XmlSchemaMessageBodyReader method readFrom.
@Override
public XmlSchema readFrom(Class<XmlSchema> clazz, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream inStream) throws IOException, WebApplicationException {
// Determine if this is an XMLSchema
String input = IOUtils.toString(inStream);
inStream.reset();
String count = COUNT_XPATH_BUILDER.evaluate(camelContext, input);
// See if there exactly one instance of "xsd:schema" in this doc
if (Integer.parseInt(count) == 1) {
XmlSchema schema = null;
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
schemaCollection.init();
schemaCollection.setSchemaResolver(wfsUriResolver);
schema = schemaCollection.read(new InputSource(inStream));
return schema;
}
LOGGER.debug("Did not receive valid XML Schema, instead got: \n{}", input);
return null;
}
use of org.apache.ws.commons.schema.XmlSchemaCollection in project tdi-studio-se by Talend.
the class AllTypeDialog method initSimpleType.
private void initSimpleType() throws WSDLException, URISyntaxException {
String url = URLValue;
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader newWSDLReader = wsdlFactory.newWSDLReader();
newWSDLReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
URI wsdlURI = new URI(url);
Definition definition = newWSDLReader.readWSDL(url);
java.util.List<ExtensibilityElement> extensibilityElements = definition.getTypes().getExtensibilityElements();
String tmpTNName = "";
int tmpCount = 0;
for (ExtensibilityElement el : extensibilityElements) {
if (el instanceof Schema) {
Schema schema = (Schema) el;
// for bug 8674
// set base uri for relative path in schemaLocation.
schemaCollection.setBaseUri(schema.getDocumentBaseURI());
if (schema.getElement().getAttributeNode("targetNamespace") == null) {
tmpTNName = schema.getDocumentBaseURI() + "#type" + tmpCount;
schemaCollection.read(schema.getElement(), tmpTNName);
tmpCount++;
} else {
schemaCollection.read(schema.getElement());
}
}
}
Map namespaces = definition.getNamespaces();
// System.out.println(namespaces);
XmlSchema[] schemas = schemaCollection.getXmlSchemas();
java.util.List<String> labelList = new ArrayList<String>();
for (int i = 0; i < schemas.length; i++) {
XmlSchema schema = schemas[i];
XmlSchemaObjectTable types = schema.getSchemaTypes();
Iterator it = types.getValues();
while (it.hasNext()) {
XmlSchemaType type = (XmlSchemaType) it.next();
if (type instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType t = (XmlSchemaSimpleType) type;
String label = "simpletype:" + t.getName();
if (!labelList.contains(label)) {
labelList.add(label);
labelAndNameSpaceMap.put(label, t.getQName().toString());
}
}
}
}
allXMLSimpleTypeName = new String[labelList.size()];
for (int i = 0; i < labelList.size(); i++) {
allXMLSimpleTypeName[i] = labelList.get(i);
}
}
Aggregations