/** * 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; }
/** * 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; } } }
/** * 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; }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * 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()}); } } } }
/** * 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); } }
/** * 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); } }
/** * 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); } /**
prop.getPropertyName(), prop.getPropertyValue());
prop.getPropertyName(), prop.getPropertyValue());
List<String> relationshipNames = new ArrayList<String>(); for (Property property : artifact.getProperty()) { propertyNames.add(property.getPropertyName());
prop.getPropertyName(), prop.getPropertyValue()); prop.getPropertyName(), prop.getPropertyValue());
/** * Test method for {@link org.overlord.sramp.integration.switchyard.deriver.SwitchYardXmlDeriver#derive(java.util.Collection, org.s_ramp.xmlns._2010.s_ramp.BaseArtifactType, org.w3c.dom.Element, javax.xml.xpath.XPath)}. * @throws IOException */ @Test public void testJavaDeriver() throws IOException { MavenPomDeriver deriver = new MavenPomDeriver(); ExtendedDocument artifact = new ExtendedDocument(); artifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE); artifact.setName("pom.xml"); //$NON-NLS-1$ InputStream is = getClass().getResourceAsStream("pom.xml"); //$NON-NLS-1$ // Derive @SuppressWarnings("unused") Collection<BaseArtifactType> derivedArtifacts = deriver.derive(artifact, is); is.close(); // Assert Assert.assertNotNull(artifact.getProperty()); for (Property property : artifact.getProperty()) { System.out.println(property.getPropertyName() + " - " + property.getPropertyValue()); } System.out.println(artifact.getDescription()); }
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); 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);
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); 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);
commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.CustomPropsHeading")); for (Property property : artifact.getProperty()) { printProperty(property.getPropertyName(), property.getPropertyValue());