use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method createComplexTypeForClass.
private ComplexType createComplexTypeForClass(JavaClass myClass, TypeInfo info) {
Schema schema = getSchemaForNamespace(info.getClassNamespace());
ComplexType type = new ComplexType();
JavaClass superClass = CompilerHelper.getNextMappedSuperClass(myClass, this.typeInfo, this.helper);
// Handle abstract class
if (myClass.isAbstract()) {
type.setAbstractValue(true);
}
Extension extension = null;
if (superClass != null) {
TypeInfo parentTypeInfo = this.typeInfo.get(superClass.getQualifiedName());
if (parentTypeInfo != null) {
extension = new Extension();
// may need to qualify the type
String parentPrefix = getPrefixForNamespace(schema, parentTypeInfo.getClassNamespace());
if (parentPrefix != null) {
extension.setBaseType(parentPrefix + COLON + parentTypeInfo.getSchemaTypeName());
} else {
extension.setBaseType(parentTypeInfo.getSchemaTypeName());
}
if (parentTypeInfo.getXmlValueProperty() != null) {
SimpleContent content = new SimpleContent();
content.setExtension(extension);
type.setSimpleContent(content);
return type;
} else {
ComplexContent content = new ComplexContent();
content.setExtension(extension);
type.setComplexContent(content);
}
}
}
TypeDefParticle compositor = null;
String[] propOrder = null;
if (info.isSetPropOrder()) {
propOrder = info.getPropOrder();
}
if (propOrder != null && propOrder.length == 0) {
// requires the extension case to use sequences
if (info.hasElementRefs()) {
// generate a sequence to satisfy TCK
compositor = new Sequence();
if (extension != null) {
extension.setSequence((Sequence) compositor);
} else {
type.setSequence((Sequence) compositor);
}
} else if (extension != null) {
compositor = new All();
extension.setAll((All) compositor);
} else {
compositor = new All();
type.setAll((All) compositor);
}
} else {
// generate a sequence to satisfy TCK
compositor = new Sequence();
if (extension != null) {
extension.setSequence((Sequence) compositor);
} else {
type.setSequence((Sequence) compositor);
}
}
return type;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.
the class SimpleTableWithNestedSQLTestSuite method checkWSDL.
@Test
public void checkWSDL() throws WSDLException {
DBWS_BUILDER_XML_USERNAME = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<dbws-builder xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<properties>" + "<property name=\"projectName\">simpletable2</property>" + "<property name=\"logLevel\">off</property>" + "<property name=\"username\">";
DBWS_BUILDER_XML_PASSWORD = "</property><property name=\"password\">";
DBWS_BUILDER_XML_URL = "</property><property name=\"url\">";
DBWS_BUILDER_XML_DRIVER = "</property><property name=\"driver\">";
DBWS_BUILDER_XML_PLATFORM = "</property><property name=\"platformClassname\">";
DBWS_BUILDER_XML_MAIN = "</property>" + "</properties>" + "<table " + "schemaPattern=\"%\" " + "tableNamePattern=\"simpletable2\" " + ">" + "<sql " + "name=\"findByName\" " + "isCollection=\"true\" " + "returnType=\"simpletable2Type\" " + ">" + "<text><![CDATA[select * from SIMPLETABLE2 where NAME like ?]]></text>" + "<binding name=\"NAME\" type=\"xsd:string\"/>" + "</sql>" + "</table>" + "</dbws-builder>";
String username = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
String password = System.getProperty(DATABASE_PASSWORD_KEY, DEFAULT_DATABASE_PASSWORD);
String url = System.getProperty(DATABASE_URL_KEY, DEFAULT_DATABASE_URL);
String builderString = DBWS_BUILDER_XML_USERNAME + username + DBWS_BUILDER_XML_PASSWORD + password + DBWS_BUILDER_XML_URL + url + DBWS_BUILDER_XML_DRIVER + DATABASE_DRIVER + DBWS_BUILDER_XML_PLATFORM + DATABASE_PLATFORM + DBWS_BUILDER_XML_MAIN;
XMLContext context = new XMLContext(new DBWSBuilderModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSBuilderModel builderModel = (DBWSBuilderModel) unmarshaller.unmarshal(new StringReader(builderString));
DBWSBuilder builder = new DBWSBuilder();
builder.quiet = true;
// builder.setLogLevel(SessionLog.FINE_LABEL);
builder.setLogLevel(SessionLog.OFF_LABEL);
builder.setPlatformClassname(DATABASE_PLATFORM);
builder.properties = builderModel.properties;
builder.getProperties().put(SESSIONS_FILENAME_KEY, NO_SESSIONS_FILENAME);
builder.operations = builderModel.operations;
builder.setPackager(new JSR109WebServicePackager(null, "WebServiceTestPackager", noArchive) {
@Override
public void start() {
// do nothing - don't have to verify existence of 'stageDir' when
// all the streams are in-memory
}
});
ByteArrayOutputStream dbwsServiceStream = new ByteArrayOutputStream();
ByteArrayOutputStream wsdlStream = new ByteArrayOutputStream();
builder.build(__nullStream, __nullStream, dbwsServiceStream, __nullStream, __nullStream, __nullStream, __nullStream, wsdlStream, __nullStream, __nullStream, __nullStream, __nullStream, null);
// for the nested sql operation 'findByName'
try {
StringWriter sw = new StringWriter();
StreamSource wsdlStreamSource = new StreamSource(new StringReader(wsdlStream.toString()));
Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(MATCH_SCHEMA)));
StreamResult streamResult = new StreamResult(sw);
t.transform(wsdlStreamSource, streamResult);
sw.toString();
SchemaModelProject schemaProject = new SchemaModelProject();
XMLContext xmlContext2 = new XMLContext(schemaProject);
unmarshaller = xmlContext2.createUnmarshaller();
Schema schema = (Schema) unmarshaller.unmarshal(new StringReader(sw.toString()));
ComplexType findByNameResponseType = schema.getTopLevelComplexTypes().get(FINDBYNAME_RESPONSETYPE);
Element result = findByNameResponseType.getSequence().getElements().get(0);
Element unnamed = result.getComplexType().getSequence().getElements().get(0);
assertTrue("wrong refType for " + FINDBYNAME_RESPONSETYPE, TABLE_ALIAS.equals(unnamed.getRef()));
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method getSchema.
/**
* Return a Schema for the given Source object.
*
* Since this method is called recursively, and the SchemaResolverWrapper is stateful,
* the resolver wrapper must be created outside of this method.
*
* @param xsdSource
* @param schemaResolverWrapper wraps the schema resolver to be used to resolve imports/includes
* @return
*/
public Schema getSchema(Source xsdSource, SchemaResolverWrapper schemaResolverWrapper, boolean closeStream) {
xsdSource = schemaResolverWrapper.resolveSchema(xsdSource);
XMLContext context = new XMLContext(getSchemaProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setEntityResolver(schemaResolverWrapper.getSchemaResolver());
Schema schema = (Schema) unmarshaller.unmarshal(xsdSource);
if (closeStream) {
closeSource(xsdSource);
}
// populate Imports
java.util.List<Import> imports = schema.getImports();
Iterator<Import> iter = imports.iterator();
while (iter.hasNext()) {
Import nextImport = iter.next();
Source referencedSchema = getReferencedSchema(xsdSource, nextImport.getNamespace(), nextImport.getSchemaLocation(), schemaResolverWrapper);
if (referencedSchema != null) {
Schema importedSchema = getSchema(referencedSchema, schemaResolverWrapper, true);
nextImport.setSchema(importedSchema);
}
}
// populate includes
java.util.List<Include> includes = schema.getIncludes();
Iterator<Include> includesIter = includes.iterator();
while (includesIter.hasNext()) {
Include nextInclude = includesIter.next();
Source referencedSchema = getReferencedSchema(xsdSource, schema.getTargetNamespace(), nextInclude.getSchemaLocation(), schemaResolverWrapper);
if (referencedSchema != null) {
Schema includedSchema = getSchema(referencedSchema, schemaResolverWrapper, true);
nextInclude.setSchema(includedSchema);
}
}
return schema;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method generateSchemas.
/**
* Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors.
* The descriptors are assumed to have been initialized. One Schema object will be generated
* per namespace.
*
* @param descriptorsToProcess list of XMLDescriptors which will be used to generate Schema objects
* @param properties holds a namespace to Properties map containing schema settings, such as elementFormDefault
* @return a map of namespaces to EclipseLink schema model Schema objects
* @throws DescriptorException if the reference descriptor for a composite mapping is not in the list of descriptors
* @see Schema
*/
public Map<String, Schema> generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties) throws DescriptorException {
HashMap<String, Schema> schemaForNamespace = new HashMap<>();
Schema workingSchema = null;
if (properties == null) {
properties = new SchemaModelGeneratorProperties();
}
// set up schemas for the descriptors
for (Descriptor desc : descriptorsToProcess) {
String namespace;
XMLSchemaReference schemaRef = desc.getSchemaReference();
if (schemaRef != null) {
namespace = schemaRef.getSchemaContextAsQName(desc.getNamespaceResolver()).getNamespaceURI();
workingSchema = getSchema(namespace, desc.getNamespaceResolver(), schemaForNamespace, properties);
addNamespacesToWorkingSchema(desc.getNamespaceResolver(), workingSchema);
} else {
// default root element set we will need to generate a global element for it
for (DatabaseTable table : (Vector<DatabaseTable>) desc.getTables()) {
namespace = getDefaultRootElementAsQName(desc, table.getName()).getNamespaceURI();
workingSchema = getSchema(namespace, desc.getNamespaceResolver(), schemaForNamespace, properties);
addNamespacesToWorkingSchema(desc.getNamespaceResolver(), workingSchema);
}
}
}
// process the descriptors
for (Descriptor xdesc : descriptorsToProcess) {
processDescriptor(xdesc, schemaForNamespace, workingSchema, properties, descriptorsToProcess);
}
// return the generated schema(s)
return schemaForNamespace;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processReferenceDescriptor.
/**
*/
protected Element processReferenceDescriptor(Element element, Descriptor refDesc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, Field field, boolean isCollection) {
ComplexType ctype = null;
if (refDesc.getSchemaReference() == null) {
ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
} else {
element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
}
XPathFragment frag = field.getXPathFragment();
String fragUri = frag.getNamespaceURI();
if (fragUri != null) {
// may need to add a global element
Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
String targetNS = workingSchema.getTargetNamespace();
if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
if (s.getTopLevelElements().get(frag.getShortName()) == null) {
Element globalElement = new Element();
globalElement.setName(frag.getLocalName());
if (ctype != null) {
globalElement.setComplexType(ctype);
} else {
globalElement.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
}
s.getTopLevelElements().put(frag.getShortName(), globalElement);
}
element = new Element();
element.setMinOccurs(Occurs.ZERO);
if (isCollection) {
element.setMaxOccurs(Occurs.UNBOUNDED);
}
element.setRef(frag.getShortName());
} else {
element.setComplexType(ctype);
}
} else if (ctype != null) {
element.setComplexType(ctype);
}
return element;
}
Aggregations