/** * Figures out the artifact type from the class. * @param artyClass */ private static ArtifactType valueOf(Class<? extends BaseArtifactType> artyClass) { ArtifactType rval = null; for (ArtifactTypeEnum e : ArtifactTypeEnum.values()) { if (e.getTypeClass().equals(artyClass)) { rval = new ArtifactType(e, null); } } return rval; }
/** * Figures out the type from the artifact instance. * @param artifact */ public static ArtifactTypeEnum valueOf(BaseArtifactType artifact) { BaseArtifactEnum apiType = artifact.getArtifactType(); if (apiType != null) { return valueOf(apiType); } ArtifactTypeEnum[] values = values(); for (ArtifactTypeEnum artifactType : values) { if (artifactType.getTypeClass().equals(artifact.getClass())) { return artifactType; } } throw new RuntimeException(Messages.i18n.format("ARTIFACT_TYPE_FROM_CLASS_ERROR", artifact.getClass())); }
/** * Instantiates an S-RAMP artifact of the correct type, and populates the artifactType and the * contentType. * @param artifactType */ public BaseArtifactType newArtifactInstance() { try { BaseArtifactType baseArtifactType = getArtifactType().getTypeClass().newInstance(); baseArtifactType.setArtifactType(getArtifactType().getApiType()); if (DocumentArtifactType.class.isAssignableFrom(baseArtifactType.getClass())) { ((DocumentArtifactType) baseArtifactType).setContentType(getMimeType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedArtifactType) { baseArtifactType.getOtherAttributes().put(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedArtifactType) baseArtifactType).setExtendedType(getExtendedType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { baseArtifactType.getOtherAttributes().put(ArtificerConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedDocument) baseArtifactType).setExtendedType(getExtendedType()); } return baseArtifactType; } catch (Exception e) { throw new RuntimeException(Messages.i18n.format("ARTIFACT_INSTANTIATION_ERROR", getArtifactType().getTypeClass()), e); } }
if (artifactTypeEnum.getTypeClass().equals(artifact.getClass())) { ArtifactType artifactType = new ArtifactType(artifactTypeEnum, null); if (artifactTypeEnum == ArtifactTypeEnum.ExtendedArtifactType || artifactTypeEnum == ArtifactTypeEnum.ExtendedDocument) {