List of usage examples for javax.xml.bind JAXBElement getName
public QName getName()
From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java
private void checkMandatoryExtension() { if (extensions == null) { return;//from w w w . j av a 2s . c o m } try { NODENAMES name = NODENAMES.Extension; for (ExtensionsListType extensionsList : extensions) { for (ExtensionType extension : extensionsList.getExtension()) { if (!extension.getContent().isEmpty()) { Object content = extension.getContent().get(0); if (content instanceof JAXBElement) { JAXBElement<?> element = (JAXBElement<?>) content; if (element.getName().equals(QNames._TakenOverBy_QNAME)) { TakenOverByType tob = (TakenOverByType) element.getValue(); validateSpecial(name, tob, extensionsList); } else if (element.getName().equals(QNames._ExpiredCertsRevocationInfo_QNAME)) { // Note: no need to validate anything here; either the date is specified or not } else if (element.getName().equals(QNames._AdditionalServiceInformation_QNAME)) { AdditionalServiceInformationType asi = (AdditionalServiceInformationType) element .getValue(); validateSpecial(name, asi, extensionsList); } else if (element.getName().equals(QNames._Qualifications_QNAME)) { QualificationsType qual = (QualificationsType) element.getValue(); validateSpecial(name, qual); } else { LOG.log(Level.WARNING, "Validation.checkMandatoryExtension(): " + "There is an unexpected object: " + element.getName()); } } } } } } catch (Exception ex) { LOG.log(Level.SEVERE, "Null Pointer Exception in checkMandatoryExtension() - " + ex.getMessage()); } }
From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java
/** * If the scheme type is "generic/list", the TSLType of the pointer to other TSL must be "listofthelists". And vice * et versa./*from w ww. j av a 2 s.c o m*/ */ void checkRuleTSLType() { String name = QNames._TSLType_QNAME.getLocalPart(); final String schemeTerritory = tsl.getSchemeInformation().getSchemeTerritory(); if (Configuration.getInstance().getCountryCodes().isCodeInList(schemeTerritory)) { String tslTypeInverseEu = Configuration.getInstance().getTSL().getTslTypeInverse(); if (pointers != null) { for (OtherTSLPointerType pointer : pointers) { List<Serializable> othInfo = pointer.getAdditionalInformation() .getTextualInformationOrOtherInformation(); String tslType = ""; for (Serializable obj : othInfo) { if (obj instanceof AnyType) { AnyType anyType = (AnyType) obj; List<Object> content = anyType.getContent(); if (!content.isEmpty() && content.get(0) instanceof JAXBElement<?>) { JAXBElement<?> element = (JAXBElement<?>) content.get(0); if (element.getName().getLocalPart().equals(name)) { tslType = (String) element.getValue(); break; } } } } if (tslType.isEmpty() || !tslType.equals(tslTypeInverseEu)) { logger.error(uiKeys.getString("Validation.rule.tslType.allPointersMustHave") + name + ": " + tslTypeInverseEu, pointer); } } } } }
From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java
private void checkMandatoryPointer() { if (pointers == null) { return;/* ww w .ja v a 2s .c o m*/ } try { NODENAMES name = NODENAMES.Pointer; for (OtherTSLPointerType pointer : pointers) { // tsl:ServiceDigitalIdentities // Note: at this point, the actual content of the certificate cannot be verified -> // just check if there is 'something'... validateSpecial(name, pointer.getServiceDigitalIdentities().getServiceDigitalIdentity().get(0), pointer, false); // tsl:TSLLocation validateSimple(name, QNames._TSLLocation, pointer.getTSLLocation(), TYPEFORMATS.TEXT, pointer); // go into <tsl:AdditionalInformation> and find all <tsl:OtherInformation> for (Serializable other : pointer.getAdditionalInformation() .getTextualInformationOrOtherInformation()) { if (other instanceof AnyType) { AnyType anyType = (AnyType) other; Object object = anyType.getContent().get(0); if (object instanceof JAXBElement) { JAXBElement<?> element = (JAXBElement<?>) object; if (element.getName().equals(QNames._SchemeOperatorName_QNAME)) { InternationalNamesType list = (InternationalNamesType) element.getValue(); validateList(name, QNames._SchemeOperatorName_QNAME.getLocalPart(), list.getName(), pointer); } else if (element.getName().equals(QNames._SchemeTypeCommunityRules_QNAME)) { if (!Configuration.getInstance().isTlMode()) { NonEmptyURIListType list = (NonEmptyURIListType) element.getValue(); validateList(name, QNames._SchemeTypeCommunityRules_QNAME.getLocalPart(), list.getURI(), pointer); } } else if (element.getName().equals(QNames._SchemeTerritory_QNAME)) { validateSimple(name, QNames._SchemeTerritory_QNAME.getLocalPart(), element.getValue(), TYPEFORMATS.TEXT, pointer); } else if (element.getName().equals(QNames._MimeType_QNAME)) { validateSimple(name, QNames._MimeType_QNAME.getLocalPart(), element.getValue(), TYPEFORMATS.TEXT, pointer); } else if (element.getName().equals(QNames._TSLType_QNAME)) { validateSimple(name, QNames._TSLType_QNAME.getLocalPart(), element.getValue(), TYPEFORMATS.URL, pointer); } } } } } } catch (Exception ex) { LOG.log(Level.SEVERE, "Null Pointer Exception in checkMandatoryPointer() - " + ex.getMessage()); } }
From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java
/** * If TSLType = "generic", there must be at least 2 URIs in SchemeTypeCommunityRule. If TSLType = "schemes", there * must be only 1 URI in SchemeTypeCommunityRule. Note: This check is done on each pointer; the current tsl type is * 'generic' if its pointers have a type of 'schemes' and vice versa *///from w ww . j a v a 2 s . c om private void checkRuleSchemeTypeCommunityRule() { String name = QNames._SchemeTypeCommunityRules_QNAME.getLocalPart(); String nameTSLType = QNames._TSLType_QNAME.getLocalPart(); String nameTerritory = QNames._SchemeTerritory_QNAME.getLocalPart(); if (pointers != null) { for (OtherTSLPointerType pointer : pointers) { List<Serializable> othInfo = pointer.getAdditionalInformation() .getTextualInformationOrOtherInformation(); String tslType = ""; String territory = ""; NonEmptyMultiLangURIListType communityRules = null; for (Serializable obj : othInfo) { if (obj instanceof AnyType) { AnyType anyType = (AnyType) obj; List<Object> content = anyType.getContent(); if (!content.isEmpty() && content.get(0) instanceof JAXBElement<?>) { JAXBElement<?> element = (JAXBElement<?>) content.get(0); if (element.getName().getLocalPart().equals(nameTSLType)) { tslType = (String) element.getValue(); } else if (element.getName().getLocalPart().equals(name)) { communityRules = (NonEmptyMultiLangURIListType) element.getValue(); } else if (element.getName().getLocalPart().equals(nameTerritory)) { territory = (String) element.getValue(); } } } } if (Configuration.getInstance().getCountryCodes().isCodeInList(territory)) { // eu country boolean isLotlTslType = tslType.equals(Configuration.getInstance().getLotlTslTypeEu()); boolean isTlTslType = tslType.equals(Configuration.getInstance().getTlTslTypeEu()); if (isLotlTslType) { // schemes if (communityRules != null && communityRules.getURI().size() != 1) { logger.error(name + uiKeys.getString("Validation.rule.schemeTypeCommunityRule.lotl"), pointer); } } else { if (isTlTslType) { if (communityRules != null && communityRules.getURI().size() < 2) { logger.error(name + uiKeys.getString("Validation.rule.schemeTypeCommunityRule.tl"), pointer); } } } } else { // no check done if non-eu country } } } }
From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java
/** * If TSLType = "schemes" (lotl), SchemeTerritory must be "EU". */// w w w .j a v a2 s . co m void checkRuleSchemeTerritory() { String nameTSLType = QNames._TSLType_QNAME.getLocalPart(); String nameTerritory = QNames._SchemeTerritory_QNAME.getLocalPart(); String schemesTSLType = Configuration.getInstance().getLotlTslTypeEu(); if (pointers != null) { for (OtherTSLPointerType pointer : pointers) { List<Serializable> othInfo = pointer.getAdditionalInformation() .getTextualInformationOrOtherInformation(); String tslType = ""; String territory = ""; for (Serializable obj : othInfo) { if (obj instanceof AnyType) { AnyType anyType = (AnyType) obj; List<Object> content = anyType.getContent(); if (!content.isEmpty() && content.get(0) instanceof JAXBElement<?>) { JAXBElement<?> element = (JAXBElement<?>) content.get(0); if (element.getName().getLocalPart().equals(nameTSLType)) { tslType = (String) element.getValue(); } else if (element.getName().getLocalPart().equals(nameTerritory)) { territory = (String) element.getValue(); } } } } // check that the territory code is in uppercase if (!territory.toUpperCase().equals(territory)) { logger.error(nameTerritory + uiKeys.getString("Validation.rule.schemeTerritory.uppercase"), pointer); } // check that the EUlistofthelist is used only for territory EU if (tslType.equals(schemesTSLType)) { if (!territory.equals("EU")) { logger.error(uiKeys.getString("Validation.rule.schemeTerritory.eu"), pointer); } } if (!Configuration.getInstance().getCountryCodes().isCodeInList(territory)) { final String tslTypeInverseNonEu = Configuration.getInstance().getTSL().getTslTypeInverse(); String regExp = tslTypeInverseNonEu.replaceAll("(#CC#)", "(.+)"); final Pattern pattern = Pattern.compile(regExp); final Matcher matcher = pattern.matcher(tslType); if (matcher.matches()) { final String countryInTslType = matcher.group(1); if (!countryInTslType.equals(territory)) { logger.error( nameTerritory + uiKeys.getString("Validation.rule.tslType.country.matcherror"), pointer); } } } } } }
From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java
private void validateSpecial(NODENAMES name, QualificationsType type) { String field = QNames._Qualifications_QNAME.getLocalPart(); if (type != null) { for (QualificationElementType element : type.getQualificationElement()) { // ecc:Qualifiers - 2 ecc:Qualifier boolean isEmpty = false; if (element.getQualifiers() == null || element.getQualifiers().getQualifier().isEmpty()) { isEmpty = true;/* w w w . j ava 2s .co m*/ } else { List<QualifierType> qualifiers = element.getQualifiers().getQualifier(); // if (qualifiers.size() >= 1) { String uri1 = qualifiers.get(0).getUri(); if (uri1 == null || uri1.isEmpty() || uri1.equals(Util.DEFAULT_NO_SELECTION_ENTRY)) { isEmpty = true; } // } else { // logger.error(logger.getPrefix(name.toString(), field)+ // "cannot be validated due to wrong number of Qualifiers!", element); // LOG.log(Level.WARNING, // "Validation.validateSpecial(QualificationsType): wrong number of Qualifiers!"); // } } if (isEmpty) { logger.error(logger.getEmptyMessage(name.toString(), QNames._QualificationsQualifiers), element); } CriteriaListType criteriaList = element.getCriteriaList(); // cannot be null - created in ObjectFiller // ecc:CriteriaList assert validateSimple(name, QNames._QualificationsAssert, criteriaList.getAssert(), TYPEFORMATS.TEXT, element); // ecc:KeyUsage boolean foundContent = false; List<KeyUsageType> keyUsage = criteriaList.getKeyUsage(); if (!keyUsage.isEmpty()) { List<KeyUsageBitType> keyUsageBit = keyUsage.get(0).getKeyUsageBit(); for (KeyUsageBitType kubit : keyUsageBit) { foundContent = kubit.isValue(); if (foundContent) { break; } } } if (!foundContent) { // ecc:PolicyIdentifier List<PoliciesListType> policySet = criteriaList.getPolicySet(); if (!policySet.isEmpty()) { for (PoliciesListType policy : policySet) { List<ObjectIdentifierType> policyIdentifier = policy.getPolicyIdentifier(); for (ObjectIdentifierType polId : policyIdentifier) { IdentifierType identifier = polId.getIdentifier(); if (identifier != null && identifier.getValue() != null && !identifier.getValue().isEmpty()) { foundContent = true; break; } } if (foundContent) { break; } } } // tslx:ExtendedKeyUsageType & tslx:CertSubjectDNAttributeType eu.europa.ec.markt.tsl.jaxb.xades.AnyType otherCriteriaList = criteriaList .getOtherCriteriaList(); List<Object> content = otherCriteriaList.getContent(); for (Object obj : content) { if (obj instanceof JAXBElement<?>) { JAXBElement<?> jex = (JAXBElement<?>) obj; if (jex.getName().equals(QNames._ExtendedKeyUsage_QNAME)) { ExtendedKeyUsageType ekut = (ExtendedKeyUsageType) jex.getValue(); if (!ekut.getKeyPurposeId().isEmpty()) { for (ObjectIdentifierType oid : ekut.getKeyPurposeId()) { if (oid.getIdentifier() != null && !oid.getIdentifier().getValue().isEmpty()) { foundContent = true; break; } } if (foundContent) { break; } } } else if (jex.getName().equals(QNames._CertSubjectDNAttribute_QNAME)) { CertSubjectDNAttributeType csdat = (CertSubjectDNAttributeType) jex.getValue(); if (!csdat.getAttributeOID().isEmpty()) { for (ObjectIdentifierType oid : csdat.getAttributeOID()) { if (oid.getIdentifier() != null && !oid.getIdentifier().getValue().isEmpty()) { foundContent = true; break; } } if (foundContent) { break; } } } } } } if (!foundContent) { logger.error( logger.getPrefix(name.toString(), field) + uiKeys.getString("Validation.mandatory.qualification.minimumFields"), element); } } } }
From source file:de.ingrid.interfaces.csw.domain.filter.impl.LuceneFilterParser.java
/** * Build a piece of Lucene query with the specified Spatial filter. * * @param spatialOpsEl// ww w.j av a 2 s. co m * @return Filter * @throws CSWFilterException */ protected Filter processSpatialOperator(JAXBElement<? extends SpatialOpsType> spatialOpsEl) throws CSWFilterException { LuceneOGCFilter spatialfilter = null; SpatialOpsType spatialOps = spatialOpsEl.getValue(); if (spatialOps instanceof BBOXType) { BBOXType bbox = (BBOXType) spatialOps; String propertyName = bbox.getPropertyName(); String crsName = bbox.getSRS(); // make sure we DO have a valid srs // joachim@wemove.com at 21.05.2012 if (crsName == null || crsName.length() == 0) { crsName = "EPSG:4326"; } // verify that all the parameters are specified if (propertyName == null) { throw new CSWFilterException("Missing propertyName parameter for BBOX operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } else if (!propertyName.contains("BoundingBox")) { throw new CSWFilterException("The propertyName parameter for BBOX operator is not a BoundingBox.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } if (bbox.getEnvelope() == null && bbox.getEnvelopeWithTimePeriod() == null) { throw new CSWFilterException("Missing envelope parameter for BBOX operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } // transform the EnvelopeEntry in GeneralEnvelope spatialfilter = LuceneOGCFilter.wrap(FF.bbox(LuceneOGCFilter.GEOMETRY_PROPERTY, bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY(), crsName)); } else if (spatialOps instanceof DistanceBufferType) { DistanceBufferType dist = (DistanceBufferType) spatialOps; double distance = dist.getDistance(); String units = dist.getDistanceUnits(); JAXBElement<?> geomEl = dist.getAbstractGeometry(); String operator = spatialOpsEl.getName().getLocalPart(); // verify that all the parameters are specified if (dist.getPropertyName() == null) { throw new CSWFilterException("Missing propertyName parameter for distanceBuffer operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } if (units == null) { throw new CSWFilterException("Missing units parameter for distanceBuffer operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } if (geomEl == null || geomEl.getValue() == null) { throw new CSWFilterException("Missing geometry object for distanceBuffer operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } Object gml = geomEl.getValue(); Geometry geometry = null; String crsName = null; // transform the GML envelope into JTS polygon try { if (gml instanceof PointType) { PointType gmlPoint = (PointType) gml; crsName = gmlPoint.getSrsName(); geometry = GeometrytoJTS.toJTS(gmlPoint); } else if (gml instanceof LineStringType) { LineStringType gmlLine = (LineStringType) gml; crsName = gmlLine.getSrsName(); geometry = GeometrytoJTS.toJTS(gmlLine); } else if (gml instanceof EnvelopeType) { EnvelopeType gmlEnvelope = (EnvelopeType) gml; crsName = gmlEnvelope.getSrsName(); geometry = GeometrytoJTS.toJTS(gmlEnvelope); } if (operator.equals("DWithin")) { spatialfilter = LuceneOGCFilter.wrap( FF.dwithin(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(geometry), distance, units)); } else if (operator.equals("Beyond")) { spatialfilter = LuceneOGCFilter.wrap( FF.beyond(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(geometry), distance, units)); } else { throw new CSWFilterException("Unknow DistanceBuffer operator: " + operator, INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } } catch (NoSuchAuthorityCodeException e) { throw new CSWFilterException(UNKNOW_CRS_ERROR_MSG + crsName, INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } catch (FactoryException e) { throw new CSWFilterException(FACTORY_BBOX_ERROR_MSG + e.getMessage(), INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } catch (IllegalArgumentException e) { throw new CSWFilterException(INCORRECT_BBOX_DIM_ERROR_MSG + e.getMessage(), INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } } else if (spatialOps instanceof BinarySpatialOpType) { BinarySpatialOpType binSpatial = (BinarySpatialOpType) spatialOps; String propertyName = null; String operator = spatialOpsEl.getName().getLocalPart(); operator = operator.toUpperCase(); Object gmlGeometry = null; // the propertyName if (binSpatial.getPropertyName() != null && binSpatial.getPropertyName().getValue() != null) { PropertyNameType p = binSpatial.getPropertyName().getValue(); propertyName = p.getContent(); } // geometric object: envelope if (binSpatial.getEnvelope() != null && binSpatial.getEnvelope().getValue() != null) { gmlGeometry = binSpatial.getEnvelope().getValue(); } if (binSpatial.getAbstractGeometry() != null && binSpatial.getAbstractGeometry().getValue() != null) { AbstractGeometryType ab = binSpatial.getAbstractGeometry().getValue(); // geometric object: point if (ab instanceof PointType) { gmlGeometry = ab; } // geometric object: Line else if (ab instanceof LineStringType) { gmlGeometry = ab; } else if (ab == null) { throw new IllegalArgumentException("null value in BinarySpatialOp type"); } else { throw new IllegalArgumentException( "unknow BinarySpatialOp type: " + ab.getClass().getSimpleName()); } } if (propertyName == null && gmlGeometry == null) { throw new CSWFilterException( "Missing propertyName or geometry parameter for binary spatial operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } SpatialFilterType filterType = null; try { filterType = SpatialFilterType.valueOf(operator); } catch (IllegalArgumentException ex) { log.error("Unknow spatial filter type"); } if (filterType == null) { throw new CSWFilterException("Unknow FilterType: " + operator, INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } String crsName = "undefined CRS"; try { Geometry filterGeometry = null; if (gmlGeometry instanceof EnvelopeType) { // transform the EnvelopeEntry in GeneralEnvelope EnvelopeType gmlEnvelope = (EnvelopeType) gmlGeometry; crsName = gmlEnvelope.getSrsName(); filterGeometry = GeometrytoJTS.toJTS(gmlEnvelope); } else if (gmlGeometry instanceof PointType) { PointType gmlPoint = (PointType) gmlGeometry; crsName = gmlPoint.getSrsName(); filterGeometry = GeometrytoJTS.toJTS(gmlPoint); } else if (gmlGeometry instanceof LineStringType) { LineStringType gmlLine = (LineStringType) gmlGeometry; crsName = gmlLine.getSrsName(); filterGeometry = GeometrytoJTS.toJTS(gmlLine); } int srid = SRIDGenerator.toSRID(crsName, Version.V1); filterGeometry.setSRID(srid); switch (filterType) { case CONTAINS: spatialfilter = LuceneOGCFilter .wrap(FF.contains(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case CROSSES: spatialfilter = LuceneOGCFilter .wrap(FF.crosses(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case DISJOINT: spatialfilter = LuceneOGCFilter .wrap(FF.disjoint(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case EQUALS: spatialfilter = LuceneOGCFilter .wrap(FF.equal(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case INTERSECTS: spatialfilter = LuceneOGCFilter .wrap(FF.intersects(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case OVERLAPS: spatialfilter = LuceneOGCFilter .wrap(FF.overlaps(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case TOUCHES: spatialfilter = LuceneOGCFilter .wrap(FF.touches(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; case WITHIN: spatialfilter = LuceneOGCFilter .wrap(FF.within(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; default: log.info("using default filter within"); spatialfilter = LuceneOGCFilter .wrap(FF.within(LuceneOGCFilter.GEOMETRY_PROPERTY, FF.literal(filterGeometry))); break; } } catch (NoSuchAuthorityCodeException e) { throw new CSWFilterException(UNKNOW_CRS_ERROR_MSG + crsName, INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } catch (FactoryException e) { throw new CSWFilterException(FACTORY_BBOX_ERROR_MSG + e.getMessage(), INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } catch (IllegalArgumentException e) { throw new CSWFilterException(INCORRECT_BBOX_DIM_ERROR_MSG + e.getMessage(), INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } } return spatialfilter; }
From source file:de.ingrid.interfaces.csw.domain.filter.impl.LuceneFilterParser.java
/** * Build a piece of Lucene query with the specified Comparison filter. * * @param comparisonOpsEl/*ww w .j a v a 2 s. co m*/ * @return String * @throws CSWFilterException */ protected String processComparisonOperator(JAXBElement<? extends ComparisonOpsType> comparisonOpsEl) throws CSWFilterException { StringBuilder response = new StringBuilder(); ComparisonOpsType comparisonOps = comparisonOpsEl.getValue(); if (comparisonOps instanceof PropertyIsLikeType) { PropertyIsLikeType pil = (PropertyIsLikeType) comparisonOps; // get the field String propertyName = ""; String propertyNameLocal = ""; if (pil.getPropertyName() != null) { propertyName = pil.getPropertyName().getContent(); propertyNameLocal = this.removePrefix(propertyName); response.append(propertyNameLocal.toLowerCase()).append(':'); } else { throw new CSWFilterException("Missing propertyName parameter for propertyIsLike operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } // get the queryable represented by the field Queryable queryableProperty = Queryable.UNKNOWN; try { queryableProperty = Queryable.valueOf(propertyNameLocal.toUpperCase()); } catch (IllegalArgumentException ex) { throw new CSWFilterException("Unknown queryable: " + propertyName); } // get the value of the field if (pil.getLiteral() != null && pil.getLiteral() != null) { // format the value by replacing the specified special char by // the Lucene special char String value = pil.getLiteral(); if (pil.getWildCard() != null) { value = value.replace(pil.getWildCard(), "*"); } if (pil.getSingleChar() != null) { value = value.replace(pil.getSingleChar(), "?"); } if (pil.getEscapeChar() != null) { value = value.replace(pil.getEscapeChar(), "\\"); } // for a date remove the time zone if (queryableProperty.getType() instanceof Date) { value = value.replace("Z", ""); } response.append(this.maskPhrase(value)); } else { throw new CSWFilterException("Missing literal parameter for propertyIsLike operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } } else if (comparisonOps instanceof PropertyIsNullType) { PropertyIsNullType pin = (PropertyIsNullType) comparisonOps; // get the field if (pin.getPropertyName() != null) { response.append(this.removePrefix(pin.getPropertyName().getContent().toLowerCase())).append(':') .append("null"); } else { throw new CSWFilterException("Missing propertyName parameter for propertyIsNull operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } } else if (comparisonOps instanceof PropertyIsBetweenType) { // TODO PropertyIsBetweenType throw new UnsupportedOperationException("Not supported yet."); } else if (comparisonOps instanceof BinaryComparisonOpType) { BinaryComparisonOpType bc = (BinaryComparisonOpType) comparisonOps; String propertyName = bc.getPropertyName(); String propertyNameLocal = this.removePrefix(propertyName); String literal = bc.getLiteral().getStringValue(); String operator = comparisonOpsEl.getName().getLocalPart(); if (propertyName == null || literal == null) { throw new CSWFilterException( "Missing propertyName or literal parameter for binary comparison operator.", INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } else { // get the queryable represented by the field Queryable queryableProperty = Queryable.UNKNOWN; try { queryableProperty = Queryable.valueOf(propertyNameLocal.toUpperCase()); } catch (IllegalArgumentException ex) { throw new CSWFilterException("Unknown queryable: " + propertyName); } QueryableType queryableType = queryableProperty.getType(); propertyNameLocal = propertyNameLocal.toLowerCase(); // property == value -> property:"value" if (operator.equals("PropertyIsEqualTo")) { // add '*' to date fields to return also parts of the Dates AND to disable analyzing of the date field if (queryableType instanceof Date && !literal.endsWith("*")) { literal = literal.concat("*"); } response.append(propertyNameLocal).append(":").append(this.maskPhrase(literal)); } // property != value -> metafile:doc NOT property:"value" else if (operator.equals("PropertyIsNotEqualTo")) { response.append(defaultField).append(" NOT "); response.append(propertyNameLocal).append(":").append(this.maskPhrase(literal)); } // property >= value -> property:[value UPPER_BOUND] else if (operator.equals("PropertyIsGreaterThanOrEqualTo")) { if (queryableType instanceof Date) { literal = literal.replace("Z", ""); } response.append(propertyNameLocal).append(":[").append(literal).append(' ') .append(queryableType.getUpperBound()).append("]"); } // property > value -> property:{value UPPER_BOUND} else if (operator.equals("PropertyIsGreaterThan")) { if (queryableType instanceof Date) { literal = literal.replace("Z", ""); } response.append(propertyNameLocal).append(":{").append(literal).append(' ') .append(queryableType.getUpperBound()).append("}"); } // property < value -> property:{LOWER_BOUND value} else if (operator.equals("PropertyIsLessThan")) { if (queryableType instanceof Date) { literal = literal.replace("Z", ""); } response.append(propertyNameLocal).append(":{").append(queryableType.getLowerBound()) .append(' ').append(literal).append("}"); } // property <= value -> property:[LOWER_BOUND value] else if (operator.equals("PropertyIsLessThanOrEqualTo")) { if (queryableType instanceof Date) { literal = literal.replace("Z", ""); } response.append(propertyNameLocal).append(":[").append(queryableType.getLowerBound()) .append(' ').append(literal).append("]"); } else { throw new CSWFilterException("Unkwnow comparison operator: " + operator, INVALID_PARAMETER_CODE, QUERY_CONSTRAINT_LOCATOR); } } } return response.toString(); }
From source file:org.apache.axis2.datasource.jaxb.JAXBDSContext.java
/** * The root element being read is defined by schema/JAXB; however its contents are known by * schema/JAXB. Therefore we use unmarshal by the declared type (This method is used to * unmarshal rpc elements)// w w w. j a va 2 s . c om * * @param u Unmarshaller * @param reader XMLStreamReader * @param type Class * @return Object * @throws WebServiceException */ public static Object unmarshalByType(final Unmarshaller u, final XMLStreamReader reader, final Class type, final boolean isList, final JAXBUtils.CONSTRUCTION_TYPE ctype) throws WebServiceException { if (DEBUG_ENABLED) { log.debug("Invoking unmarshalByType."); log.debug(" type = " + type); log.debug(" isList = " + isList); log.debug(" ctype = " + ctype); } return AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { // Unfortunately RPC is type based. Thus a // declared type must be used to unmarshal the xml. Object jaxb; if (!isList) { // case: We are not unmarshalling an xsd:list but an Array. if (type.isArray()) { // If the context is created using package // we will not have common arrays or type array in the context // but there is not much we can do about it so seralize it as // usual if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH) { if (DEBUG_ENABLED) { log.debug("Unmarshal Array via BY_CONTEXT_PATH approach"); } jaxb = u.unmarshal(reader, type); } // list on client array on server, Can happen only in start from java // case. else if ((ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY)) { // The type could be any Object or primitive //process primitives first //first verify if we have a primitive type associated in the array. //array could be single dimension or multi dimension. Class cType = type.getComponentType(); while (cType.isArray()) { cType = cType.getComponentType(); } if (cType.isPrimitive()) { if (DEBUG_ENABLED) { log.debug("Unmarshal Array of primitive via BY_CLASS_ARRAY approach"); } jaxb = u.unmarshal(reader, type); } // process non primitive // I will first unmarshall the xmldata to a String[] // Then use the unmarshalled jaxbElement to create // proper type Object Array. else { if (DEBUG_ENABLED) { log.debug("Unmarshal Array of non-primitive via BY_CLASS_ARRAY approach"); } jaxb = unmarshalArray(reader, u, type); } } else { if (DEBUG_ENABLED) { log.debug("Unmarshal Array"); } jaxb = u.unmarshal(reader, type); } } else if (type.isEnum()) { // When JAXBContext is created using a context path, it will not // include Enum classes. // These classes have @XmlEnum annotation but not @XmlType/@XmlElement, // so the user will see MarshallingEx, class not known to ctxt. // // This is a jax-b defect, for now this fix is in place to pass CTS. // This only fixes the // situation where the enum is the top-level object (e.g., message-part // in rpc-lit scenario) // // Sample of what enum looks like: // @XmlEnum public enum EnumString { // @XmlEnumValue("String1") STRING_1("String1"), // @XmlEnumValue("String2") STRING_2("String2"); // // public static getValue(String){} <-- resolves a "value" to an emum // object // ... } if (DEBUG_ENABLED) { log.debug("Unmarshalling " + type.getName() + " as Enum"); } JAXBElement<String> enumValue = u.unmarshal(reader, XmlEnumUtils.getConversionType(type)); if (enumValue != null) { jaxb = XmlEnumUtils.fromValue(type, enumValue.getValue()); } else { jaxb = null; } } //Normal case: We are not unmarshalling a xsd:list or Array else { if (DEBUG_ENABLED) { log.debug("Unmarshalling normal case (not array, not xsd:list, not enum)"); } jaxb = u.unmarshal(reader, type); } } else { // If this is an xsd:list, we need to return the appropriate // list or array (see NOTE above) // First unmarshal as a String //Second convert the String into a list or array if (DEBUG_ENABLED) { log.debug("Unmarshalling xsd:list"); } jaxb = unmarshalAsListOrArray(reader, u, type); } if (log.isDebugEnabled()) { Class cls; if (jaxb == null) { if (DEBUG_ENABLED) { log.debug("End unmarshalByType returning null object"); } } else if (jaxb instanceof JAXBElement) { JAXBElement jbe = (JAXBElement) jaxb; if (DEBUG_ENABLED) { log.debug("End unmarshalByType returning JAXBElement"); log.debug(" Class = " + jbe.getDeclaredType()); log.debug(" QName = " + jbe.getName()); } } else { if (DEBUG_ENABLED) { log.debug("End unmarshalByType returning " + jaxb.getClass()); } } } return jaxb; } catch (OMException e) { throw e; } catch (Throwable t) { throw new OMException(t); } } }); }
From source file:org.apache.axis2.datasource.jaxb.JAXBDSContext.java
/** * Marshal objects by type//from w w w . ja v a 2 s. c o m * * @param b Object that can be rendered as an element, but the element name is not known to the * schema (i.e. rpc) * @param m Marshaller * @param writer XMLStreamWriter * @param type Class * @param isList true if this is an XmlList * @param ctype CONSTRUCTION_TYPE * @param optimize boolean set to true if optimization directly to * outputstream should be attempted. */ private void marshalByType(final Object b, final Marshaller m, final XMLStreamWriter writer, final Class type, final boolean isList, final JAXBUtils.CONSTRUCTION_TYPE ctype, final boolean optimize) throws WebServiceException { if (log.isDebugEnabled()) { log.debug("Enter marshalByType b=" + getDebugName(b) + " type=" + type + " marshaller=" + m + " writer=" + writer + " isList=" + isList + " ctype=" + ctype + " optimize=" + optimize); } if (isOccurrenceArray(b)) { marshalOccurrenceArray((JAXBElement) b, m, writer); return; } AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { // NOTE // Example: // <xsd:simpleType name="LongList"> // <xsd:list> // <xsd:simpleType> // <xsd:restriction base="xsd:unsignedInt"/> // </xsd:simpleType> // </xsd:list> // </xsd:simpleType> // <element name="myLong" nillable="true" type="impl:LongList"/> // // LongList will be represented as an int[] // On the wire myLong will be represented as a list of integers // with intervening whitespace // <myLong>1 2 3</myLong> // // Unfortunately, we are trying to marshal by type. Therefore // we want to marshal an element (foo) that is unknown to schema. // If we use the normal marshal code, the wire will look like // this (which is incorrect): // <foo><item>1</item><item>2</item><item>3</item></foo> // // The solution is to detect this situation and marshal the // String instead. Then we get the correct wire format: // <foo>1 2 3</foo> Object jbo = b; if (DEBUG_ENABLED) { log.debug("check if marshalling list or array object, type = " + ((b != null) ? b.getClass().getName() : "null")); } if (isList) { if (DEBUG_ENABLED) { log.debug("marshalling type which is a List"); } // This code assumes that the JAXBContext does not understand // the array or list. In such cases, the contents are converted // to a String and passed directly. if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH) { QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(b); String text = XSDListUtils.toXSDListString(getTypeEnabledObject(b)); if (DEBUG_ENABLED) { log.debug("marshalling [context path approach] " + "with xmllist text = " + text); } jbo = new JAXBElement(qName, String.class, text); } else if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY) { // Some versions of JAXB have array/list processing built in. // This code is a safeguard because apparently some versions // of JAXB don't. QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(b); String text = XSDListUtils.toXSDListString(getTypeEnabledObject(b)); if (DEBUG_ENABLED) { log.debug("marshalling [class array approach] " + "with xmllist text = " + text); } jbo = new JAXBElement(qName, String.class, text); } } // When JAXBContext is created using a context path, it will not include Enum // classes. // These classes have @XmlEnum annotation but not @XmlType/@XmlElement, so the // user will see MarshallingEx, class not known to ctxt. // // This is a jax-b defect, for now this fix is in place to pass CTS. This only // fixes the // situation where the enum is the top-level object (e.g., message-part in // rpc-lit scenario) // // Sample of what enum looks like: // @XmlEnum public enum EnumString { // @XmlEnumValue("String1") STRING_1("String1"), // @XmlEnumValue("String2") STRING_2("String2"); // ... } if (type.isEnum()) { if (b != null) { if (DEBUG_ENABLED) { log.debug("marshalByType. Marshaling " + type.getName() + " as Enum"); } JAXBElement jbe = (JAXBElement) b; String value = XMLRootElementUtil.getEnumValue((Enum) jbe.getValue()); jbo = new JAXBElement(jbe.getName(), String.class, value); } } // If the output stream is available, marshal directly to it OutputStream os = (optimize) ? getOutputStream(writer, m) : null; if (os == null) { if (DEBUG_ENABLED) { log.debug("Invoking marshalByType. " + "Marshaling to an XMLStreamWriter. Object is " + getDebugName(jbo)); } m.marshal(jbo, writer); } else { if (DEBUG_ENABLED) { log.debug("Invoking marshalByType. " + "Marshaling to an OutputStream. Object is " + getDebugName(jbo)); } m.marshal(jbo, os); } } catch (OMException e) { throw e; } catch (Throwable t) { throw new OMException(t); } return null; } }); }