/**
 * Copyright (C) 2014 SINTEF <franck.fleurey@sintef.no>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.thingml.compilers.java.cepHelper;

import org.sintef.thingml.Filter;
import org.sintef.thingml.LengthWindow;
import org.sintef.thingml.TimeWindow;
import org.thingml.compilers.Context;
import org.thingml.compilers.thing.ThingCepViewCompiler;

/**
 * @author ludovic
 */
public class JavaCepViewCompiler extends ThingCepViewCompiler{
    @Override
    public void generate(Filter filter, StringBuilder builder, Context context) {
        builder.append(".filter(");
        context.getCompiler().getThingActionCompiler().generate(filter.getGuard(), builder, context);
        builder.append("())");
    }

    @Override
    public void generate(TimeWindow timeWindow, StringBuilder builder, Context context) {
        builder.append(".buffer(" + timeWindow.getSize() + "," + timeWindow.getStep() + ",TimeUnit.MILLISECONDS)");
    }

    @Override
    public void generate(LengthWindow lengthWindow, StringBuilder builder, Context context) {
        builder.append(".buffer(" + lengthWindow.getNbEvents());
        if(lengthWindow.getStep() != -1) {
            builder.append(", " + lengthWindow.getStep());
        }
        builder.append( ")");
    }
}

@@ -698,22 +698,17 @@
 thingml.
-Filter
+*
 ;%0Aimport
@@ -712,31 +712,24 @@
 ort org.
-sintef.
 thingml.
 LengthWi
@@ -724,58 +724,25 @@
 gml.
-LengthWindow;%0Aimport org.sintef.thingml.TimeWindow
+compilers.Context
 ;%0Aim
@@ -760,39 +760,47 @@
 ingml.compilers.
-Context
+java.JavaHelper
 ;%0Aimport org.thi
@@ -1041,32 +1041,918 @@
     
-builder.append(%22.filter(
+String param = %22x%22;%0A        String type = %22Object%22;%0A        if (filter.eContainer() instanceof SimpleSource) %7B%0A            SimpleSource s = (SimpleSource) filter.eContainer();%0A            param = s.getMessage().getMessage().getName();%0A            type = context.firstToUpper(s.getMessage().getMessage().getName()) + %22MessageType.%22 + context.firstToUpper(s.getMessage().getMessage().getName()) + %22Message%22;%0A        %7D else if (filter.eContainer() instanceof SourceComposition) %7B%0A            SourceComposition s = (SourceComposition) filter.eContainer();%0A            param = s.getResultMessage().getName();%0A            type = context.firstToUpper(s.getResultMessage().getName()) + %22MessageType.%22 + context.firstToUpper(s.getResultMessage().getName()) + %22Message%22;%0A        %7D%0A        builder.append(%22.filter(new Func1%3C%22 + type + %22, Boolean%3E() %7B%5Cn@Override%5Cnpublic Boolean call(%22 + type + %22 %22 + param + %22)%7B%5Cn return 
 %22);%0A
@@ -2077,18 +2077,19 @@
 append(%22
-()
+;%7D%7D
 )%22);%0A   

fix Java compiler according to latest refactoring in CEP metamodel