/** * Validates the <code>KeyTransport</code> element included in this P-Mode. * <p>When included the element must have at least one child. Also when the <i>RSA-OAEP</i> algorithm is specified * an MGF algorithm must be specified. * * @throws PersistenceException If there is not at least one child element or when no MGF algorithm is specified in * case <i>RSA-OAEP</i> is specified */ @Validate public void validate() throws PersistenceException { // Check at least one child element is included if (Utils.getValue(algorithm, null) == null && Utils.getValue(MGFAlgorithm, null) == null && Utils.getValue(digestAlgorithm, null) == null && Utils.getValue(keyReferenceMethod.referenceMethod, null) == null) throw new PersistenceException("KeyTransport MUST have at least one child element", null); // Check if MGF is specified in case RSA-OAEP is kt algorithm if (WSConstants.KEYTRANSPORT_RSAOEP_XENC11.equalsIgnoreCase(algorithm) && Utils.getValue(MGFAlgorithm, null) == null) throw new PersistenceException("You MUST specify a MGF algorithm when specifying RSA-OAEP as " + "key transport algorithm", null); }
/** * Validates the read XML data to ensure that there are at most two UsernameToken child elements and that each * has its own target. * * @throws PersistenceException When the read XML document contains more than 2 UsernameToken elements or the * specified UsernameToken elements have the same target */ @Validate public void validate() throws PersistenceException { if (usernameTokens == null) return; if (usernameTokens.size() > 2) throw new PersistenceException("There may not be more than 2 UsernameToken elements", null); else if (usernameTokens.size() == 2) { // Compare the target attribute value of both elements final int c = Utils.compareStrings(usernameTokens.get(0).target, usernameTokens.get(1).target); if (c == -1 || c == 0) // The targets are equal throw new PersistenceException("You must specify separate targets for the UsernameToken elements!", null); } }
public static Base64Value parse(String value) throws PersistenceException { try { return new Base64Value(Base64.decode(value)); } catch (IOException e) { throw new PersistenceException("Cannot Base64-decode: " + value); } }
private static Value getValue(InputNode node) throws Exception { switch (node.getName()) { case IntegerValue.CODE: return IntegerValue.parse(node.getValue()); case IntegerValue.CODE_ALTERNTAIVE: return IntegerValue.parse(node.getValue()); case LongValue.CODE: return LongValue.parse(node.getValue()); case DoubleValue.CODE: return DoubleValue.parse(node.getValue()); case BooleanValue.CODE: return BooleanValue.parse(node.getValue()); case StringValue.CODE: return StringValue.parse(node.getValue()); case DateValue.CODE: return DateValue.parse(node.getValue()); case Base64Value.CODE: return Base64Value.parse(node.getValue()); case ArrayValue.CODE: ArrayList<Value> data = new ArrayList<>(); InputNode dataNode = node.getNext().getNext(); while (dataNode != null && dataNode.getName().equals(Value.CODE)) { data.add(getValue(dataNode.getNext())); dataNode = node.getNext(); } return new ArrayValue(data); case StructValue.CODE: List<Member> members = new ArrayList<>(); InputNode member = node.getNext(); do { String name = member.getNext().getValue(); Value value = getValue(member.getNext().getNext()); members.add(Member.create(name, value)); member = node.getNext(); } while (member != null && member.getName().equals(Member.CODE)); return new StructValue(members); } throw new PersistenceException(node.getName() + " is an unsupported type in XML-RPC"); }
public void read(Type field, NodeMap<InputNode> node) throws Exception { String namespace = node.getNode().getReference(); if(namespace != null && namespace.length() > 0) { String type = new PackageParser().revert(namespace).getName(); if(type == null) { throw new PersistenceException("Could not match name %s", namespace); } node.put("class", type); } }
public void write(Type field, NodeMap<OutputNode> node) throws Exception { OutputNode value = node.remove("class"); if(value != null) { String type = value.getValue(); String name = new PackageParser().parse(type); if(name == null) { throw new PersistenceException("Could not match class %s", type); } if(comment) { node.getNode().setComment(type); } node.getNode().getNamespaces().setReference(name, "class"); node.getNode().setReference(name); } }
/** * Validates the read configuration. At the moment this validation only checks that each parameter is named. * * @throws PersistenceException When a parameter included in the XML document has no name. */ @Validate public void validate() throws PersistenceException { if (!Utils.isNullOrEmpty(parameters)) { for (final String name : parameters.keySet()) if (Utils.isNullOrEmpty(name)) throw new PersistenceException("Each parameter in the configuration must be named!"); } }
/** * Validates the read XML data to ensure that there is at most one UsernameToken child element. This only element * should have no <code>target</code> attribute specified or with value <i>"ebms"</i> because the sub-channel * authentication and authorization can only use the security header targeted to this role. * * @throws PersistenceException When the read XML document contains more than 1 UsernameToken element */ @Override @Validate public void validate() throws PersistenceException { if (usernameTokens == null) return; else if (usernameTokens.size() > 1) throw new PersistenceException("There shall be only one UsernameToken element for PullRequestFlow", null); }
/** * Validates the data read from the XML document. The validation for now only checks whether an URL is specified * when the response pattern is set to CALLBACK * * @throws PersistenceException When no URL is provided when the reply pattern is set to CALLBACK */ @Validate public void validate() throws PersistenceException { if (getPattern() == ReplyPattern.CALLBACK && (to == null || to.isEmpty())) throw new PersistenceException("You must specify the URL where to sent errors when setting" + " reply pattern to CALLBACK", null); }
/** * Performs additional checks to ensure that the read XML document is valid according to the XSD. * <p>Because a general definition is used for reading both the default and specific pullers there is no check * on the number of P-Modes referenced by the pullers when the XML is deserialized. Therefor this method performs * checks:<ol> * <li>There are no referenced P-Modes for the default puller</li> * <li>There is at least one reference P-Mode for each specific puller</li> * </ol> * * @throws PersistenceException When the read XML fails one of the checks */ @Validate private void validate() throws PersistenceException { // Default puller should have no PModes associated with it if(defaultPuller.pmodes != null && !defaultPuller.pmodes.isEmpty()) throw new PersistenceException("The default puller should not specify specific PModes!"); // A specific puller must specifiy at least one PMode if(pullers != null) { for(final PullerConfig p : pullers) if(p.pmodes == null || p.pmodes.isEmpty()) throw new PersistenceException("Specific puller must reference at least one PMode!"); } }
@Commit public void build() throws PersistenceException { for(Behavior behavior : allowedBehaviors) { behavior.question = questionMap.get(behavior.questionId); } for(AdditionalInformation ai : additionalInformation) { ai.behavior = behaviorMap.get(ai.behaviorId); } super.build(); }
@Validate public void validate() throws PersistenceException { if(filenameBackgroundProgram != null) { if(!filenameBackgroundProgram.exists()) { String dir = Angerona.getInstance().getActualSimulation().getDirectory(); filenameBackgroundProgram = new File(dir + "/" + filenameBackgroundProgram.getPath()); if(!filenameBackgroundProgram.exists()) throw new PersistenceException("Cannot find background program in '" + filenameBackgroundProgram + "'"); } } }
@Commit public void build() throws PersistenceException { try { if(filenameBackgroundProgram != null) { backgroundKnowledge = ASPParser.parseProgram(new FileReader(filenameBackgroundProgram)); } } catch (FileNotFoundException | ParseException e) { throw new PersistenceException("Cannot parse background program in '" + filenameBackgroundProgram + "' - " + e.getMessage()); } }
/** * Checks if the loaded agent instance is valid. * @throws PersistenceException */ @Validate public void validation() throws PersistenceException { if(!(this.cylceScript instanceof CommandSequence)) { throw new PersistenceException("cycle-script is not of type '%s' but of type '%s", CommandSequence.class.getName(), this.cylceScript == null ? "null" : this.cylceScript.getClass().getName()); } }
@Validate private void validate() throws PersistenceException{ if (commands == null || commands.length != COMMANDS_COUNT) throw new PersistenceException("There must be always " + COMMANDS_COUNT + " commands in a configuration."); }
@Validate public void validate() throws PersistenceException { List<String> err = new ArrayList<>(); // check if no question is double (id or real-equal)): List<Question> temp = new ArrayList<>(questions); for(int i=0; i<temp.size(); ++i) { Question iQ = temp.get(i); for(int k=i+1; k<temp.size(); ++k) { Question kQ = temp.get(k); // check for duplo id: if(iQ.id == kQ.id) { err.add("The questions '" + iQ.toString() + "' and '" + kQ.toString() + "' share the same id: '" + iQ.id + "'"); // check for equal questions with mismatching ids } else if(Utility.equals(iQ.symbol, kQ.symbol)) { err.add("There exist two versions of questions with the same symbol: '" + iQ.toString() + "' one with 'id=" + iQ.id + "' and the other with id='" + kQ.id + "', questions with same " + "symbol but difference arguments are not supported."); } } } // check if all the behavior and additional information can be referenced for(Question question : questions) { questionMap.put(question.id, question); } for(Behavior behavior : this.allowedBehaviors) { if(!questionMap.keySet().contains(behavior.questionId)) { err.add("The behavior '" + behavior.toString() + "' references not existing question with id='" + behavior.questionId + "'"); } behaviorMap.put(behavior.id, behavior); } for(AdditionalInformation ai : this.additionalInformation) { if(!behaviorMap.keySet().contains(ai.behaviorId)) { err.add("The additional-information: '" + ai.toString() + "' references not existing behavior with id='" + ai.behaviorId + "'"); } } if(!err.isEmpty()) { String out = "Cannot deserialize DefendingSituation:"; for(String line : err) { out += "\n" + line; } throw new PersistenceException(out); } super.validate(); }
/** * Validates the read XML structure. The only restriction is that <i>Address</i> must be specified when the * </i>AddActorOrRoleAttribute</i> is set. * * @throws PersistenceException When no URL is provided for <i>Address</i> when the * </i>AddActorOrRoleAttribute</i> is set. */ @Validate public void validate() throws PersistenceException { if (shouldshouldAddActorOrRoleAttribute != null && (address == null || address.isEmpty())) throw new PersistenceException("Address must be specified if AddActorOrRoleAttribute is set"); }
/** * Validates the read data for the <code>PartInfo</code> element. * <p>If the payload is or should be contained in the SOAP body or as an attachment the location of the payload * document must be specified. * * @throws PersistenceException When the payload is contained in either SOAP body or attachment but no location is * specified */ @Validate public void validate() throws PersistenceException { if (!"external".equalsIgnoreCase(this.containment) && (location == null || location.isEmpty())) throw new PersistenceException("location attributed is required for containment type " + containment, (Object[]) null); }
/** * Checks that the trading partner configuration included in the P-Mode XML document includes at least a PartyId or * security configuration. * * @throws PersistenceException When neither PartyId or security configuration is included in the XML document */ @Validate public void validate() throws PersistenceException { if (Utils.isNullOrEmpty(partyIds) && securityConfig == null) throw new PersistenceException("Either one or more PartyIds or the security configuration must be included"); }