Search in sources :

Example 1 with XmlEntityStruct

use of alma.xmlentity.XmlEntityStruct in project ACS by ACS-Community.

the class CastorMarshalMapper method translate.

/**
	 * Converts a Castor generated entity object to the marshalled representation as
	 * an <code>XmlEntityStruct</code>.
	 *  
	 * @see alma.acs.component.dynwrapper.TypeMapper#translate(java.lang.Object, java.lang.Object, java.lang.Class,
	 * alma.acs.component.dynwrapper.ComponentInvocationHandler)
	 */
@SuppressWarnings("unchecked")
public Object translate(Object oldObject, Object newObjectTemplate, Class newObjectClass, ComponentInvocationHandler invHandler) throws DynWrapperException {
    if (oldObject == null) {
        return null;
    }
    EntityT entityMeta;
    try {
        entityMeta = m_entityTFinder.extractEntityT(oldObject);
    } catch (EntityException e) {
        String extractionErrMsg = "failed to extract EntityT object from " + oldObject.getClass().getName();
        throw new DynWrapperException(extractionErrMsg, e);
    }
    if (entityMeta == null) {
        String extractionNullErrMsg = "entity object of type " + oldObject.getClass().getName() + " must have a non-null child assignable to " + EntityT.class.getName() + " to be serialized.";
        throw new DynWrapperException(extractionNullErrMsg);
    }
    XmlEntityStruct entStruct = null;
    // dealt with using a Holder class. Just confused right now...
    if (newObjectTemplate != null) {
        if (!XmlEntityStruct.class.isInstance(newObjectTemplate)) {
            throw new DynWrapperException("invalid template for XmlEntityStruct object");
        }
        entStruct = (XmlEntityStruct) newObjectTemplate;
    } else {
        entStruct = new XmlEntityStruct();
    }
    entStruct.entityId = entityMeta.getEntityId();
    entStruct.entityTypeName = entityMeta.getEntityTypeName();
    entStruct.schemaVersion = (entityMeta.getSchemaVersion() != null ? entityMeta.getSchemaVersion() : "");
    try {
        StringWriter wr = new StringWriter();
        Marshaller marsh = new Marshaller(wr);
        marsh.setValidation(false);
        marsh.marshal(oldObject);
        entStruct.xmlString = wr.toString();
    } catch (Exception e) {
        String msg = "failed to marshal entity object with id='" + entityMeta.getEntityId() + "' using the Castor Marshaller without validation.";
        throw new DynWrapperException(msg);
    }
    if (m_verbose) {
        m_logger.finer("successfully translated from '" + oldObject.getClass().getName() + "' to '" + entStruct.getClass().getName() + "'.");
    }
    return entStruct;
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) StringWriter(java.io.StringWriter) EntityT(alma.entities.commonentity.EntityT) EntityException(alma.acs.entityutil.EntityException) XmlEntityStruct(alma.xmlentity.XmlEntityStruct) EntityException(alma.acs.entityutil.EntityException)

Example 2 with XmlEntityStruct

use of alma.xmlentity.XmlEntityStruct in project ACS by ACS-Community.

the class XmlComponentClient method createSchedBlockXml.

/**
	 * creates schedblock xml. not fancy, always the same ID, but good enough for the test.
	 */
private XmlEntityStruct createSchedBlockXml(boolean breakUnmarshaller) {
    String sbXML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<ns1:SchedBlock xmlns:ns1=\"AlmaTest/SchedBlock\">" + "<ns1:SchedBlockEntity " + "entityIdEncrypted=\"-- id encryption not yet implemented --\" " + "entityId=\"uid://X0000000000000064/X10000001\" entityTypeName=\"SchedBlock\"/> " + "<ns1:SchedBlockControl repeatCount=\"1\" entityPartId=\"X00000008\" />";
    if (breakUnmarshaller) {
        sbXML += "<ns1:ElementTooMany whyIsThis=\"to martially break the unmarshaller\" />";
    }
    sbXML += "</ns1:SchedBlock>";
    XmlEntityStruct entStruct = new XmlEntityStruct();
    entStruct.xmlString = sbXML;
    entStruct.entityId = "uid://X0000000000000064/X10000001";
    entStruct.entityTypeName = "SchedBlock";
    entStruct.schemaVersion = "";
    entStruct.timeStamp = "";
    return entStruct;
}
Also used : XmlEntityStruct(alma.xmlentity.XmlEntityStruct)

Example 3 with XmlEntityStruct

use of alma.xmlentity.XmlEntityStruct in project ACS by ACS-Community.

the class DynamicProxyFactoryTest method testCallXmlInOutMethod.

public void testCallXmlInOutMethod() throws DynWrapperException {
    XmlComponentOperations serverProxy = createServerProxy();
    assertNotNull(serverProxy);
    XmlEntityStruct entStructObsProp = serverProxy.createObsProposal();
    XmlEntityStructHolder xesh = new XmlEntityStructHolder();
    // send invalid xml
    entStructObsProp.xmlString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<ns1:ObsProposal xmlns:ns1=\"AlmaTest/ObsProposal\">" + "	<ns1:ObsProposalEntity entityIdEncrypted=\"ljasd;ljfa;lsfd\"" + "		entityId=\"uid://X0000000000000000/X00000001\" entityTypeName=\"ObsProposal\"/>" + "	<ns1:ContactPerson>Otis P. Driftwood.</ns1:ContactPerson>" + "</ns1:ObsProposal>";
    serverProxy.xmlInOutMethod(entStructObsProp, xesh);
    assertNotNull(xesh.value);
    String xml = xesh.value.xmlString;
    assertNotNull(xml);
    System.out.println("received out-param SchedBlock as XML: " + xml);
}
Also used : XmlEntityStructHolder(alma.xmlentity.XmlEntityStructHolder) XmlComponentOperations(alma.demo.XmlComponentOperations) XmlEntityStruct(alma.xmlentity.XmlEntityStruct)

Example 4 with XmlEntityStruct

use of alma.xmlentity.XmlEntityStruct in project ACS by ACS-Community.

the class DynamicProxyFactoryTest method testInvalidXml.

public void testInvalidXml() throws DynWrapperException {
    XmlComponentOperations serverProxy = createServerProxy();
    assertNotNull(serverProxy);
    XmlEntityStruct entStructObsProp = serverProxy.createObsProposal();
    XmlEntityStructHolder xesh = new XmlEntityStructHolder();
    // send invalid xml
    entStructObsProp.xmlString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + //			"<ns1:ObsProposal xmlns:ns1=\"AlmaTest/ObsProposal\">" +
    "	<ns1:ObsProposalEntity entityIdEncrypted=\"ljasd;ljfa;lsfd\"" + "		entityId=\"uid://X0000000000000000/X00000001\" entityTypeName=\"ObsProposal\"/>" + "	<ns1:PerformanceGoals>peak performance enduring a 24-7-365 schedule.</ns1:PerformanceGoals>" + "</ns1:ObsProposal>";
    try {
        serverProxy.xmlInOutMethod(entStructObsProp, xesh);
        fail("invalid XML should have caused an exception");
    } catch (UndeclaredThrowableException e) {
        Throwable cause = e.getCause();
        assertTrue(cause instanceof DynWrapperException);
        Throwable cause2 = cause.getCause();
        assertTrue(cause2 instanceof MarshalException);
        assertTrue(((MarshalException) cause2).getCause() instanceof org.xml.sax.SAXException);
    }
}
Also used : XmlEntityStructHolder(alma.xmlentity.XmlEntityStructHolder) MarshalException(org.exolab.castor.xml.MarshalException) XmlComponentOperations(alma.demo.XmlComponentOperations) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) XmlEntityStruct(alma.xmlentity.XmlEntityStruct)

Example 5 with XmlEntityStruct

use of alma.xmlentity.XmlEntityStruct in project ACS by ACS-Community.

the class DynamicProxyFactoryTest method testEmptyXml.

/**
	 * Sends an empty (one blank) XML representation of an ObsProposal to the method
	 * <code>xmlInOutMethod</code>. Expects to not get an exception.
	 * @throws DynWrapperException
	 */
public void testEmptyXml() throws DynWrapperException {
    XmlComponentOperations serverProxy = createServerProxy();
    assertNotNull(serverProxy);
    // just to have a valid struct
    XmlEntityStruct entStructObsProp = serverProxy.createObsProposal();
    XmlEntityStructHolder xesh = new XmlEntityStructHolder();
    // send empty xml
    entStructObsProp.xmlString = " ";
    serverProxy.xmlInOutMethod(entStructObsProp, xesh);
    // ObsProposal in-param and thus SchedBlock out-param are null, 
    // so that the out-XmlEntityStruct struct must be empty.
    assertEquals("", xesh.value.xmlString);
}
Also used : XmlEntityStructHolder(alma.xmlentity.XmlEntityStructHolder) XmlComponentOperations(alma.demo.XmlComponentOperations) XmlEntityStruct(alma.xmlentity.XmlEntityStruct)

Aggregations

XmlEntityStruct (alma.xmlentity.XmlEntityStruct)13 XmlComponentOperations (alma.demo.XmlComponentOperations)6 XmlEntityStructHolder (alma.xmlentity.XmlEntityStructHolder)3 XmlOffshoot (alma.demo.XmlOffshoot)2 EntityT (alma.entities.commonentity.EntityT)2 CharArrayReader (java.io.CharArrayReader)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 Document (org.w3c.dom.Document)2 InputSource (org.xml.sax.InputSource)2 EntityException (alma.acs.entityutil.EntityException)1 ComponentWithXmlOffshoot (alma.demo.ComponentWithXmlOffshoot)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 MarshalException (org.exolab.castor.xml.MarshalException)1 Marshaller (org.exolab.castor.xml.Marshaller)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1