/** * Convenience method to help set a custom s-ramp property on the given artifact. * @param artifact * @param propName * @param propValue */ public static void setCustomProperty(BaseArtifactType artifact, String propName, String propValue) { Property prop = null; List<Property> properties = artifact.getProperty(); for (Property property : properties) { if (property.getPropertyName().equals(propName)) { prop = property; break; } } if (prop == null) { prop = new Property(); prop.setPropertyName(propName); properties.add(prop); } prop.setPropertyValue(propValue); } /**
/** * Gets all of the custom properties from the artifact and returns them as a map. * @param artifact */ private static Map<String, String> getArtifactProperties(BaseArtifactType artifact) { Map<String, String> props = new HashMap<String, String>(); for (org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Property property : artifact.getProperty()) props.put(property.getPropertyName(), property.getPropertyValue()); return props; }
String propName = propQName.substring(srampPropsPrefixLen); String propValue = property.getValue().getString(); org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Property srampProp = new org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Property(); srampProp.setPropertyName(propName); srampProp.setPropertyValue(propValue); artifact.getProperty().add(srampProp);
/** * Gets all the custom property names for the artifact. * @param artifact */ private static Collection<String> getCustomPropertyNames(BaseArtifactType artifact) { Set<String> props = new HashSet<String>(); for (Property prop : artifact.getProperty()) { props.add(prop.getPropertyName()); } return props; }
/** * Create an instance of {@link Property } * */ public Property createProperty() { return new Property(); }
xsdDocument.getRelationship().add(relationship); Property property = new Property(); property.setPropertyName("myPropertyName"); property.setPropertyValue("myPropertyValue"); xsdDocument.getProperty().add(property);
/** * Convenience method to help remove a custom s-ramp property on the given artifact. * @param artifact * @param propName */ public static void unsetCustomProperty(BaseArtifactType artifact, String propName) { Iterator<Property> iter = artifact.getProperty().iterator(); while (iter.hasNext()) { Property property = iter.next(); if (property.getPropertyName().equals(propName)) { iter.remove(); break; } } }
/** * Create an instance of {@link Property } * */ public Property createProperty() { return new Property(); }
/** * Convenience method to help set a custom s-ramp property on the given artifact. * @param artifact * @param propName * @param propValue */ public static void setCustomProperty(BaseArtifactType artifact, String propName, String propValue) { Property prop = null; List<Property> properties = artifact.getProperty(); for (Property property : properties) { if (property.getPropertyName().equals(propName)) { prop = property; break; } } if (prop == null) { prop = new Property(); prop.setPropertyName(propName); properties.add(prop); } if (propValue == null) { properties.remove(prop); } else { prop.setPropertyValue(propValue); } }
/** * Gets the value of one of the s-ramp custom properties. * @param artifact the s-ramp artifact * @param propName the name of the custom property * @return the custom property value or null if not found */ public static String getCustomProperty(BaseArtifactType artifact, String propName) { String rval = null; List<Property> properties = artifact.getProperty(); for (Property prop : properties) { if (propName.equals(prop.getPropertyName())) { rval = prop.getPropertyValue(); break; } } return rval; }
Property srampProp = new Property(); srampProp.setPropertyName(artificerProperty.getKey()); srampProp.setPropertyValue(artificerProperty.getValue()); srampArtifact.getProperty().add(srampProp);
List<String> relationshipNames = new ArrayList<String>(); for (Property property : artifact.getProperty()) { propertyNames.add(property.getPropertyName());
Property prop1 = new Property(); prop1.setPropertyName("prop1"); //$NON-NLS-1$ prop1.setPropertyValue("propval1"); //$NON-NLS-1$ artifact.getProperty().add(prop1); Property prop2 = new Property(); prop2.setPropertyName("prop2"); //$NON-NLS-1$ prop2.setPropertyValue("propval2"); //$NON-NLS-1$ artifact.getProperty().add(prop2); persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument()); String p1 = artifact.getProperty().get(0).getPropertyName() + "=" + artifact.getProperty().get(0).getPropertyValue(); //$NON-NLS-1$ String p2 = artifact.getProperty().get(1).getPropertyName() + "=" + artifact.getProperty().get(1).getPropertyValue(); //$NON-NLS-1$ Set<String> ps = new HashSet<String>(); ps.add(p1); prop1 = new Property(); prop1.setPropertyName("prop1"); //$NON-NLS-1$ prop1.setPropertyValue("propval1-updated"); //$NON-NLS-1$ artifact.getProperty().add(prop1); Property prop3 = new Property(); prop3.setPropertyName("prop3"); //$NON-NLS-1$ prop3.setPropertyValue("propval3"); //$NON-NLS-1$ artifact.getProperty().add(prop3); persistenceManager.updateArtifact(artifact, ArtifactType.XsdDocument()); p1 = artifact.getProperty().get(0).getPropertyName() + "=" + artifact.getProperty().get(0).getPropertyValue(); //$NON-NLS-1$ p2 = artifact.getProperty().get(1).getPropertyName() + "=" + artifact.getProperty().get(1).getPropertyValue(); //$NON-NLS-1$ ps.clear(); ps.add(p1);
/** * Gets the value of one of the s-ramp custom properties. * @param artifact the s-ramp artifact * @param propName the name of the custom property * @return the custom property value or null if not found */ public static String getCustomProperty(BaseArtifactType artifact, String propName) { String rval = null; List<Property> properties = artifact.getProperty(); for (Property prop : properties) { if (propName.equals(prop.getPropertyName())) { rval = prop.getPropertyValue(); break; } } return rval; }
Property prop1 = new Property(); prop1.setPropertyName("prop1"); //$NON-NLS-1$ prop1.setPropertyValue("propval1"); //$NON-NLS-1$ artifact.getProperty().add(prop1); Property prop2 = new Property(); prop2.setPropertyName("prop2"); //$NON-NLS-1$ prop2.setPropertyValue("propval2"); //$NON-NLS-1$ artifact.getProperty().add(prop2); persistenceManager.updateArtifact(artifact, ArtifactType.Document()); String p1 = artifact.getProperty().get(0).getPropertyName() + "=" + artifact.getProperty().get(0).getPropertyValue(); //$NON-NLS-1$ String p2 = artifact.getProperty().get(1).getPropertyName() + "=" + artifact.getProperty().get(1).getPropertyValue(); //$NON-NLS-1$ Set<String> ps = new HashSet<String>(); ps.add(p1); prop1 = new Property(); prop1.setPropertyName("prop1"); //$NON-NLS-1$ prop1.setPropertyValue("propval1-updated"); //$NON-NLS-1$ artifact.getProperty().add(prop1); Property prop3 = new Property(); prop3.setPropertyName("prop3"); //$NON-NLS-1$ prop3.setPropertyValue("propval3"); //$NON-NLS-1$ artifact.getProperty().add(prop3); persistenceManager.updateArtifact(artifact, ArtifactType.Document()); p1 = artifact.getProperty().get(0).getPropertyName() + "=" + artifact.getProperty().get(0).getPropertyValue(); //$NON-NLS-1$ p2 = artifact.getProperty().get(1).getPropertyName() + "=" + artifact.getProperty().get(1).getPropertyValue(); //$NON-NLS-1$ ps.clear(); ps.add(p1);
/** * Gets all properties with names that begin with the given prefix. This is useful * if the artifact has a number of custom properties that all start with a common * domain specific prefix. * * @param artifact the s-ramp artifact * @param prefix the prefix of the properties searched * @return the map of custom properties that start by the prefix */ public static Map<String, String> getCustomPropertiesByPrefix(BaseArtifactType artifact, String prefix) { Map<String, String> result = new HashMap<String, String>(); List<Property> properties = artifact.getProperty(); for (Property prop : properties) { if (prop.getPropertyName().startsWith(prefix)) { result.put(prop.getPropertyName(), prop.getPropertyValue()); } } return result; } }
/** * Updates the custom s-ramp properties. * @param artifact * @throws Exception */ private void updateArtifactProperties(BaseArtifactType artifact) throws Exception { for (org.oasis_open.docs.s_ramp.ns.s_ramp_v1.Property property : artifact.getProperty()) { createProperty(property.getPropertyName(), property.getPropertyValue(), true); } }
/** * Creates the artifact that should be included in the returned Entry. * @throws IllegalAccessException * @throws InstantiationException */ protected BaseArtifactType createIncludedArtifact(BaseArtifactType artifact) throws InstantiationException, IllegalAccessException { if (includeArtifact()) { BaseArtifactType includedArtifact = artifact.getClass().newInstance(); List<Property> properties = artifact.getProperty(); for (Property prop : properties) { if (this.propertyNames.contains(prop.getPropertyName())) { SrampModelUtils.setCustomProperty(includedArtifact, prop.getPropertyName(), prop.getPropertyValue()); } } return includedArtifact; } else { return null; } }
private void processProperties( final BaseArtifactType artifact, final Element element, final XPath xpath ) throws Exception { final NodeList props = (NodeList)query(xpath, element, Utils.getElementQueryString(Propertied.XmlId.PROPERTY), XPathConstants.NODESET); if (props.getLength() != 0) { LOGGER.debug("VdbManifestDeriver:processing '{}' properties", props.getLength()); //$NON-NLS-1$ for (int propIndex = 0, numProps = props.getLength(); propIndex < numProps; ++propIndex) { final Element prop = (Element)props.item(propIndex); final String name = prop.getAttribute(Propertied.XmlId.NAME); final String value = prop.getAttribute(Propertied.XmlId.VALUE); SrampModelUtils.setCustomProperty(artifact, name, value); } if (LOGGER.isDebugEnabled()) { for (final Property prop : artifact.getProperty()) { LOGGER.debug("VdbManifestDeriver:artifact '{}' has property '{}' with value '{}'", //$NON-NLS-1$ new Object[] {artifact.getName(), prop.getPropertyName(), prop.getPropertyValue()}); } } } }