static private Version forNamespaceURI(String namespaceURI){ if(("").equals(namespaceURI)){ return ImportFilter.version; } return Version.forNamespaceURI(namespaceURI); }
/** * @param localName The name of the element. * Use the asterisk symbol (\"*\") to match any name. */ public ElementFilter(String localName){ this((Version.PMML_4_3).getNamespaceURI(), localName); }
static public Version forNamespaceURI(String namespaceURI){ Version[] versions = Version.values(); for(Version version : versions){ if((version.getNamespaceURI()).equals(namespaceURI)){ return version; } } throw new IllegalArgumentException(namespaceURI); } }
private String filterNamespaceURI(String namespaceURI){ Version version = forNamespaceURI(namespaceURI); if((version).compareTo(Version.PMML_3_0) >= 0 && (version).compareTo(Version.PMML_4_1) <= 0){ return ImportFilter.version.getNamespaceURI(); } return namespaceURI; }
@Override public Attributes filterAttributes(String localName, Attributes attributes){ if(("Apply").equals(localName) && compare(getSource(), Version.PMML_4_1) == 0){ return renameAttribute(attributes, "mapMissingTo", "defaultValue"); } else if(("PMML").equals(localName)){ Version target = getTarget(); if(getExtensions()){ attributes = renameAttribute(attributes, "version", "x-baseVersion"); } return setAttribute(attributes, "version", target.getVersion()); } else if(("TargetValue").equals(localName) && compare(getSource(), Version.PMML_3_1) <= 0){ return renameAttribute(attributes, "rawDataValue", "displayValue"); } return attributes; }
private void updateSource(String namespaceURI){ if(("").equals(namespaceURI)){ return; } // End if if(this.sourceNamespaceURI != null && (this.sourceNamespaceURI).equals(namespaceURI)){ return; } Version version = Version.forNamespaceURI(namespaceURI); Version source = getSource(); if(source != null && !(source).equals(version)){ throw new IllegalStateException(); } // Keep the String reference of the namespaceURI argument, as opposed to getting one using Version#getNamespaceURI(). // If the same String instance is reused, which is typical, // then String#equals(String) will be able to return quickly by performing an identity comparison this.sourceNamespaceURI = namespaceURI; setSource(version); }
static public Version getMinimum(){ Version[] versions = Version.values(); return versions[0]; }
static private void checkPMML(byte[] bytes, Version version) throws Exception { Node node = XPathUtil.selectNode(bytes, "/:PMML"); assertEquals(version.getNamespaceURI(), node.getNamespaceURI()); assertEquals(version.getVersion(), DOMUtil.getAttributeValue(node, "version")); } }
@Test public void unmarshal() throws Exception { Version[] versions = Version.values(); for(Version version : versions){ PMML pmml; try(InputStream is = ResourceUtil.getStream(version)){ pmml = PMMLUtil.unmarshal(is); } assertEquals(pmml.getVersion(), Version.PMML_4_3.getVersion()); assertEquals(pmml.getBaseVersion(), version.getVersion()); } } }
private void updateMaximum(Version maximum){ if(maximum != null && maximum.compareTo(this.maximum) < 0){ this.maximum = maximum; } }
private String filterLocalName(String namespaceURI, String localName){ Version version = forNamespaceURI(namespaceURI); if((version).equals(Version.PMML_4_0)){ if(("Trend").equals(localName)){ return "Trend_ExpoSmooth"; } } return localName; }
private Version(String namespaceUri){ setNamespaceURI(namespaceUri); }
@Override public void applyTo(Visitable visitable){ this.minimum = Version.getMinimum(); this.maximum = Version.getMaximum(); super.applyTo(visitable); }
@Override public Attributes filterAttributes(String localName, Attributes attributes){ if(("Apply").equals(localName) && compare(getSource(), Version.PMML_4_1) == 0){ return renameAttribute(attributes, "mapMissingTo", "defaultValue"); } else if(("PMML").equals(localName)){ Version target = getTarget(); if(getExtensions()){ attributes = renameAttribute(attributes, "version", "x-baseVersion"); } return setAttribute(attributes, "version", target.getVersion()); } else if(("TargetValue").equals(localName) && compare(getSource(), Version.PMML_3_1) <= 0){ return renameAttribute(attributes, "rawDataValue", "displayValue"); } return attributes; }
private void updateSource(String namespaceURI){ if(("").equals(namespaceURI)){ return; } // End if if(this.sourceNamespaceURI != null && (this.sourceNamespaceURI).equals(namespaceURI)){ return; } Version version = Version.forNamespaceURI(namespaceURI); Version source = getSource(); if(source != null && !(source).equals(version)){ throw new IllegalStateException(); } // Keep the String reference of the namespaceURI argument, as opposed to getting one using Version#getNamespaceURI(). // If the same String instance is reused, which is typical, // then String#equals(String) will be able to return quickly by performing an identity comparison this.sourceNamespaceURI = namespaceURI; setSource(version); }
static public Version getMaximum(){ Version[] versions = Version.values(); return versions[versions.length - 1]; }
private void updateMaximum(Version maximum){ if(maximum != null && maximum.compareTo(this.maximum) < 0){ this.maximum = maximum; } }
static public PMML unmarshal(Version version) throws IOException, JAXBException { if(!(Version.PMML_4_3).equals(version)){ throw new IllegalArgumentException(); } try(InputStream is = getStream(version)){ return JAXBUtil.unmarshalPMML(new StreamSource(is)); } }