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>
* <?xml version="1.0" encoding="ISO-8859-1"?><br>
* <ns1:MyXmlConfigData someAttribute="great attribute here!" xmlns:ns1="AlmaTest/MyXmlConfigData"><br>
* <ns1:MyXmlConfigDataEntity<br>
* entityIdEncrypted="-- id encryption not yet implemented --"<br>
* entityId="uid://X96fe17ec9c9de1be/X00000000" entityTypeName="MyXmlConfigData"/><br>
* <ns1:myStringData>string child elements looks like a string attribute
* when using binding classes...</ns1:myStringData><br>
* <ns1:childData><br>
* <ns1:someNestedData/><br>
* <ns1:someOtherData>one more silly string</ns1:someOtherData><br>
* </ns1:childData><br>
* </ns1:MyXmlConfigData><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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations