| ParameterChecker.java |
1 /*
2 * Copyright 2000-2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.apache.wsrp4j.util;
18
19 import javax.xml.namespace.QName;
20
21 import oasis.names.tc.wsrp.v1.types.BlockingInteractionResponse;
22 import oasis.names.tc.wsrp.v1.types.ClonePortlet;
23 import oasis.names.tc.wsrp.v1.types.CookieProtocol;
24 import oasis.names.tc.wsrp.v1.types.DestroyFailed;
25 import oasis.names.tc.wsrp.v1.types.DestroyPortlets;
26 import oasis.names.tc.wsrp.v1.types.DestroyPortletsResponse;
27 import oasis.names.tc.wsrp.v1.types.GetMarkup;
28 import oasis.names.tc.wsrp.v1.types.GetPortletDescription;
29 import oasis.names.tc.wsrp.v1.types.GetPortletProperties;
30 import oasis.names.tc.wsrp.v1.types.GetPortletPropertyDescription;
31 import oasis.names.tc.wsrp.v1.types.GetServiceDescription;
32 import oasis.names.tc.wsrp.v1.types.InitCookie;
33 import oasis.names.tc.wsrp.v1.types.InteractionParams;
34 import oasis.names.tc.wsrp.v1.types.MarkupContext;
35 import oasis.names.tc.wsrp.v1.types.MarkupParams;
36 import oasis.names.tc.wsrp.v1.types.MarkupResponse;
37 import oasis.names.tc.wsrp.v1.types.MissingParametersFault;
38 import oasis.names.tc.wsrp.v1.types.ModifyRegistration;
39 import oasis.names.tc.wsrp.v1.types.PerformBlockingInteraction;
40 import oasis.names.tc.wsrp.v1.types.PortletContext;
41 import oasis.names.tc.wsrp.v1.types.PortletDescription;
42 import oasis.names.tc.wsrp.v1.types.PortletDescriptionResponse;
43 import oasis.names.tc.wsrp.v1.types.PortletPropertyDescriptionResponse;
44 import oasis.names.tc.wsrp.v1.types.PropertyList;
45 import oasis.names.tc.wsrp.v1.types.RegistrationContext;
46 import oasis.names.tc.wsrp.v1.types.RegistrationData;
47 import oasis.names.tc.wsrp.v1.types.ReleaseSessions;
48 import oasis.names.tc.wsrp.v1.types.Resource;
49 import oasis.names.tc.wsrp.v1.types.ResourceList;
50 import oasis.names.tc.wsrp.v1.types.RuntimeContext;
51 import oasis.names.tc.wsrp.v1.types.ServiceDescription;
52 import oasis.names.tc.wsrp.v1.types.SessionContext;
53 import oasis.names.tc.wsrp.v1.types.SetPortletProperties;
54 import oasis.names.tc.wsrp.v1.types.Templates;
55 import oasis.names.tc.wsrp.v1.types.UpdateResponse;
56 import oasis.names.tc.wsrp.v1.types.UserContext;
57
58 import org.apache.wsrp4j.log.LogManager;
59 import org.apache.wsrp4j.log.Logger;
60
61 /**
62 * This class validates the objects and their attributes used for the WSRP communication
63 * requests. The object and attribute tree is scanned including the 2nd level. This means,
64 * that the input object, it's attributes and ,if the attribute is itself an object, the
65 * subsequent object and It's attributes are also checked. The checking is done only for
66 * required (R) parameters in the WSRP specification. Optional (O) parameters are ignored.
67 * If a parameter is specified as 'nillable' in the WSRP specification, the check is
68 * performed if the value is 'not null'. On null value, no checking is done.
69 */
70 public class ParameterChecker {
71
72 // for logging and exception support
73 private Logger logger = LogManager.getLogManager().getLogger(
74 ParameterChecker.class);
75
76 /**
77 * Default Constructor
78 */
79 public ParameterChecker() {
80 }
81
82 /**
83 * @return true if we check
84 */
85 private boolean isCheckEnabled() {
86 if (logger.isLogging(Logger.TRACE_HIGH)) {
87 return true;
88 }
89 return false;
90 }
91
92 /**
93 * --- THIS IS THE REQUEST SECTION OF THE PARAMETER-CHECKER ---
94 */
95
96 /**
97 * Check the GetServiceDescritpion. The following attributes are mandatory:
98 *
99 * 1) RegistrationContext, only if available
100 * 2) String[] DesiredLocales, only if SendAllLocales == false
101 *
102 * @param request _getServiceDescription
103 *
104 * @throws MissingParametersFault
105 *
106 * @see GetServiceDescription
107 */
108 public void check(GetServiceDescription request)
109 throws MissingParametersFault {
110 if (isCheckEnabled()) {
111 // check ClonePortlet request object pointer
112 if (request instanceof GetServiceDescription) {
113
114 // check for registration context
115 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
116
117 }
118 else {
119 throwMissingParametersFault("Input object is not from type GetServiceDescription or is null");
120 }
121 }
122 }
123
124 /**
125 * Check the ModifyRegistration. The following attributes are mandatory:
126 *
127 * 1) RegistrationContext, only if available
128 * 2) RegistrationData
129 *
130 * @param request _modifyRegistration
131 *
132 * @throws MissingParametersFault
133 *
134 * @see ModifyRegistration
135 */
136 public void check(ModifyRegistration request)
137 throws MissingParametersFault {
138 if (isCheckEnabled()) {
139 // check ClonePortlet request object pointer
140 if (request instanceof ModifyRegistration) {
141
142 // check for registration context
143 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
144 check(request.getRegistrationData(), Constants.NILLABLE_FALSE);
145
146 }
147 else {
148 throwMissingParametersFault("Input object is not from type ModifyRegistration or is null");
149 }
150 }
151 }
152
153 /**
154 * Check the GetMarkup. The following attributes are mandatory:
155 *
156 * 1) RegistrationContext, only if available
157 * 2) PortletContext
158 * 3) RuntimeContext
159 * 4) UserContext, only if available
160 * 5) MarkupParams
161 *
162 * @param request getMarkup
163 *
164 * @throws MissingParametersFault
165 *
166 * @see GetMarkup
167 */
168 public void check(GetMarkup request) throws MissingParametersFault {
169 if (isCheckEnabled()) {
170 // check ClonePortlet request object pointer
171 if (request instanceof GetMarkup) {
172
173 // check for registration context
174 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
175 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
176 check(request.getRuntimeContext(), Constants.NILLABLE_FALSE);
177 check(request.getUserContext(), Constants.NILLABLE_TRUE);
178 check(request.getMarkupParams(), Constants.NILLABLE_FALSE);
179
180 }
181 else {
182 throwMissingParametersFault("Input object is not from type GetMarkup or is null");
183 }
184 }
185 }
186
187 /**
188 * Check the PerformBlockingInteraction. The following attributes are mandatory:
189 *
190 * 1) RegistrationContext, only if available
191 * 2) PortletContext
192 * 3) RuntimeContext
193 * 4) UserContext, only if available
194 * 5) MarkupParams
195 * 6) InteractionParams
196 *
197 * @param request _performBlockingInteraction
198 *
199 * @throws MissingParametersFault
200 *
201 * @see PerformBlockingInteraction
202 */
203 public void check(PerformBlockingInteraction request)
204 throws MissingParametersFault {
205 if (isCheckEnabled()) {
206 // check PerformBlockingInteraction request object pointer
207 if (request instanceof PerformBlockingInteraction) {
208
209 // check for registration context
210 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
211 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
212 check(request.getRuntimeContext(), Constants.NILLABLE_FALSE);
213 check(request.getUserContext(), Constants.NILLABLE_TRUE);
214 check(request.getMarkupParams(), Constants.NILLABLE_FALSE);
215 check(request.getInteractionParams(), Constants.NILLABLE_FALSE);
216
217 }
218 else {
219 throwMissingParametersFault("Input object is not from type PerformBlockingInteraction or is null");
220 }
221 }
222 }
223
224 /**
225 * Check the InitCookie. The following attributes are mandatory:
226 *
227 * 1) RegistrationContext, only if available
228 *
229 * @param request _initCookie
230 *
231 * @throws MissingParametersFault
232 *
233 * @see InitCookie
234 */
235 public void check(InitCookie request) throws MissingParametersFault {
236 if (isCheckEnabled()) {
237 // check InitCookie request object pointer
238 if (request instanceof InitCookie) {
239
240 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
241
242 }
243 else {
244
245 throwMissingParametersFault("Input object is not from type InitCookie or is null");
246 }
247 }
248 }
249
250 /**
251 * Parameter check for the GetPortletDescription object. The following attributes are mandatory
252 *
253 * 1) RegistrationContext, only if available
254 * 2) PortletContext
255 * 3) UserContext, only if available
256 *
257 * @param request _getPortletDescription
258 *
259 * @throws MissingParametersFault
260 *
261 * @see GetPortletDescription
262 */
263 public void check(GetPortletDescription request)
264 throws MissingParametersFault {
265 if (isCheckEnabled()) {
266 // check GetPortletDescription request object pointer
267 if (request instanceof GetPortletDescription) {
268 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
269 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
270 check(request.getUserContext(), Constants.NILLABLE_TRUE);
271
272 }
273 else {
274 throwMissingParametersFault("Input object is not from type GetPortletDescription or is null");
275 }
276 }
277 }
278
279 /**
280 * Parameter check for the ClonePortlet object. The following attributes are mandatory:
281 *
282 * 1) RegistrationContext, only if available
283 * 2) PortletContext
284 * 3) UserContext, only if available
285 *
286 * @param request _clonePortlet
287 *
288 * @throws MissingParametersFault
289 *
290 * @see ClonePortlet
291 */
292 public void check(ClonePortlet request) throws MissingParametersFault {
293 if (isCheckEnabled()) {
294 // check ClonePortlet request object pointer
295 if (request instanceof ClonePortlet) {
296
297 // check for registration context
298 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
299 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
300 check(request.getUserContext(), Constants.NILLABLE_TRUE);
301
302 }
303 else {
304
305 throwMissingParametersFault("Input object is not a ClonePortlet or is null");
306 }
307 }
308 }
309
310 /**
311 * Parameter check for the DestroyEntites object. The following attributes are mandatory:
312 *
313 * 1) RegistrationContext, only if available
314 * 2) PortletHandle
315 *
316 * @param request _destroyPortlets
317 *
318 * @throws MissingParametersFault
319 *
320 * @see DestroyPortlets
321 */
322 public void check(DestroyPortlets request) throws MissingParametersFault {
323 if (isCheckEnabled()) {
324 // check DestroyPortlet request object pointer
325 if (request instanceof DestroyPortlets) {
326
327 // check for registration context
328 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
329 check(request.getPortletHandles(), Constants.NILLABLE_FALSE);
330
331 }
332 else {
333
334 throwMissingParametersFault("Input object is not a DestroyPortlets or is null");
335 }
336 }
337 }
338
339 /**
340 * Parameter check for the SetPortletProperties object. The following attributes are mandatory:
341 *
342 * 1) RegistrationContext, only if available
343 * 2) PortletContext
344 * 3) UserContext, only if available
345 * 4) PropertyList
346 *
347 * @param request _setPortletProperties
348 *
349 * @throws MissingParametersFault
350 *
351 * @see SetPortletProperties
352 */
353 public void check(SetPortletProperties request)
354 throws MissingParametersFault {
355 if (isCheckEnabled()) {
356 // check SetPortletProperties request object pointer
357 if (request instanceof SetPortletProperties) {
358
359 // check for registration context
360 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
361 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
362 check(request.getUserContext(), Constants.NILLABLE_TRUE);
363 check(request.getPropertyList(), Constants.NILLABLE_FALSE);
364
365 }
366 else {
367
368 throwMissingParametersFault("Input object is not a SetPortletProperties or is null");
369 }
370 }
371 }
372
373 /**
374 * Parameter check for the SetPortletProperties object. The following attributes are mandatory:
375 *
376 * 1) RegistrationContext, only if available
377 * 2) PortletContext
378 * 3) UserContext, only if available
379 * 4) Names, only if available
380 *
381 * @param request _getPortletProperties
382 *
383 * @throws MissingParametersFault
384 *
385 * @see GetPortletPorperties
386 */
387 public void check(GetPortletProperties request)
388 throws MissingParametersFault {
389 if (isCheckEnabled()) {
390 // check GetPortletProperties request object pointer
391 if (request instanceof GetPortletProperties) {
392
393 // check for registration context
394 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
395 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
396 check(request.getUserContext(), Constants.NILLABLE_TRUE);
397 check(request.getNames(), Constants.NILLABLE_TRUE);
398
399 }
400 else {
401 throwMissingParametersFault("Input object is not a GetPortletProperties or is null");
402 }
403 }
404 }
405
406 /**
407 * Parameter check for the SetPortletProperties object. The following attributes are mandatory:
408 *
409 * 1) RegistrationContext, only if available
410 * 2) PortletContext
411 * 3) UserContext, only if available
412 *
413 * @param request _getPortletPropertyDescription
414 *
415 * @throws MissingParametersFault
416 *
417 * @see GetPortletPropertyDescription
418 */
419 public void check(GetPortletPropertyDescription request)
420 throws MissingParametersFault {
421 if (isCheckEnabled()) {
422 // check GetPortletPropertyDescription request object pointer
423 if (request instanceof GetPortletPropertyDescription) {
424
425 // check for registration context
426 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
427 check(request.getPortletContext(), Constants.NILLABLE_FALSE);
428 check(request.getUserContext(), Constants.NILLABLE_TRUE);
429
430 }
431 else {
432
433 throwMissingParametersFault("Input object is not a GetPortletPropertyDescription or is null");
434 }
435 }
436 }
437
438 /**
439 * Parameter check for the ReleaseSession object. The following attributes are mandatory:
440 *
441 * 1) RegistrationContext, only if available
442 * 2) String[] SessionHandles
443 *
444 * @param request _releaseSession
445 *
446 * @throws MissingParametersFault
447 *
448 * @see ReleaseSession
449 */
450 public void check(ReleaseSessions request) throws MissingParametersFault {
451 if (isCheckEnabled()) {
452 // check ReleaseSession request object pointer
453 if (request instanceof ReleaseSessions) {
454
455 // check for registration context
456 check(request.getRegistrationContext(), Constants.NILLABLE_TRUE);
457
458 // check sessionhandles array
459 check(request.getSessionIDs(), Constants.NILLABLE_FALSE);
460
461 }
462 else {
463
464 throwMissingParametersFault("Input object is not a ReleaseSession or is null");
465 }
466 }
467 }
468
469 /**
470 * --- THIS IS THE RESPONSE SECTION OF THE PARAMETER-CHECKER ---
471 */
472
473 /**
474 * Parameter check for the ServiceDescription object. The following attribute needs to be set:
475 *
476 * - requiresRegistration
477 *
478 * @param response ServiceDescription
479 *
480 * @throws MissingParametersFault
481 *
482 * @see ServiceDescription
483 */
484 public void check(ServiceDescription response)
485 throws MissingParametersFault {
486 if (isCheckEnabled()) {
487 // check ServiceDescription object pointer
488 if (response instanceof ServiceDescription) {
489
490 if (response != null) {
491
492 }
493 else if (response.getOfferedPortlets() != null) {
494
495 PortletDescription[] portletDesc = response
496 .getOfferedPortlets();
497
498 for (int i = 0; i < portletDesc.length; i++) {
499
500 check(portletDesc[i]);
501 }
502
503 }
504 else if (response.getRequiresInitCookie() != null) {
505
506 check(response.getRequiresInitCookie(), true);
507
508 }
509 else if (response.getResourceList() != null) {
510
511 check(response.getResourceList(), true);
512
513 }
514 else {
515
516 throwMissingParametersFault("No valid service description.");
517 }
518 }
519 else {
520
521 throwMissingParametersFault("No valid service description response found.");
522 }
523 }
524 }
525
526 /**
527 * Parameter check for the BlockingInteractionResponse object. The following attribute needs to be set:
528 *
529 * either
530 * - updateResponse
531 * or
532 * - redirectURL
533 *
534 * @param response BlockingInteractionResponse
535 *
536 * @throws MissingParametersFault
537 *
538 * @see BlockingInteractionResponse
539 */
540 public void check(BlockingInteractionResponse response)
541 throws MissingParametersFault {
542 if (isCheckEnabled()) {
543 // check BlockingInteractionResponse object pointer
544 if (response instanceof BlockingInteractionResponse) {
545
546 if (response.getUpdateResponse() != null
547 && response.getRedirectURL() == null) {
548
549 check(response.getUpdateResponse());
550
551 }
552 else if (response.getRedirectURL() != null
553 && response.getUpdateResponse() == null) {
554
555 // everything is fine
556
557 }
558 else {
559
560 throwMissingParametersFault("No valid blocking interaction response. UpdateResponse"
561 + "and redirect url are mutually exclusive");
562 }
563 }
564 else {
565
566 throwMissingParametersFault("No valid blocking interaction response found.");
567 }
568 }
569 }
570
571 /**
572 * Parameter check for the UpdateResponse object. The following attribute needs to be set:
573 *
574 * 1) SessionContext, only if available
575 * 2) PortletContext, only if available
576 * 3) MarkupContext, only if available
577 * 4) NavigationalState
578 *
579 * @param response UpdateResponse
580 *
581 * @throws MissingParametersFault
582 *
583 * @see UpdateResponse
584 */
585 private void check(UpdateResponse response) throws MissingParametersFault {
586
587 // check UpdateResponse object pointer
588 if (response instanceof UpdateResponse) {
589
590 check(response.getSessionContext(), Constants.NILLABLE_TRUE);
591 check(response.getPortletContext(), Constants.NILLABLE_TRUE);
592 check(response.getMarkupContext(), Constants.NILLABLE_TRUE);
593
594 // TODO: check for valid window states and portlet modes
595
596 }
597 else {
598
599 throwMissingParametersFault("No valid update response found.");
600 }
601 }
602
603 /**
604 * Parameter check for the MarkupResponse object. The following attribute needs to be set:
605 *
606 * 1) MarkupContext
607 * 2) SessionContext, only if available
608 *
609 * @param response MarkupResponse
610 *
611 * @throws MissingParametersFault
612 *
613 * @see MarkupResponse
614 */
615 public void check(MarkupResponse response) throws MissingParametersFault {
616 if (isCheckEnabled()) {
617 // check MarkupResponse object pointer
618 if (response instanceof MarkupResponse) {
619
620 check(response.getMarkupContext(), Constants.NILLABLE_FALSE);
621 check(response.getSessionContext(), Constants.NILLABLE_TRUE);
622
623 }
624 else {
625
626 throwMissingParametersFault("No valid markup response found.");
627 }
628 }
629 }
630
631 /**
632 * Validates the PortletDescriptionResponse object
633 *
634 * 1) PortletDescription
635 * 2) ResourceList, only if available
636 *
637 * @param response PortletDescriptionResponse
638 *
639 * @throws MissingParametersFault
640 *
641 * @see PortletDescriptionResponse
642 */
643 public void check(PortletDescriptionResponse response)
644 throws MissingParametersFault {
645 if (isCheckEnabled()) {
646 // check MarkupResponse object pointer
647 if (response instanceof PortletDescriptionResponse) {
648
649 check(response.getPortletDescription());
650 check(response.getResourceList(), Constants.NILLABLE_TRUE);
651
652 }
653 else {
654
655 throwMissingParametersFault("No valid PortletDescriptionResponse response found.");
656 }
657 }
658 }
659
660 /**
661 * Validates the PortletPropertyDescriptionResponse object
662 *
663 * 1) ResourceList
664 *
665 * @param response PortletPropertyDescriptionResponse
666 *
667 * @throws MissingParametersFault
668 *
669 * @see PortletPropertyDescriptionResponse
670 */
671 public void check(PortletPropertyDescriptionResponse response)
672 throws MissingParametersFault {
673 if (isCheckEnabled()) {
674 // check MarkupResponse object pointer
675 if (response instanceof PortletPropertyDescriptionResponse) {
676
677 // TODO: check ModelDescription
678
679 check(response.getResourceList(), Constants.NILLABLE_TRUE);
680
681 }
682 else {
683
684 throwMissingParametersFault("No valid PortletPropertyDescriptionResponse response found.");
685 }
686 }
687 }
688
689 /**
690 * Validates the DestroyPortletsResponse object
691 *
692 * 1) DestroyFailed[], only if available
693 *
694 * @param response DestroyPortletResponse
695 *
696 * @throws MissingParametersFault
697 *
698 * @see DestroyPortletsResponse
699 */
700 public void check(DestroyPortletsResponse response)
701 throws MissingParametersFault {
702 if (isCheckEnabled()) {
703 // check MarkupResponse object pointer
704 if (response instanceof DestroyPortletsResponse) {
705
706 check(response.getDestroyFailed(), Constants.NILLABLE_TRUE);
707
708 }
709 else {
710
711 throwMissingParametersFault("No valid PortletDescriptionResponse response found.");
712 }
713 }
714 }
715
716 /**
717 * --- THIS IS THE AUXILLARY SECTION OF THE PARAMETER-CHECKER ---
718 */
719
720 /**
721 * Parameter check for the PortletDescription object. The following parameter needs to be set:
722 *
723 * 1) portletHandle
724 * 2) markupType[]
725 *
726 * @param element PortletDescription
727 *
728 * @throws MissingParametersFault
729 *
730 * @see PortletDescription
731 */
732 public void check(PortletDescription element) throws MissingParametersFault {
733 if (isCheckEnabled()) {
734 // check PortletDescription object pointer
735 if (element instanceof PortletDescription) {
736
737 if (element.getPortletHandle() == null) {
738 throwMissingParametersFault("A portlet handle has to be set in the portlet description.");
739 }
740
741 if (element.getMarkupTypes() == null) {
742 throwMissingParametersFault("Markup types have to be defined in the portlet description.");
743 }
744
745 }
746 else {
747
748 throwMissingParametersFault("No valid portlet description found.");
749 }
750 }
751 }
752
753 /**
754 * Parameter check for the PortletDescription object. The following parameter needs to be set:
755 *
756 * all templates...
757 *
758 * @param element Templates
759 *
760 * @throws MissingParametersFault
761 *
762 * @see PortletDescription
763 */
764 public void check(Templates element) throws MissingParametersFault {
765 if (isCheckEnabled()) {
766 // check PortletDescription object pointer
767 if (element instanceof Templates) {
768 if (element.getDefaultTemplate() == null) {
769 throwMissingParametersFault("DefaultTemplate has not been set!");
770 }
771
772 if (element.getSecureDefaultTemplate() == null) {
773 throwMissingParametersFault("SecureDefaultTemplate Template has not been set!");
774 }
775 }
776 else {
777 throwMissingParametersFault("Consumer has to provide templates!");
778 }
779 }
780 }
781
782 /**
783 * Parameter check for the SessionContext object. The following parameter needs to be set:
784 *
785 * 1) sessionID
786 * 2) expire
787 *
788 * @param context SessionContext
789 * @param nillable boolean true, if the SessionContext can be nill
790 * false, if the SessionContext is not nillable
791 *
792 * @throws MissingParametersFault
793 *
794 * @see SessionContext
795 */
796 private void check(SessionContext context, boolean nillable)
797 throws MissingParametersFault {
798 if (context != null) {
799 if (context.getSessionID() == null) {
800 throwMissingParametersFault("No valid session context found. No session handle set.");
801 }
802 else {
803 // check, if the ID is valid, instance and length
804 //TODO: activate this, if ID is no longer as string declared!
805 //check(context.getSessionID());
806 }
807 if (context.getExpires() == 0) {
808 throwMissingParametersFault("No valid session context found. No session expire set.");
809 }
810 }
811 else {
812 if (!nillable) {
813 throwMissingParametersFault("No valid session context found.");
814 }
815 }
816 }
817
818 /**
819 * Parameter check for the MarkupContext object. The following parameter needs to be set:
820 *
821 * 1) markupBinary and markupString mutually exclusive, if markupType is available
822 * 2) locale, if markupType is available
823 *
824 * @param context MarkupContext
825 * @param nillable boolean true, if the MarkupContext can be nill
826 * false, if the MarkupContext is not nillable
827 *
828 * @throws MissingParametersFault
829 *
830 * @see MarkupContext
831 */
832 private void check(MarkupContext context, boolean nillable)
833 throws MissingParametersFault {
834 if (context != null) {
835 boolean bMarkupBinary = false, bMarkupString = false;
836 if (context.getMarkupBinary() != null) {
837 bMarkupBinary = true;
838 }
839 if (context.getMarkupString() != null) {
840 bMarkupString = true;
841 }
842
843 // XOR of markupBinary and markupString
844 if (bMarkupBinary ^ bMarkupString) {
845 if (context.getMimeType() == null) {
846 throwMissingParametersFault("MimeType not set in MarkupContext.");
847 }
848 else {
849 if (context.getLocale() == null) {
850 throwMissingParametersFault("Locale not set in MarkupContext.");
851 }
852 }
853 }
854 }
855 else {
856 if (!nillable) {
857 throwMissingParametersFault("No valid markup context found.");
858 }
859 }
860 }
861
862 /**
863 * Check the PropertyList. The following attributes are mandatory:
864 *
865 * 1) Property[]
866 *
867 * @param propertyList PropertyList
868 * @param nillable boolean true, if the PropertyList can be nill
869 * false, if the PropertyList is not nillable
870 *
871 * @throws MissingParametersFault
872 *
873 * @see PropertyList
874 */
875 public void check(PropertyList propertyList, boolean nillable)
876 throws MissingParametersFault {
877 if (isCheckEnabled()) {
878 // check only, if object not null, otherwise ignore. Object is defined as nillable
879 if (propertyList != null) {
880 // property is mandatory
881 if (propertyList.getProperties() == null) {
882 throwMissingParametersFault("PropertyList[] in PropertyList is null");
883 }
884
885 }
886 else {
887 // check if nillable is allowed
888 if (nillable == false) {
889 throwMissingParametersFault("PropertyList object is null");
890 }
891 }
892 }
893 }
894
895 /**
896 * Check the RegistrationData. The following attributes are mandatory:
897 *
898 * 1) ConsumerName
899 * 2) ConsumerAgent
900 *
901 * @param registrationData RegistrationData
902 * @param nillable boolean true, if the RegistrationData can be nill
903 * false, if the RegistrationData is not nillable
904 *
905 * @throws MissingParametersFault
906 *
907 * @see RegistrationData
908 */
909 public void check(RegistrationData registrationData, boolean nillable)
910 throws MissingParametersFault {
911 if (isCheckEnabled()) {
912 // check only, if object not null, otherwise ignore. Object is defined as nillable
913 if (registrationData != null) {
914 // check the consumer name, is mandatory
915 if (registrationData.getConsumerName() == null) {
916 throwMissingParametersFault("ConsumerName in RegistrationData is null");
917 }
918 // check the consumer agent, is mandatory
919 if (registrationData.getConsumerAgent() == null) {
920 throwMissingParametersFault("ConsumerAgent in RegistrationData is null");
921 }
922
923 }
924 else {
925 // if registrationcontext is null, check if nillable is allowed
926 if (nillable == false) {
927 throwMissingParametersFault("RegistrationData object is null");
928 }
929 }
930 }
931 }
932
933 /**
934 * Check a string array. The following attributes are mandatory:
935 *
936 * 1) must be a string array
937 * 2) must have a array.length > 0
938 *
939 * @param array String[]
940 *
941 * @param nillable boolean true, if the String[] can be nill
942 * false, if the String[] is not nillable
943 *
944 *
945 *
946 * @throws MissingParametersFault
947 *
948 * @see String
949 */
950 private void check(String[] array, boolean nillable)
951 throws MissingParametersFault {
952 // check only, if object not null, otherwise ignore. Object is defined as nillable
953 if (array != null) {
954 // check the array
955 if (array.length == 0) {
956 throwMissingParametersFault("String[] array length is zero (0)");
957 }
958 }
959 else {
960 // if array is null, check if nillable is allowed
961 if (nillable == false) {
962 throwMissingParametersFault("String array[] object is null");
963 }
964 }
965 }
966
967 /**
968 * Check the InteractionParams. The following attributes are mandatory:
969 *
970 * 1) PortletStateChange
971 *
972 * @param interactionParams InteractionParams
973 * @param nillable boolean true, if the InteractionParams can be nill
974 * false, if the InteractionParams is not nillable
975 *
976 *
977 * @throws MissingParametersFault
978 *
979 * @see InteractionParams
980 */
981 private void check(InteractionParams interactionParams, boolean nillable)
982 throws MissingParametersFault {
983 // check only, if object not null, otherwise ignore. Object is defined as nillable
984 if (interactionParams != null) {
985 // check the portletHandle, is mandatory
986 if (interactionParams.getPortletStateChange() == null) {
987 throwMissingParametersFault("PortletStateChange in InteractionParams is null");
988 }
989 }
990 else {
991 // if registrationcontext is null, check if nillable is allowed
992 if (nillable == false) {
993 throwMissingParametersFault("InteractionParams object is null");
994 }
995 }
996 }
997
998 /**
999 * Check the RegistrationContext. The following attributes are mandatory:
1000 *
1001 * 1) RegistrationHandle
1002 *
1003 * @param registrationContext RegistrationContext
1004 *
1005 * @param nillable boolean true, if the RegistrationContext can be nill
1006 * false, if the RegistrationContext is not nillable
1007 *
1008 *
1009 * @throws MissingParametersFault
1010 *
1011 * @see RegistrationContext
1012 */
1013 public void check(RegistrationContext registrationContext, boolean nillable)
1014 throws MissingParametersFault {
1015 if (isCheckEnabled()) {
1016 // check only, if object not null, otherwise ignore. Object is defined as nillable
1017 if (registrationContext != null) {
1018 // check the registrationHandle, is mandatory
1019 if (registrationContext.getRegistrationHandle() == null) {
1020 throwMissingParametersFault("RegistrationHandle in RegistrationContext is null");
1021 }
1022 }
1023 else {
1024 // if registrationcontext is null, check if nillable is allowed
1025 if (nillable == false) {
1026 throwMissingParametersFault("RegistrationContext object is null");
1027 }
1028 }
1029 }
1030 }
1031
1032 /**
1033 * Check the PortletContext. The following attributes are mandatory:
1034 *
1035 * 1) PortletHandle
1036 *
1037 * @param portletContext PortletContext
1038 *
1039 * @param nillable boolean true, if the PortletContext can be nill
1040 * false, if the PortletContext is not nillable
1041 *
1042 * @throws MissingParametersFault
1043 *
1044 * @see PortletContext
1045 */
1046 public void check(PortletContext portletContext, boolean nillable)
1047 throws MissingParametersFault {
1048 if (isCheckEnabled()) {
1049 // check only, if object not null, otherwise ignore. Object is defined as nillable
1050 if (portletContext != null) {
1051 // check the portletHandle, is mandatory
1052 if (portletContext.getPortletHandle() == null) {
1053 throwMissingParametersFault("PortletHandle in PortletContext is null");
1054 }
1055 }
1056 else {
1057 // if registrationcontext is null, check if nillable is allowed
1058 if (nillable == false) {
1059 throwMissingParametersFault("PortletContext object is null");
1060 }
1061 }
1062 }
1063 }
1064
1065 /**
1066 * Check the RuntimeContext. The following attributes are mandatory:
1067 *
1068 * 1) UserAuthentication
1069 * 2) PortletInstanceKey
1070 *
1071 * @param runtimeContext RuntimeContext
1072 *
1073 * @param nillable boolean true, if the RuntimeContext can be nill
1074 * false, if the RuntimeContext is not nillable
1075 *
1076 * @throws MissingParametersFault
1077 *
1078 * @see RuntimeContext
1079 */
1080 private void check(RuntimeContext runtimeContext, boolean nillable)
1081 throws MissingParametersFault {
1082 // check only, if object not null, otherwise ignore. Object is defined as nillable
1083 if (runtimeContext != null) {
1084 // check the userAuthentication, is mandatory
1085 if (runtimeContext.getUserAuthentication() == null) {
1086 throwMissingParametersFault("UserAuthentication in RuntimeContext is null");
1087 }
1088
1089 // check the portletHandle, is mandatory
1090 if (runtimeContext.getPortletInstanceKey() != null) {
1091 //TODO: activate this, if the string is changed to key type
1092 //check(runtimeContext.getPortletInstanceKey());
1093 }
1094 }
1095 else {
1096 // if registrationcontext is null, check if nillable is allowed
1097 if (nillable == false) {
1098 throwMissingParametersFault("RuntimeContext object is null");
1099 }
1100 }
1101 }
1102
1103 /**
1104 * Validates the DestroyFailed Array. If DestroyFailed objects are available,
1105 * they are checked for their content.
1106 *
1107 * @param destroyFailedArray DestroyFailed[]
1108 *
1109 * @param nillable boolean true, if the DestroyFailed[] can be nill
1110 * false, if the DestroyFailed[] is not nillable
1111 *
1112 */
1113 private void check(DestroyFailed[] destroyFailedArray, boolean nillable)
1114 throws MissingParametersFault {
1115 // check only, if object not null, otherwise ignore. Object is defined as nillable
1116 if (destroyFailedArray != null) {
1117 if (destroyFailedArray.length > 0) {
1118 for (int x = 0; x < destroyFailedArray.length; x++) {
1119 // mandatory
1120 if (destroyFailedArray[x].getPortletHandle() == null) {
1121 throwMissingParametersFault("Missing Portlet handle in DestroyFailed object.");
1122 }
1123
1124 // mandatory
1125 if (destroyFailedArray[x].getReason() == null) {
1126 throwMissingParametersFault("Missing Reason in DestroyFailed object.");
1127 }
1128 }
1129 }
1130 else {
1131 throwMissingParametersFault("DestroyFailedArray length is zero (0).");
1132 }
1133 }
1134 else {
1135 // if destroyFailedArray is null, check if nillable is allowed
1136 if (nillable == false) {
1137 throwMissingParametersFault("DestroyFailed[] object is null");
1138 }
1139 }
1140 }
1141
1142 /**
1143 * Check the UserContext. The following attributes are mandatory:
1144 *
1145 * 1) UserContextKey
1146 *
1147 * @param userContext UserContext
1148 * @param nillable boolean true, if the UserContext can be nill
1149 * false, if the UserContext is not nillable
1150 *
1151 *
1152 * @throws MissingParametersFault
1153 *
1154 * @see UserContext
1155 */
1156 private void check(UserContext userContext, boolean nillable)
1157 throws MissingParametersFault {
1158 // check only, if object not null, otherwise ignore. Object is defined as nillable
1159 if (userContext != null) {
1160 // check the UserContextKey, is mandatory
1161 if (userContext.getUserContextKey() == null) {
1162 throwMissingParametersFault("UserContextKey in UserContext is null");
1163 }
1164 }
1165 else {
1166 // if registrationcontext is null, check if nillable is allowed
1167 if (nillable == false) {
1168 throwMissingParametersFault("UserContext object is null");
1169 }
1170 }
1171 }
1172
1173 /**
1174 * Validates the ResourceList object for available resources.
1175 *
1176 * @param resourceList
1177 * @param nillable, true if null is allowed
1178 *
1179 * @throws MissingParametersFault
1180 */
1181 private void check(ResourceList resourceList, boolean nillable)
1182 throws MissingParametersFault {
1183 // check only, if object not null.
1184 if (resourceList != null) {
1185 // check for Resources, it's mandatory
1186 if (resourceList.getResources() == null) {
1187 throwMissingParametersFault("Resource[] is null");
1188 }
1189 else {
1190 Resource[] resourceArray = resourceList.getResources();
1191 if (resourceArray.length < 1) {
1192 throwMissingParametersFault("ResourceArray length is zero (0).");
1193 }
1194 }
1195 }
1196 else {
1197 // if registrationcontext is null, check if nillable is allowed
1198 if (nillable == false) {
1199 throwMissingParametersFault("ResourceList object is null");
1200 }
1201 }
1202 }
1203
1204 /**
1205 * Validates the CookieProtocol object
1206 *
1207 * @param requiresInit
1208 * @param nillable, true if null is allowed
1209 *
1210 * @throws MissingParametersFault
1211 */
1212 private void check(CookieProtocol requiresInit, boolean nillable)
1213 throws MissingParametersFault {
1214 // check only, if object not null.
1215 if (requiresInit != null) {
1216 if (requiresInit.toString().equals(CookieProtocol._none)) {
1217 }
1218 else if (requiresInit.toString().equals(CookieProtocol._perGroup)) {
1219 }
1220 else if (requiresInit.toString().equals(CookieProtocol._perUser)) {
1221 }
1222 else {
1223 throwMissingParametersFault("Invalid value ("
1224 + requiresInit.toString()
1225 + ") of CookieProtocol object.");
1226 }
1227 }
1228 else {
1229 // if requiresInit is null, check if nillable is allowed
1230 if (nillable == false) {
1231 throwMissingParametersFault("RequiresInitCookie object is null");
1232 }
1233 }
1234 }
1235
1236 /**
1237 * Check the MarkupParams. The following attributes are mandatory:
1238 *
1239 * 1) ClientData
1240 * 2) Locale
1241 * 3) MimeType
1242 * 4) Mode
1243 * 5) WindowState
1244 *
1245 * @param markupParams MarkupParams
1246 *
1247 * @param nillable boolean true, if the MarkupParams can be nill
1248 * false, if the MarkupParams is not nillable
1249 *
1250 *
1251 * @throws MissingParametersFault
1252 *
1253 * @see MarkupParams
1254 */
1255 private void check(MarkupParams markupParams, boolean nillable)
1256 throws MissingParametersFault {
1257 // check only, if object not null, otherwise ignore. Object is defined as nillable
1258 if (markupParams != null) {
1259 // check ClientData, is mandatory
1260 if (markupParams.getClientData() == null) {
1261 throwMissingParametersFault("ClientData in MarkupParams is null");
1262 }
1263 if (markupParams.getLocales() == null) {
1264 throwMissingParametersFault("Locales in MarkupParams is null");
1265 }
1266 if (markupParams.getMimeTypes() == null) {
1267 throwMissingParametersFault("MimeTypes in MarkupParams is null");
1268 }
1269 if (markupParams.getMode() == null) {
1270 throwMissingParametersFault("Mode in MarkupParams is null");
1271 }
1272 if (markupParams.getWindowState() == null) {
1273 throwMissingParametersFault("WindowState in MarkupParams is null");
1274 }
1275 }
1276 else {
1277 // if registrationcontext is null, check if nillable is allowed
1278 if (nillable == false) {
1279 throwMissingParametersFault("MarkupParams object is null");
1280 }
1281 }
1282 }
1283
1284 /**
1285 * Creates and throws a MissingParametersFault exception
1286 *
1287 * @param msg String error message
1288 *
1289 * @throws MissingParametersFault
1290 *
1291 * @see MissingParameterFault
1292 */
1293 private void throwMissingParametersFault(String msg)
1294 throws MissingParametersFault {
1295 MissingParametersFault e = new MissingParametersFault();
1296 e.setFaultCode(new QName("urn:oasis:names:tc:wsrp:v1:types",
1297 "Interface.MissingParameters"));
1298 e.setFaultString(msg);
1299 throw e;
1300 }
1301}