Search in sources :

Example 1 with EntityT

use of alma.entities.commonentity.EntityT in project ACS by ACS-Community.

the class Mount6Impl method createMyXmlConfigData.

/**
	 * Creates and returns binding classes which the container will automatically serialize to the following XML
	 * string which can be seen for example in the objexp client. 
	 * 	<verbatim>
	 * 	  &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;<br>
	 * 	  &lt;ns1:MyXmlConfigData someAttribute=&quot;great attribute here!&quot; xmlns:ns1=&quot;AlmaTest/MyXmlConfigData&quot;&gt;<br>
	 * 	  &lt;ns1:MyXmlConfigDataEntity<br>
	 * 	  entityIdEncrypted=&quot;-- id encryption not yet implemented --&quot;<br>
	 * 	  entityId=&quot;uid://X96fe17ec9c9de1be/X00000000&quot; entityTypeName=&quot;MyXmlConfigData&quot;/&gt;<br>
	 * 	  &lt;ns1:myStringData&gt;string child elements looks like a string attribute 
	 * 	  when using binding classes...&lt;/ns1:myStringData&gt;<br>
	 * 	  &lt;ns1:childData&gt;<br>
	 * 	  &lt;ns1:someNestedData/&gt;<br>
	 * 	  &lt;ns1:someOtherData&gt;one more silly string&lt;/ns1:someOtherData&gt;<br>
	 * 	  &lt;/ns1:childData&gt;<br>
	 * 	  &lt;/ns1:MyXmlConfigData&gt;<br>
	 * 	</verbatim>
	 */
public MyXmlConfigData createMyXmlConfigData() {
    MyXmlConfigData xmlData = new MyXmlConfigData();
    try {
        EntityT entity = new EntityT();
        // the next line could be omitted if we had defined a subtype of EntityT in the XML schema, 
        // as it is done in the schemas of module acstestentities
        entity.setEntityTypeName("MyXmlConfigData");
        m_containerServices.assignUniqueEntityId(entity);
        xmlData.setMyXmlConfigDataEntity(entity);
        // note how we use the type-safe methods: "SomeAttribute" and "MyStringData" are names derived from the schema
        xmlData.setSomeAttribute("great attribute here!");
        xmlData.setMyStringData("string child elements looks like a string attribute when using binding classes...");
        MyNestedDataT childData = new MyNestedDataT();
        childData.setSomeOtherData("one more silly string");
        xmlData.setChildData(childData);
        // of the possible 0..7 (grand)child elements, we just add 1
        MyNestedDataT grandchildData = new MyNestedDataT();
        childData.addSomeNestedData(grandchildData);
    } catch (AcsJContainerServicesEx e) {
        m_logger.log(Level.SEVERE, "failed to create ObsProposal. ", e);
    }
    return xmlData;
}
Also used : MyXmlConfigData(alma.acscourse.xmlbinding.myxmlconfigdata.MyXmlConfigData) MyNestedDataT(alma.acscourse.xmlbinding.myxmlconfigdata.MyNestedDataT) EntityT(alma.entities.commonentity.EntityT) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Example 2 with EntityT

use of alma.entities.commonentity.EntityT 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 3 with EntityT

use of alma.entities.commonentity.EntityT in project ACS by ACS-Community.

the class XmlComponentClient method testCreateObsProposal.

/**
	 * Makes sure the obs proposal exists and checks its entity id.
	 */
public void testCreateObsProposal() {
    ObsProposal obsProp = m_xmlCompJ.createObsProposal();
    assertNotNull(obsProp);
    EntityT ent = obsProp.getObsProposalEntity();
    assertNotNull(ent);
    String id = ent.getEntityId();
    assertNotNull(id);
    System.out.println("received ObsProposal with id " + id);
}
Also used : EntityT(alma.entities.commonentity.EntityT) ObsProposal(alma.xmljbind.test.obsproposal.ObsProposal)

Example 4 with EntityT

use of alma.entities.commonentity.EntityT in project ACS by ACS-Community.

the class EntitySerializerTest method testSerializeNull.

public void testSerializeNull() throws EntityException {
    XmlEntityStruct entStruct = m_serializer.serializeEntity(null);
    assertNull(entStruct);
    entStruct = m_serializer.serializeEntity(null, new EntityT());
    assertNull(entStruct);
    entStruct = m_serializer.serializeEntity(null, null);
    assertNull(entStruct);
}
Also used : EntityT(alma.entities.commonentity.EntityT) XmlEntityStruct(alma.xmlentity.XmlEntityStruct)

Example 5 with EntityT

use of alma.entities.commonentity.EntityT in project ACS by ACS-Community.

the class EntityTFinder method extractEntityT.

/**
	 * Extracts the <code>EntityT</code> child of <code>entityObj</code>.
	 * Implementation uses {@link #getEntityTMethod}.
	 * 
	 * @param entityObj  the entity object, e.g. an <code>alma.xmljbind.test.schedblock.SchedBlock</code>.
	 * @return  the administrational data of type EntityT, possibly <code>null</code>.
	 * @throws EntityException  if there is no method returning an <code>EntityT</code> assignable
	 * 							object, or if the invocation of that method fails. 
	 */
public EntityT extractEntityT(Object entityObj) throws EntityException {
    Method entityTMethod = getEntityTMethod(entityObj.getClass());
    EntityT entityT = null;
    try {
        entityT = (EntityT) entityTMethod.invoke(entityObj, (Object[]) null);
    } catch (Exception e) {
        String msg = "failed to retrieve EntityT child object from binding class '" + entityObj.getClass() + ".";
        throw new EntityException(msg);
    }
    if (entityT != null) {
        if (m_verbose) {
            m_logger.finer("EntityT with id='" + entityT.getEntityId() + "' extracted from object of Class '" + entityObj.getClass().getName() + "'.");
        }
    } else {
        m_logger.finer("Method " + entityObj.getClass().getName() + "#" + entityTMethod.getName() + " returned null as the " + entityTMethod.getReturnType().getName() + " object");
    }
    return entityT;
}
Also used : EntityT(alma.entities.commonentity.EntityT) Method(java.lang.reflect.Method)

Aggregations

EntityT (alma.entities.commonentity.EntityT)8 XmlEntityStruct (alma.xmlentity.XmlEntityStruct)2 ObsProposal (alma.xmljbind.test.obsproposal.ObsProposal)2 AcsJIdentifierUnavailableEx (alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx)1 AcsJUidAlreadyExistsEx (alma.ArchiveIdentifierError.wrappers.AcsJUidAlreadyExistsEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 EntityException (alma.acs.entityutil.EntityException)1 MyNestedDataT (alma.acscourse.xmlbinding.myxmlconfigdata.MyNestedDataT)1 MyXmlConfigData (alma.acscourse.xmlbinding.myxmlconfigdata.MyXmlConfigData)1 SchedBlockHolder (alma.demo.SchedBlockHolder)1 SchedBlock (alma.xmljbind.test.schedblock.SchedBlock)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 Marshaller (org.exolab.castor.xml.Marshaller)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1