Search in sources :

Example 21 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class TwoProjectsTestSuite method testAddDuplicateSession.

public void testAddDuplicateSession() throws Exception {
    XMLContext xmlContext = new XMLContext(CONTEXT_PATH_SAX);
    Project empProject = new EmployeeProject();
    XMLPlatform<org.eclipse.persistence.internal.oxm.XMLUnmarshaller> platform = new SAXPlatform();
    empProject.setLogin(new XMLLogin(platform));
    DatabaseSession employeeSession = empProject.createDatabaseSession();
    xmlContext.addSession(employeeSession);
    xmlMarshaller = xmlContext.createMarshaller();
    Employee employee = getControlEmployee();
    Document controlDocument = getControlDocument(XML_RESOURCE_EMPLOYEE);
    Document testDocument = parser.newDocument();
    xmlMarshaller.marshal(employee, testDocument);
    log("\nExpected:");
    log(controlDocument);
    log("\nActual:");
    log(testDocument);
    log("");
    this.assertXMLIdentical(controlDocument, testDocument);
    int numSessions = xmlContext.getSessions().size();
    assertEquals(3, numSessions);
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Document(org.w3c.dom.Document) Project(org.eclipse.persistence.sessions.Project) SAXPlatform(org.eclipse.persistence.oxm.platform.SAXPlatform) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller)

Example 22 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class TwoProjectsTestSuite method testAddLoggedOutSession.

public void testAddLoggedOutSession() throws Exception {
    XMLContext xmlContext = new XMLContext(new CustomerProject());
    Project empProject = new EmployeeProject();
    XMLPlatform<org.eclipse.persistence.internal.oxm.XMLUnmarshaller> platform = new SAXPlatform();
    empProject.setLogin(new XMLLogin(platform));
    DatabaseSession employeeSession = empProject.createDatabaseSession();
    employeeSession.logout();
    xmlContext.addSession(employeeSession);
    xmlMarshaller = xmlContext.createMarshaller();
    Employee employee = getControlEmployee();
    Document controlDocument = getControlDocument(XML_RESOURCE_EMPLOYEE);
    Document testDocument = parser.newDocument();
    xmlMarshaller.marshal(employee, testDocument);
    log("\nExpected:");
    log(controlDocument);
    log("\nActual:");
    log(testDocument);
    log("");
    this.assertXMLIdentical(controlDocument, testDocument);
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Document(org.w3c.dom.Document) Project(org.eclipse.persistence.sessions.Project) SAXPlatform(org.eclipse.persistence.oxm.platform.SAXPlatform) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller)

Example 23 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class SDOSchemaGenerator method generate.

/**
 * <p>Method to generate an XSD. Note the following:<ul>
 * <li> All types must have same URI
 * <li> Referenced types in same URI will also be generated in schema
 * <li> Includes will never be generated
 * <li> Imports will be generated for referenced types in other URIs
 * </ul>
 * @param types The list of commonj.sdo.Type objects to generate the XSD from
 * @param aNamespaceToSchemaLocation map of namespaces to schemaLocations
 * used for getting the value of the schemaLocation attribute of generated imports and includes
 * @return String The generated XSD.
 */
public String generate(List types, Map<String, String> aNamespaceToSchemaLocation) {
    if ((types == null) || (types.size() == 0)) {
        throw new IllegalArgumentException("No Schema was generated from null or empty list of types.");
    }
    String uri = null;
    namespaceToSchemaLocation = aNamespaceToSchemaLocation;
    Type firstType = (Type) types.get(0);
    if (firstType == null) {
        throw new IllegalArgumentException("No Schema was generated from a list of types containing null elements");
    } else {
        uri = firstType.getURI();
    }
    allTypes = types;
    generateSchema(uri, types);
    // Now we have a built schema model
    Project p = new SchemaModelProject();
    Vector<Namespace> namespaces = generatedSchema.getNamespaceResolver().getNamespaces();
    for (int i = 0; i < namespaces.size(); i++) {
        Namespace next = namespaces.get(i);
        ((XMLDescriptor) p.getDescriptor(Schema.class)).getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI());
    }
    XMLLogin login = new XMLLogin();
    login.setDatasourcePlatform(new DOMPlatform());
    p.setDatasourceLogin(login);
    XMLContext context = new XMLContext(p);
    XMLMarshaller marshaller = context.createMarshaller();
    StringWriter generatedSchemaWriter = new StringWriter();
    marshaller.marshal(generatedSchema, generatedSchemaWriter);
    return generatedSchemaWriter.toString();
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Namespace(org.eclipse.persistence.internal.oxm.Namespace) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) StringWriter(java.io.StringWriter)

Example 24 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildSchema.

/**
 * Build the schema
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void buildSchema(NamingConventionTransformer nct) {
    Project oxProject = dbwsBuilder.getOxProject();
    Schema schema = null;
    List<Descriptor> descriptorsToProcess = new ArrayList<Descriptor>();
    for (Descriptor desc : (List<Descriptor>) (List) oxProject.getOrderedDescriptors()) {
        String alias = desc.getAlias();
        if (!DEFAULT_SIMPLE_XML_FORMAT_TAG.equals(alias)) {
            descriptorsToProcess.add(desc);
        }
    }
    if (descriptorsToProcess.size() > 0) {
        // need a deep-copy clone of oxProject; simplest way is to marshall/unmarshall to a stream
        StringWriter sw = new StringWriter();
        XMLProjectWriter.write(oxProject, sw);
        XRDynamicClassLoader specialLoader = new XRDynamicClassLoader(this.getClass().getClassLoader());
        Project oxProjectClone = XMLProjectReader.read(new StringReader(sw.toString()), specialLoader);
        ProjectHelper.fixOROXAccessors(oxProjectClone, null);
        XMLLogin xmlLogin = new XMLLogin();
        DOMPlatform domPlatform = new DOMPlatform();
        domPlatform.getConversionManager().setLoader(specialLoader);
        xmlLogin.setPlatform(domPlatform);
        oxProjectClone.setLogin(xmlLogin);
        // initialize reference descriptors
        oxProjectClone.createDatabaseSession();
        SchemaModelGenerator schemaGenerator = new SchemaModelGenerator(XMLConversionManager.getDefaultXMLManager(), true);
        SchemaModelGeneratorProperties sgProperties = new SchemaModelGeneratorProperties();
        // set element form default to qualified for target namespace
        sgProperties.addProperty(dbwsBuilder.getTargetNamespace(), ELEMENT_FORM_QUALIFIED_KEY, true);
        Map<String, Schema> schemaMap = schemaGenerator.generateSchemas(descriptorsToProcess, sgProperties);
        Schema s = schemaMap.get(dbwsBuilder.getTargetNamespace());
        // check existing schema for any top-level ComplexTypes
        if (dbwsBuilder.getSchema() != null && s != null) {
            Map<String, ComplexType> topLevelComplexTypes = dbwsBuilder.getSchema().getTopLevelComplexTypes();
            for (Map.Entry<String, ComplexType> me : topLevelComplexTypes.entrySet()) {
                s.addTopLevelComplexTypes(me.getValue());
            }
            // add any additional namespaces
            NamespaceResolver snr = s.getNamespaceResolver();
            NamespaceResolver nr = dbwsBuilder.getSchema().getNamespaceResolver();
            // we only want to add prefix/uri pairs for prefixes that don't already exist
            for (String prefix : nr.getPrefixesToNamespaces().keySet()) {
                if (snr.resolveNamespacePrefix(prefix) == null) {
                    snr.put(prefix, nr.resolveNamespacePrefix(prefix));
                }
            }
            // switch
            schema = s;
            schema.setNamespaceResolver(snr);
        }
    } else {
        schema = new Schema();
        addSimpleXMLFormat(schema);
        schema.setTargetNamespace(dbwsBuilder.getTargetNamespace());
    }
    dbwsBuilder.setSchema(schema);
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) ArrayList(java.util.ArrayList) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) Util.buildOXDescriptor(org.eclipse.persistence.tools.dbws.Util.buildOXDescriptor) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) Util.buildORDescriptor(org.eclipse.persistence.tools.dbws.Util.buildORDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) ArrayList(java.util.ArrayList) List(java.util.List) SchemaModelGenerator(org.eclipse.persistence.internal.oxm.schema.SchemaModelGenerator) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class SOAP12TestSuite method buildSessions.

@Override
public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
        conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);
    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
        MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
        processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
        PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
        processor.addNamedQueries();
        orProject = processor.getProject().getProject();
    } else {
        orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
        databaseSession.dontLogMessages();
    } else {
        databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);
    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
        JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
        XmlBindingsModel model = jaxbElt.getValue();
        for (XmlBindings xmlBindings : model.getBindingsList()) {
            metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
        }
    } catch (JAXBException jaxbex) {
        jaxbex.printStackTrace();
    }
    Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
        org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(parentClassLoader, properties);
        oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) HashMap(java.util.HashMap) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) JAXBContext(jakarta.xml.bind.JAXBContext) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel) Unmarshaller(jakarta.xml.bind.Unmarshaller) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) Project(org.eclipse.persistence.sessions.Project) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

XMLLogin (org.eclipse.persistence.oxm.XMLLogin)29 Project (org.eclipse.persistence.sessions.Project)25 XMLContext (org.eclipse.persistence.oxm.XMLContext)17 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)13 StringReader (java.io.StringReader)11 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)9 DOMPlatform (org.eclipse.persistence.oxm.platform.DOMPlatform)9 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)8 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)8 JAXBContext (jakarta.xml.bind.JAXBContext)7 JAXBException (jakarta.xml.bind.JAXBException)7 Unmarshaller (jakarta.xml.bind.Unmarshaller)7 StreamSource (javax.xml.transform.stream.StreamSource)7 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)7 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)7 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)7 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)7