View Javadoc
1   /*
2    * (c) Copyright 2013- Openflexo
3    *
4    * This file is part of OpenFlexo.
5    *
6    * OpenFlexo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * OpenFlexo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>.
18   *
19   */
20  
21  package org.openflexo.foundation.doc.fml;
22  
23  import java.util.logging.Logger;
24  
25  import org.openflexo.foundation.doc.FlexoDocument;
26  import org.openflexo.foundation.doc.rm.FlexoDocumentResource;
27  import org.openflexo.foundation.resource.FlexoResource;
28  import org.openflexo.foundation.technologyadapter.FreeModelSlot;
29  import org.openflexo.pamela.annotations.Getter;
30  import org.openflexo.pamela.annotations.ImplementationClass;
31  import org.openflexo.pamela.annotations.ModelEntity;
32  import org.openflexo.pamela.annotations.PropertyIdentifier;
33  import org.openflexo.pamela.annotations.Setter;
34  import org.openflexo.pamela.annotations.XMLAttribute;
35  
36  /**
37   * Implementation of the ModelSlot class for the DOCX technology adapter<br>
38   * We expect here to connect an .docx document<br>
39   * 
40   * We might here supply a template document, which might be used as a "metamodel" to help manage connected document
41   * 
42   * @author sylvain
43   * 
44   */
45  @ModelEntity(isAbstract = true)
46  @ImplementationClass(FlexoDocumentModelSlot.FlexoDocumentModelSlotImpl.class)
47  public interface FlexoDocumentModelSlot<D extends FlexoDocument<D, ?>> extends FreeModelSlot<D> {
48  
49  	@PropertyIdentifier(type = String.class)
50  	public static final String TEMPLATE_DOCUMENT_URI_KEY = "templateDocumentURI";
51  	@PropertyIdentifier(type = FlexoResource.class)
52  	public static final String TEMPLATE_RESOURCE_KEY = "templateResource";
53  
54  	@Getter(value = TEMPLATE_DOCUMENT_URI_KEY)
55  	@XMLAttribute
56  	public String getTemplateDocumentURI();
57  
58  	@Setter(TEMPLATE_DOCUMENT_URI_KEY)
59  	public void setTemplateDocumentURI(String templateDocumentURI);
60  
61  	public FlexoDocumentResource<D, ?, ?> getTemplateResource();
62  
63  	public static abstract class FlexoDocumentModelSlotImpl<D extends FlexoDocument<D, ?>> extends FreeModelSlotImpl<D>
64  			implements FlexoDocumentModelSlot<D> {
65  
66  		private static final Logger logger = Logger.getLogger(FlexoDocumentModelSlot.class.getPackage().getName());
67  
68  		protected String templateDocumentURI;
69  
70  		@Override
71  		public String getTemplateDocumentURI() {
72  			if (getTemplateResource() != null) {
73  				return getTemplateResource().getURI();
74  			}
75  			return templateDocumentURI;
76  		}
77  
78  		@Override
79  		public void setTemplateDocumentURI(String templateDocumentURI) {
80  			if ((templateDocumentURI == null && this.templateDocumentURI != null)
81  					|| (templateDocumentURI != null && !templateDocumentURI.equals(this.templateDocumentURI))) {
82  				String oldValue = this.templateDocumentURI;
83  				this.templateDocumentURI = templateDocumentURI;
84  				getPropertyChangeSupport().firePropertyChange("templateDocumentURI", oldValue, templateDocumentURI);
85  			}
86  		}
87  
88  		@Override
89  		protected String getFMLRepresentationForConformToStatement() {
90  			return "conformTo " + getTemplateDocumentURI() + " ";
91  		}
92  
93  	}
94  }