@Override public void visit(Rewrite node) { node.getLeft().accept(this); current = right; node.getRight().accept(this); current = left; }
@Override public Void visit(Rewrite rew, Void _) { // builder.append('('); visitNodeOrKList(rew.getLeft()); builder.append(" => "); visitNodeOrKList(rew.getRight()); // builder.append(')'); return null; }
private void contributeResources(DeploymentContext context, Service service) { Map<String, String> filterParams = new HashMap<String, String>(); List<Route> bindings = serviceDefinition.getRoutes(); for (Route binding : bindings) { List<Rewrite> filters = binding.getRewrites(); if (filters != null && !filters.isEmpty()) { filterParams.clear(); for (Rewrite filter : filters) { filterParams.put(filter.getTo(), filter.getApply()); } } try { contributeResource(context, service, binding, filterParams); } catch (URISyntaxException e) { e.printStackTrace(); } } }
@Override public ASTNode transform(Rule node) throws TransformerException { final boolean heating = node.containsAttribute(MetaK.Constants.heatingTag); final boolean cooling = node.containsAttribute(MetaK.Constants.coolingTag); if (!(heating || cooling)) return node; if (!(node.getBody() instanceof Rewrite)) { GlobalSettings.kem.register( new KException( KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, "Heating/Cooling rules should have rewrite at the top.", getName(), node.getFilename(), node.getLocation())); } KSequence kSequence; Rewrite rewrite = (Rewrite) node.getBody(); if (heating) { if (!(rewrite.getRight() instanceof KSequence)) { GlobalSettings.kem.register( new KException( KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, "Heating rules should have a K sequence in the rhs.", getName(), node.getFilename(), node.getLocation())); } kSequence = (KSequence) rewrite.getRight(); } else { if (!(rewrite.getLeft() instanceof KSequence)) { GlobalSettings.kem.register( new KException( KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, "Cooling rules should have a K sequence in the lhs.", getName(), node.getFilename(), node.getLocation())); } kSequence = (KSequence) rewrite.getLeft(); } List<Term> kSequenceContents = kSequence.getContents(); if (kSequenceContents.size() != 2) { GlobalSettings.kem.register( new KException( KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, "Heating/Cooling rules should have exactly 2 items in their K Sequence.", getName(), node.getFilename(), node.getLocation())); } final Term freezer = kSequenceContents.get(1); if (!(freezer instanceof Freezer)) { kSequenceContents = new ArrayList<Term>(kSequenceContents); kSequenceContents.set(1, new ContextsToHeating(context).freeze(freezer)); kSequence = kSequence.shallowCopy(); kSequence.setContents(kSequenceContents); rewrite = rewrite.shallowCopy(); if (heating) { rewrite.replaceChildren(rewrite.getLeft(), kSequence, context); } else { rewrite.replaceChildren(kSequence, rewrite.getRight(), context); } node = node.shallowCopy(); node.setBody(rewrite); } return node; }