Debian Codegraph @

src/main/java/com/eprosima/idl/parser/tree/Module.java

raw
1 // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.eprosima.idl.parser.tree;
16
17 import java.util.ArrayList;
18
19 import org.antlr.v4.runtime.Token;
20
21 public class Module extends DefinitionContainer implements Definition
22 {
23 public Module(String scopeFile, boolean isInScope, String scope, String name, Token tk)
24 {
25 super(scopeFile, isInScope, scope, name, tk);
26 }
27
28 public void setParent(Object obj)
29 {
30 m_parent = obj;
31 }
32
33 public Object getParent()
34 {
35 return m_parent;
36 }
37
38
39 /*!
40 * @brief This function is used in stringtemplates to not generate module in some cases (Right now in RequestReply.idl).
41 */
42 public boolean isThereAreValidDefinitions()
43 {
44 boolean returnedValue = false;
45
46 for(int count = 0; !returnedValue && count < getDefinitions().size(); ++count)
47 {
48 returnedValue = getDefinitions().get(count).isIsInterface();
49 }
50
51 return returnedValue;
52 }
53
54 /*!
55 * @brief This function is used in stringtemplates to not generate module in some cases (Right now in generated (previous c) idl).
56 */
57 public boolean isThereAreDeclarations()
58 {
59 boolean returnedValue = false;
60
61 for(int count = 0; !returnedValue && count < getDefinitions().size(); ++count)
62 {
63 if(getDefinitions().get(count).isIsInterface())
64 {
65 returnedValue = ((Interface)getDefinitions().get(count)).isThereAreDeclarations();
66 }
67 else
68 {
69 returnedValue = getDefinitions().get(count).isIsTypeDeclaration() ||
70 getDefinitions().get(count).isIsException();
71 }
72 }
73
74 return returnedValue;
75 }
76
77 @Override
78 public boolean isIsModule()
79 {
80 return true;
81 }
82
83 @Override
84 public boolean isIsInterface()
85 {
86 return false;
87 }
88
89 @Override
90 public boolean isIsException()
91 {
92 return false;
93 }
94
95 @Override
96 public boolean isIsTypeDeclaration()
97 {
98 return false;
99 }
100
101 @Override
102 public boolean isIsConstDeclaration()
103 {
104 return false;
105 }
106
107 @Override
108 public boolean isIsAnnotation()
109 {
110 return false;
111 }
112
113 ////////// RESTful block //////////
114
115 public String getResourceCompleteBaseUri()
116 {
117 Annotation baseUri = getAnnotations().get("RESOURCES_BASE_URI");
118 String baseUriStr = baseUri.getValue("value");
119
120 if(baseUriStr != null)
121 {
122 // Remove http://
123 int posInit = baseUriStr.indexOf("//");
124
125 if(posInit == -1)
126 posInit = 0;
127 else
128 posInit += 2;
129
130 return baseUriStr.substring(posInit);
131 }
132
133 return baseUriStr;
134 }
135
136 /*
137 * @brief This function return the base URI without the host.
138 * Also all spaces are converted to %20.
139 */
140 public String getResourceBaseUri()
141 {
142 String baseUri = getResourceCompleteBaseUri();
143
144 if(baseUri != null)
145 {
146 // Remove host
147 int posEnd = baseUri.indexOf('/');
148
149 if(posEnd == -1)
150 return "";
151 else
152 return baseUri.substring(posEnd).replace(" ", "%20");
153 }
154
155 return null;
156 }
157
158 /*
159 * @brief This function return the base URI without the host.
160 * Also all spaces are converted to %20.
161 */
162 public String getResourceBaseUriWithoutLastBackslace()
163 {
164 String baseUri = getResourceBaseUri();
165
166 if(baseUri != null)
167 {
168 if(!baseUri.isEmpty() && baseUri.charAt(baseUri.length() - 1) == '/')
169 {
170 if(baseUri.length() > 1)
171 baseUri = baseUri.substring(0, baseUri.length() - 1);
172 else
173 baseUri = "";
174 }
175 return baseUri;
176 }
177
178 return null;
179 }
180
181 public String getResourceHost() {
182 Annotation path = getAnnotations().get("RESOURCES_BASE_URI");
183 String pathStr = path.getValue("value");
184
185 // Remove http://
186 int posInit = pathStr.indexOf("//");
187 if(posInit == -1)
188 posInit = 0;
189 else
190 posInit += 2;
191
192 // Remove path
193 int posEnd = pathStr.indexOf('/', posInit);
194
195 if(posEnd == -1)
196 posEnd = pathStr.length()-1;
197
198 return pathStr.substring(posInit, posEnd);
199 }
200
201 ////////// End RESTful block //////////
202
203 private Object m_parent = null;
204 }