/** * Generates the corresponding MAL Element List from a certain MAL Element * * @param obj The MAL Element * @return The MAL Element List * @throws java.lang.Exception */ public static ElementList element2elementList(Object obj) throws Exception { if (obj == null) { return null; } if (obj instanceof Element) { long l = ((Element) obj).getShortForm(); long ll = (-((l) & 0xFFFFFFL)) & 0xFFFFFFL + (l & 0xFFFFFFFFFF000000L); MALElementFactory eleFact = MALContextFactory.getElementFactoryRegistry().lookupElementFactory(ll); if (eleFact == null) { Logger.getLogger(HelperMisc.class.getName()).log(Level.SEVERE, "The element could not be found in the MAL ElementFactory! The object type is: '" + obj.getClass().getSimpleName() + "'. Maybe the service Helper for this object was not initialized. " + "Try initializing the Service Helper of this object."); } return (ElementList) eleFact.createElement(); } else { return HelperAttributes.generateElementListFromJavaType(obj); } }
final ByteArrayOutputStream bodyBaos = new ByteArrayOutputStream(); final BinaryEncoder be = new BinaryEncoder(bodyBaos); be.encodeLong(ele.getShortForm()); be.encodeNullableElement(ele); this.obj = bodyBaos.toByteArray();
protected void encodeSubElement(final Element e, final Object sf, final MALEncodingContext ctx) throws MALException { if (null == sf) { // dirty check to see if we are trying to decode an abstract Attribute (and not a list of them either) Object[] finalEleShortForms = null; if (null != ctx) { finalEleShortForms = ctx.getOperation().getOperationStage(ctx.getHeader().getInteractionStage()).getLastElementShortForms(); } if ((null != finalEleShortForms) && (Attribute._URI_TYPE_SHORT_FORM == finalEleShortForms.length) && ((((Long) finalEleShortForms[0]) & 0x800000L) == 0)) { enc.encodeNullableOctet(enc.internalEncodeAttributeType(e.getTypeShortForm().byteValue())); } else { enc.encodeAbstractElementType(e.getShortForm(), true); } // now encode the element enc.encodeElement(e); } else { enc.encodeNullableElement(e); } }