1 /* 2 wsmo4j - a WSMO API and Reference Implementation 3 Copyright (c) 2005, University of Innsbruck, Austria 4 This library is free software; you can redistribute it and/or modify it under 5 the terms of the GNU Lesser General Public License as published by the Free 6 Software Foundation; either version 2.1 of the License, or (at your option) 7 any later version. 8 This library is distributed in the hope that it will be useful, but WITHOUT 9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 11 details. 12 You should have received a copy of the GNU Lesser General Public License along 13 with this library; if not, write to the Free Software Foundation, Inc., 14 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 */ 16 package org.deri.wsmo4j.io.serializer.wsml; 17 18 19 import org.deri.wsmo4j.io.parser.wsml.LogExprParserImpl; 20 import org.deri.wsmo4j.logicalexpression.LogicalExpressionImpl; 21 import org.omwg.logicalexpression.*; 22 import org.wsmo.common.*; 23 24 25 /** 26 * This class is used to serialize logical expressions to WSML. 27 * @author retkru hollau 28 * @see org.omwg.logicalexpression.io.Serializer 29 */ 30 public class LogExprSerializerWSML{ 31 32 private VisitorSerializeWSML wsml; 33 private TopEntity container = null; 34 35 /** 36 * @param container TopEntity 37 */ 38 public LogExprSerializerWSML(TopEntity container) { 39 this.container=container; 40 wsml = new VisitorSerializeWSML(container); 41 } 42 43 /** 44 * @param logExpr Logical expression object model to be serialized 45 * @return serialized String object 46 * @see org.omwg.logicalexpression.io.Serializer#serialize(org.omwg.logicalexpression.LogicalExpression) 47 */ 48 public String serialize(LogicalExpression logExpr) { 49 logExpr.accept(wsml); 50 if (!(logExpr instanceof LogicalExpressionImpl)){ 51 return wsml.getSerializedObject() + ". "; 52 } 53 LogicalExpressionImpl logExprImpl = (LogicalExpressionImpl)logExpr; 54 String originalLE = logExprImpl.getStringRepresentation(); 55 if (originalLE==null){ 56 return wsml.getSerializedObject() + ". "; 57 } 58 try{ 59 LogExprParserImpl p = new LogExprParserImpl(null,container); 60 LogicalExpression leFromOrgExpr =p.parse(originalLE); 61 if (leFromOrgExpr.equals(logExpr)){ 62 //nice we can safe the old style of the LE 63 return originalLE; 64 } 65 }catch (Throwable e){ 66 //OK we take the serializer version 67 //e.printStackTrace(); 68 } 69 return wsml.getSerializedObject() + ". "; 70 } 71 72 }