0001: /*
0002: * Copyright 2000-2001,2004 The Apache Software Foundation.
0003: *
0004: * Licensed under the Apache License, Version 2.0 (the "License");
0005: * you may not use this file except in compliance with the License.
0006: * You may obtain a copy of the License at
0007: *
0008: * http://www.apache.org/licenses/LICENSE-2.0
0009: *
0010: * Unless required by applicable law or agreed to in writing, software
0011: * distributed under the License is distributed on an "AS IS" BASIS,
0012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013: * See the License for the specific language governing permissions and
0014: * limitations under the License.
0015: */
0016:
0017: package org.apache.wsrp4j.util;
0018:
0019: import javax.xml.namespace.QName;
0020:
0021: import oasis.names.tc.wsrp.v1.types.BlockingInteractionResponse;
0022: import oasis.names.tc.wsrp.v1.types.ClonePortlet;
0023: import oasis.names.tc.wsrp.v1.types.CookieProtocol;
0024: import oasis.names.tc.wsrp.v1.types.DestroyFailed;
0025: import oasis.names.tc.wsrp.v1.types.DestroyPortlets;
0026: import oasis.names.tc.wsrp.v1.types.DestroyPortletsResponse;
0027: import oasis.names.tc.wsrp.v1.types.GetMarkup;
0028: import oasis.names.tc.wsrp.v1.types.GetPortletDescription;
0029: import oasis.names.tc.wsrp.v1.types.GetPortletProperties;
0030: import oasis.names.tc.wsrp.v1.types.GetPortletPropertyDescription;
0031: import oasis.names.tc.wsrp.v1.types.GetServiceDescription;
0032: import oasis.names.tc.wsrp.v1.types.InitCookie;
0033: import oasis.names.tc.wsrp.v1.types.InteractionParams;
0034: import oasis.names.tc.wsrp.v1.types.MarkupContext;
0035: import oasis.names.tc.wsrp.v1.types.MarkupParams;
0036: import oasis.names.tc.wsrp.v1.types.MarkupResponse;
0037: import oasis.names.tc.wsrp.v1.types.MissingParametersFault;
0038: import oasis.names.tc.wsrp.v1.types.ModifyRegistration;
0039: import oasis.names.tc.wsrp.v1.types.PerformBlockingInteraction;
0040: import oasis.names.tc.wsrp.v1.types.PortletContext;
0041: import oasis.names.tc.wsrp.v1.types.PortletDescription;
0042: import oasis.names.tc.wsrp.v1.types.PortletDescriptionResponse;
0043: import oasis.names.tc.wsrp.v1.types.PortletPropertyDescriptionResponse;
0044: import oasis.names.tc.wsrp.v1.types.PropertyList;
0045: import oasis.names.tc.wsrp.v1.types.RegistrationContext;
0046: import oasis.names.tc.wsrp.v1.types.RegistrationData;
0047: import oasis.names.tc.wsrp.v1.types.ReleaseSessions;
0048: import oasis.names.tc.wsrp.v1.types.Resource;
0049: import oasis.names.tc.wsrp.v1.types.ResourceList;
0050: import oasis.names.tc.wsrp.v1.types.RuntimeContext;
0051: import oasis.names.tc.wsrp.v1.types.ServiceDescription;
0052: import oasis.names.tc.wsrp.v1.types.SessionContext;
0053: import oasis.names.tc.wsrp.v1.types.SetPortletProperties;
0054: import oasis.names.tc.wsrp.v1.types.Templates;
0055: import oasis.names.tc.wsrp.v1.types.UpdateResponse;
0056: import oasis.names.tc.wsrp.v1.types.UserContext;
0057:
0058: import org.apache.wsrp4j.log.LogManager;
0059: import org.apache.wsrp4j.log.Logger;
0060:
0061: /**
0062: * This class validates the objects and their attributes used for the WSRP communication
0063: * requests. The object and attribute tree is scanned including the 2nd level. This means,
0064: * that the input object, it's attributes and ,if the attribute is itself an object, the
0065: * subsequent object and It's attributes are also checked. The checking is done only for
0066: * required (R) parameters in the WSRP specification. Optional (O) parameters are ignored.
0067: * If a parameter is specified as 'nillable' in the WSRP specification, the check is
0068: * performed if the value is 'not null'. On null value, no checking is done.
0069: */
0070: public class ParameterChecker {
0071:
0072: // for logging and exception support
0073: private Logger logger = LogManager.getLogManager().getLogger(
0074: ParameterChecker.class);
0075:
0076: /**
0077: * Default Constructor
0078: */
0079: public ParameterChecker() {
0080: }
0081:
0082: /**
0083: * @return true if we check
0084: */
0085: private boolean isCheckEnabled() {
0086: if (logger.isLogging(Logger.TRACE_HIGH)) {
0087: return true;
0088: }
0089: return false;
0090: }
0091:
0092: /**
0093: * --- THIS IS THE REQUEST SECTION OF THE PARAMETER-CHECKER ---
0094: */
0095:
0096: /**
0097: * Check the GetServiceDescritpion. The following attributes are mandatory:
0098: *
0099: * 1) RegistrationContext, only if available
0100: * 2) String[] DesiredLocales, only if SendAllLocales == false
0101: *
0102: * @param request _getServiceDescription
0103: *
0104: * @throws MissingParametersFault
0105: *
0106: * @see GetServiceDescription
0107: */
0108: public void check(GetServiceDescription request)
0109: throws MissingParametersFault {
0110: if (isCheckEnabled()) {
0111: // check ClonePortlet request object pointer
0112: if (request instanceof GetServiceDescription) {
0113:
0114: // check for registration context
0115: check(request.getRegistrationContext(),
0116: Constants.NILLABLE_TRUE);
0117:
0118: } else {
0119: throwMissingParametersFault("Input object is not from type GetServiceDescription or is null");
0120: }
0121: }
0122: }
0123:
0124: /**
0125: * Check the ModifyRegistration. The following attributes are mandatory:
0126: *
0127: * 1) RegistrationContext, only if available
0128: * 2) RegistrationData
0129: *
0130: * @param request _modifyRegistration
0131: *
0132: * @throws MissingParametersFault
0133: *
0134: * @see ModifyRegistration
0135: */
0136: public void check(ModifyRegistration request)
0137: throws MissingParametersFault {
0138: if (isCheckEnabled()) {
0139: // check ClonePortlet request object pointer
0140: if (request instanceof ModifyRegistration) {
0141:
0142: // check for registration context
0143: check(request.getRegistrationContext(),
0144: Constants.NILLABLE_TRUE);
0145: check(request.getRegistrationData(),
0146: Constants.NILLABLE_FALSE);
0147:
0148: } else {
0149: throwMissingParametersFault("Input object is not from type ModifyRegistration or is null");
0150: }
0151: }
0152: }
0153:
0154: /**
0155: * Check the GetMarkup. The following attributes are mandatory:
0156: *
0157: * 1) RegistrationContext, only if available
0158: * 2) PortletContext
0159: * 3) RuntimeContext
0160: * 4) UserContext, only if available
0161: * 5) MarkupParams
0162: *
0163: * @param request getMarkup
0164: *
0165: * @throws MissingParametersFault
0166: *
0167: * @see GetMarkup
0168: */
0169: public void check(GetMarkup request) throws MissingParametersFault {
0170: if (isCheckEnabled()) {
0171: // check ClonePortlet request object pointer
0172: if (request instanceof GetMarkup) {
0173:
0174: // check for registration context
0175: check(request.getRegistrationContext(),
0176: Constants.NILLABLE_TRUE);
0177: check(request.getPortletContext(),
0178: Constants.NILLABLE_FALSE);
0179: check(request.getRuntimeContext(),
0180: Constants.NILLABLE_FALSE);
0181: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0182: check(request.getMarkupParams(),
0183: Constants.NILLABLE_FALSE);
0184:
0185: } else {
0186: throwMissingParametersFault("Input object is not from type GetMarkup or is null");
0187: }
0188: }
0189: }
0190:
0191: /**
0192: * Check the PerformBlockingInteraction. The following attributes are mandatory:
0193: *
0194: * 1) RegistrationContext, only if available
0195: * 2) PortletContext
0196: * 3) RuntimeContext
0197: * 4) UserContext, only if available
0198: * 5) MarkupParams
0199: * 6) InteractionParams
0200: *
0201: * @param request _performBlockingInteraction
0202: *
0203: * @throws MissingParametersFault
0204: *
0205: * @see PerformBlockingInteraction
0206: */
0207: public void check(PerformBlockingInteraction request)
0208: throws MissingParametersFault {
0209: if (isCheckEnabled()) {
0210: // check PerformBlockingInteraction request object pointer
0211: if (request instanceof PerformBlockingInteraction) {
0212:
0213: // check for registration context
0214: check(request.getRegistrationContext(),
0215: Constants.NILLABLE_TRUE);
0216: check(request.getPortletContext(),
0217: Constants.NILLABLE_FALSE);
0218: check(request.getRuntimeContext(),
0219: Constants.NILLABLE_FALSE);
0220: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0221: check(request.getMarkupParams(),
0222: Constants.NILLABLE_FALSE);
0223: check(request.getInteractionParams(),
0224: Constants.NILLABLE_FALSE);
0225:
0226: } else {
0227: throwMissingParametersFault("Input object is not from type PerformBlockingInteraction or is null");
0228: }
0229: }
0230: }
0231:
0232: /**
0233: * Check the InitCookie. The following attributes are mandatory:
0234: *
0235: * 1) RegistrationContext, only if available
0236: *
0237: * @param request _initCookie
0238: *
0239: * @throws MissingParametersFault
0240: *
0241: * @see InitCookie
0242: */
0243: public void check(InitCookie request) throws MissingParametersFault {
0244: if (isCheckEnabled()) {
0245: // check InitCookie request object pointer
0246: if (request instanceof InitCookie) {
0247:
0248: check(request.getRegistrationContext(),
0249: Constants.NILLABLE_TRUE);
0250:
0251: } else {
0252:
0253: throwMissingParametersFault("Input object is not from type InitCookie or is null");
0254: }
0255: }
0256: }
0257:
0258: /**
0259: * Parameter check for the GetPortletDescription object. The following attributes are mandatory
0260: *
0261: * 1) RegistrationContext, only if available
0262: * 2) PortletContext
0263: * 3) UserContext, only if available
0264: *
0265: * @param request _getPortletDescription
0266: *
0267: * @throws MissingParametersFault
0268: *
0269: * @see GetPortletDescription
0270: */
0271: public void check(GetPortletDescription request)
0272: throws MissingParametersFault {
0273: if (isCheckEnabled()) {
0274: // check GetPortletDescription request object pointer
0275: if (request instanceof GetPortletDescription) {
0276: check(request.getRegistrationContext(),
0277: Constants.NILLABLE_TRUE);
0278: check(request.getPortletContext(),
0279: Constants.NILLABLE_FALSE);
0280: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0281:
0282: } else {
0283: throwMissingParametersFault("Input object is not from type GetPortletDescription or is null");
0284: }
0285: }
0286: }
0287:
0288: /**
0289: * Parameter check for the ClonePortlet object. The following attributes are mandatory:
0290: *
0291: * 1) RegistrationContext, only if available
0292: * 2) PortletContext
0293: * 3) UserContext, only if available
0294: *
0295: * @param request _clonePortlet
0296: *
0297: * @throws MissingParametersFault
0298: *
0299: * @see ClonePortlet
0300: */
0301: public void check(ClonePortlet request)
0302: throws MissingParametersFault {
0303: if (isCheckEnabled()) {
0304: // check ClonePortlet request object pointer
0305: if (request instanceof ClonePortlet) {
0306:
0307: // check for registration context
0308: check(request.getRegistrationContext(),
0309: Constants.NILLABLE_TRUE);
0310: check(request.getPortletContext(),
0311: Constants.NILLABLE_FALSE);
0312: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0313:
0314: } else {
0315:
0316: throwMissingParametersFault("Input object is not a ClonePortlet or is null");
0317: }
0318: }
0319: }
0320:
0321: /**
0322: * Parameter check for the DestroyEntites object. The following attributes are mandatory:
0323: *
0324: * 1) RegistrationContext, only if available
0325: * 2) PortletHandle
0326: *
0327: * @param request _destroyPortlets
0328: *
0329: * @throws MissingParametersFault
0330: *
0331: * @see DestroyPortlets
0332: */
0333: public void check(DestroyPortlets request)
0334: throws MissingParametersFault {
0335: if (isCheckEnabled()) {
0336: // check DestroyPortlet request object pointer
0337: if (request instanceof DestroyPortlets) {
0338:
0339: // check for registration context
0340: check(request.getRegistrationContext(),
0341: Constants.NILLABLE_TRUE);
0342: check(request.getPortletHandles(),
0343: Constants.NILLABLE_FALSE);
0344:
0345: } else {
0346:
0347: throwMissingParametersFault("Input object is not a DestroyPortlets or is null");
0348: }
0349: }
0350: }
0351:
0352: /**
0353: * Parameter check for the SetPortletProperties object. The following attributes are mandatory:
0354: *
0355: * 1) RegistrationContext, only if available
0356: * 2) PortletContext
0357: * 3) UserContext, only if available
0358: * 4) PropertyList
0359: *
0360: * @param request _setPortletProperties
0361: *
0362: * @throws MissingParametersFault
0363: *
0364: * @see SetPortletProperties
0365: */
0366: public void check(SetPortletProperties request)
0367: throws MissingParametersFault {
0368: if (isCheckEnabled()) {
0369: // check SetPortletProperties request object pointer
0370: if (request instanceof SetPortletProperties) {
0371:
0372: // check for registration context
0373: check(request.getRegistrationContext(),
0374: Constants.NILLABLE_TRUE);
0375: check(request.getPortletContext(),
0376: Constants.NILLABLE_FALSE);
0377: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0378: check(request.getPropertyList(),
0379: Constants.NILLABLE_FALSE);
0380:
0381: } else {
0382:
0383: throwMissingParametersFault("Input object is not a SetPortletProperties or is null");
0384: }
0385: }
0386: }
0387:
0388: /**
0389: * Parameter check for the SetPortletProperties object. The following attributes are mandatory:
0390: *
0391: * 1) RegistrationContext, only if available
0392: * 2) PortletContext
0393: * 3) UserContext, only if available
0394: * 4) Names, only if available
0395: *
0396: * @param request _getPortletProperties
0397: *
0398: * @throws MissingParametersFault
0399: *
0400: * @see GetPortletPorperties
0401: */
0402: public void check(GetPortletProperties request)
0403: throws MissingParametersFault {
0404: if (isCheckEnabled()) {
0405: // check GetPortletProperties request object pointer
0406: if (request instanceof GetPortletProperties) {
0407:
0408: // check for registration context
0409: check(request.getRegistrationContext(),
0410: Constants.NILLABLE_TRUE);
0411: check(request.getPortletContext(),
0412: Constants.NILLABLE_FALSE);
0413: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0414: check(request.getNames(), Constants.NILLABLE_TRUE);
0415:
0416: } else {
0417: throwMissingParametersFault("Input object is not a GetPortletProperties or is null");
0418: }
0419: }
0420: }
0421:
0422: /**
0423: * Parameter check for the SetPortletProperties object. The following attributes are mandatory:
0424: *
0425: * 1) RegistrationContext, only if available
0426: * 2) PortletContext
0427: * 3) UserContext, only if available
0428: *
0429: * @param request _getPortletPropertyDescription
0430: *
0431: * @throws MissingParametersFault
0432: *
0433: * @see GetPortletPropertyDescription
0434: */
0435: public void check(GetPortletPropertyDescription request)
0436: throws MissingParametersFault {
0437: if (isCheckEnabled()) {
0438: // check GetPortletPropertyDescription request object pointer
0439: if (request instanceof GetPortletPropertyDescription) {
0440:
0441: // check for registration context
0442: check(request.getRegistrationContext(),
0443: Constants.NILLABLE_TRUE);
0444: check(request.getPortletContext(),
0445: Constants.NILLABLE_FALSE);
0446: check(request.getUserContext(), Constants.NILLABLE_TRUE);
0447:
0448: } else {
0449:
0450: throwMissingParametersFault("Input object is not a GetPortletPropertyDescription or is null");
0451: }
0452: }
0453: }
0454:
0455: /**
0456: * Parameter check for the ReleaseSession object. The following attributes are mandatory:
0457: *
0458: * 1) RegistrationContext, only if available
0459: * 2) String[] SessionHandles
0460: *
0461: * @param request _releaseSession
0462: *
0463: * @throws MissingParametersFault
0464: *
0465: * @see ReleaseSession
0466: */
0467: public void check(ReleaseSessions request)
0468: throws MissingParametersFault {
0469: if (isCheckEnabled()) {
0470: // check ReleaseSession request object pointer
0471: if (request instanceof ReleaseSessions) {
0472:
0473: // check for registration context
0474: check(request.getRegistrationContext(),
0475: Constants.NILLABLE_TRUE);
0476:
0477: // check sessionhandles array
0478: check(request.getSessionIDs(), Constants.NILLABLE_FALSE);
0479:
0480: } else {
0481:
0482: throwMissingParametersFault("Input object is not a ReleaseSession or is null");
0483: }
0484: }
0485: }
0486:
0487: /**
0488: * --- THIS IS THE RESPONSE SECTION OF THE PARAMETER-CHECKER ---
0489: */
0490:
0491: /**
0492: * Parameter check for the ServiceDescription object. The following attribute needs to be set:
0493: *
0494: * - requiresRegistration
0495: *
0496: * @param response ServiceDescription
0497: *
0498: * @throws MissingParametersFault
0499: *
0500: * @see ServiceDescription
0501: */
0502: public void check(ServiceDescription response)
0503: throws MissingParametersFault {
0504: if (isCheckEnabled()) {
0505: // check ServiceDescription object pointer
0506: if (response instanceof ServiceDescription) {
0507:
0508: if (response != null) {
0509:
0510: } else if (response.getOfferedPortlets() != null) {
0511:
0512: PortletDescription[] portletDesc = response
0513: .getOfferedPortlets();
0514:
0515: for (int i = 0; i < portletDesc.length; i++) {
0516:
0517: check(portletDesc[i]);
0518: }
0519:
0520: } else if (response.getRequiresInitCookie() != null) {
0521:
0522: check(response.getRequiresInitCookie(), true);
0523:
0524: } else if (response.getResourceList() != null) {
0525:
0526: check(response.getResourceList(), true);
0527:
0528: } else {
0529:
0530: throwMissingParametersFault("No valid service description.");
0531: }
0532: } else {
0533:
0534: throwMissingParametersFault("No valid service description response found.");
0535: }
0536: }
0537: }
0538:
0539: /**
0540: * Parameter check for the BlockingInteractionResponse object. The following attribute needs to be set:
0541: *
0542: * either
0543: * - updateResponse
0544: * or
0545: * - redirectURL
0546: *
0547: * @param response BlockingInteractionResponse
0548: *
0549: * @throws MissingParametersFault
0550: *
0551: * @see BlockingInteractionResponse
0552: */
0553: public void check(BlockingInteractionResponse response)
0554: throws MissingParametersFault {
0555: if (isCheckEnabled()) {
0556: // check BlockingInteractionResponse object pointer
0557: if (response instanceof BlockingInteractionResponse) {
0558:
0559: if (response.getUpdateResponse() != null
0560: && response.getRedirectURL() == null) {
0561:
0562: check(response.getUpdateResponse());
0563:
0564: } else if (response.getRedirectURL() != null
0565: && response.getUpdateResponse() == null) {
0566:
0567: // everything is fine
0568:
0569: } else {
0570:
0571: throwMissingParametersFault("No valid blocking interaction response. UpdateResponse"
0572: + "and redirect url are mutually exclusive");
0573: }
0574: } else {
0575:
0576: throwMissingParametersFault("No valid blocking interaction response found.");
0577: }
0578: }
0579: }
0580:
0581: /**
0582: * Parameter check for the UpdateResponse object. The following attribute needs to be set:
0583: *
0584: * 1) SessionContext, only if available
0585: * 2) PortletContext, only if available
0586: * 3) MarkupContext, only if available
0587: * 4) NavigationalState
0588: *
0589: * @param response UpdateResponse
0590: *
0591: * @throws MissingParametersFault
0592: *
0593: * @see UpdateResponse
0594: */
0595: private void check(UpdateResponse response)
0596: throws MissingParametersFault {
0597:
0598: // check UpdateResponse object pointer
0599: if (response instanceof UpdateResponse) {
0600:
0601: check(response.getSessionContext(), Constants.NILLABLE_TRUE);
0602: check(response.getPortletContext(), Constants.NILLABLE_TRUE);
0603: check(response.getMarkupContext(), Constants.NILLABLE_TRUE);
0604:
0605: // TODO: check for valid window states and portlet modes
0606:
0607: } else {
0608:
0609: throwMissingParametersFault("No valid update response found.");
0610: }
0611: }
0612:
0613: /**
0614: * Parameter check for the MarkupResponse object. The following attribute needs to be set:
0615: *
0616: * 1) MarkupContext
0617: * 2) SessionContext, only if available
0618: *
0619: * @param response MarkupResponse
0620: *
0621: * @throws MissingParametersFault
0622: *
0623: * @see MarkupResponse
0624: */
0625: public void check(MarkupResponse response)
0626: throws MissingParametersFault {
0627: if (isCheckEnabled()) {
0628: // check MarkupResponse object pointer
0629: if (response instanceof MarkupResponse) {
0630:
0631: check(response.getMarkupContext(),
0632: Constants.NILLABLE_FALSE);
0633: check(response.getSessionContext(),
0634: Constants.NILLABLE_TRUE);
0635:
0636: } else {
0637:
0638: throwMissingParametersFault("No valid markup response found.");
0639: }
0640: }
0641: }
0642:
0643: /**
0644: * Validates the PortletDescriptionResponse object
0645: *
0646: * 1) PortletDescription
0647: * 2) ResourceList, only if available
0648: *
0649: * @param response PortletDescriptionResponse
0650: *
0651: * @throws MissingParametersFault
0652: *
0653: * @see PortletDescriptionResponse
0654: */
0655: public void check(PortletDescriptionResponse response)
0656: throws MissingParametersFault {
0657: if (isCheckEnabled()) {
0658: // check MarkupResponse object pointer
0659: if (response instanceof PortletDescriptionResponse) {
0660:
0661: check(response.getPortletDescription());
0662: check(response.getResourceList(),
0663: Constants.NILLABLE_TRUE);
0664:
0665: } else {
0666:
0667: throwMissingParametersFault("No valid PortletDescriptionResponse response found.");
0668: }
0669: }
0670: }
0671:
0672: /**
0673: * Validates the PortletPropertyDescriptionResponse object
0674: *
0675: * 1) ResourceList
0676: *
0677: * @param response PortletPropertyDescriptionResponse
0678: *
0679: * @throws MissingParametersFault
0680: *
0681: * @see PortletPropertyDescriptionResponse
0682: */
0683: public void check(PortletPropertyDescriptionResponse response)
0684: throws MissingParametersFault {
0685: if (isCheckEnabled()) {
0686: // check MarkupResponse object pointer
0687: if (response instanceof PortletPropertyDescriptionResponse) {
0688:
0689: // TODO: check ModelDescription
0690:
0691: check(response.getResourceList(),
0692: Constants.NILLABLE_TRUE);
0693:
0694: } else {
0695:
0696: throwMissingParametersFault("No valid PortletPropertyDescriptionResponse response found.");
0697: }
0698: }
0699: }
0700:
0701: /**
0702: * Validates the DestroyPortletsResponse object
0703: *
0704: * 1) DestroyFailed[], only if available
0705: *
0706: * @param response DestroyPortletResponse
0707: *
0708: * @throws MissingParametersFault
0709: *
0710: * @see DestroyPortletsResponse
0711: */
0712: public void check(DestroyPortletsResponse response)
0713: throws MissingParametersFault {
0714: if (isCheckEnabled()) {
0715: // check MarkupResponse object pointer
0716: if (response instanceof DestroyPortletsResponse) {
0717:
0718: check(response.getDestroyFailed(),
0719: Constants.NILLABLE_TRUE);
0720:
0721: } else {
0722:
0723: throwMissingParametersFault("No valid PortletDescriptionResponse response found.");
0724: }
0725: }
0726: }
0727:
0728: /**
0729: * --- THIS IS THE AUXILLARY SECTION OF THE PARAMETER-CHECKER ---
0730: */
0731:
0732: /**
0733: * Parameter check for the PortletDescription object. The following parameter needs to be set:
0734: *
0735: * 1) portletHandle
0736: * 2) markupType[]
0737: *
0738: * @param element PortletDescription
0739: *
0740: * @throws MissingParametersFault
0741: *
0742: * @see PortletDescription
0743: */
0744: public void check(PortletDescription element)
0745: throws MissingParametersFault {
0746: if (isCheckEnabled()) {
0747: // check PortletDescription object pointer
0748: if (element instanceof PortletDescription) {
0749:
0750: if (element.getPortletHandle() == null) {
0751: throwMissingParametersFault("A portlet handle has to be set in the portlet description.");
0752: }
0753:
0754: if (element.getMarkupTypes() == null) {
0755: throwMissingParametersFault("Markup types have to be defined in the portlet description.");
0756: }
0757:
0758: } else {
0759:
0760: throwMissingParametersFault("No valid portlet description found.");
0761: }
0762: }
0763: }
0764:
0765: /**
0766: * Parameter check for the PortletDescription object. The following parameter needs to be set:
0767: *
0768: * all templates...
0769: *
0770: * @param element Templates
0771: *
0772: * @throws MissingParametersFault
0773: *
0774: * @see PortletDescription
0775: */
0776: public void check(Templates element) throws MissingParametersFault {
0777: if (isCheckEnabled()) {
0778: // check PortletDescription object pointer
0779: if (element instanceof Templates) {
0780: if (element.getDefaultTemplate() == null) {
0781: throwMissingParametersFault("DefaultTemplate has not been set!");
0782: }
0783:
0784: if (element.getSecureDefaultTemplate() == null) {
0785: throwMissingParametersFault("SecureDefaultTemplate Template has not been set!");
0786: }
0787: } else {
0788: throwMissingParametersFault("Consumer has to provide templates!");
0789: }
0790: }
0791: }
0792:
0793: /**
0794: * Parameter check for the SessionContext object. The following parameter needs to be set:
0795: *
0796: * 1) sessionID
0797: * 2) expire
0798: *
0799: * @param context SessionContext
0800: * @param nillable boolean true, if the SessionContext can be nill
0801: * false, if the SessionContext is not nillable
0802: *
0803: * @throws MissingParametersFault
0804: *
0805: * @see SessionContext
0806: */
0807: private void check(SessionContext context, boolean nillable)
0808: throws MissingParametersFault {
0809: if (context != null) {
0810: if (context.getSessionID() == null) {
0811: throwMissingParametersFault("No valid session context found. No session handle set.");
0812: } else {
0813: // check, if the ID is valid, instance and length
0814: //TODO: activate this, if ID is no longer as string declared!
0815: //check(context.getSessionID());
0816: }
0817: if (context.getExpires() == 0) {
0818: throwMissingParametersFault("No valid session context found. No session expire set.");
0819: }
0820: } else {
0821: if (!nillable) {
0822: throwMissingParametersFault("No valid session context found.");
0823: }
0824: }
0825: }
0826:
0827: /**
0828: * Parameter check for the MarkupContext object. The following parameter needs to be set:
0829: *
0830: * 1) markupBinary and markupString mutually exclusive, if markupType is available
0831: * 2) locale, if markupType is available
0832: *
0833: * @param context MarkupContext
0834: * @param nillable boolean true, if the MarkupContext can be nill
0835: * false, if the MarkupContext is not nillable
0836: *
0837: * @throws MissingParametersFault
0838: *
0839: * @see MarkupContext
0840: */
0841: private void check(MarkupContext context, boolean nillable)
0842: throws MissingParametersFault {
0843: if (context != null) {
0844: boolean bMarkupBinary = false, bMarkupString = false;
0845: if (context.getMarkupBinary() != null) {
0846: bMarkupBinary = true;
0847: }
0848: if (context.getMarkupString() != null) {
0849: bMarkupString = true;
0850: }
0851:
0852: // XOR of markupBinary and markupString
0853: if (bMarkupBinary ^ bMarkupString) {
0854: if (context.getMimeType() == null) {
0855: throwMissingParametersFault("MimeType not set in MarkupContext.");
0856: } else {
0857: if (context.getLocale() == null) {
0858: throwMissingParametersFault("Locale not set in MarkupContext.");
0859: }
0860: }
0861: }
0862: } else {
0863: if (!nillable) {
0864: throwMissingParametersFault("No valid markup context found.");
0865: }
0866: }
0867: }
0868:
0869: /**
0870: * Check the PropertyList. The following attributes are mandatory:
0871: *
0872: * 1) Property[]
0873: *
0874: * @param propertyList PropertyList
0875: * @param nillable boolean true, if the PropertyList can be nill
0876: * false, if the PropertyList is not nillable
0877: *
0878: * @throws MissingParametersFault
0879: *
0880: * @see PropertyList
0881: */
0882: public void check(PropertyList propertyList, boolean nillable)
0883: throws MissingParametersFault {
0884: if (isCheckEnabled()) {
0885: // check only, if object not null, otherwise ignore. Object is defined as nillable
0886: if (propertyList != null) {
0887: // property is mandatory
0888: if (propertyList.getProperties() == null) {
0889: throwMissingParametersFault("PropertyList[] in PropertyList is null");
0890: }
0891:
0892: } else {
0893: // check if nillable is allowed
0894: if (nillable == false) {
0895: throwMissingParametersFault("PropertyList object is null");
0896: }
0897: }
0898: }
0899: }
0900:
0901: /**
0902: * Check the RegistrationData. The following attributes are mandatory:
0903: *
0904: * 1) ConsumerName
0905: * 2) ConsumerAgent
0906: *
0907: * @param registrationData RegistrationData
0908: * @param nillable boolean true, if the RegistrationData can be nill
0909: * false, if the RegistrationData is not nillable
0910: *
0911: * @throws MissingParametersFault
0912: *
0913: * @see RegistrationData
0914: */
0915: public void check(RegistrationData registrationData,
0916: boolean nillable) throws MissingParametersFault {
0917: if (isCheckEnabled()) {
0918: // check only, if object not null, otherwise ignore. Object is defined as nillable
0919: if (registrationData != null) {
0920: // check the consumer name, is mandatory
0921: if (registrationData.getConsumerName() == null) {
0922: throwMissingParametersFault("ConsumerName in RegistrationData is null");
0923: }
0924: // check the consumer agent, is mandatory
0925: if (registrationData.getConsumerAgent() == null) {
0926: throwMissingParametersFault("ConsumerAgent in RegistrationData is null");
0927: }
0928:
0929: } else {
0930: // if registrationcontext is null, check if nillable is allowed
0931: if (nillable == false) {
0932: throwMissingParametersFault("RegistrationData object is null");
0933: }
0934: }
0935: }
0936: }
0937:
0938: /**
0939: * Check a string array. The following attributes are mandatory:
0940: *
0941: * 1) must be a string array
0942: * 2) must have a array.length > 0
0943: *
0944: * @param array String[]
0945: *
0946: * @param nillable boolean true, if the String[] can be nill
0947: * false, if the String[] is not nillable
0948: *
0949: *
0950: *
0951: * @throws MissingParametersFault
0952: *
0953: * @see String
0954: */
0955: private void check(String[] array, boolean nillable)
0956: throws MissingParametersFault {
0957: // check only, if object not null, otherwise ignore. Object is defined as nillable
0958: if (array != null) {
0959: // check the array
0960: if (array.length == 0) {
0961: throwMissingParametersFault("String[] array length is zero (0)");
0962: }
0963: } else {
0964: // if array is null, check if nillable is allowed
0965: if (nillable == false) {
0966: throwMissingParametersFault("String array[] object is null");
0967: }
0968: }
0969: }
0970:
0971: /**
0972: * Check the InteractionParams. The following attributes are mandatory:
0973: *
0974: * 1) PortletStateChange
0975: *
0976: * @param interactionParams InteractionParams
0977: * @param nillable boolean true, if the InteractionParams can be nill
0978: * false, if the InteractionParams is not nillable
0979: *
0980: *
0981: * @throws MissingParametersFault
0982: *
0983: * @see InteractionParams
0984: */
0985: private void check(InteractionParams interactionParams,
0986: boolean nillable) throws MissingParametersFault {
0987: // check only, if object not null, otherwise ignore. Object is defined as nillable
0988: if (interactionParams != null) {
0989: // check the portletHandle, is mandatory
0990: if (interactionParams.getPortletStateChange() == null) {
0991: throwMissingParametersFault("PortletStateChange in InteractionParams is null");
0992: }
0993: } else {
0994: // if registrationcontext is null, check if nillable is allowed
0995: if (nillable == false) {
0996: throwMissingParametersFault("InteractionParams object is null");
0997: }
0998: }
0999: }
1000:
1001: /**
1002: * Check the RegistrationContext. The following attributes are mandatory:
1003: *
1004: * 1) RegistrationHandle
1005: *
1006: * @param registrationContext RegistrationContext
1007: *
1008: * @param nillable boolean true, if the RegistrationContext can be nill
1009: * false, if the RegistrationContext is not nillable
1010: *
1011: *
1012: * @throws MissingParametersFault
1013: *
1014: * @see RegistrationContext
1015: */
1016: public void check(RegistrationContext registrationContext,
1017: boolean nillable) throws MissingParametersFault {
1018: if (isCheckEnabled()) {
1019: // check only, if object not null, otherwise ignore. Object is defined as nillable
1020: if (registrationContext != null) {
1021: // check the registrationHandle, is mandatory
1022: if (registrationContext.getRegistrationHandle() == null) {
1023: throwMissingParametersFault("RegistrationHandle in RegistrationContext is null");
1024: }
1025: } else {
1026: // if registrationcontext is null, check if nillable is allowed
1027: if (nillable == false) {
1028: throwMissingParametersFault("RegistrationContext object is null");
1029: }
1030: }
1031: }
1032: }
1033:
1034: /**
1035: * Check the PortletContext. The following attributes are mandatory:
1036: *
1037: * 1) PortletHandle
1038: *
1039: * @param portletContext PortletContext
1040: *
1041: * @param nillable boolean true, if the PortletContext can be nill
1042: * false, if the PortletContext is not nillable
1043: *
1044: * @throws MissingParametersFault
1045: *
1046: * @see PortletContext
1047: */
1048: public void check(PortletContext portletContext, boolean nillable)
1049: throws MissingParametersFault {
1050: if (isCheckEnabled()) {
1051: // check only, if object not null, otherwise ignore. Object is defined as nillable
1052: if (portletContext != null) {
1053: // check the portletHandle, is mandatory
1054: if (portletContext.getPortletHandle() == null) {
1055: throwMissingParametersFault("PortletHandle in PortletContext is null");
1056: }
1057: } else {
1058: // if registrationcontext is null, check if nillable is allowed
1059: if (nillable == false) {
1060: throwMissingParametersFault("PortletContext object is null");
1061: }
1062: }
1063: }
1064: }
1065:
1066: /**
1067: * Check the RuntimeContext. The following attributes are mandatory:
1068: *
1069: * 1) UserAuthentication
1070: * 2) PortletInstanceKey
1071: *
1072: * @param runtimeContext RuntimeContext
1073: *
1074: * @param nillable boolean true, if the RuntimeContext can be nill
1075: * false, if the RuntimeContext is not nillable
1076: *
1077: * @throws MissingParametersFault
1078: *
1079: * @see RuntimeContext
1080: */
1081: private void check(RuntimeContext runtimeContext, boolean nillable)
1082: throws MissingParametersFault {
1083: // check only, if object not null, otherwise ignore. Object is defined as nillable
1084: if (runtimeContext != null) {
1085: // check the userAuthentication, is mandatory
1086: if (runtimeContext.getUserAuthentication() == null) {
1087: throwMissingParametersFault("UserAuthentication in RuntimeContext is null");
1088: }
1089:
1090: // check the portletHandle, is mandatory
1091: if (runtimeContext.getPortletInstanceKey() != null) {
1092: //TODO: activate this, if the string is changed to key type
1093: //check(runtimeContext.getPortletInstanceKey());
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,
1114: boolean nillable) 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: } else {
1130: throwMissingParametersFault("DestroyFailedArray length is zero (0).");
1131: }
1132: } else {
1133: // if destroyFailedArray is null, check if nillable is allowed
1134: if (nillable == false) {
1135: throwMissingParametersFault("DestroyFailed[] object is null");
1136: }
1137: }
1138: }
1139:
1140: /**
1141: * Check the UserContext. The following attributes are mandatory:
1142: *
1143: * 1) UserContextKey
1144: *
1145: * @param userContext UserContext
1146: * @param nillable boolean true, if the UserContext can be nill
1147: * false, if the UserContext is not nillable
1148: *
1149: *
1150: * @throws MissingParametersFault
1151: *
1152: * @see UserContext
1153: */
1154: private void check(UserContext userContext, boolean nillable)
1155: throws MissingParametersFault {
1156: // check only, if object not null, otherwise ignore. Object is defined as nillable
1157: if (userContext != null) {
1158: // check the UserContextKey, is mandatory
1159: if (userContext.getUserContextKey() == null) {
1160: throwMissingParametersFault("UserContextKey in UserContext is null");
1161: }
1162: } else {
1163: // if registrationcontext is null, check if nillable is allowed
1164: if (nillable == false) {
1165: throwMissingParametersFault("UserContext object is null");
1166: }
1167: }
1168: }
1169:
1170: /**
1171: * Validates the ResourceList object for available resources.
1172: *
1173: * @param resourceList
1174: * @param nillable, true if null is allowed
1175: *
1176: * @throws MissingParametersFault
1177: */
1178: private void check(ResourceList resourceList, boolean nillable)
1179: throws MissingParametersFault {
1180: // check only, if object not null.
1181: if (resourceList != null) {
1182: // check for Resources, it's mandatory
1183: if (resourceList.getResources() == null) {
1184: throwMissingParametersFault("Resource[] is null");
1185: } else {
1186: Resource[] resourceArray = resourceList.getResources();
1187: if (resourceArray.length < 1) {
1188: throwMissingParametersFault("ResourceArray length is zero (0).");
1189: }
1190: }
1191: } else {
1192: // if registrationcontext is null, check if nillable is allowed
1193: if (nillable == false) {
1194: throwMissingParametersFault("ResourceList object is null");
1195: }
1196: }
1197: }
1198:
1199: /**
1200: * Validates the CookieProtocol object
1201: *
1202: * @param requiresInit
1203: * @param nillable, true if null is allowed
1204: *
1205: * @throws MissingParametersFault
1206: */
1207: private void check(CookieProtocol requiresInit, boolean nillable)
1208: throws MissingParametersFault {
1209: // check only, if object not null.
1210: if (requiresInit != null) {
1211: if (requiresInit.toString().equals(CookieProtocol._none)) {
1212: } else if (requiresInit.toString().equals(
1213: CookieProtocol._perGroup)) {
1214: } else if (requiresInit.toString().equals(
1215: CookieProtocol._perUser)) {
1216: } else {
1217: throwMissingParametersFault("Invalid value ("
1218: + requiresInit.toString()
1219: + ") of CookieProtocol object.");
1220: }
1221: } else {
1222: // if requiresInit is null, check if nillable is allowed
1223: if (nillable == false) {
1224: throwMissingParametersFault("RequiresInitCookie object is null");
1225: }
1226: }
1227: }
1228:
1229: /**
1230: * Check the MarkupParams. The following attributes are mandatory:
1231: *
1232: * 1) ClientData
1233: * 2) Locale
1234: * 3) MimeType
1235: * 4) Mode
1236: * 5) WindowState
1237: *
1238: * @param markupParams MarkupParams
1239: *
1240: * @param nillable boolean true, if the MarkupParams can be nill
1241: * false, if the MarkupParams is not nillable
1242: *
1243: *
1244: * @throws MissingParametersFault
1245: *
1246: * @see MarkupParams
1247: */
1248: private void check(MarkupParams markupParams, boolean nillable)
1249: throws MissingParametersFault {
1250: // check only, if object not null, otherwise ignore. Object is defined as nillable
1251: if (markupParams != null) {
1252: // check ClientData, is mandatory
1253: if (markupParams.getClientData() == null) {
1254: throwMissingParametersFault("ClientData in MarkupParams is null");
1255: }
1256: if (markupParams.getLocales() == null) {
1257: throwMissingParametersFault("Locales in MarkupParams is null");
1258: }
1259: if (markupParams.getMimeTypes() == null) {
1260: throwMissingParametersFault("MimeTypes in MarkupParams is null");
1261: }
1262: if (markupParams.getMode() == null) {
1263: throwMissingParametersFault("Mode in MarkupParams is null");
1264: }
1265: if (markupParams.getWindowState() == null) {
1266: throwMissingParametersFault("WindowState in MarkupParams is null");
1267: }
1268: } else {
1269: // if registrationcontext is null, check if nillable is allowed
1270: if (nillable == false) {
1271: throwMissingParametersFault("MarkupParams object is null");
1272: }
1273: }
1274: }
1275:
1276: /**
1277: * Creates and throws a MissingParametersFault exception
1278: *
1279: * @param msg String error message
1280: *
1281: * @throws MissingParametersFault
1282: *
1283: * @see MissingParameterFault
1284: */
1285: private void throwMissingParametersFault(String msg)
1286: throws MissingParametersFault {
1287: MissingParametersFault e = new MissingParametersFault();
1288: e.setFaultCode(new QName("urn:oasis:names:tc:wsrp:v1:types",
1289: "Interface.MissingParameters"));
1290: e.setFaultString(msg);
1291: throw e;
1292: }
1293: }
|