/** * Creates the artifact instance based on the type of the discovered artifact. * @param discoveredArtifact */ protected BaseArtifactType createArtifact(DiscoveredArtifact discoveredArtifact) { BaseArtifactType metaData = null; String archivePath = discoveredArtifact.getArchivePath().toLowerCase(); if (archivePath.endsWith(".xml")) { //$NON-NLS-1$ metaData = new XmlDocument(); metaData.setArtifactType(BaseArtifactEnum.XML_DOCUMENT); } else if (archivePath.endsWith(".wsdl")) { //$NON-NLS-1$ metaData = new WsdlDocument(); metaData.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT); } else if (archivePath.endsWith(".xsd")) { //$NON-NLS-1$ metaData = new XsdDocument(); metaData.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT); } else if (archivePath.endsWith(".wspolicy")) { //$NON-NLS-1$ metaData = new XsdDocument(); metaData.setArtifactType(BaseArtifactEnum.POLICY_DOCUMENT); } else { metaData = new Document(); metaData.setArtifactType(BaseArtifactEnum.DOCUMENT); } return metaData; }
/** * Common visit method for all artifacts. * @param artifact */ protected void visitBase(BaseArtifactType artifact) { ArtifactType artifactType = ArtifactType.valueOf(artifact); BaseArtifactEnum apiType = artifactType.getArtifactType().getApiType(); artifact.setArtifactType(apiType); // Subclasses can do common visit logic here }
/** * Called to unwrap the S-RAMP artifact from its wrapper. * @param artifactWrapper the S-RAMP artifact wrapper * @return the specific artifact based on type */ public BaseArtifactType unwrap(Artifact artifactWrapper) { try { Method method = Artifact.class.getMethod("get" + getArtifactType().getType()); BaseArtifactType artifact = (BaseArtifactType) method.invoke(artifactWrapper); artifact.setArtifactType(this.getArtifactType().getApiType()); return artifact; } catch (Exception e) { throw new RuntimeException(Messages.i18n.format("ARTIFACT_UNWRAP_ERROR", getArtifactType().getType()), e); } }
/** * Called to unwrap the S-RAMP artifact from its wrapper. * @param artifactWrapper the S-RAMP artifact wrapper * @return the specific artifact based on type */ public BaseArtifactType unwrap(Artifact artifactWrapper) { try { Method method = Artifact.class.getMethod("get" + getArtifactType().getType()); //$NON-NLS-1$ BaseArtifactType artifact = (BaseArtifactType) method.invoke(artifactWrapper); artifact.setArtifactType(this.getArtifactType().getApiType()); return artifact; } catch (Exception e) { throw new RuntimeException(Messages.i18n.format("ARTIFACT_UNWRAP_ERROR", getArtifactType().getType()), e); //$NON-NLS-1$ } }
@Override public Collection<BaseArtifactType> findArtifacts(String model, String type, Map<String, String> criteria) { BaseArtifactType doc = new Document(); doc.setArtifactType(BaseArtifactEnum.DOCUMENT); doc.setName("Mock Artifact"); //$NON-NLS-1$ doc.setUuid(UUID.randomUUID().toString()); return Collections.singletonList(doc); } };
/** * 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); } }
/** * 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(SrampConstants.SRAMP_CONTENT_TYPE_QNAME, getMimeType()); ((ExtendedArtifactType) baseArtifactType).setExtendedType(getExtendedType()); } if (getArtifactType() == ArtifactTypeEnum.ExtendedDocument) { baseArtifactType.getOtherAttributes().put(SrampConstants.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); //$NON-NLS-1$ } }
ArtifactType artifactType = ArtifactType.valueOf(artifact); BaseArtifactEnum apiType = artifactType.getArtifactType().getApiType(); artifact.setArtifactType(apiType);
srampArtifact.setArtifactType(artifactType.getArtifactType().getApiType()); srampArtifact.setCreatedBy(artificerArtifact.getCreatedBy().getUsername()); XMLGregorianCalendar createdTimestamp = HibernateEntityFactory.calendar(artificerArtifact.getCreatedBy().getLastActionTime());