/** * Converting {@link SegmentGroup} to {@link EClass} * * @param grp * @return */ public static EClass segmentGroupToEClass(SegmentGroup grp) { EClass clazz = EcoreFactory.eINSTANCE.createEClass(); clazz.setName(toJavaName(grp.getXmltag(), true)); addMappingInformation(clazz, grp); return clazz; }
/** * * Process the {@link org.milyn.edisax.model.internal.SegmentGroup} in List and insert info into the {@link org.milyn.ejc.ClassModel}. * @param segmentGroup the {@link org.milyn.edisax.model.internal.SegmentGroup} to process. * @param parent the JClass 'owning' the {@link org.milyn.edisax.model.internal.SegmentGroup}. * @throws IllegalNameException when name found in a xmltag-attribute is a java keyword. */ private BindingConfig processSegmentGroup(SegmentGroup segmentGroup, BindingConfig parent) throws IllegalNameException { LOG.debug("Parsing SegmentGroup " + segmentGroup.getXmltag()); if(segmentGroup.getJavaName() == null) { throw new EJCException("The <segmentGroup> element can optionally omit the 'xmltag' attribute. However, this attribute must be present for EJC to work properly. It is omitted from one of the <segmentGroup> elements in this configuration."); } pushNode(segmentGroup); BindingConfig segGroupBinding = createChildAndConnectWithParent(parent, segmentGroup, segmentGroup.getMaxOccurs(), null); if (segmentGroup instanceof Segment) { Segment segment = (Segment) segmentGroup; processFields(segment.getFields(), segGroupBinding); } processSegmentGroups(segmentGroup.getSegments(), segGroupBinding); popNode(); return segGroupBinding; }
/** * Convert {@link SegmentGroup} into {@link EReference} to the given * {@link EClass} * * @param grp * @param refClass * @return */ public static EReference segmentGroupToEReference(SegmentGroup grp, EClass refClass) { EReference reference = EcoreFactory.eINSTANCE.createEReference(); reference.setContainment(true); reference.setName(toJavaName(grp.getXmltag(), false)); reference.setEType(refClass); reference.setLowerBound(grp.getMinOccurs()); reference.setUpperBound(grp.getMaxOccurs()); addMappingInformation(reference, grp); annotate(reference, "minOccurs", String.valueOf(grp.getMinOccurs())); annotate(reference, "maxOccurs", String.valueOf(grp.getMaxOccurs())); annotate(reference, SmooksMetadata.ANNOTATION_TYPE_KEY, SmooksMetadata.SEGMENT_GROUP_TYPE); annotate(reference, SmooksMetadata.SEGCODE, grp.getSegcode()); return reference; }