Search in sources :

Example 6 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)

Example 7 with XmlEntityStruct

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

the class ComponentWithXmlOffshootClientTest method testOffshoot.

public void testOffshoot() throws Exception {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    XmlOffshoot shoot = componentWithXmlOffshoot.getOffshoot();
    assertNotNull(shoot.getObsProposal());
    assertNotNull(shoot.getSchedBlock());
    // these values are hardcoded in the m_offshoot implementation
    XmlEntityStruct struct = shoot.getObsProposal();
    Document d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("rtobar", d.getElementsByTagName("PI").item(0).getTextContent());
    assertEquals("2010.0045.34S", d.getElementsByTagName("code").item(0).getTextContent());
    assertEquals("just for fun", d.getElementsByTagName("ScientificJustification").item(0).getTextContent());
    struct = shoot.getSchedBlock();
    d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("holography", d.getElementsByTagName("ns2:name").item(0).getTextContent());
    assertEquals("DONE", d.getElementsByTagName("ns1:status").item(0).getTextContent());
    assertEquals("true", d.getElementsByTagName("StandardMode").item(0).getTextContent());
    // just to check the setters
    shoot.setObsProposal(new XmlEntityStruct());
    shoot.setSchedBlock(new XmlEntityStruct());
    // deactivate the m_offshoot on the server-side
    componentWithXmlOffshoot.deactivateOffshoot();
    try {
        shoot.getObsProposal();
        fail("m_offshoot should be deactivated, I shouldn't be able to use it");
    } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
    }
}
Also used : InputSource(org.xml.sax.InputSource) CharArrayReader(java.io.CharArrayReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlEntityStruct(alma.xmlentity.XmlEntityStruct) ComponentWithXmlOffshoot(alma.demo.ComponentWithXmlOffshoot) XmlOffshoot(alma.demo.XmlOffshoot) Document(org.w3c.dom.Document)

Example 8 with XmlEntityStruct

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

the class XmlComponentClientTest method testOffshoot.

public void testOffshoot() throws Exception {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    XmlOffshoot shoot = xmlComponent.getOffshoot();
    assertNotNull(shoot.getObsProposal());
    assertNotNull(shoot.getSchedBlock());
    // these values are hardcoded in the m_offshoot implementation
    XmlEntityStruct struct = shoot.getObsProposal();
    Document d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("rtobar", d.getElementsByTagName("PI").item(0).getTextContent());
    assertEquals("2010.0045.34S", d.getElementsByTagName("code").item(0).getTextContent());
    assertEquals("just for fun", d.getElementsByTagName("ScientificJustification").item(0).getTextContent());
    struct = shoot.getSchedBlock();
    d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("holography", d.getElementsByTagName("ns2:name").item(0).getTextContent());
    assertEquals("DONE", d.getElementsByTagName("ns1:status").item(0).getTextContent());
    assertEquals("true", d.getElementsByTagName("StandardMode").item(0).getTextContent());
    // just to check the setters
    shoot.setObsProposal(new XmlEntityStruct());
    shoot.setSchedBlock(new XmlEntityStruct());
    // deactivate the m_offshoot on the server-side
    xmlComponent.deactivateOffshoot();
    try {
        shoot.getObsProposal();
        fail("m_offshoot should be deactivated, I shouldn't be able to use it");
    } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
    }
}
Also used : InputSource(org.xml.sax.InputSource) CharArrayReader(java.io.CharArrayReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlEntityStruct(alma.xmlentity.XmlEntityStruct) XmlOffshoot(alma.demo.XmlOffshoot) Document(org.w3c.dom.Document)

Example 9 with XmlEntityStruct

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

the class CastorUnmarshalMapper method translate.

/**
	 * Translates an <code>XmlEntityStruct</code> to a Castor binding object graph.
	 * <p>
	 * This will only happen for <code>in</code>-parameters (server-side) or return values (client-side), 
	 * since xml entities as <code>out</code> or <code>inout</code>-parameters will be mapped to 
	 * <code>XmlEntityStructHolder</code>s instead of <code>XmlEntityStruct</code>s.
	 * Therefore preserving object identity (parameter <code>newObjectTemplate</code>) is not an issue.
	 *<p>
	 * Returns null if the <code>XmlEntityStruct</code> or the contained XML is null, or if the XML string
	 * is empty or whitespace only. Throws an exception if the XML is syntactically invalid. 
	 *
	 * @see alma.acs.component.dynwrapper.TypeMapper#translate(java.lang.Object, java.lang.Object, java.lang.Class, 
	 * 		alma.acs.component.dynwrapper.ComponentInvocationHandler)
	 */
public <T> Object translate(Object oldObject, T newObjectTemplate, Class<T> newObjectClass, ComponentInvocationHandler invHandler) throws DynWrapperException {
    XmlEntityStruct entStruct = (XmlEntityStruct) oldObject;
    if (entStruct == null || entStruct.xmlString == null || entStruct.xmlString.trim().length() == 0) {
        return null;
    }
    // todo (for support of entity version conversions) 
    // check entStruct.schemaVersion and use a previous version of newObjectClass if required,
    // e.g. the respective class from a different Java package that denotes the vintage version     
    Unmarshaller unmarsh = new Unmarshaller(newObjectClass);
    unmarsh.setValidation(false);
    unmarsh.setWhitespacePreserve(true);
    //		unmarsh.setIgnoreExtraAttributes(true);
    //		unmarsh.setIgnoreExtraElements(true);
    Object entity;
    try {
        entity = unmarsh.unmarshal(new StringReader(entStruct.xmlString));
    } catch (Exception ex) {
        String errorMsg = "failed to unmarshal entity object of type '" + entStruct.entityTypeName + "' using the Castor framework. ";
        if (ex.getMessage().trim().startsWith("unable to find FieldDescriptor for")) {
            errorMsg += "This is likely a versioning problem, where the XML document contains data types " + "which are no longer allowed by the current XML schema, " + "and are therefore unknown to the generated Castor binding classes. ";
        }
        String xmlMsg = null;
        if (entStruct.xmlString.length() <= 300) {
            xmlMsg = "XML string=\n" + entStruct.xmlString;
        } else {
            xmlMsg = "XML string (first 300 chars) =\n" + entStruct.xmlString.substring(0, 300) + "***TRUNCATED|";
        }
        throw new DynWrapperException(errorMsg + xmlMsg, ex);
    }
    return entity;
}
Also used : StringReader(java.io.StringReader) XmlEntityStruct(alma.xmlentity.XmlEntityStruct) Unmarshaller(org.exolab.castor.xml.Unmarshaller)

Example 10 with XmlEntityStruct

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

the class EntitySerializer method serializeEntity.

/**
	 * Marshals an entity object to the CORBA struct used for transport.
	 * 
	 * @param entityObject  the entity object as a binding class, currently generated by castor.
	 * @param entityMeta  usually subtype of <code>EntityT</code>. 
	 * @return  the struct that contains the stringified xml and some other data;
	 * 			null if <code>entityObject</code> is null.
	 */
public XmlEntityStruct serializeEntity(Object entityObject, EntityT entityMeta) throws EntityException {
    if (entityObject == null) {
        return null;
    }
    if (entityMeta == null) {
        throw new EntityException("Entity administrational data of type EntityT must not be null. " + "(object of type " + entityObject.getClass().getName() + ")");
    }
    XmlEntityStruct entStruct = m_esf.createXmlEntityStruct();
    try {
        entStruct.entityId = entityMeta.getEntityId();
        entStruct.entityTypeName = entityMeta.getEntityTypeName();
        entStruct.schemaVersion = (entityMeta.getSchemaVersion() != null ? entityMeta.getSchemaVersion() : "");
        entStruct.timeStamp = (entityMeta.getTimestamp() != null ? entityMeta.getTimestamp() : "");
        entStruct.xmlString = serializeEntityPart(entityObject);
    } catch (Exception e) {
        throw new EntityException(e);
    }
    return entStruct;
}
Also used : XmlEntityStruct(alma.xmlentity.XmlEntityStruct) IOException(java.io.IOException)

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