KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > dto > ResourceReferenceDTO


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.dto;
22
23 import java.io.Serializable JavaDoc;
24
25 import com.jaspersoft.jasperserver.api.JSException;
26 import com.jaspersoft.jasperserver.api.metadata.common.domain.Query;
27 import com.jaspersoft.jasperserver.api.metadata.common.domain.Resource;
28 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceReference;
29 import com.jaspersoft.jasperserver.war.common.JasperServerConst;
30
31 /**
32  * @author Lucian Chirita (lucianc@users.sourceforge.net)
33  * @version $Id: ResourceReferenceDTO.java 4544 2006-09-15 00:22:51Z lucian $
34  */

35 public class ResourceReferenceDTO implements Serializable JavaDoc {
36
37     private String JavaDoc source;
38     private Resource localResource;
39     private String JavaDoc referenceURI;
40     
41     public ResourceReferenceDTO() {
42         this(null);
43     }
44     
45     public ResourceReferenceDTO(ResourceReference reference) {
46         if (reference == null) {
47             source = JasperServerConst.FIELD_CHOICE_NONE;
48         } else if (reference.isLocal()) {
49             source = JasperServerConst.FIELD_CHOICE_LOCAL;
50             localResource = (Query) reference.getLocalResource();
51         } else {
52             source = JasperServerConst.FIELD_CHOICE_CONT_REPO;
53             referenceURI = reference.getReferenceURI();
54         }
55     }
56     
57     /**
58      * @return Returns the referenceURI.
59      */

60     public String JavaDoc getReferenceURI() {
61         return referenceURI;
62     }
63     
64     /**
65      * @param referenceURI The referenceURI to set.
66      */

67     public void setReferenceURI(String JavaDoc referenceURI) {
68         this.referenceURI = referenceURI;
69     }
70     
71     /**
72      * @return Returns the source.
73      */

74     public String JavaDoc getSource() {
75         return source;
76     }
77     
78     /**
79      * @param source The source to set.
80      */

81     public void setSource(String JavaDoc source) {
82         this.source = source;
83     }
84     
85     /**
86      * @return Returns the localResource.
87      */

88     public Resource getLocalResource() {
89         return localResource;
90     }
91     /**
92      * @param localResource The localResource to set.
93      */

94     public void setLocalResource(Resource localResource) {
95         this.localResource = localResource;
96     }
97     
98     public ResourceReference toResourceReference() {
99         ResourceReference ref;
100         if (getSource().equals(JasperServerConst.FIELD_CHOICE_NONE)) {
101             ref = null;
102         } else if (getSource().equals(JasperServerConst.FIELD_CHOICE_LOCAL)) {
103             ref = new ResourceReference(getLocalResource());
104         } else if (getSource().equals(JasperServerConst.FIELD_CHOICE_CONT_REPO)) {
105             ref = new ResourceReference(getReferenceURI());
106         } else {
107             throw new JSException("Invalid resource reference source \"" + getSource() + "\"");
108         }
109         return ref;
110     }
111 }
112
Popular Tags