text
stringlengths
30
1.67M
<s> package org . gatein . wsrp . payload ; import org . w3c . dom . Element ; import java . io . Serializable ; public class SerializableSimplePayload extends SerializablePayload { private final Serializable payload ; private final XSDTypeConverter converter ; public SerializableSimplePayload ( Element element , Serializable payload , XSDTypeConverter converter ) { super ( element ) ; this . payload = payload ; this . converter = converter ; } public Serializable getPayload ( ) { return payload ; } public XSDTypeConverter getConverter ( ) { return converter ; } } </s>
<s> package org . gatein . wsrp . payload ; import org . gatein . common . util . ParameterValidation ; import org . gatein . wsrp . WSRPTypeFactory ; import org . gatein . wsrp . api . extensions . UnmarshalledExtension ; import org . oasis . wsrp . v2 . Event ; import org . oasis . wsrp . v2 . EventPayload ; import org . oasis . wsrp . v2 . NamedStringArray ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . TypeInfo ; import org . w3c . dom . ls . DOMImplementationLS ; import org . w3c . dom . ls . LSSerializer ; import javax . xml . XMLConstants ; import javax . xml . bind . JAXBContext ; import javax . xml . bind . JAXBElement ; import javax . xml . bind . JAXBException ; import javax . xml . bind . Marshaller ; import javax . xml . namespace . QName ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import java . io . Serializable ; import java . util . HashMap ; import java . util . Map ; public class PayloadUtils { private final static Map < String , XSDTypeConverter > typeToConverters = new HashMap < String , XSDTypeConverter > ( <NUM_LIT> ) ; private final static Map < Class , XSDTypeConverter > classToConverters = new HashMap < Class , XSDTypeConverter > ( <NUM_LIT> ) ; private final static ThreadLocal < DocumentBuilder > documentBuilder = new ThreadLocal < DocumentBuilder > ( ) ; static { XSDTypeConverter [ ] converterArray = XSDTypeConverter . values ( ) ; for ( XSDTypeConverter converter : converterArray ) { typeToConverters . put ( converter . typeName ( ) , converter ) ; Class javaType = converter . getJavaType ( ) ; if ( javaType != null ) { classToConverters . put ( javaType , converter ) ; } } } public static Serializable getPayloadAsSerializable ( Event event ) { EventPayload payload = event . getPayload ( ) ; if ( payload == null ) { return null ; } ParameterValidation . throwIllegalArgExceptionIfNull ( event , "<STR_LIT>" ) ; Object any = payload . getAny ( ) ; if ( any == null ) { NamedStringArray namedStringArray = payload . getNamedStringArray ( ) ; if ( namedStringArray != null ) { return new SerializableNamedStringArray ( namedStringArray ) ; } else { return null ; } } else { Element element = ( Element ) any ; QName type = event . getType ( ) ; if ( type != null ) { String typeName = type . getLocalPart ( ) ; if ( XMLConstants . W3C_XML_SCHEMA_NS_URI . equals ( type . getNamespaceURI ( ) ) ) { XSDTypeConverter converter = typeToConverters . get ( typeName ) ; if ( converter == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + type ) ; } return new SerializableSimplePayload ( element , converter . parseFromXML ( element . getTextContent ( ) ) , converter ) ; } } return new SerializablePayload ( element ) ; } } public static EventPayload getPayloadAsEventPayload ( Event eventNeedingType , Serializable payload ) { if ( payload instanceof SerializableNamedStringArray ) { SerializableNamedStringArray stringArray = ( SerializableNamedStringArray ) payload ; return WSRPTypeFactory . createEventPayloadAsNamedString ( stringArray . toNamedStringArray ( ) ) ; } else if ( payload instanceof SerializablePayload ) { if ( payload instanceof SerializableSimplePayload ) { eventNeedingType . setType ( ( ( SerializableSimplePayload ) payload ) . getConverter ( ) . getXSDType ( ) ) ; } return WSRPTypeFactory . createEventPayloadAsAny ( ( ( SerializablePayload ) payload ) . getElement ( ) ) ; } else { Class payloadClass = payload . getClass ( ) ; XSDTypeConverter converter = classToConverters . get ( payloadClass ) ; if ( converter != null ) { eventNeedingType . setType ( converter . getXSDType ( ) ) ; } QName name = eventNeedingType . getName ( ) ; try { return WSRPTypeFactory . createEventPayloadAsAny ( marshallPayload ( payload , payloadClass , name ) ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "<STR_LIT>" + payload , e ) ; } } } public static Element marshallPayload ( Serializable payload ) { ParameterValidation . throwIllegalArgExceptionIfNull ( payload , "<STR_LIT>" ) ; final Class < ? extends Serializable > payloadClass = payload . getClass ( ) ; XSDTypeConverter converter = classToConverters . get ( payloadClass ) ; if ( converter == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + payload ) ; } else { try { return marshallPayload ( payload , payloadClass , converter . getXSDType ( ) ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "<STR_LIT>" + payload , e ) ; } } } public static Serializable unmarshallPayload ( Object object ) { ParameterValidation . throwIllegalArgExceptionIfNull ( object , "<STR_LIT>" ) ; if ( object instanceof Element ) { Element element = ( Element ) object ; String namespace = element . getNamespaceURI ( ) ; if ( XMLConstants . W3C_XML_SCHEMA_NS_URI . equals ( namespace ) ) { final TypeInfo type = element . getSchemaTypeInfo ( ) ; String typeName = type . getTypeName ( ) ; if ( typeName == null ) { String tagName = element . getTagName ( ) ; int prefixEnd = tagName . indexOf ( '<CHAR_LIT::>' ) ; typeName = prefixEnd == - <NUM_LIT:1> ? tagName : tagName . substring ( prefixEnd + <NUM_LIT:1> ) ; } XSDTypeConverter converter = typeToConverters . get ( typeName ) ; if ( converter == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + type ) ; } return converter . parseFromXML ( element . getTextContent ( ) ) ; } } else if ( object instanceof Serializable ) { return ( Serializable ) object ; } throw new IllegalArgumentException ( "<STR_LIT>" ) ; } public static UnmarshalledExtension unmarshallExtension ( Object object ) { if ( object instanceof Element ) { Element element = ( Element ) object ; Object value = element ; String namespace = element . getNamespaceURI ( ) ; String tagName = element . getTagName ( ) ; int prefixEnd = tagName . indexOf ( '<CHAR_LIT::>' ) ; tagName = prefixEnd == - <NUM_LIT:1> ? tagName : tagName . substring ( prefixEnd + <NUM_LIT:1> ) ; if ( XMLConstants . W3C_XML_SCHEMA_NS_URI . equals ( namespace ) ) { final TypeInfo type = element . getSchemaTypeInfo ( ) ; String typeName = type . getTypeName ( ) ; if ( typeName == null ) { typeName = tagName ; } XSDTypeConverter converter = typeToConverters . get ( typeName ) ; if ( converter == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + type ) ; } value = converter . parseFromXML ( element . getTextContent ( ) ) ; } return new UnmarshalledExtension ( tagName , value , namespace ) ; } throw new IllegalArgumentException ( "<STR_LIT>" + object + "<STR_LIT:'>" ) ; } private static Element marshallPayload ( Serializable payload , Class payloadClass , QName name ) throws JAXBException , ParserConfigurationException { JAXBContext context = JAXBContext . newInstance ( payloadClass ) ; Marshaller marshaller = context . createMarshaller ( ) ; JAXBElement < Serializable > element = new JAXBElement < Serializable > ( name , payloadClass , payload ) ; DocumentBuilderFactory builderFactory = DocumentBuilderFactory . newInstance ( ) ; builderFactory . setNamespaceAware ( true ) ; Document document = builderFactory . newDocumentBuilder ( ) . newDocument ( ) ; marshaller . marshal ( element , document ) ; return document . getDocumentElement ( ) ; } public static Element marshallExtension ( Object value ) { if ( value instanceof Element ) { return ( Element ) value ; } try { return marshallPayload ( ( Serializable ) value ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "<STR_LIT>" + value + "<STR_LIT:'>" ) ; } } private static DocumentBuilder getBuilder ( ) { DocumentBuilder builder = documentBuilder . get ( ) ; if ( builder == null ) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory . newInstance ( ) ; builderFactory . setNamespaceAware ( true ) ; try { builder = builderFactory . newDocumentBuilder ( ) ; documentBuilder . set ( builder ) ; } catch ( ParserConfigurationException e ) { throw new RuntimeException ( "<STR_LIT>" , e ) ; } } return builder ; } public static String outputToXML ( Element node ) { Document document = node . getOwnerDocument ( ) ; DOMImplementationLS domImplLS = ( DOMImplementationLS ) document . getImplementation ( ) ; LSSerializer serializer = domImplLS . createLSSerializer ( ) ; return serializer . writeToString ( node ) ; } public static Element createElement ( String namespaceURI , String name ) { Document document = getBuilder ( ) . newDocument ( ) ; return document . createElementNS ( namespaceURI , name ) ; } } </s>
<s> package org . gatein . wsrp . spec . v2 ; public final class WSRP2RewritingConstants { private WSRP2RewritingConstants ( ) { } public static final String RESOURCE_ID = "<STR_LIT>" ; public static final String RESOURCE_PREFER_OPERATION = "<STR_LIT>" ; public static final String RESOURCE_STATE = "<STR_LIT>" ; public static final String RESOURCE_CACHEABILITY = "<STR_LIT>" ; public static final String NAVIGATIONAL_VALUES = "<STR_LIT>" ; } </s>
<s> package org . gatein . wsrp . spec . v2 ; import javax . xml . namespace . QName ; public final class ErrorCodes { public static final String WSRP2_TYPES_NS = "<STR_LIT>" ; public static final QName AccessDenied = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName ExportNoLongerValid = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName InconsistentParameters = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName InvalidRegistration = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName InvalidCookie = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName InvalidHandle = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName InvalidSession = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName InvalidUserCategory = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName ModifyRegistrationRequired = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName MissingParameters = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName OperationFailed = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName OperationNotSupported = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName ResourceSuspended = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName TooBusy = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static final QName TooManyRequests = new QName ( WSRP2_TYPES_NS , "<STR_LIT>" ) ; public static enum Codes { ACCESSDENIED , EXPORTNOLONGERVALID , INCONSISTENTPARAMETERS , INVALIDREGISTRATION , INVALIDCOOKIE , INVALIDHANDLE , INVALIDSESSION , INVALIDUSERCATEGORY , MODIFYREGISTRATIONREQUIRED , MISSINGPARAMETERS , OPERATIONFAILED , OPERATIONNOTSUPPORTED , RESOURCESUSPENDED , TOOBUSY , TOOMANYREQUESTS } public static QName getQname ( Codes code ) { switch ( code ) { case ACCESSDENIED : return AccessDenied ; case EXPORTNOLONGERVALID : return ExportNoLongerValid ; case INCONSISTENTPARAMETERS : return InconsistentParameters ; case INVALIDREGISTRATION : return InvalidRegistration ; case INVALIDCOOKIE : return InvalidCookie ; case INVALIDHANDLE : return InvalidHandle ; case INVALIDSESSION : return InvalidSession ; case INVALIDUSERCATEGORY : return InvalidUserCategory ; case MODIFYREGISTRATIONREQUIRED : return ModifyRegistrationRequired ; case MISSINGPARAMETERS : return MissingParameters ; case OPERATIONFAILED : return OperationFailed ; case OPERATIONNOTSUPPORTED : return OperationNotSupported ; case RESOURCESUSPENDED : return ResourceSuspended ; case TOOBUSY : return TooBusy ; case TOOMANYREQUESTS : return TooManyRequests ; default : return OperationFailed ; } } } </s>
<s> package org . gatein . wsrp . spec . v2 ; public final class WSRP2Constants { private WSRP2Constants ( ) { } public static final String OPTIONS_EVENTS = "<STR_LIT>" ; public static final String OPTIONS_LEASING = "<STR_LIT>" ; public static final String OPTIONS_COPYPORTLETS = "<STR_LIT>" ; public static final String OPTIONS_IMPORT = "<STR_LIT>" ; public static final String OPTIONS_EXPORT = "<STR_LIT>" ; public static final String RESOURCE_CACHEABILITY_FULL = "<STR_LIT>" ; public static final String RESOURCE_CACHEABILITY_PORTLET = "<STR_LIT>" ; public static final String RESOURCE_CACHEABILITY_PAGE = "<STR_LIT>" ; } </s>
<s> package org . gatein . wsrp . spec . v2 ; import org . gatein . wsrp . WSRPExceptionFactory ; import org . gatein . wsrp . WSRPTypeFactory ; import org . oasis . wsrp . v2 . AccessDenied ; import org . oasis . wsrp . v2 . ExportByValueNotSupported ; import org . oasis . wsrp . v2 . ExportNoLongerValid ; import org . oasis . wsrp . v2 . Fault ; import org . oasis . wsrp . v2 . InconsistentParameters ; import org . oasis . wsrp . v2 . InvalidCookie ; import org . oasis . wsrp . v2 . InvalidHandle ; import org . oasis . wsrp . v2 . InvalidRegistration ; import org . oasis . wsrp . v2 . InvalidSession ; import org . oasis . wsrp . v2 . InvalidUserCategory ; import org . oasis . wsrp . v2 . MissingParameters ; import org . oasis . wsrp . v2 . MissingParametersFault ; import org . oasis . wsrp . v2 . ModifyRegistrationRequired ; import org . oasis . wsrp . v2 . OperationFailed ; import org . oasis . wsrp . v2 . OperationFailedFault ; import org . oasis . wsrp . v2 . OperationNotSupported ; import org . oasis . wsrp . v2 . PortletStateChangeRequired ; import org . oasis . wsrp . v2 . ResourceSuspended ; import org . oasis . wsrp . v2 . UnsupportedLocale ; import org . oasis . wsrp . v2 . UnsupportedMimeType ; import org . oasis . wsrp . v2 . UnsupportedMode ; import org . oasis . wsrp . v2 . UnsupportedWindowState ; public class WSRP2ExceptionFactory extends WSRPExceptionFactory { protected void loadExceptionFactories ( ) { try { exceptionClassToFactory . put ( AccessDenied . class , new V2ExceptionFactory < AccessDenied > ( AccessDenied . class ) ) ; exceptionClassToFactory . put ( ExportByValueNotSupported . class , new V2ExceptionFactory < ExportByValueNotSupported > ( ExportByValueNotSupported . class ) ) ; exceptionClassToFactory . put ( ExportNoLongerValid . class , new V2ExceptionFactory < ExportNoLongerValid > ( ExportNoLongerValid . class ) ) ; exceptionClassToFactory . put ( InconsistentParameters . class , new V2ExceptionFactory < InconsistentParameters > ( InconsistentParameters . class ) ) ; exceptionClassToFactory . put ( InvalidCookie . class , new V2ExceptionFactory < InvalidCookie > ( InvalidCookie . class ) ) ; exceptionClassToFactory . put ( InvalidHandle . class , new V2ExceptionFactory < InvalidHandle > ( InvalidHandle . class ) ) ; exceptionClassToFactory . put ( InvalidRegistration . class , new V2ExceptionFactory < InvalidRegistration > ( InvalidRegistration . class ) ) ; exceptionClassToFactory . put ( InvalidSession . class , new V2ExceptionFactory < InvalidSession > ( InvalidSession . class ) ) ; exceptionClassToFactory . put ( InvalidUserCategory . class , new V2ExceptionFactory < InvalidUserCategory > ( InvalidUserCategory . class ) ) ; exceptionClassToFactory . put ( MissingParameters . class , new V2ExceptionFactory < MissingParameters > ( MissingParameters . class ) ) ; exceptionClassToFactory . put ( ModifyRegistrationRequired . class , new V2ExceptionFactory < ModifyRegistrationRequired > ( ModifyRegistrationRequired . class ) ) ; exceptionClassToFactory . put ( OperationFailed . class , new V2ExceptionFactory < OperationFailed > ( OperationFailed . class ) ) ; exceptionClassToFactory . put ( OperationNotSupported . class , new V2ExceptionFactory < OperationNotSupported > ( OperationNotSupported . class ) ) ; exceptionClassToFactory . put ( PortletStateChangeRequired . class , new V2ExceptionFactory < PortletStateChangeRequired > ( PortletStateChangeRequired . class ) ) ; exceptionClassToFactory . put ( ResourceSuspended . class , new V2ExceptionFactory < ResourceSuspended > ( ResourceSuspended . class ) ) ; exceptionClassToFactory . put ( UnsupportedLocale . class , new V2ExceptionFactory < UnsupportedLocale > ( UnsupportedLocale . class ) ) ; exceptionClassToFactory . put ( UnsupportedMimeType . class , new V2ExceptionFactory < UnsupportedMimeType > ( UnsupportedMimeType . class ) ) ; exceptionClassToFactory . put ( UnsupportedMode . class , new V2ExceptionFactory < UnsupportedMode > ( UnsupportedMode . class ) ) ; exceptionClassToFactory . put ( UnsupportedWindowState . class , new V2ExceptionFactory < UnsupportedWindowState > ( UnsupportedWindowState . class ) ) ; } catch ( Exception e ) { throw new RuntimeException ( "<STR_LIT>" , e ) ; } } private static final class InstanceHolder { public static final WSRP2ExceptionFactory factory = new WSRP2ExceptionFactory ( ) ; } public static WSRPExceptionFactory getInstance ( ) { return InstanceHolder . factory ; } private WSRP2ExceptionFactory ( ) { } public static void throwMissingParametersIfValueIsMissing ( Object valueToCheck , String valueName , String context ) throws MissingParameters { if ( valueToCheck == null ) { throw new MissingParameters ( "<STR_LIT>" + valueName + ( context != null ? "<STR_LIT>" + context : "<STR_LIT>" ) , WSRPTypeFactory . createMissingParametersFault ( ) ) ; } } public static void throwOperationFailedIfValueIsMissing ( Object valueToCheck , String valueName ) throws OperationFailed { if ( valueToCheck == null ) { throw new OperationFailed ( "<STR_LIT>" + valueName , WSRPTypeFactory . createOperationFailedFault ( ) ) ; } } protected static class V2ExceptionFactory < E extends Exception > extends ExceptionFactory { public V2ExceptionFactory ( Class < E > exceptionClass ) throws NoSuchMethodException , IllegalAccessException , InstantiationException , ClassNotFoundException { super ( exceptionClass ) ; } protected Class initFaultAndGetClass ( Class clazz ) throws IllegalAccessException , InstantiationException { if ( Fault . class . isAssignableFrom ( clazz ) ) { Class < ? extends Fault > faultClass = ( Class < Fault > ) clazz ; fault = faultClass . newInstance ( ) ; return faultClass ; } else { throw new IllegalArgumentException ( "<STR_LIT>" + clazz ) ; } } } } </s>
<s> package org . gatein . wsrp . spec . v1 ; import org . gatein . common . text . TextTools ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . ActionURL ; import org . gatein . pc . api . ContainerURL ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . OpaqueStateString ; import org . gatein . pc . api . PortletStateType ; import org . gatein . pc . api . RenderURL ; import org . gatein . pc . api . ResourceURL ; import org . gatein . pc . api . StateString ; import org . gatein . pc . api . StatefulPortletContext ; import org . gatein . pc . api . URLFormat ; import org . gatein . pc . api . WindowState ; import org . gatein . pc . api . cache . CacheLevel ; import org . gatein . pc . api . spi . PortletInvocationContext ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . WSRPResourceURL ; import org . gatein . wsrp . WSRPRewritingConstants ; import org . gatein . wsrp . WSRPUtils ; import org . oasis . wsrp . v1 . V1BlockingInteractionResponse ; import org . oasis . wsrp . v1 . V1CacheControl ; import org . oasis . wsrp . v1 . V1ClientData ; import org . oasis . wsrp . v1 . V1ClonePortlet ; import org . oasis . wsrp . v1 . V1DestroyFailed ; import org . oasis . wsrp . v1 . V1DestroyPortlets ; import org . oasis . wsrp . v1 . V1DestroyPortletsResponse ; import org . oasis . wsrp . v1 . V1GetMarkup ; import org . oasis . wsrp . v1 . V1GetPortletDescription ; import org . oasis . wsrp . v1 . V1GetPortletProperties ; import org . oasis . wsrp . v1 . V1GetPortletPropertyDescription ; import org . oasis . wsrp . v1 . V1GetServiceDescription ; import org . oasis . wsrp . v1 . V1InitCookie ; import org . oasis . wsrp . v1 . V1InteractionParams ; import org . oasis . wsrp . v1 . V1LocalizedString ; import org . oasis . wsrp . v1 . V1MarkupContext ; import org . oasis . wsrp . v1 . V1MarkupParams ; import org . oasis . wsrp . v1 . V1MarkupResponse ; import org . oasis . wsrp . v1 . V1MarkupType ; import org . oasis . wsrp . v1 . V1ModelDescription ; import org . oasis . wsrp . v1 . V1ModifyRegistration ; import org . oasis . wsrp . v1 . V1PerformBlockingInteraction ; import org . oasis . wsrp . v1 . V1PortletContext ; import org . oasis . wsrp . v1 . V1PortletDescription ; import org . oasis . wsrp . v1 . V1PortletDescriptionResponse ; import org . oasis . wsrp . v1 . V1PortletPropertyDescriptionResponse ; import org . oasis . wsrp . v1 . V1Property ; import org . oasis . wsrp . v1 . V1PropertyDescription ; import org . oasis . wsrp . v1 . V1PropertyList ; import org . oasis . wsrp . v1 . V1RegistrationContext ; import org . oasis . wsrp . v1 . V1RegistrationData ; import org . oasis . wsrp . v1 . V1ReleaseSessions ; import org . oasis . wsrp . v1 . V1ResetProperty ; import org . oasis . wsrp . v1 . V1RuntimeContext ; import org . oasis . wsrp . v1 . V1ServiceDescription ; import org . oasis . wsrp . v1 . V1SessionContext ; import org . oasis . wsrp . v1 . V1SetPortletProperties ; import org . oasis . wsrp . v1 . V1StateChange ; import org . oasis . wsrp . v1 . V1Templates ; import org . oasis . wsrp . v1 . V1UpdateResponse ; import org . oasis . wsrp . v1 . V1UploadContext ; import org . oasis . wsrp . v1 . V1UserContext ; import javax . xml . namespace . QName ; import java . util . Collections ; import java . util . List ; import java . util . Map ; import static org . gatein . wsrp . WSRPRewritingConstants . * ; public class WSRP1TypeFactory { private static final String REQUIRE_REWRITE_URL_PARAM = "<STR_LIT:&>" + WSRPRewritingConstants . RESOURCE_REQUIRES_REWRITE + "<STR_LIT:=>" + WSRPRewritingConstants . WSRP_REQUIRES_REWRITE ; private WSRP1TypeFactory ( ) { } public static V1GetServiceDescription createGetServiceDescription ( ) { return new V1GetServiceDescription ( ) ; } public static V1GetMarkup createMarkupRequest ( V1PortletContext portletContext , V1RuntimeContext runtimeContext , V1MarkupParams markupParams ) { ParameterValidation . throwIllegalArgExceptionIfNull ( runtimeContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupParams , "<STR_LIT>" ) ; V1GetMarkup getMarkup = new V1GetMarkup ( ) ; getMarkup . setPortletContext ( portletContext ) ; getMarkup . setRuntimeContext ( runtimeContext ) ; getMarkup . setMarkupParams ( markupParams ) ; return getMarkup ; } public static V1PerformBlockingInteraction createPerformBlockingInteraction ( V1PortletContext portletContext , V1RuntimeContext runtimeContext , V1MarkupParams markupParams , V1InteractionParams interactionParams ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletContext . getPortletHandle ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( runtimeContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupParams , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( interactionParams , "<STR_LIT>" ) ; V1PerformBlockingInteraction performBlockingInteraction = new V1PerformBlockingInteraction ( ) ; performBlockingInteraction . setPortletContext ( portletContext ) ; performBlockingInteraction . setRuntimeContext ( runtimeContext ) ; performBlockingInteraction . setMarkupParams ( markupParams ) ; performBlockingInteraction . setInteractionParams ( interactionParams ) ; return performBlockingInteraction ; } public static V1GetPortletDescription createGetPortletDescription ( V1RegistrationContext registrationContext , String portletHandle ) { V1GetPortletDescription description = new V1GetPortletDescription ( ) ; description . setPortletContext ( createPortletContext ( portletHandle ) ) ; description . setRegistrationContext ( registrationContext ) ; return description ; } public static V1GetPortletDescription createGetPortletDescription ( V1RegistrationContext registrationContext , org . gatein . pc . api . PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; V1PortletContext wsrpPC = createPortletContext ( portletContext . getId ( ) ) ; if ( portletContext instanceof StatefulPortletContext ) { StatefulPortletContext context = ( StatefulPortletContext ) portletContext ; if ( PortletStateType . OPAQUE . equals ( context . getType ( ) ) ) { wsrpPC . setPortletState ( ( ( StatefulPortletContext < byte [ ] > ) context ) . getState ( ) ) ; } } V1GetPortletDescription getPortletDescription = new V1GetPortletDescription ( ) ; getPortletDescription . setRegistrationContext ( registrationContext ) ; getPortletDescription . setPortletContext ( wsrpPC ) ; return getPortletDescription ; } public static V1GetPortletProperties createGetPortletProperties ( V1RegistrationContext registrationContext , V1PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; V1GetPortletProperties properties = new V1GetPortletProperties ( ) ; properties . setRegistrationContext ( registrationContext ) ; properties . setPortletContext ( portletContext ) ; return properties ; } public static V1BlockingInteractionResponse createBlockingInteractionResponse ( V1UpdateResponse updateResponse ) { if ( updateResponse == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1BlockingInteractionResponse interactionResponse = new V1BlockingInteractionResponse ( ) ; interactionResponse . setUpdateResponse ( updateResponse ) ; return interactionResponse ; } public static V1BlockingInteractionResponse createBlockingInteractionResponse ( String redirectURL ) { if ( redirectURL == null || redirectURL . length ( ) == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1BlockingInteractionResponse interactionResponse = new V1BlockingInteractionResponse ( ) ; interactionResponse . setRedirectURL ( redirectURL ) ; return interactionResponse ; } public static V1UpdateResponse createUpdateResponse ( ) { return new V1UpdateResponse ( ) ; } public static V1PortletDescription createPortletDescription ( org . gatein . pc . api . PortletContext portletContext , List < V1MarkupType > markupTypes ) { V1PortletContext context = V2ToV1Converter . toV1PortletContext ( WSRPUtils . convertToWSRPPortletContext ( portletContext ) ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupTypes , "<STR_LIT>" ) ; if ( markupTypes . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1PortletDescription portletDescription = new V1PortletDescription ( ) ; portletDescription . setPortletHandle ( context . getPortletHandle ( ) ) ; portletDescription . getMarkupTypes ( ) . addAll ( markupTypes ) ; return portletDescription ; } public static V1PortletDescription createPortletDescription ( String portletHandle , List < V1MarkupType > markupTypes ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletHandle , "<STR_LIT>" , null ) ; checkPortletHandle ( portletHandle ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupTypes , "<STR_LIT>" ) ; if ( markupTypes . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1PortletDescription portletDescription = new V1PortletDescription ( ) ; portletDescription . setPortletHandle ( portletHandle ) ; portletDescription . getMarkupTypes ( ) . addAll ( markupTypes ) ; return portletDescription ; } private static void checkPortletHandle ( String portletHandle ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletHandle , "<STR_LIT>" , "<STR_LIT>" ) ; if ( portletHandle . length ( ) > <NUM_LIT:255> ) { throw new IllegalArgumentException ( "<STR_LIT>" + portletHandle . length ( ) + "<STR_LIT>" ) ; } } public static V1MarkupParams createDefaultMarkupParams ( ) { return createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , WSRPConstants . getDefaultMimeTypes ( ) , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ; } public static V1MarkupParams createMarkupParams ( boolean secureClientCommunication , List < String > locales , List < String > mimeTypes , String mode , String windowState ) { ParameterValidation . throwIllegalArgExceptionIfNull ( locales , "<STR_LIT>" ) ; if ( locales . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ParameterValidation . throwIllegalArgExceptionIfNull ( mimeTypes , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mode , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( windowState , "<STR_LIT>" , "<STR_LIT>" ) ; V1MarkupParams markupParams = new V1MarkupParams ( ) ; markupParams . setSecureClientCommunication ( secureClientCommunication ) ; markupParams . setMode ( mode ) ; markupParams . setWindowState ( windowState ) ; if ( ParameterValidation . existsAndIsNotEmpty ( locales ) ) { markupParams . getLocales ( ) . addAll ( locales ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( mimeTypes ) ) { markupParams . getMimeTypes ( ) . addAll ( mimeTypes ) ; } return markupParams ; } public static V1RuntimeContext createRuntimeContext ( String userAuthentication , String portletInstanceKey , String namespacePrefix ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userAuthentication , "<STR_LIT>" , "<STR_LIT>" ) ; V1RuntimeContext runtimeContext = new V1RuntimeContext ( ) ; runtimeContext . setUserAuthentication ( userAuthentication ) ; runtimeContext . setPortletInstanceKey ( portletInstanceKey ) ; runtimeContext . setNamespacePrefix ( namespacePrefix ) ; return runtimeContext ; } public static V1PortletContext createPortletContext ( String portletHandle ) { checkPortletHandle ( portletHandle ) ; V1PortletContext portletContext = new V1PortletContext ( ) ; portletContext . setPortletHandle ( portletHandle ) ; return portletContext ; } public static V1PortletContext createPortletContext ( String portletHandle , byte [ ] portletState ) { V1PortletContext pc = createPortletContext ( portletHandle ) ; pc . setPortletState ( portletState ) ; return pc ; } public static V1InteractionParams createDefaultInteractionParams ( ) { return createInteractionParams ( V1StateChange . READ_ONLY ) ; } public static V1InteractionParams createInteractionParams ( V1StateChange portletStateChange ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletStateChange , "<STR_LIT>" ) ; V1InteractionParams interactionParams = new V1InteractionParams ( ) ; interactionParams . setPortletStateChange ( portletStateChange ) ; return interactionParams ; } public static V1InitCookie createInitCookie ( V1RegistrationContext registrationContext ) { V1InitCookie initCookie = new V1InitCookie ( ) ; initCookie . setRegistrationContext ( registrationContext ) ; return initCookie ; } public static V1ServiceDescription createServiceDescription ( boolean requiresRegistration ) { V1ServiceDescription serviceDescription = new V1ServiceDescription ( ) ; serviceDescription . setRequiresRegistration ( requiresRegistration ) ; return serviceDescription ; } public static V1MarkupResponse createMarkupResponse ( V1MarkupContext markupContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( markupContext , "<STR_LIT>" ) ; V1MarkupResponse markupResponse = new V1MarkupResponse ( ) ; markupResponse . setMarkupContext ( markupContext ) ; return markupResponse ; } public static V1MarkupContext createMarkupContext ( String mediaType , String markupString , byte [ ] markupBinary , Boolean useCacheItem ) { boolean isUseCacheItem = ( useCacheItem == null ) ? false : useCacheItem . booleanValue ( ) ; V1MarkupContext markupContext = new V1MarkupContext ( ) ; markupContext . setMimeType ( mediaType ) ; if ( isUseCacheItem ) { markupContext . setUseCachedMarkup ( useCacheItem ) ; } else { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mediaType , "<STR_LIT>" , "<STR_LIT>" ) ; if ( markupBinary != null ) { markupContext . setMarkupBinary ( markupBinary ) ; } else if ( markupString != null ) { markupContext . setMarkupString ( markupString ) ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } return markupContext ; } public static V1SessionContext createSessionContext ( String sessionID , int expires ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( sessionID , "<STR_LIT>" , "<STR_LIT>" ) ; if ( expires < <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1SessionContext sessionContext = new V1SessionContext ( ) ; sessionContext . setSessionID ( sessionID ) ; sessionContext . setExpires ( expires ) ; return sessionContext ; } public static V1UserContext createUserContext ( String userContextKey ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userContextKey , "<STR_LIT>" , "<STR_LIT>" ) ; V1UserContext userContext = new V1UserContext ( ) ; userContext . setUserContextKey ( userContextKey ) ; return userContext ; } public static V1RegistrationData createRegistrationData ( String consumerName , boolean methodGetSupported ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerName , "<STR_LIT>" , "<STR_LIT>" ) ; V1RegistrationData regData = createDefaultRegistrationData ( ) ; regData . setConsumerName ( consumerName ) ; regData . setMethodGetSupported ( methodGetSupported ) ; return regData ; } public static V1RegistrationData createDefaultRegistrationData ( ) { V1RegistrationData registrationData = new V1RegistrationData ( ) ; registrationData . setConsumerName ( WSRPConstants . DEFAULT_CONSUMER_NAME ) ; registrationData . setConsumerAgent ( WSRPConstants . CONSUMER_AGENT ) ; registrationData . setMethodGetSupported ( false ) ; return registrationData ; } public static V1Property createProperty ( String name , String lang , String stringValue ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT:name>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( stringValue , "<STR_LIT>" , "<STR_LIT>" ) ; V1Property property = new V1Property ( ) ; property . setName ( name ) ; if ( ! ParameterValidation . isNullOrEmpty ( lang ) ) { property . setLang ( lang ) ; } property . setStringValue ( stringValue ) ; return property ; } private static final ActionURL ACTION_URL = new ActionURL ( ) { public StateString getInteractionState ( ) { return new OpaqueStateString ( REWRITE_PARAMETER_OPEN + INTERACTION_STATE + REWRITE_PARAMETER_CLOSE ) ; } public StateString getNavigationalState ( ) { return getTemplateNS ( ) ; } public Mode getMode ( ) { return getTemplateMode ( ) ; } public WindowState getWindowState ( ) { return getTemplateWindowState ( ) ; } public Map < String , String > getProperties ( ) { return Collections . emptyMap ( ) ; } } ; private static final RenderURL RENDER_URL = new RenderURL ( ) { public StateString getNavigationalState ( ) { return getTemplateNS ( ) ; } public Map < String , String [ ] > getPublicNavigationalStateChanges ( ) { return null ; } public Mode getMode ( ) { return getTemplateMode ( ) ; } public WindowState getWindowState ( ) { return getTemplateWindowState ( ) ; } public Map < String , String > getProperties ( ) { return Collections . emptyMap ( ) ; } } ; private static ResourceURL RESOURCE_URL = new WSRPResourceURL ( ) { public String getResourceId ( ) { return REWRITE_PARAMETER_OPEN + WSRPRewritingConstants . RESOURCE_URL + REWRITE_PARAMETER_CLOSE ; } public StateString getResourceState ( ) { return null ; } public CacheLevel getCacheability ( ) { return null ; } public Mode getMode ( ) { return getTemplateMode ( ) ; } public WindowState getWindowState ( ) { return getTemplateWindowState ( ) ; } public StateString getNavigationalState ( ) { return getTemplateNS ( ) ; } } ; private static StateString getTemplateNS ( ) { return new OpaqueStateString ( REWRITE_PARAMETER_OPEN + NAVIGATIONAL_STATE + REWRITE_PARAMETER_CLOSE ) ; } private static WindowState getTemplateWindowState ( ) { return WindowState . create ( REWRITE_PARAMETER_OPEN + WINDOW_STATE + REWRITE_PARAMETER_CLOSE , true ) ; } private static Mode getTemplateMode ( ) { return Mode . create ( REWRITE_PARAMETER_OPEN + MODE + REWRITE_PARAMETER_CLOSE , true ) ; } public static V1Templates createTemplates ( PortletInvocationContext context ) { V1Templates templates = new V1Templates ( ) ; templates . setBlockingActionTemplate ( createTemplate ( context , ACTION_URL , Boolean . FALSE ) ) ; templates . setRenderTemplate ( createTemplate ( context , RENDER_URL , Boolean . FALSE ) ) ; templates . setSecureBlockingActionTemplate ( createTemplate ( context , ACTION_URL , Boolean . TRUE ) ) ; templates . setSecureRenderTemplate ( createTemplate ( context , RENDER_URL , Boolean . TRUE ) ) ; templates . setResourceTemplate ( createTemplate ( context , RESOURCE_URL , false ) ) ; templates . setSecureResourceTemplate ( createTemplate ( context , RESOURCE_URL , true ) ) ; return templates ; } private static String createTemplate ( PortletInvocationContext context , ContainerURL url , Boolean secure ) { String template = context . renderURL ( url , new URLFormat ( secure , null , null , true ) ) ; template = TextTools . replace ( template , WSRPRewritingConstants . ENC_OPEN , WSRPRewritingConstants . REWRITE_PARAMETER_OPEN ) ; template = TextTools . replace ( template , WSRPRewritingConstants . ENC_CLOSE , WSRPRewritingConstants . REWRITE_PARAMETER_CLOSE ) ; if ( RESOURCE_URL == url ) { template += REQUIRE_REWRITE_URL_PARAM ; } return template ; } public static V1ClientData createClientData ( String userAgent ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userAgent , "<STR_LIT>" , "<STR_LIT>" ) ; V1ClientData clientData = new V1ClientData ( ) ; clientData . setUserAgent ( userAgent ) ; return clientData ; } public static V1CacheControl createCacheControl ( int expires , String userScope ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userScope , "<STR_LIT>" , "<STR_LIT>" ) ; if ( expires < - <NUM_LIT:1> ) { throw new IllegalArgumentException ( "<STR_LIT>" + "<STR_LIT>" ) ; } V1CacheControl cacheControl = new V1CacheControl ( ) ; cacheControl . setExpires ( expires ) ; cacheControl . setUserScope ( userScope ) ; return cacheControl ; } public static V1RegistrationContext createRegistrationContext ( String registrationHandle ) { ParameterValidation . throwIllegalArgExceptionIfNull ( registrationHandle , "<STR_LIT>" ) ; V1RegistrationContext registrationContext = new V1RegistrationContext ( ) ; registrationContext . setRegistrationHandle ( registrationHandle ) ; return registrationContext ; } public static V1ModelDescription createModelDescription ( List < V1PropertyDescription > propertyDescriptions ) { V1ModelDescription description = new V1ModelDescription ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( propertyDescriptions ) ) { description . getPropertyDescriptions ( ) . addAll ( propertyDescriptions ) ; } return description ; } public static V1PropertyDescription createPropertyDescription ( String name , QName type ) { ParameterValidation . throwIllegalArgExceptionIfNull ( name , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( type , "<STR_LIT>" ) ; V1PropertyDescription description = new V1PropertyDescription ( ) ; description . setName ( name ) ; description . setType ( type ) ; return description ; } public static V1LocalizedString createLocalizedString ( String lang , String resourceName , String value ) { ParameterValidation . throwIllegalArgExceptionIfNull ( lang , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( value , "<STR_LIT>" ) ; V1LocalizedString localizedString = new V1LocalizedString ( ) ; localizedString . setLang ( lang ) ; localizedString . setResourceName ( resourceName ) ; localizedString . setValue ( value ) ; return localizedString ; } public static V1LocalizedString createLocalizedString ( String value ) { return createLocalizedString ( "<STR_LIT:en>" , null , value ) ; } public static V1PortletDescriptionResponse createPortletDescriptionResponse ( V1PortletDescription portletDescription ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletDescription , "<STR_LIT>" ) ; V1PortletDescriptionResponse response = new V1PortletDescriptionResponse ( ) ; response . setPortletDescription ( portletDescription ) ; return response ; } public static V1PortletPropertyDescriptionResponse createPortletPropertyDescriptionResponse ( List < V1PropertyDescription > propertyDescriptions ) { V1ModelDescription modelDescription = propertyDescriptions == null ? null : createModelDescription ( propertyDescriptions ) ; V1PortletPropertyDescriptionResponse portletPropertyDescriptionResponse = new V1PortletPropertyDescriptionResponse ( ) ; portletPropertyDescriptionResponse . setModelDescription ( modelDescription ) ; return portletPropertyDescriptionResponse ; } public static V1GetPortletPropertyDescription createGetPortletPropertyDescription ( V1RegistrationContext registrationContext , V1PortletContext portletContext , V1UserContext userContext , List < String > desiredLocales ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; V1GetPortletPropertyDescription description = new V1GetPortletPropertyDescription ( ) ; description . setRegistrationContext ( registrationContext ) ; description . setPortletContext ( portletContext ) ; description . setUserContext ( userContext ) ; if ( ParameterValidation . existsAndIsNotEmpty ( desiredLocales ) ) { description . getDesiredLocales ( ) . addAll ( desiredLocales ) ; } return description ; } public static V1GetPortletPropertyDescription createSimpleGetPortletPropertyDescription ( String portletHandle ) { return createGetPortletPropertyDescription ( null , createPortletContext ( portletHandle ) , null , null ) ; } public static V1DestroyFailed createDestroyFailed ( String portletHandle , String reason ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletHandle , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( reason , "<STR_LIT>" , "<STR_LIT>" ) ; V1DestroyFailed destroyFailed = new V1DestroyFailed ( ) ; destroyFailed . setPortletHandle ( portletHandle ) ; destroyFailed . setReason ( reason ) ; return destroyFailed ; } public static V1DestroyPortletsResponse createDestroyPortletsResponse ( List < V1DestroyFailed > destroyFailed ) { V1DestroyPortletsResponse destroyPortletsResponse = new V1DestroyPortletsResponse ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( destroyFailed ) ) { destroyPortletsResponse . getDestroyFailed ( ) . addAll ( destroyFailed ) ; } return destroyPortletsResponse ; } public static V1SetPortletProperties createSetPortletProperties ( V1RegistrationContext registrationContext , V1PortletContext portletContext , V1PropertyList propertyList ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( propertyList , "<STR_LIT>" ) ; V1SetPortletProperties properties = new V1SetPortletProperties ( ) ; properties . setRegistrationContext ( registrationContext ) ; properties . setPortletContext ( portletContext ) ; properties . setPropertyList ( propertyList ) ; return properties ; } public static V1ClonePortlet createSimpleClonePortlet ( String portletHandle ) { return createClonePortlet ( null , createPortletContext ( portletHandle ) , null ) ; } public static V1ClonePortlet createClonePortlet ( V1RegistrationContext registrationContext , V1PortletContext portletContext , V1UserContext userContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; V1ClonePortlet clonePortlet = new V1ClonePortlet ( ) ; clonePortlet . setPortletContext ( portletContext ) ; clonePortlet . setRegistrationContext ( registrationContext ) ; clonePortlet . setUserContext ( userContext ) ; return clonePortlet ; } public static V1DestroyPortlets createDestroyPortlets ( V1RegistrationContext registrationContext , List < String > portletHandles ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletHandles , "<STR_LIT>" ) ; if ( portletHandles . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1DestroyPortlets destroyPortlets = new V1DestroyPortlets ( ) ; destroyPortlets . setRegistrationContext ( registrationContext ) ; if ( ParameterValidation . existsAndIsNotEmpty ( portletHandles ) ) { destroyPortlets . getPortletHandles ( ) . addAll ( portletHandles ) ; } return destroyPortlets ; } public static V1PropertyList createPropertyList ( ) { return new V1PropertyList ( ) ; } public static V1ResetProperty createResetProperty ( String name ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT>" , "<STR_LIT>" ) ; V1ResetProperty resetProperty = new V1ResetProperty ( ) ; resetProperty . setName ( name ) ; return resetProperty ; } public static V1ReleaseSessions createReleaseSessions ( V1RegistrationContext registrationContext , List < String > sessionIDs ) { ParameterValidation . throwIllegalArgExceptionIfNull ( sessionIDs , "<STR_LIT>" ) ; if ( sessionIDs . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1ReleaseSessions sessions = new V1ReleaseSessions ( ) ; sessions . setRegistrationContext ( registrationContext ) ; if ( ParameterValidation . existsAndIsNotEmpty ( sessionIDs ) ) { sessions . getSessionIDs ( ) . addAll ( sessionIDs ) ; } return sessions ; } public static V1ModifyRegistration createModifyRegistration ( V1RegistrationContext registrationContext , V1RegistrationData registrationData ) { ParameterValidation . throwIllegalArgExceptionIfNull ( registrationData , "<STR_LIT>" ) ; V1ModifyRegistration registration = new V1ModifyRegistration ( ) ; registration . setRegistrationContext ( registrationContext ) ; registration . setRegistrationData ( registrationData ) ; return registration ; } public static V1UploadContext createUploadContext ( String mimeType , byte [ ] uploadData ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mimeType , "<STR_LIT>" , "<STR_LIT>" ) ; if ( uploadData == null || uploadData . length == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } V1UploadContext uploadContext = new V1UploadContext ( ) ; uploadContext . setMimeType ( mimeType ) ; uploadContext . setUploadData ( uploadData ) ; return uploadContext ; } public static V1MarkupType createMarkupType ( String mimeType , List < String > modeNames , List < String > windowStateNames , List < String > localeNames ) { V1MarkupType markupType = new V1MarkupType ( ) ; markupType . setMimeType ( mimeType ) ; if ( ParameterValidation . existsAndIsNotEmpty ( modeNames ) ) { markupType . getModes ( ) . addAll ( modeNames ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( windowStateNames ) ) { markupType . getWindowStates ( ) . addAll ( windowStateNames ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( localeNames ) ) { markupType . getLocales ( ) . addAll ( localeNames ) ; } return markupType ; } } </s>
<s> package org . gatein . wsrp . spec . v1 ; import org . gatein . wsrp . WSRPExceptionFactory ; import org . oasis . wsrp . v1 . V1AccessDenied ; import org . oasis . wsrp . v1 . V1Fault ; import org . oasis . wsrp . v1 . V1InconsistentParameters ; import org . oasis . wsrp . v1 . V1InvalidCookie ; import org . oasis . wsrp . v1 . V1InvalidHandle ; import org . oasis . wsrp . v1 . V1InvalidRegistration ; import org . oasis . wsrp . v1 . V1InvalidSession ; import org . oasis . wsrp . v1 . V1InvalidUserCategory ; import org . oasis . wsrp . v1 . V1MissingParameters ; import org . oasis . wsrp . v1 . V1MissingParametersFault ; import org . oasis . wsrp . v1 . V1OperationFailed ; import org . oasis . wsrp . v1 . V1PortletStateChangeRequired ; import org . oasis . wsrp . v1 . V1UnsupportedLocale ; import org . oasis . wsrp . v1 . V1UnsupportedMimeType ; import org . oasis . wsrp . v1 . V1UnsupportedMode ; import org . oasis . wsrp . v1 . V1UnsupportedWindowState ; public class WSRP1ExceptionFactory extends WSRPExceptionFactory { protected void loadExceptionFactories ( ) { try { exceptionClassToFactory . put ( V1AccessDenied . class , new V1ExceptionFactory < V1AccessDenied > ( V1AccessDenied . class ) ) ; exceptionClassToFactory . put ( V1InconsistentParameters . class , new V1ExceptionFactory < V1InconsistentParameters > ( V1InconsistentParameters . class ) ) ; exceptionClassToFactory . put ( V1InvalidCookie . class , new V1ExceptionFactory < V1InvalidCookie > ( V1InvalidCookie . class ) ) ; exceptionClassToFactory . put ( V1InvalidHandle . class , new V1ExceptionFactory < V1InvalidHandle > ( V1InvalidHandle . class ) ) ; exceptionClassToFactory . put ( V1InvalidRegistration . class , new V1ExceptionFactory < V1InvalidRegistration > ( V1InvalidRegistration . class ) ) ; exceptionClassToFactory . put ( V1InvalidSession . class , new V1ExceptionFactory < V1InvalidSession > ( V1InvalidSession . class ) ) ; exceptionClassToFactory . put ( V1InvalidUserCategory . class , new V1ExceptionFactory < V1InvalidUserCategory > ( V1InvalidUserCategory . class ) ) ; exceptionClassToFactory . put ( V1MissingParameters . class , new V1ExceptionFactory < V1MissingParameters > ( V1MissingParameters . class ) ) ; exceptionClassToFactory . put ( V1OperationFailed . class , new V1ExceptionFactory < V1OperationFailed > ( V1OperationFailed . class ) ) ; exceptionClassToFactory . put ( V1PortletStateChangeRequired . class , new V1ExceptionFactory < V1PortletStateChangeRequired > ( V1PortletStateChangeRequired . class ) ) ; exceptionClassToFactory . put ( V1UnsupportedLocale . class , new V1ExceptionFactory < V1UnsupportedLocale > ( V1UnsupportedLocale . class ) ) ; exceptionClassToFactory . put ( V1UnsupportedMimeType . class , new V1ExceptionFactory < V1UnsupportedMimeType > ( V1UnsupportedMimeType . class ) ) ; exceptionClassToFactory . put ( V1UnsupportedMode . class , new V1ExceptionFactory < V1UnsupportedMode > ( V1UnsupportedMode . class ) ) ; exceptionClassToFactory . put ( V1UnsupportedWindowState . class , new V1ExceptionFactory < V1UnsupportedWindowState > ( V1UnsupportedWindowState . class ) ) ; } catch ( Exception e ) { throw new RuntimeException ( "<STR_LIT>" , e ) ; } } private static final class InstanceHolder { public static final WSRP1ExceptionFactory factory = new WSRP1ExceptionFactory ( ) ; } public static WSRPExceptionFactory getInstance ( ) { return InstanceHolder . factory ; } private WSRP1ExceptionFactory ( ) { } public static void throwMissingParametersIfValueIsMissing ( Object valueToCheck , String valueName , String context ) throws V1MissingParameters { if ( valueToCheck == null ) { throw new V1MissingParameters ( "<STR_LIT>" + valueName + ( context != null ? "<STR_LIT>" + context : "<STR_LIT>" ) , new V1MissingParametersFault ( ) ) ; } } protected static class V1ExceptionFactory < E extends Exception > extends ExceptionFactory { public V1ExceptionFactory ( Class < E > exceptionClass ) throws NoSuchMethodException , IllegalAccessException , InstantiationException , ClassNotFoundException { super ( exceptionClass ) ; } protected Class initFaultAndGetClass ( Class clazz ) throws IllegalAccessException , InstantiationException { if ( V1Fault . class . isAssignableFrom ( clazz ) ) { Class < ? extends V1Fault > faultClass = ( Class < V1Fault > ) clazz ; fault = faultClass . newInstance ( ) ; return faultClass ; } else { throw new IllegalArgumentException ( "<STR_LIT>" + clazz ) ; } } } } </s>
<s> package org . gatein . wsrp . spec . v1 ; import com . google . common . base . Function ; import com . google . common . collect . Lists ; import org . gatein . common . util . ParameterValidation ; import org . gatein . wsrp . WSRPUtils ; import org . oasis . wsrp . v1 . V1BlockingInteractionResponse ; import org . oasis . wsrp . v1 . V1CacheControl ; import org . oasis . wsrp . v1 . V1ClientData ; import org . oasis . wsrp . v1 . V1Contact ; import org . oasis . wsrp . v1 . V1CookieProtocol ; import org . oasis . wsrp . v1 . V1DestroyFailed ; import org . oasis . wsrp . v1 . V1DestroyPortletsResponse ; import org . oasis . wsrp . v1 . V1EmployerInfo ; import org . oasis . wsrp . v1 . V1Extension ; import org . oasis . wsrp . v1 . V1InteractionParams ; import org . oasis . wsrp . v1 . V1ItemDescription ; import org . oasis . wsrp . v1 . V1LocalizedString ; import org . oasis . wsrp . v1 . V1MarkupContext ; import org . oasis . wsrp . v1 . V1MarkupParams ; import org . oasis . wsrp . v1 . V1MarkupResponse ; import org . oasis . wsrp . v1 . V1MarkupType ; import org . oasis . wsrp . v1 . V1ModelDescription ; import org . oasis . wsrp . v1 . V1ModelTypes ; import org . oasis . wsrp . v1 . V1NamedString ; import org . oasis . wsrp . v1 . V1Online ; import org . oasis . wsrp . v1 . V1PersonName ; import org . oasis . wsrp . v1 . V1PortletContext ; import org . oasis . wsrp . v1 . V1PortletDescription ; import org . oasis . wsrp . v1 . V1PortletDescriptionResponse ; import org . oasis . wsrp . v1 . V1PortletPropertyDescriptionResponse ; import org . oasis . wsrp . v1 . V1Postal ; import org . oasis . wsrp . v1 . V1Property ; import org . oasis . wsrp . v1 . V1PropertyDescription ; import org . oasis . wsrp . v1 . V1PropertyList ; import org . oasis . wsrp . v1 . V1RegistrationContext ; import org . oasis . wsrp . v1 . V1RegistrationData ; import org . oasis . wsrp . v1 . V1RegistrationState ; import org . oasis . wsrp . v1 . V1ResetProperty ; import org . oasis . wsrp . v1 . V1Resource ; import org . oasis . wsrp . v1 . V1ResourceList ; import org . oasis . wsrp . v1 . V1ResourceValue ; import org . oasis . wsrp . v1 . V1ReturnAny ; import org . oasis . wsrp . v1 . V1RuntimeContext ; import org . oasis . wsrp . v1 . V1ServiceDescription ; import org . oasis . wsrp . v1 . V1SessionContext ; import org . oasis . wsrp . v1 . V1StateChange ; import org . oasis . wsrp . v1 . V1Telecom ; import org . oasis . wsrp . v1 . V1TelephoneNum ; import org . oasis . wsrp . v1 . V1Templates ; import org . oasis . wsrp . v1 . V1UpdateResponse ; import org . oasis . wsrp . v1 . V1UploadContext ; import org . oasis . wsrp . v1 . V1UserContext ; import org . oasis . wsrp . v1 . V1UserProfile ; import org . oasis . wsrp . v2 . BlockingInteractionResponse ; import org . oasis . wsrp . v2 . CacheControl ; import org . oasis . wsrp . v2 . ClientData ; import org . oasis . wsrp . v2 . Contact ; import org . oasis . wsrp . v2 . CookieProtocol ; import org . oasis . wsrp . v2 . DestroyPortletsResponse ; import org . oasis . wsrp . v2 . EmployerInfo ; import org . oasis . wsrp . v2 . Extension ; import org . oasis . wsrp . v2 . FailedPortlets ; import org . oasis . wsrp . v2 . InteractionParams ; import org . oasis . wsrp . v2 . ItemDescription ; import org . oasis . wsrp . v2 . LocalizedString ; import org . oasis . wsrp . v2 . MarkupContext ; import org . oasis . wsrp . v2 . MarkupParams ; import org . oasis . wsrp . v2 . MarkupResponse ; import org . oasis . wsrp . v2 . MarkupType ; import org . oasis . wsrp . v2 . ModelDescription ; import org . oasis . wsrp . v2 . ModelTypes ; import org . oasis . wsrp . v2 . NamedString ; import org . oasis . wsrp . v2 . NavigationalContext ; import org . oasis . wsrp . v2 . Online ; import org . oasis . wsrp . v2 . PersonName ; import org . oasis . wsrp . v2 . PortletContext ; import org . oasis . wsrp . v2 . PortletDescription ; import org . oasis . wsrp . v2 . PortletDescriptionResponse ; import org . oasis . wsrp . v2 . PortletPropertyDescriptionResponse ; import org . oasis . wsrp . v2 . Postal ; import org . oasis . wsrp . v2 . Property ; import org . oasis . wsrp . v2 . PropertyDescription ; import org . oasis . wsrp . v2 . PropertyList ; import org . oasis . wsrp . v2 . RegistrationContext ; import org . oasis . wsrp . v2 . RegistrationData ; import org . oasis . wsrp . v2 . RegistrationState ; import org . oasis . wsrp . v2 . ResetProperty ; import org . oasis . wsrp . v2 . Resource ; import org . oasis . wsrp . v2 . ResourceList ; import org . oasis . wsrp . v2 . ResourceValue ; import org . oasis . wsrp . v2 . ReturnAny ; import org . oasis . wsrp . v2 . RuntimeContext ; import org . oasis . wsrp . v2 . ServiceDescription ; import org . oasis . wsrp . v2 . SessionContext ; import org . oasis . wsrp . v2 . SessionParams ; import org . oasis . wsrp . v2 . StateChange ; import org . oasis . wsrp . v2 . Telecom ; import org . oasis . wsrp . v2 . TelephoneNum ; import org . oasis . wsrp . v2 . Templates ; import org . oasis . wsrp . v2 . UpdateResponse ; import org . oasis . wsrp . v2 . UploadContext ; import org . oasis . wsrp . v2 . UserContext ; import org . oasis . wsrp . v2 . UserProfile ; import javax . xml . namespace . QName ; import java . util . ArrayList ; import java . util . List ; public class V2ToV1Converter { public static final V2ToV1Extension EXTENSION = new V2ToV1Extension ( ) ; public static final V2ToV1MarkupType MARKUPTYPE = new V2ToV1MarkupType ( ) ; public static final V2ToV1PortletDescription PORTLETDESCRIPTION = new V2ToV1PortletDescription ( ) ; public static final V2ToV1LocalizedString LOCALIZEDSTRING = new V2ToV1LocalizedString ( ) ; public static final V2ToV1ItemDescription ITEMDESCRIPTION = new V2ToV1ItemDescription ( ) ; public static final V2ToV1PropertyDescription PROPERTYDESCRIPTION = new V2ToV1PropertyDescription ( ) ; public static final V2ToV1Resource RESOURCE = new V2ToV1Resource ( ) ; public static final V2ToV1ResourceValue RESOURCEVALUE = new V2ToV1ResourceValue ( ) ; public static final V2ToV1NamedString NAMEDSTRING = new V2ToV1NamedString ( ) ; public static final V2ToV1UploadContext UPLOADCONTEXT = new V2ToV1UploadContext ( ) ; public static final V2ToV1Property PROPERTY = new V2ToV1Property ( ) ; public static final V2ToV1ResetProperty RESETPROPERTY = new V2ToV1ResetProperty ( ) ; public static final V2ToV1FailedPortlets FAILEDPORTLET = new V2ToV1FailedPortlets ( ) ; public static V1PortletContext toV1PortletContext ( PortletContext portletContext ) { if ( portletContext != null ) { V1PortletContext v1PortletContext = WSRP1TypeFactory . createPortletContext ( portletContext . getPortletHandle ( ) , portletContext . getPortletState ( ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( portletContext . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { v1PortletContext . getExtensions ( ) . addAll ( extensions ) ; } return v1PortletContext ; } else { return null ; } } public static V1MarkupParams toV1MarkupParams ( MarkupParams markupParams ) { if ( markupParams != null ) { V1MarkupParams v1MarkupParams = WSRP1TypeFactory . createMarkupParams ( markupParams . isSecureClientCommunication ( ) , markupParams . getLocales ( ) , markupParams . getMimeTypes ( ) , markupParams . getMode ( ) , markupParams . getWindowState ( ) ) ; v1MarkupParams . setClientData ( toV1ClientData ( markupParams . getClientData ( ) ) ) ; NavigationalContext navigationalContext = markupParams . getNavigationalContext ( ) ; if ( navigationalContext != null ) { v1MarkupParams . setNavigationalState ( navigationalContext . getOpaqueValue ( ) ) ; } v1MarkupParams . setValidateTag ( markupParams . getValidateTag ( ) ) ; List < String > charSets = markupParams . getMarkupCharacterSets ( ) ; if ( charSets != null ) { v1MarkupParams . getMarkupCharacterSets ( ) . addAll ( charSets ) ; } List < String > validNewModes = markupParams . getValidNewModes ( ) ; if ( validNewModes != null ) { v1MarkupParams . getValidNewModes ( ) . addAll ( validNewModes ) ; } List < String > validNewWindowStates = markupParams . getValidNewWindowStates ( ) ; if ( validNewWindowStates != null ) { v1MarkupParams . getValidNewWindowStates ( ) . addAll ( validNewWindowStates ) ; } List < V1Extension > extensions = WSRPUtils . transform ( markupParams . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { v1MarkupParams . getExtensions ( ) . addAll ( extensions ) ; } return v1MarkupParams ; } else { return null ; } } private static V1ClientData toV1ClientData ( ClientData clientData ) { if ( clientData != null ) { V1ClientData v1ClientData = WSRP1TypeFactory . createClientData ( clientData . getUserAgent ( ) ) ; List < Extension > extensions = clientData . getExtensions ( ) ; if ( extensions != null ) { v1ClientData . getExtensions ( ) . addAll ( Lists . transform ( extensions , EXTENSION ) ) ; } return v1ClientData ; } else { return null ; } } public static V1RuntimeContext toV1RuntimeContext ( RuntimeContext runtimeContext ) { if ( runtimeContext != null ) { V1RuntimeContext v1RuntimeContext = WSRP1TypeFactory . createRuntimeContext ( runtimeContext . getUserAuthentication ( ) , runtimeContext . getPortletInstanceKey ( ) , runtimeContext . getNamespacePrefix ( ) ) ; v1RuntimeContext . setNamespacePrefix ( runtimeContext . getNamespacePrefix ( ) ) ; v1RuntimeContext . setPortletInstanceKey ( runtimeContext . getPortletInstanceKey ( ) ) ; SessionParams sessionParams = runtimeContext . getSessionParams ( ) ; if ( sessionParams != null ) { v1RuntimeContext . setSessionID ( sessionParams . getSessionID ( ) ) ; } v1RuntimeContext . setTemplates ( V2ToV1Converter . toV1Templates ( runtimeContext . getTemplates ( ) ) ) ; List < Extension > extensions = runtimeContext . getExtensions ( ) ; if ( extensions != null ) { v1RuntimeContext . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1RuntimeContext ; } else { return null ; } } public static V1Templates toV1Templates ( Templates templates ) { if ( templates != null ) { V1Templates v1Templates = new V1Templates ( ) ; v1Templates . setBlockingActionTemplate ( templates . getBlockingActionTemplate ( ) ) ; v1Templates . setDefaultTemplate ( templates . getDefaultTemplate ( ) ) ; v1Templates . setRenderTemplate ( templates . getRenderTemplate ( ) ) ; v1Templates . setResourceTemplate ( templates . getResourceTemplate ( ) ) ; v1Templates . setSecureBlockingActionTemplate ( templates . getSecureBlockingActionTemplate ( ) ) ; v1Templates . setSecureRenderTemplate ( templates . getSecureRenderTemplate ( ) ) ; v1Templates . setSecureResourceTemplate ( templates . getSecureResourceTemplate ( ) ) ; List < Extension > extensions = templates . getExtensions ( ) ; if ( extensions != null ) { v1Templates . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1Templates ; } else { return null ; } } public static V1UserContext toV1UserContext ( UserContext userContext ) { if ( userContext != null ) { V1UserContext v1UserContext = WSRP1TypeFactory . createUserContext ( userContext . getUserContextKey ( ) ) ; v1UserContext . setProfile ( toV1UserProfile ( userContext . getProfile ( ) ) ) ; List < Extension > extensions = userContext . getExtensions ( ) ; if ( extensions != null ) { v1UserContext . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } if ( userContext . getUserCategories ( ) != null ) { v1UserContext . getUserCategories ( ) . addAll ( userContext . getUserCategories ( ) ) ; } return v1UserContext ; } else { return null ; } } public static V1UserProfile toV1UserProfile ( UserProfile userProfile ) { if ( userProfile != null ) { V1UserProfile v1UserProfile = new V1UserProfile ( ) ; v1UserProfile . setBdate ( userProfile . getBdate ( ) ) ; v1UserProfile . setBusinessInfo ( toV1Context ( userProfile . getBusinessInfo ( ) ) ) ; v1UserProfile . setEmployerInfo ( toV1EmployerInfo ( userProfile . getEmployerInfo ( ) ) ) ; v1UserProfile . setGender ( userProfile . getGender ( ) ) ; v1UserProfile . setHomeInfo ( toV1Context ( userProfile . getHomeInfo ( ) ) ) ; v1UserProfile . setName ( toV1PersonName ( userProfile . getName ( ) ) ) ; return v1UserProfile ; } else { return null ; } } public static V1EmployerInfo toV1EmployerInfo ( EmployerInfo employerInfo ) { if ( employerInfo != null ) { V1EmployerInfo v1EmployerInfo = new V1EmployerInfo ( ) ; v1EmployerInfo . setDepartment ( employerInfo . getDepartment ( ) ) ; v1EmployerInfo . setEmployer ( employerInfo . getEmployer ( ) ) ; v1EmployerInfo . setJobtitle ( employerInfo . getJobtitle ( ) ) ; List < Extension > extensions = employerInfo . getExtensions ( ) ; if ( extensions != null ) { v1EmployerInfo . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1EmployerInfo ; } else { return null ; } } public static V1PersonName toV1PersonName ( PersonName personName ) { if ( personName != null ) { V1PersonName v1PersonName = new V1PersonName ( ) ; v1PersonName . setFamily ( personName . getFamily ( ) ) ; v1PersonName . setGiven ( personName . getGiven ( ) ) ; v1PersonName . setMiddle ( personName . getMiddle ( ) ) ; v1PersonName . setNickname ( personName . getNickname ( ) ) ; v1PersonName . setPrefix ( personName . getPrefix ( ) ) ; v1PersonName . setSuffix ( personName . getSuffix ( ) ) ; List < Extension > extensions = personName . getExtensions ( ) ; if ( extensions != null ) { v1PersonName . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1PersonName ; } else { return null ; } } public static V1Contact toV1Context ( Contact contact ) { if ( contact != null ) { V1Contact v1Contact = new V1Contact ( ) ; v1Contact . setOnline ( toV1Online ( contact . getOnline ( ) ) ) ; v1Contact . setPostal ( toV1Postal ( contact . getPostal ( ) ) ) ; v1Contact . setTelecom ( toV1Telecom ( contact . getTelecom ( ) ) ) ; List < Extension > extensions = contact . getExtensions ( ) ; if ( extensions != null ) { v1Contact . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1Contact ; } else { return null ; } } public static V1Online toV1Online ( Online online ) { if ( online != null ) { V1Online v1Online = new V1Online ( ) ; v1Online . setEmail ( online . getEmail ( ) ) ; v1Online . setUri ( online . getUri ( ) ) ; List < Extension > extensions = online . getExtensions ( ) ; if ( extensions != null ) { v1Online . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1Online ; } else { return null ; } } public static V1Postal toV1Postal ( Postal postal ) { if ( postal != null ) { V1Postal v1Postal = new V1Postal ( ) ; v1Postal . setCity ( postal . getCity ( ) ) ; v1Postal . setCountry ( postal . getCountry ( ) ) ; v1Postal . setName ( postal . getName ( ) ) ; v1Postal . setOrganization ( postal . getOrganization ( ) ) ; v1Postal . setPostalcode ( postal . getPostalcode ( ) ) ; v1Postal . setStateprov ( postal . getStateprov ( ) ) ; v1Postal . setStreet ( postal . getStreet ( ) ) ; List < Extension > extensions = postal . getExtensions ( ) ; if ( extensions != null ) { v1Postal . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1Postal ; } else { return null ; } } public static V1Telecom toV1Telecom ( Telecom telecom ) { if ( telecom != null ) { V1Telecom v1Telecom = new V1Telecom ( ) ; v1Telecom . setFax ( toV1TelephoneNum ( telecom . getFax ( ) ) ) ; v1Telecom . setMobile ( toV1TelephoneNum ( telecom . getMobile ( ) ) ) ; v1Telecom . setPager ( toV1TelephoneNum ( telecom . getPager ( ) ) ) ; v1Telecom . setTelephone ( toV1TelephoneNum ( telecom . getTelephone ( ) ) ) ; List < Extension > extensions = telecom . getExtensions ( ) ; if ( extensions != null ) { v1Telecom . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1Telecom ; } else { return null ; } } public static V1TelephoneNum toV1TelephoneNum ( TelephoneNum telephoneNum ) { if ( telephoneNum != null ) { V1TelephoneNum v1TelephoneNum = new V1TelephoneNum ( ) ; v1TelephoneNum . setComment ( telephoneNum . getComment ( ) ) ; v1TelephoneNum . setExt ( telephoneNum . getExt ( ) ) ; v1TelephoneNum . setIntcode ( telephoneNum . getIntcode ( ) ) ; v1TelephoneNum . setLoccode ( telephoneNum . getLoccode ( ) ) ; v1TelephoneNum . setNumber ( telephoneNum . getNumber ( ) ) ; List < Extension > extensions = telephoneNum . getExtensions ( ) ; if ( extensions != null ) { v1TelephoneNum . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1TelephoneNum ; } else { return null ; } } public static V1MarkupContext toV1MarkupContext ( MarkupContext markupContext ) { if ( markupContext != null ) { V1MarkupContext v1MarkupContext = WSRP1TypeFactory . createMarkupContext ( markupContext . getMimeType ( ) , markupContext . getItemString ( ) , markupContext . getItemBinary ( ) , markupContext . isUseCachedItem ( ) ) ; v1MarkupContext . setCacheControl ( toV1CacheControl ( markupContext . getCacheControl ( ) ) ) ; v1MarkupContext . setLocale ( markupContext . getLocale ( ) ) ; v1MarkupContext . setPreferredTitle ( markupContext . getPreferredTitle ( ) ) ; v1MarkupContext . setRequiresUrlRewriting ( markupContext . isRequiresRewriting ( ) ) ; List < Extension > extensions = markupContext . getExtensions ( ) ; if ( extensions != null ) { v1MarkupContext . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1MarkupContext ; } else { return null ; } } public static V1CacheControl toV1CacheControl ( CacheControl cacheControl ) { if ( cacheControl != null ) { V1CacheControl v1CacheControl = WSRP1TypeFactory . createCacheControl ( cacheControl . getExpires ( ) , cacheControl . getUserScope ( ) ) ; v1CacheControl . setValidateTag ( cacheControl . getValidateTag ( ) ) ; List < Extension > extensions = cacheControl . getExtensions ( ) ; if ( extensions != null ) { v1CacheControl . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return v1CacheControl ; } else { return null ; } } public static V1RegistrationContext toV1RegistrationContext ( RegistrationContext registrationContext ) { if ( registrationContext != null ) { V1RegistrationContext result = WSRP1TypeFactory . createRegistrationContext ( registrationContext . getRegistrationHandle ( ) ) ; result . setRegistrationState ( registrationContext . getRegistrationState ( ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( registrationContext . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static < E extends Exception > E toV1Exception ( Class < E > v1ExceptionClass , Exception v2Exception ) { if ( ! "<STR_LIT>" . equals ( v1ExceptionClass . getPackage ( ) . getName ( ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + v1ExceptionClass ) ; } Class < ? extends Exception > v2ExceptionClass = v2Exception . getClass ( ) ; String v2Name = v2ExceptionClass . getSimpleName ( ) ; if ( ! "<STR_LIT>" . equals ( v2ExceptionClass . getPackage ( ) . getName ( ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + v2Exception ) ; } String v1Name = v1ExceptionClass . getSimpleName ( ) ; if ( ! v2Name . equals ( v1Name . substring ( <NUM_LIT:2> ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + v1Name + "<STR_LIT>" + v2Name ) ; } return WSRP1ExceptionFactory . createWSException ( v1ExceptionClass , v2Exception . getMessage ( ) , v2Exception . getCause ( ) ) ; } public static V1CookieProtocol toV1CookieProtocol ( CookieProtocol requiresInitCookie ) { if ( requiresInitCookie != null ) { return V1CookieProtocol . fromValue ( requiresInitCookie . value ( ) ) ; } else { return null ; } } public static V1ModelDescription toV1ModelDescription ( ModelDescription modelDescription ) { if ( modelDescription != null ) { V1ModelDescription result = WSRP1TypeFactory . createModelDescription ( WSRPUtils . transform ( modelDescription . getPropertyDescriptions ( ) , PROPERTYDESCRIPTION ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( modelDescription . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } result . setModelTypes ( toV1ModelTypes ( modelDescription . getModelTypes ( ) ) ) ; return result ; } else { return null ; } } public static V1ModelTypes toV1ModelTypes ( ModelTypes modelTypes ) { if ( modelTypes != null ) { V1ModelTypes result = new V1ModelTypes ( ) ; result . setAny ( modelTypes . getAny ( ) ) ; return result ; } else { return null ; } } public static V1ResourceList toV1ResourceList ( ResourceList resourceList ) { if ( resourceList != null ) { V1ResourceList result = new V1ResourceList ( ) ; List < V1Extension > extensions = WSRPUtils . transform ( resourceList . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } List < V1Resource > v1Resources = WSRPUtils . transform ( resourceList . getResources ( ) , RESOURCE ) ; if ( v1Resources != null ) { result . getResources ( ) . addAll ( v1Resources ) ; } return result ; } else { return null ; } } public static V1InteractionParams toV1InteractionParams ( InteractionParams interactionParams ) { if ( interactionParams != null ) { V1InteractionParams v1InteractionParams = WSRP1TypeFactory . createInteractionParams ( toV1StateChange ( interactionParams . getPortletStateChange ( ) ) ) ; v1InteractionParams . setInteractionState ( interactionParams . getInteractionState ( ) ) ; List < Extension > extensions = interactionParams . getExtensions ( ) ; if ( extensions != null ) { v1InteractionParams . getExtensions ( ) . addAll ( Lists . transform ( extensions , EXTENSION ) ) ; } List < NamedString > formParameters = interactionParams . getFormParameters ( ) ; if ( formParameters != null ) { v1InteractionParams . getFormParameters ( ) . addAll ( Lists . transform ( formParameters , NAMEDSTRING ) ) ; } List < UploadContext > uploadContext = interactionParams . getUploadContexts ( ) ; if ( uploadContext != null ) { v1InteractionParams . getUploadContexts ( ) . addAll ( Lists . transform ( uploadContext , UPLOADCONTEXT ) ) ; } return v1InteractionParams ; } else { return null ; } } public static V1StateChange toV1StateChange ( StateChange stateChange ) { if ( stateChange != null ) { return V1StateChange . fromValue ( stateChange . value ( ) ) ; } else { return null ; } } public static V1UpdateResponse toV1UpdateResponse ( UpdateResponse updateResponse ) { if ( updateResponse != null ) { V1UpdateResponse v1UpdateResponse = WSRP1TypeFactory . createUpdateResponse ( ) ; v1UpdateResponse . setMarkupContext ( toV1MarkupContext ( updateResponse . getMarkupContext ( ) ) ) ; v1UpdateResponse . setNavigationalState ( updateResponse . getNavigationalContext ( ) . getOpaqueValue ( ) ) ; v1UpdateResponse . setNewWindowState ( updateResponse . getNewWindowState ( ) ) ; v1UpdateResponse . setPortletContext ( toV1PortletContext ( updateResponse . getPortletContext ( ) ) ) ; v1UpdateResponse . setSessionContext ( toV1SessionContext ( updateResponse . getSessionContext ( ) ) ) ; v1UpdateResponse . setNewMode ( updateResponse . getNewMode ( ) ) ; return v1UpdateResponse ; } else { return null ; } } public static V1LocalizedString toV1LocalizedString ( LocalizedString localizedString ) { return LOCALIZEDSTRING . apply ( localizedString ) ; } public static V1SessionContext toV1SessionContext ( SessionContext sessionContext ) { if ( sessionContext != null && ! ParameterValidation . isNullOrEmpty ( sessionContext . getSessionID ( ) ) ) { V1SessionContext v1SessionContext = WSRP1TypeFactory . createSessionContext ( sessionContext . getSessionID ( ) , sessionContext . getExpires ( ) ) ; v1SessionContext . getExtensions ( ) . addAll ( Lists . transform ( sessionContext . getExtensions ( ) , EXTENSION ) ) ; return v1SessionContext ; } else { return null ; } } public static V1PortletDescription toV1PortletDescription ( PortletDescription description ) { return PORTLETDESCRIPTION . apply ( description ) ; } public static List < V1DestroyFailed > toV1DestroyFailed ( List < FailedPortlets > failedPortletsList ) { if ( failedPortletsList != null ) { List < V1DestroyFailed > result = new ArrayList < V1DestroyFailed > ( failedPortletsList . size ( ) ) ; for ( FailedPortlets failedPortlets : failedPortletsList ) { QName errorCode = failedPortlets . getErrorCode ( ) ; V1LocalizedString reason = toV1LocalizedString ( failedPortlets . getReason ( ) ) ; String v1Reason ; if ( reason != null && reason . getValue ( ) != null ) { v1Reason = errorCode . toString ( ) + "<STR_LIT::U+0020>" + reason . getValue ( ) ; } else { v1Reason = errorCode . toString ( ) ; } for ( String handle : failedPortlets . getPortletHandles ( ) ) { V1DestroyFailed destroyFailed = WSRP1TypeFactory . createDestroyFailed ( handle , v1Reason ) ; result . add ( destroyFailed ) ; } } return result ; } else { return null ; } } public static V1PropertyList toV1PropertyList ( PropertyList propertyList ) { if ( propertyList != null ) { V1PropertyList result = new V1PropertyList ( ) ; List < V1Property > properties = WSRPUtils . transform ( propertyList . getProperties ( ) , PROPERTY ) ; if ( properties != null ) { result . getProperties ( ) . addAll ( properties ) ; } List < V1ResetProperty > resetProperties = WSRPUtils . transform ( propertyList . getResetProperties ( ) , RESETPROPERTY ) ; if ( resetProperties != null ) { result . getResetProperties ( ) . addAll ( resetProperties ) ; } List < V1Extension > extensions = WSRPUtils . transform ( propertyList . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1RegistrationData toV1RegistrationData ( RegistrationData registrationData ) { if ( registrationData != null ) { V1RegistrationData result = WSRP1TypeFactory . createRegistrationData ( registrationData . getConsumerName ( ) , registrationData . isMethodGetSupported ( ) ) ; result . setConsumerAgent ( registrationData . getConsumerAgent ( ) ) ; List < V1Property > properties = WSRPUtils . transform ( registrationData . getRegistrationProperties ( ) , PROPERTY ) ; if ( properties != null ) { result . getRegistrationProperties ( ) . addAll ( properties ) ; } List < String > modes = registrationData . getConsumerModes ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( modes ) ) { result . getConsumerModes ( ) . addAll ( modes ) ; } List < String > consumerUserScopes = registrationData . getConsumerUserScopes ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( consumerUserScopes ) ) { result . getConsumerUserScopes ( ) . addAll ( consumerUserScopes ) ; } List < String > windowStates = registrationData . getConsumerWindowStates ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( windowStates ) ) { result . getConsumerWindowStates ( ) . addAll ( windowStates ) ; } List < V1Extension > extensions = WSRPUtils . transform ( registrationData . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1ServiceDescription toV1ServiceDescription ( ServiceDescription serviceDescription ) { if ( serviceDescription != null ) { V1ServiceDescription result = new V1ServiceDescription ( ) ; result . setRegistrationPropertyDescription ( toV1ModelDescription ( serviceDescription . getRegistrationPropertyDescription ( ) ) ) ; result . setRequiresInitCookie ( toV1CookieProtocol ( serviceDescription . getRequiresInitCookie ( ) ) ) ; result . setRequiresRegistration ( serviceDescription . isRequiresRegistration ( ) ) ; result . setResourceList ( toV1ResourceList ( serviceDescription . getResourceList ( ) ) ) ; List < V1ItemDescription > modes = WSRPUtils . transform ( serviceDescription . getCustomModeDescriptions ( ) , ITEMDESCRIPTION ) ; if ( modes != null ) { result . getCustomModeDescriptions ( ) . addAll ( modes ) ; } List < V1ItemDescription > windowStates = WSRPUtils . transform ( serviceDescription . getCustomWindowStateDescriptions ( ) , ITEMDESCRIPTION ) ; if ( windowStates != null ) { result . getCustomWindowStateDescriptions ( ) . addAll ( windowStates ) ; } List < V1Extension > extensions = WSRPUtils . transform ( serviceDescription . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } List < String > locales = result . getLocales ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( locales ) ) { result . getLocales ( ) . addAll ( locales ) ; } List < V1ItemDescription > userCategories = WSRPUtils . transform ( serviceDescription . getUserCategoryDescriptions ( ) , ITEMDESCRIPTION ) ; if ( userCategories != null ) { result . getUserCategoryDescriptions ( ) . addAll ( userCategories ) ; } List < V1PortletDescription > portletDescriptions = WSRPUtils . transform ( serviceDescription . getOfferedPortlets ( ) , PORTLETDESCRIPTION ) ; if ( portletDescriptions != null ) { result . getOfferedPortlets ( ) . addAll ( portletDescriptions ) ; } return result ; } else { return null ; } } public static V1MarkupResponse toV1MarkupResponse ( MarkupResponse markupResponse ) { if ( markupResponse != null ) { V1MarkupResponse result = WSRP1TypeFactory . createMarkupResponse ( toV1MarkupContext ( markupResponse . getMarkupContext ( ) ) ) ; result . setSessionContext ( toV1SessionContext ( markupResponse . getSessionContext ( ) ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( markupResponse . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1ReturnAny toV1ReturnAny ( ReturnAny returnAny ) { if ( returnAny != null ) { V1ReturnAny result = new V1ReturnAny ( ) ; List < V1Extension > extensions = WSRPUtils . transform ( returnAny . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1RegistrationState toV1RegistrationState ( RegistrationState registrationState ) { if ( registrationState != null ) { V1RegistrationState result = new V1RegistrationState ( ) ; result . setRegistrationState ( registrationState . getRegistrationState ( ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( registrationState . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1BlockingInteractionResponse toV1BlockingInteractionResponse ( BlockingInteractionResponse blockingInteractionResponse ) { if ( blockingInteractionResponse != null ) { V1BlockingInteractionResponse result ; V1UpdateResponse updateResponse = toV1UpdateResponse ( blockingInteractionResponse . getUpdateResponse ( ) ) ; String redirectURL = blockingInteractionResponse . getRedirectURL ( ) ; if ( redirectURL != null ) { result = WSRP1TypeFactory . createBlockingInteractionResponse ( redirectURL ) ; } else { result = WSRP1TypeFactory . createBlockingInteractionResponse ( updateResponse ) ; } List < V1Extension > extensions = WSRPUtils . transform ( blockingInteractionResponse . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1DestroyPortletsResponse toV1DestroyPortlesResponse ( DestroyPortletsResponse destroyPortletResponse ) { if ( destroyPortletResponse != null ) { List < V1DestroyFailed > destroyedFailed = WSRPUtils . transform ( destroyPortletResponse . getFailedPortlets ( ) , FAILEDPORTLET ) ; V1DestroyPortletsResponse result = WSRP1TypeFactory . createDestroyPortletsResponse ( destroyedFailed ) ; List < V1Extension > extensions = WSRPUtils . transform ( destroyPortletResponse . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1PortletPropertyDescriptionResponse toV1PortletPropertyDescriptionResponse ( PortletPropertyDescriptionResponse portletPropertyDescriptionResponse ) { if ( portletPropertyDescriptionResponse != null ) { V1PortletPropertyDescriptionResponse result = new V1PortletPropertyDescriptionResponse ( ) ; result . setModelDescription ( toV1ModelDescription ( portletPropertyDescriptionResponse . getModelDescription ( ) ) ) ; result . setResourceList ( toV1ResourceList ( portletPropertyDescriptionResponse . getResourceList ( ) ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( portletPropertyDescriptionResponse . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1PortletDescriptionResponse toV1PortletDescriptionResponse ( PortletDescriptionResponse portletDescriptionResponse ) { if ( portletDescriptionResponse != null ) { V1PortletDescriptionResponse result = WSRP1TypeFactory . createPortletDescriptionResponse ( toV1PortletDescription ( portletDescriptionResponse . getPortletDescription ( ) ) ) ; result . setResourceList ( toV1ResourceList ( portletDescriptionResponse . getResourceList ( ) ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( portletDescriptionResponse . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static V1PropertyDescription toV1PropertyDescription ( PropertyDescription propertyDescription ) { if ( propertyDescription != null ) { V1PropertyDescription result = WSRP1TypeFactory . createPropertyDescription ( propertyDescription . getName ( ) . toString ( ) , propertyDescription . getType ( ) ) ; result . setHint ( toV1LocalizedString ( propertyDescription . getHint ( ) ) ) ; result . setLabel ( toV1LocalizedString ( propertyDescription . getLabel ( ) ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( propertyDescription . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } private static class V2ToV1Extension implements Function < Extension , V1Extension > { public V1Extension apply ( Extension from ) { if ( from != null ) { V1Extension extension = new V1Extension ( ) ; extension . setAny ( from . getAny ( ) ) ; return extension ; } else { return null ; } } } private static class V2ToV1PortletDescription implements Function < PortletDescription , V1PortletDescription > { public V1PortletDescription apply ( PortletDescription from ) { if ( from != null ) { V1PortletDescription result = WSRP1TypeFactory . createPortletDescription ( from . getPortletHandle ( ) , WSRPUtils . transform ( from . getMarkupTypes ( ) , MARKUPTYPE ) ) ; result . setDescription ( LOCALIZEDSTRING . apply ( from . getDescription ( ) ) ) ; result . setDisplayName ( LOCALIZEDSTRING . apply ( from . getDisplayName ( ) ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } List < V1LocalizedString > keywords = WSRPUtils . transform ( from . getKeywords ( ) , LOCALIZEDSTRING ) ; if ( keywords != null ) { result . getKeywords ( ) . addAll ( keywords ) ; } List < String > userCategories = from . getUserCategories ( ) ; if ( userCategories != null ) { result . getUserCategories ( ) . addAll ( userCategories ) ; } List < String > userProfileItems = from . getUserProfileItems ( ) ; if ( userProfileItems != null ) { result . getUserProfileItems ( ) . addAll ( userProfileItems ) ; } result . setDefaultMarkupSecure ( from . isDefaultMarkupSecure ( ) ) ; result . setDoesUrlTemplateProcessing ( from . isDoesUrlTemplateProcessing ( ) ) ; result . setTemplatesStoredInSession ( from . isTemplatesStoredInSession ( ) ) ; result . setHasUserSpecificState ( from . isHasUserSpecificState ( ) ) ; result . setOnlySecure ( from . isOnlySecure ( ) ) ; result . setUserContextStoredInSession ( from . isUserContextStoredInSession ( ) ) ; result . setUsesMethodGet ( from . isUsesMethodGet ( ) ) ; result . setShortTitle ( LOCALIZEDSTRING . apply ( from . getShortTitle ( ) ) ) ; result . setTitle ( LOCALIZEDSTRING . apply ( from . getTitle ( ) ) ) ; result . setGroupID ( from . getGroupID ( ) ) ; return result ; } else { return null ; } } } private static class V2ToV1ItemDescription implements Function < ItemDescription , V1ItemDescription > { public V1ItemDescription apply ( ItemDescription from ) { if ( from != null ) { V1ItemDescription result = new V1ItemDescription ( ) ; result . setItemName ( from . getItemName ( ) ) ; if ( from . getDescription ( ) != null ) { result . setDescription ( LOCALIZEDSTRING . apply ( from . getDescription ( ) ) ) ; } else if ( from . getDisplayName ( ) != null ) { result . setDescription ( LOCALIZEDSTRING . apply ( from . getDisplayName ( ) ) ) ; } else { result . setDescription ( WSRP1TypeFactory . createLocalizedString ( "<STR_LIT>" ) ) ; } List < V1Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } public static class V2ToV1NamedString implements Function < NamedString , V1NamedString > { public V1NamedString apply ( NamedString namedString ) { if ( namedString != null ) { V1NamedString result = new V1NamedString ( ) ; result . setName ( namedString . getName ( ) ) ; if ( namedString . getValue ( ) == null ) { result . setValue ( namedString . getName ( ) ) ; } else { result . setValue ( namedString . getValue ( ) ) ; } return result ; } else { return null ; } } } public static class V2ToV1UploadContext implements Function < UploadContext , V1UploadContext > { public V1UploadContext apply ( UploadContext uploadContext ) { if ( uploadContext != null ) { V1UploadContext result = WSRP1TypeFactory . createUploadContext ( uploadContext . getMimeType ( ) , uploadContext . getUploadData ( ) ) ; List < Extension > extensions = uploadContext . getExtensions ( ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( Lists . transform ( extensions , EXTENSION ) ) ; } List < NamedString > mimeAttributes = uploadContext . getMimeAttributes ( ) ; if ( mimeAttributes != null ) { result . getMimeAttributes ( ) . addAll ( Lists . transform ( mimeAttributes , NAMEDSTRING ) ) ; } return result ; } else { return null ; } } } private static class V2ToV1MarkupType implements Function < MarkupType , V1MarkupType > { public V1MarkupType apply ( MarkupType from ) { if ( from != null ) { V1MarkupType result = WSRP1TypeFactory . createMarkupType ( from . getMimeType ( ) , from . getModes ( ) , from . getWindowStates ( ) , from . getLocales ( ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } private static class V2ToV1LocalizedString implements Function < LocalizedString , V1LocalizedString > { public V1LocalizedString apply ( LocalizedString from ) { if ( from != null ) { return WSRP1TypeFactory . createLocalizedString ( from . getLang ( ) , from . getResourceName ( ) , from . getValue ( ) ) ; } else { return null ; } } } private static class V2ToV1PropertyDescription implements Function < PropertyDescription , V1PropertyDescription > { public V1PropertyDescription apply ( PropertyDescription from ) { return toV1PropertyDescription ( from ) ; } } private static class V2ToV1Resource implements Function < Resource , V1Resource > { public V1Resource apply ( Resource from ) { if ( from != null ) { V1Resource result = new V1Resource ( ) ; result . setResourceName ( from . getResourceName ( ) ) ; List < V1ResourceValue > values = WSRPUtils . transform ( from . getValues ( ) , RESOURCEVALUE ) ; if ( values != null ) { result . getValues ( ) . addAll ( values ) ; } return result ; } else { return null ; } } } private static class V2ToV1ResourceValue implements Function < ResourceValue , V1ResourceValue > { public V1ResourceValue apply ( ResourceValue from ) { if ( from != null ) { V1ResourceValue result = new V1ResourceValue ( ) ; result . setLang ( from . getLang ( ) ) ; result . setValue ( from . getValue ( ) ) ; List < V1Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } private static class V2ToV1Property implements Function < Property , V1Property > { public V1Property apply ( Property from ) { if ( from != null ) { V1Property result = WSRP1TypeFactory . createProperty ( from . getName ( ) . toString ( ) , from . getLang ( ) , from . getStringValue ( ) ) ; List < Object > any = from . getAny ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( any ) ) { result . getAny ( ) . addAll ( any ) ; } return result ; } else { return null ; } } } private static class V2ToV1ResetProperty implements Function < ResetProperty , V1ResetProperty > { public V1ResetProperty apply ( ResetProperty from ) { if ( from != null ) { return WSRP1TypeFactory . createResetProperty ( from . getName ( ) . toString ( ) ) ; } else { return null ; } } } private static class V2ToV1FailedPortlets implements Function < FailedPortlets , V1DestroyFailed > { public V1ResetProperty apply ( ResetProperty from ) { if ( from != null ) { return WSRP1TypeFactory . createResetProperty ( from . getName ( ) . toString ( ) ) ; } else { return null ; } } public V1DestroyFailed apply ( FailedPortlets from ) { if ( from != null ) { return WSRP1TypeFactory . createDestroyFailed ( from . getPortletHandles ( ) . get ( <NUM_LIT:0> ) , from . getReason ( ) . toString ( ) ) ; } return null ; } } } </s>
<s> package org . gatein . wsrp . spec . v1 ; import com . google . common . base . Function ; import com . google . common . collect . Lists ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . OpaqueStateString ; import org . gatein . pc . portlet . impl . jsr168 . PortletUtils ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . WSRPExceptionFactory ; import org . gatein . wsrp . WSRPTypeFactory ; import org . gatein . wsrp . WSRPUtils ; import org . gatein . wsrp . spec . v2 . ErrorCodes ; import org . oasis . wsrp . v1 . V1CacheControl ; import org . oasis . wsrp . v1 . V1ClientData ; import org . oasis . wsrp . v1 . V1ClonePortlet ; import org . oasis . wsrp . v1 . V1Contact ; import org . oasis . wsrp . v1 . V1CookieProtocol ; import org . oasis . wsrp . v1 . V1DestroyFailed ; import org . oasis . wsrp . v1 . V1DestroyPortlets ; import org . oasis . wsrp . v1 . V1EmployerInfo ; import org . oasis . wsrp . v1 . V1Extension ; import org . oasis . wsrp . v1 . V1GetMarkup ; import org . oasis . wsrp . v1 . V1GetPortletDescription ; import org . oasis . wsrp . v1 . V1GetPortletProperties ; import org . oasis . wsrp . v1 . V1GetPortletPropertyDescription ; import org . oasis . wsrp . v1 . V1GetServiceDescription ; import org . oasis . wsrp . v1 . V1InitCookie ; import org . oasis . wsrp . v1 . V1InteractionParams ; import org . oasis . wsrp . v1 . V1ItemDescription ; import org . oasis . wsrp . v1 . V1LocalizedString ; import org . oasis . wsrp . v1 . V1MarkupContext ; import org . oasis . wsrp . v1 . V1MarkupParams ; import org . oasis . wsrp . v1 . V1MarkupType ; import org . oasis . wsrp . v1 . V1ModelDescription ; import org . oasis . wsrp . v1 . V1ModelTypes ; import org . oasis . wsrp . v1 . V1ModifyRegistration ; import org . oasis . wsrp . v1 . V1NamedString ; import org . oasis . wsrp . v1 . V1Online ; import org . oasis . wsrp . v1 . V1PerformBlockingInteraction ; import org . oasis . wsrp . v1 . V1PersonName ; import org . oasis . wsrp . v1 . V1PortletContext ; import org . oasis . wsrp . v1 . V1PortletDescription ; import org . oasis . wsrp . v1 . V1Postal ; import org . oasis . wsrp . v1 . V1Property ; import org . oasis . wsrp . v1 . V1PropertyDescription ; import org . oasis . wsrp . v1 . V1PropertyList ; import org . oasis . wsrp . v1 . V1RegistrationContext ; import org . oasis . wsrp . v1 . V1RegistrationData ; import org . oasis . wsrp . v1 . V1ReleaseSessions ; import org . oasis . wsrp . v1 . V1ResetProperty ; import org . oasis . wsrp . v1 . V1Resource ; import org . oasis . wsrp . v1 . V1ResourceList ; import org . oasis . wsrp . v1 . V1ResourceValue ; import org . oasis . wsrp . v1 . V1RuntimeContext ; import org . oasis . wsrp . v1 . V1SessionContext ; import org . oasis . wsrp . v1 . V1SetPortletProperties ; import org . oasis . wsrp . v1 . V1StateChange ; import org . oasis . wsrp . v1 . V1Telecom ; import org . oasis . wsrp . v1 . V1TelephoneNum ; import org . oasis . wsrp . v1 . V1Templates ; import org . oasis . wsrp . v1 . V1UpdateResponse ; import org . oasis . wsrp . v1 . V1UploadContext ; import org . oasis . wsrp . v1 . V1UserContext ; import org . oasis . wsrp . v1 . V1UserProfile ; import org . oasis . wsrp . v2 . CacheControl ; import org . oasis . wsrp . v2 . ClientData ; import org . oasis . wsrp . v2 . ClonePortlet ; import org . oasis . wsrp . v2 . Contact ; import org . oasis . wsrp . v2 . CookieProtocol ; import org . oasis . wsrp . v2 . DestroyPortlets ; import org . oasis . wsrp . v2 . EmployerInfo ; import org . oasis . wsrp . v2 . Extension ; import org . oasis . wsrp . v2 . FailedPortlets ; import org . oasis . wsrp . v2 . GetMarkup ; import org . oasis . wsrp . v2 . GetPortletDescription ; import org . oasis . wsrp . v2 . GetPortletProperties ; import org . oasis . wsrp . v2 . GetPortletPropertyDescription ; import org . oasis . wsrp . v2 . GetServiceDescription ; import org . oasis . wsrp . v2 . InitCookie ; import org . oasis . wsrp . v2 . InteractionParams ; import org . oasis . wsrp . v2 . ItemDescription ; import org . oasis . wsrp . v2 . LocalizedString ; import org . oasis . wsrp . v2 . MarkupContext ; import org . oasis . wsrp . v2 . MarkupParams ; import org . oasis . wsrp . v2 . MarkupType ; import org . oasis . wsrp . v2 . ModelDescription ; import org . oasis . wsrp . v2 . ModelTypes ; import org . oasis . wsrp . v2 . ModifyRegistration ; import org . oasis . wsrp . v2 . NamedString ; import org . oasis . wsrp . v2 . Online ; import org . oasis . wsrp . v2 . PerformBlockingInteraction ; import org . oasis . wsrp . v2 . PersonName ; import org . oasis . wsrp . v2 . PortletContext ; import org . oasis . wsrp . v2 . PortletDescription ; import org . oasis . wsrp . v2 . Postal ; import org . oasis . wsrp . v2 . Property ; import org . oasis . wsrp . v2 . PropertyDescription ; import org . oasis . wsrp . v2 . PropertyList ; import org . oasis . wsrp . v2 . RegistrationContext ; import org . oasis . wsrp . v2 . RegistrationData ; import org . oasis . wsrp . v2 . ReleaseSessions ; import org . oasis . wsrp . v2 . ResetProperty ; import org . oasis . wsrp . v2 . Resource ; import org . oasis . wsrp . v2 . ResourceList ; import org . oasis . wsrp . v2 . ResourceValue ; import org . oasis . wsrp . v2 . RuntimeContext ; import org . oasis . wsrp . v2 . SessionContext ; import org . oasis . wsrp . v2 . SessionParams ; import org . oasis . wsrp . v2 . SetPortletProperties ; import org . oasis . wsrp . v2 . StateChange ; import org . oasis . wsrp . v2 . Telecom ; import org . oasis . wsrp . v2 . TelephoneNum ; import org . oasis . wsrp . v2 . Templates ; import org . oasis . wsrp . v2 . UpdateResponse ; import org . oasis . wsrp . v2 . UploadContext ; import org . oasis . wsrp . v2 . UserContext ; import org . oasis . wsrp . v2 . UserProfile ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import javax . xml . datatype . XMLGregorianCalendar ; public class V1ToV2Converter { public static final V1ToV2Extension EXTENSION = new V1ToV2Extension ( ) ; public static final V1ToV2MarkupType MARKUPTYPE = new V1ToV2MarkupType ( ) ; public static final V1ToV2PortletDescription PORTLETDESCRIPTION = new V1ToV2PortletDescription ( ) ; public static final V1ToV2LocalizedString LOCALIZEDSTRING = new V1ToV2LocalizedString ( ) ; public static final V1ToV2ItemDescription ITEMDESCRIPTION = new V1ToV2ItemDescription ( ) ; public static final V1ToV2PropertyDescription PROPERTYDESCRIPTION = new V1ToV2PropertyDescription ( ) ; public static final V1ToV2Resource RESOURCE = new V1ToV2Resource ( ) ; public static final V1ToV2ResourceValue RESOURCEVALUE = new V1ToV2ResourceValue ( ) ; public static final V1ToV2NamedString NAMEDSTRING = new V1ToV2NamedString ( ) ; public static final V1ToV2UploadContext UPLOADCONTEXT = new V1ToV2UploadContext ( ) ; public static final V1ToV2Property PROPERTY = new V1ToV2Property ( ) ; public static final V1ToV2ResetProperty RESETPROPERTY = new V1ToV2ResetProperty ( ) ; public static MarkupParams toV2MarkupParams ( V1MarkupParams v1MarkupParams ) { if ( v1MarkupParams != null ) { MarkupParams markupParams = WSRPTypeFactory . createMarkupParams ( v1MarkupParams . isSecureClientCommunication ( ) , v1MarkupParams . getLocales ( ) , v1MarkupParams . getMimeTypes ( ) , v1MarkupParams . getMode ( ) , v1MarkupParams . getWindowState ( ) ) ; markupParams . setClientData ( toV2ClientData ( v1MarkupParams . getClientData ( ) ) ) ; if ( v1MarkupParams . getNavigationalState ( ) != null ) { markupParams . setNavigationalContext ( WSRPTypeFactory . createNavigationalContextOrNull ( new OpaqueStateString ( v1MarkupParams . getNavigationalState ( ) ) , null ) ) ; } markupParams . setValidateTag ( v1MarkupParams . getValidateTag ( ) ) ; List < String > charSets = v1MarkupParams . getMarkupCharacterSets ( ) ; if ( charSets != null ) { markupParams . getMarkupCharacterSets ( ) . addAll ( charSets ) ; } List < String > validNewModes = v1MarkupParams . getValidNewModes ( ) ; if ( validNewModes != null ) { markupParams . getValidNewModes ( ) . addAll ( validNewModes ) ; } List < String > validNewWindowStates = v1MarkupParams . getValidNewWindowStates ( ) ; if ( validNewWindowStates != null ) { markupParams . getValidNewWindowStates ( ) . addAll ( validNewWindowStates ) ; } List < Extension > extensions = WSRPUtils . transform ( v1MarkupParams . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { markupParams . getExtensions ( ) . addAll ( extensions ) ; } return markupParams ; } else { return null ; } } public static ClientData toV2ClientData ( V1ClientData v1ClientData ) { if ( v1ClientData != null ) { ClientData clientData = WSRPTypeFactory . createClientData ( v1ClientData . getUserAgent ( ) ) ; List < V1Extension > extensions = v1ClientData . getExtensions ( ) ; if ( extensions != null ) { clientData . getExtensions ( ) . addAll ( Lists . transform ( extensions , EXTENSION ) ) ; } return clientData ; } else { return null ; } } public static PortletContext toV2PortletContext ( V1PortletContext v1PortletContext ) { if ( v1PortletContext != null ) { PortletContext portletContext = WSRPTypeFactory . createPortletContext ( v1PortletContext . getPortletHandle ( ) , v1PortletContext . getPortletState ( ) ) ; List < V1Extension > extensions = v1PortletContext . getExtensions ( ) ; if ( extensions != null ) { portletContext . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return portletContext ; } else { return null ; } } public static RegistrationContext toV2RegistrationContext ( V1RegistrationContext registrationContext ) { if ( registrationContext != null ) { RegistrationContext result = WSRPTypeFactory . createRegistrationContext ( registrationContext . getRegistrationHandle ( ) ) ; result . setRegistrationState ( registrationContext . getRegistrationState ( ) ) ; List < Extension > extensions = WSRPUtils . transform ( registrationContext . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static RuntimeContext toV2RuntimeContext ( V1RuntimeContext v1RuntimeContext , String portletHandle ) { if ( v1RuntimeContext != null ) { String portletInstanceKey ; String namespacePrefix ; if ( ParameterValidation . isNullOrEmpty ( v1RuntimeContext . getPortletInstanceKey ( ) ) ) { portletInstanceKey = portletHandle ; } else { portletInstanceKey = v1RuntimeContext . getPortletInstanceKey ( ) ; } if ( ParameterValidation . isNullOrEmpty ( v1RuntimeContext . getNamespacePrefix ( ) ) ) { namespacePrefix = PortletUtils . generateNamespaceFrom ( portletHandle ) ; } else { namespacePrefix = v1RuntimeContext . getNamespacePrefix ( ) ; } RuntimeContext runtimeContext = WSRPTypeFactory . createRuntimeContext ( v1RuntimeContext . getUserAuthentication ( ) , portletInstanceKey , namespacePrefix ) ; SessionParams sessionParams = WSRPTypeFactory . createSessionParams ( v1RuntimeContext . getSessionID ( ) ) ; runtimeContext . setSessionParams ( sessionParams ) ; runtimeContext . setTemplates ( toV2Templates ( v1RuntimeContext . getTemplates ( ) ) ) ; List < V1Extension > extensions = v1RuntimeContext . getExtensions ( ) ; if ( extensions != null ) { runtimeContext . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return runtimeContext ; } else { return null ; } } public static Templates toV2Templates ( V1Templates v1Templates ) { if ( v1Templates != null ) { String defaultTemplate = v1Templates . getDefaultTemplate ( ) ; String blockingActionTemplate = v1Templates . getBlockingActionTemplate ( ) ; String renderTemplate = v1Templates . getRenderTemplate ( ) ; String resourceTemplate = v1Templates . getResourceTemplate ( ) ; String secureDefaultTemplate = v1Templates . getSecureDefaultTemplate ( ) ; String secureBlockingActionTemplate = v1Templates . getSecureBlockingActionTemplate ( ) ; String secureRenderTemplate = v1Templates . getSecureRenderTemplate ( ) ; String secureResourceTemplate = v1Templates . getSecureResourceTemplate ( ) ; Templates templates = WSRPTypeFactory . createTemplates ( defaultTemplate , blockingActionTemplate , renderTemplate , resourceTemplate , secureDefaultTemplate , secureBlockingActionTemplate , secureRenderTemplate , secureResourceTemplate ) ; List < V1Extension > extensions = v1Templates . getExtensions ( ) ; if ( extensions != null ) { templates . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return templates ; } else { return null ; } } public static UserContext toV2UserContext ( V1UserContext v1UserContext ) { if ( v1UserContext != null ) { UserContext userContext = WSRPTypeFactory . createUserContext ( v1UserContext . getUserContextKey ( ) ) ; userContext . setProfile ( toV2UserProfile ( v1UserContext . getProfile ( ) ) ) ; List < V1Extension > extensions = v1UserContext . getExtensions ( ) ; if ( extensions != null ) { userContext . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } if ( v1UserContext . getUserCategories ( ) != null ) { userContext . getUserCategories ( ) . addAll ( v1UserContext . getUserCategories ( ) ) ; } return userContext ; } else { return null ; } } public static UserProfile toV2UserProfile ( V1UserProfile v1UserProfile ) { if ( v1UserProfile != null ) { PersonName name = toV2PersonName ( v1UserProfile . getName ( ) ) ; XMLGregorianCalendar bdate = v1UserProfile . getBdate ( ) ; String gender = v1UserProfile . getGender ( ) ; EmployerInfo employerInfo = toV2EmployerInfo ( v1UserProfile . getEmployerInfo ( ) ) ; Contact homeInfo = toV2Context ( v1UserProfile . getHomeInfo ( ) ) ; Contact businessInfo = toV2Context ( v1UserProfile . getBusinessInfo ( ) ) ; UserProfile userProfile = WSRPTypeFactory . createUserProfile ( name , bdate , gender , employerInfo , homeInfo , businessInfo ) ; return userProfile ; } else { return null ; } } public static EmployerInfo toV2EmployerInfo ( V1EmployerInfo v1EmployerInfo ) { if ( v1EmployerInfo != null ) { String employer = v1EmployerInfo . getEmployer ( ) ; String department = v1EmployerInfo . getEmployer ( ) ; String jobTitle = v1EmployerInfo . getJobtitle ( ) ; EmployerInfo employerInfo = WSRPTypeFactory . createEmployerInfo ( employer , department , jobTitle ) ; List < V1Extension > extensions = v1EmployerInfo . getExtensions ( ) ; if ( extensions != null ) { employerInfo . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return employerInfo ; } else { return null ; } } public static PersonName toV2PersonName ( V1PersonName v1PersonName ) { if ( v1PersonName != null ) { PersonName personName = WSRPTypeFactory . createPersonName ( v1PersonName . getPrefix ( ) , v1PersonName . getGiven ( ) , v1PersonName . getFamily ( ) , v1PersonName . getMiddle ( ) , v1PersonName . getSuffix ( ) , v1PersonName . getNickname ( ) ) ; List < V1Extension > extensions = v1PersonName . getExtensions ( ) ; if ( extensions != null ) { personName . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return personName ; } else { return null ; } } public static Contact toV2Context ( V1Contact v1Contact ) { if ( v1Contact != null ) { Postal postal = toV2Postal ( v1Contact . getPostal ( ) ) ; Telecom teleCom = toV2Telecom ( v1Contact . getTelecom ( ) ) ; Online online = toV2Online ( v1Contact . getOnline ( ) ) ; Contact contact = WSRPTypeFactory . createContact ( postal , teleCom , online ) ; List < V1Extension > extensions = v1Contact . getExtensions ( ) ; if ( extensions != null ) { contact . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return contact ; } else { return null ; } } public static Online toV2Online ( V1Online v1Online ) { if ( v1Online != null ) { Online online = WSRPTypeFactory . createOnline ( v1Online . getEmail ( ) , v1Online . getUri ( ) ) ; List < V1Extension > extensions = v1Online . getExtensions ( ) ; if ( extensions != null ) { online . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return online ; } else { return null ; } } public static Postal toV2Postal ( V1Postal v1Postal ) { if ( v1Postal != null ) { Postal postal = WSRPTypeFactory . createPostal ( v1Postal . getName ( ) , v1Postal . getStreet ( ) , v1Postal . getCity ( ) , v1Postal . getStateprov ( ) , v1Postal . getPostalcode ( ) , v1Postal . getCountry ( ) , v1Postal . getOrganization ( ) ) ; List < V1Extension > extensions = v1Postal . getExtensions ( ) ; if ( extensions != null ) { postal . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return postal ; } else { return null ; } } public static Telecom toV2Telecom ( V1Telecom v1Telecom ) { if ( v1Telecom != null ) { TelephoneNum telephone = toV2TelephoneNum ( v1Telecom . getTelephone ( ) ) ; TelephoneNum fax = toV2TelephoneNum ( v1Telecom . getFax ( ) ) ; TelephoneNum mobile = toV2TelephoneNum ( v1Telecom . getMobile ( ) ) ; TelephoneNum pager = toV2TelephoneNum ( v1Telecom . getPager ( ) ) ; Telecom telecom = WSRPTypeFactory . createTelecom ( telephone , fax , mobile , pager ) ; List < V1Extension > extensions = v1Telecom . getExtensions ( ) ; if ( extensions != null ) { telecom . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return telecom ; } else { return null ; } } public static TelephoneNum toV2TelephoneNum ( V1TelephoneNum v1TelephoneNum ) { if ( v1TelephoneNum != null ) { String intCode = v1TelephoneNum . getIntcode ( ) ; String loccode = v1TelephoneNum . getLoccode ( ) ; String number = v1TelephoneNum . getNumber ( ) ; String ext = v1TelephoneNum . getExt ( ) ; String comment = v1TelephoneNum . getComment ( ) ; TelephoneNum telephoneNum = WSRPTypeFactory . createTelephoneNum ( intCode , loccode , number , ext , comment ) ; List < V1Extension > extensions = v1TelephoneNum . getExtensions ( ) ; if ( extensions != null ) { telephoneNum . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return telephoneNum ; } else { return null ; } } public static < E extends Exception > E toV2Exception ( Class < E > v2ExceptionClass , Exception v1Exception ) { if ( ! "<STR_LIT>" . equals ( v2ExceptionClass . getPackage ( ) . getName ( ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + v2ExceptionClass ) ; } Class < ? extends Exception > v1ExceptionClass = v1Exception . getClass ( ) ; String v1Name = v1ExceptionClass . getSimpleName ( ) ; int v1Index = v1Name . indexOf ( "<STR_LIT>" ) ; if ( v1Index != <NUM_LIT:0> && ! "<STR_LIT>" . equals ( v1ExceptionClass . getPackage ( ) . getName ( ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + v1Exception ) ; } String v2Name = v2ExceptionClass . getSimpleName ( ) ; if ( ! v2Name . equals ( v1Name . substring ( <NUM_LIT:2> ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + v2Name + "<STR_LIT>" + v1Name ) ; } return WSRPExceptionFactory . createWSException ( v2ExceptionClass , v1Exception . getMessage ( ) , v1Exception . getCause ( ) ) ; } public static InteractionParams toV2InteractionParams ( V1InteractionParams v1InteractionParams ) { if ( v1InteractionParams != null ) { InteractionParams interactionParams = WSRPTypeFactory . createInteractionParams ( toV2StateChange ( v1InteractionParams . getPortletStateChange ( ) ) ) ; interactionParams . setInteractionState ( v1InteractionParams . getInteractionState ( ) ) ; interactionParams . getExtensions ( ) . addAll ( Lists . transform ( v1InteractionParams . getExtensions ( ) , EXTENSION ) ) ; interactionParams . getFormParameters ( ) . addAll ( Lists . transform ( v1InteractionParams . getFormParameters ( ) , NAMEDSTRING ) ) ; interactionParams . getUploadContexts ( ) . addAll ( Lists . transform ( v1InteractionParams . getUploadContexts ( ) , UPLOADCONTEXT ) ) ; return interactionParams ; } else { return null ; } } public static StateChange toV2StateChange ( V1StateChange v1StateChange ) { if ( v1StateChange != null ) { return StateChange . fromValue ( ( v1StateChange . value ( ) ) ) ; } else { return null ; } } public static LocalizedString toV2LocalizedString ( V1LocalizedString localizedString ) { return LOCALIZEDSTRING . apply ( localizedString ) ; } public static CookieProtocol toV2CookieProtocol ( V1CookieProtocol v1CookieProtocol ) { if ( v1CookieProtocol != null ) { return CookieProtocol . fromValue ( v1CookieProtocol . value ( ) ) ; } else { return null ; } } public static ModelDescription toV2ModelDescription ( V1ModelDescription v1ModelDescription ) { if ( v1ModelDescription != null ) { ModelDescription result = WSRPTypeFactory . createModelDescription ( WSRPUtils . transform ( v1ModelDescription . getPropertyDescriptions ( ) , PROPERTYDESCRIPTION ) ) ; List < Extension > extensions = WSRPUtils . transform ( v1ModelDescription . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } result . setModelTypes ( toV2ModelTypes ( v1ModelDescription . getModelTypes ( ) ) ) ; return result ; } else { return null ; } } public static ModelTypes toV2ModelTypes ( V1ModelTypes modelTypes ) { if ( modelTypes != null ) { ModelTypes result = new ModelTypes ( ) ; result . setAny ( modelTypes . getAny ( ) ) ; return result ; } else { return null ; } } public static ResourceList toV2ResourceList ( V1ResourceList v1ResourceList ) { if ( v1ResourceList != null ) { List < Resource > resources = WSRPUtils . transform ( v1ResourceList . getResources ( ) , RESOURCE ) ; ResourceList result = WSRPTypeFactory . createResourceList ( resources ) ; List < Extension > extensions = WSRPUtils . transform ( v1ResourceList . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static PropertyList toV2PropertyList ( V1PropertyList v1PropertyList ) { if ( v1PropertyList != null ) { PropertyList result = WSRPTypeFactory . createPropertyList ( ) ; List < Property > properties = WSRPUtils . transform ( v1PropertyList . getProperties ( ) , PROPERTY ) ; if ( properties != null ) { result . getProperties ( ) . addAll ( properties ) ; } List < ResetProperty > resetProperties = WSRPUtils . transform ( v1PropertyList . getResetProperties ( ) , RESETPROPERTY ) ; if ( resetProperties != null ) { result . getResetProperties ( ) . addAll ( resetProperties ) ; } List < Extension > extensions = WSRPUtils . transform ( v1PropertyList . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static PortletDescription toV2PortletDescription ( V1PortletDescription v1PortletDescription ) { return PORTLETDESCRIPTION . apply ( v1PortletDescription ) ; } public static List < FailedPortlets > toV2FailedPortlets ( List < V1DestroyFailed > destroyFailed ) { if ( ParameterValidation . existsAndIsNotEmpty ( destroyFailed ) ) { List < FailedPortlets > result = new ArrayList < FailedPortlets > ( destroyFailed . size ( ) ) ; for ( V1DestroyFailed failed : destroyFailed ) { result . add ( WSRPTypeFactory . createFailedPortlets ( Collections . singletonList ( failed . getPortletHandle ( ) ) , ErrorCodes . Codes . OPERATIONFAILED , failed . getReason ( ) ) ) ; } return result ; } else { return null ; } } public static RegistrationData toV2RegistrationData ( V1RegistrationData registrationData ) { if ( registrationData != null ) { RegistrationData result = WSRPTypeFactory . createRegistrationData ( registrationData . getConsumerName ( ) , registrationData . getConsumerAgent ( ) , registrationData . isMethodGetSupported ( ) ) ; List < Property > properties = WSRPUtils . transform ( registrationData . getRegistrationProperties ( ) , PROPERTY ) ; if ( properties != null ) { result . getRegistrationProperties ( ) . addAll ( properties ) ; } List < String > modes = registrationData . getConsumerModes ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( modes ) ) { result . getConsumerModes ( ) . addAll ( modes ) ; } List < String > consumerUserScopes = registrationData . getConsumerUserScopes ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( consumerUserScopes ) ) { result . getConsumerUserScopes ( ) . addAll ( consumerUserScopes ) ; } List < String > windowStates = registrationData . getConsumerWindowStates ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( windowStates ) ) { result . getConsumerWindowStates ( ) . addAll ( windowStates ) ; } List < Extension > extensions = WSRPUtils . transform ( registrationData . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } public static MarkupContext toV2MarkupContext ( V1MarkupContext v1MarkupContext ) { if ( v1MarkupContext != null ) { MarkupContext result = WSRPTypeFactory . createMarkupContext ( v1MarkupContext . getMimeType ( ) , v1MarkupContext . getMarkupString ( ) , v1MarkupContext . getMarkupBinary ( ) , v1MarkupContext . isUseCachedMarkup ( ) ) ; result . setCacheControl ( toV2CacheControl ( v1MarkupContext . getCacheControl ( ) ) ) ; result . setLocale ( v1MarkupContext . getLocale ( ) ) ; result . setMimeType ( v1MarkupContext . getMimeType ( ) ) ; result . setPreferredTitle ( v1MarkupContext . getPreferredTitle ( ) ) ; result . setRequiresRewriting ( v1MarkupContext . isRequiresUrlRewriting ( ) ) ; List < V1Extension > extensions = v1MarkupContext . getExtensions ( ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return result ; } else { return null ; } } private static CacheControl toV2CacheControl ( V1CacheControl v1CacheControl ) { if ( v1CacheControl != null ) { CacheControl result = WSRPTypeFactory . createCacheControl ( v1CacheControl . getExpires ( ) , v1CacheControl . getUserScope ( ) ) ; result . setValidateTag ( v1CacheControl . getValidateTag ( ) ) ; List < V1Extension > extensions = v1CacheControl . getExtensions ( ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( WSRPUtils . transform ( extensions , EXTENSION ) ) ; } return result ; } else { return null ; } } public static SessionContext toV2SessionContext ( V1SessionContext sessionContext ) { if ( sessionContext != null ) { SessionContext result = WSRPTypeFactory . createSessionContext ( sessionContext . getSessionID ( ) , sessionContext . getExpires ( ) ) ; result . getExtensions ( ) . addAll ( Lists . transform ( sessionContext . getExtensions ( ) , EXTENSION ) ) ; return result ; } else { return null ; } } public static UpdateResponse toV2UpdateResponse ( V1UpdateResponse updateResponse ) { if ( updateResponse != null ) { UpdateResponse result = WSRPTypeFactory . createUpdateResponse ( ) ; result . setMarkupContext ( toV2MarkupContext ( updateResponse . getMarkupContext ( ) ) ) ; String state = updateResponse . getNavigationalState ( ) ; if ( state != null ) { result . setNavigationalContext ( WSRPTypeFactory . createNavigationalContextOrNull ( new OpaqueStateString ( state ) , null ) ) ; } result . setNewWindowState ( updateResponse . getNewWindowState ( ) ) ; result . setPortletContext ( toV2PortletContext ( updateResponse . getPortletContext ( ) ) ) ; result . setSessionContext ( toV2SessionContext ( updateResponse . getSessionContext ( ) ) ) ; result . setNewMode ( updateResponse . getNewMode ( ) ) ; return result ; } else { return null ; } } public static GetServiceDescription toV2GetServiceDescription ( V1GetServiceDescription getServiceDescription ) { if ( getServiceDescription != null ) { GetServiceDescription result = WSRPTypeFactory . createGetServiceDescription ( toV2RegistrationContext ( getServiceDescription . getRegistrationContext ( ) ) , null ) ; List < String > locales = getServiceDescription . getDesiredLocales ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( locales ) ) { result . getDesiredLocales ( ) . addAll ( locales ) ; } return result ; } else { return null ; } } public static GetMarkup toV2GetMarkup ( V1GetMarkup getMarkup ) { if ( getMarkup != null ) { PortletContext portletContext = toV2PortletContext ( getMarkup . getPortletContext ( ) ) ; RuntimeContext runtimeContext = toV2RuntimeContext ( getMarkup . getRuntimeContext ( ) , portletContext . getPortletHandle ( ) ) ; MarkupParams markupParams = toV2MarkupParams ( getMarkup . getMarkupParams ( ) ) ; RegistrationContext registrationContext = toV2RegistrationContext ( getMarkup . getRegistrationContext ( ) ) ; UserContext userContext = toV2UserContext ( getMarkup . getUserContext ( ) ) ; return WSRPTypeFactory . createGetMarkup ( registrationContext , portletContext , runtimeContext , userContext , markupParams ) ; } else { return null ; } } public static ModifyRegistration toV2ModifyRegistration ( V1ModifyRegistration modifyRegistration ) { if ( modifyRegistration != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( modifyRegistration . getRegistrationContext ( ) ) ; RegistrationData registrationData = toV2RegistrationData ( modifyRegistration . getRegistrationData ( ) ) ; ModifyRegistration result = WSRPTypeFactory . createModifyRegistration ( registrationContext , registrationData ) ; return result ; } else { return null ; } } public static ClonePortlet toV2ClonePortlet ( V1ClonePortlet clonePortlet ) { if ( clonePortlet != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( clonePortlet . getRegistrationContext ( ) ) ; PortletContext portletContext = toV2PortletContext ( clonePortlet . getPortletContext ( ) ) ; UserContext userContext = toV2UserContext ( clonePortlet . getUserContext ( ) ) ; ClonePortlet result = WSRPTypeFactory . createClonePortlet ( registrationContext , portletContext , userContext ) ; return result ; } else { return null ; } } public static PerformBlockingInteraction toV2PerformBlockingInteraction ( V1PerformBlockingInteraction performBlockingInteraction ) { if ( performBlockingInteraction != null ) { InteractionParams interactionParams = toV2InteractionParams ( performBlockingInteraction . getInteractionParams ( ) ) ; MarkupParams markupParams = toV2MarkupParams ( performBlockingInteraction . getMarkupParams ( ) ) ; PortletContext portletContext = toV2PortletContext ( performBlockingInteraction . getPortletContext ( ) ) ; RuntimeContext runtimeContext = toV2RuntimeContext ( performBlockingInteraction . getRuntimeContext ( ) , portletContext . getPortletHandle ( ) ) ; return WSRPTypeFactory . createPerformBlockingInteraction ( toV2RegistrationContext ( performBlockingInteraction . getRegistrationContext ( ) ) , portletContext , runtimeContext , toV2UserContext ( performBlockingInteraction . getUserContext ( ) ) , markupParams , interactionParams ) ; } else { return null ; } } public static DestroyPortlets toV2DestroyPortlets ( V1DestroyPortlets destroyPortlets ) { if ( destroyPortlets != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( destroyPortlets . getRegistrationContext ( ) ) ; DestroyPortlets result = WSRPTypeFactory . createDestroyPortlets ( registrationContext , destroyPortlets . getPortletHandles ( ) ) ; return result ; } else { return null ; } } public static SetPortletProperties toV2SetPortletProperties ( V1SetPortletProperties setPortletProperties ) { if ( setPortletProperties != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( setPortletProperties . getRegistrationContext ( ) ) ; PortletContext portletContext = toV2PortletContext ( setPortletProperties . getPortletContext ( ) ) ; PropertyList propertyList = toV2PropertyList ( setPortletProperties . getPropertyList ( ) ) ; SetPortletProperties result = WSRPTypeFactory . createSetPortletProperties ( registrationContext , portletContext , propertyList ) ; result . setUserContext ( toV2UserContext ( setPortletProperties . getUserContext ( ) ) ) ; return result ; } else { return null ; } } public static GetPortletProperties toV2GetPortletProperties ( V1GetPortletProperties getPortletProperties ) { if ( getPortletProperties != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( getPortletProperties . getRegistrationContext ( ) ) ; PortletContext portletContext = toV2PortletContext ( getPortletProperties . getPortletContext ( ) ) ; UserContext userContext = toV2UserContext ( getPortletProperties . getUserContext ( ) ) ; GetPortletProperties result = WSRPTypeFactory . createGetPortletProperties ( registrationContext , portletContext , userContext , getPortletProperties . getNames ( ) ) ; return result ; } else { return null ; } } public static ReleaseSessions toV2ReleaseSessions ( V1ReleaseSessions releaseSessions ) { if ( releaseSessions != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( releaseSessions . getRegistrationContext ( ) ) ; ReleaseSessions result = WSRPTypeFactory . createReleaseSessions ( registrationContext , releaseSessions . getSessionIDs ( ) ) ; return result ; } else { return null ; } } public static InitCookie toV2InitCookie ( V1InitCookie initCookie ) { if ( initCookie != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( initCookie . getRegistrationContext ( ) ) ; InitCookie result = WSRPTypeFactory . createInitCookie ( registrationContext ) ; return result ; } else { return null ; } } public static GetPortletPropertyDescription toV2GetPortletPropertyDescription ( V1GetPortletPropertyDescription getPortletPropertyDescription ) { if ( getPortletPropertyDescription != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( getPortletPropertyDescription . getRegistrationContext ( ) ) ; PortletContext portletContext = toV2PortletContext ( getPortletPropertyDescription . getPortletContext ( ) ) ; UserContext userContext = toV2UserContext ( getPortletPropertyDescription . getUserContext ( ) ) ; GetPortletPropertyDescription result = WSRPTypeFactory . createGetPortletPropertyDescription ( registrationContext , portletContext , userContext , getPortletPropertyDescription . getDesiredLocales ( ) ) ; return result ; } else { return null ; } } public static GetPortletDescription toV2GetPortletDescription ( V1GetPortletDescription getPortletDescription ) { if ( getPortletDescription != null ) { RegistrationContext registrationContext = toV2RegistrationContext ( getPortletDescription . getRegistrationContext ( ) ) ; PortletContext portletContext = toV2PortletContext ( getPortletDescription . getPortletContext ( ) ) ; UserContext userContext = toV2UserContext ( getPortletDescription . getUserContext ( ) ) ; GetPortletDescription result = WSRPTypeFactory . createGetPortletDescription ( registrationContext , portletContext , userContext ) ; result . getDesiredLocales ( ) . addAll ( getPortletDescription . getDesiredLocales ( ) ) ; return result ; } else { return null ; } } public static class V1ToV2Extension implements Function < V1Extension , Extension > { public Extension apply ( V1Extension from ) { if ( from != null ) { Extension extension = WSRPTypeFactory . createExtension ( from . getAny ( ) ) ; return extension ; } else { return null ; } } } public static class V1ToV2PortletDescription implements Function < V1PortletDescription , PortletDescription > { public PortletDescription apply ( V1PortletDescription from ) { if ( from != null ) { PortletDescription result = WSRPTypeFactory . createPortletDescription ( from . getPortletHandle ( ) , WSRPUtils . transform ( from . getMarkupTypes ( ) , MARKUPTYPE ) ) ; result . setDescription ( LOCALIZEDSTRING . apply ( from . getDescription ( ) ) ) ; result . setDisplayName ( LOCALIZEDSTRING . apply ( from . getDisplayName ( ) ) ) ; List < Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } List < LocalizedString > keywords = WSRPUtils . transform ( from . getKeywords ( ) , LOCALIZEDSTRING ) ; if ( keywords != null ) { result . getKeywords ( ) . addAll ( keywords ) ; } List < String > userCategories = from . getUserCategories ( ) ; if ( userCategories != null ) { result . getUserCategories ( ) . addAll ( userCategories ) ; } List < String > userProfileItems = from . getUserProfileItems ( ) ; if ( userProfileItems != null ) { result . getUserProfileItems ( ) . addAll ( userProfileItems ) ; } result . setDefaultMarkupSecure ( from . isDefaultMarkupSecure ( ) ) ; result . setDoesUrlTemplateProcessing ( from . isDoesUrlTemplateProcessing ( ) ) ; result . setTemplatesStoredInSession ( from . isTemplatesStoredInSession ( ) ) ; result . setHasUserSpecificState ( from . isHasUserSpecificState ( ) ) ; result . setOnlySecure ( from . isOnlySecure ( ) ) ; result . setUserContextStoredInSession ( from . isUserContextStoredInSession ( ) ) ; result . setUsesMethodGet ( from . isUsesMethodGet ( ) ) ; result . setShortTitle ( LOCALIZEDSTRING . apply ( from . getShortTitle ( ) ) ) ; result . setTitle ( LOCALIZEDSTRING . apply ( from . getTitle ( ) ) ) ; result . setGroupID ( from . getGroupID ( ) ) ; return result ; } else { return null ; } } } public static class V1ToV2ItemDescription implements Function < V1ItemDescription , ItemDescription > { public ItemDescription apply ( V1ItemDescription from ) { if ( from != null ) { LocalizedString description = LOCALIZEDSTRING . apply ( from . getDescription ( ) ) ; ItemDescription result = WSRPTypeFactory . createItemDescription ( description , null , from . getItemName ( ) ) ; List < Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } public static class V1ToV2NamedString implements Function < V1NamedString , NamedString > { public NamedString apply ( V1NamedString v1NamedString ) { if ( v1NamedString != null ) { return WSRPTypeFactory . createNamedString ( v1NamedString . getName ( ) , v1NamedString . getValue ( ) ) ; } else { return null ; } } } public static class V1ToV2UploadContext implements Function < V1UploadContext , UploadContext > { public UploadContext apply ( V1UploadContext v1UploadContext ) { if ( v1UploadContext != null ) { UploadContext result = WSRPTypeFactory . createUploadContext ( v1UploadContext . getMimeType ( ) , v1UploadContext . getUploadData ( ) ) ; result . getExtensions ( ) . addAll ( Lists . transform ( v1UploadContext . getExtensions ( ) , EXTENSION ) ) ; result . getMimeAttributes ( ) . addAll ( Lists . transform ( v1UploadContext . getMimeAttributes ( ) , NAMEDSTRING ) ) ; return result ; } else { return null ; } } } public static class V1ToV2MarkupType implements Function < V1MarkupType , MarkupType > { public MarkupType apply ( V1MarkupType from ) { if ( from != null ) { MarkupType result = WSRPTypeFactory . createMarkupType ( from . getMimeType ( ) , from . getModes ( ) , from . getWindowStates ( ) , from . getLocales ( ) ) ; List < Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } public static class V1ToV2LocalizedString implements Function < V1LocalizedString , LocalizedString > { public LocalizedString apply ( V1LocalizedString from ) { if ( from != null ) { return WSRPTypeFactory . createLocalizedString ( from . getLang ( ) , from . getResourceName ( ) , from . getValue ( ) ) ; } else { return null ; } } } public static class V1ToV2Resource implements Function < V1Resource , Resource > { public Resource apply ( V1Resource from ) { if ( from != null ) { Resource result = WSRPTypeFactory . createResource ( from . getResourceName ( ) , WSRPUtils . transform ( from . getValues ( ) , RESOURCEVALUE ) ) ; return result ; } else { return null ; } } } public static class V1ToV2ResourceValue implements Function < V1ResourceValue , ResourceValue > { public ResourceValue apply ( V1ResourceValue from ) { if ( from != null ) { ResourceValue result = WSRPTypeFactory . createResourceValue ( from . getLang ( ) , from . getValue ( ) ) ; List < Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } public static class V1ToV2PropertyDescription implements Function < V1PropertyDescription , PropertyDescription > { public PropertyDescription apply ( V1PropertyDescription from ) { if ( from != null ) { PropertyDescription result = WSRPTypeFactory . createPropertyDescription ( from . getName ( ) , from . getType ( ) ) ; result . setHint ( toV2LocalizedString ( from . getHint ( ) ) ) ; result . setLabel ( toV2LocalizedString ( from . getLabel ( ) ) ) ; List < Extension > extensions = WSRPUtils . transform ( from . getExtensions ( ) , EXTENSION ) ; if ( extensions != null ) { result . getExtensions ( ) . addAll ( extensions ) ; } return result ; } else { return null ; } } } public static class V1ToV2Property implements Function < V1Property , Property > { public Property apply ( V1Property from ) { if ( from != null ) { Property result = WSRPTypeFactory . createProperty ( from . getName ( ) , from . getLang ( ) , from . getStringValue ( ) ) ; result . setType ( WSRPConstants . XSD_STRING ) ; List < Object > any = from . getAny ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( any ) ) { result . getAny ( ) . addAll ( any ) ; } return result ; } else { return null ; } } } private static class V1ToV2ResetProperty implements Function < V1ResetProperty , ResetProperty > { public ResetProperty apply ( V1ResetProperty from ) { if ( from != null ) { return WSRPTypeFactory . createResetProperty ( from . getName ( ) ) ; } else { return null ; } } } } </s>
<s> package org . gatein . wsrp ; public class MIMEUtils { public static final String UTF_8 = "<STR_LIT:UTF-8>" ; public static final String CHARSET = "<STR_LIT>" ; public static final int CHARSET_LENGTH = CHARSET . length ( ) ; public static final String JAVASCRIPT = "<STR_LIT>" ; public static final String TEXT = "<STR_LIT:text>" ; public static final String ECMASCRIPT = "<STR_LIT>" ; public static final String CSS = "<STR_LIT>" ; public static final String HTML = "<STR_LIT>" ; public static final String XML = "<STR_LIT>" ; public static final String APPLICATION_XML = "<STR_LIT>" ; public static boolean isInterpretableAsText ( String contentType ) { return contentType != null && ( contentType . startsWith ( TEXT ) || isJavascript ( contentType ) || isApplicationXML ( contentType ) ) ; } public static boolean needsRewriting ( String contentType ) { return contentType != null && ( ( contentType . startsWith ( TEXT ) && ( contentType . contains ( CSS ) || contentType . contains ( HTML ) || contentType . contains ( XML ) ) ) || isJavascript ( contentType ) || isApplicationXML ( contentType ) ) ; } private static boolean isApplicationXML ( String contentType ) { return contentType . startsWith ( APPLICATION_XML ) ; } private static boolean isJavascript ( String contentType ) { return contentType . contains ( JAVASCRIPT ) || contentType . contains ( ECMASCRIPT ) ; } public static String getCharsetFrom ( String contentType ) { String charset = UTF_8 ; if ( contentType != null ) { for ( String part : contentType . split ( "<STR_LIT:;>" ) ) { if ( part . startsWith ( CHARSET ) ) { charset = part . substring ( CHARSET_LENGTH ) ; } } } return charset ; } } </s>
<s> package org . gatein . wsrp ; import com . google . common . base . Function ; import com . google . common . collect . Lists ; import org . gatein . common . i18n . LocaleFormat ; import org . gatein . common . net . URLTools ; import org . gatein . common . util . ConversionException ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . PortletContext ; import org . gatein . pc . api . PortletStateType ; import org . gatein . pc . api . StatefulPortletContext ; import org . gatein . pc . api . WindowState ; import org . gatein . pc . api . cache . CacheLevel ; import org . gatein . pc . api . state . AccessMode ; import org . gatein . wsrp . registration . LocalizedString ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import org . gatein . wsrp . spec . v2 . WSRP2Constants ; import org . oasis . wsrp . v2 . InteractionParams ; import org . oasis . wsrp . v2 . MarkupParams ; import org . oasis . wsrp . v2 . NamedString ; import org . oasis . wsrp . v2 . NavigationalContext ; import org . oasis . wsrp . v2 . PropertyDescription ; import org . oasis . wsrp . v2 . StateChange ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import javax . servlet . http . HttpServletRequest ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Locale ; import java . util . Map ; import java . util . Set ; public class WSRPUtils { private final static Map < String , String > JSR168_WSRP_WINDOW_STATES = new HashMap < String , String > ( <NUM_LIT:7> ) ; private final static Map < String , WindowState > WSRP_JSR168_WINDOW_STATES = new HashMap < String , WindowState > ( <NUM_LIT:7> ) ; private final static Map < String , String > JSR168_WSRP_MODES = new HashMap < String , String > ( <NUM_LIT:7> ) ; private final static Map < String , Mode > WSRP_JSR168_MODES = new HashMap < String , Mode > ( <NUM_LIT:7> ) ; private final static Map < CacheLevel , String > JSR286_WSRP_CACHE = new HashMap < CacheLevel , String > ( <NUM_LIT:7> ) ; private static final String SET_OF_LOCALES = "<STR_LIT>" ; private static final String MODE = "<STR_LIT>" ; private static final String WSRP_MODE_NAME = "<STR_LIT>" ; private static final String WSRP_WINDOW_STATE_NAME = "<STR_LIT>" ; private static final String WINDOW_STATE = "<STR_LIT>" ; public static final Set < Mode > DEFAULT_JSR168_MODES ; public static final Set < WindowState > DEFAULT_JSR168_WINDOWSTATES ; private static boolean strict = true ; private static Logger log = LoggerFactory . getLogger ( WSRPUtils . class ) ; private static PropertyAccessor propertyAccessor = new DefaultPropertyAccessor ( ) ; public static final String DEACTIVATE_URL_REWRITING = "<STR_LIT>" ; public static void setStrict ( boolean strict ) { WSRPUtils . strict = strict ; log . debug ( "<STR_LIT>" + ( strict ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" ) ; } static { JSR168_WSRP_WINDOW_STATES . put ( WindowState . MAXIMIZED . toString ( ) , WSRPConstants . MAXIMIZED_WINDOW_STATE ) ; JSR168_WSRP_WINDOW_STATES . put ( WindowState . MINIMIZED . toString ( ) , WSRPConstants . MINIMIZED_WINDOW_STATE ) ; JSR168_WSRP_WINDOW_STATES . put ( WindowState . NORMAL . toString ( ) , WSRPConstants . NORMAL_WINDOW_STATE ) ; JSR168_WSRP_MODES . put ( Mode . EDIT . toString ( ) , WSRPConstants . EDIT_MODE ) ; JSR168_WSRP_MODES . put ( Mode . HELP . toString ( ) , WSRPConstants . HELP_MODE ) ; JSR168_WSRP_MODES . put ( Mode . VIEW . toString ( ) , WSRPConstants . VIEW_MODE ) ; WSRP_JSR168_WINDOW_STATES . put ( WSRPConstants . MAXIMIZED_WINDOW_STATE , WindowState . MAXIMIZED ) ; WSRP_JSR168_WINDOW_STATES . put ( WSRPConstants . MINIMIZED_WINDOW_STATE , WindowState . MINIMIZED ) ; WSRP_JSR168_WINDOW_STATES . put ( WSRPConstants . NORMAL_WINDOW_STATE , WindowState . NORMAL ) ; WSRP_JSR168_MODES . put ( WSRPConstants . EDIT_MODE , Mode . EDIT ) ; WSRP_JSR168_MODES . put ( WSRPConstants . HELP_MODE , Mode . HELP ) ; WSRP_JSR168_MODES . put ( WSRPConstants . VIEW_MODE , Mode . VIEW ) ; DEFAULT_JSR168_MODES = new HashSet < Mode > ( WSRP_JSR168_MODES . values ( ) ) ; DEFAULT_JSR168_WINDOWSTATES = new HashSet < WindowState > ( WSRP_JSR168_WINDOW_STATES . values ( ) ) ; JSR286_WSRP_CACHE . put ( CacheLevel . FULL , WSRP2Constants . RESOURCE_CACHEABILITY_FULL ) ; JSR286_WSRP_CACHE . put ( CacheLevel . PAGE , WSRP2Constants . RESOURCE_CACHEABILITY_PAGE ) ; JSR286_WSRP_CACHE . put ( CacheLevel . PORTLET , WSRP2Constants . RESOURCE_CACHEABILITY_PORTLET ) ; } private WSRPUtils ( ) { } public static WindowState getJSR168WindowStateFromWSRPName ( String wsrpWindowStateName ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( wsrpWindowStateName , WSRP_WINDOW_STATE_NAME , null ) ; WindowState windowState = WSRP_JSR168_WINDOW_STATES . get ( wsrpWindowStateName ) ; return ( windowState == null ) ? WindowState . create ( wsrpWindowStateName ) : windowState ; } public static boolean isDefaultWSRPWindowState ( String wsrpWindowStateName ) { return WSRP_JSR168_WINDOW_STATES . containsKey ( wsrpWindowStateName ) || WSRPConstants . SOLO_WINDOW_STATE . equals ( wsrpWindowStateName ) ; } public static String convertJSR168WindowStateNameToWSRPName ( String jsr168WindowStateName ) { if ( jsr168WindowStateName == null ) { return WSRPConstants . NORMAL_WINDOW_STATE ; } ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( jsr168WindowStateName , WSRP_WINDOW_STATE_NAME , null ) ; String wsrpName = JSR168_WSRP_WINDOW_STATES . get ( jsr168WindowStateName ) ; return ( wsrpName == null ) ? jsr168WindowStateName : wsrpName ; } public static String getWSRPNameFromJSR168WindowState ( WindowState windowState ) { ParameterValidation . throwIllegalArgExceptionIfNull ( windowState , WINDOW_STATE ) ; return convertJSR168WindowStateNameToWSRPName ( windowState . toString ( ) ) ; } public static Mode getJSR168PortletModeFromWSRPName ( String wsrpPortletModeName ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( wsrpPortletModeName , WSRP_MODE_NAME , null ) ; Mode mode = WSRP_JSR168_MODES . get ( wsrpPortletModeName ) ; return ( mode == null ) ? Mode . create ( wsrpPortletModeName ) : mode ; } public static boolean isDefaultWSRPMode ( String wsrpPortletModeName ) { return WSRP_JSR168_MODES . containsKey ( wsrpPortletModeName ) || WSRPConstants . PREVIEW_MODE . equals ( wsrpPortletModeName ) ; } public static String convertJSR168PortletModeNameToWSRPName ( String jsr168PortletModeName ) { if ( jsr168PortletModeName == null ) { return WSRPConstants . VIEW_MODE ; } ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( jsr168PortletModeName , WSRP_MODE_NAME , null ) ; String wsrpName = JSR168_WSRP_MODES . get ( jsr168PortletModeName ) ; return ( wsrpName == null ) ? jsr168PortletModeName : wsrpName ; } public static String getWSRPNameFromJSR168PortletMode ( Mode portletMode ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletMode , MODE ) ; return convertJSR168PortletModeNameToWSRPName ( portletMode . toString ( ) ) ; } public static AccessMode getAccessModeFromStateChange ( StateChange stateChange ) { if ( StateChange . READ_ONLY . equals ( stateChange ) ) { return AccessMode . READ_ONLY ; } if ( StateChange . CLONE_BEFORE_WRITE . equals ( stateChange ) ) { return AccessMode . CLONE_BEFORE_WRITE ; } if ( StateChange . READ_WRITE . equals ( stateChange ) ) { return AccessMode . READ_WRITE ; } throw new IllegalArgumentException ( "<STR_LIT>" + stateChange ) ; } public static StateChange getStateChangeFromAccessMode ( AccessMode accessMode ) { if ( AccessMode . READ_ONLY . equals ( accessMode ) ) { return StateChange . READ_ONLY ; } if ( AccessMode . READ_WRITE . equals ( accessMode ) ) { return StateChange . READ_WRITE ; } if ( AccessMode . CLONE_BEFORE_WRITE . equals ( accessMode ) ) { return StateChange . CLONE_BEFORE_WRITE ; } throw new IllegalArgumentException ( "<STR_LIT>" + accessMode ) ; } public static String convertRequestAuthTypeToWSRPAuthType ( String authType ) { if ( authType == null ) { return WSRPConstants . NONE_USER_AUTHENTICATION ; } if ( HttpServletRequest . CLIENT_CERT_AUTH . equals ( authType ) ) { return WSRPConstants . CERTIFICATE_USER_AUTHENTICATION ; } if ( HttpServletRequest . BASIC_AUTH . equalsIgnoreCase ( authType ) || HttpServletRequest . FORM_AUTH . equals ( authType ) ) { return WSRPConstants . PASSWORD_USER_AUTHENTICATION ; } return authType ; } public static List < String > convertLocalesToRFC3066LanguageTags ( List < Locale > localesOrderedByPreference ) { ParameterValidation . throwIllegalArgExceptionIfNull ( localesOrderedByPreference , SET_OF_LOCALES ) ; List < String > desiredLocales = new ArrayList < String > ( localesOrderedByPreference . size ( ) ) ; for ( Locale locale : localesOrderedByPreference ) { desiredLocales . add ( toString ( locale ) ) ; } return desiredLocales ; } public static PortletContext convertToPortalPortletContext ( org . oasis . wsrp . v2 . PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; String handle = portletContext . getPortletHandle ( ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( handle , "<STR_LIT>" , "<STR_LIT>" ) ; PortletContext context ; byte [ ] state = portletContext . getPortletState ( ) ; context = PortletContext . createPortletContext ( handle , state , false ) ; return context ; } public static PortletContext convertToPortalPortletContext ( String portletHandle , byte [ ] state ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletHandle , "<STR_LIT>" , "<STR_LIT>" ) ; PortletContext context ; context = PortletContext . createPortletContext ( portletHandle , state , false ) ; return context ; } public static org . oasis . wsrp . v2 . PortletContext convertToWSRPPortletContext ( PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; String id = portletContext . getId ( ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( id , "<STR_LIT>" , "<STR_LIT>" ) ; org . oasis . wsrp . v2 . PortletContext result = WSRPTypeFactory . createPortletContext ( id ) ; if ( portletContext instanceof StatefulPortletContext ) { StatefulPortletContext context = ( StatefulPortletContext ) portletContext ; if ( PortletStateType . OPAQUE . equals ( context . getType ( ) ) ) { result . setPortletState ( ( ( StatefulPortletContext < byte [ ] > ) context ) . getState ( ) ) ; } } return result ; } public static String getResourceCacheabilityFromCacheLevel ( CacheLevel cacheLevel ) { return cacheLevel == null ? null : cacheLevel . name ( ) . toLowerCase ( Locale . ENGLISH ) ; } public static CacheLevel getCacheLevelFromResourceCacheability ( String resourceCacheability ) { if ( resourceCacheability == null ) { return CacheLevel . PAGE ; } return CacheLevel . create ( resourceCacheability . toUpperCase ( Locale . ENGLISH ) ) ; } public static Locale getLocale ( String lang ) throws IllegalArgumentException { if ( lang != null ) { String possiblyRelaxed = lang ; if ( ! WSRPUtils . strict ) { possiblyRelaxed = lang . replace ( '<CHAR_LIT:_>' , '<CHAR_LIT:->' ) ; } try { return LocaleFormat . RFC3066_LANGUAGE_TAG . getLocale ( possiblyRelaxed ) ; } catch ( ConversionException e ) { if ( WSRPUtils . strict ) { throw new IllegalArgumentException ( e ) ; } else { log . debug ( "<STR_LIT>" + possiblyRelaxed + "<STR_LIT>" + Locale . ENGLISH + "<STR_LIT>" , e ) ; return Locale . ENGLISH ; } } } else { return Locale . getDefault ( ) ; } } public static String toString ( Locale locale ) throws IllegalArgumentException { try { return LocaleFormat . RFC3066_LANGUAGE_TAG . toString ( locale ) ; } catch ( ConversionException e ) { throw new IllegalArgumentException ( e ) ; } } public static String toString ( MarkupParams params ) { if ( params != null ) { StringBuffer sb = new StringBuffer ( "<STR_LIT>" ) ; if ( params . isSecureClientCommunication ( ) ) { sb . append ( "<STR_LIT>" ) ; } NavigationalContext navigationalContext = params . getNavigationalContext ( ) ; sb . append ( "<STR_LIT>" ) . append ( params . getMode ( ) ) . append ( "<STR_LIT>" ) . append ( params . getWindowState ( ) ) . append ( "<STR_LIT:]>" ) ; if ( navigationalContext != null ) { sb . append ( "<STR_LIT>" ) . append ( navigationalContext . getOpaqueValue ( ) ) . append ( "<STR_LIT:]>" ) . append ( "<STR_LIT>" ) . append ( navigationalContext . getPublicValues ( ) ) . append ( "<STR_LIT:]>" ) ; } return sb . toString ( ) ; } return null ; } public static String toString ( InteractionParams interactionParams ) { if ( interactionParams != null ) { StringBuffer sb = new StringBuffer ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) . append ( interactionParams . getInteractionState ( ) ) . append ( "<STR_LIT:]>" ) . append ( "<STR_LIT>" ) . append ( interactionParams . getPortletStateChange ( ) . value ( ) ) . append ( "<STR_LIT:]>" ) ; List < NamedString > formParams = interactionParams . getFormParameters ( ) ; if ( formParams != null ) { sb . append ( "<STR_LIT>" ) ; for ( NamedString formParam : formParams ) { sb . append ( "<STR_LIT>" ) . append ( formParam . getName ( ) ) . append ( "<STR_LIT>" ) . append ( formParam . getValue ( ) ) . append ( "<STR_LIT>" ) ; } } return sb . toString ( ) ; } return null ; } public static RegistrationPropertyDescription convertToRegistrationPropertyDescription ( PropertyDescription propertyDescription ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyDescription , "<STR_LIT>" ) ; RegistrationPropertyDescription desc = new RegistrationPropertyDescription ( propertyDescription . getName ( ) , propertyDescription . getType ( ) ) ; desc . setLabel ( getLocalizedStringOrNull ( propertyDescription . getLabel ( ) ) ) ; desc . setHint ( getLocalizedStringOrNull ( propertyDescription . getHint ( ) ) ) ; return desc ; } public static PropertyDescription convertToPropertyDescription ( RegistrationPropertyDescription propertyDescription ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyDescription , "<STR_LIT>" ) ; PropertyDescription propDesc = WSRPTypeFactory . createPropertyDescription ( propertyDescription . getName ( ) . toString ( ) , propertyDescription . getType ( ) ) ; LocalizedString hint = propertyDescription . getHint ( ) ; if ( hint != null ) { propDesc . setHint ( convertToWSRPLocalizedString ( hint ) ) ; } LocalizedString label = propertyDescription . getLabel ( ) ; if ( label != null ) { propDesc . setLabel ( convertToWSRPLocalizedString ( label ) ) ; } return propDesc ; } public static org . oasis . wsrp . v2 . LocalizedString convertToWSRPLocalizedString ( LocalizedString regLocalizedString ) { ParameterValidation . throwIllegalArgExceptionIfNull ( regLocalizedString , "<STR_LIT>" ) ; return WSRPTypeFactory . createLocalizedString ( toString ( regLocalizedString . getLocale ( ) ) , regLocalizedString . getResourceName ( ) , regLocalizedString . getValue ( ) ) ; } private static LocalizedString getLocalizedStringOrNull ( org . oasis . wsrp . v2 . LocalizedString wsrpLocalizedString ) { if ( wsrpLocalizedString == null ) { return null ; } else { return convertToRegistrationLocalizedString ( wsrpLocalizedString ) ; } } public static LocalizedString convertToRegistrationLocalizedString ( org . oasis . wsrp . v2 . LocalizedString wsrpLocalizedString ) { ParameterValidation . throwIllegalArgExceptionIfNull ( wsrpLocalizedString , "<STR_LIT>" ) ; String lang = wsrpLocalizedString . getLang ( ) ; Locale locale ; if ( lang == null ) { locale = Locale . getDefault ( ) ; } else { locale = getLocale ( lang ) ; } LocalizedString localizedString = new LocalizedString ( wsrpLocalizedString . getValue ( ) , locale ) ; localizedString . setResourceName ( wsrpLocalizedString . getResourceName ( ) ) ; return localizedString ; } public static String getAbsoluteURLFor ( String url , boolean checkWSRPToken , String serverAddress ) { if ( checkWSRPToken && url . startsWith ( WSRPRewritingConstants . BEGIN_WSRP_REWRITE ) ) { return url ; } if ( ! URLTools . isNetworkURL ( url ) && url . startsWith ( URLTools . SLASH ) ) { return serverAddress + url ; } else { return url ; } } public static < F , T > List < T > transform ( List < F > fromList , Function < ? super F , ? extends T > function ) { if ( fromList == null ) { return null ; } else { return Lists . transform ( fromList , function ) ; } } public static org . gatein . common . i18n . LocalizedString convertToCommonLocalizedStringOrNull ( org . oasis . wsrp . v2 . LocalizedString wsrpLocalizedString ) { if ( wsrpLocalizedString != null ) { return new org . gatein . common . i18n . LocalizedString ( wsrpLocalizedString . getValue ( ) , getLocale ( wsrpLocalizedString . getLang ( ) ) ) ; } return null ; } public static Map < String , String [ ] > createPublicNSFrom ( List < NamedString > publicParams ) { Map < String , String [ ] > publicNS = new HashMap < String , String [ ] > ( publicParams . size ( ) ) ; for ( NamedString publicParam : publicParams ) { String paramName = publicParam . getName ( ) ; addMultiValuedValueTo ( publicNS , paramName , publicParam . getValue ( ) ) ; } return publicNS ; } public static void addMultiValuedValueTo ( Map < String , String [ ] > paramMap , String paramName , String paramValue ) { String [ ] values = paramMap . get ( paramName ) ; if ( ParameterValidation . existsAndIsNotEmpty ( values ) ) { int valuesNb = values . length ; String [ ] newValues = new String [ valuesNb + <NUM_LIT:1> ] ; System . arraycopy ( values , <NUM_LIT:0> , newValues , <NUM_LIT:0> , valuesNb ) ; newValues [ valuesNb ] = paramValue ; paramMap . put ( paramName , newValues ) ; } else { values = new String [ ] { paramValue } ; paramMap . put ( paramName , values ) ; } } public static String encodePublicNS ( Map < String , String [ ] > publicNSChanges ) { if ( ParameterValidation . existsAndIsNotEmpty ( publicNSChanges ) ) { StringBuilder sb = new StringBuilder ( <NUM_LIT> ) ; Set < Map . Entry < String , String [ ] > > entries = publicNSChanges . entrySet ( ) ; int entryNb = entries . size ( ) ; int currentEntry = <NUM_LIT:0> ; for ( Map . Entry < String , String [ ] > entry : entries ) { String name = entry . getKey ( ) ; String [ ] values = entry . getValue ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( values ) ) { int valueNb = values . length ; int currentValueIndex = <NUM_LIT:0> ; for ( String value : values ) { sb . append ( name ) . append ( "<STR_LIT:=>" ) . append ( value ) ; if ( currentValueIndex ++ != valueNb - <NUM_LIT:1> ) { sb . append ( "<STR_LIT:&>" ) ; } } } else { sb . append ( name ) ; } if ( currentEntry ++ != entryNb - <NUM_LIT:1> ) { sb . append ( "<STR_LIT:&>" ) ; } } return URLTools . encodeXWWWFormURL ( sb . toString ( ) ) ; } else { return null ; } } public static Map < String , String [ ] > decodePublicNS ( String paramValue ) { if ( ! ParameterValidation . isNullOrEmpty ( paramValue ) ) { String encodedURL = URLTools . decodeXWWWFormURL ( paramValue ) ; Map < String , String [ ] > publicNS = new HashMap < String , String [ ] > ( <NUM_LIT:7> ) ; boolean finished = false ; while ( encodedURL . length ( ) > <NUM_LIT:0> && ! finished ) { int endParamIndex = encodedURL . indexOf ( WSRPPortletURL . AMPERSAND ) ; String param ; if ( endParamIndex < <NUM_LIT:0> ) { param = encodedURL ; finished = true ; } else { param = encodedURL . substring ( <NUM_LIT:0> , endParamIndex ) ; } int equalsIndex = param . indexOf ( WSRPPortletURL . EQUALS ) ; if ( equalsIndex < <NUM_LIT:0> ) { publicNS . put ( param , null ) ; } else { String name = param . substring ( <NUM_LIT:0> , equalsIndex ) ; String value = param . substring ( equalsIndex + WSRPPortletURL . EQUALS . length ( ) , param . length ( ) ) ; addMultiValuedValueTo ( publicNS , name , value ) ; } encodedURL = encodedURL . substring ( endParamIndex + WSRPPortletURL . AMPERSAND . length ( ) ) ; } return publicNS ; } else { return null ; } } public static PropertyAccessor getPropertyAccessor ( ) { return propertyAccessor ; } static PropertyAccessor getPropertyAccessor ( boolean reload ) { if ( reload ) { propertyAccessor = new DefaultPropertyAccessor ( ) ; } return propertyAccessor ; } public static class AbsoluteURLReplacementGenerator extends URLTools . URLReplacementGenerator { private String serverAddress ; public AbsoluteURLReplacementGenerator ( HttpServletRequest request ) { serverAddress = URLTools . getServerAddressFrom ( request ) ; } public String getReplacementFor ( int i , URLTools . URLMatch urlMatch ) { return getAbsoluteURLFor ( urlMatch . getURLAsString ( ) ) ; } String getAbsoluteURLFor ( String url ) { return WSRPUtils . getAbsoluteURLFor ( url , true , serverAddress ) ; } } private static class DefaultPropertyAccessor implements PropertyAccessor { private boolean urlRewritingActive = ! Boolean . parseBoolean ( System . getProperty ( DEACTIVATE_URL_REWRITING ) ) ; @ Override public boolean isURLRewritingActive ( ) { return urlRewritingActive ; } } } </s>
<s> package org . gatein . wsrp . servlet ; import org . gatein . wsrp . WSRPTypeFactory ; import org . gatein . wsrp . api . servlet . ServletAccess ; import org . oasis . wsrp . v2 . UserContext ; import javax . servlet . http . HttpServletRequest ; public class UserAccess { private UserAccess ( ) { } public static String getUser ( ) { HttpServletRequest req = ServletAccess . getRequest ( ) ; return req != null ? req . getRemoteUser ( ) : null ; } public static UserContext getUserContext ( ) { String userId = getUser ( ) ; return userId != null ? WSRPTypeFactory . createUserContext ( userId ) : null ; } } </s>
<s> package org . gatein . wsrp . servlet ; import org . gatein . common . io . IOTools ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import javax . servlet . Filter ; import javax . servlet . FilterChain ; import javax . servlet . FilterConfig ; import javax . servlet . ServletException ; import javax . servlet . ServletRequest ; import javax . servlet . ServletResponse ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import java . io . IOException ; import java . io . Reader ; import java . io . StringWriter ; import java . util . Map ; public class RequestDumperFilter implements Filter { private static Logger log = LoggerFactory . getLogger ( RequestDumperFilter . class ) ; public void init ( FilterConfig cfg ) throws ServletException { } public void doFilter ( ServletRequest req , ServletResponse resp , FilterChain chain ) throws IOException , ServletException { doFilter ( ( HttpServletRequest ) req , ( HttpServletResponse ) resp , chain ) ; } public void doFilter ( HttpServletRequest req , HttpServletResponse resp , FilterChain chain ) throws IOException , ServletException { boolean trace = log . isTraceEnabled ( ) ; if ( trace ) { StringBuffer tmp = new StringBuffer ( ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getCharacterEncoding ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getContentLength ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getContentType ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getMethod ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getPathInfo ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getQueryString ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getRequestURI ( ) ) . append ( '<STR_LIT:\n>' ) ; tmp . append ( "<STR_LIT>" ) . append ( req . getServletPath ( ) ) . append ( '<STR_LIT:\n>' ) ; for ( Object o : req . getParameterMap ( ) . entrySet ( ) ) { Map . Entry entry = ( Map . Entry ) o ; String name = ( String ) entry . getKey ( ) ; String [ ] values = ( String [ ] ) entry . getValue ( ) ; tmp . append ( "<STR_LIT>" ) . append ( name ) . append ( '<CHAR_LIT:=>' ) ; for ( int j = <NUM_LIT:0> ; j < values . length ; j ++ ) { String value = values [ j ] ; tmp . append ( j == <NUM_LIT:0> ? "<STR_LIT>" : "<STR_LIT:U+002C>" ) . append ( value ) ; } } Reader reader = req . getReader ( ) ; if ( reader != null ) { StringWriter buffer = new StringWriter ( ) ; IOTools . copy ( reader , buffer ) ; tmp . append ( "<STR_LIT>" ) . append ( buffer . toString ( ) ) ; } log . trace ( tmp . toString ( ) ) ; } chain . doFilter ( req , resp ) ; } public void destroy ( ) { } } </s>
<s> package org . gatein . wsrp . servlet ; import org . gatein . wsrp . api . servlet . ServletAccess ; import javax . servlet . Filter ; import javax . servlet . FilterChain ; import javax . servlet . FilterConfig ; import javax . servlet . ServletException ; import javax . servlet . ServletRequest ; import javax . servlet . ServletResponse ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpServletResponse ; import java . io . IOException ; public class ServletAccessFilter implements Filter { public void init ( FilterConfig filterConfig ) throws ServletException { } public void doFilter ( ServletRequest servletRequest , ServletResponse servletResponse , FilterChain filterChain ) throws IOException , ServletException { ServletAccess . setRequestAndResponse ( ( HttpServletRequest ) servletRequest , ( HttpServletResponse ) servletResponse ) ; filterChain . doFilter ( servletRequest , servletResponse ) ; } public void destroy ( ) { } } </s>
<s> package org . gatein . wsrp ; import org . gatein . common . text . TextTools ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . ActionURL ; import org . gatein . pc . api . ContainerURL ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . OpaqueStateString ; import org . gatein . pc . api . PortletStateType ; import org . gatein . pc . api . RenderURL ; import org . gatein . pc . api . ResourceURL ; import org . gatein . pc . api . StateString ; import org . gatein . pc . api . StatefulPortletContext ; import org . gatein . pc . api . URLFormat ; import org . gatein . pc . api . WindowState ; import org . gatein . pc . api . cache . CacheLevel ; import org . gatein . pc . api . spi . InstanceContext ; import org . gatein . pc . api . spi . PortletInvocationContext ; import org . gatein . pc . api . spi . WindowContext ; import org . gatein . wsrp . payload . PayloadUtils ; import org . gatein . wsrp . spec . v2 . ErrorCodes ; import org . gatein . wsrp . spec . v2 . WSRP2RewritingConstants ; import org . oasis . wsrp . v2 . BlockingInteractionResponse ; import org . oasis . wsrp . v2 . CacheControl ; import org . oasis . wsrp . v2 . ClientData ; import org . oasis . wsrp . v2 . ClonePortlet ; import org . oasis . wsrp . v2 . Contact ; import org . oasis . wsrp . v2 . CopiedPortlet ; import org . oasis . wsrp . v2 . CopyPortlets ; import org . oasis . wsrp . v2 . CopyPortletsResponse ; import org . oasis . wsrp . v2 . DestroyPortlets ; import org . oasis . wsrp . v2 . DestroyPortletsResponse ; import org . oasis . wsrp . v2 . EmployerInfo ; import org . oasis . wsrp . v2 . Event ; import org . oasis . wsrp . v2 . EventDescription ; import org . oasis . wsrp . v2 . EventParams ; import org . oasis . wsrp . v2 . EventPayload ; import org . oasis . wsrp . v2 . ExportPortlets ; import org . oasis . wsrp . v2 . ExportPortletsResponse ; import org . oasis . wsrp . v2 . ExportedPortlet ; import org . oasis . wsrp . v2 . Extension ; import org . oasis . wsrp . v2 . FailedPortlets ; import org . oasis . wsrp . v2 . GetMarkup ; import org . oasis . wsrp . v2 . GetPortletDescription ; import org . oasis . wsrp . v2 . GetPortletProperties ; import org . oasis . wsrp . v2 . GetPortletPropertyDescription ; import org . oasis . wsrp . v2 . GetResource ; import org . oasis . wsrp . v2 . GetServiceDescription ; import org . oasis . wsrp . v2 . HandleEvents ; import org . oasis . wsrp . v2 . HandleEventsResponse ; import org . oasis . wsrp . v2 . ImportPortlet ; import org . oasis . wsrp . v2 . ImportPortlets ; import org . oasis . wsrp . v2 . ImportPortletsFailed ; import org . oasis . wsrp . v2 . ImportPortletsResponse ; import org . oasis . wsrp . v2 . ImportedPortlet ; import org . oasis . wsrp . v2 . InitCookie ; import org . oasis . wsrp . v2 . InteractionParams ; import org . oasis . wsrp . v2 . ItemDescription ; import org . oasis . wsrp . v2 . Lifetime ; import org . oasis . wsrp . v2 . LocalizedString ; import org . oasis . wsrp . v2 . MarkupContext ; import org . oasis . wsrp . v2 . MarkupParams ; import org . oasis . wsrp . v2 . MarkupResponse ; import org . oasis . wsrp . v2 . MarkupType ; import org . oasis . wsrp . v2 . MimeResponse ; import org . oasis . wsrp . v2 . MissingParametersFault ; import org . oasis . wsrp . v2 . ModelDescription ; import org . oasis . wsrp . v2 . ModifyRegistration ; import org . oasis . wsrp . v2 . NamedString ; import org . oasis . wsrp . v2 . NamedStringArray ; import org . oasis . wsrp . v2 . NavigationalContext ; import org . oasis . wsrp . v2 . Online ; import org . oasis . wsrp . v2 . OperationFailedFault ; import org . oasis . wsrp . v2 . ParameterDescription ; import org . oasis . wsrp . v2 . PerformBlockingInteraction ; import org . oasis . wsrp . v2 . PersonName ; import org . oasis . wsrp . v2 . PortletContext ; import org . oasis . wsrp . v2 . PortletDescription ; import org . oasis . wsrp . v2 . PortletDescriptionResponse ; import org . oasis . wsrp . v2 . PortletPropertyDescriptionResponse ; import org . oasis . wsrp . v2 . Postal ; import org . oasis . wsrp . v2 . Property ; import org . oasis . wsrp . v2 . PropertyDescription ; import org . oasis . wsrp . v2 . PropertyList ; import org . oasis . wsrp . v2 . RegistrationContext ; import org . oasis . wsrp . v2 . RegistrationData ; import org . oasis . wsrp . v2 . ReleaseExport ; import org . oasis . wsrp . v2 . ReleaseSessions ; import org . oasis . wsrp . v2 . ResetProperty ; import org . oasis . wsrp . v2 . Resource ; import org . oasis . wsrp . v2 . ResourceContext ; import org . oasis . wsrp . v2 . ResourceList ; import org . oasis . wsrp . v2 . ResourceParams ; import org . oasis . wsrp . v2 . ResourceResponse ; import org . oasis . wsrp . v2 . ResourceValue ; import org . oasis . wsrp . v2 . ReturnAny ; import org . oasis . wsrp . v2 . RuntimeContext ; import org . oasis . wsrp . v2 . ServiceDescription ; import org . oasis . wsrp . v2 . SessionContext ; import org . oasis . wsrp . v2 . SessionParams ; import org . oasis . wsrp . v2 . SetExportLifetime ; import org . oasis . wsrp . v2 . SetPortletProperties ; import org . oasis . wsrp . v2 . StateChange ; import org . oasis . wsrp . v2 . Telecom ; import org . oasis . wsrp . v2 . TelephoneNum ; import org . oasis . wsrp . v2 . Templates ; import org . oasis . wsrp . v2 . UpdateResponse ; import org . oasis . wsrp . v2 . UploadContext ; import org . oasis . wsrp . v2 . UserContext ; import org . oasis . wsrp . v2 . UserProfile ; import javax . xml . datatype . XMLGregorianCalendar ; import javax . xml . namespace . QName ; import java . io . Serializable ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import static org . gatein . wsrp . WSRPRewritingConstants . * ; public class WSRPTypeFactory { private static final String AMP = "<STR_LIT:&>" ; private static final String EQ = "<STR_LIT:=>" ; private static final String ADDITIONAL_RESOURCE_URL_PARAMS = AMP + RESOURCE_REQUIRES_REWRITE + EQ + WSRP_REQUIRES_REWRITE + AMP + WSRPRewritingConstants . RESOURCE_URL + EQ + REWRITE_PARAMETER_OPEN + WSRPRewritingConstants . RESOURCE_URL + REWRITE_PARAMETER_CLOSE + AMP + WSRP2RewritingConstants . RESOURCE_PREFER_OPERATION + EQ + REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants . RESOURCE_PREFER_OPERATION + REWRITE_PARAMETER_CLOSE ; private static final OpaqueStateString WSRP_NAVIGATIONAL_STATE_TOKEN = new OpaqueStateString ( REWRITE_PARAMETER_OPEN + NAVIGATIONAL_STATE + REWRITE_PARAMETER_CLOSE ) ; private static final WindowState WSRP_WINDOW_STATE_TOKEN = WindowState . create ( REWRITE_PARAMETER_OPEN + WINDOW_STATE + REWRITE_PARAMETER_CLOSE , true ) ; private static final Mode WSRP_MODE_TOKEN = Mode . create ( REWRITE_PARAMETER_OPEN + MODE + REWRITE_PARAMETER_CLOSE , true ) ; private WSRPTypeFactory ( ) { } public static GetServiceDescription createGetServiceDescription ( RegistrationContext registrationContext , UserContext userContext ) { GetServiceDescription getServiceDescription = new GetServiceDescription ( ) ; getServiceDescription . setRegistrationContext ( registrationContext ) ; getServiceDescription . setUserContext ( userContext ) ; return getServiceDescription ; } public static GetMarkup createGetMarkup ( RegistrationContext registrationContext , PortletContext portletContext , RuntimeContext runtimeContext , UserContext userContext , MarkupParams markupParams ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletContext . getPortletHandle ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( runtimeContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupParams , "<STR_LIT>" ) ; GetMarkup getMarkup = new GetMarkup ( ) ; getMarkup . setRegistrationContext ( registrationContext ) ; getMarkup . setPortletContext ( portletContext ) ; getMarkup . setRuntimeContext ( runtimeContext ) ; getMarkup . setUserContext ( userContext ) ; getMarkup . setMarkupParams ( markupParams ) ; return getMarkup ; } public static GetResource createGetResource ( RegistrationContext registrationContext , PortletContext portletContext , RuntimeContext runtimeContext , UserContext userContext , ResourceParams resourceParams ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletContext . getPortletHandle ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( runtimeContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( resourceParams , "<STR_LIT>" ) ; GetResource getResource = new GetResource ( ) ; getResource . setRegistrationContext ( registrationContext ) ; getResource . setPortletContext ( portletContext ) ; getResource . setRuntimeContext ( runtimeContext ) ; getResource . setUserContext ( userContext ) ; getResource . setResourceParams ( resourceParams ) ; return getResource ; } public static PerformBlockingInteraction createPerformBlockingInteraction ( RegistrationContext registrationContext , PortletContext portletContext , RuntimeContext runtimeContext , UserContext userContext , MarkupParams markupParams , InteractionParams interactionParams ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletContext . getPortletHandle ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( runtimeContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupParams , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( interactionParams , "<STR_LIT>" ) ; PerformBlockingInteraction performBlockingInteraction = new PerformBlockingInteraction ( ) ; performBlockingInteraction . setRegistrationContext ( registrationContext ) ; performBlockingInteraction . setPortletContext ( portletContext ) ; performBlockingInteraction . setRuntimeContext ( runtimeContext ) ; performBlockingInteraction . setUserContext ( userContext ) ; performBlockingInteraction . setMarkupParams ( markupParams ) ; performBlockingInteraction . setInteractionParams ( interactionParams ) ; return performBlockingInteraction ; } public static HandleEvents createHandleEvents ( RegistrationContext registrationContext , PortletContext portletContext , RuntimeContext runtimeContext , UserContext userContext , MarkupParams markupParams , EventParams eventParams ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletContext . getPortletHandle ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( runtimeContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupParams , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( eventParams , "<STR_LIT>" ) ; HandleEvents handleEvents = new HandleEvents ( ) ; handleEvents . setRegistrationContext ( registrationContext ) ; handleEvents . setPortletContext ( portletContext ) ; handleEvents . setRuntimeContext ( runtimeContext ) ; handleEvents . setUserContext ( userContext ) ; handleEvents . setMarkupParams ( markupParams ) ; handleEvents . setEventParams ( eventParams ) ; return handleEvents ; } public static GetPortletDescription createGetPortletDescription ( RegistrationContext registrationContext , String portletHandle ) { PortletContext portletContext = createPortletContext ( portletHandle ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; GetPortletDescription description = new GetPortletDescription ( ) ; description . setPortletContext ( portletContext ) ; description . setRegistrationContext ( registrationContext ) ; return description ; } public static GetPortletDescription createGetPortletDescription ( RegistrationContext registrationContext , PortletContext portletContext , UserContext userContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; GetPortletDescription description = new GetPortletDescription ( ) ; description . setPortletContext ( portletContext ) ; description . setRegistrationContext ( registrationContext ) ; description . setUserContext ( userContext ) ; return description ; } public static GetPortletDescription createGetPortletDescription ( RegistrationContext registrationContext , org . gatein . pc . api . PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; PortletContext wsrpPC = createPortletContext ( portletContext . getId ( ) ) ; if ( portletContext instanceof StatefulPortletContext ) { StatefulPortletContext context = ( StatefulPortletContext ) portletContext ; if ( PortletStateType . OPAQUE . equals ( context . getType ( ) ) ) { wsrpPC . setPortletState ( ( ( StatefulPortletContext < byte [ ] > ) context ) . getState ( ) ) ; } } GetPortletDescription getPortletDescription = new GetPortletDescription ( ) ; getPortletDescription . setRegistrationContext ( registrationContext ) ; getPortletDescription . setPortletContext ( wsrpPC ) ; return getPortletDescription ; } public static GetPortletProperties createGetPortletProperties ( RegistrationContext registrationContext , PortletContext portletContext , UserContext userContext , List < String > names ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; GetPortletProperties properties = new GetPortletProperties ( ) ; properties . setRegistrationContext ( registrationContext ) ; properties . setPortletContext ( portletContext ) ; properties . setUserContext ( userContext ) ; properties . getNames ( ) . addAll ( names ) ; return properties ; } public static BlockingInteractionResponse createBlockingInteractionResponse ( UpdateResponse updateResponse ) { if ( updateResponse == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } BlockingInteractionResponse interactionResponse = new BlockingInteractionResponse ( ) ; interactionResponse . setUpdateResponse ( updateResponse ) ; return interactionResponse ; } public static BlockingInteractionResponse createBlockingInteractionResponse ( String redirectURL ) { if ( redirectURL == null || redirectURL . length ( ) == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } BlockingInteractionResponse interactionResponse = new BlockingInteractionResponse ( ) ; interactionResponse . setRedirectURL ( redirectURL ) ; return interactionResponse ; } public static UpdateResponse createUpdateResponse ( ) { return new UpdateResponse ( ) ; } public static PortletDescription createPortletDescription ( String portletHandle , List < MarkupType > markupTypes ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletHandle , "<STR_LIT>" , null ) ; checkPortletHandle ( portletHandle ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( markupTypes , "<STR_LIT>" ) ; if ( markupTypes . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } PortletDescription portletDescription = new PortletDescription ( ) ; portletDescription . setPortletHandle ( portletHandle ) ; portletDescription . getMarkupTypes ( ) . addAll ( markupTypes ) ; return portletDescription ; } private static void checkPortletHandle ( String portletHandle ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletHandle , "<STR_LIT>" , null ) ; if ( portletHandle . length ( ) > <NUM_LIT:255> ) { throw new IllegalArgumentException ( "<STR_LIT>" + portletHandle . length ( ) + "<STR_LIT>" ) ; } } public static MarkupParams createMarkupParams ( boolean secureClientCommunication , List < String > locales , List < String > mimeTypes , String mode , String windowState ) { ParameterValidation . throwIllegalArgExceptionIfNull ( locales , "<STR_LIT>" ) ; if ( locales . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( mimeTypes . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ParameterValidation . throwIllegalArgExceptionIfNull ( mimeTypes , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mode , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( windowState , "<STR_LIT>" , "<STR_LIT>" ) ; MarkupParams markupParams = new MarkupParams ( ) ; markupParams . setSecureClientCommunication ( secureClientCommunication ) ; markupParams . setMode ( mode ) ; markupParams . setWindowState ( windowState ) ; if ( ParameterValidation . existsAndIsNotEmpty ( locales ) ) { markupParams . getLocales ( ) . addAll ( locales ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( mimeTypes ) ) { markupParams . getMimeTypes ( ) . addAll ( mimeTypes ) ; } return markupParams ; } public static ResourceParams createDefaultResourceParams ( String resourceID ) { return createResourceParams ( false , WSRPConstants . getDefaultLocales ( ) , WSRPConstants . getDefaultMimeTypes ( ) , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE , resourceID , StateChange . READ_ONLY ) ; } public static ResourceParams createResourceParams ( boolean secureClientCommunication , List < String > locales , List < String > mimeTypes , String mode , String windowState , String resourceID , StateChange stateChange ) { ParameterValidation . throwIllegalArgExceptionIfNull ( locales , "<STR_LIT>" ) ; if ( locales . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ParameterValidation . throwIllegalArgExceptionIfNull ( mimeTypes , "<STR_LIT>" ) ; if ( mimeTypes . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ParameterValidation . throwIllegalArgExceptionIfNull ( mimeTypes , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( stateChange , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mode , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( windowState , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( resourceID , "<STR_LIT>" , "<STR_LIT>" ) ; ResourceParams resourceParams = new ResourceParams ( ) ; resourceParams . setSecureClientCommunication ( secureClientCommunication ) ; resourceParams . setMode ( mode ) ; resourceParams . setWindowState ( windowState ) ; if ( ParameterValidation . existsAndIsNotEmpty ( locales ) ) { resourceParams . getLocales ( ) . addAll ( locales ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( mimeTypes ) ) { resourceParams . getMimeTypes ( ) . addAll ( mimeTypes ) ; } resourceParams . setResourceID ( resourceID ) ; resourceParams . setPortletStateChange ( stateChange ) ; return resourceParams ; } public static RuntimeContext createRuntimeContext ( String userAuthentication , String portletInstanceKey , String namespacePrefix ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userAuthentication , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( portletInstanceKey , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( namespacePrefix , "<STR_LIT>" , "<STR_LIT>" ) ; RuntimeContext runtimeContext = new RuntimeContext ( ) ; runtimeContext . setUserAuthentication ( userAuthentication ) ; runtimeContext . setPortletInstanceKey ( portletInstanceKey ) ; runtimeContext . setNamespacePrefix ( namespacePrefix ) ; return runtimeContext ; } public static PortletContext createPortletContext ( String portletHandle ) { checkPortletHandle ( portletHandle ) ; PortletContext portletContext = new PortletContext ( ) ; portletContext . setPortletHandle ( portletHandle ) ; return portletContext ; } public static PortletContext createPortletContext ( String portletHandle , byte [ ] portletState ) { PortletContext pc = createPortletContext ( portletHandle ) ; pc . setPortletState ( portletState ) ; return pc ; } public static InteractionParams createInteractionParams ( StateChange portletStateChange ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletStateChange , "<STR_LIT>" ) ; InteractionParams interactionParams = new InteractionParams ( ) ; interactionParams . setPortletStateChange ( portletStateChange ) ; return interactionParams ; } public static InitCookie createInitCookie ( RegistrationContext registrationContext ) { InitCookie initCookie = new InitCookie ( ) ; initCookie . setRegistrationContext ( registrationContext ) ; return initCookie ; } public static ServiceDescription createServiceDescription ( boolean requiresRegistration ) { ServiceDescription serviceDescription = new ServiceDescription ( ) ; serviceDescription . setRequiresRegistration ( requiresRegistration ) ; return serviceDescription ; } public static MarkupResponse createMarkupResponse ( MarkupContext markupContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( markupContext , "<STR_LIT>" ) ; MarkupResponse markupResponse = new MarkupResponse ( ) ; markupResponse . setMarkupContext ( markupContext ) ; return markupResponse ; } public static ResourceResponse createResourceResponse ( ResourceContext resourceContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( resourceContext , "<STR_LIT>" ) ; ResourceResponse resourceResponse = new ResourceResponse ( ) ; resourceResponse . setResourceContext ( resourceContext ) ; return resourceResponse ; } public static MarkupContext createMarkupContext ( String mediaType , String markupString , byte [ ] markupBinary , Boolean useCachedItem ) { boolean isUseCachedItem = ( useCachedItem == null ) ? false : useCachedItem . booleanValue ( ) ; MarkupContext markupContext = new MarkupContext ( ) ; markupContext . setMimeType ( mediaType ) ; if ( isUseCachedItem ) { markupContext . setUseCachedItem ( useCachedItem ) ; } else { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mediaType , "<STR_LIT>" , "<STR_LIT>" ) ; if ( markupBinary != null ) { markupContext . setItemBinary ( markupBinary ) ; } else if ( markupString != null ) { markupContext . setItemString ( markupString ) ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } return markupContext ; } public static ResourceContext createResourceContext ( String mediaType , String resourceString , byte [ ] resourceBinary ) { return createMimeResponse ( mediaType , resourceString , resourceBinary , ResourceContext . class ) ; } public static < T extends MimeResponse > T createMimeResponse ( String mimeType , String itemString , byte [ ] itemBinary , Class < T > clazz ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mimeType , "<STR_LIT>" , "<STR_LIT>" ) ; if ( ( itemString == null ) && ( itemBinary == null || itemBinary . length == <NUM_LIT:0> ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } T mimeResponse ; try { mimeResponse = clazz . newInstance ( ) ; } catch ( Exception e ) { throw new RuntimeException ( "<STR_LIT>" + clazz . getSimpleName ( ) , e ) ; } mimeResponse . setMimeType ( mimeType ) ; if ( itemString != null ) { mimeResponse . setItemString ( itemString ) ; } else { mimeResponse . setItemBinary ( itemBinary ) ; } return mimeResponse ; } public static SessionContext createSessionContext ( String sessionID , int expires ) { if ( expires < <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } SessionContext sessionContext = new SessionContext ( ) ; sessionContext . setSessionID ( sessionID ) ; sessionContext . setExpires ( expires ) ; return sessionContext ; } public static UserContext createUserContext ( String userContextKey ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userContextKey , "<STR_LIT>" , "<STR_LIT>" ) ; UserContext userContext = new UserContext ( ) ; userContext . setUserContextKey ( userContextKey ) ; return userContext ; } public static RegistrationData createRegistrationData ( String consumerName , String consumerAgent , boolean methodGetSupported ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerName , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerAgent , "<STR_LIT>" , "<STR_LIT>" ) ; RegistrationData regData = createDefaultRegistrationData ( ) ; regData . setConsumerName ( consumerName ) ; regData . setConsumerAgent ( consumerAgent ) ; regData . setMethodGetSupported ( methodGetSupported ) ; return regData ; } public static RegistrationData createDefaultRegistrationData ( ) { RegistrationData registrationData = new RegistrationData ( ) ; registrationData . setConsumerName ( WSRPConstants . DEFAULT_CONSUMER_NAME ) ; registrationData . setConsumerAgent ( WSRPConstants . CONSUMER_AGENT ) ; registrationData . setMethodGetSupported ( false ) ; return registrationData ; } public static Property createProperty ( String name , String lang , String stringValue ) { QName qName = QName . valueOf ( name ) ; return createProperty ( qName , lang , stringValue ) ; } public static Property createProperty ( QName name , String lang , String stringValue ) { ParameterValidation . throwIllegalArgExceptionIfNull ( name , "<STR_LIT:name>" ) ; Property property = new Property ( ) ; property . setName ( name ) ; if ( ! ParameterValidation . isNullOrEmpty ( lang ) ) { property . setLang ( lang ) ; } property . setStringValue ( stringValue ) ; return property ; } private static final OpaqueStateString WSRP_INTERACTION_STATE_TOKEN = new OpaqueStateString ( REWRITE_PARAMETER_OPEN + INTERACTION_STATE + REWRITE_PARAMETER_CLOSE ) ; private static final ActionURL ACTION_URL = new ActionURL ( ) { public StateString getInteractionState ( ) { return WSRP_INTERACTION_STATE_TOKEN ; } public StateString getNavigationalState ( ) { return getTemplateNS ( ) ; } public Mode getMode ( ) { return getTemplateMode ( ) ; } public WindowState getWindowState ( ) { return getTemplateWindowState ( ) ; } public Map < String , String > getProperties ( ) { return Collections . emptyMap ( ) ; } } ; private static final HashMap < String , String [ ] > WSRP_PNS_MAP_TOKEN = new HashMap < String , String [ ] > ( ) ; static { WSRP_PNS_MAP_TOKEN . put ( WSRP2RewritingConstants . NAVIGATIONAL_VALUES , new String [ ] { REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants . NAVIGATIONAL_VALUES + REWRITE_PARAMETER_CLOSE } ) ; } private static final RenderURL RENDER_URL = new RenderURL ( ) { public StateString getNavigationalState ( ) { return getTemplateNS ( ) ; } public Map < String , String [ ] > getPublicNavigationalStateChanges ( ) { return WSRP_PNS_MAP_TOKEN ; } public Mode getMode ( ) { return getTemplateMode ( ) ; } public WindowState getWindowState ( ) { return getTemplateWindowState ( ) ; } public Map < String , String > getProperties ( ) { return Collections . emptyMap ( ) ; } } ; private static final OpaqueStateString WSRP_RESOURCE_STATE_TOKEN = new OpaqueStateString ( REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants . RESOURCE_STATE + REWRITE_PARAMETER_CLOSE ) ; private static ResourceURL RESOURCE_URL = new ResourceURL ( ) { public String getResourceId ( ) { return REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants . RESOURCE_ID + REWRITE_PARAMETER_CLOSE ; } public StateString getResourceState ( ) { return WSRP_RESOURCE_STATE_TOKEN ; } public CacheLevel getCacheability ( ) { return CacheLevel . create ( REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants . RESOURCE_CACHEABILITY + REWRITE_PARAMETER_CLOSE ) ; } public Mode getMode ( ) { return getTemplateMode ( ) ; } public WindowState getWindowState ( ) { return getTemplateWindowState ( ) ; } public StateString getNavigationalState ( ) { return getTemplateNS ( ) ; } public Map < String , String > getProperties ( ) { return Collections . emptyMap ( ) ; } } ; private static StateString getTemplateNS ( ) { return WSRP_NAVIGATIONAL_STATE_TOKEN ; } private static WindowState getTemplateWindowState ( ) { return WSRP_WINDOW_STATE_TOKEN ; } private static Mode getTemplateMode ( ) { return WSRP_MODE_TOKEN ; } public static Templates createTemplates ( PortletInvocationContext context ) { Templates templates = new Templates ( ) ; templates . setBlockingActionTemplate ( createTemplate ( context , ACTION_URL , Boolean . FALSE ) ) ; templates . setRenderTemplate ( createTemplate ( context , RENDER_URL , Boolean . FALSE ) ) ; templates . setSecureBlockingActionTemplate ( createTemplate ( context , ACTION_URL , Boolean . TRUE ) ) ; templates . setSecureRenderTemplate ( createTemplate ( context , RENDER_URL , Boolean . TRUE ) ) ; templates . setResourceTemplate ( createTemplate ( context , RESOURCE_URL , false ) ) ; templates . setSecureResourceTemplate ( createTemplate ( context , RESOURCE_URL , true ) ) ; return templates ; } public static Templates createTemplates ( String defaultTemplate , String blockingActionTemplate , String renderTemplate , String resourceTemplate , String secureDefaultTemplate , String secureBlockingActionTemplate , String secureRenderTemplate , String secureResourceTemplate ) { Templates templates = new Templates ( ) ; templates . setDefaultTemplate ( defaultTemplate ) ; templates . setBlockingActionTemplate ( blockingActionTemplate ) ; templates . setRenderTemplate ( renderTemplate ) ; templates . setResourceTemplate ( resourceTemplate ) ; templates . setSecureDefaultTemplate ( secureDefaultTemplate ) ; templates . setSecureBlockingActionTemplate ( secureBlockingActionTemplate ) ; templates . setSecureRenderTemplate ( secureRenderTemplate ) ; templates . setSecureResourceTemplate ( secureResourceTemplate ) ; return templates ; } private static String createTemplate ( PortletInvocationContext context , ContainerURL url , Boolean secure ) { String template = context . renderURL ( url , new URLFormat ( secure , null , null , true ) ) ; template = TextTools . replace ( template , WSRPRewritingConstants . ENC_OPEN , WSRPRewritingConstants . REWRITE_PARAMETER_OPEN ) ; template = TextTools . replace ( template , WSRPRewritingConstants . ENC_CLOSE , WSRPRewritingConstants . REWRITE_PARAMETER_CLOSE ) ; if ( RESOURCE_URL == url ) { template += ADDITIONAL_RESOURCE_URL_PARAMS ; } return template ; } public static ClientData createClientData ( String userAgent ) { ClientData clientData = new ClientData ( ) ; clientData . setUserAgent ( userAgent ) ; return clientData ; } public static CacheControl createCacheControl ( int expires , String userScope ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( userScope , "<STR_LIT>" , "<STR_LIT>" ) ; if ( expires < - <NUM_LIT:1> ) { throw new IllegalArgumentException ( "<STR_LIT>" + "<STR_LIT>" ) ; } CacheControl cacheControl = new CacheControl ( ) ; cacheControl . setExpires ( expires ) ; cacheControl . setUserScope ( userScope ) ; return cacheControl ; } public static RegistrationContext createRegistrationContext ( String registrationHandle ) { ParameterValidation . throwIllegalArgExceptionIfNull ( registrationHandle , "<STR_LIT>" ) ; RegistrationContext registrationContext = new RegistrationContext ( ) ; registrationContext . setRegistrationHandle ( registrationHandle ) ; return registrationContext ; } public static ModelDescription createModelDescription ( List < PropertyDescription > propertyDescriptions ) { ModelDescription description = new ModelDescription ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( propertyDescriptions ) ) { description . getPropertyDescriptions ( ) . addAll ( propertyDescriptions ) ; } return description ; } public static PropertyDescription createPropertyDescription ( String name , QName type ) { QName qName = QName . valueOf ( name ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( type , "<STR_LIT>" ) ; PropertyDescription description = new PropertyDescription ( ) ; description . setName ( qName ) ; description . setType ( type ) ; return description ; } public static LocalizedString createLocalizedString ( String lang , String resourceName , String value ) { ParameterValidation . throwIllegalArgExceptionIfNull ( lang , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( value , "<STR_LIT>" ) ; LocalizedString localizedString = new LocalizedString ( ) ; localizedString . setLang ( lang ) ; localizedString . setResourceName ( resourceName ) ; localizedString . setValue ( value ) ; return localizedString ; } public static LocalizedString createLocalizedString ( String value ) { return createLocalizedString ( "<STR_LIT:en>" , null , value ) ; } public static PortletDescriptionResponse createPortletDescriptionResponse ( PortletDescription portletDescription ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletDescription , "<STR_LIT>" ) ; PortletDescriptionResponse response = new PortletDescriptionResponse ( ) ; response . setPortletDescription ( portletDescription ) ; return response ; } public static PortletPropertyDescriptionResponse createPortletPropertyDescriptionResponse ( List < PropertyDescription > propertyDescriptions ) { ModelDescription modelDescription = propertyDescriptions == null ? null : createModelDescription ( propertyDescriptions ) ; PortletPropertyDescriptionResponse portletPropertyDescriptionResponse = new PortletPropertyDescriptionResponse ( ) ; portletPropertyDescriptionResponse . setModelDescription ( modelDescription ) ; return portletPropertyDescriptionResponse ; } public static GetPortletPropertyDescription createGetPortletPropertyDescription ( RegistrationContext registrationContext , PortletContext portletContext , UserContext userContext , List < String > desiredLocales ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; GetPortletPropertyDescription description = new GetPortletPropertyDescription ( ) ; description . setRegistrationContext ( registrationContext ) ; description . setPortletContext ( portletContext ) ; description . setUserContext ( userContext ) ; if ( ParameterValidation . existsAndIsNotEmpty ( desiredLocales ) ) { description . getDesiredLocales ( ) . addAll ( desiredLocales ) ; } return description ; } public static GetPortletPropertyDescription createSimpleGetPortletPropertyDescription ( String portletHandle ) { return createGetPortletPropertyDescription ( null , createPortletContext ( portletHandle ) , null , null ) ; } public static SetPortletProperties createSetPortletProperties ( RegistrationContext registrationContext , PortletContext portletContext , PropertyList propertyList ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( propertyList , "<STR_LIT>" ) ; SetPortletProperties properties = new SetPortletProperties ( ) ; properties . setRegistrationContext ( registrationContext ) ; properties . setPortletContext ( portletContext ) ; properties . setPropertyList ( propertyList ) ; return properties ; } public static ClonePortlet createSimpleClonePortlet ( String portletHandle ) { return createClonePortlet ( null , createPortletContext ( portletHandle ) , null ) ; } public static ClonePortlet createClonePortlet ( RegistrationContext registrationContext , PortletContext portletContext , UserContext userContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ClonePortlet clonePortlet = new ClonePortlet ( ) ; clonePortlet . setPortletContext ( portletContext ) ; clonePortlet . setRegistrationContext ( registrationContext ) ; clonePortlet . setUserContext ( userContext ) ; return clonePortlet ; } public static DestroyPortlets createDestroyPortlets ( RegistrationContext registrationContext , List < String > portletHandles ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletHandles , "<STR_LIT>" ) ; if ( ! ParameterValidation . existsAndIsNotEmpty ( portletHandles ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } DestroyPortlets destroyPortlets = new DestroyPortlets ( ) ; destroyPortlets . setRegistrationContext ( registrationContext ) ; destroyPortlets . getPortletHandles ( ) . addAll ( portletHandles ) ; return destroyPortlets ; } public static PropertyList createPropertyList ( ) { return new PropertyList ( ) ; } public static ResetProperty createResetProperty ( String name ) { QName qName = QName . valueOf ( name ) ; ResetProperty resetProperty = new ResetProperty ( ) ; resetProperty . setName ( qName ) ; return resetProperty ; } public static ReleaseSessions createReleaseSessions ( RegistrationContext registrationContext , List < String > sessionIDs ) { ParameterValidation . throwIllegalArgExceptionIfNull ( sessionIDs , "<STR_LIT>" ) ; if ( sessionIDs . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ReleaseSessions sessions = new ReleaseSessions ( ) ; sessions . setRegistrationContext ( registrationContext ) ; if ( ParameterValidation . existsAndIsNotEmpty ( sessionIDs ) ) { sessions . getSessionIDs ( ) . addAll ( sessionIDs ) ; } return sessions ; } public static ModifyRegistration createModifyRegistration ( RegistrationContext registrationContext , RegistrationData registrationData ) { ParameterValidation . throwIllegalArgExceptionIfNull ( registrationData , "<STR_LIT>" ) ; ModifyRegistration registration = new ModifyRegistration ( ) ; registration . setRegistrationContext ( registrationContext ) ; registration . setRegistrationData ( registrationData ) ; return registration ; } public static UploadContext createUploadContext ( String mimeType , byte [ ] uploadData ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mimeType , "<STR_LIT>" , "<STR_LIT>" ) ; if ( uploadData == null || uploadData . length == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } UploadContext uploadContext = new UploadContext ( ) ; uploadContext . setMimeType ( mimeType ) ; uploadContext . setUploadData ( uploadData ) ; return uploadContext ; } public static MarkupType createMarkupType ( String mimeType , List < String > modeNames , List < String > windowStateNames , List < String > localeNames ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( mimeType , "<STR_LIT>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( modeNames , "<STR_LIT>" ) ; if ( modeNames . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ParameterValidation . throwIllegalArgExceptionIfNull ( windowStateNames , "<STR_LIT>" ) ; if ( windowStateNames . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } MarkupType markupType = new MarkupType ( ) ; markupType . setMimeType ( mimeType ) ; if ( ParameterValidation . existsAndIsNotEmpty ( modeNames ) ) { markupType . getModes ( ) . addAll ( modeNames ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( windowStateNames ) ) { markupType . getWindowStates ( ) . addAll ( windowStateNames ) ; } if ( ParameterValidation . existsAndIsNotEmpty ( localeNames ) ) { markupType . getLocales ( ) . addAll ( localeNames ) ; } return markupType ; } public static FailedPortlets createFailedPortlets ( Collection < String > portletHandles , ErrorCodes . Codes errorCode , String reason ) { ParameterValidation . throwIllegalArgExceptionIfNull ( errorCode , "<STR_LIT>" ) ; if ( ParameterValidation . existsAndIsNotEmpty ( portletHandles ) ) { FailedPortlets failedPortlets = new FailedPortlets ( ) ; failedPortlets . getPortletHandles ( ) . addAll ( portletHandles ) ; if ( reason != null ) { failedPortlets . setReason ( createLocalizedString ( reason ) ) ; } failedPortlets . setErrorCode ( ErrorCodes . getQname ( errorCode ) ) ; return failedPortlets ; } throw new IllegalArgumentException ( "<STR_LIT>" ) ; } public static DestroyPortletsResponse createDestroyPortletsResponse ( List < FailedPortlets > failedPortlets ) { DestroyPortletsResponse dpr = new DestroyPortletsResponse ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( failedPortlets ) ) { dpr . getFailedPortlets ( ) . addAll ( failedPortlets ) ; } return dpr ; } public static NavigationalContext createNavigationalContextOrNull ( StateString navigationalState , Map < String , String [ ] > publicNavigationalState ) { if ( navigationalState != null || publicNavigationalState != null ) { NavigationalContext context = new NavigationalContext ( ) ; if ( navigationalState != null ) { String state = navigationalState . getStringValue ( ) ; if ( ! StateString . JBPNS_PREFIX . equals ( state ) ) { context . setOpaqueValue ( state ) ; } } if ( ParameterValidation . existsAndIsNotEmpty ( publicNavigationalState ) ) { for ( Map . Entry < String , String [ ] > entry : publicNavigationalState . entrySet ( ) ) { String name = entry . getKey ( ) ; for ( String value : entry . getValue ( ) ) { context . getPublicValues ( ) . add ( WSRPTypeFactory . createNamedString ( name , value ) ) ; } } } return context ; } return null ; } public static NavigationalContext createNavigationalContext ( String opaqueValue , List < NamedString > publicValues ) { NavigationalContext navigationalContext = new NavigationalContext ( ) ; navigationalContext . setOpaqueValue ( opaqueValue ) ; if ( publicValues != null && ! publicValues . isEmpty ( ) ) { navigationalContext . getPublicValues ( ) . addAll ( publicValues ) ; } return navigationalContext ; } public static ParameterDescription createParameterDescription ( String identifier ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( identifier , "<STR_LIT>" , null ) ; ParameterDescription desc = new ParameterDescription ( ) ; desc . setIdentifier ( identifier ) ; return desc ; } public static EventDescription createEventDescription ( QName name ) { ParameterValidation . throwIllegalArgExceptionIfNull ( name , "<STR_LIT:name>" ) ; EventDescription desc = new EventDescription ( ) ; desc . setName ( name ) ; return desc ; } public static HandleEventsResponse createHandleEventsReponse ( ) { return new HandleEventsResponse ( ) ; } public static EventParams createEventParams ( List < Event > events , StateChange portletStateChange ) { if ( ! ParameterValidation . existsAndIsNotEmpty ( events ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ParameterValidation . throwIllegalArgExceptionIfNull ( portletStateChange , "<STR_LIT>" ) ; EventParams eventParams = new EventParams ( ) ; eventParams . setPortletStateChange ( portletStateChange ) ; eventParams . getEvents ( ) . addAll ( events ) ; return eventParams ; } public static Event createEvent ( QName name , Serializable payload ) { ParameterValidation . throwIllegalArgExceptionIfNull ( name , "<STR_LIT>" ) ; Event event = new Event ( ) ; event . setName ( name ) ; if ( payload != null ) { event . setPayload ( PayloadUtils . getPayloadAsEventPayload ( event , payload ) ) ; } return event ; } public static EventPayload createEventPayloadAsAny ( Object value ) { EventPayload payload = new EventPayload ( ) ; payload . setAny ( value ) ; return payload ; } public static NamedString createNamedString ( String name , String value ) { ParameterValidation . throwIllegalArgExceptionIfNull ( name , "<STR_LIT:name>" ) ; NamedString namedString = new NamedString ( ) ; namedString . setName ( name ) ; namedString . setValue ( value ) ; return namedString ; } public static EventPayload createEventPayloadAsNamedString ( NamedStringArray payload ) { EventPayload result = new EventPayload ( ) ; result . setNamedStringArray ( payload ) ; return result ; } public static ExportPortlets createExportPortlets ( RegistrationContext registrationContext , List < PortletContext > portletContexts , UserContext userContext , Lifetime lifetime , Boolean exportByValue ) { if ( ! ParameterValidation . existsAndIsNotEmpty ( portletContexts ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ExportPortlets exportPortlets = new ExportPortlets ( ) ; exportPortlets . setRegistrationContext ( registrationContext ) ; exportPortlets . getPortletContext ( ) . addAll ( portletContexts ) ; exportPortlets . setUserContext ( userContext ) ; exportPortlets . setLifetime ( lifetime ) ; exportPortlets . setExportByValueRequired ( exportByValue ) ; return exportPortlets ; } public static ExportPortletsResponse createExportPortletsResponse ( byte [ ] exportContext , List < ExportedPortlet > exportedPortlets , List < FailedPortlets > failedPortlets , Lifetime lifetime , ResourceList resourceList ) { ExportPortletsResponse response = new ExportPortletsResponse ( ) ; response . setExportContext ( exportContext ) ; response . getExportedPortlet ( ) . addAll ( exportedPortlets ) ; response . getFailedPortlets ( ) . addAll ( failedPortlets ) ; response . setLifetime ( lifetime ) ; response . setResourceList ( resourceList ) ; return response ; } public static ExportedPortlet createExportedPortlet ( String portletHandle , byte [ ] exportData ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletHandle , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( exportData , "<STR_LIT>" ) ; ExportedPortlet exportedPortlet = new ExportedPortlet ( ) ; exportedPortlet . setPortletHandle ( portletHandle ) ; exportedPortlet . setExportData ( exportData ) ; return exportedPortlet ; } public static ImportPortlets createImportPortlets ( RegistrationContext registrationContext , byte [ ] importContext , List < ImportPortlet > importPortlet , UserContext userContext , Lifetime lifetime ) { if ( ! ParameterValidation . existsAndIsNotEmpty ( importPortlet ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ImportPortlets importPortlets = new ImportPortlets ( ) ; importPortlets . setRegistrationContext ( registrationContext ) ; importPortlets . setImportContext ( importContext ) ; importPortlets . getImportPortlet ( ) . addAll ( importPortlet ) ; importPortlets . setUserContext ( userContext ) ; importPortlets . setLifetime ( lifetime ) ; return importPortlets ; } public static ImportPortlet createImportPortlet ( String importID , byte [ ] exportData ) { ParameterValidation . throwIllegalArgExceptionIfNull ( importID , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( exportData , "<STR_LIT>" ) ; ImportPortlet importPortlet = new ImportPortlet ( ) ; importPortlet . setImportID ( importID ) ; importPortlet . setExportData ( exportData ) ; return importPortlet ; } public static ImportPortletsResponse createImportPortletsResponse ( List < ImportedPortlet > importedPortlets , List < ImportPortletsFailed > importPortletsFailed , ResourceList resourceList ) { ImportPortletsResponse response = new ImportPortletsResponse ( ) ; response . getImportedPortlets ( ) . addAll ( importedPortlets ) ; response . getImportFailed ( ) . addAll ( importPortletsFailed ) ; response . setResourceList ( resourceList ) ; return response ; } public static ImportPortletsFailed createImportPortletsFailed ( List < String > importIds , ErrorCodes . Codes errorCode , String reason ) { ParameterValidation . throwIllegalArgExceptionIfNull ( errorCode , "<STR_LIT>" ) ; if ( ParameterValidation . existsAndIsNotEmpty ( importIds ) ) { ImportPortletsFailed failedPortlets = new ImportPortletsFailed ( ) ; failedPortlets . getImportID ( ) . addAll ( importIds ) ; if ( reason != null ) { failedPortlets . setReason ( createLocalizedString ( reason ) ) ; } failedPortlets . setErrorCode ( ErrorCodes . getQname ( errorCode ) ) ; return failedPortlets ; } throw new IllegalArgumentException ( "<STR_LIT>" ) ; } public static ImportedPortlet createImportedPortlet ( String portletID , PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNull ( portletID , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; ImportedPortlet importedPortlet = new ImportedPortlet ( ) ; importedPortlet . setImportID ( portletID ) ; importedPortlet . setNewPortletContext ( portletContext ) ; return importedPortlet ; } public static ReleaseExport createReleaseExport ( RegistrationContext registrationContext , byte [ ] exportContext , UserContext userContext ) { if ( exportContext == null || exportContext . length == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ReleaseExport releaseExport = new ReleaseExport ( ) ; releaseExport . setRegistrationContext ( registrationContext ) ; releaseExport . setExportContext ( exportContext ) ; releaseExport . setUserContext ( userContext ) ; return releaseExport ; } public static SetExportLifetime createSetExportLifetime ( RegistrationContext registrationContext , byte [ ] exportContext , UserContext userContext , Lifetime lifetime ) { if ( exportContext == null || exportContext . length == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } SetExportLifetime setExportLifetime = new SetExportLifetime ( ) ; setExportLifetime . setRegistrationContext ( registrationContext ) ; setExportLifetime . setExportContext ( exportContext ) ; setExportLifetime . setUserContext ( userContext ) ; setExportLifetime . setLifetime ( lifetime ) ; return setExportLifetime ; } public static Contact createContact ( Postal postal , Telecom telecom , Online online ) { Contact contact = new Contact ( ) ; contact . setPostal ( postal ) ; contact . setTelecom ( telecom ) ; contact . setOnline ( online ) ; return contact ; } public static Postal createPostal ( String name , String street , String city , String stateprov , String postalCode , String country , String organization ) { Postal postal = new Postal ( ) ; postal . setName ( name ) ; postal . setStreet ( street ) ; postal . setCity ( city ) ; postal . setStateprov ( stateprov ) ; postal . setPostalcode ( postalCode ) ; postal . setCountry ( country ) ; postal . setOrganization ( organization ) ; return postal ; } public static Telecom createTelecom ( TelephoneNum telephone , TelephoneNum fax , TelephoneNum mobile , TelephoneNum pager ) { Telecom telecom = new Telecom ( ) ; telecom . setTelephone ( telephone ) ; telecom . setFax ( fax ) ; telecom . setMobile ( mobile ) ; telecom . setPager ( pager ) ; return telecom ; } public static TelephoneNum createTelephoneNum ( String intCode , String loccode , String number , String ext , String comment ) { TelephoneNum telephoneNum = new TelephoneNum ( ) ; telephoneNum . setIntcode ( intCode ) ; telephoneNum . setLoccode ( loccode ) ; telephoneNum . setNumber ( number ) ; telephoneNum . setExt ( ext ) ; telephoneNum . setComment ( comment ) ; return telephoneNum ; } public static Online createOnline ( String email , String uri ) { Online online = new Online ( ) ; online . setEmail ( email ) ; online . setUri ( uri ) ; return online ; } public static EmployerInfo createEmployerInfo ( String employer , String department , String jobTitle ) { EmployerInfo employerInfo = new EmployerInfo ( ) ; employerInfo . setEmployer ( employer ) ; employerInfo . setDepartment ( department ) ; employerInfo . setJobtitle ( jobTitle ) ; return employerInfo ; } public static PersonName createPersonName ( String prefix , String given , String family , String middle , String suffix , String nickname ) { PersonName personName = new PersonName ( ) ; personName . setPrefix ( prefix ) ; personName . setGiven ( given ) ; personName . setFamily ( family ) ; personName . setMiddle ( middle ) ; personName . setSuffix ( suffix ) ; personName . setNickname ( nickname ) ; return personName ; } public static Extension createExtension ( Object any ) { ParameterValidation . throwIllegalArgExceptionIfNull ( any , "<STR_LIT>" ) ; Extension extension = new Extension ( ) ; extension . setAny ( any ) ; return extension ; } public static MissingParametersFault createMissingParametersFault ( ) { MissingParametersFault missingParametersFault = new MissingParametersFault ( ) ; return missingParametersFault ; } public static OperationFailedFault createOperationFailedFault ( ) { OperationFailedFault operationFailedFault = new OperationFailedFault ( ) ; return operationFailedFault ; } public static ItemDescription createItemDescription ( LocalizedString description , LocalizedString displayName , String itemName ) { ParameterValidation . throwIllegalArgExceptionIfNull ( itemName , "<STR_LIT>" ) ; ItemDescription itemDescription = new ItemDescription ( ) ; itemDescription . setDescription ( description ) ; itemDescription . setDisplayName ( displayName ) ; itemDescription . setItemName ( itemName ) ; return itemDescription ; } public static Resource createResource ( String resourceName , List < ResourceValue > resourceValue ) { ParameterValidation . throwIllegalArgExceptionIfNull ( resourceName , "<STR_LIT>" ) ; Resource resource = new Resource ( ) ; resource . setResourceName ( resourceName ) ; if ( resourceValue != null && ! resourceValue . isEmpty ( ) ) { resource . getValues ( ) . addAll ( resourceValue ) ; } return resource ; } public static ResourceList createResourceList ( List < Resource > resources ) { if ( ParameterValidation . existsAndIsNotEmpty ( resources ) ) { ResourceList resourceList = new ResourceList ( ) ; resourceList . getResources ( ) . addAll ( resources ) ; return resourceList ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } public static ResourceValue createResourceValue ( String lang , String value ) { ParameterValidation . throwIllegalArgExceptionIfNull ( lang , "<STR_LIT>" ) ; ResourceValue resourceValue = new ResourceValue ( ) ; resourceValue . setLang ( value ) ; resourceValue . setValue ( value ) ; return resourceValue ; } public static ReturnAny createReturnAny ( ) { return new ReturnAny ( ) ; } public static SessionParams createSessionParams ( String sessionID ) { SessionParams sessionParams = new SessionParams ( ) ; sessionParams . setSessionID ( sessionID ) ; return sessionParams ; } public static UserProfile createUserProfile ( PersonName name , XMLGregorianCalendar bdate , String gender , EmployerInfo employerInfo , Contact homeInfo , Contact businessInfo ) { UserProfile userProfile = new UserProfile ( ) ; userProfile . setName ( name ) ; userProfile . setBdate ( bdate ) ; userProfile . setGender ( gender ) ; userProfile . setEmployerInfo ( employerInfo ) ; userProfile . setHomeInfo ( homeInfo ) ; userProfile . setBusinessInfo ( businessInfo ) ; return userProfile ; } public static CopyPortlets createCopyPortlets ( RegistrationContext toRegistrationContext , UserContext toUserContext , RegistrationContext fromRegistrationContext , UserContext fromUserContext , List < PortletContext > fromPortletContexts ) { if ( ! ParameterValidation . existsAndIsNotEmpty ( fromPortletContexts ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } CopyPortlets copyPortlets = new CopyPortlets ( ) ; copyPortlets . setToRegistrationContext ( toRegistrationContext ) ; copyPortlets . setToUserContext ( toUserContext ) ; copyPortlets . setFromRegistrationContext ( fromRegistrationContext ) ; copyPortlets . setFromUserContext ( fromUserContext ) ; copyPortlets . getFromPortletContexts ( ) . addAll ( fromPortletContexts ) ; return copyPortlets ; } public static CopyPortletsResponse createCopyPortletsResponse ( List < CopiedPortlet > copiedPortlets , List < FailedPortlets > failedPortlets , ResourceList resourceList ) { CopyPortletsResponse response = new CopyPortletsResponse ( ) ; response . getCopiedPortlets ( ) . addAll ( copiedPortlets ) ; response . getFailedPortlets ( ) . addAll ( failedPortlets ) ; response . setResourceList ( resourceList ) ; return response ; } public static CopiedPortlet createCopiedPortlet ( PortletContext newPortletContext , String fromPortletHandle ) { ParameterValidation . throwIllegalArgExceptionIfNull ( newPortletContext , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( fromPortletHandle , "<STR_LIT>" , "<STR_LIT>" ) ; CopiedPortlet copiedPortlet = new CopiedPortlet ( ) ; copiedPortlet . setNewPortletContext ( newPortletContext ) ; copiedPortlet . setFromPortletHandle ( fromPortletHandle ) ; return copiedPortlet ; } public static NamedStringArray createNamedStringArray ( ) { return new NamedStringArray ( ) ; } public static String getPortletInstanceKey ( InstanceContext instanceContext ) { return instanceContext . getId ( ) ; } public static String getNamespacePrefix ( WindowContext windowContext , String portletHandle ) { String namespacePrefix = getNamespaceFrom ( windowContext ) ; if ( namespacePrefix == null ) { return portletHandle ; } return namespacePrefix ; } public static String getNamespaceFrom ( WindowContext windowContext ) { if ( windowContext != null ) { return windowContext . getNamespace ( ) ; } return null ; } } </s>
<s> package org . gatein . wsrp ; import org . gatein . common . net . URLTools ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . OpaqueStateString ; import org . gatein . pc . api . ResourceURL ; import org . gatein . pc . api . StateString ; import org . gatein . pc . api . WindowState ; import org . gatein . pc . api . cache . CacheLevel ; import org . gatein . wsrp . spec . v2 . WSRP2RewritingConstants ; import java . net . MalformedURLException ; import java . net . URL ; import java . util . HashMap ; import java . util . Map ; public class WSRPResourceURL extends WSRPPortletURL implements ResourceURL { public final static String DEFAULT_RESOURCE_ID = "<STR_LIT>" ; private String resourceId ; private StateString resourceState ; private CacheLevel cacheability ; private boolean requiresRewrite = false ; private URL resourceURL ; private boolean preferOperation = false ; public WSRPResourceURL ( ) { } public WSRPResourceURL ( Mode mode , WindowState windowState , boolean secure , StateString navigationalState , StateString resourceState , String resourceId , CacheLevel cacheability , URLContext context ) { super ( mode , windowState , secure , navigationalState , context ) ; if ( resourceId == null ) { resourceId = DEFAULT_RESOURCE_ID ; } else { preferOperation = true ; } if ( context != null && ! URLContext . EMPTY . equals ( context ) ) { resourceURL = ResourceServingUtil . encode ( mode , windowState , secure , navigationalState , resourceState , resourceId , cacheability , context ) ; } else { resourceURL = null ; } this . resourceId = resourceId ; this . resourceState = resourceState ; this . cacheability = cacheability ; } protected String getURLType ( ) { return WSRPRewritingConstants . URL_TYPE_RESOURCE ; } protected void appendEnd ( StringBuffer sb ) { if ( resourceURL != null ) { createURLParameter ( sb , WSRPRewritingConstants . RESOURCE_URL , URLTools . encodeXWWWFormURL ( resourceURL . toExternalForm ( ) ) ) ; } createURLParameter ( sb , WSRPRewritingConstants . RESOURCE_REQUIRES_REWRITE , requiresRewrite ? "<STR_LIT:true>" : "<STR_LIT:false>" ) ; if ( resourceId != null ) { createURLParameter ( sb , WSRP2RewritingConstants . RESOURCE_ID , URLTools . encodeXWWWFormURL ( resourceId ) ) ; } if ( preferOperation != false ) { createURLParameter ( sb , WSRP2RewritingConstants . RESOURCE_PREFER_OPERATION , Boolean . toString ( preferOperation ) ) ; } if ( resourceState != null ) { createURLParameter ( sb , WSRP2RewritingConstants . RESOURCE_STATE , resourceState . getStringValue ( ) ) ; } } @ Override protected void dealWithSpecificParams ( Map < String , String > params , String originalURL ) { super . dealWithSpecificParams ( params , originalURL ) ; String requireRewrite = getRawParameterValueFor ( params , WSRPRewritingConstants . RESOURCE_REQUIRES_REWRITE ) ; if ( requireRewrite != null ) { requiresRewrite = Boolean . valueOf ( requireRewrite ) ; params . remove ( WSRPRewritingConstants . RESOURCE_REQUIRES_REWRITE ) ; } String resourceState = getRawParameterValueFor ( params , WSRP2RewritingConstants . RESOURCE_STATE ) ; if ( resourceState != null ) { this . resourceState = new OpaqueStateString ( resourceState ) ; params . remove ( WSRP2RewritingConstants . RESOURCE_STATE ) ; } String url = getRawParameterValueFor ( params , WSRPRewritingConstants . RESOURCE_URL ) ; if ( url != null ) { try { url = URLTools . decodeXWWWFormURL ( url ) ; this . resourceURL = new URL ( url ) ; params . remove ( WSRPRewritingConstants . RESOURCE_URL ) ; } catch ( MalformedURLException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + url , e ) ; } } String resourceIDParam = getRawParameterValueFor ( params , WSRP2RewritingConstants . RESOURCE_ID ) ; if ( resourceIDParam != null ) { resourceId = URLTools . decodeXWWWFormURL ( resourceIDParam ) ; params . remove ( WSRP2RewritingConstants . RESOURCE_ID ) ; } if ( resourceIDParam == null && requireRewrite == null ) { requiresRewrite = false ; } if ( resourceIDParam == null && url == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + WSRP2RewritingConstants . RESOURCE_ID + "<STR_LIT>" + WSRPRewritingConstants . RESOURCE_URL + "<STR_LIT:U+0020andU+0020>" + WSRPRewritingConstants . RESOURCE_REQUIRES_REWRITE + "<STR_LIT>" + originalURL ) ; } String preferOperationParam = getRawParameterValueFor ( params , WSRP2RewritingConstants . RESOURCE_PREFER_OPERATION ) ; if ( preferOperationParam != null ) { preferOperation = Boolean . valueOf ( preferOperationParam ) ; params . remove ( WSRP2RewritingConstants . RESOURCE_PREFER_OPERATION ) ; } String cacheabilityParam = getRawParameterValueFor ( params , WSRP2RewritingConstants . RESOURCE_CACHEABILITY ) ; if ( cacheabilityParam != null ) { cacheability = WSRPUtils . getCacheLevelFromResourceCacheability ( cacheabilityParam ) ; params . remove ( WSRP2RewritingConstants . RESOURCE_CACHEABILITY ) ; } if ( resourceIDParam == null && url == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + WSRPRewritingConstants . RESOURCE_URL + "<STR_LIT>" + WSRP2RewritingConstants . RESOURCE_ID + "<STR_LIT>" + originalURL ) ; } } public URL getResourceURL ( ) { return resourceURL ; } public String getResourceId ( ) { return encodeResource ( resourceId , resourceURL , preferOperation ) ; } public StateString getResourceState ( ) { return resourceState ; } public CacheLevel getCacheability ( ) { return cacheability ; } public boolean requiresRewrite ( ) { return requiresRewrite ; } public static String encodeResource ( String resourceId , URL resourceURL , boolean preferedOperation ) { Map < String , String [ ] > parameters = new HashMap < String , String [ ] > ( ) ; if ( resourceId != null ) { parameters . put ( WSRP2RewritingConstants . RESOURCE_ID , new String [ ] { resourceId } ) ; } if ( resourceURL != null ) { parameters . put ( WSRPRewritingConstants . RESOURCE_URL , new String [ ] { resourceURL . toString ( ) } ) ; } parameters . put ( WSRP2RewritingConstants . RESOURCE_PREFER_OPERATION , new String [ ] { Boolean . toString ( preferedOperation ) } ) ; return StateString . encodeAsOpaqueValue ( parameters ) ; } public static Map < String , String > decodeResource ( String resourceInfo ) { Map < String , String > resource = new HashMap < String , String > ( ) ; if ( resourceInfo != null && resourceInfo . startsWith ( StateString . JBPNS_PREFIX ) ) { Map < String , String [ ] > resourceParameters = StateString . decodeOpaqueValue ( resourceInfo ) ; for ( Map . Entry < String , String [ ] > entry : resourceParameters . entrySet ( ) ) { if ( entry . getValue ( ) != null && entry . getValue ( ) . length > <NUM_LIT:0> ) { resource . put ( entry . getKey ( ) , entry . getValue ( ) [ <NUM_LIT:0> ] ) ; } } } else { resource . put ( WSRP2RewritingConstants . RESOURCE_ID , resourceInfo ) ; } return resource ; } } </s>
<s> package org . gatein . wsrp . api . extensions ; import org . oasis . wsrp . v2 . Extension ; import java . util . List ; public class DefaultConsumerExtensionAccessor extends AbstractExtensionAccessor implements ConsumerExtensionAccessor { private DefaultConsumerExtensionAccessor ( ) { } @ Override public List < Extension > getRequestExtensionsFor ( Class targetClass ) { return getExtensions ( targetClass ) ; } @ Override public void addRequestExtension ( Class targetClass , Object extension ) { addExtension ( targetClass , extension ) ; } @ Override public List < UnmarshalledExtension > getResponseExtensionsFrom ( Class responseClass ) { return getUnmarshalledExtensions ( responseClass ) ; } @ Override public void addResponseExtension ( Class responseClass , UnmarshalledExtension extension ) { addUnmarshalledExtension ( responseClass , extension ) ; } private static final class InstanceHolder { public static final ConsumerExtensionAccessor instance = new DefaultConsumerExtensionAccessor ( ) ; } public synchronized static void registerWithAPI ( ) { if ( ExtensionAccess . getConsumerExtensionAccessor ( ) == null ) { ExtensionAccess . registerConsumerAccessorInstance ( InstanceHolder . instance ) ; } } } </s>
<s> package org . gatein . wsrp . api . extensions ; import org . gatein . common . util . ParameterValidation ; import org . gatein . wsrp . WSRPTypeFactory ; import org . gatein . wsrp . payload . PayloadUtils ; import org . oasis . wsrp . v2 . Extension ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Map ; import java . util . concurrent . ConcurrentHashMap ; public class AbstractExtensionAccessor { private final ThreadLocal < Map < Class , List < Extension > > > extensions = new ThreadLocal < Map < Class , List < Extension > > > ( ) ; private final ThreadLocal < Map < Class , List < UnmarshalledExtension > > > unmarshalledExtensions = new ThreadLocal < Map < Class , List < UnmarshalledExtension > > > ( ) ; public List < Extension > getExtensions ( Class targetClass ) { return get ( extensions , targetClass ) ; } public List < UnmarshalledExtension > getUnmarshalledExtensions ( Class targetClass ) { return get ( unmarshalledExtensions , targetClass ) ; } private < T > List < T > get ( ThreadLocal < Map < Class , List < T > > > mapThreadLocal , Class targetClass ) { List < T > extensions = null ; if ( targetClass != null ) { final Map < Class , List < T > > extensionsMap = mapThreadLocal . get ( ) ; if ( extensionsMap != null ) { extensions = extensionsMap . get ( targetClass ) ; } } return extensions != null ? extensions : Collections . < T > emptyList ( ) ; } public void addExtension ( Class targetClass , Object extension ) { ParameterValidation . throwIllegalArgExceptionIfNull ( extension , "<STR_LIT>" ) ; add ( extensions , targetClass , WSRPTypeFactory . createExtension ( PayloadUtils . marshallExtension ( extension ) ) ) ; } public void addUnmarshalledExtension ( Class targetClass , UnmarshalledExtension extension ) { add ( unmarshalledExtensions , targetClass , extension ) ; } private < T > void add ( ThreadLocal < Map < Class , List < T > > > mapThreadLocal , Class targetClass , T toAdd ) { Map < Class , List < T > > extensionsMap = mapThreadLocal . get ( ) ; if ( extensionsMap == null ) { extensionsMap = new ConcurrentHashMap < Class , List < T > > ( <NUM_LIT:7> ) ; mapThreadLocal . set ( extensionsMap ) ; } List < T > extensions = extensionsMap . get ( targetClass ) ; if ( toAdd != null ) { if ( extensions == null ) { extensions = new ArrayList < T > ( <NUM_LIT:3> ) ; extensionsMap . put ( targetClass , extensions ) ; } extensions . add ( toAdd ) ; } } public void clear ( ) { extensions . set ( null ) ; unmarshalledExtensions . set ( null ) ; } } </s>
<s> package org . gatein . wsrp . api . extensions ; import org . oasis . wsrp . v2 . Extension ; import java . util . List ; public class DefaultProducerExtensionAccessor extends AbstractExtensionAccessor implements ProducerExtensionAccessor { private DefaultProducerExtensionAccessor ( ) { } @ Override public void addRequestExtension ( Class fromClass , UnmarshalledExtension extension ) { addUnmarshalledExtension ( fromClass , extension ) ; } @ Override public List < UnmarshalledExtension > getRequestExtensionsFor ( Class targetClass ) { return getUnmarshalledExtensions ( targetClass ) ; } @ Override public List < Extension > getResponseExtensionsFor ( Class wsrpResponseClass ) { return getExtensions ( wsrpResponseClass ) ; } @ Override public void addResponseExtension ( Class wsrpResponseClass , Object extension ) { addExtension ( wsrpResponseClass , extension ) ; } private static final class InstanceHolder { public static final ProducerExtensionAccessor instance = new DefaultProducerExtensionAccessor ( ) ; } public synchronized static void registerWithAPI ( ) { if ( ExtensionAccess . getProducerExtensionAccessor ( ) == null ) { ExtensionAccess . registerProducerAccessorInstance ( InstanceHolder . instance ) ; } } } </s>
<s> package org . gatein . wsrp ; import org . gatein . common . RuntimeContext ; import org . gatein . pc . api . spi . PortalContext ; import javax . xml . namespace . QName ; import java . io . IOException ; import java . net . InetAddress ; import java . net . UnknownHostException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Locale ; import java . util . Properties ; import java . util . Random ; public final class WSRPConstants { public static final boolean RUNS_IN_EPP = RuntimeContext . getInstance ( ) . isRunningIn ( RuntimeContext . RunningEnvironment . epp ) ; public static String SERVICES_DIRECTORY_URL ; public static final String WSRP_SERVICE_VERSION ; static { Properties props = new Properties ( ) ; try { props . load ( Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; } catch ( IOException e ) { throw new RuntimeException ( "<STR_LIT>" ) ; } WSRP_SERVICE_VERSION = props . getProperty ( "<STR_LIT>" ) ; final String serverPath = System . getProperty ( "<STR_LIT>" ) ; if ( serverPath != null ) { SERVICES_DIRECTORY_URL = serverPath + "<STR_LIT>" ; } else { SERVICES_DIRECTORY_URL = null ; } } public static final String NORMAL_WINDOW_STATE = "<STR_LIT>" ; public static final String MINIMIZED_WINDOW_STATE = "<STR_LIT>" ; public static final String MAXIMIZED_WINDOW_STATE = "<STR_LIT>" ; public static final String SOLO_WINDOW_STATE = "<STR_LIT>" ; public static final String VIEW_MODE = "<STR_LIT>" ; public static final String EDIT_MODE = "<STR_LIT>" ; public static final String HELP_MODE = "<STR_LIT>" ; public static final String PREVIEW_MODE = "<STR_LIT>" ; public static final String NONE_USER_AUTHENTICATION = "<STR_LIT>" ; public static final String PASSWORD_USER_AUTHENTICATION = "<STR_LIT>" ; public static final String CERTIFICATE_USER_AUTHENTICATION = "<STR_LIT>" ; public static final String DEFAULT_CHARACTER_SET = "<STR_LIT:UTF-8>" ; public static final String DEFAULT_CONSUMER_NAME ; public static final String CONSUMER_AGENT = PortalContext . VERSION . getName ( ) + "<STR_LIT:.>" + PortalContext . VERSION . getMajor ( ) + "<STR_LIT:.>" + PortalContext . VERSION . getMinor ( ) + "<STR_LIT:.>" + PortalContext . VERSION . getQualifier ( ) ; static { InetAddress localhost = null ; try { localhost = InetAddress . getLocalHost ( ) ; } catch ( UnknownHostException e ) { e . printStackTrace ( ) ; } if ( localhost != null ) { DEFAULT_CONSUMER_NAME = localhost . getCanonicalHostName ( ) ; } else { Random random = new Random ( System . currentTimeMillis ( ) ) ; DEFAULT_CONSUMER_NAME = CONSUMER_AGENT + "<STR_LIT>" + random . nextInt ( ) ; } } public static final String CACHE_PER_USER = "<STR_LIT>" ; public static final String CACHE_FOR_ALL = "<STR_LIT>" ; public static final int SESSION_NEVER_EXPIRES = - <NUM_LIT:1> ; public static final QName XSD_STRING = new QName ( "<STR_LIT>" , "<STR_LIT:string>" ) ; public static final QName XSD_INTEGER = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_INT = new QName ( "<STR_LIT>" , "<STR_LIT:int>" ) ; public static final QName XSD_LONG = new QName ( "<STR_LIT>" , "<STR_LIT:long>" ) ; public static final QName XSD_SHORT = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_DECIMAL = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_FLOAT = new QName ( "<STR_LIT>" , "<STR_LIT:float>" ) ; public static final QName XSD_DOUBLE = new QName ( "<STR_LIT>" , "<STR_LIT:double>" ) ; public static final QName XSD_BOOLEAN = new QName ( "<STR_LIT>" , "<STR_LIT:boolean>" ) ; public static final QName XSD_BYTE = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_DATE_TIME = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_BASE_64_BINARY = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_HEX_BINARY = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_UNSIGNED_INT = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_UNSIGNED_SHORT = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_TIME = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final QName XSD_DATE = new QName ( "<STR_LIT>" , "<STR_LIT:date>" ) ; public static final QName XSD_ANY_SIMPLE_TYPE = new QName ( "<STR_LIT>" , "<STR_LIT>" ) ; public static final String FROM_WSRP_ATTRIBUTE_NAME = "<STR_LIT>" ; private WSRPConstants ( ) { } public static String DEFAULT_LOCALE = WSRPUtils . toString ( Locale . getDefault ( ) ) ; public static List < String > getDefaultLocales ( ) { ArrayList < String > locales = new ArrayList < String > ( <NUM_LIT:2> ) ; locales . add ( DEFAULT_LOCALE ) ; locales . add ( "<STR_LIT:en>" ) ; return locales ; } public static List < String > getDefaultMimeTypes ( ) { return Collections . singletonList ( "<STR_LIT:text/html>" ) ; } } </s>
<s> package org . gatein . wsrp ; public interface PropertyAccessor { boolean isURLRewritingActive ( ) ; } </s>
<s> package org . gatein . wsrp ; import org . gatein . common . net . URLTools ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . StateString ; import org . gatein . pc . api . WindowState ; import org . gatein . pc . api . cache . CacheLevel ; import org . oasis . wsrp . v2 . GetResource ; import org . oasis . wsrp . v2 . NamedString ; import org . oasis . wsrp . v2 . PortletContext ; import org . oasis . wsrp . v2 . RegistrationContext ; import org . oasis . wsrp . v2 . ResourceParams ; import org . oasis . wsrp . v2 . RuntimeContext ; import org . oasis . wsrp . v2 . StateChange ; import javax . servlet . http . HttpServletRequest ; import java . net . URI ; import java . net . URL ; import java . util . Collections ; import java . util . Enumeration ; import java . util . List ; public class ResourceServingUtil { private static final String REG_HANDLE = "<STR_LIT>" ; private static final String INSTANCE_KEY = "<STR_LIT>" ; private static final String NS = "<STR_LIT>" ; private static final String MODE = "<STR_LIT>" ; private static final String WINDOW_STATE = "<STR_LIT>" ; private static final String RESOURCE_STATE = "<STR_LIT>" ; private static final String NAV_STATE = "<STR_LIT>" ; private static final String SLASH_REPLACEMENT = "<STR_LIT>" ; private static final String QMARK = "<STR_LIT:?>" ; public static GetResource decode ( HttpServletRequest req ) { String path = req . getPathInfo ( ) ; int portletHandleEnd = path . indexOf ( URLTools . SLASH , <NUM_LIT:1> ) ; String portletHandle = path . substring ( <NUM_LIT:1> , portletHandleEnd ) ; PortletContext portletContext = decode ( portletHandle ) ; String resourceId = path . substring ( portletHandleEnd ) ; String registrationHandle = req . getParameter ( REG_HANDLE ) ; RegistrationContext registrationContext = null ; if ( ! ParameterValidation . isNullOrEmpty ( registrationHandle ) ) { registrationContext = WSRPTypeFactory . createRegistrationContext ( registrationHandle ) ; } String instanceKey = URLTools . decodeXWWWFormURL ( req . getParameter ( INSTANCE_KEY ) ) ; String ns = req . getParameter ( NS ) ; RuntimeContext runtimeContext = WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , instanceKey , ns ) ; Enumeration reqLocales = req . getLocales ( ) ; List < String > locales = WSRPUtils . convertLocalesToRFC3066LanguageTags ( Collections . list ( reqLocales ) ) ; List < String > mimeTypes = WSRPConstants . getDefaultMimeTypes ( ) ; ResourceParams resourceParams = WSRPTypeFactory . createResourceParams ( req . isSecure ( ) , locales , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE , resourceId , StateChange . READ_ONLY ) ; resourceParams . setResourceState ( req . getParameter ( RESOURCE_STATE ) ) ; String navState = req . getParameter ( NAV_STATE ) ; if ( ! ParameterValidation . isNullOrEmpty ( navState ) ) { resourceParams . setNavigationalContext ( WSRPTypeFactory . createNavigationalContext ( navState , Collections . < NamedString > emptyList ( ) ) ) ; } return WSRPTypeFactory . createGetResource ( registrationContext , portletContext , runtimeContext , null , resourceParams ) ; } public static URL encode ( Mode mode , WindowState windowState , boolean secure , StateString navigationalState , StateString resourceState , String resourceId , CacheLevel cacheability , WSRPPortletURL . URLContext context ) { String serverAddress = ( String ) context . getValueFor ( WSRPPortletURL . URLContext . SERVER_ADDRESS ) ; org . gatein . pc . api . PortletContext portletContext = ( org . gatein . pc . api . PortletContext ) context . getValueFor ( WSRPPortletURL . URLContext . PORTLET_CONTEXT ) ; try { StringBuilder sb = new StringBuilder ( createAbsoluteURLFrom ( resourceId , serverAddress , portletContext ) ) ; appendParameter ( sb , MODE , mode ) ; appendParameter ( sb , WINDOW_STATE , windowState ) ; String instanceKey = ( String ) context . getValueFor ( WSRPPortletURL . URLContext . INSTANCE_KEY ) ; instanceKey = URLTools . encodeXWWWFormURL ( instanceKey ) ; appendParameter ( sb , INSTANCE_KEY , instanceKey ) ; appendParameter ( sb , NS , context . getValueFor ( WSRPPortletURL . URLContext . NAMESPACE ) ) ; appendParameter ( sb , REG_HANDLE , context . getValueFor ( WSRPPortletURL . URLContext . REGISTRATION_HANDLE ) ) ; if ( resourceState != null ) { appendParameter ( sb , RESOURCE_STATE , resourceState . getStringValue ( ) ) ; } if ( navigationalState != null ) { appendParameter ( sb , NAV_STATE , navigationalState . getStringValue ( ) ) ; } return new URI ( sb . toString ( ) ) . toURL ( ) ; } catch ( Exception e ) { throw new RuntimeException ( "<STR_LIT>" + resourceId + "<STR_LIT>" + serverAddress + "<STR_LIT>" + portletContext , e ) ; } } private static String createAbsoluteURLFrom ( String resourceId , String serverAddress , org . gatein . pc . api . PortletContext portletContext ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( resourceId , "<STR_LIT>" , null ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( serverAddress , "<STR_LIT>" , null ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( portletContext , "<STR_LIT>" ) ; String url = serverAddress + "<STR_LIT>" ; url += encode ( portletContext ) ; if ( resourceId . startsWith ( URLTools . SLASH ) ) { url += resourceId + QMARK ; } else { url += URLTools . SLASH + resourceId + QMARK ; } return url ; } private static String encode ( org . gatein . pc . api . PortletContext portletContext ) { String id = portletContext . getId ( ) ; if ( id . startsWith ( URLTools . SLASH ) ) { id = id . replace ( URLTools . SLASH , SLASH_REPLACEMENT ) ; } return URLTools . encodeXWWWFormURL ( id ) ; } private static PortletContext decode ( String encodedPortletContext ) { if ( encodedPortletContext . startsWith ( SLASH_REPLACEMENT ) ) { encodedPortletContext = encodedPortletContext . replace ( SLASH_REPLACEMENT , URLTools . SLASH ) ; } return WSRPTypeFactory . createPortletContext ( URLTools . decodeXWWWFormURL ( encodedPortletContext ) ) ; } private static void appendParameter ( StringBuilder builder , String name , Object value ) { if ( value != null ) { builder . append ( "<STR_LIT:&>" ) . append ( name ) . append ( "<STR_LIT:=>" ) . append ( value ) ; } } } </s>
<s> package org . gatein . wsrp ; import org . gatein . common . NotYetImplemented ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . spi . UserContext ; import org . oasis . wsrp . v2 . Contact ; import org . oasis . wsrp . v2 . EmployerInfo ; import org . oasis . wsrp . v2 . Online ; import org . oasis . wsrp . v2 . PersonName ; import org . oasis . wsrp . v2 . Postal ; import org . oasis . wsrp . v2 . Telecom ; import org . oasis . wsrp . v2 . TelephoneNum ; import org . oasis . wsrp . v2 . UserProfile ; import javax . xml . datatype . DatatypeConfigurationException ; import javax . xml . datatype . DatatypeFactory ; import javax . xml . datatype . XMLGregorianCalendar ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Locale ; import java . util . Map ; import static org . gatein . common . p3p . P3PConstants . * ; public class UserContextConverter { private UserContextConverter ( ) { } public static UserContext createPortalUserContextFrom ( org . oasis . wsrp . v2 . UserContext userContext , List < String > desiredLocales , String preferredLocale ) { return new WSRPMappedUserContext ( userContext , desiredLocales , preferredLocale ) ; } public static org . oasis . wsrp . v2 . UserContext createWSRPUserContextFrom ( UserContext userContext , String userContextKey , List < String > userCategories ) { org . oasis . wsrp . v2 . UserContext wsrpUserContext = WSRPTypeFactory . createUserContext ( userContextKey ) ; wsrpUserContext . setProfile ( createUserProfileFrom ( userContext ) ) ; if ( ParameterValidation . existsAndIsNotEmpty ( userCategories ) ) { wsrpUserContext . getUserCategories ( ) . addAll ( userCategories ) ; } return wsrpUserContext ; } private static UserProfile createUserProfileFrom ( UserContext userContext ) { Map < String , String > userInfos = userContext . getInformations ( ) ; if ( ! ParameterValidation . existsAndIsNotEmpty ( userInfos ) ) { return null ; } PersonName name = createNameFrom ( userInfos ) ; XMLGregorianCalendar bdate = null ; String bdateAsString = userInfos . get ( INFO_USER_BDATE ) ; if ( bdateAsString != null ) { DatatypeFactory datatypeFactory = null ; try { datatypeFactory = DatatypeFactory . newInstance ( ) ; bdate = datatypeFactory . newXMLGregorianCalendar ( bdateAsString ) ; } catch ( DatatypeConfigurationException e ) { e . printStackTrace ( ) ; } } String employer = userInfos . get ( INFO_USER_EMPLOYER ) ; String department = userInfos . get ( INFO_USER_DEPARTMENT ) ; String jobTitle = userInfos . get ( INFO_USER_JOB_TITLE ) ; EmployerInfo employerInfo = WSRPTypeFactory . createEmployerInfo ( employer , department , jobTitle ) ; Contact homeInfo = createContactFrom ( userInfos , false ) ; Contact businessInfo = createContactFrom ( userInfos , true ) ; UserProfile userProfile = WSRPTypeFactory . createUserProfile ( name , bdate , userInfos . get ( INFO_USER_GENDER ) , employerInfo , homeInfo , businessInfo ) ; return userProfile ; } private static PersonName createNameFrom ( Map < String , String > userInfos ) { String prefix = userInfos . get ( INFO_USER_NAME_PREFIX ) ; String given = userInfos . get ( INFO_USER_NAME_GIVEN ) ; String family = userInfos . get ( INFO_USER_NAME_FAMILY ) ; String middle = userInfos . get ( INFO_USER_NAME_MIDDLE ) ; String suffix = userInfos . get ( INFO_USER_NAME_SUFFIX ) ; String nickName = userInfos . get ( INFO_USER_NAME_NICKNAME ) ; PersonName name = WSRPTypeFactory . createPersonName ( prefix , given , family , middle , suffix , nickName ) ; return name ; } private static Contact createContactFrom ( Map < String , String > infos , boolean isBusiness ) { String email = infos . get ( getOnlineUserInfoKey ( OnlineInfo . EMAIL , isBusiness ) ) ; String uri = infos . get ( getOnlineUserInfoKey ( OnlineInfo . URI , isBusiness ) ) ; Online online = WSRPTypeFactory . createOnline ( email , uri ) ; String name = infos . get ( getPostalUserInfoKey ( PostalInfo . NAME , isBusiness ) ) ; String street = infos . get ( getPostalUserInfoKey ( PostalInfo . STREET , isBusiness ) ) ; String city = infos . get ( getPostalUserInfoKey ( PostalInfo . CITY , isBusiness ) ) ; String stateprov = infos . get ( getPostalUserInfoKey ( PostalInfo . STATEPROV , isBusiness ) ) ; String postalCode = infos . get ( getPostalUserInfoKey ( PostalInfo . POSTALCODE , isBusiness ) ) ; String country = infos . get ( getPostalUserInfoKey ( PostalInfo . COUNTRY , isBusiness ) ) ; String organization = infos . get ( getPostalUserInfoKey ( PostalInfo . ORGANIZATION , isBusiness ) ) ; Postal postal = WSRPTypeFactory . createPostal ( name , street , city , stateprov , postalCode , country , organization ) ; TelephoneNum telephone = createTelephoneNumFrom ( infos , TelecomType . TELEPHONE , isBusiness ) ; TelephoneNum fax = createTelephoneNumFrom ( infos , TelecomType . FAX , isBusiness ) ; TelephoneNum mobile = createTelephoneNumFrom ( infos , TelecomType . MOBILE , isBusiness ) ; TelephoneNum pager = createTelephoneNumFrom ( infos , TelecomType . PAGER , isBusiness ) ; Telecom telecom = WSRPTypeFactory . createTelecom ( telephone , fax , mobile , pager ) ; Contact contact = WSRPTypeFactory . createContact ( postal , telecom , online ) ; return contact ; } private static TelephoneNum createTelephoneNumFrom ( Map < String , String > infos , TelecomType type , boolean isBusiness ) { String intCode = infos . get ( getTelecomInfoKey ( type , TelecomInfo . INTCODE , isBusiness ) ) ; String loccode = infos . get ( getTelecomInfoKey ( type , TelecomInfo . LOCCODE , isBusiness ) ) ; String number = infos . get ( getTelecomInfoKey ( type , TelecomInfo . NUMBER , isBusiness ) ) ; String ext = infos . get ( getTelecomInfoKey ( type , TelecomInfo . EXT , isBusiness ) ) ; String comment = infos . get ( getTelecomInfoKey ( type , TelecomInfo . COMMENT , isBusiness ) ) ; TelephoneNum telephoneNum = WSRPTypeFactory . createTelephoneNum ( intCode , loccode , number , ext , comment ) ; return telephoneNum ; } static class WSRPMappedUserContext implements UserContext { private Map < String , String > infos ; private List < String > desiredLocales ; private Locale locale ; private String id ; public WSRPMappedUserContext ( org . oasis . wsrp . v2 . UserContext userContext , List < String > desiredLocales , String preferredLocale ) { this . desiredLocales = desiredLocales ; this . locale = WSRPUtils . getLocale ( preferredLocale ) ; if ( userContext != null ) { UserProfile profile = userContext . getProfile ( ) ; if ( profile != null ) { infos = new HashMap < String , String > ( ) ; XMLGregorianCalendar bdate = profile . getBdate ( ) ; if ( bdate != null ) { infos . put ( INFO_USER_BDATE , bdate . toString ( ) ) ; } infos . put ( INFO_USER_GENDER , profile . getGender ( ) ) ; PersonName name = profile . getName ( ) ; if ( name != null ) { infos . put ( INFO_USER_NAME_FAMILY , name . getFamily ( ) ) ; infos . put ( INFO_USER_NAME_GIVEN , name . getGiven ( ) ) ; infos . put ( INFO_USER_NAME_MIDDLE , name . getMiddle ( ) ) ; infos . put ( INFO_USER_NAME_NICKNAME , name . getNickname ( ) ) ; infos . put ( INFO_USER_NAME_PREFIX , name . getPrefix ( ) ) ; infos . put ( INFO_USER_NAME_SUFFIX , name . getSuffix ( ) ) ; } populateContactInfo ( profile . getBusinessInfo ( ) , true ) ; populateContactInfo ( profile . getHomeInfo ( ) , false ) ; EmployerInfo employerInfo = profile . getEmployerInfo ( ) ; if ( employerInfo != null ) { infos . put ( INFO_USER_DEPARTMENT , employerInfo . getDepartment ( ) ) ; infos . put ( INFO_USER_EMPLOYER , employerInfo . getEmployer ( ) ) ; infos . put ( INFO_USER_JOB_TITLE , employerInfo . getJobtitle ( ) ) ; } } String key = userContext . getUserContextKey ( ) ; if ( key == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } id = key ; } else { infos = Collections . emptyMap ( ) ; } } public String getId ( ) { return id ; } public Map getInformations ( ) { return infos ; } private void populateContactInfo ( Contact contact , boolean isBusiness ) { if ( contact != null ) { Online online = contact . getOnline ( ) ; if ( online != null ) { infos . put ( getOnlineUserInfoKey ( OnlineInfo . EMAIL , isBusiness ) , online . getEmail ( ) ) ; infos . put ( getOnlineUserInfoKey ( OnlineInfo . URI , isBusiness ) , online . getUri ( ) ) ; } Postal postal = contact . getPostal ( ) ; if ( postal != null ) { infos . put ( getPostalUserInfoKey ( PostalInfo . NAME , isBusiness ) , postal . getName ( ) ) ; infos . put ( getPostalUserInfoKey ( PostalInfo . STREET , isBusiness ) , postal . getStreet ( ) ) ; infos . put ( getPostalUserInfoKey ( PostalInfo . CITY , isBusiness ) , postal . getCity ( ) ) ; infos . put ( getPostalUserInfoKey ( PostalInfo . STATEPROV , isBusiness ) , postal . getStateprov ( ) ) ; infos . put ( getPostalUserInfoKey ( PostalInfo . POSTALCODE , isBusiness ) , postal . getPostalcode ( ) ) ; infos . put ( getPostalUserInfoKey ( PostalInfo . COUNTRY , isBusiness ) , postal . getCountry ( ) ) ; infos . put ( getPostalUserInfoKey ( PostalInfo . ORGANIZATION , isBusiness ) , postal . getOrganization ( ) ) ; } Telecom telecom = contact . getTelecom ( ) ; if ( telecom != null ) { populateTelephoneInfo ( telecom . getFax ( ) , TelecomType . FAX , isBusiness ) ; populateTelephoneInfo ( telecom . getMobile ( ) , TelecomType . MOBILE , isBusiness ) ; populateTelephoneInfo ( telecom . getPager ( ) , TelecomType . PAGER , isBusiness ) ; populateTelephoneInfo ( telecom . getTelephone ( ) , TelecomType . TELEPHONE , isBusiness ) ; } } } private void populateTelephoneInfo ( TelephoneNum telephoneNum , TelecomType type , boolean isBusiness ) { if ( telephoneNum != null ) { infos . put ( getTelecomInfoKey ( type , TelecomInfo . INTCODE , isBusiness ) , telephoneNum . getIntcode ( ) ) ; infos . put ( getTelecomInfoKey ( type , TelecomInfo . LOCCODE , isBusiness ) , telephoneNum . getLoccode ( ) ) ; infos . put ( getTelecomInfoKey ( type , TelecomInfo . NUMBER , isBusiness ) , telephoneNum . getNumber ( ) ) ; infos . put ( getTelecomInfoKey ( type , TelecomInfo . EXT , isBusiness ) , telephoneNum . getExt ( ) ) ; infos . put ( getTelecomInfoKey ( type , TelecomInfo . COMMENT , isBusiness ) , telephoneNum . getComment ( ) ) ; } } public Locale getLocale ( ) { return locale ; } public List < Locale > getLocales ( ) { List < Locale > locales = Collections . emptyList ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( desiredLocales ) ) { locales = new ArrayList < Locale > ( desiredLocales . size ( ) ) ; for ( String desiredLocale : desiredLocales ) { Locale locale = WSRPUtils . getLocale ( desiredLocale ) ; locales . add ( locale ) ; } } return locales ; } public Object getAttribute ( String arg0 ) { throw new NotYetImplemented ( ) ; } public void setAttribute ( String arg0 , Object arg1 ) { throw new NotYetImplemented ( ) ; } } } </s>
<s> package org . gatein . wsrp . test ; import junit . framework . Assert ; import java . util . Arrays ; import java . util . List ; public class ExtendedAssert extends Assert { public static void assertEquals ( Object [ ] expected , Object [ ] actual ) { assertEquals ( null , expected , actual ) ; } public static void assertEquals ( String message , Object [ ] expected , Object [ ] actual ) { if ( Arrays . equals ( expected , actual ) ) { return ; } fail ( format ( message , expected , actual ) ) ; } public static void assertEquals ( char [ ] expected , char [ ] actual ) { assertEquals ( null , expected , actual ) ; } public static void assertEquals ( String message , char [ ] expected , char [ ] actual ) { if ( Arrays . equals ( expected , actual ) ) { return ; } fail ( format ( message , expected , actual ) ) ; } public static void assertEquals ( byte [ ] expected , byte [ ] actual ) { assertEquals ( null , expected , actual ) ; } public static void assertEquals ( String message , byte [ ] expected , byte [ ] actual ) { if ( Arrays . equals ( expected , actual ) ) { return ; } fail ( format ( message , toString ( expected ) , toString ( actual ) ) ) ; } private static String toString ( byte [ ] expected ) { StringBuffer expectedBuffer = new StringBuffer ( "<STR_LIT:[>" ) ; for ( byte expectedByte : expected ) { expectedBuffer . append ( expectedByte ) . append ( '<CHAR_LIT:U+002C>' ) ; } if ( expectedBuffer . length ( ) == <NUM_LIT:1> ) { expectedBuffer . append ( '<CHAR_LIT:]>' ) ; } else { expectedBuffer . setCharAt ( expectedBuffer . length ( ) , '<CHAR_LIT:]>' ) ; } return expectedBuffer . toString ( ) ; } public static String format ( String message , Object expected , Object actual ) { String formatted = "<STR_LIT>" ; if ( message != null ) { formatted = message + "<STR_LIT:U+0020>" ; } return formatted + "<STR_LIT>" + format ( expected ) + "<STR_LIT>" + format ( actual ) + "<STR_LIT:>>" ; } private static String format ( Object o ) { if ( o instanceof Object [ ] ) { Object [ ] array = ( Object [ ] ) o ; StringBuffer buffer = new StringBuffer ( "<STR_LIT:[>" ) ; for ( int i = <NUM_LIT:0> ; i < array . length ; i ++ ) { buffer . append ( i == <NUM_LIT:0> ? "<STR_LIT>" : "<STR_LIT:U+002C>" ) . append ( String . valueOf ( array [ i ] ) ) ; } buffer . append ( "<STR_LIT:]>" ) ; return buffer . toString ( ) ; } else { return String . valueOf ( o ) ; } } public static void assertEquals ( Object [ ] expected , Object [ ] tested , boolean isOrderRelevant , String failMessage ) { if ( isOrderRelevant ) { if ( ! Arrays . equals ( expected , tested ) ) { fail ( failMessage ) ; } } else { boolean equals = ( expected == tested ) ; if ( ! equals ) { if ( expected == null || tested == null ) { fail ( failMessage + "<STR_LIT>" ) ; } if ( expected . getClass ( ) . getComponentType ( ) != tested . getClass ( ) . getComponentType ( ) ) { fail ( failMessage + "<STR_LIT>" ) ; } if ( expected . length != tested . length ) { fail ( failMessage + "<STR_LIT>" + tested . length + "<STR_LIT>" + expected . length + "<STR_LIT>" ) ; } List expectedList = Arrays . asList ( expected ) ; List testedList = Arrays . asList ( tested ) ; if ( ! expectedList . containsAll ( testedList ) ) { fail ( failMessage ) ; } } } } public static void assertEquals ( Object [ ] expected , Object [ ] tested , boolean isOrderRelevant , String failMessage , Decorator decorator ) { Object [ ] decoratedExpected = null , decoratedTested = null ; if ( decorator != null ) { decoratedExpected = decorate ( expected , decorator ) ; decoratedTested = decorate ( tested , decorator ) ; } assertEquals ( decoratedExpected , decoratedTested , isOrderRelevant , failMessage ) ; } public static Object [ ] decorate ( Object [ ] toBeDecorated , Decorator decorator ) { if ( toBeDecorated != null ) { DecoratedObject [ ] decorated = new DecoratedObject [ toBeDecorated . length ] ; for ( int i = <NUM_LIT:0> ; i < decorated . length ; i ++ ) { decorated [ i ] = new DecoratedObject ( toBeDecorated [ i ] , decorator ) ; } return decorated ; } return null ; } public static void assertString1ContainsString2 ( String string1 , String string2 ) { assertTrue ( "<STR_LIT:<>" + string1 + "<STR_LIT>" + string2 + "<STR_LIT:>>" , string1 . indexOf ( string2 ) >= <NUM_LIT:0> ) ; } public static interface Decorator { void decorate ( Object decorated ) ; } public static class DecoratedObject { private Decorator decorator ; private Object decorated ; public Object getDecorated ( ) { return decorated ; } public DecoratedObject ( Object decorated , Decorator decorator ) { this . decorator = decorator ; this . decorated = decorated ; } public boolean equals ( Object obj ) { decorator . decorate ( decorated ) ; return decorator . equals ( obj ) ; } public String toString ( ) { decorator . decorate ( decorated ) ; return decorator . toString ( ) ; } } } </s>
<s> package org . gatein . wsrp . test . support ; import org . gatein . common . util . Tools ; import javax . servlet . http . HttpSession ; import java . io . Serializable ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; import java . util . HashMap ; import java . util . Map ; public class MockHttpSession implements InvocationHandler , Serializable { private final Map map = new HashMap ( ) ; private MockHttpSession ( ) { } public static HttpSession createMockSession ( ) { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; return ( HttpSession ) Proxy . newProxyInstance ( loader , new Class [ ] { HttpSession . class } , new MockHttpSession ( ) ) ; } public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { String methodName = method . getName ( ) ; if ( "<STR_LIT>" . equals ( methodName ) ) { map . put ( args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] ) ; return null ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { map . remove ( args [ <NUM_LIT:0> ] ) ; return null ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { return map . get ( args [ <NUM_LIT:0> ] ) ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { return Tools . toEnumeration ( map . keySet ( ) . iterator ( ) ) ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } else { throw new UnsupportedOperationException ( "<STR_LIT>" + method ) ; } } } </s>
<s> package org . gatein . wsrp . test . support ; import javax . servlet . http . HttpServletResponse ; import java . io . Serializable ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; public class MockHttpServletResponse implements InvocationHandler , Serializable { Object cookie ; private MockHttpServletResponse ( ) { } public static HttpServletResponse createMockResponse ( ) { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; return ( HttpServletResponse ) Proxy . newProxyInstance ( loader , new Class [ ] { HttpServletResponse . class } , new MockHttpServletResponse ( ) ) ; } public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { String methodName = method . getName ( ) ; if ( "<STR_LIT>" . equals ( methodName ) ) { cookie = args [ <NUM_LIT:0> ] ; return null ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { cookie = null ; return null ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } throw new UnsupportedOperationException ( "<STR_LIT>" + method ) ; } } </s>
<s> package org . gatein . wsrp . test . support ; import javax . servlet . http . Cookie ; import javax . servlet . http . HttpServletRequest ; import javax . servlet . http . HttpSession ; import java . io . Serializable ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . Map ; public class MockHttpServletRequest implements InvocationHandler , Serializable { private HttpSession session ; private Map attrs ; public static String scheme = "<STR_LIT:http>" ; public static String serverName = "<STR_LIT:localhost>" ; public static Integer serverPort = <NUM_LIT> ; private MockHttpServletRequest ( HttpSession session ) { this . session = session ; this . attrs = new HashMap ( ) ; } public static HttpServletRequest createMockRequest ( HttpSession session ) { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( session == null ) { session = MockHttpSession . createMockSession ( ) ; } return ( HttpServletRequest ) Proxy . newProxyInstance ( loader , new Class [ ] { HttpServletRequest . class } , new MockHttpServletRequest ( session ) ) ; } public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { String methodName = method . getName ( ) ; if ( "<STR_LIT>" . equals ( methodName ) ) { return session ; } if ( "<STR_LIT>" . equals ( methodName ) ) { if ( "<STR_LIT>" . equals ( args [ <NUM_LIT:0> ] ) ) { return "<STR_LIT>" ; } return null ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return attrs . get ( args [ <NUM_LIT:0> ] ) ; } if ( "<STR_LIT>" . equals ( methodName ) ) { String name = ( String ) args [ <NUM_LIT:0> ] ; Object value = args [ <NUM_LIT:1> ] ; if ( value != null ) { attrs . put ( name , value ) ; } else { attrs . remove ( value ) ; } return null ; } if ( "<STR_LIT>" . equals ( methodName ) ) { String name = ( String ) args [ <NUM_LIT:0> ] ; attrs . remove ( name ) ; return null ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return scheme ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return serverName ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return serverPort ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return new Enumeration < String > ( ) { public boolean hasMoreElements ( ) { return false ; } public String nextElement ( ) { return null ; } } ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return new Cookie [ <NUM_LIT:0> ] ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT:GET>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT:/>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT:/>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return "<STR_LIT:/>" ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return null ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return false ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return null ; } if ( "<STR_LIT>" . equals ( methodName ) ) { return null ; } throw new UnsupportedOperationException ( "<STR_LIT>" + method ) ; } } </s>
<s> package org . gatein . wsrp . test . handler ; import javax . xml . ws . BindingProvider ; import javax . xml . ws . handler . MessageContext ; import javax . xml . ws . handler . soap . SOAPMessageContext ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; public class MockSOAPMessageContext implements InvocationHandler { MockSOAPMessage message ; Map < String , List < String > > httpHeaders = new HashMap < String , List < String > > ( ) ; public MockSOAPMessageContext ( MockSOAPMessage message ) { this . message = message ; } public MockSOAPMessage getMessage ( ) { return message ; } public void setMessage ( MockSOAPMessage message ) { this . message = message ; } public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { String methodName = method . getName ( ) ; if ( "<STR_LIT>" . equals ( methodName ) ) { return getMessage ( ) ; } else if ( "<STR_LIT:get>" . equals ( methodName ) ) { if ( BindingProvider . ENDPOINT_ADDRESS_PROPERTY . equals ( args [ <NUM_LIT:0> ] ) ) { return "<STR_LIT>" ; } if ( MessageContext . HTTP_REQUEST_HEADERS . equals ( args [ <NUM_LIT:0> ] ) ) { return httpHeaders ; } throw new IllegalArgumentException ( "<STR_LIT>" + BindingProvider . ENDPOINT_ADDRESS_PROPERTY + "<STR_LIT>" + MessageContext . HTTP_REQUEST_HEADERS + "<STR_LIT>" + args [ <NUM_LIT:0> ] ) ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { if ( MessageContext . HTTP_REQUEST_HEADERS . equals ( args [ <NUM_LIT:0> ] ) ) { httpHeaders = ( Map < String , List < String > > ) args [ <NUM_LIT:1> ] ; return null ; } throw new IllegalArgumentException ( "<STR_LIT>" + args [ <NUM_LIT:0> ] + "<STR_LIT>" + args [ <NUM_LIT:1> ] ) ; } else if ( "<STR_LIT>" . equals ( methodName ) ) { return this . toString ( ) ; } throw new UnsupportedOperationException ( "<STR_LIT>" + methodName + "<STR_LIT>" ) ; } public static SOAPMessageContext createMessageContext ( MockSOAPMessage message , ClassLoader classLoader ) { return ( SOAPMessageContext ) Proxy . newProxyInstance ( classLoader , new Class [ ] { SOAPMessageContext . class } , new MockSOAPMessageContext ( message ) ) ; } } </s>
<s> package org . gatein . wsrp . test . handler ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . xml . sax . SAXException ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import javax . xml . soap . SOAPBody ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; public class MockSOAPBody implements InvocationHandler { Element body ; private static DocumentBuilder BUILDER ; static { DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setValidating ( false ) ; factory . setNamespaceAware ( true ) ; try { BUILDER = factory . newDocumentBuilder ( ) ; } catch ( ParserConfigurationException e ) { BUILDER = null ; } } public MockSOAPBody ( Element body ) { this . body = body ; } public static SOAPBody newInstance ( String body ) throws IOException { return ( SOAPBody ) Proxy . newProxyInstance ( MockSOAPBody . class . getClassLoader ( ) , new Class [ ] { SOAPBody . class } , new MockSOAPBody ( parse ( body ) ) ) ; } public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { return method . invoke ( body , args ) ; } private static Element parse ( String elementAsString ) throws IOException { try { Document doc = BUILDER . parse ( new ByteArrayInputStream ( elementAsString . getBytes ( "<STR_LIT:UTF-8>" ) ) ) ; return doc . getDocumentElement ( ) ; } catch ( SAXException e ) { throw new IOException ( e . toString ( ) ) ; } } } </s>
<s> package org . gatein . wsrp . test . handler ; import javax . xml . soap . AttachmentPart ; import javax . xml . soap . MimeHeaders ; import javax . xml . soap . SOAPBody ; import javax . xml . soap . SOAPElement ; import javax . xml . soap . SOAPException ; import javax . xml . soap . SOAPMessage ; import javax . xml . soap . SOAPPart ; import java . io . IOException ; import java . io . OutputStream ; import java . util . Iterator ; public class MockSOAPMessage extends SOAPMessage { MimeHeaders headers ; String messageBody ; public MockSOAPMessage ( ) { headers = new MimeHeaders ( ) ; } public MockSOAPMessage ( MimeHeaders headers ) { this . headers = headers ; } public void setMessageBody ( String messageBody ) { this . messageBody = messageBody ; } @ Override public SOAPBody getSOAPBody ( ) throws SOAPException { try { return MockSOAPBody . newInstance ( messageBody ) ; } catch ( IOException e ) { throw new SOAPException ( e ) ; } } public MimeHeaders getMimeHeaders ( ) { return headers ; } public void setMimeHeaders ( MimeHeaders mimeHeaders ) { this . headers = mimeHeaders ; } public void addAttachmentPart ( AttachmentPart attachmentPart ) { throw new UnsupportedOperationException ( ) ; } public AttachmentPart createAttachmentPart ( ) { throw new UnsupportedOperationException ( ) ; } public String getContentDescription ( ) { throw new UnsupportedOperationException ( ) ; } public void setContentDescription ( String string ) { throw new UnsupportedOperationException ( ) ; } public SOAPPart getSOAPPart ( ) { throw new UnsupportedOperationException ( ) ; } public void removeAllAttachments ( ) { throw new UnsupportedOperationException ( ) ; } public int countAttachments ( ) { throw new UnsupportedOperationException ( ) ; } public Iterator getAttachments ( ) { throw new UnsupportedOperationException ( ) ; } public AttachmentPart getAttachment ( SOAPElement element ) { throw new UnsupportedOperationException ( ) ; } public Iterator getAttachments ( MimeHeaders mimeHeaders ) { throw new UnsupportedOperationException ( ) ; } public void saveChanges ( ) throws SOAPException { throw new UnsupportedOperationException ( ) ; } public boolean saveRequired ( ) { throw new UnsupportedOperationException ( ) ; } public void writeTo ( OutputStream outputStream ) throws SOAPException , IOException { throw new UnsupportedOperationException ( ) ; } public void removeAttachments ( MimeHeaders mimeHeaders ) { throw new UnsupportedOperationException ( ) ; } } </s>
<s> package org . gatein . wsrp . examples ; import org . gatein . registration . InvalidConsumerDataException ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import javax . xml . namespace . QName ; import java . util . Map ; public class ExampleRegistrationPolicy extends DefaultRegistrationPolicy { @ Override public String getConsumerIdFrom ( String consumerName , Map < QName , Object > registrationProperties ) throws IllegalArgumentException , InvalidConsumerDataException { return consumerName . toLowerCase ( ) ; } } </s>
<s> package org . gatein . wsrp . examples ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; public class DOMUtils { static Element createElement ( String namespaceURI , String name ) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory . newInstance ( ) ; builderFactory . setNamespaceAware ( true ) ; try { final DocumentBuilder builder = builderFactory . newDocumentBuilder ( ) ; final Document document = builder . newDocument ( ) ; return document . createElementNS ( namespaceURI , name ) ; } catch ( ParserConfigurationException e ) { throw new RuntimeException ( "<STR_LIT>" , e ) ; } } static Node addChild ( Node parent , String namespaceURI , String childName ) { final Element child = parent . getOwnerDocument ( ) . createElementNS ( namespaceURI , childName ) ; return parent . appendChild ( child ) ; } } </s>
<s> package org . gatein . wsrp . examples ; import org . gatein . common . logging . Logger ; import org . gatein . common . logging . LoggerFactory ; import org . gatein . pc . api . invocation . PortletInvocation ; import org . gatein . pc . api . invocation . RenderInvocation ; import org . gatein . pc . api . invocation . response . ContentResponse ; import org . gatein . pc . api . invocation . response . PortletInvocationResponse ; import org . gatein . wsrp . api . extensions . ConsumerExtensionAccessor ; import org . gatein . wsrp . api . extensions . ExtensionAccess ; import org . gatein . wsrp . api . extensions . InvocationHandlerDelegate ; import org . gatein . wsrp . api . extensions . UnmarshalledExtension ; import org . oasis . wsrp . v2 . MarkupParams ; import org . oasis . wsrp . v2 . MarkupResponse ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import java . util . List ; public class ExampleConsumerInvocationHandlerDelegate extends InvocationHandlerDelegate { private final static Logger log = LoggerFactory . getLogger ( InvocationHandlerDelegate . class ) ; @ Override public void processInvocation ( PortletInvocation invocation ) { if ( invocation instanceof RenderInvocation ) { final String id = invocation . getRequest ( ) . getSession ( ) . getId ( ) ; log . info ( "<STR_LIT>" + id ) ; final String namespaceURI = "<STR_LIT>" ; final Element markupParamsExtension = DOMUtils . createElement ( namespaceURI , "<STR_LIT>" ) ; final Node originalSessionId = DOMUtils . addChild ( markupParamsExtension , namespaceURI , "<STR_LIT>" ) ; originalSessionId . setTextContent ( id ) ; final ConsumerExtensionAccessor consumerExtensionAccessor = ExtensionAccess . getConsumerExtensionAccessor ( ) ; consumerExtensionAccessor . addRequestExtension ( MarkupParams . class , markupParamsExtension ) ; } } @ Override public void processInvocationResponse ( PortletInvocationResponse response , PortletInvocation invocation ) { if ( response instanceof ContentResponse ) { final List < UnmarshalledExtension > extensions = ExtensionAccess . getConsumerExtensionAccessor ( ) . getResponseExtensionsFrom ( MarkupResponse . class ) ; final UnmarshalledExtension unmarshalledExtension = extensions . get ( <NUM_LIT:0> ) ; if ( unmarshalledExtension . isElement ( ) ) { final Element element = ( Element ) unmarshalledExtension . getValue ( ) ; final String textContent = element . getTextContent ( ) ; log . info ( "<STR_LIT>" + textContent ) ; invocation . getRequest ( ) . getSession ( ) . setAttribute ( "<STR_LIT>" , textContent ) ; } } } } </s>
<s> package org . gatein . wsrp . examples ; import org . gatein . pc . api . invocation . PortletInvocation ; import org . gatein . pc . api . invocation . RenderInvocation ; import org . gatein . pc . api . invocation . response . ContentResponse ; import org . gatein . pc . api . invocation . response . PortletInvocationResponse ; import org . gatein . wsrp . api . extensions . ExtensionAccess ; import org . gatein . wsrp . api . extensions . InvocationHandlerDelegate ; import org . gatein . wsrp . api . extensions . UnmarshalledExtension ; import org . oasis . wsrp . v2 . MarkupParams ; import org . oasis . wsrp . v2 . MarkupResponse ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import java . util . List ; public class ExampleProducerInvocationHandlerDelegate extends InvocationHandlerDelegate { @ Override public void processInvocation ( PortletInvocation invocation ) { if ( invocation instanceof RenderInvocation ) { final List < UnmarshalledExtension > requestExtensions = ExtensionAccess . getProducerExtensionAccessor ( ) . getRequestExtensionsFor ( MarkupParams . class ) ; if ( ! requestExtensions . isEmpty ( ) ) { final UnmarshalledExtension unmarshalledExtension = requestExtensions . get ( <NUM_LIT:0> ) ; if ( unmarshalledExtension . isElement ( ) ) { final Element element = ( Element ) unmarshalledExtension . getValue ( ) ; final String textContent = element . getTextContent ( ) ; invocation . getRequest ( ) . getSession ( ) . setAttribute ( "<STR_LIT>" , textContent ) ; } } } } @ Override public void processInvocationResponse ( PortletInvocationResponse response , PortletInvocation invocation ) { if ( response instanceof ContentResponse ) { final Object consumerSaid = invocation . getRequest ( ) . getSession ( ) . getAttribute ( "<STR_LIT>" ) ; final String namespaceURI = "<STR_LIT>" ; final Element markupResponseExtension = DOMUtils . createElement ( namespaceURI , "<STR_LIT>" ) ; final Node originalSessionId = DOMUtils . addChild ( markupResponseExtension , namespaceURI , "<STR_LIT>" ) ; originalSessionId . setTextContent ( "<STR_LIT>" + consumerSaid ) ; ExtensionAccess . getProducerExtensionAccessor ( ) . addResponseExtension ( MarkupResponse . class , markupResponseExtension ) ; } } } </s>
<s> package org . gatein . wsrp . examples ; import org . apache . ws . security . WSPasswordCallback ; import org . gatein . wsrp . wss . cxf . consumer . CurrentUserPasswordCallback ; import javax . security . auth . callback . Callback ; import javax . security . auth . callback . CallbackHandler ; import javax . security . auth . callback . UnsupportedCallbackException ; import java . io . IOException ; public class TestCallbackHandler implements CallbackHandler { @ Override public void handle ( Callback [ ] callbacks ) throws IOException , UnsupportedCallbackException { CurrentUserPasswordCallback currentUserPasswordCallback = new CurrentUserPasswordCallback ( ) ; currentUserPasswordCallback . handle ( callbacks ) ; for ( Callback callback : callbacks ) { if ( callback instanceof WSPasswordCallback ) { WSPasswordCallback wsPWCallback = ( WSPasswordCallback ) callback ; if ( wsPWCallback . getUsage ( ) != WSPasswordCallback . USERNAME_TOKEN ) { wsPWCallback . setPassword ( "<STR_LIT>" ) ; } } } } } </s>
<s> package org . gatein . wsrp . consumer . registry . hibernate ; import org . gatein . wsrp . consumer . ConsumerException ; import org . gatein . wsrp . consumer . ProducerInfo ; import org . gatein . wsrp . consumer . registry . AbstractConsumerRegistry ; import org . hibernate . HibernateException ; import org . hibernate . Session ; import org . hibernate . SessionFactory ; import javax . naming . InitialContext ; import java . util . Collection ; import java . util . Iterator ; public class HibernateConsumerRegistry extends AbstractConsumerRegistry { private SessionFactory sessionFactory ; private String sessionFactoryJNDIName ; public void save ( ProducerInfo info , String messageOnError ) { try { Session session = sessionFactory . getCurrentSession ( ) ; session . persist ( info ) ; } catch ( HibernateException e ) { throw new ConsumerException ( messageOnError , e ) ; } } public void delete ( ProducerInfo info ) { Session session = sessionFactory . getCurrentSession ( ) ; session . delete ( info ) ; } public String getSessionFactoryJNDIName ( ) { return sessionFactoryJNDIName ; } public void setSessionFactoryJNDIName ( String sessionFactoryJNDIName ) { this . sessionFactoryJNDIName = sessionFactoryJNDIName ; } public String update ( ProducerInfo producerInfo ) { String oldId ; Session session = sessionFactory . getCurrentSession ( ) ; try { oldId = ( String ) session . createQuery ( "<STR_LIT>" ) . setParameter ( "<STR_LIT:key>" , producerInfo . getKey ( ) ) . uniqueResult ( ) ; if ( producerInfo . getId ( ) . equals ( oldId ) ) { oldId = null ; } session . update ( producerInfo ) ; } catch ( HibernateException e ) { throw new ConsumerException ( "<STR_LIT>" + producerInfo . getId ( ) + "<STR_LIT:'>" , e ) ; } return oldId ; } public Iterator < ProducerInfo > getProducerInfosFromStorage ( ) { Session session = sessionFactory . getCurrentSession ( ) ; return session . createQuery ( "<STR_LIT>" ) . iterate ( ) ; } public ProducerInfo loadProducerInfo ( String id ) { Session session = sessionFactory . getCurrentSession ( ) ; return ( ProducerInfo ) session . createQuery ( "<STR_LIT>" ) . setParameter ( "<STR_LIT:id>" , id ) . uniqueResult ( ) ; } @ Override public void start ( ) throws Exception { InitialContext initialContext = new InitialContext ( ) ; sessionFactory = ( SessionFactory ) initialContext . lookup ( sessionFactoryJNDIName ) ; super . start ( ) ; } @ Override public void stop ( ) throws Exception { sessionFactory = null ; super . stop ( ) ; } public Collection < String > getConfiguredConsumersIds ( ) { throw new UnsupportedOperationException ( ) ; } @ Override protected void initConsumerCache ( ) { setConsumerCache ( new InMemoryConsumerCache ( this ) ) ; } } </s>
<s> package org . gatein . wsrp . consumer ; import org . hibernate . event . PostLoadEvent ; import org . hibernate . event . def . DefaultPostLoadEventListener ; public class RegistrationInfoPostLoadEventListener extends DefaultPostLoadEventListener { public void onPostLoad ( PostLoadEvent event ) { Object entity = event . getEntity ( ) ; if ( entity instanceof RegistrationInfo ) { RegistrationInfo info = ( RegistrationInfo ) entity ; for ( RegistrationProperty property : info . getRegistrationProperties ( ) . values ( ) ) { property . setListener ( info ) ; } } super . onPostLoad ( event ) ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import junit . framework . TestCase ; import java . util . Locale ; import java . util . Map ; public class BeanContextTestCase extends TestCase { public void testDefaultMessageFormatting ( ) { assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT:foo>" , Locale . getDefault ( ) ) ) ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT:foo>" , Locale . getDefault ( ) , BeanContext . DEFAULT_RESOURCE_NAME , "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT>" , Locale . getDefault ( ) , BeanContext . DEFAULT_RESOURCE_NAME , "<STR_LIT:foo>" ) ) ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT>" , Locale . getDefault ( ) , BeanContext . DEFAULT_RESOURCE_NAME , "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) ; } public void testMessageFormatting ( ) { String resourceName = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT:foo>" , Locale . getDefault ( ) , resourceName ) ) ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT:foo>" , Locale . getDefault ( ) , resourceName , "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT>" , Locale . getDefault ( ) , resourceName , "<STR_LIT:foo>" ) ) ; assertEquals ( "<STR_LIT>" , BeanContext . getLocalizedMessage ( "<STR_LIT>" , Locale . getDefault ( ) , resourceName , "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) ; } public void testErrorMessage ( ) { TestBeanContext context = new TestBeanContext ( ) ; context . createErrorMessage ( "<STR_LIT>" , "<STR_LIT:error>" ) ; assertEquals ( "<STR_LIT>" , context . getMessage ( ) ) ; assertEquals ( TestBeanContext . ERROR , context . getSeverity ( ) ) ; } private static class TestBeanContext extends BeanContext { private static final String ERROR = "<STR_LIT>" ; private static final String INFO = "<STR_LIT>" ; private String message ; private Object severity ; private Object [ ] params ; public String getMessage ( ) { return message ; } public Object getSeverity ( ) { return severity ; } public Object [ ] getParams ( ) { return params ; } @ Override public String getParameter ( String key ) { throw new UnsupportedOperationException ( ) ; } @ Override protected void createMessage ( String target , String message , Object severity , Object ... additionalParams ) { this . message = message ; this . severity = severity ; this . params = additionalParams ; } @ Override protected Object getErrorSeverity ( ) { return ERROR ; } @ Override protected Object getInfoSeverity ( ) { return INFO ; } @ Override protected Locale getLocale ( ) { return Locale . getDefault ( ) ; } @ Override public String getServerAddress ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public Map < String , Object > getSessionMap ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public < T > T findBean ( String name , Class < T > type ) { throw new UnsupportedOperationException ( ) ; } } } </s>
<s> package org . gatein . wsrp . admin . ui ; import junit . framework . TestCase ; import org . gatein . common . NotYetImplemented ; import org . gatein . wsrp . WSRPConsumer ; import org . gatein . wsrp . consumer . registry . ConsumerRegistry ; import org . gatein . wsrp . consumer . registry . InMemoryConsumerRegistry ; import org . gatein . wsrp . services . SOAPServiceFactory ; import org . gatein . wsrp . test . protocol . v2 . BehaviorBackedServiceFactory ; import org . gatein . wsrp . test . support . MockEndpointConfigurationInfo ; import javax . faces . model . DataModel ; import java . util . Collections ; import java . util . Locale ; import java . util . Map ; public class ConsumerBeanTestCase extends TestCase { private static final String CONSUMER_ID = "<STR_LIT:foo>" ; private static final String WSDL = BehaviorBackedServiceFactory . DEFAULT_WSDL_URL ; private ConsumerBean bean ; protected void setUp ( ) throws Exception { bean = new ConsumerBean ( ) ; ConsumerRegistry registry = new TestInMemoryConsumerRegistry ( ) ; registry . createConsumer ( CONSUMER_ID , null , WSDL ) ; ConsumerManagerBean managerBean = new ConsumerManagerBean ( ) ; managerBean . setRegistry ( registry ) ; bean . setManager ( managerBean ) ; bean . setBeanContext ( new TestBeanContext ( ) ) ; bean . setId ( CONSUMER_ID ) ; } public void testInitialState ( ) { assertEquals ( CONSUMER_ID , bean . getId ( ) ) ; assertEquals ( bean . getProducerInfo ( ) . getId ( ) , bean . getId ( ) ) ; assertEquals ( WSDL , bean . getWsdl ( ) ) ; assertEquals ( SOAPServiceFactory . DEFAULT_TIMEOUT_MS , bean . getTimeout ( ) . intValue ( ) ) ; assertFalse ( bean . isModified ( ) ) ; assertTrue ( bean . isRefreshNeeded ( ) ) ; assertFalse ( bean . isActive ( ) ) ; assertFalse ( bean . isRegistrationChecked ( ) ) ; assertTrue ( bean . isRegistrationCheckNeeded ( ) ) ; assertFalse ( bean . isRegistered ( ) ) ; assertFalse ( bean . isRegistrationLocallyModified ( ) ) ; assertFalse ( bean . isRegistrationPropertiesExisting ( ) ) ; assertNull ( bean . getCurrentExport ( ) ) ; DataModel existingExports = bean . getExistingExports ( ) ; assertNotNull ( existingExports ) ; assertEquals ( <NUM_LIT:0> , existingExports . getRowCount ( ) ) ; try { assertFalse ( bean . isRegistrationRequired ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalStateException e ) { } try { assertFalse ( bean . isRegistrationValid ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception e ) { } } public void testSetId ( ) { String newId = "<STR_LIT>" ; bean . setId ( newId ) ; assertEquals ( newId , bean . getId ( ) ) ; assertTrue ( bean . isModified ( ) ) ; } public void testSetCache ( ) { bean . setCache ( <NUM_LIT> ) ; assertEquals ( <NUM_LIT> , bean . getCache ( ) . intValue ( ) ) ; assertTrue ( bean . isModified ( ) ) ; } private static class TestBeanContext extends BeanContext { public String getParameter ( String key ) { return null ; } protected void createMessage ( String target , String message , Object severity , Object ... addtionalParams ) { } protected Object getErrorSeverity ( ) { return null ; } protected Object getInfoSeverity ( ) { return null ; } protected Locale getLocale ( ) { return Locale . getDefault ( ) ; } public String getServerAddress ( ) { throw new NotYetImplemented ( ) ; } public Map < String , Object > getSessionMap ( ) { return Collections . emptyMap ( ) ; } @ Override public < T > T findBean ( String name , Class < T > type ) { throw new NotYetImplemented ( ) ; } } private static class TestInMemoryConsumerRegistry extends InMemoryConsumerRegistry { @ Override public WSRPConsumer createConsumer ( String id , Integer expirationCacheSeconds , String wsdlURL ) { WSRPConsumer consumer = super . createConsumer ( id , expirationCacheSeconds , wsdlURL ) ; consumer . getProducerInfo ( ) . setEndpointConfigurationInfo ( new MockEndpointConfigurationInfo ( ) ) ; return consumer ; } } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . common . util . ParameterValidation ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import java . io . Serializable ; import java . text . MessageFormat ; import java . util . Locale ; import java . util . Map ; import java . util . MissingResourceException ; import java . util . ResourceBundle ; public abstract class BeanContext implements Serializable { protected final static Logger log = LoggerFactory . getLogger ( BeanContext . class ) ; public static final String STATUS = "<STR_LIT:status>" ; static final String DEFAULT_RESOURCE_NAME = "<STR_LIT>" ; private static final String UNEXPECTED_ERROR = "<STR_LIT>" ; private static final String CAUSE = "<STR_LIT>" ; private static final String CURRENT_PLACEHOLDER = "<STR_LIT>" ; private String resourceName = DEFAULT_RESOURCE_NAME ; public void setResourceName ( String resourceName ) { this . resourceName = resourceName ; } public String getResourceName ( ) { return resourceName ; } public abstract String getParameter ( String key ) ; protected abstract void createMessage ( String target , String message , Object severity , Object ... additionalParams ) ; protected abstract Object getErrorSeverity ( ) ; protected abstract Object getInfoSeverity ( ) ; protected abstract Locale getLocale ( ) ; public abstract String getServerAddress ( ) ; public void createErrorMessage ( String localizedMessageId , Object ... params ) { createLocalizedMessage ( STATUS , localizedMessageId , getErrorSeverity ( ) , params ) ; } public void createTargetedErrorMessage ( String target , String localizedMessageId , Object ... params ) { createLocalizedMessage ( target , localizedMessageId , getErrorSeverity ( ) , params ) ; } protected void createLocalizedMessage ( String target , String localizedMessageId , Object severity , Object ... params ) { createMessage ( target , getMessageFromBundle ( localizedMessageId , params ) , severity ) ; } public String getMessageFromBundle ( String localizedMessageId , Object ... params ) { return getLocalizedMessage ( localizedMessageId , getLocale ( ) , resourceName , params ) ; } public static String getLocalizedMessage ( String localizationKey , Locale locale , Object ... params ) { return getLocalizedMessage ( localizationKey , locale , DEFAULT_RESOURCE_NAME , params ) ; } public static String getLocalizedMessage ( String localizationKey , Locale locale , String resourceName , Object ... params ) { ResourceBundle rb = ResourceBundle . getBundle ( resourceName , locale ) ; String message ; try { message = rb . getString ( localizationKey ) ; } catch ( MissingResourceException e ) { log . info ( "<STR_LIT>" + localizationKey + "<STR_LIT>" + resourceName + "<STR_LIT>" + locale . getDisplayName ( ) ) ; return localizationKey ; } return MessageFormat . format ( message , params ) ; } public void createErrorMessageFrom ( Exception e ) { createErrorMessageFrom ( STATUS , e ) ; } public void createErrorMessageFrom ( String target , Exception e ) { String localizedMessage = getLocalizedMessageOrExceptionName ( e ) ; createMessage ( target , localizedMessage , getErrorSeverity ( ) , e . getCause ( ) ) ; } private String getLocalizedMessageOrExceptionName ( Throwable e ) { String localizedMessage = e . getLocalizedMessage ( ) ; if ( localizedMessage == null ) { localizedMessage = getMessageFromBundle ( UNEXPECTED_ERROR ) + e . getClass ( ) . getName ( ) ; } return localizedMessage ; } protected void createInfoMessage ( String target , String localizedMessageId ) { createLocalizedMessage ( target , localizedMessageId , getInfoSeverity ( ) ) ; } public void createInfoMessage ( String localizedMessageId ) { createInfoMessage ( STATUS , localizedMessageId ) ; } public void removeFromSession ( String name , String ... otherNames ) { Map < String , Object > sessionMap = getSessionMap ( ) ; sessionMap . remove ( name ) ; if ( otherNames != null ) { for ( String other : otherNames ) { sessionMap . remove ( other ) ; } } } public abstract Map < String , Object > getSessionMap ( ) ; public < T > T replaceInSession ( String name , T newValue ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT:name>" , "<STR_LIT>" ) ; Map < String , Object > sessionMap = getSessionMap ( ) ; if ( newValue == null ) { sessionMap . remove ( name ) ; return null ; } getFromSession ( name , newValue . getClass ( ) , sessionMap , "<STR_LIT>" + newValue + "<STR_LIT>" + name + "<STR_LIT>" + CURRENT_PLACEHOLDER ) ; sessionMap . put ( name , newValue ) ; return newValue ; } public < T > T getFromSession ( String name , Class < T > expectedClass ) { return getFromSession ( name , expectedClass , getSessionMap ( ) , "<STR_LIT>" + CURRENT_PLACEHOLDER + "<STR_LIT>" + expectedClass + "<STR_LIT>" + name + "<STR_LIT:'>" ) ; } private < T > T getFromSession ( String name , Class < T > expectedClass , Map < String , Object > sessionMap , String errorMessage ) { Object result = sessionMap . get ( name ) ; return checkObject ( result , expectedClass , errorMessage ) ; } protected < T > T checkObject ( Object result , Class < T > expectedClass , String errorMessage ) { if ( result != null && ! expectedClass . isAssignableFrom ( result . getClass ( ) ) ) { throw new IllegalArgumentException ( errorMessage . replace ( CURRENT_PLACEHOLDER , result . toString ( ) ) ) ; } return expectedClass . cast ( result ) ; } public abstract < T > T findBean ( String name , Class < T > type ) ; } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . common . util . ParameterValidation ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import javax . faces . context . FacesContext ; import javax . faces . model . SelectItem ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . List ; import java . util . regex . Pattern ; public abstract class WSRPManagedBean implements Serializable { protected transient Logger log = LoggerFactory . getLogger ( getClass ( ) ) ; protected BeanContext beanContext ; private String cancelOutcome ; public static final String INVALID_NAME = "<STR_LIT>" ; public static final String INVALID_PATH = "<STR_LIT>" ; public static final String DUPLICATE = "<STR_LIT>" ; static void bypassAndRedisplay ( ) { FacesContext . getCurrentInstance ( ) . renderResponse ( ) ; } public static interface PropertyValidator extends Serializable { boolean checkForDuplicates ( ) ; String getObjectTypeName ( ) ; boolean isAlreadyExisting ( String propertyName ) ; String doSimpleChecks ( String name ) ; ParameterValidation . ValidationErrorHandler getValidationErrorHandler ( String name , String targetForErrorMessage ) ; Pattern getValidationPattern ( ) ; } private PropertyValidator validator = new DefaultPropertyValidator ( ) ; protected void setValidator ( PropertyValidator validator ) { this . validator = validator ; } public void setBeanContext ( BeanContext beanContext ) { this . beanContext = beanContext ; } public void setCancelOutcome ( String cancelOutcome ) { this . cancelOutcome = cancelOutcome ; } public String checkNameValidity ( String name , String targetForErrorMessage ) { return checkNameValidity ( name , targetForErrorMessage , validator ) ; } public String checkNameValidity ( String name , String targetForErrorMessage , PropertyValidator validator ) { ParameterValidation . throwIllegalArgExceptionIfNull ( validator , "<STR_LIT>" ) ; String objectTypeName = validator . getObjectTypeName ( ) ; if ( ParameterValidation . isNullOrEmpty ( name ) ) { beanContext . createTargetedErrorMessage ( targetForErrorMessage , INVALID_NAME , name , getLocalizedType ( objectTypeName ) ) ; return null ; } else { String original = name ; name = validator . doSimpleChecks ( name ) ; if ( name == null ) { beanContext . createTargetedErrorMessage ( targetForErrorMessage , INVALID_NAME , original , getLocalizedType ( objectTypeName ) ) ; return null ; } name = name . trim ( ) ; name = ParameterValidation . sanitizeFromPatternWithHandler ( name , validator . getValidationPattern ( ) , validator . getValidationErrorHandler ( name , targetForErrorMessage ) ) ; if ( name == null ) { return null ; } if ( validator . checkForDuplicates ( ) && validator . isAlreadyExisting ( name ) ) { getDuplicateErrorMessage ( name , targetForErrorMessage , objectTypeName ) ; return null ; } return name ; } } protected void getDuplicateErrorMessage ( String name , String targetForErrorMessage , String objectTypeName ) { beanContext . createTargetedErrorMessage ( targetForErrorMessage , DUPLICATE , name , getLocalizedType ( objectTypeName ) ) ; } private String getLocalizedType ( String objectTypeName ) { return beanContext . getMessageFromBundle ( objectTypeName ) ; } protected abstract String getObjectTypeName ( ) ; public abstract boolean isAlreadyExisting ( String objectName ) ; public boolean isOldAndNewDifferent ( Object oldValue , Object newValue ) { oldValue = normalizeStringIfNeeded ( oldValue ) ; newValue = normalizeStringIfNeeded ( newValue ) ; return ( oldValue != null && ! oldValue . equals ( newValue ) ) || ( oldValue == null && newValue != null ) ; } public Object normalizeStringIfNeeded ( Object value ) { if ( value == null ) { return null ; } else { if ( value instanceof String ) { String stringValue = ( String ) value ; return stringValue . length ( ) == <NUM_LIT:0> ? null : stringValue . trim ( ) ; } else { return value ; } } } protected class MessageValidationHandler extends ParameterValidation . ValidationErrorHandler { private String targetForErrorMessage ; private String validatedName ; private String objectTypeName ; private String errorMessageKey ; public MessageValidationHandler ( String defaultValue , String targetForErrorMessage , String validatedName , String objectTypeName ) { this ( defaultValue , targetForErrorMessage , validatedName , objectTypeName , INVALID_NAME ) ; } public MessageValidationHandler ( String defaultValue , String targetForErrorMessage , String validatedName , String objectTypeName , String errorMessageKey ) { super ( defaultValue ) ; this . targetForErrorMessage = targetForErrorMessage ; this . validatedName = validatedName ; this . objectTypeName = objectTypeName ; this . errorMessageKey = errorMessageKey ; } protected String internalValidationErrorHandling ( String s ) { beanContext . createTargetedErrorMessage ( targetForErrorMessage , errorMessageKey , validatedName , getLocalizedType ( objectTypeName ) ) ; return null ; } } protected class DefaultPropertyValidator implements PropertyValidator { public boolean checkForDuplicates ( ) { return true ; } public String getObjectTypeName ( ) { return WSRPManagedBean . this . getObjectTypeName ( ) ; } public boolean isAlreadyExisting ( String propertyName ) { return WSRPManagedBean . this . isAlreadyExisting ( propertyName ) ; } public String doSimpleChecks ( String name ) { return ( name . indexOf ( '<CHAR_LIT:.>' ) != - <NUM_LIT:1> || name . indexOf ( '<CHAR_LIT:/>' ) != - <NUM_LIT:1> ) ? null : name ; } public ParameterValidation . ValidationErrorHandler getValidationErrorHandler ( String name , String targetForErrorMessage ) { return new MessageValidationHandler ( null , targetForErrorMessage , name , getObjectTypeName ( ) ) ; } public Pattern getValidationPattern ( ) { return ParameterValidation . XSS_CHECK ; } } public String cancel ( ) { return cancelOutcome ; } protected static List < SelectItem > getSelectItemsFrom ( List < String > identifiers ) { List < SelectItem > result = new ArrayList < SelectItem > ( identifiers . size ( ) ) ; for ( String pageIdentifier : identifiers ) { result . add ( new SelectItem ( pageIdentifier ) ) ; } return result ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . common . net . URLTools ; import org . gatein . common . util . ParameterValidation ; import javax . faces . application . FacesMessage ; import javax . faces . component . UIComponent ; import javax . faces . component . UIViewRoot ; import javax . faces . context . FacesContext ; import javax . portlet . PortletRequest ; import javax . servlet . http . HttpServletRequest ; import java . io . Serializable ; import java . util . Locale ; import java . util . Map ; public class JSFBeanContext extends BeanContext implements Serializable { public String getParameter ( String key ) { return getParameter ( key , FacesContext . getCurrentInstance ( ) ) ; } public static String getParameter ( String key , FacesContext facesContext ) { Map pmap = facesContext . getExternalContext ( ) . getRequestParameterMap ( ) ; return ( String ) pmap . get ( key ) ; } public Map < String , Object > getSessionMap ( ) { return JSFBeanContext . getSessionMap ( FacesContext . getCurrentInstance ( ) ) ; } @ Override public < T > T findBean ( String name , Class < T > type ) { final FacesContext facesContext = FacesContext . getCurrentInstance ( ) ; final Map < String , Object > applicationMap = facesContext . getExternalContext ( ) . getApplicationMap ( ) ; Object candidate = applicationMap . get ( name ) ; if ( candidate == null ) { candidate = getFromSession ( name , type ) ; if ( candidate == null ) { candidate = facesContext . getApplication ( ) . evaluateExpressionGet ( facesContext , "<STR_LIT>" + name + "<STR_LIT:}>" , type ) ; } } if ( candidate != null ) { return checkObject ( candidate , type , "<STR_LIT>" + name + "<STR_LIT>" + type . getSimpleName ( ) + "<STR_LIT:'>" ) ; } else { return null ; } } public static Map < String , Object > getSessionMap ( FacesContext facesContext ) { return facesContext . getExternalContext ( ) . getSessionMap ( ) ; } protected void createMessage ( String target , String message , Object severity , Object ... additionalParams ) { outputMessage ( target , message , severity , additionalParams ) ; } public static void outputMessage ( String target , String message , Object severity , Object ... additionalParams ) { if ( ParameterValidation . isNullOrEmpty ( target ) ) { target = STATUS ; } FacesMessage . Severity jsfSeverity ; if ( severity instanceof FacesMessage . Severity ) { jsfSeverity = ( FacesMessage . Severity ) severity ; } else { jsfSeverity = FacesMessage . SEVERITY_ERROR ; } FacesContext facesContext = FacesContext . getCurrentInstance ( ) ; UIViewRoot viewRoot = facesContext . getViewRoot ( ) ; UIComponent component = viewRoot . findComponent ( target ) ; if ( component != null ) { target = component . getClientId ( facesContext ) ; } else { log . info ( "<STR_LIT>" + target ) ; } String details = "<STR_LIT>" ; if ( additionalParams != null && additionalParams . length > <NUM_LIT:0> ) { Exception exception = ( Exception ) additionalParams [ <NUM_LIT:0> ] ; if ( exception != null ) { details = exception . getLocalizedMessage ( ) ; } } FacesMessage msg = new FacesMessage ( jsfSeverity , message , details ) ; facesContext . addMessage ( target , msg ) ; } public static void outputLocalizedMessage ( String target , String localizationKey , Object severity , String resourceName , Object ... params ) { if ( severity == null ) { severity = FacesMessage . SEVERITY_ERROR ; } outputMessage ( target , getLocalizedMessage ( localizationKey , getRequestLocale ( ) , resourceName , params ) , severity ) ; } protected Object getErrorSeverity ( ) { return FacesMessage . SEVERITY_ERROR ; } protected Object getInfoSeverity ( ) { return FacesMessage . SEVERITY_INFO ; } protected Locale getLocale ( ) { return getRequestLocale ( ) ; } public String getServerAddress ( ) { Object request = FacesContext . getCurrentInstance ( ) . getExternalContext ( ) . getRequest ( ) ; String serverAddress ; if ( request instanceof PortletRequest ) { PortletRequest portletRequest = ( PortletRequest ) request ; String scheme = portletRequest . getScheme ( ) ; String host = portletRequest . getServerName ( ) ; int port = portletRequest . getServerPort ( ) ; return scheme + URLTools . SCH_END + host + URLTools . PORT_END + port ; } else { serverAddress = URLTools . getServerAddressFrom ( ( HttpServletRequest ) request ) ; } return serverAddress ; } public static Locale getRequestLocale ( ) { return FacesContext . getCurrentInstance ( ) . getExternalContext ( ) . getRequestLocale ( ) ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . wsrp . registration . LocalizedString ; import javax . faces . component . UIComponent ; import javax . faces . context . FacesContext ; import javax . faces . convert . Converter ; public class LocalizedStringConverter implements Converter { public Object getAsObject ( FacesContext facesContext , UIComponent uiComponent , String s ) { return ( s == null || s . length ( ) == <NUM_LIT:0> ) ? null : new LocalizedString ( s ) ; } public String getAsString ( FacesContext facesContext , UIComponent uiComponent , Object o ) { return getAsString ( o ) ; } static String getAsString ( Object localizedString ) { return localizedString == null ? null : ( ( LocalizedString ) localizedString ) . getValue ( ) ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import javax . faces . context . FacesContext ; import java . util . Collection ; import java . util . Collections ; import java . util . Map ; import java . util . Set ; public class ResourceBean implements Map < String , String > { public void clear ( ) { } public boolean containsKey ( Object key ) { return true ; } public boolean containsValue ( Object value ) { return true ; } public Set < Entry < String , String > > entrySet ( ) { return Collections . emptySet ( ) ; } public String get ( Object key ) { FacesContext facesContext = FacesContext . getCurrentInstance ( ) ; String url = null ; if ( null == key ) { url = null ; } else if ( null != facesContext ) { url = facesContext . getApplication ( ) . getViewHandler ( ) . getResourceURL ( facesContext , key . toString ( ) ) ; url = facesContext . getExternalContext ( ) . encodeResourceURL ( url ) ; } else { url = key . toString ( ) ; } return url ; } public boolean isEmpty ( ) { return false ; } public Set < String > keySet ( ) { return Collections . emptySet ( ) ; } public String put ( String key , String value ) { return null ; } public void putAll ( Map < ? extends String , ? extends String > t ) { } public String remove ( Object key ) { return null ; } public int size ( ) { return <NUM_LIT:0> ; } public Collection < String > values ( ) { return Collections . emptySet ( ) ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . common . util . ParameterValidation ; import org . gatein . wsrp . WSRPConsumer ; import org . gatein . wsrp . consumer . ProducerInfo ; import org . gatein . wsrp . consumer . RefreshResult ; import org . gatein . wsrp . consumer . RegistrationInfo ; import org . gatein . wsrp . consumer . registry . ConsumerRegistry ; import javax . faces . context . FacesContext ; import javax . faces . event . ActionEvent ; import java . io . Serializable ; import java . util . List ; import java . util . Map ; public class ConsumerManagerBean extends WSRPManagedBean implements Serializable { private transient ConsumerRegistry registry ; private String selectedId ; private static final String NO_CONSUMER = "<STR_LIT>" ; private static final String INVALID_NEW_CONSUMER_NAME = "<STR_LIT>" ; private static final String REFRESH_BYPASSED = "<STR_LIT>" ; private static final String REFRESH_SUCCESS = "<STR_LIT>" ; private static final String REFRESH_FAILURE = "<STR_LIT>" ; private static final String REFRESH_FAILURE_WSDL = "<STR_LIT>" ; private static final String REFRESH_EXCEPTION = "<STR_LIT>" ; static final String CONFIGURE_CONSUMER = "<STR_LIT>" ; static final String EXPORT = "<STR_LIT>" ; static final String EXPORTS = "<STR_LIT>" ; static final String EXPORT_DETAIL = "<STR_LIT>" ; static final String IMPORT = "<STR_LIT>" ; static final String CONSUMERS = "<STR_LIT>" ; static final String EXPECTED_REG_INFO_KEY = "<STR_LIT>" ; static final String REFRESH_MODIFY = "<STR_LIT>" ; static final String REQUESTED_CONSUMER_ID = "<STR_LIT:id>" ; static final String SESSION_CONSUMER_ID = "<STR_LIT>" ; private static final String MESSAGE_TARGET = "<STR_LIT>" ; public ConsumerRegistry getRegistry ( ) { if ( registry == null ) { registry = beanContext . findBean ( "<STR_LIT>" , ConsumerRegistry . class ) ; } return registry ; } public void setRegistry ( ConsumerRegistry registry ) { this . registry = registry ; } public void setSelectedId ( String consumerId ) { this . selectedId = consumerId ; } public String getSelectedId ( ) { return selectedId ; } public WSRPConsumer getSelectedConsumer ( ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( selectedId , "<STR_LIT>" , null ) ; return getRegistry ( ) . getConsumer ( selectedId ) ; } public boolean isConsumersEmpty ( ) { return getRegistry ( ) . getConfiguredConsumerNumber ( ) == <NUM_LIT:0> ; } public List < WSRPConsumer > getConsumers ( ) { return getRegistry ( ) . getConfiguredConsumers ( ) ; } public String reload ( ) { getRegistry ( ) . reloadConsumers ( ) ; return CONSUMERS ; } public String activateConsumer ( ) { if ( refreshConsumerId ( ) != null ) { boolean activate = Boolean . valueOf ( beanContext . getParameter ( "<STR_LIT>" ) ) ; try { if ( activate ) { WSRPConsumer consumer = getSelectedConsumer ( ) ; if ( consumer . isRefreshNeeded ( ) ) { RefreshResult result = internalRefresh ( consumer ) ; if ( result != null && ! result . hasIssues ( ) ) { getRegistry ( ) . activateConsumerWith ( selectedId ) ; } } else { getRegistry ( ) . activateConsumerWith ( selectedId ) ; } } else { getRegistry ( ) . deactivateConsumerWith ( selectedId ) ; } } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; } return listConsumers ( ) ; } else { noSelectedConsumerError ( ) ; return listConsumers ( ) ; } } public String registerConsumer ( ) { if ( refreshConsumerId ( ) != null ) { boolean register = Boolean . valueOf ( beanContext . getParameter ( "<STR_LIT>" ) ) ; try { getRegistry ( ) . registerOrDeregisterConsumerWith ( selectedId , register ) ; return CONFIGURE_CONSUMER ; } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } } else { noSelectedConsumerError ( ) ; return null ; } } public String createConsumer ( ) { selectedId = checkNameValidity ( selectedId , MESSAGE_TARGET ) ; if ( selectedId != null ) { try { getRegistry ( ) . createConsumer ( selectedId , ProducerInfo . DEFAULT_CACHE_VALUE , null ) ; return CONFIGURE_CONSUMER ; } catch ( Exception e ) { selectedId = null ; beanContext . createErrorMessageFrom ( MESSAGE_TARGET , e ) ; return null ; } } return null ; } public String destroyConsumer ( ) { if ( refreshConsumerId ( ) != null ) { try { getRegistry ( ) . destroyConsumer ( selectedId ) ; return listConsumers ( ) ; } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } } else { noSelectedConsumerError ( ) ; return null ; } } public String configureConsumer ( ) { if ( refreshConsumerId ( ) != null ) { return CONFIGURE_CONSUMER ; } else { noSelectedConsumerError ( ) ; return null ; } } public String refreshConsumer ( ) { if ( refreshConsumerId ( ) != null ) { internalRefresh ( getSelectedConsumer ( ) ) ; return configureConsumer ( ) ; } else { noSelectedConsumerError ( ) ; return null ; } } public String importPortlets ( ) { if ( refreshConsumerId ( ) != null ) { return EXPORTS ; } else { noSelectedConsumerError ( ) ; return null ; } } public String exportPortlets ( ) { if ( refreshConsumerId ( ) != null ) { return EXPORT ; } else { noSelectedConsumerError ( ) ; return null ; } } private RefreshResult internalRefresh ( WSRPConsumer consumer ) { try { RefreshResult result = consumer . refresh ( true ) ; String statusMessage = getLocalizationKeyFrom ( result ) ; if ( result . hasIssues ( ) ) { RegistrationInfo expected = new RegistrationInfo ( consumer . getProducerInfo ( ) . getRegistrationInfo ( ) ) ; expected . refresh ( result . getServiceDescription ( ) , consumer . getProducerId ( ) , true , true , true ) ; setExpectedRegistrationInfo ( expected ) ; beanContext . createErrorMessage ( statusMessage ) ; getRegistry ( ) . deactivateConsumerWith ( consumer . getProducerId ( ) ) ; } else { if ( consumer . isActive ( ) ) { getRegistry ( ) . activateConsumerWith ( consumer . getProducerId ( ) ) ; } else { getRegistry ( ) . deactivateConsumerWith ( consumer . getProducerId ( ) ) ; } beanContext . createInfoMessage ( statusMessage ) ; } return result ; } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } } private String getLocalizationKeyFrom ( RefreshResult result ) { RefreshResult . Status status = result . getStatus ( ) ; if ( RefreshResult . Status . BYPASSED . equals ( status ) ) { return REFRESH_BYPASSED ; } else if ( RefreshResult . Status . SUCCESS . equals ( status ) ) { return REFRESH_SUCCESS ; } else if ( RefreshResult . Status . FAILURE . equals ( status ) ) { RefreshResult registrationResult = result . getRegistrationResult ( ) ; if ( registrationResult != null ) { return REFRESH_FAILURE ; } else { return REFRESH_FAILURE_WSDL ; } } else if ( RefreshResult . Status . MODIFY_REGISTRATION_REQUIRED . equals ( status ) ) { return REFRESH_MODIFY ; } else { return REFRESH_EXCEPTION ; } } RefreshResult refresh ( WSRPConsumer consumer ) { RefreshResult result = internalRefresh ( consumer ) ; selectedId = consumer . getProducerId ( ) ; return result ; } private void setExpectedRegistrationInfo ( RegistrationInfo expected ) { Map < String , Object > sessionMap = FacesContext . getCurrentInstance ( ) . getExternalContext ( ) . getSessionMap ( ) ; sessionMap . put ( EXPECTED_REG_INFO_KEY , expected ) ; } public String listConsumers ( ) { selectedId = null ; return CONSUMERS ; } public void selectConsumer ( ActionEvent actionEvent ) { refreshConsumerId ( ) ; } private String refreshConsumerId ( ) { selectedId = beanContext . getParameter ( REQUESTED_CONSUMER_ID ) ; return selectedId ; } private void noSelectedConsumerError ( ) { beanContext . createErrorMessage ( NO_CONSUMER ) ; } protected String getObjectTypeName ( ) { return "<STR_LIT>" ; } public boolean isAlreadyExisting ( String objectName ) { return getRegistry ( ) . containsConsumer ( objectName ) ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import com . google . common . base . Function ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . Portlet ; import org . gatein . pc . api . PortletContext ; import org . gatein . pc . api . PortletInvokerException ; import org . gatein . wsrp . WSRPConsumer ; import org . gatein . wsrp . WSRPUtils ; import org . gatein . wsrp . api . context . ConsumerStructureProvider ; import org . gatein . wsrp . consumer . EndpointConfigurationInfo ; import org . gatein . wsrp . consumer . ProducerInfo ; import org . gatein . wsrp . consumer . RegistrationInfo ; import org . gatein . wsrp . consumer . RegistrationProperty ; import org . gatein . wsrp . consumer . migration . ExportInfo ; import org . gatein . wsrp . consumer . migration . ImportInfo ; import org . gatein . wsrp . consumer . migration . MigrationService ; import org . gatein . wsrp . consumer . registry . ConsumerRegistry ; import javax . faces . event . ActionEvent ; import javax . faces . event . ValueChangeEvent ; import javax . faces . model . DataModel ; import javax . faces . model . ListDataModel ; import javax . faces . model . SelectItem ; import javax . xml . namespace . QName ; import java . io . Serializable ; import java . net . MalformedURLException ; import java . net . URL ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . LinkedList ; import java . util . List ; import java . util . Locale ; import java . util . Map ; import java . util . SortedMap ; public class ConsumerBean extends WSRPManagedBean implements Serializable { public static final SelectablePortletToHandleFunction SELECTABLE_TO_HANDLE = new SelectablePortletToHandleFunction ( ) ; private transient WSRPConsumer consumer ; private transient ConsumerManagerBean manager ; private boolean modified ; private String wsdl ; private String id ; private long currentExportTime ; private static final String NULL_ID_CONSUMER = "<STR_LIT>" ; private static final String CANNOT_FIND_CONSUMER = "<STR_LIT>" ; private static final String CANNOT_UPDATE_CONSUMER = "<STR_LIT>" ; private static final String CANNOT_REFRESH_CONSUMER = "<STR_LIT>" ; private static final String MODIFY_REG_SUCCESS = "<STR_LIT>" ; private static final String INVALID_MODIFY = "<STR_LIT>" ; private static final String CANNOT_MODIFY_REG = "<STR_LIT>" ; private static final String CANNOT_ERASE_REG = "<STR_LIT>" ; private static final String MALFORMED_URL = "<STR_LIT>" ; private static final String UPDATE_SUCCESS = "<STR_LIT>" ; private static final String CANNOT_EXPORT = "<STR_LIT>" ; private static final String IMPORT_SUCCESS = "<STR_LIT>" ; private static final String FAILED_PORTLETS = "<STR_LIT>" ; private static final String CONSUMER_TYPE = "<STR_LIT>" ; private static final String CURRENT_EXPORT_TIME = "<STR_LIT>" ; private transient DataModel portletHandles ; private transient DataModel existingExports ; private transient ExportInfoDisplay currentExport ; public void setManager ( ConsumerManagerBean manager ) { this . manager = manager ; } public boolean isModified ( ) { return modified || getProducerInfo ( ) . isModifyRegistrationRequired ( ) || isRegistrationLocallyModified ( ) ; } public boolean isRefreshNeeded ( ) { return getConsumer ( ) . isRefreshNeeded ( ) ; } public String getId ( ) { return getConsumer ( ) . getProducerId ( ) ; } public void setId ( String id ) { if ( consumer != null ) { ProducerInfo info = getProducerInfo ( ) ; String oldId = info . getId ( ) ; if ( isOldAndNewDifferent ( oldId , id ) ) { id = checkNameValidity ( id , "<STR_LIT>" ) ; if ( id != null ) { info . setId ( id ) ; getRegistry ( ) . updateProducerInfo ( info ) ; modified = true ; this . id = id ; } } } else { resolveConsumer ( id ) ; } } private void resolveConsumer ( String id ) { if ( id == null ) { id = getManager ( ) . getSelectedId ( ) ; } if ( id == null ) { beanContext . createErrorMessage ( NULL_ID_CONSUMER ) ; bypassAndRedisplay ( ) ; } else { consumer = getRegistry ( ) . getConsumer ( id ) ; if ( consumer != null ) { EndpointConfigurationInfo endpoint = getProducerInfo ( ) . getEndpointConfigurationInfo ( ) ; wsdl = endpoint . getWsdlDefinitionURL ( ) ; this . id = id ; } else { beanContext . createErrorMessage ( CANNOT_FIND_CONSUMER , id ) ; bypassAndRedisplay ( ) ; } } } public Integer getCache ( ) { return getProducerInfo ( ) . getExpirationCacheSeconds ( ) ; } public void setCache ( Integer cache ) { getProducerInfo ( ) . setExpirationCacheSeconds ( ( Integer ) modifyIfNeeded ( getCache ( ) , cache , "<STR_LIT>" , false ) ) ; } public Integer getTimeout ( ) { return getProducerInfo ( ) . getEndpointConfigurationInfo ( ) . getWSOperationTimeOut ( ) ; } public void setTimeout ( Integer timeout ) { getProducerInfo ( ) . getEndpointConfigurationInfo ( ) . setWSOperationTimeOut ( ( Integer ) modifyIfNeeded ( getTimeout ( ) , timeout , "<STR_LIT>" , false ) ) ; } public String getWsdl ( ) { return wsdl ; } public void setWsdl ( String wsdlURL ) { wsdl = ( String ) modifyIfNeeded ( wsdl , wsdlURL , "<STR_LIT>" , true ) ; } private void internalSetWsdl ( String wsdlURL ) { try { getProducerInfo ( ) . getEndpointConfigurationInfo ( ) . setWsdlDefinitionURL ( wsdlURL ) ; } catch ( Exception e ) { getRegistry ( ) . deactivateConsumerWith ( getId ( ) ) ; beanContext . createErrorMessageFrom ( "<STR_LIT>" , e ) ; } } public boolean isActive ( ) { return getConsumer ( ) . isActive ( ) ; } public boolean isRegistered ( ) { return getProducerInfo ( ) . isRegistered ( ) ; } public boolean isRegistrationRequired ( ) { return getProducerInfo ( ) . isRegistrationRequired ( ) ; } public boolean isRegistrationCheckNeeded ( ) { ProducerInfo info = getProducerInfo ( ) ; if ( info . isRefreshNeeded ( true ) ) { RegistrationInfo regInfo = info . getRegistrationInfo ( ) ; if ( regInfo == null ) { return true ; } else { Boolean consistent = regInfo . isConsistentWithProducerExpectations ( ) ; return consistent == null || ! consistent . booleanValue ( ) ; } } else { return false ; } } public boolean isDisplayExpectedNeeded ( ) { ProducerInfo producerInfo = getProducerInfo ( ) ; return producerInfo . isModifyRegistrationRequired ( ) && producerInfo . getRegistrationInfo ( ) != producerInfo . getExpectedRegistrationInfo ( ) ; } public boolean isRegistrationLocallyModified ( ) { return isRegistered ( ) && getProducerInfo ( ) . getRegistrationInfo ( ) . isModifiedSinceLastRefresh ( ) ; } public boolean isRegistrationChecked ( ) { return getProducerInfo ( ) . isRegistrationChecked ( ) ; } public boolean isRegistrationValid ( ) { if ( isRegistrationChecked ( ) ) { return getProducerInfo ( ) . getRegistrationInfo ( ) . isRegistrationValid ( ) . booleanValue ( ) ; } throw new IllegalStateException ( "<STR_LIT>" ) ; } public ProducerInfo getProducerInfo ( ) { return getConsumer ( ) . getProducerInfo ( ) ; } public boolean isLocalInfoPresent ( ) { return getProducerInfo ( ) . hasLocalRegistrationInfo ( ) ; } public boolean isRegistrationPropertiesExisting ( ) { RegistrationInfo regInfo = getProducerInfo ( ) . getRegistrationInfo ( ) ; return regInfo == null || regInfo . isRegistrationPropertiesExisting ( ) ; } public boolean isExpectedRegistrationPropertiesExisting ( ) { RegistrationInfo info = getExpectedRegistrationInfo ( ) ; return info != null && info . isRegistrationPropertiesExisting ( ) ; } private RegistrationInfo getExpectedRegistrationInfo ( ) { return getProducerInfo ( ) . getExpectedRegistrationInfo ( ) ; } public List < RegistrationProperty > getRegistrationProperties ( ) { return getSortedProperties ( getProducerInfo ( ) . getRegistrationInfo ( ) ) ; } public List < RegistrationProperty > getExpectedRegistrationProperties ( ) { return getSortedProperties ( getExpectedRegistrationInfo ( ) ) ; } private List < RegistrationProperty > getSortedProperties ( RegistrationInfo registrationInfo ) { if ( registrationInfo != null ) { LinkedList < RegistrationProperty > list = new LinkedList < RegistrationProperty > ( registrationInfo . getRegistrationProperties ( ) . values ( ) ) ; Collections . sort ( list ) ; return list ; } else { return Collections . emptyList ( ) ; } } public String update ( ) { return internalUpdate ( true ) ; } public String confirmEraseRegistration ( ) { return "<STR_LIT>" ; } private String internalUpdate ( boolean showMessage ) { if ( getConsumer ( ) != null ) { if ( isModified ( ) ) { try { ProducerInfo prodInfo = getProducerInfo ( ) ; EndpointConfigurationInfo endpointInfo = prodInfo . getEndpointConfigurationInfo ( ) ; internalSetWsdl ( wsdl ) ; saveToRegistry ( prodInfo ) ; } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } } if ( showMessage ) { beanContext . createInfoMessage ( UPDATE_SUCCESS ) ; } return ConsumerManagerBean . CONFIGURE_CONSUMER ; } beanContext . createErrorMessage ( CANNOT_UPDATE_CONSUMER ) ; return null ; } private void saveToRegistry ( ProducerInfo prodInfo ) { getRegistry ( ) . updateProducerInfo ( prodInfo ) ; modified = false ; } public String refreshConsumer ( ) { final WSRPConsumer consumer = getConsumer ( ) ; if ( consumer != null ) { if ( isModified ( ) ) { String updateResult = internalUpdate ( false ) ; if ( updateResult == null ) { return null ; } } if ( ! isRegistrationLocallyModified ( ) ) { getManager ( ) . refresh ( consumer ) ; } else { beanContext . createInfoMessage ( ConsumerManagerBean . REFRESH_MODIFY ) ; } return ConsumerManagerBean . CONFIGURE_CONSUMER ; } beanContext . createErrorMessage ( CANNOT_REFRESH_CONSUMER ) ; return null ; } public String modifyRegistration ( ) { if ( getConsumer ( ) != null ) { ProducerInfo info = getProducerInfo ( ) ; if ( isModified ( ) ) { RegistrationInfo newReg = getExpectedRegistrationInfo ( ) ; saveToRegistry ( info ) ; RegistrationInfo oldReg = getProducerInfo ( ) . getRegistrationInfo ( ) ; if ( newReg == null ) { newReg = new RegistrationInfo ( oldReg ) ; if ( ! isRegistrationLocallyModified ( ) ) { IllegalStateException e = new IllegalStateException ( "<STR_LIT>" ) ; log . debug ( "<STR_LIT>" , e ) ; throw e ; } } try { newReg . setModifiedSinceLastRefresh ( true ) ; info . setRegistrationInfo ( newReg ) ; info . modifyRegistration ( ) ; newReg . setModifiedSinceLastRefresh ( false ) ; beanContext . createInfoMessage ( MODIFY_REG_SUCCESS ) ; } catch ( Exception e ) { info . setRegistrationInfo ( oldReg ) ; beanContext . createErrorMessageFrom ( e ) ; return null ; } refreshConsumer ( ) ; return null ; } else { beanContext . createErrorMessage ( INVALID_MODIFY ) ; } } beanContext . createErrorMessage ( CANNOT_MODIFY_REG ) ; return null ; } public String eraseLocalRegistration ( ) { if ( getConsumer ( ) != null ) { getProducerInfo ( ) . eraseRegistrationInfo ( ) ; return ConsumerManagerBean . CONFIGURE_CONSUMER ; } beanContext . createErrorMessage ( CANNOT_ERASE_REG ) ; return null ; } private Object modifyIfNeeded ( Object oldValue , Object newValue , String target , boolean checkURL ) { if ( isOldAndNewDifferent ( oldValue , newValue ) ) { if ( checkURL ) { try { new URL ( newValue . toString ( ) ) ; } catch ( MalformedURLException e ) { beanContext . createTargetedErrorMessage ( target , MALFORMED_URL , newValue , e . getLocalizedMessage ( ) ) ; } } oldValue = newValue ; modified = true ; } return oldValue ; } protected String getObjectTypeName ( ) { return CONSUMER_TYPE ; } public boolean isAlreadyExisting ( String objectName ) { return getRegistry ( ) . containsConsumer ( objectName ) ; } public ConsumerRegistry getRegistry ( ) { return getManager ( ) . getRegistry ( ) ; } public DataModel getPortlets ( ) { try { if ( portletHandles == null ) { final WSRPConsumer consumer = getConsumer ( ) ; Collection < Portlet > portlets = consumer . getProducerInfo ( ) . getPortletMap ( ) . values ( ) ; List < SelectablePortletHandle > selectableHandles = Collections . emptyList ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( portlets ) ) { selectableHandles = new ArrayList < SelectablePortletHandle > ( portlets . size ( ) ) ; for ( Portlet portlet : portlets ) { selectableHandles . add ( new SelectablePortletHandle ( portlet . getContext ( ) . getId ( ) , consumer . getMigrationService ( ) . getStructureProvider ( ) ) ) ; } } Collections . sort ( selectableHandles ) ; portletHandles = new ListDataModel ( selectableHandles ) ; } return portletHandles ; } catch ( PortletInvokerException e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } } public boolean isReadyForExport ( ) { List < SelectablePortletHandle > handles = ( List < SelectablePortletHandle > ) getPortlets ( ) . getWrappedData ( ) ; for ( SelectablePortletHandle handle : handles ) { if ( handle . isSelected ( ) ) { return true ; } } return false ; } public String exportPortlets ( ) { final WSRPConsumer consumer = getConsumer ( ) ; if ( consumer != null ) { List < SelectablePortletHandle > handles = ( List < SelectablePortletHandle > ) getPortlets ( ) . getWrappedData ( ) ; List < String > selectedHandles = new ArrayList < String > ( handles . size ( ) ) ; for ( SelectablePortletHandle selectablePortletHandle : handles ) { if ( selectablePortletHandle . isSelected ( ) ) { selectedHandles . add ( selectablePortletHandle . getHandle ( ) ) ; } } try { setCurrentExport ( new ExportInfoDisplay ( consumer . exportPortlets ( selectedHandles ) , beanContext . getLocale ( ) , consumer . getMigrationService ( ) . getStructureProvider ( ) ) ) ; } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } return ConsumerManagerBean . EXPORT_DETAIL ; } beanContext . createErrorMessage ( CANNOT_EXPORT ) ; return null ; } public ExportInfoDisplay getCurrentExport ( ) { return getCurrentExport ( currentExportTime ) ; } private ExportInfoDisplay getCurrentExport ( long exportTime ) { if ( currentExport != null ) { if ( exportTime == currentExport . getExport ( ) . getExportTime ( ) ) { return currentExport ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } else { if ( exportTime <= <NUM_LIT:0> ) { final String time = beanContext . getParameter ( CURRENT_EXPORT_TIME ) ; if ( ! ParameterValidation . isNullOrEmpty ( time ) ) { exportTime = Long . parseLong ( time ) ; } else { final Long fromSession = beanContext . getFromSession ( CURRENT_EXPORT_TIME , Long . class ) ; if ( fromSession != null ) { exportTime = fromSession ; beanContext . removeFromSession ( CURRENT_EXPORT_TIME ) ; } else { return null ; } } } setCurrentExport ( new ExportInfoDisplay ( this , exportTime ) ) ; return currentExport ; } } private void setCurrentExport ( ExportInfoDisplay currentExport ) { this . currentExport = currentExport ; this . currentExportTime = currentExport != null ? currentExport . getExport ( ) . getExportTime ( ) : - <NUM_LIT:1> ; beanContext . getSessionMap ( ) . put ( CURRENT_EXPORT_TIME , currentExportTime ) ; } public boolean isExportsAvailable ( ) { return getExistingExports ( ) . getRowCount ( ) > <NUM_LIT:0> ; } public DataModel getExistingExports ( ) { if ( existingExports == null ) { Locale locale = beanContext . getLocale ( ) ; MigrationService migrationService = getConsumer ( ) . getMigrationService ( ) ; List < ExportInfo > availableExportInfos = migrationService . getAvailableExportInfos ( ) ; List < ExportInfoDisplay > exportDisplays = new ArrayList < ExportInfoDisplay > ( availableExportInfos . size ( ) ) ; for ( ExportInfo exportInfo : availableExportInfos ) { exportDisplays . add ( new ExportInfoDisplay ( exportInfo , locale , migrationService . getStructureProvider ( ) ) ) ; } existingExports = new ListDataModel ( exportDisplays ) ; } return existingExports ; } public String viewExport ( ) { selectExport ( ) ; return ConsumerManagerBean . EXPORT_DETAIL ; } public String importPortlets ( long exportTime ) { final ExportInfoDisplay currentExport = getCurrentExport ( exportTime ) ; List < SelectablePortletHandle > exportedPortlets = currentExport . getExportedPortlets ( ) ; try { List < SelectablePortletHandle > portletsToImport = new ArrayList < SelectablePortletHandle > ( exportedPortlets . size ( ) ) ; for ( SelectablePortletHandle exportedPortlet : exportedPortlets ) { if ( exportedPortlet . isSelected ( ) ) { portletsToImport . add ( exportedPortlet ) ; } } final WSRPConsumer consumer = getConsumer ( ) ; ImportInfo info = consumer . importPortlets ( currentExport . getExport ( ) , WSRPUtils . transform ( portletsToImport , SELECTABLE_TO_HANDLE ) ) ; ConsumerStructureProvider structureProvider = consumer . getMigrationService ( ) . getStructureProvider ( ) ; int importCount = <NUM_LIT:0> ; for ( SelectablePortletHandle importedPortlet : portletsToImport ) { String handle = importedPortlet . getHandle ( ) ; PortletContext portletContext = info . getPortletContextFor ( handle ) ; if ( portletContext != null ) { structureProvider . assignPortletToWindow ( portletContext , importedPortlet . getWindow ( ) , importedPortlet . getPage ( ) , handle ) ; importCount ++ ; } } if ( importCount > <NUM_LIT:0> ) { beanContext . createLocalizedMessage ( BeanContext . STATUS , IMPORT_SUCCESS , beanContext . getInfoSeverity ( ) , importCount ) ; } SortedMap < QName , List < String > > errorCodesToFailedPortletHandlesMapping = info . getErrorCodesToFailedPortletHandlesMapping ( ) ; if ( ! errorCodesToFailedPortletHandlesMapping . isEmpty ( ) ) { for ( Map . Entry < QName , List < String > > entry : errorCodesToFailedPortletHandlesMapping . entrySet ( ) ) { QName errorCode = entry . getKey ( ) ; for ( String handle : entry . getValue ( ) ) { beanContext . createErrorMessage ( FAILED_PORTLETS , handle + "<STR_LIT>" + errorCode + "<STR_LIT:)>" ) ; } } } return ConsumerManagerBean . CONSUMERS ; } catch ( Exception e ) { beanContext . createErrorMessageFrom ( e ) ; return null ; } } public String deleteExport ( ) { ExportInfo export = getCurrentExport ( ) . getExport ( ) ; final WSRPConsumer consumer = getConsumer ( ) ; if ( consumer . getMigrationService ( ) . remove ( export ) == export ) { try { consumer . releaseExport ( export ) ; } catch ( PortletInvokerException e ) { consumer . getMigrationService ( ) . add ( export ) ; beanContext . createErrorMessageFrom ( e ) ; return null ; } existingExports = null ; setCurrentExport ( null ) ; } return ConsumerManagerBean . EXPORTS ; } public void selectExport ( ActionEvent actionEvent ) { selectExport ( ) ; } public void selectExport ( ) { setCurrentExport ( ( ExportInfoDisplay ) getExistingExports ( ) . getRowData ( ) ) ; } public boolean isImportExportSupported ( ) { return isActive ( ) && getConsumer ( ) . isImportExportSupported ( ) ; } public boolean isAvailableExportInfosEmpty ( ) { return getConsumer ( ) . getMigrationService ( ) . isAvailableExportInfosEmpty ( ) ; } public boolean isWssEnabled ( ) { return getProducerInfo ( ) . getEndpointConfigurationInfo ( ) . getWSSEnabled ( ) ; } public boolean isWssAvailable ( ) { return getProducerInfo ( ) . getEndpointConfigurationInfo ( ) . isWSSAvailable ( ) ; } public void setWssEnabled ( boolean enable ) { getProducerInfo ( ) . getEndpointConfigurationInfo ( ) . setWSSEnabled ( enable ) ; } public WSRPConsumer getConsumer ( ) { if ( consumer == null ) { resolveConsumer ( id ) ; } return consumer ; } public void setConsumer ( WSRPConsumer consumer ) { this . consumer = consumer ; } public ConsumerManagerBean getManager ( ) { if ( manager == null ) { manager = beanContext . findBean ( "<STR_LIT>" , ConsumerManagerBean . class ) ; } return manager ; } public static class SelectablePortletHandle implements Comparable < SelectablePortletHandle > { private String handle ; private boolean selected ; private String page ; private String window ; private ConsumerStructureProvider provider ; public SelectablePortletHandle ( String handle , ConsumerStructureProvider provider ) { this . handle = handle ; this . provider = provider ; } public boolean isReadyForImport ( ) { return selected && ! ParameterValidation . isNullOrEmpty ( window ) ; } public String getHandle ( ) { return handle ; } public boolean isSelected ( ) { return selected ; } public void setSelected ( boolean selected ) { this . selected = selected ; } public void setPage ( String page ) { this . page = page ; } public String getPage ( ) { return page ; } public void setWindow ( String window ) { this . window = window ; } public String getWindow ( ) { return window ; } public void selectCurrentPage ( ValueChangeEvent event ) { page = ( String ) event . getNewValue ( ) ; if ( page != null ) { List < String > windows = provider . getWindowIdentifiersFor ( page ) ; if ( ParameterValidation . existsAndIsNotEmpty ( windows ) && windows . size ( ) == <NUM_LIT:1> ) { window = windows . get ( <NUM_LIT:0> ) ; } } bypassAndRedisplay ( ) ; } public void selectCurrentWindow ( ValueChangeEvent event ) { window = ( String ) event . getNewValue ( ) ; bypassAndRedisplay ( ) ; } public List < SelectItem > getPages ( ) { List < String > pageIdentifiers = provider . getPageIdentifiers ( ) ; return getSelectItemsFrom ( pageIdentifiers ) ; } public List < SelectItem > getWindows ( ) { return getSelectItemsFrom ( provider . getWindowIdentifiersFor ( page ) ) ; } public void select ( ValueChangeEvent event ) { selected = ( Boolean ) event . getNewValue ( ) ; bypassAndRedisplay ( ) ; } public int compareTo ( SelectablePortletHandle o ) { return handle . compareTo ( o . handle ) ; } } public static class ExportInfoDisplay { private ExportInfo export ; private Locale locale ; private List < FailedPortletsDisplay > failedPortlets ; private List < SelectablePortletHandle > exportedPortlets ; public ExportInfoDisplay ( ExportInfo export , Locale locale , ConsumerStructureProvider provider ) { init ( export , locale , provider ) ; } private void init ( ExportInfo export , Locale locale , ConsumerStructureProvider provider ) { this . export = export ; this . locale = locale ; List < String > exportedPortletHandles = export . getExportedPortletHandles ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( exportedPortletHandles ) ) { exportedPortlets = new ArrayList < SelectablePortletHandle > ( exportedPortletHandles . size ( ) ) ; for ( String handle : exportedPortletHandles ) { exportedPortlets . add ( new SelectablePortletHandle ( handle , provider ) ) ; } } else { exportedPortlets = Collections . emptyList ( ) ; } SortedMap < QName , List < String > > errorCodesToFailedPortletHandlesMapping = export . getErrorCodesToFailedPortletHandlesMapping ( ) ; if ( ParameterValidation . existsAndIsNotEmpty ( errorCodesToFailedPortletHandlesMapping ) ) { failedPortlets = new ArrayList < FailedPortletsDisplay > ( errorCodesToFailedPortletHandlesMapping . size ( ) ) ; for ( Map . Entry < QName , List < String > > entry : errorCodesToFailedPortletHandlesMapping . entrySet ( ) ) { failedPortlets . add ( new FailedPortletsDisplay ( entry . getKey ( ) , entry . getValue ( ) ) ) ; } } else { failedPortlets = Collections . emptyList ( ) ; } } public ExportInfoDisplay ( ConsumerBean bean , long exportTime ) { final MigrationService migrationService = bean . getConsumer ( ) . getMigrationService ( ) ; init ( migrationService . getExportInfo ( exportTime ) , bean . beanContext . getLocale ( ) , migrationService . getStructureProvider ( ) ) ; } public String getExportTime ( ) { return export . getHumanReadableExportTime ( locale ) ; } public String getExpirationTime ( ) { return export . getHumanReadableExpirationTime ( locale ) ; } public boolean isHasFailedPortlets ( ) { return ! failedPortlets . isEmpty ( ) ; } public List < SelectablePortletHandle > getExportedPortlets ( ) { return exportedPortlets ; } public List < FailedPortletsDisplay > getFailedPortlets ( ) { return failedPortlets ; } public ExportInfo getExport ( ) { return export ; } public boolean isReadyForImport ( ) { boolean ready = false ; for ( SelectablePortletHandle portlet : exportedPortlets ) { ready = ready || portlet . isReadyForImport ( ) ; } return ready ; } } public static class FailedPortletsDisplay { private QName errorCode ; private List < String > faliedPortlets ; public FailedPortletsDisplay ( QName errorCode , List < String > failedPortlets ) { this . errorCode = errorCode ; this . faliedPortlets = failedPortlets ; } public QName getErrorCode ( ) { return errorCode ; } public List < String > getFailedPortlets ( ) { return faliedPortlets ; } } private static class SelectablePortletToHandleFunction implements Function < SelectablePortletHandle , String > { public String apply ( SelectablePortletHandle from ) { return from . getHandle ( ) ; } } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . wsrp . consumer . RegistrationProperty ; import javax . faces . component . UIComponent ; import javax . faces . context . FacesContext ; import javax . faces . convert . Converter ; import java . util . Locale ; public class StatusConverter implements Converter { public Object getAsObject ( FacesContext facesContext , UIComponent uiComponent , String s ) { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } public String getAsString ( FacesContext facesContext , UIComponent uiComponent , Object o ) { if ( o == null ) { return null ; } Locale locale = facesContext . getExternalContext ( ) . getRequestLocale ( ) ; RegistrationProperty . Status status = ( RegistrationProperty . Status ) o ; String key = status . getLocalizationKey ( ) ; return BeanContext . getLocalizedMessage ( key , locale ) ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import javax . faces . application . ConfigurableNavigationHandler ; import javax . faces . application . NavigationCase ; import javax . faces . application . NavigationHandler ; import javax . faces . context . FacesContext ; import java . util . Map ; import java . util . Set ; public class RedirectOnNoConsumerNavigationHandler extends ConfigurableNavigationHandler { private NavigationHandler base ; private static final String CONFIGURE_CONSUMER = "<STR_LIT>" ; private static final String CONSUMERS = "<STR_LIT>" ; private static final String CONSUMERS_MGR = "<STR_LIT>" ; public RedirectOnNoConsumerNavigationHandler ( NavigationHandler base ) { this . base = base ; } public void handleNavigation ( FacesContext facesContext , String fromAction , String outcome ) { if ( CONFIGURE_CONSUMER . equals ( outcome ) ) { String currentConsumer = JSFBeanContext . getParameter ( ConsumerManagerBean . REQUESTED_CONSUMER_ID , facesContext ) ; if ( currentConsumer == null ) { currentConsumer = ( String ) JSFBeanContext . getSessionMap ( facesContext ) . get ( ConsumerManagerBean . SESSION_CONSUMER_ID ) ; if ( currentConsumer == null ) { outcome = CONSUMERS ; } } } else if ( CONSUMERS . equals ( outcome ) ) { ConsumerManagerBean consumersMgr = ( ConsumerManagerBean ) JSFBeanContext . getSessionMap ( facesContext ) . get ( CONSUMERS_MGR ) ; outcome = consumersMgr . listConsumers ( ) ; } base . handleNavigation ( facesContext , fromAction , outcome ) ; } @ Override public NavigationCase getNavigationCase ( FacesContext context , String fromAction , String outcome ) { return ( base instanceof ConfigurableNavigationHandler ) ? ( ( ConfigurableNavigationHandler ) base ) . getNavigationCase ( context , fromAction , outcome ) : null ; } @ Override public Map < String , Set < NavigationCase > > getNavigationCases ( ) { return ( base instanceof ConfigurableNavigationHandler ) ? ( ( ConfigurableNavigationHandler ) base ) . getNavigationCases ( ) : null ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import org . gatein . registration . policies . RegistrationPolicyWrapper ; import org . gatein . wsrp . producer . config . ProducerConfiguration ; import org . gatein . wsrp . producer . config . ProducerConfigurationService ; import org . gatein . wsrp . producer . config . ProducerRegistrationRequirements ; import org . gatein . wsrp . producer . config . impl . ProducerRegistrationRequirementsImpl ; import org . gatein . wsrp . registration . LocalizedString ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import javax . faces . application . FacesMessage ; import javax . faces . component . UIComponent ; import javax . faces . component . html . HtmlDataTable ; import javax . faces . context . FacesContext ; import javax . faces . event . ActionEvent ; import javax . faces . event . ValueChangeEvent ; import javax . faces . model . SelectItem ; import javax . faces . validator . ValidatorException ; import javax . xml . namespace . QName ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . Collections ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; public class ProducerBean extends WSRPManagedBean implements Serializable { private static final String REGISTRATION_PROPERTY_TYPE = "<STR_LIT>" ; private transient ProducerConfigurationService configurationService ; private static final String PROPERTY = "<STR_LIT>" ; private static final String PRODUCER = "<STR_LIT>" ; private String selectedProp ; private transient LocalProducerConfiguration localProducerConfiguration ; public ProducerConfigurationService getConfigurationService ( ) { if ( configurationService == null ) { configurationService = beanContext . findBean ( "<STR_LIT>" , ProducerConfigurationService . class ) ; } return configurationService ; } public void setConfigurationService ( ProducerConfigurationService configurationService ) { this . configurationService = configurationService ; } public ProducerConfiguration getConfiguration ( ) { return getConfigurationService ( ) . getConfiguration ( ) ; } public boolean isRegistrationRequiredForFullDescription ( ) { return getLocalConfiguration ( ) . isRegistrationRequiredForFullDescription ( ) ; } public void setRegistrationRequiredForFullDescription ( boolean requireRegForFullDescription ) { getLocalConfiguration ( ) . setRegistrationRequiredForFullDescription ( requireRegForFullDescription ) ; } public boolean isRegistrationRequired ( ) { return getLocalConfiguration ( ) . isRegistrationRequired ( ) ; } public void setRegistrationRequired ( boolean requireRegistration ) { getLocalConfiguration ( ) . setRegistrationRequired ( requireRegistration ) ; } public boolean isStrictMode ( ) { return getLocalConfiguration ( ) . isUsingStrictMode ( ) ; } public void setStrictMode ( boolean strictMode ) { getLocalConfiguration ( ) . setUsingStrictMode ( strictMode ) ; } public List < RegistrationPropertyDescription > getRegistrationProperties ( ) { ArrayList < RegistrationPropertyDescription > propertyDescriptions = new ArrayList < RegistrationPropertyDescription > ( getLocalConfiguration ( ) . getRegistrationProperties ( ) . values ( ) ) ; Collections . sort ( propertyDescriptions ) ; return propertyDescriptions ; } public boolean isRegistrationPropertiesEmpty ( ) { return getLocalConfiguration ( ) . getRegistrationProperties ( ) . isEmpty ( ) ; } public List < SelectItem > getSupportedPropertyTypes ( ) { return Collections . singletonList ( new SelectItem ( "<STR_LIT>" ) ) ; } public String getSelectedPropertyName ( ) { return selectedProp ; } public String save ( ) { try { ProducerConfiguration currentlyPersistedConfiguration = getConfiguration ( ) ; LocalProducerConfiguration localConfiguration = getLocalConfiguration ( ) ; ProducerRegistrationRequirements registrationRequirements = currentlyPersistedConfiguration . getRegistrationRequirements ( ) ; registrationRequirements . setRegistrationRequiredForFullDescription ( localConfiguration . isRegistrationRequiredForFullDescription ( ) ) ; registrationRequirements . setRegistrationRequired ( localConfiguration . isRegistrationRequired ( ) ) ; registrationRequirements . reloadPolicyFrom ( localConfiguration . getRegistrationPolicyClassName ( ) , localConfiguration . getValidatorClassName ( ) ) ; registrationRequirements . setRegistrationProperties ( localConfiguration . getRegistrationProperties ( ) ) ; currentlyPersistedConfiguration . setUsingStrictMode ( localConfiguration . isUsingStrictMode ( ) ) ; getConfigurationService ( ) . saveConfiguration ( ) ; localProducerConfiguration = null ; beanContext . createInfoMessage ( "<STR_LIT>" ) ; } catch ( Exception e ) { log . debug ( "<STR_LIT>" , e ) ; beanContext . createErrorMessage ( "<STR_LIT>" , e . getLocalizedMessage ( ) ) ; } return PRODUCER ; } public String reloadConfiguration ( ) { try { getConfigurationService ( ) . reloadConfiguration ( ) ; localProducerConfiguration = null ; beanContext . createInfoMessage ( "<STR_LIT>" ) ; } catch ( Exception e ) { log . debug ( "<STR_LIT>" , e ) ; beanContext . createErrorMessage ( "<STR_LIT>" , e . getLocalizedMessage ( ) ) ; } return PRODUCER ; } public String addRegistrationProperty ( ) { getLocalConfiguration ( ) . addEmptyRegistrationProperty ( PROPERTY + System . currentTimeMillis ( ) ) ; return PRODUCER ; } public String deleteRegistrationProperty ( ) { getLocalConfiguration ( ) . removeRegistrationProperty ( selectedProp ) ; return PRODUCER ; } public void requireRegistrationListener ( ValueChangeEvent event ) { setRegistrationRequired ( ( Boolean ) event . getNewValue ( ) ) ; bypassAndRedisplay ( ) ; } public void strictModeListener ( ValueChangeEvent event ) { setStrictMode ( ( Boolean ) event . getNewValue ( ) ) ; bypassAndRedisplay ( ) ; } public void requireRegistrationForFullDescListener ( ValueChangeEvent event ) { setRegistrationRequiredForFullDescription ( ( Boolean ) event . getNewValue ( ) ) ; bypassAndRedisplay ( ) ; } public void selectProperty ( ActionEvent event ) { HtmlDataTable table = getParentDataTable ( ( UIComponent ) event . getSource ( ) ) ; RegistrationPropertyDescription prop = ( RegistrationPropertyDescription ) table . getRowData ( ) ; selectedProp = prop . getNameAsString ( ) ; } private HtmlDataTable getParentDataTable ( UIComponent component ) { if ( component == null ) { return null ; } if ( component instanceof HtmlDataTable ) { return ( HtmlDataTable ) component ; } return getParentDataTable ( component . getParent ( ) ) ; } protected String getObjectTypeName ( ) { return REGISTRATION_PROPERTY_TYPE ; } public boolean isAlreadyExisting ( String objectName ) { return false ; } private LocalProducerConfiguration getLocalConfiguration ( ) { if ( localProducerConfiguration == null ) { localProducerConfiguration = new LocalProducerConfiguration ( ) ; ProducerConfiguration configuration = getConfiguration ( ) ; localProducerConfiguration . initFrom ( configuration . getRegistrationRequirements ( ) , configuration . isUsingStrictMode ( ) ) ; } return localProducerConfiguration ; } public String getV1WSDL ( ) { return beanContext . getServerAddress ( ) + "<STR_LIT>" ; } public String getV2WSDL ( ) { return beanContext . getServerAddress ( ) + "<STR_LIT>" ; } public void validate ( FacesContext facesContext , UIComponent uiComponent , Object o ) { String toValidate = null ; if ( o instanceof String ) { toValidate = ( String ) o ; } else if ( o instanceof LocalizedString ) { toValidate = LocalizedStringConverter . getAsString ( o ) ; } final String validated = this . checkNameValidity ( toValidate , uiComponent . getClientId ( facesContext ) ) ; if ( validated == null ) { throw new ValidatorException ( new FacesMessage ( ) ) ; } } public List < SelectItem > getAvailableRegistrationPolicies ( ) { return getSelectItemsFrom ( localProducerConfiguration . getRegistrationRequirements ( ) . getAvailableRegistrationPolicies ( ) ) ; } public void policyChangeListener ( ValueChangeEvent event ) { getLocalConfiguration ( ) . setRegistrationPolicyClassName ( ( String ) event . getNewValue ( ) ) ; bypassAndRedisplay ( ) ; } public String getRegistrationPolicyClassName ( ) { return getLocalConfiguration ( ) . getRegistrationPolicyClassName ( ) ; } public void setRegistrationPolicyClassName ( String policyClassName ) { getLocalConfiguration ( ) . setRegistrationPolicyClassName ( policyClassName ) ; } public boolean isDefaultRegistrationPolicy ( ) { return getLocalConfiguration ( ) . isDefaultRegistrationPolicy ( ) ; } public String getValidatorClassName ( ) { return getLocalConfiguration ( ) . getValidatorClassName ( ) ; } public void setValidatorClassName ( String validatorClassName ) { getLocalConfiguration ( ) . setValidatorClassName ( validatorClassName ) ; } public List < SelectItem > getAvailableValidators ( ) { return getSelectItemsFrom ( localProducerConfiguration . getRegistrationRequirements ( ) . getAvailableRegistrationPropertyValidators ( ) ) ; } private static class LocalProducerConfiguration { private List < RegistrationPropertyDescription > registrationProperties ; private ProducerRegistrationRequirements registrationRequirements ; private boolean strictMode ; private String policyClassName ; private String validatorClassName ; public void initFrom ( ProducerRegistrationRequirements registrationRequirements , boolean usingStrictMode ) { this . registrationRequirements = new ProducerRegistrationRequirementsImpl ( registrationRequirements ) ; Map < QName , RegistrationPropertyDescription > descriptions = registrationRequirements . getRegistrationProperties ( ) ; registrationProperties = new LinkedList < RegistrationPropertyDescription > ( descriptions . values ( ) ) ; Collections . sort ( registrationProperties ) ; policyClassName = this . registrationRequirements . getPolicyClassName ( ) ; validatorClassName = getValidatorClassName ( ) ; this . strictMode = usingStrictMode ; } public boolean isRegistrationRequiredForFullDescription ( ) { return registrationRequirements . isRegistrationRequiredForFullDescription ( ) ; } public void setRegistrationRequiredForFullDescription ( boolean requireRegForFullDescription ) { registrationRequirements . setRegistrationRequiredForFullDescription ( requireRegForFullDescription ) ; } public boolean isRegistrationRequired ( ) { return registrationRequirements . isRegistrationRequired ( ) ; } public void setRegistrationRequired ( boolean requireRegistration ) { registrationRequirements . setRegistrationRequired ( requireRegistration ) ; } public RegistrationPolicy getPolicy ( ) { return registrationRequirements . getPolicy ( ) ; } public Map < QName , RegistrationPropertyDescription > getRegistrationProperties ( ) { return registrationRequirements . getRegistrationProperties ( ) ; } public void addEmptyRegistrationProperty ( String propertyName ) { RegistrationPropertyDescription prop = registrationRequirements . addEmptyRegistrationProperty ( propertyName ) ; int index = Collections . binarySearch ( registrationProperties , prop ) ; if ( index < <NUM_LIT:0> ) { registrationProperties . add ( - index - <NUM_LIT:1> , prop ) ; } } public void removeRegistrationProperty ( String propertyName ) { RegistrationPropertyDescription prop = registrationRequirements . removeRegistrationProperty ( propertyName ) ; registrationProperties . remove ( prop ) ; } public ProducerRegistrationRequirements getRegistrationRequirements ( ) { return registrationRequirements ; } public boolean isUsingStrictMode ( ) { return strictMode ; } public void setUsingStrictMode ( boolean usingStrictMode ) { this . strictMode = usingStrictMode ; } public String getRegistrationPolicyClassName ( ) { return policyClassName ; } public void setRegistrationPolicyClassName ( String className ) { policyClassName = className ; } public boolean isDefaultRegistrationPolicy ( ) { return ProducerRegistrationRequirements . DEFAULT_POLICY_CLASS_NAME . equals ( getRegistrationPolicyClassName ( ) ) ; } public String getValidatorClassName ( ) { if ( isDefaultRegistrationPolicy ( ) ) { if ( validatorClassName == null ) { DefaultRegistrationPolicy policy = ( DefaultRegistrationPolicy ) RegistrationPolicyWrapper . unwrap ( getPolicy ( ) ) ; validatorClassName = policy . getValidator ( ) . getClass ( ) . getName ( ) ; } return validatorClassName ; } else { return null ; } } public void setValidatorClassName ( String className ) { validatorClassName = className ; } } } </s>
<s> package org . gatein . wsrp . admin . ui ; import org . gatein . wsrp . WSRPConstants ; public class WSRPVersionBean { public String getVersion ( ) { return WSRPConstants . WSRP_SERVICE_VERSION ; } } </s>
<s> package org . gatein . wsrp . admin . ui ; import javax . faces . application . NavigationHandler ; import javax . faces . context . ExternalContext ; import javax . faces . context . FacesContext ; import javax . faces . event . PhaseEvent ; import javax . faces . event . PhaseId ; import javax . faces . event . PhaseListener ; import java . util . Map ; public class RedirectToErrorIfWSRPUnavailablePhaseListener implements PhaseListener { private static final String CONSUMER_REGISTRY = "<STR_LIT>" ; private static final String PRODUCER_CONFIGURATION_SERVICE = "<STR_LIT>" ; public void afterPhase ( PhaseEvent event ) { } public void beforePhase ( PhaseEvent event ) { FacesContext context = event . getFacesContext ( ) ; ExternalContext externalContext = context . getExternalContext ( ) ; Map < String , Object > applicationMap = externalContext . getApplicationMap ( ) ; if ( ! applicationMap . containsKey ( CONSUMER_REGISTRY ) || ! applicationMap . containsKey ( PRODUCER_CONFIGURATION_SERVICE ) ) { NavigationHandler navigationHandler = context . getApplication ( ) . getNavigationHandler ( ) ; navigationHandler . handleNavigation ( context , null , "<STR_LIT:error>" ) ; } } public PhaseId getPhaseId ( ) { return PhaseId . RESTORE_VIEW ; } } </s>
<s> package org . gatein . export ; import java . io . IOException ; import java . io . UnsupportedEncodingException ; import org . gatein . exports . data . ExportData ; import org . gatein . exports . data . ExportPortletData ; import org . gatein . wsrp . test . ExtendedAssert ; import junit . framework . TestCase ; public class ExportTestCase extends TestCase { public void testTransformationByValueStateless ( ) throws IOException { String portletId = "<STR_LIT>" ; double version = <NUM_LIT:1.0> ; ExportPortletData exportPortletData = new ExportPortletData ( portletId , null ) ; assertEquals ( version , exportPortletData . getVersion ( ) ) ; assertEquals ( portletId , exportPortletData . getPortletHandle ( ) ) ; assertNull ( exportPortletData . getPortletState ( ) ) ; byte [ ] bytes = exportPortletData . encodeAsBytes ( ) ; byte [ ] internalBytes = ExportData . getInternalBytes ( bytes ) ; ExportPortletData portletDataFromBytes = ExportPortletData . create ( internalBytes ) ; assertEquals ( version , portletDataFromBytes . getVersion ( ) ) ; assertEquals ( portletId , portletDataFromBytes . getPortletHandle ( ) ) ; assertEquals ( version , portletDataFromBytes . getVersion ( ) ) ; assertNull ( portletDataFromBytes . getPortletState ( ) ) ; } public void testTransformationByValueStatefull ( ) throws IOException { String portletId = "<STR_LIT>" ; double version = <NUM_LIT:1.0> ; byte [ ] state = new byte [ ] { - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , '<CHAR_LIT:a>' , '<CHAR_LIT:b>' , '<CHAR_LIT:c>' } ; ExportPortletData exportPortletData = new ExportPortletData ( portletId , state ) ; assertEquals ( version , exportPortletData . getVersion ( ) ) ; assertEquals ( portletId , exportPortletData . getPortletHandle ( ) ) ; assertNotNull ( exportPortletData . getPortletState ( ) ) ; ExtendedAssert . assertEquals ( state , exportPortletData . getPortletState ( ) ) ; byte [ ] bytes = exportPortletData . encodeAsBytes ( ) ; byte [ ] internalBytes = ExportData . getInternalBytes ( bytes ) ; ExportPortletData portletDataFromBytes = ExportPortletData . create ( internalBytes ) ; assertEquals ( version , portletDataFromBytes . getVersion ( ) ) ; assertEquals ( portletId , portletDataFromBytes . getPortletHandle ( ) ) ; assertEquals ( version , portletDataFromBytes . getVersion ( ) ) ; assertNotNull ( portletDataFromBytes . getPortletState ( ) ) ; assertEquals ( state . length , portletDataFromBytes . getPortletState ( ) . length ) ; ExtendedAssert . assertEquals ( state , portletDataFromBytes . getPortletState ( ) ) ; } } </s>
<s> package org . gatein . registration ; import junit . framework . TestCase ; public class RegistrationUtilsTestCase extends TestCase { public void testValidateConsumerAgentStrict ( ) { RegistrationUtils . setStrict ( true ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; checkValidateProperlyRejects ( "<STR_LIT>" ) ; checkValidateProperlyRejects ( "<STR_LIT>" ) ; checkValidateProperlyRejects ( "<STR_LIT>" ) ; checkValidateProperlyRejects ( "<STR_LIT>" ) ; checkValidateProperlyRejects ( "<STR_LIT>" ) ; } private void checkValidateProperlyRejects ( String consumerAgent ) { try { RegistrationUtils . validateConsumerAgent ( consumerAgent ) ; fail ( "<STR_LIT>" + consumerAgent + "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { } } public void testValidateConsumerAgentLenient ( ) { RegistrationUtils . setStrict ( false ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; RegistrationUtils . validateConsumerAgent ( "<STR_LIT>" ) ; } } </s>
<s> package org . gatein . registration . policies ; import junit . framework . TestCase ; import org . gatein . registration . RegistrationPolicy ; public class RegistrationPolicyWrapperTestCase extends TestCase { public void testWrap ( ) { RegistrationPolicy policy = new DefaultRegistrationPolicy ( ) ; RegistrationPolicy wrapper = RegistrationPolicyWrapper . wrap ( policy ) ; assertEquals ( policy . getClass ( ) , wrapper . getRealClass ( ) ) ; assertEquals ( policy . getClassName ( ) , wrapper . getClassName ( ) ) ; assertEquals ( policy . getClass ( ) . getName ( ) , wrapper . getClassName ( ) ) ; assertEquals ( wrapper , RegistrationPolicyWrapper . wrap ( wrapper ) ) ; assertTrue ( wrapper instanceof RegistrationPolicyWrapper ) ; assertEquals ( policy , RegistrationPolicyWrapper . unwrap ( wrapper ) ) ; assertEquals ( policy , RegistrationPolicyWrapper . unwrap ( policy ) ) ; } } </s>
<s> package org . gatein . registration . policies ; import junit . framework . TestCase ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationManager ; import org . gatein . registration . impl . RegistrationManagerImpl ; import org . gatein . registration . impl . RegistrationPersistenceManagerImpl ; import org . gatein . wsrp . producer . config . TestRegistrationPropertyValidator ; import org . gatein . wsrp . registration . PropertyDescription ; import javax . xml . namespace . QName ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; public class DefaultRegistrationPolicyTestCase extends TestCase { DefaultRegistrationPolicy policy ; Map < QName , Object > registrationProperties ; Map < QName , PropertyDescription > expectations ; private static final String CONSUMER = "<STR_LIT>" ; private static final QName PROP1 = new QName ( "<STR_LIT>" ) ; private static final QName PROP2 = new QName ( "<STR_LIT>" ) ; private static final QName PROP3 = new QName ( "<STR_LIT>" ) ; private RegistrationManager manager ; @ Override protected void setUp ( ) throws Exception { policy = new DefaultRegistrationPolicy ( ) ; policy . setValidator ( new DefaultRegistrationPropertyValidator ( ) ) ; manager = new RegistrationManagerImpl ( ) ; manager . setPolicy ( policy ) ; manager . setPersistenceManager ( new RegistrationPersistenceManagerImpl ( ) ) ; manager . createConsumer ( CONSUMER ) ; registrationProperties = new HashMap < QName , Object > ( ) ; registrationProperties . put ( PROP1 , "<STR_LIT:value1>" ) ; registrationProperties . put ( PROP2 , "<STR_LIT>" ) ; expectations = new HashMap < QName , PropertyDescription > ( ) ; } public void testInitialState ( ) { DefaultRegistrationPolicy registrationPolicy = new DefaultRegistrationPolicy ( ) ; assertEquals ( DefaultRegistrationPropertyValidator . DEFAULT , registrationPolicy . getValidator ( ) ) ; } public void testValidateRegistrationDataForNull ( ) throws RegistrationException { try { policy . validateRegistrationDataFor ( null , "<STR_LIT:foo>" , expectations , manager ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { } try { policy . validateRegistrationDataFor ( Collections . < QName , Object > emptyMap ( ) , null , expectations , manager ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { } } public void testValidateRegistrationDataForInexistentConsumer ( ) { try { policy . validateRegistrationDataFor ( Collections . < QName , Object > emptyMap ( ) , "<STR_LIT:foo>" , expectations , manager ) ; } catch ( RegistrationException e ) { fail ( "<STR_LIT>" ) ; } } public void testValidateRegistrationDataMissingProps ( ) { expectations . put ( PROP1 , new TestPropertyDescription ( PROP1 ) ) ; expectations . put ( PROP2 , new TestPropertyDescription ( PROP2 ) ) ; expectations . put ( PROP3 , new TestPropertyDescription ( PROP3 ) ) ; try { policy . validateRegistrationDataFor ( registrationProperties , CONSUMER , expectations , manager ) ; fail ( "<STR_LIT>" ) ; } catch ( RegistrationException e ) { String message = e . getLocalizedMessage ( ) ; assertTrue ( message . startsWith ( DefaultRegistrationPolicy . MISSING_VALUE_ERROR_MSG_BEGIN ) ) ; assertTrue ( message . contains ( "<STR_LIT>" ) ) ; } } public void testValidateRegistrationDataFailedValidation ( ) { expectations . put ( PROP1 , new TestPropertyDescription ( PROP1 ) ) ; expectations . put ( PROP2 , new TestPropertyDescription ( PROP2 ) ) ; policy . setValidator ( new TestRegistrationPropertyValidator ( ) ) ; try { policy . validateRegistrationDataFor ( registrationProperties , CONSUMER , expectations , manager ) ; fail ( "<STR_LIT>" ) ; } catch ( RegistrationException e ) { String message = e . getLocalizedMessage ( ) ; assertTrue ( message . startsWith ( DefaultRegistrationPolicy . INVALID_VALUE_ERROR_MSG_BEGIN ) ) ; assertTrue ( message . contains ( "<STR_LIT>" ) ) ; assertTrue ( message . contains ( "<STR_LIT>" ) ) ; } } public void testValidateRegistrationDataExtraProps ( ) { expectations . put ( PROP1 , new TestPropertyDescription ( PROP1 ) ) ; try { policy . validateRegistrationDataFor ( registrationProperties , CONSUMER , expectations , manager ) ; fail ( "<STR_LIT>" ) ; } catch ( RegistrationException e ) { assertTrue ( e . getLocalizedMessage ( ) . contains ( "<STR_LIT>" ) ) ; } } public void testValidateRegistrationDataInvalidValue ( ) { expectations . put ( PROP1 , new TestPropertyDescription ( PROP1 ) ) ; registrationProperties . remove ( PROP2 ) ; registrationProperties . put ( PROP1 , null ) ; try { policy . validateRegistrationDataFor ( registrationProperties , CONSUMER , expectations , manager ) ; fail ( "<STR_LIT>" ) ; } catch ( RegistrationException e ) { assertTrue ( e . getLocalizedMessage ( ) . contains ( "<STR_LIT>" ) ) ; } } static class TestPropertyDescription implements PropertyDescription { private QName name ; private static final QName TYPE = new QName ( "<STR_LIT:type>" ) ; TestPropertyDescription ( QName name ) { this . name = name ; } public QName getName ( ) { return name ; } public QName getType ( ) { return TYPE ; } public int compareTo ( PropertyDescription o ) { return name . toString ( ) . compareTo ( o . getName ( ) . toString ( ) ) ; } } } </s>
<s> package org . gatein . registration ; import junit . framework . TestCase ; import org . gatein . registration . impl . RegistrationManagerImpl ; import org . gatein . registration . impl . RegistrationPersistenceManagerImpl ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import org . gatein . registration . policies . DefaultRegistrationPropertyValidator ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import javax . xml . namespace . QName ; import java . util . Collection ; import java . util . HashMap ; import java . util . Map ; public class RegistrationManagerTestCase extends TestCase { private RegistrationManager manager ; private Map < QName , Object > registrationProperties ; private Map < QName , RegistrationPropertyDescription > expectations ; protected void setUp ( ) throws Exception { manager = new RegistrationManagerImpl ( ) ; DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy ( ) ; policy . setValidator ( new DefaultRegistrationPropertyValidator ( ) ) ; manager . setPolicy ( policy ) ; manager . setPersistenceManager ( new RegistrationPersistenceManagerImpl ( ) ) ; QName prop1Name = new QName ( "<STR_LIT>" ) ; QName prop2Name = new QName ( "<STR_LIT>" ) ; registrationProperties = new HashMap < QName , Object > ( ) ; registrationProperties . put ( prop1Name , "<STR_LIT:value1>" ) ; registrationProperties . put ( prop2Name , "<STR_LIT>" ) ; expectations = new HashMap < QName , RegistrationPropertyDescription > ( ) ; expectations . put ( prop1Name , new RegistrationPropertyDescription ( prop1Name , WSRPConstants . XSD_STRING ) ) ; expectations . put ( prop2Name , new RegistrationPropertyDescription ( prop2Name , WSRPConstants . XSD_STRING ) ) ; } public void testPolicy ( ) { RegistrationPolicy policy = manager . getPolicy ( ) ; assertNotNull ( policy ) ; } public void testAddRegistrationTo ( ) throws Exception { Registration registration = manager . addRegistrationTo ( "<STR_LIT>" , registrationProperties , expectations , true ) ; assertNotNull ( registration ) ; assertNotNull ( registration . getPersistentKey ( ) ) ; Consumer consumer = manager . getConsumerByIdentity ( "<STR_LIT>" ) ; assertNotNull ( consumer ) ; assertEquals ( consumer , registration . getConsumer ( ) ) ; String registrationHandle = registration . getRegistrationHandle ( ) ; assertNotNull ( registrationHandle ) ; assertEquals ( consumer , manager . getConsumerFor ( registrationHandle ) ) ; } public void testAddRegistrationToInexistentConsumer ( ) throws RegistrationException { try { manager . addRegistrationTo ( "<STR_LIT>" , registrationProperties , expectations , false ) ; fail ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } assertNull ( manager . getConsumerByIdentity ( "<STR_LIT>" ) ) ; } public void testGetConsumerForNullRegistrationHandle ( ) throws Exception { try { manager . getConsumerFor ( null ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { } } public void testCreateConsumer ( ) throws Exception { String name = "<STR_LIT>" ; Consumer consumer = manager . createConsumer ( name ) ; assertNotNull ( consumer ) ; assertEquals ( name , consumer . getName ( ) ) ; assertNotNull ( consumer . getId ( ) ) ; assertNull ( consumer . getGroup ( ) ) ; Collection consumers = manager . getConsumers ( ) ; assertEquals ( <NUM_LIT:1> , consumers . size ( ) ) ; assertTrue ( consumers . contains ( consumer ) ) ; assertEquals ( consumer , manager . getConsumerByIdentity ( name ) ) ; try { consumers . add ( consumer ) ; fail ( "<STR_LIT>" ) ; } catch ( UnsupportedOperationException expected ) { } } public void testCreateConsumerWithGroupFromPolicy ( ) throws RegistrationException { DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy ( ) { public String getAutomaticGroupNameFor ( String consumerName ) { return "<STR_LIT>" + consumerName ; } } ; manager . setPolicy ( policy ) ; String name = "<STR_LIT:name>" ; Consumer consumer = manager . createConsumer ( name ) ; assertNotNull ( consumer ) ; ConsumerGroup group = manager . getConsumerGroup ( "<STR_LIT>" + name ) ; assertNotNull ( group ) ; assertEquals ( group , consumer . getGroup ( ) ) ; assertTrue ( group . getConsumers ( ) . contains ( consumer ) ) ; } public void testCreateDuplicateConsumer ( ) throws RegistrationException { String name = "<STR_LIT:name>" ; assertNotNull ( manager . createConsumer ( name ) ) ; try { manager . createConsumer ( name ) ; fail ( "<STR_LIT>" ) ; } catch ( DuplicateRegistrationException expected ) { } } public void testAddAutomaticallyCreatedConsumerToInexistentGroup ( ) throws RegistrationException { try { manager . addConsumerToGroupNamed ( "<STR_LIT:foo>" , "<STR_LIT:bar>" , false , true ) ; fail ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } assertNull ( manager . getConsumerByIdentity ( "<STR_LIT:foo>" ) ) ; assertNull ( manager . getConsumerGroup ( "<STR_LIT:bar>" ) ) ; } public void testAddInexistentConsumerToAutomaticallyCreatedGroup ( ) throws RegistrationException { try { manager . addConsumerToGroupNamed ( "<STR_LIT:foo>" , "<STR_LIT:bar>" , true , false ) ; fail ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } assertNull ( manager . getConsumerByIdentity ( "<STR_LIT:foo>" ) ) ; assertNull ( manager . getConsumerGroup ( "<STR_LIT:bar>" ) ) ; } public void testAddInexistentConsumerToGroup ( ) throws RegistrationException { manager . createConsumerGroup ( "<STR_LIT:bar>" ) ; try { manager . addConsumerToGroupNamed ( "<STR_LIT:foo>" , "<STR_LIT:bar>" , false , false ) ; fail ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } assertNull ( manager . getConsumerByIdentity ( "<STR_LIT:foo>" ) ) ; assertNotNull ( manager . getConsumerGroup ( "<STR_LIT:bar>" ) ) ; } public void testAddInexistentConsumerToInexistentGroup ( ) throws RegistrationException { try { manager . addConsumerToGroupNamed ( "<STR_LIT:foo>" , "<STR_LIT:bar>" , false , false ) ; fail ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } assertNull ( manager . getConsumerByIdentity ( "<STR_LIT:foo>" ) ) ; assertNull ( manager . getConsumerGroup ( "<STR_LIT:bar>" ) ) ; } public void testAddConsumerToGroup ( ) throws Exception { String groupName = "<STR_LIT>" ; String consumerName = "<STR_LIT>" ; Consumer consumer = manager . addConsumerToGroupNamed ( consumerName , groupName , true , true ) ; Consumer consumer1 = manager . getConsumerByIdentity ( consumerName ) ; assertNotNull ( consumer1 ) ; assertEquals ( consumer1 , consumer ) ; ConsumerGroup group = manager . getConsumerGroup ( groupName ) ; assertNotNull ( group ) ; assertEquals ( group , consumer . getGroup ( ) ) ; } public void testCreateConsumerGroup ( ) throws Exception { String groupName = "<STR_LIT:name>" ; ConsumerGroup group = manager . createConsumerGroup ( groupName ) ; assertNotNull ( group ) ; assertEquals ( groupName , group . getName ( ) ) ; Collection groups = manager . getConsumerGroups ( ) ; assertEquals ( <NUM_LIT:1> , groups . size ( ) ) ; assertTrue ( groups . contains ( group ) ) ; assertEquals ( group , manager . getConsumerGroup ( groupName ) ) ; try { groups . add ( group ) ; fail ( "<STR_LIT>" ) ; } catch ( UnsupportedOperationException expected ) { } } public void testRemoveConsumerGroup ( ) throws RegistrationException { String groupName = "<STR_LIT:name>" ; ConsumerGroup group = manager . createConsumerGroup ( groupName ) ; manager . removeConsumerGroup ( group ) ; assertNull ( manager . getConsumerGroup ( groupName ) ) ; manager . createConsumerGroup ( groupName ) ; manager . removeConsumerGroup ( groupName ) ; assertNull ( manager . getConsumerGroup ( groupName ) ) ; } public void testCascadeRemovalOnConsumerGroupRemoval ( ) throws Exception { String groupName = "<STR_LIT>" ; String consumerName = "<STR_LIT>" ; Consumer consumer = manager . addConsumerToGroupNamed ( consumerName , groupName , true , true ) ; String consumerIdentity = consumer . getId ( ) ; Registration reg = manager . addRegistrationTo ( consumerName , registrationProperties , expectations , false ) ; String handle = reg . getRegistrationHandle ( ) ; ConsumerGroup group = manager . getConsumerGroup ( groupName ) ; manager . removeConsumerGroup ( group ) ; assertNull ( manager . getConsumerByIdentity ( consumerIdentity ) ) ; assertNull ( manager . getRegistration ( handle ) ) ; } public void testCascadeRemovalOnConsumerRemoval ( ) throws Exception { String consumerName = "<STR_LIT>" ; Consumer consumer = manager . createConsumer ( consumerName ) ; String consumerIdentity = consumer . getId ( ) ; Registration reg = manager . addRegistrationTo ( consumerName , registrationProperties , expectations , false ) ; String handle = reg . getRegistrationHandle ( ) ; manager . removeConsumer ( consumer ) ; assertNull ( manager . getConsumerByIdentity ( consumerIdentity ) ) ; assertNull ( manager . getRegistration ( handle ) ) ; } public void testRemoveSingleRegistration ( ) throws Exception { String consumerName = "<STR_LIT>" ; Consumer consumer = manager . createConsumer ( consumerName ) ; Registration reg = manager . addRegistrationTo ( consumerName , registrationProperties , expectations , false ) ; String handle = reg . getRegistrationHandle ( ) ; assertTrue ( consumer . getRegistrations ( ) . contains ( reg ) ) ; manager . removeRegistration ( handle ) ; assertTrue ( ! consumer . getRegistrations ( ) . contains ( reg ) ) ; assertNull ( manager . getRegistration ( handle ) ) ; assertEquals ( RegistrationStatus . PENDING , consumer . getStatus ( ) ) ; assertNull ( manager . getConsumerFor ( handle ) ) ; } public void testRemoveRegistrationOnConsumerWithOtherRegistrations ( ) throws Exception { String consumerName = "<STR_LIT>" ; Consumer consumer = manager . createConsumer ( consumerName ) ; Registration reg = manager . addRegistrationTo ( consumerName , registrationProperties , expectations , false ) ; String handle = reg . getRegistrationHandle ( ) ; RegistrationStatus status = consumer . getStatus ( ) ; manager . removeRegistration ( handle ) ; assertEquals ( status , consumer . getStatus ( ) ) ; assertNull ( manager . getConsumerFor ( handle ) ) ; } public void testAddRegistrationWithInvalidRegistrationProperties ( ) throws Exception { String consumerName = "<STR_LIT>" ; Consumer consumer = manager . createConsumer ( consumerName ) ; registrationProperties . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) ; try { manager . addRegistrationTo ( consumerName , registrationProperties , expectations , false ) ; fail ( "<STR_LIT>" ) ; } catch ( RegistrationException e ) { assertTrue ( e . getMessage ( ) . contains ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:0> , consumer . getRegistrations ( ) . size ( ) ) ; } } public void testRemoveInexistentRegistration ( ) throws RegistrationException { try { manager . removeRegistration ( ( Registration ) null ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } try { manager . removeRegistration ( ( String ) null ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } try { manager . removeRegistration ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } try { manager . removeRegistration ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } } public void testClear ( ) throws Exception { manager . createConsumer ( "<STR_LIT>" ) ; manager . createConsumer ( "<STR_LIT>" ) ; manager . addConsumerToGroupNamed ( "<STR_LIT>" , "<STR_LIT>" , true , true ) ; manager . createConsumerGroup ( "<STR_LIT>" ) ; Registration r1 = manager . addRegistrationTo ( "<STR_LIT>" , registrationProperties , expectations , false ) ; Registration r2 = manager . addRegistrationTo ( "<STR_LIT>" , registrationProperties , expectations , true ) ; manager . clear ( ) ; assertTrue ( manager . getConsumerGroups ( ) . isEmpty ( ) ) ; assertTrue ( manager . getConsumers ( ) . isEmpty ( ) ) ; assertNull ( manager . getRegistration ( r1 . getRegistrationHandle ( ) ) ) ; assertNull ( manager . getRegistration ( r2 . getRegistrationHandle ( ) ) ) ; } } </s>
<s> package org . gatein . registration ; import junit . framework . TestCase ; import org . gatein . pc . api . PortletContext ; import org . gatein . registration . impl . RegistrationManagerImpl ; import org . gatein . registration . impl . RegistrationPersistenceManagerImpl ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import org . gatein . registration . spi . RegistrationSPI ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . registration . PropertyDescription ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import javax . xml . namespace . QName ; import java . util . HashMap ; import java . util . Map ; import java . util . Set ; public class RegistrationTestCase extends TestCase { private RegistrationSPI registration ; private Map < QName , Object > registrationProperties ; protected void setUp ( ) throws Exception { RegistrationManager manager = new RegistrationManagerImpl ( ) ; RegistrationPolicy policy = new DefaultRegistrationPolicy ( ) { public void validateRegistrationDataFor ( Map < QName , Object > registrationProperties , String consumerIdentity , final Map < QName , ? extends PropertyDescription > expectations , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException , DuplicateRegistrationException { } } ; manager . setPolicy ( policy ) ; manager . setPersistenceManager ( new RegistrationPersistenceManagerImpl ( ) ) ; registrationProperties = new HashMap < QName , Object > ( ) ; QName prop1Name = new QName ( "<STR_LIT>" ) ; registrationProperties . put ( prop1Name , "<STR_LIT:value1>" ) ; QName prop2Name = new QName ( "<STR_LIT>" ) ; registrationProperties . put ( prop2Name , "<STR_LIT>" ) ; Map < QName , RegistrationPropertyDescription > expectations = new HashMap < QName , RegistrationPropertyDescription > ( ) ; expectations . put ( prop1Name , new RegistrationPropertyDescription ( prop1Name , WSRPConstants . XSD_STRING ) ) ; expectations . put ( prop2Name , new RegistrationPropertyDescription ( prop2Name , WSRPConstants . XSD_STRING ) ) ; registration = ( RegistrationSPI ) manager . addRegistrationTo ( "<STR_LIT:name>" , registrationProperties , expectations , true ) ; } public void testGetPropertiesIsUnmodifiable ( ) { Map properties = registration . getProperties ( ) ; try { properties . remove ( "<STR_LIT:foo>" ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testPropertiesAreClonedNotLive ( ) { QName prop = new QName ( "<STR_LIT>" ) ; registrationProperties . put ( prop , "<STR_LIT>" ) ; assertNull ( registration . getProperties ( ) . get ( prop ) ) ; } public void testSetNullPropertyValueThrowsIAE ( ) { try { registration . setPropertyValueFor ( "<STR_LIT:foo>" , null ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testSetNullPropertyNameThrowsIAE ( ) { try { registration . setPropertyValueFor ( ( QName ) null , null ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testProperties ( ) { QName name = new QName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT:value1>" , registration . getProperties ( ) . get ( name ) ) ; assertEquals ( "<STR_LIT>" , registration . getProperties ( ) . get ( new QName ( "<STR_LIT>" ) ) ) ; String newValue = "<STR_LIT>" ; registration . setPropertyValueFor ( "<STR_LIT>" , newValue ) ; assertEquals ( newValue , registration . getProperties ( ) . get ( name ) ) ; registration . removeProperty ( name ) ; assertNull ( registration . getPropertyValueFor ( name ) ) ; } public void testUpdateProperties ( ) { registrationProperties . remove ( new QName ( "<STR_LIT>" ) ) ; registration . updateProperties ( registrationProperties ) ; assertNull ( registration . getPropertyValueFor ( "<STR_LIT>" ) ) ; QName name = new QName ( "<STR_LIT>" ) ; String value = "<STR_LIT>" ; registrationProperties . put ( name , value ) ; registration . updateProperties ( registrationProperties ) ; assertEquals ( value , registration . getPropertyValueFor ( name ) ) ; } public void testHasEqualProperties ( ) { assertTrue ( registration . hasEqualProperties ( registration ) ) ; assertTrue ( registration . hasEqualProperties ( registrationProperties ) ) ; registrationProperties . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertTrue ( ! registration . hasEqualProperties ( registrationProperties ) ) ; } public void testPortletContextOperations ( ) throws RegistrationException { PortletContext foo = PortletContext . createPortletContext ( "<STR_LIT>" , "<STR_LIT:foo>" ) ; registration . addPortletContext ( foo ) ; assertTrue ( registration . knows ( foo ) ) ; assertTrue ( registration . knows ( foo . getId ( ) ) ) ; Set < PortletContext > knownPortletContexts = registration . getKnownPortletContexts ( ) ; assertEquals ( <NUM_LIT:1> , knownPortletContexts . size ( ) ) ; assertTrue ( knownPortletContexts . contains ( foo ) ) ; registration . removePortletContext ( foo ) ; assertFalse ( registration . knows ( foo ) ) ; assertFalse ( registration . knows ( foo . getId ( ) ) ) ; knownPortletContexts = registration . getKnownPortletContexts ( ) ; assertTrue ( knownPortletContexts . isEmpty ( ) ) ; } } </s>
<s> package org . gatein . registration ; import org . gatein . registration . impl . RegistrationPersistenceManagerImpl ; public class RegistrationPersistenceManagerTestCase extends AbstractRegistrationPersistenceManagerTestCase { private RegistrationPersistenceManager manager ; public void setUp ( ) throws Exception { manager = new RegistrationPersistenceManagerImpl ( ) ; super . setUp ( ) ; } protected void tearDown ( ) throws Exception { super . tearDown ( ) ; this . manager = null ; } public RegistrationPersistenceManager getManager ( ) { return manager ; } } </s>
<s> package org . gatein . registration ; import junit . framework . TestCase ; import org . gatein . common . util . MapBuilder ; import javax . xml . namespace . QName ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; public abstract class AbstractRegistrationPersistenceManagerTestCase extends TestCase { private Map < QName , Object > registrationProperties ; public abstract RegistrationPersistenceManager getManager ( ) throws Exception ; public void setUp ( ) throws Exception { registrationProperties = new HashMap < QName , Object > ( ) ; registrationProperties . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT:value1>" ) ; registrationProperties . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) ; } protected void tearDown ( ) throws Exception { registrationProperties = null ; } public void testGetGroupThrowsIAE ( ) throws Exception { try { getManager ( ) . getConsumerGroup ( null ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testCreateConsumer ( ) throws Exception { Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; assertTrue ( getManager ( ) . isConsumerExisting ( "<STR_LIT>" ) ) ; assertFalse ( getManager ( ) . isConsumerExisting ( "<STR_LIT>" ) ) ; assertNotNull ( consumer ) ; assertEquals ( "<STR_LIT>" , consumer . getName ( ) ) ; assertTrue ( consumer . getRegistrations ( ) . isEmpty ( ) ) ; assertNull ( consumer . getGroup ( ) ) ; assertNotNull ( consumer . getPersistentKey ( ) ) ; assertNull ( consumer . getConsumerAgent ( ) ) ; assertNotNull ( consumer . getCapabilities ( ) ) ; assertEquals ( RegistrationStatus . PENDING , consumer . getStatus ( ) ) ; } public void testCreateConsumerThrowsIAE ( ) throws Exception { try { getManager ( ) . createConsumer ( null , "<STR_LIT:foo>" ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } try { getManager ( ) . createConsumer ( "<STR_LIT:foo>" , null ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testCreateDuplicatedConsumer ( ) throws Exception { getManager ( ) . createConsumer ( "<STR_LIT:id>" , "<STR_LIT:name>" ) ; assertTrue ( getManager ( ) . isConsumerExisting ( "<STR_LIT:id>" ) ) ; assertFalse ( getManager ( ) . isConsumerExisting ( "<STR_LIT:name>" ) ) ; try { getManager ( ) . createConsumer ( "<STR_LIT:id>" , "<STR_LIT>" ) ; fail ( ) ; } catch ( DuplicateRegistrationException expected ) { } getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT:name>" ) ; assertTrue ( getManager ( ) . isConsumerExisting ( "<STR_LIT>" ) ) ; } public void testCreateGroup ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; assertNotNull ( group ) ; assertNotNull ( group . getPersistentKey ( ) ) ; assertEquals ( "<STR_LIT>" , group . getName ( ) ) ; assertTrue ( group . getConsumers ( ) . isEmpty ( ) ) ; assertEquals ( RegistrationStatus . PENDING , group . getStatus ( ) ) ; } public void testCreateGroupThrowsIAE ( ) throws Exception { try { getManager ( ) . createConsumerGroup ( null ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testAddGroup ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; assertNotNull ( group ) ; group = getManager ( ) . getConsumerGroup ( "<STR_LIT>" ) ; assertNotNull ( group ) ; assertEquals ( "<STR_LIT>" , group . getName ( ) ) ; assertEquals ( Collections . EMPTY_LIST , new ArrayList ( group . getConsumers ( ) ) ) ; Collection groups = getManager ( ) . getConsumerGroups ( ) ; assertNotNull ( groups ) ; assertEquals ( <NUM_LIT:1> , groups . size ( ) ) ; group = ( ConsumerGroup ) groups . iterator ( ) . next ( ) ; assertNotNull ( group ) ; assertEquals ( "<STR_LIT>" , group . getName ( ) ) ; assertEquals ( Collections . EMPTY_LIST , new ArrayList ( group . getConsumers ( ) ) ) ; } public void testAddDuplicateGroup ( ) throws Exception { getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; try { getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; fail ( ) ; } catch ( DuplicateRegistrationException expected ) { } } public void testAddGroupThrowsIAE ( ) throws Exception { try { getManager ( ) . createConsumerGroup ( null ) ; } catch ( IllegalArgumentException expected ) { assertEquals ( Collections . EMPTY_SET , new HashSet ( getManager ( ) . getConsumerGroups ( ) ) ) ; } } public void testRemoveGroup ( ) throws Exception { getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; getManager ( ) . removeConsumerGroup ( "<STR_LIT>" ) ; assertNull ( getManager ( ) . getConsumerGroup ( "<STR_LIT>" ) ) ; assertEquals ( Collections . EMPTY_SET , new HashSet ( getManager ( ) . getConsumerGroups ( ) ) ) ; } public void testRemoveGroupThrowsIAE ( ) throws Exception { try { getManager ( ) . removeConsumerGroup ( null ) ; } catch ( IllegalArgumentException expected ) { } } public void testRemoveNonExistingGroup ( ) throws Exception { try { getManager ( ) . removeConsumerGroup ( "<STR_LIT>" ) ; } catch ( NoSuchRegistrationException expected ) { } } public void testGetConsumerThrowsIAE ( ) throws Exception { try { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; group . getConsumer ( null ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testAddConsumer ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; assertEquals ( "<STR_LIT>" , consumer . getGroup ( ) . getName ( ) ) ; consumer = group . getConsumer ( "<STR_LIT>" ) ; assertNotNull ( consumer ) ; assertEquals ( "<STR_LIT>" , consumer . getName ( ) ) ; assertEquals ( Collections . EMPTY_LIST , new ArrayList ( consumer . getRegistrations ( ) ) ) ; assertEquals ( "<STR_LIT>" , consumer . getGroup ( ) . getName ( ) ) ; Collection consumers = group . getConsumers ( ) ; assertNotNull ( consumers ) ; assertEquals ( <NUM_LIT:1> , consumers . size ( ) ) ; consumer = ( Consumer ) consumers . iterator ( ) . next ( ) ; assertNotNull ( consumer ) ; assertEquals ( "<STR_LIT>" , consumer . getName ( ) ) ; assertEquals ( Collections . EMPTY_LIST , new ArrayList ( consumer . getRegistrations ( ) ) ) ; assertEquals ( "<STR_LIT>" , consumer . getGroup ( ) . getName ( ) ) ; } public void testAddDuplicateConsumer ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; try { group . addConsumer ( consumer ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testAddConsumerThrowsIAE ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; try { group . addConsumer ( null ) ; } catch ( IllegalArgumentException expected ) { assertEquals ( Collections . EMPTY_SET , new HashSet ( group . getConsumers ( ) ) ) ; } } public void testRemoveConsumer ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; group . removeConsumer ( consumer ) ; assertNull ( group . getConsumer ( "<STR_LIT>" ) ) ; assertEquals ( Collections . EMPTY_SET , new HashSet ( group . getConsumers ( ) ) ) ; } public void testRemoveConsumerThrowsIAE ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; try { group . removeConsumer ( null ) ; } catch ( IllegalArgumentException expected ) { } } public void testAddRegistration ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; Registration reg1 = getManager ( ) . addRegistrationFor ( "<STR_LIT>" , registrationProperties ) ; assertNotNull ( reg1 ) ; String regId = reg1 . getPersistentKey ( ) ; assertNotNull ( regId ) ; assertEquals ( consumer , reg1 . getConsumer ( ) ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; assertEquals ( reg1 , consumer . getRegistration ( regId ) ) ; Map expectedProps = new HashMap ( ) ; expectedProps . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT:value1>" ) ; expectedProps . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) ; assertEquals ( expectedProps , reg1 . getProperties ( ) ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; Collection registrations = consumer . getRegistrations ( ) ; assertNotNull ( registrations ) ; assertEquals ( <NUM_LIT:1> , registrations . size ( ) ) ; Registration reg3 = ( Registration ) registrations . iterator ( ) . next ( ) ; assertEquals ( reg1 , reg3 ) ; assertEquals ( regId , reg3 . getPersistentKey ( ) ) ; assertEquals ( consumer , reg3 . getConsumer ( ) ) ; assertEquals ( expectedProps , reg3 . getProperties ( ) ) ; Registration reg2 = getManager ( ) . getRegistration ( regId ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; assertNotNull ( reg2 ) ; assertEquals ( regId , reg2 . getPersistentKey ( ) ) ; assertEquals ( consumer , reg2 . getConsumer ( ) ) ; assertEquals ( expectedProps , reg2 . getProperties ( ) ) ; } public void testAddRegistrationThrowsIAE ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; try { getManager ( ) . addRegistrationFor ( consumer . getId ( ) , null ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testRemoveRegistrationThrowsIAE ( ) throws Exception { try { getManager ( ) . removeRegistration ( null ) ; fail ( ) ; } catch ( IllegalArgumentException expected ) { } } public void testRemoveRegistration ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; Registration reg = getManager ( ) . addRegistrationFor ( "<STR_LIT>" , registrationProperties ) ; String regId = reg . getPersistentKey ( ) ; getManager ( ) . removeRegistration ( regId ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; Collection registrations = consumer . getRegistrations ( ) ; assertNotNull ( registrations ) ; assertEquals ( <NUM_LIT:0> , registrations . size ( ) ) ; assertEquals ( null , getManager ( ) . getRegistration ( regId ) ) ; } public void testBulkUpdateRegistrationProperties ( ) throws Exception { ConsumerGroup group = getManager ( ) . createConsumerGroup ( "<STR_LIT>" ) ; Consumer consumer = getManager ( ) . createConsumer ( "<STR_LIT>" , "<STR_LIT>" ) ; group . addConsumer ( consumer ) ; getManager ( ) . addRegistrationFor ( "<STR_LIT>" , registrationProperties ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; Registration reg = consumer . getRegistrations ( ) . iterator ( ) . next ( ) ; registrationProperties . remove ( new QName ( "<STR_LIT>" ) ) ; reg . updateProperties ( registrationProperties ) ; assertEquals ( Collections . singletonMap ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) , reg . getProperties ( ) ) ; getManager ( ) . saveChangesTo ( reg ) ; final Registration registration = getManager ( ) . getRegistration ( reg . getPersistentKey ( ) ) ; assertEquals ( reg . getProperties ( ) , registration . getProperties ( ) ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; reg = consumer . getRegistrations ( ) . iterator ( ) . next ( ) ; assertEquals ( Collections . singletonMap ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) , reg . getProperties ( ) ) ; registrationProperties . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) ; reg . updateProperties ( registrationProperties ) ; assertEquals ( MapBuilder . hashMap ( ) . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) . get ( ) , reg . getProperties ( ) ) ; getManager ( ) . saveChangesTo ( reg ) ; consumer = getManager ( ) . getConsumerById ( "<STR_LIT>" ) ; reg = consumer . getRegistrations ( ) . iterator ( ) . next ( ) ; assertEquals ( MapBuilder . hashMap ( ) . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) . put ( new QName ( "<STR_LIT>" ) , "<STR_LIT>" ) . get ( ) , reg . getProperties ( ) ) ; } } </s>
<s> package org . gatein . registration ; import junit . framework . TestCase ; import org . gatein . registration . impl . RegistrationManagerImpl ; import org . gatein . registration . impl . RegistrationPersistenceManagerImpl ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import org . gatein . registration . policies . DefaultRegistrationPropertyValidator ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import javax . xml . namespace . QName ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; public class ConsumerTestCase extends TestCase { private Consumer consumer ; private RegistrationManager manager ; private static final Map < QName , RegistrationPropertyDescription > EMPTY_EXPECTATIONS = Collections . emptyMap ( ) ; protected void setUp ( ) throws Exception { manager = new RegistrationManagerImpl ( ) ; DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy ( ) ; policy . setValidator ( new DefaultRegistrationPropertyValidator ( ) ) ; manager . setPolicy ( policy ) ; manager . setPersistenceManager ( new RegistrationPersistenceManagerImpl ( ) ) ; consumer = manager . createConsumer ( "<STR_LIT:name>" ) ; } public void testGetName ( ) { assertEquals ( "<STR_LIT:name>" , consumer . getName ( ) ) ; } public void testStatus ( ) throws RegistrationException { assertEquals ( RegistrationStatus . PENDING , consumer . getStatus ( ) ) ; String name = consumer . getName ( ) ; Registration registration = manager . addRegistrationTo ( name , Collections . < QName , Object > emptyMap ( ) , EMPTY_EXPECTATIONS , false ) ; assertEquals ( RegistrationStatus . PENDING , consumer . getStatus ( ) ) ; registration . setStatus ( RegistrationStatus . VALID ) ; assertEquals ( RegistrationStatus . VALID , consumer . getStatus ( ) ) ; Map < QName , Object > props = new HashMap < QName , Object > ( <NUM_LIT:1> ) ; QName propName = new QName ( "<STR_LIT>" ) ; props . put ( propName , "<STR_LIT:value>" ) ; Map < QName , RegistrationPropertyDescription > expectations = new HashMap < QName , RegistrationPropertyDescription > ( ) ; expectations . put ( propName , new RegistrationPropertyDescription ( propName , WSRPConstants . XSD_STRING ) ) ; registration = manager . addRegistrationTo ( name , props , expectations , false ) ; assertEquals ( <NUM_LIT:2> , consumer . getRegistrations ( ) . size ( ) ) ; assertEquals ( RegistrationStatus . PENDING , consumer . getStatus ( ) ) ; registration . setStatus ( RegistrationStatus . INVALID ) ; assertEquals ( RegistrationStatus . INVALID , consumer . getStatus ( ) ) ; registration . setStatus ( RegistrationStatus . PENDING ) ; assertEquals ( RegistrationStatus . PENDING , consumer . getStatus ( ) ) ; registration . setStatus ( RegistrationStatus . VALID ) ; assertEquals ( RegistrationStatus . VALID , consumer . getStatus ( ) ) ; } public void testSetGroup ( ) throws Exception { ConsumerGroup group = manager . createConsumerGroup ( "<STR_LIT>" ) ; assertTrue ( ! group . getConsumers ( ) . contains ( consumer ) ) ; consumer . setGroup ( group ) ; assertEquals ( group , consumer . getGroup ( ) ) ; assertTrue ( group . getConsumers ( ) . contains ( consumer ) ) ; consumer . setGroup ( null ) ; assertNull ( consumer . getGroup ( ) ) ; assertTrue ( ! group . getConsumers ( ) . contains ( consumer ) ) ; } public void testGetIdentity ( ) throws Exception { assertNotNull ( consumer . getId ( ) ) ; } } </s>
<s> package org . gatein . registration ; import junit . framework . TestCase ; import org . gatein . registration . impl . RegistrationManagerImpl ; import org . gatein . registration . impl . RegistrationPersistenceManagerImpl ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; public class ConsumerGroupTestCase extends TestCase { private RegistrationManager manager ; private ConsumerGroup group ; private static final String NAME = "<STR_LIT:name>" ; protected void setUp ( ) throws Exception { manager = new RegistrationManagerImpl ( ) ; RegistrationPolicy policy = new DefaultRegistrationPolicy ( ) ; manager . setPolicy ( policy ) ; manager . setPersistenceManager ( new RegistrationPersistenceManagerImpl ( ) ) ; group = manager . createConsumerGroup ( NAME ) ; } public void testGetName ( ) { assertEquals ( NAME , group . getName ( ) ) ; } public void testConsumersManagement ( ) throws RegistrationException { assertTrue ( group . isEmpty ( ) ) ; assertEquals ( <NUM_LIT:0> , group . getConsumers ( ) . size ( ) ) ; Consumer c1 = manager . createConsumer ( "<STR_LIT>" ) ; group . addConsumer ( c1 ) ; assertTrue ( ! group . isEmpty ( ) ) ; assertEquals ( <NUM_LIT:1> , group . getConsumers ( ) . size ( ) ) ; assertTrue ( group . contains ( c1 ) ) ; assertEquals ( group , c1 . getGroup ( ) ) ; assertEquals ( c1 , group . getConsumer ( c1 . getId ( ) ) ) ; Consumer c2 = manager . createConsumer ( "<STR_LIT>" ) ; group . addConsumer ( c2 ) ; assertEquals ( <NUM_LIT:2> , group . getConsumers ( ) . size ( ) ) ; assertTrue ( group . contains ( c2 ) ) ; assertEquals ( group , c2 . getGroup ( ) ) ; group . removeConsumer ( c1 ) ; assertEquals ( <NUM_LIT:1> , group . getConsumers ( ) . size ( ) ) ; assertTrue ( ! group . contains ( c1 ) ) ; assertTrue ( group . contains ( c2 ) ) ; assertEquals ( null , c1 . getGroup ( ) ) ; } public void testAddNullConsumer ( ) throws RegistrationException { try { group . addConsumer ( null ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } } public void testStatus ( ) { assertEquals ( RegistrationStatus . PENDING , group . getStatus ( ) ) ; group . setStatus ( RegistrationStatus . VALID ) ; assertEquals ( RegistrationStatus . VALID , group . getStatus ( ) ) ; } public void testIllegalStatus ( ) { try { group . setStatus ( null ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException expected ) { } } } </s>
<s> package org . gatein . wsrp . registration ; import junit . framework . TestCase ; import org . gatein . wsrp . WSRPConstants ; import javax . xml . namespace . QName ; import java . util . Locale ; public class RegistrationPropertyDescriptionTestCase extends TestCase { private RegistrationPropertyDescription desc ; protected void setUp ( ) throws Exception { desc = new RegistrationPropertyDescription ( "<STR_LIT:foo>" , WSRPConstants . XSD_STRING ) ; } public void testNotify ( ) { TestParent parent = new TestParent ( ) ; desc . setValueChangeListener ( parent ) ; desc . setDefaultHint ( null ) ; assertFalse ( parent . notifyCalled ) ; parent . resetNotifyCalled ( ) ; desc . setDefaultHint ( "<STR_LIT>" ) ; assertTrue ( parent . notifyCalled ) ; } public void testChangingNameUpdatesParent ( ) { TestParent parent = new TestParent ( ) ; desc . setValueChangeListener ( parent ) ; assertNotNull ( parent . getRegistrationPropertyWith ( "<STR_LIT:foo>" ) ) ; desc . setName ( QName . valueOf ( "<STR_LIT:bar>" ) ) ; assertEquals ( desc , parent . getRegistrationPropertyWith ( "<STR_LIT:bar>" ) ) ; assertNull ( parent . getRegistrationPropertyWith ( "<STR_LIT:foo>" ) ) ; } public void testModifyIfNeeded ( ) { String oldValue = "<STR_LIT>" ; String newValue = "<STR_LIT>" ; assertEquals ( oldValue , desc . modifyIfNeeded ( oldValue , oldValue ) ) ; assertEquals ( newValue , desc . modifyIfNeeded ( oldValue , newValue ) ) ; assertEquals ( null , desc . modifyIfNeeded ( null , null ) ) ; assertEquals ( newValue , desc . modifyIfNeeded ( null , newValue ) ) ; assertEquals ( null , desc . modifyIfNeeded ( oldValue , null ) ) ; } public void testGetLang ( ) { assertEquals ( Locale . getDefault ( ) , desc . getLang ( ) ) ; desc . setLabel ( new LocalizedString ( "<STR_LIT>" , Locale . FRENCH ) ) ; assertEquals ( Locale . FRENCH , desc . getLang ( ) ) ; } class TestParent implements ValueChangeListener { private boolean notifyCalled ; private String propName = "<STR_LIT:foo>" ; void resetNotifyCalled ( ) { notifyCalled = false ; } public RegistrationPropertyDescription getRegistrationPropertyWith ( String name ) { if ( propName . equals ( name ) ) { return desc ; } return null ; } public void valueHasChanged ( RegistrationPropertyDescription originating , Object oldValue , Object newValue , boolean isName ) { String oldValueString = oldValue == null ? null : oldValue . toString ( ) ; if ( "<STR_LIT:foo>" . equals ( oldValueString ) ) { propName = originating . getName ( ) . getLocalPart ( ) ; } notifyCalled = true ; } } } </s>
<s> package org . gatein . wsrp . producer . invoker ; import junit . framework . TestCase ; import org . gatein . pc . api . Portlet ; import org . gatein . pc . api . PortletContext ; import org . gatein . pc . api . PortletInvoker ; import org . gatein . pc . api . PortletInvokerException ; import org . gatein . registration . impl . RegistrationManagerImpl ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import static org . mockito . Mockito . mock ; import static org . mockito . Mockito . when ; public class RegistrationCheckingPortletInvokerTestCase extends TestCase { public void testGetPortletShouldWorkDirectly ( ) throws PortletInvokerException { RegistrationCheckingPortletInvoker invoker = new RegistrationCheckingPortletInvoker ( ) ; RegistrationManagerImpl registrationManager = new RegistrationManagerImpl ( ) ; registrationManager . setPolicy ( new DefaultRegistrationPolicy ( ) ) ; invoker . setRegistrationManager ( registrationManager ) ; PortletInvoker next = mock ( PortletInvoker . class ) ; PortletContext portletContext = PortletContext . createPortletContext ( "<STR_LIT>" , "<STR_LIT>" ) ; Portlet portlet = mock ( Portlet . class ) ; when ( next . getPortlet ( portletContext ) ) . thenReturn ( portlet ) ; invoker . setNext ( next ) ; assertEquals ( portlet , invoker . getPortlet ( portletContext ) ) ; } } </s>
<s> package org . gatein . wsrp . producer . config ; import org . xml . sax . EntityResolver ; import org . xml . sax . InputSource ; import org . xml . sax . SAXException ; import java . io . IOException ; import java . io . InputStream ; public class TestEntityResolver implements EntityResolver { private static final String CONSUMER = "<STR_LIT>" ; private static final String PRODUCER = "<STR_LIT>" ; public InputSource resolveEntity ( String publicId , String systemId ) throws SAXException , IOException { String dtd ; if ( PRODUCER . equals ( publicId ) ) { dtd = "<STR_LIT>" ; } else if ( CONSUMER . equals ( publicId ) ) { dtd = "<STR_LIT>" ; } else { return null ; } InputStream dtdStream = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( dtd ) ; if ( dtdStream != null ) { return new InputSource ( dtdStream ) ; } return null ; } } </s>
<s> package org . gatein . wsrp . producer . config ; import junit . framework . TestCase ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import org . gatein . registration . policies . DefaultRegistrationPropertyValidator ; import org . gatein . registration . policies . RegistrationPolicyWrapper ; import org . gatein . registration . policies . RegistrationPropertyValidator ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . api . plugins . PluginsAccess ; import org . gatein . wsrp . producer . config . impl . ProducerConfigurationImpl ; import org . gatein . wsrp . producer . config . impl . xml . ProducerConfigurationProvider ; import org . gatein . wsrp . registration . LocalizedString ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import org . jboss . xb . binding . ObjectModelProvider ; import org . jboss . xb . binding . XercesXsMarshaller ; import org . jboss . xb . binding . sunday . unmarshalling . DefaultSchemaResolver ; import org . xml . sax . SAXException ; import javax . xml . namespace . QName ; import javax . xml . parsers . ParserConfigurationException ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . Reader ; import java . io . StringWriter ; import java . io . Writer ; import java . net . URL ; import java . util . Locale ; import java . util . Map ; public abstract class ProducerConfigurationTestCase extends TestCase { private static DefaultSchemaResolver RESOLVER ; static { RESOLVER = new DefaultSchemaResolver ( ) ; RESOLVER . setCacheResolvedSchemas ( true ) ; RESOLVER . addSchemaLocation ( "<STR_LIT>" , "<STR_LIT>" ) ; RESOLVER . addSchemaLocation ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( PluginsAccess . getPlugins ( ) == null ) { PluginsAccess . register ( new TestPlugins ( ) ) ; } } public void testCustomPolicyUnmarshalling ( ) throws Exception { ProducerConfiguration producerConfiguration = getProducerConfiguration ( "<STR_LIT>" ) ; assertTrue ( producerConfiguration . isUsingStrictMode ( ) ) ; ProducerRegistrationRequirements requirements = producerConfiguration . getRegistrationRequirements ( ) ; assertNotNull ( requirements ) ; RegistrationPolicy policy = requirements . getPolicy ( ) ; assertTrue ( policy . isWrapped ( ) ) ; assertFalse ( policy instanceof TestRegistrationPolicy ) ; assertEquals ( TestRegistrationPolicy . class , RegistrationPolicyWrapper . unwrap ( policy ) . getClass ( ) ) ; } public void testExtendedUnmarshalling ( ) throws Exception { ProducerConfiguration producerConfiguration = getProducerConfiguration ( "<STR_LIT>" ) ; assertTrue ( producerConfiguration . isUsingStrictMode ( ) ) ; ProducerRegistrationRequirements requirements = producerConfiguration . getRegistrationRequirements ( ) ; assertNotNull ( requirements ) ; RegistrationPolicy policy = RegistrationPolicyWrapper . unwrap ( requirements . getPolicy ( ) ) ; assertTrue ( policy instanceof DefaultRegistrationPolicy ) ; RegistrationPropertyValidator propertyValidator = ( ( DefaultRegistrationPolicy ) policy ) . getValidator ( ) ; assertNotNull ( propertyValidator ) ; assertTrue ( propertyValidator instanceof DefaultRegistrationPropertyValidator ) ; assertTrue ( requirements . isRegistrationRequired ( ) ) ; assertTrue ( requirements . isRegistrationRequiredForFullDescription ( ) ) ; Map properties = requirements . getRegistrationProperties ( ) ; assertNotNull ( properties ) ; assertEquals ( <NUM_LIT:2> , properties . size ( ) ) ; checkRegistrationProperty ( requirements , <NUM_LIT:1> ) ; checkRegistrationProperty ( requirements , <NUM_LIT:2> ) ; } public void testMinimalRegistrationUnmarshalling ( ) throws Exception { ProducerConfiguration producerConfiguration = getProducerConfiguration ( "<STR_LIT>" ) ; assertTrue ( producerConfiguration . isUsingStrictMode ( ) ) ; ProducerRegistrationRequirements requirements = producerConfiguration . getRegistrationRequirements ( ) ; assertNotNull ( requirements ) ; assertTrue ( requirements . isRegistrationRequired ( ) ) ; assertTrue ( ! requirements . isRegistrationRequiredForFullDescription ( ) ) ; Map properties = requirements . getRegistrationProperties ( ) ; assertNotNull ( properties ) ; assertTrue ( properties . isEmpty ( ) ) ; assertNotNull ( requirements . getPolicy ( ) ) ; } public void testMinimalUnmarshalling ( ) throws Exception { ProducerConfiguration producerConfiguration = getProducerConfiguration ( "<STR_LIT>" ) ; assertTrue ( producerConfiguration . isUsingStrictMode ( ) ) ; ProducerRegistrationRequirements requirements = producerConfiguration . getRegistrationRequirements ( ) ; assertNotNull ( requirements ) ; assertFalse ( requirements . isRegistrationRequired ( ) ) ; assertFalse ( requirements . isRegistrationRequiredForFullDescription ( ) ) ; assertTrue ( requirements . getRegistrationProperties ( ) . isEmpty ( ) ) ; assertNotNull ( requirements . getPolicy ( ) ) ; } public void testInvalidMultipleRegistrationConfiguration ( ) throws Exception { try { getProducerConfiguration ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testInvalidTypeValue ( ) throws Exception { try { getProducerConfiguration ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testInvalidPropertyValidator ( ) { try { getProducerConfiguration ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testInvalidFullServiceDescriptionValue ( ) { try { getProducerConfiguration ( "<STR_LIT>" ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception expected ) { } } public void testUseStrictMode ( ) throws Exception { ProducerConfiguration producerConfiguration = getProducerConfiguration ( "<STR_LIT>" ) ; assertFalse ( producerConfiguration . isUsingStrictMode ( ) ) ; } public void testChangeListeners ( ) throws Exception { ProducerConfiguration producerConfiguration = getProducerConfiguration ( "<STR_LIT>" ) ; assertTrue ( producerConfiguration . isUsingStrictMode ( ) ) ; TestProducerConfigurationChangeListener listener = new TestProducerConfigurationChangeListener ( ) ; producerConfiguration . addChangeListener ( listener ) ; assertFalse ( listener . called ) ; producerConfiguration . setUsingStrictMode ( true ) ; assertFalse ( listener . called ) ; producerConfiguration . setUsingStrictMode ( false ) ; assertFalse ( producerConfiguration . isUsingStrictMode ( ) ) ; assertTrue ( listener . called ) ; } public void testSaveAndReload ( ) throws Exception { ProducerConfiguration configuration = new ProducerConfigurationImpl ( ) ; configuration . setUsingStrictMode ( false ) ; ProducerRegistrationRequirements registrationRequirements = configuration . getRegistrationRequirements ( ) ; registrationRequirements . setRegistrationRequiredForFullDescription ( true ) ; registrationRequirements . setRegistrationRequired ( true ) ; String prop1 = "<STR_LIT>" ; registrationRequirements . addEmptyRegistrationProperty ( prop1 ) ; registrationRequirements . getRegistrationPropertyWith ( prop1 ) . setDefaultLabel ( "<STR_LIT>" ) ; String prop2 = "<STR_LIT>" ; registrationRequirements . addEmptyRegistrationProperty ( prop2 ) ; registrationRequirements . getRegistrationPropertyWith ( prop2 ) . setDefaultHint ( "<STR_LIT>" ) ; String prop3 = "<STR_LIT>" ; registrationRequirements . addEmptyRegistrationProperty ( prop3 ) ; registrationRequirements . getRegistrationPropertyWith ( prop3 ) . setDefaultDescription ( "<STR_LIT>" ) ; String prop4 = "<STR_LIT>" ; registrationRequirements . addEmptyRegistrationProperty ( prop4 ) ; RegistrationPropertyDescription propDesc4 = registrationRequirements . getRegistrationPropertyWith ( prop4 ) ; propDesc4 . setDefaultLabel ( "<STR_LIT>" ) ; propDesc4 . setDefaultHint ( "<STR_LIT>" ) ; propDesc4 . setDefaultDescription ( "<STR_LIT>" ) ; File tmp = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; tmp . deleteOnExit ( ) ; writeConfigToFile ( configuration , tmp ) ; configuration = getProducerConfiguration ( tmp . toURI ( ) . toURL ( ) ) ; assertFalse ( configuration . isUsingStrictMode ( ) ) ; registrationRequirements = configuration . getRegistrationRequirements ( ) ; assertTrue ( registrationRequirements . isRegistrationRequired ( ) ) ; assertTrue ( registrationRequirements . isRegistrationRequiredForFullDescription ( ) ) ; assertEquals ( <NUM_LIT:4> , registrationRequirements . getRegistrationProperties ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , registrationRequirements . getRegistrationPropertyWith ( prop1 ) . getLabel ( ) . getValue ( ) ) ; assertEquals ( "<STR_LIT>" , registrationRequirements . getRegistrationPropertyWith ( prop2 ) . getHint ( ) . getValue ( ) ) ; assertEquals ( "<STR_LIT>" , registrationRequirements . getRegistrationPropertyWith ( prop3 ) . getDescription ( ) . getValue ( ) ) ; propDesc4 = registrationRequirements . getRegistrationPropertyWith ( prop4 ) ; assertEquals ( "<STR_LIT>" , propDesc4 . getLabel ( ) . getValue ( ) ) ; assertEquals ( "<STR_LIT>" , propDesc4 . getHint ( ) . getValue ( ) ) ; assertEquals ( "<STR_LIT>" , propDesc4 . getDescription ( ) . getValue ( ) ) ; } private void writeConfigToFile ( ProducerConfiguration configuration , File file ) throws IOException , ParserConfigurationException , SAXException { StringWriter xmlOutput = new StringWriter ( ) ; InputStream is = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( "<STR_LIT>" ) ; Reader xsReader = new InputStreamReader ( is ) ; XercesXsMarshaller marshaller = new XercesXsMarshaller ( ) ; marshaller . setSchemaResolver ( RESOLVER ) ; marshaller . addRootElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; marshaller . declareNamespace ( "<STR_LIT>" , "<STR_LIT>" ) ; marshaller . declareNamespace ( "<STR_LIT>" , "<STR_LIT>" ) ; marshaller . addAttribute ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:string>" , "<STR_LIT>" ) ; ObjectModelProvider provider = new ProducerConfigurationProvider ( ) ; marshaller . setProperty ( "<STR_LIT>" , "<STR_LIT:true>" ) ; marshaller . marshal ( xsReader , provider , configuration , xmlOutput ) ; xsReader . close ( ) ; file . createNewFile ( ) ; Writer configFile = new BufferedWriter ( new FileWriter ( file ) ) ; configFile . write ( xmlOutput . toString ( ) ) ; configFile . flush ( ) ; configFile . close ( ) ; } protected ProducerConfiguration getProducerConfiguration ( String fileName ) throws Exception { URL location = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( fileName ) ; assertNotNull ( location ) ; System . out . println ( "<STR_LIT>" + location ) ; return getProducerConfiguration ( location ) ; } protected abstract ProducerConfiguration getProducerConfiguration ( URL location ) throws Exception ; private void checkRegistrationProperty ( ProducerRegistrationRequirements requirements , int index ) { RegistrationPropertyDescription desc = requirements . getRegistrationPropertyWith ( "<STR_LIT:name>" + index ) ; assertNotNull ( desc ) ; assertEquals ( new QName ( "<STR_LIT:name>" + index ) , desc . getName ( ) ) ; assertEquals ( WSRPConstants . XSD_STRING , desc . getType ( ) ) ; LocalizedString localizedString = new LocalizedString ( "<STR_LIT>" + index , Locale . ENGLISH ) ; localizedString . setResourceName ( "<STR_LIT>" + index ) ; localizedString . setValue ( "<STR_LIT>" + index ) ; assertEquals ( localizedString , desc . getHint ( ) ) ; localizedString = new LocalizedString ( "<STR_LIT:label>" + index , Locale . ENGLISH ) ; localizedString . setResourceName ( "<STR_LIT>" + index ) ; localizedString . setValue ( "<STR_LIT:label>" + index ) ; assertEquals ( localizedString , desc . getLabel ( ) ) ; } private static class TestProducerConfigurationChangeListener implements ProducerConfigurationChangeListener { boolean called = false ; public void usingStrictModeChangedTo ( boolean strictMode ) { called = true ; } } } </s>
<s> package org . gatein . wsrp . producer . config ; import org . gatein . registration . policies . RegistrationPropertyValidator ; import javax . xml . namespace . QName ; public class TestRegistrationPropertyValidator implements RegistrationPropertyValidator { public void validateValueFor ( QName propertyName , Object value ) throws IllegalArgumentException { System . out . println ( "<STR_LIT>" + propertyName + "<STR_LIT>" + value ) ; if ( ! ( value instanceof String ) || ! ( ( String ) value ) . contains ( "<STR_LIT:test>" ) ) { throw new IllegalArgumentException ( value + "<STR_LIT>" + propertyName + "<STR_LIT>" ) ; } } } </s>
<s> package org . gatein . wsrp . producer . config ; import junit . framework . TestCase ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; public class RegistrationPropertyDescriptionTestCase extends TestCase { public void testEquals ( ) { RegistrationPropertyDescription foo1 = new RegistrationPropertyDescription ( "<STR_LIT:foo>" , WSRPConstants . XSD_STRING ) ; RegistrationPropertyDescription foo2 = new RegistrationPropertyDescription ( "<STR_LIT:foo>" , WSRPConstants . XSD_STRING ) ; assertEquals ( foo1 , foo2 ) ; assertEquals ( foo1 , new RegistrationPropertyDescription ( foo1 ) ) ; } } </s>
<s> package org . gatein . wsrp . producer . config ; import org . gatein . wsrp . ResourceFinder ; import org . gatein . wsrp . api . plugins . AbstractPlugins ; import java . io . IOException ; import java . util . ArrayList ; import java . util . List ; public class TestPlugins extends AbstractPlugins { private final ResourceFinder resourceFinder ; public TestPlugins ( ) { resourceFinder = new ResourceFinder ( "<STR_LIT>" ) ; } @ Override protected List < String > getImplementationNamesFor ( String pluginClassName , String defaultImplementationClassName ) { try { final List < String > allStrings = resourceFinder . findAllStrings ( pluginClassName ) ; List < String > implementations = new ArrayList < String > ( allStrings . size ( ) + <NUM_LIT:1> ) ; implementations . add ( defaultImplementationClassName ) ; return implementations ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } @ Override protected < T > Class < ? extends T > getImplementationNamed ( String className , Class < T > pluginClass ) throws ClassNotFoundException { try { return resourceFinder . findClass ( className , pluginClass ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } } </s>
<s> package org . gatein . wsrp . producer . config ; import junit . framework . TestCase ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . registration . RegistrationPolicyChangeListener ; import org . gatein . registration . RegistrationPropertyChangeListener ; import org . gatein . registration . policies . DefaultRegistrationPolicy ; import org . gatein . registration . policies . DefaultRegistrationPropertyValidator ; import org . gatein . registration . policies . RegistrationPolicyWrapper ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . api . plugins . PluginsAccess ; import org . gatein . wsrp . producer . config . impl . ProducerRegistrationRequirementsImpl ; import org . gatein . wsrp . registration . PropertyDescription ; import org . gatein . wsrp . registration . RegistrationPropertyDescription ; import javax . xml . namespace . QName ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; public class ProducerRegistrationRequirementsTestCase extends TestCase { static { if ( PluginsAccess . getPlugins ( ) == null ) { PluginsAccess . register ( new TestPlugins ( ) ) ; } } public void testSetRegistrationProperties ( ) { ProducerRegistrationRequirements requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . addEmptyRegistrationProperty ( "<STR_LIT:foo>" ) ; requirements . addEmptyRegistrationProperty ( "<STR_LIT:bar>" ) ; final Map < QName , RegistrationPropertyDescription > expected = new HashMap < QName , RegistrationPropertyDescription > ( ) ; RegistrationPropertyDescription newFoo = new RegistrationPropertyDescription ( "<STR_LIT>" , WSRPConstants . XSD_STRING ) ; expected . put ( newFoo . getName ( ) , newFoo ) ; long lastModified = requirements . getLastModified ( ) ; requirements . addRegistrationPropertyChangeListener ( new RegistrationPropertyChangeListener ( ) { public void propertiesHaveChanged ( Map < QName , ? extends PropertyDescription > newRegistrationProperties ) { assertEquals ( expected , newRegistrationProperties ) ; } } ) ; requirements . setRegistrationProperties ( expected ) ; assertTrue ( requirements . getLastModified ( ) > lastModified ) ; } public void testChangeRegistrationPolicy ( ) { ProducerRegistrationRequirementsImpl requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . setRegistrationRequired ( true ) ; RegistrationPolicy policy = requirements . getPolicy ( ) ; assertTrue ( policy . isWrapped ( ) ) ; assertFalse ( policy instanceof DefaultRegistrationPolicy ) ; assertEquals ( ProducerRegistrationRequirements . DEFAULT_POLICY_CLASS_NAME , policy . getClassName ( ) ) ; requirements . reloadPolicyFrom ( "<STR_LIT>" , ProducerRegistrationRequirements . DEFAULT_VALIDATOR_CLASS_NAME ) ; policy = requirements . getPolicy ( ) ; assertTrue ( policy . isWrapped ( ) ) ; assertFalse ( policy instanceof TestRegistrationPolicy ) ; assertEquals ( "<STR_LIT>" , requirements . getPolicyClassName ( ) ) ; assertEquals ( "<STR_LIT>" , policy . getClassName ( ) ) ; assertNull ( requirements . getValidatorClassName ( ) ) ; } public void testChangeToDefaultPolicyWithEmptyValidatorName ( ) { ProducerRegistrationRequirementsImpl requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . setRegistrationRequired ( true ) ; requirements . reloadPolicyFrom ( ProducerRegistrationRequirements . DEFAULT_POLICY_CLASS_NAME , "<STR_LIT>" ) ; RegistrationPolicy policy = requirements . getPolicy ( ) ; assertEquals ( ProducerRegistrationRequirements . DEFAULT_POLICY_CLASS_NAME , policy . getClassName ( ) ) ; assertEquals ( ProducerRegistrationRequirements . DEFAULT_VALIDATOR_CLASS_NAME , requirements . getValidatorClassName ( ) ) ; DefaultRegistrationPolicy unwrap = ( DefaultRegistrationPolicy ) RegistrationPolicyWrapper . unwrap ( policy ) ; assertTrue ( unwrap . getValidator ( ) instanceof DefaultRegistrationPropertyValidator ) ; } public void testSetUnchangedRegistrationProperties ( ) { ProducerRegistrationRequirements requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . addEmptyRegistrationProperty ( "<STR_LIT:foo>" ) ; final Map < QName , RegistrationPropertyDescription > expected = new HashMap < QName , RegistrationPropertyDescription > ( ) ; RegistrationPropertyDescription newFoo = new RegistrationPropertyDescription ( "<STR_LIT:foo>" , WSRPConstants . XSD_STRING ) ; expected . put ( newFoo . getName ( ) , newFoo ) ; long lastModified = requirements . getLastModified ( ) ; requirements . addRegistrationPropertyChangeListener ( new RegistrationPropertyChangeListener ( ) { public void propertiesHaveChanged ( Map < QName , ? extends PropertyDescription > newRegistrationProperties ) { fail ( "<STR_LIT>" ) ; } } ) ; requirements . setRegistrationProperties ( expected ) ; assertEquals ( lastModified , requirements . getLastModified ( ) ) ; } public void testSetRegistrationPropertiesPropertyRemoval ( ) { ProducerRegistrationRequirements requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . addEmptyRegistrationProperty ( "<STR_LIT:foo>" ) ; final Map < QName , RegistrationPropertyDescription > expected = Collections . emptyMap ( ) ; long lastModified = requirements . getLastModified ( ) ; requirements . addRegistrationPropertyChangeListener ( new RegistrationPropertyChangeListener ( ) { public void propertiesHaveChanged ( Map < QName , ? extends PropertyDescription > newRegistrationProperties ) { assertEquals ( expected , newRegistrationProperties ) ; } } ) ; requirements . setRegistrationProperties ( expected ) ; assertTrue ( requirements . getLastModified ( ) > lastModified ) ; } public void testReloadSamePolicy ( ) { ProducerRegistrationRequirements requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . reloadPolicyFrom ( ProducerRegistrationRequirements . DEFAULT_POLICY_CLASS_NAME , ProducerRegistrationRequirements . DEFAULT_VALIDATOR_CLASS_NAME ) ; requirements . addRegistrationPolicyChangeListener ( new RegistrationPolicyChangeListener ( ) { public void policyUpdatedTo ( RegistrationPolicy policy ) { fail ( "<STR_LIT>" ) ; } } ) ; requirements . reloadPolicyFrom ( ProducerRegistrationRequirements . DEFAULT_POLICY_CLASS_NAME , ProducerRegistrationRequirements . DEFAULT_VALIDATOR_CLASS_NAME ) ; } public void testSetRegistrationRequired ( ) { ProducerRegistrationRequirements requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . setRegistrationRequired ( true ) ; assertTrue ( requirements . isRegistrationRequired ( ) ) ; requirements . addRegistrationPropertyChangeListener ( new RegistrationPropertyChangeListener ( ) { public void propertiesHaveChanged ( Map < QName , ? extends PropertyDescription > newRegistrationProperties ) { fail ( "<STR_LIT>" ) ; } } ) ; requirements . setRegistrationRequired ( true ) ; } public void testRemoveProperty ( ) { ProducerRegistrationRequirements requirements = new ProducerRegistrationRequirementsImpl ( ) ; requirements . addEmptyRegistrationProperty ( "<STR_LIT:foo>" ) ; long lastModified = requirements . getLastModified ( ) ; requirements . removeRegistrationProperty ( "<STR_LIT:foo>" ) ; requirements . addRegistrationPropertyChangeListener ( new RegistrationPropertyChangeListener ( ) { public void propertiesHaveChanged ( Map < QName , ? extends PropertyDescription > newRegistrationProperties ) { assertTrue ( newRegistrationProperties . isEmpty ( ) ) ; } } ) ; assertTrue ( requirements . getLastModified ( ) > lastModified ) ; } } </s>
<s> package org . gatein . wsrp . producer . config ; import org . gatein . pc . api . PortletContext ; import org . gatein . registration . InvalidConsumerDataException ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationManager ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . wsrp . registration . PropertyDescription ; import javax . xml . namespace . QName ; import java . util . Map ; public class TestRegistrationPolicy implements RegistrationPolicy { public void validateRegistrationDataFor ( Map < QName , Object > registrationProperties , String consumerIdentity , final Map < QName , ? extends PropertyDescription > expectations , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { } public String createRegistrationHandleFor ( String registrationId ) throws IllegalArgumentException { return null ; } public String getAutomaticGroupNameFor ( String consumerName ) throws IllegalArgumentException { return null ; } public String getConsumerIdFrom ( String consumerName , Map < QName , Object > registrationProperties ) throws IllegalArgumentException , InvalidConsumerDataException { return null ; } public void validateConsumerName ( String consumerName , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { } public void validateConsumerGroupName ( String groupName , RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { } public boolean allowAccessTo ( PortletContext portletContext , Registration registration , String operation ) { return true ; } public boolean isWrapped ( ) { return false ; } public String getClassName ( ) { return getClass ( ) . getName ( ) ; } public Class < ? extends RegistrationPolicy > getRealClass ( ) { return getClass ( ) ; } } </s>
<s> package org . gatein . wsrp . producer . config ; import org . gatein . wsrp . producer . config . impl . xml . ProducerConfigurationFactory ; import org . jboss . xb . binding . JBossXBException ; import org . jboss . xb . binding . ObjectModelFactory ; import org . jboss . xb . binding . Unmarshaller ; import org . jboss . xb . binding . UnmarshallerFactory ; import java . io . IOException ; import java . net . URL ; public class JAXBProducerConfigurationTestCase extends ProducerConfigurationTestCase { private Unmarshaller unmarshaller ; private ObjectModelFactory factory ; protected void setUp ( ) throws Exception { unmarshaller = UnmarshallerFactory . newInstance ( ) . newUnmarshaller ( ) ; factory = new ProducerConfigurationFactory ( ) ; unmarshaller . setEntityResolver ( new TestEntityResolver ( ) ) ; } protected ProducerConfiguration getProducerConfiguration ( URL location ) throws JBossXBException , IOException { Object o = unmarshaller . unmarshal ( location . openStream ( ) , factory , null ) ; assertNotNull ( o ) ; assertTrue ( o instanceof ProducerConfiguration ) ; return ( ProducerConfiguration ) o ; } } </s>
<s> package org . gatein . wsrp . producer . handlers . processors ; import junit . framework . TestCase ; import org . gatein . common . net . media . MediaType ; import org . gatein . pc . api . Portlet ; import org . gatein . pc . api . PortletContext ; import org . gatein . pc . api . PortletInvokerException ; import org . gatein . pc . api . info . PortletInfo ; import org . gatein . registration . Registration ; import org . gatein . wsrp . WSRPConstants ; import org . gatein . wsrp . WSRPTypeFactory ; import org . gatein . wsrp . api . servlet . ServletAccess ; import org . gatein . wsrp . test . support . MockHttpServletRequest ; import org . gatein . wsrp . test . support . MockHttpServletResponse ; import org . gatein . wsrp . test . support . MockHttpSession ; import org . oasis . wsrp . v2 . InvalidHandle ; import org . oasis . wsrp . v2 . InvalidRegistration ; import org . oasis . wsrp . v2 . MarkupType ; import org . oasis . wsrp . v2 . MissingParameters ; import org . oasis . wsrp . v2 . ModifyRegistrationRequired ; import org . oasis . wsrp . v2 . OperationFailed ; import org . oasis . wsrp . v2 . PortletDescription ; import org . oasis . wsrp . v2 . RegistrationContext ; import org . oasis . wsrp . v2 . UnsupportedLocale ; import org . oasis . wsrp . v2 . UnsupportedMimeType ; import org . oasis . wsrp . v2 . UnsupportedMode ; import org . oasis . wsrp . v2 . UnsupportedWindowState ; import java . util . ArrayList ; import java . util . List ; public class MimeResponseProcessorTestCase extends TestCase { private static final String PORTLET_HANDLE = "<STR_LIT>" ; public void testShouldUseProvidedNamespace ( ) throws OperationFailed , UnsupportedMode , InvalidHandle , MissingParameters , UnsupportedMimeType , UnsupportedWindowState , InvalidRegistration , ModifyRegistrationRequired , UnsupportedLocale { String namespace = "<STR_LIT>" ; ServletAccess . setRequestAndResponse ( MockHttpServletRequest . createMockRequest ( MockHttpSession . createMockSession ( ) ) , MockHttpServletResponse . createMockResponse ( ) ) ; MimeResponseProcessor processor = new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , namespace ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , WSRPConstants . getDefaultMimeTypes ( ) , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; assertEquals ( "<STR_LIT>" , processor . invocation . getWindowContext ( ) . getNamespace ( ) ) ; } public void testShouldProperlyHandleWildCardsInRequestedMimeTypes ( ) throws OperationFailed , UnsupportedMode , InvalidHandle , MissingParameters , UnsupportedMimeType , ModifyRegistrationRequired , UnsupportedWindowState , InvalidRegistration , UnsupportedLocale { List < String > mimeTypes = new ArrayList < String > ( <NUM_LIT:1> ) ; mimeTypes . add ( "<STR_LIT>" ) ; ServletAccess . setRequestAndResponse ( MockHttpServletRequest . createMockRequest ( MockHttpSession . createMockSession ( ) ) , MockHttpServletResponse . createMockResponse ( ) ) ; MimeResponseProcessor processor = new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , "<STR_LIT>" ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; assertEquals ( TestProducerHelper . PORTLET_MIME_TYPE , processor . markupRequest . getMediaType ( ) ) ; mimeTypes = new ArrayList < String > ( <NUM_LIT:1> ) ; mimeTypes . add ( "<STR_LIT:*>" ) ; processor = new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , "<STR_LIT>" ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; assertEquals ( TestProducerHelper . PORTLET_MIME_TYPE , processor . markupRequest . getMediaType ( ) ) ; mimeTypes = new ArrayList < String > ( <NUM_LIT:1> ) ; mimeTypes . add ( "<STR_LIT>" ) ; processor = new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , "<STR_LIT>" ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; assertEquals ( TestProducerHelper . PORTLET_MIME_TYPE , processor . markupRequest . getMediaType ( ) ) ; mimeTypes = new ArrayList < String > ( <NUM_LIT:1> ) ; mimeTypes . add ( "<STR_LIT>" ) ; try { new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , "<STR_LIT>" ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; fail ( "<STR_LIT>" ) ; } catch ( UnsupportedMimeType unsupportedMimeType ) { } } public void testShouldReturnFirstMimeTypeMatching ( ) throws OperationFailed , UnsupportedMode , InvalidHandle , MissingParameters , UnsupportedMimeType , ModifyRegistrationRequired , UnsupportedWindowState , InvalidRegistration , UnsupportedLocale { List < String > mimeTypes = new ArrayList < String > ( <NUM_LIT:2> ) ; mimeTypes . add ( "<STR_LIT>" ) ; mimeTypes . add ( "<STR_LIT>" ) ; ServletAccess . setRequestAndResponse ( MockHttpServletRequest . createMockRequest ( MockHttpSession . createMockSession ( ) ) , MockHttpServletResponse . createMockResponse ( ) ) ; MimeResponseProcessor processor = new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , "<STR_LIT>" ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; assertEquals ( "<STR_LIT>" , processor . markupRequest . getMediaType ( ) ) ; mimeTypes = new ArrayList < String > ( <NUM_LIT:2> ) ; mimeTypes . add ( "<STR_LIT>" ) ; mimeTypes . add ( "<STR_LIT>" ) ; processor = new RenderRequestProcessor ( new TestProducerHelper ( ) , WSRPTypeFactory . createGetMarkup ( null , WSRPTypeFactory . createPortletContext ( PORTLET_HANDLE ) , WSRPTypeFactory . createRuntimeContext ( WSRPConstants . NONE_USER_AUTHENTICATION , "<STR_LIT:foo>" , "<STR_LIT>" ) , null , WSRPTypeFactory . createMarkupParams ( false , WSRPConstants . getDefaultLocales ( ) , mimeTypes , WSRPConstants . VIEW_MODE , WSRPConstants . NORMAL_WINDOW_STATE ) ) ) ; assertEquals ( TestProducerHelper . PORTLET_MIME_TYPE , processor . markupRequest . getMediaType ( ) ) ; } private static class TestProducerHelper implements ProducerHelper { static final String PORTLET_MIME_TYPE = MediaType . TEXT_HTML . getValue ( ) ; public Portlet getPortletWith ( PortletContext portletContext , Registration registration ) throws InvalidHandle , PortletInvokerException { return new Portlet ( ) { public PortletContext getContext ( ) { return PortletContext . createPortletContext ( PORTLET_HANDLE ) ; } public PortletInfo getInfo ( ) { return null ; } public boolean isRemote ( ) { return false ; } } ; } public PortletDescription getPortletDescription ( org . oasis . wsrp . v2 . PortletContext portletContext , List < String > locales , Registration registration ) throws InvalidHandle , OperationFailed { List < String > modeNames = new ArrayList < String > ( <NUM_LIT:1> ) ; modeNames . add ( WSRPConstants . VIEW_MODE ) ; List < String > windowStateNames = new ArrayList < String > ( <NUM_LIT:1> ) ; windowStateNames . add ( WSRPConstants . NORMAL_WINDOW_STATE ) ; List < MarkupType > markupTypes = new ArrayList < MarkupType > ( <NUM_LIT:1> ) ; markupTypes . add ( WSRPTypeFactory . createMarkupType ( PORTLET_MIME_TYPE , modeNames , windowStateNames , locales ) ) ; markupTypes . add ( WSRPTypeFactory . createMarkupType ( "<STR_LIT>" , modeNames , windowStateNames , locales ) ) ; return WSRPTypeFactory . createPortletDescription ( PORTLET_HANDLE , markupTypes ) ; } public PortletDescription getPortletDescription ( Portlet portlet , List < String > locales ) { throw new UnsupportedOperationException ( ) ; } public Registration getRegistrationOrFailIfInvalid ( RegistrationContext registrationContext ) throws InvalidRegistration , OperationFailed { return null ; } public void reset ( ) { } } } </s>
<s> package org . gatein . registration ; import org . gatein . common . util . ParameterValidation ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class RegistrationUtils { private static boolean strict = true ; private static final Logger log = LoggerFactory . getLogger ( RegistrationUtils . class ) ; public static void setStrict ( boolean strict ) { RegistrationUtils . strict = strict ; log . debug ( "<STR_LIT>" + ( strict ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" ) ; } public static void validateConsumerAgent ( final String consumerAgent ) throws IllegalArgumentException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerAgent , "<STR_LIT>" , null ) ; char periodChar = '<CHAR_LIT:.>' ; String tmp = consumerAgent . trim ( ) ; int period = tmp . indexOf ( periodChar ) ; if ( period != - <NUM_LIT:1> ) { tmp = tmp . substring ( period + <NUM_LIT:1> ) ; period = tmp . indexOf ( periodChar ) ; if ( period != - <NUM_LIT:1> ) { tmp = tmp . substring ( period + <NUM_LIT:1> ) ; if ( tmp . length ( ) > <NUM_LIT:0> ) { return ; } } } String msg = "<STR_LIT:'>" + consumerAgent + "<STR_LIT>" ; if ( strict ) { throw new IllegalArgumentException ( msg ) ; } else { log . debug ( msg ) ; } } } </s>
<s> package org . gatein . registration . policies ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . PortletContext ; import org . gatein . registration . InvalidConsumerDataException ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationManager ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . wsrp . registration . PropertyDescription ; import javax . xml . namespace . QName ; import java . util . Map ; public class RegistrationPolicyWrapper implements RegistrationPolicy { private final RegistrationPolicy delegate ; public static RegistrationPolicy wrap ( RegistrationPolicy policy ) { ParameterValidation . throwIllegalArgExceptionIfNull ( policy , "<STR_LIT>" ) ; if ( ! policy . isWrapped ( ) ) { return new RegistrationPolicyWrapper ( policy ) ; } else { return policy ; } } public static RegistrationPolicy unwrap ( RegistrationPolicy policy ) { ParameterValidation . throwIllegalArgExceptionIfNull ( policy , "<STR_LIT>" ) ; if ( policy . isWrapped ( ) ) { return ( ( RegistrationPolicyWrapper ) policy ) . getDelegate ( ) ; } else { return policy ; } } private RegistrationPolicyWrapper ( RegistrationPolicy delegate ) { this . delegate = delegate ; } private RegistrationPolicy getDelegate ( ) { return delegate ; } public void validateRegistrationDataFor ( Map < QName , Object > registrationProperties , String consumerIdentity , final Map < QName , ? extends PropertyDescription > expectations , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { delegate . validateRegistrationDataFor ( registrationProperties , consumerIdentity , expectations , manager ) ; } public String createRegistrationHandleFor ( String registrationId ) throws IllegalArgumentException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( registrationId , "<STR_LIT>" , null ) ; return delegate . createRegistrationHandleFor ( registrationId ) ; } public String getAutomaticGroupNameFor ( String consumerName ) throws IllegalArgumentException { return delegate . getAutomaticGroupNameFor ( sanitizeConsumerName ( consumerName ) ) ; } public String getConsumerIdFrom ( String consumerName , Map < QName , Object > registrationProperties ) throws IllegalArgumentException , InvalidConsumerDataException { return delegate . getConsumerIdFrom ( sanitizeConsumerName ( consumerName ) , registrationProperties ) ; } public void validateConsumerName ( String consumerName , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { delegate . validateConsumerName ( sanitizeConsumerName ( consumerName ) , manager ) ; } public void validateConsumerGroupName ( String groupName , RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { delegate . validateConsumerGroupName ( groupName , manager ) ; } public boolean allowAccessTo ( PortletContext portletContext , Registration registration , String operation ) { return delegate . allowAccessTo ( portletContext , registration , operation ) ; } public boolean isWrapped ( ) { return true ; } public String getClassName ( ) { return delegate . getClassName ( ) ; } public Class < ? extends RegistrationPolicy > getRealClass ( ) { return delegate . getClass ( ) ; } static String sanitizeConsumerName ( String consumerName ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerName , "<STR_LIT>" , null ) ; consumerName = consumerName . trim ( ) ; consumerName = consumerName . replaceAll ( "<STR_LIT:U+002C>" , "<STR_LIT:_>" ) ; consumerName = consumerName . replaceAll ( "<STR_LIT:U+0020>" , "<STR_LIT:_>" ) ; consumerName = consumerName . replaceAll ( "<STR_LIT:/>" , "<STR_LIT:_>" ) ; return consumerName ; } } </s>
<s> package org . gatein . registration . policies ; import javax . xml . namespace . QName ; public class DefaultRegistrationPropertyValidator implements RegistrationPropertyValidator { public void validateValueFor ( QName propertyName , Object value ) throws IllegalArgumentException { if ( ! ( value instanceof String ) || ( ( String ) value ) . length ( ) <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( value + "<STR_LIT>" + propertyName + "<STR_LIT>" ) ; } } public static final RegistrationPropertyValidator DEFAULT = new DefaultRegistrationPropertyValidator ( ) ; } </s>
<s> package org . gatein . registration . policies ; import javax . xml . namespace . QName ; public interface RegistrationPropertyValidator { void validateValueFor ( QName propertyName , Object value ) throws IllegalArgumentException ; } </s>
<s> package org . gatein . registration . policies ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . PortletContext ; import org . gatein . registration . Consumer ; import org . gatein . registration . DuplicateRegistrationException ; import org . gatein . registration . InvalidConsumerDataException ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationManager ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . registration . RegistrationStatus ; import org . gatein . wsrp . registration . PropertyDescription ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import javax . xml . namespace . QName ; import java . util . Collections ; import java . util . HashSet ; import java . util . Map ; import java . util . Set ; public class DefaultRegistrationPolicy implements RegistrationPolicy { static final String MISSING_VALUE_ERROR_MSG_BEGIN = "<STR_LIT>" ; private RegistrationPropertyValidator validator ; private static final Logger log = LoggerFactory . getLogger ( DefaultRegistrationPolicy . class ) ; static final String INVALID_VALUE_ERROR_MSG_BEGIN = "<STR_LIT>" ; public DefaultRegistrationPolicy ( ) { validator = DefaultRegistrationPropertyValidator . DEFAULT ; } @ Override public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } DefaultRegistrationPolicy that = ( DefaultRegistrationPolicy ) o ; if ( ! validator . equals ( that . validator ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { return validator . hashCode ( ) ; } public void validateRegistrationDataFor ( Map < QName , Object > registrationProperties , String consumerIdentity , final Map < QName , ? extends PropertyDescription > expectations , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( registrationProperties , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerIdentity , "<STR_LIT>" , null ) ; StringBuilder message = new StringBuilder ( ) ; if ( expectations != null ) { Set < QName > expectedNames = expectations . keySet ( ) ; boolean consistentWithExpectations = true ; Set < QName > unexpected = new HashSet < QName > ( registrationProperties . keySet ( ) ) ; unexpected . removeAll ( expectedNames ) ; if ( ! unexpected . isEmpty ( ) ) { consistentWithExpectations = false ; message . append ( "<STR_LIT>" ) . append ( consumerIdentity ) . append ( "<STR_LIT>" ) ; for ( QName name : unexpected ) { message . append ( "<STR_LIT>" ) . append ( name ) . append ( "<STR_LIT:n>" ) ; } } for ( Map . Entry < QName , ? extends PropertyDescription > entry : expectations . entrySet ( ) ) { QName name = entry . getKey ( ) ; Object value = registrationProperties . get ( name ) ; if ( value == null || ( value instanceof String && ( ( String ) value ) . length ( ) == <NUM_LIT:0> ) ) { message . append ( MISSING_VALUE_ERROR_MSG_BEGIN ) . append ( name . getLocalPart ( ) ) . append ( "<STR_LIT>" ) ; consistentWithExpectations = false ; } else { try { validator . validateValueFor ( name , value ) ; } catch ( IllegalArgumentException e ) { message . append ( INVALID_VALUE_ERROR_MSG_BEGIN ) . append ( name . getLocalPart ( ) ) . append ( "<STR_LIT>" ) . append ( e . getLocalizedMessage ( ) ) . append ( "<STR_LIT:n>" ) ; consistentWithExpectations = false ; } } } if ( ! consistentWithExpectations ) { String messageString = message . toString ( ) ; log . debug ( messageString ) ; throw new InvalidConsumerDataException ( messageString ) ; } } Consumer consumer = manager . getConsumerByIdentity ( consumerIdentity ) ; if ( consumer != null && ! RegistrationStatus . PENDING . equals ( consumer . getStatus ( ) ) ) { for ( Registration registration : consumer . getRegistrations ( ) ) { if ( registration . hasEqualProperties ( registrationProperties ) ) { throw new DuplicateRegistrationException ( "<STR_LIT>" + consumer . getName ( ) + "<STR_LIT>" , null , registration ) ; } } } } public String createRegistrationHandleFor ( String registrationId ) { return registrationId ; } public String getAutomaticGroupNameFor ( String consumerName ) { return null ; } public String getConsumerIdFrom ( String consumerName , Map < QName , Object > registrationProperties ) throws IllegalArgumentException , InvalidConsumerDataException { return consumerName ; } public void validateConsumerName ( String consumerName , final RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { if ( manager . isConsumerExisting ( getConsumerIdFrom ( consumerName , Collections . < QName , Object > emptyMap ( ) ) ) ) { throw new DuplicateRegistrationException ( "<STR_LIT>" + consumerName + "<STR_LIT>" ) ; } } public void validateConsumerGroupName ( String groupName , RegistrationManager manager ) throws IllegalArgumentException , RegistrationException { } public boolean allowAccessTo ( PortletContext portletContext , Registration registration , String operation ) { return true ; } public boolean isWrapped ( ) { return false ; } public String getClassName ( ) { return getClass ( ) . getName ( ) ; } public Class < ? extends RegistrationPolicy > getRealClass ( ) { return getClass ( ) ; } public void setValidator ( RegistrationPropertyValidator validator ) { this . validator = validator ; } public RegistrationPropertyValidator getValidator ( ) { return validator ; } } </s>
<s> package org . gatein . registration ; public interface RegistrationDestructionListener { Vote destructionScheduledFor ( Registration registration ) ; static class Vote { public final boolean result ; public final String reason ; public static Vote negativeVote ( String reason ) { return new Vote ( reason ) ; } Vote ( String reason ) { this . result = false ; this . reason = reason ; } Vote ( ) { result = true ; reason = null ; } } static final Vote SUCCESS = new Vote ( ) ; } </s>
<s> package org . gatein . registration ; import org . gatein . registration . spi . ConsumerSPI ; import org . gatein . registration . spi . RegistrationSPI ; import javax . xml . namespace . QName ; import java . util . Collection ; import java . util . Map ; public interface RegistrationPersistenceManager { Consumer createConsumer ( String consumerId , String consumerName ) throws RegistrationException ; void saveChangesTo ( Consumer consumer ) throws RegistrationException ; void saveChangesTo ( Registration registration ) throws RegistrationException ; ConsumerGroup getConsumerGroup ( String name ) throws RegistrationException ; ConsumerGroup createConsumerGroup ( String name ) throws RegistrationException ; void removeConsumerGroup ( String name ) throws RegistrationException ; void removeConsumer ( String consumerId ) throws RegistrationException ; void removeRegistration ( String registrationId ) throws RegistrationException ; Consumer getConsumerById ( String consumerId ) throws IllegalArgumentException , RegistrationException ; RegistrationSPI addRegistrationFor ( String consumerId , Map < QName , Object > registrationProperties ) throws RegistrationException ; RegistrationSPI addRegistrationFor ( ConsumerSPI consumer , Map < QName , Object > registrationProperties ) throws RegistrationException ; Collection < ? extends ConsumerGroup > getConsumerGroups ( ) throws RegistrationException ; Registration getRegistration ( String registrationId ) throws RegistrationException ; Consumer addConsumerToGroupNamed ( String consumerId , String groupName ) throws RegistrationException ; Collection < ? extends Consumer > getConsumers ( ) throws RegistrationException ; Collection < ? extends Registration > getRegistrations ( ) throws RegistrationException ; boolean isConsumerExisting ( String consumerId ) throws RegistrationException ; boolean isConsumerGroupExisting ( String consumerGroupId ) throws RegistrationException ; } </s>
<s> package org . gatein . registration ; import org . gatein . pc . api . PortletContext ; import javax . xml . namespace . QName ; import java . util . Map ; import java . util . Set ; public interface Registration { String getPersistentKey ( ) ; void setRegistrationHandle ( String handle ) ; String getRegistrationHandle ( ) ; Consumer getConsumer ( ) ; Map < QName , Object > getProperties ( ) ; void setPropertyValueFor ( QName propertyName , Object value ) throws IllegalArgumentException ; void setPropertyValueFor ( String propertyName , Object value ) ; boolean hasEqualProperties ( Registration registration ) ; boolean hasEqualProperties ( Map properties ) ; RegistrationStatus getStatus ( ) ; void setStatus ( RegistrationStatus status ) ; void updateProperties ( Map registrationProperties ) ; void removeProperty ( QName propertyName ) ; void removeProperty ( String propertyName ) ; Object getPropertyValueFor ( QName propertyName ) ; Object getPropertyValueFor ( String propertyName ) ; boolean knows ( PortletContext portletContext ) ; Set < PortletContext > getKnownPortletContexts ( ) ; boolean knows ( String portletContextId ) ; } </s>
<s> package org . gatein . registration ; public interface RegistrationPolicyChangeListener { void policyUpdatedTo ( RegistrationPolicy policy ) ; } </s>
<s> package org . gatein . registration ; import org . gatein . wsrp . registration . PropertyDescription ; import javax . xml . namespace . QName ; import java . util . Collection ; import java . util . Map ; public interface RegistrationManager extends RegistrationPropertyChangeListener , RegistrationPolicyChangeListener { RegistrationPolicy getPolicy ( ) ; void setPolicy ( RegistrationPolicy policy ) ; RegistrationPersistenceManager getPersistenceManager ( ) ; void setPersistenceManager ( RegistrationPersistenceManager persistenceManager ) ; Registration addRegistrationTo ( String consumerName , Map < QName , Object > registrationProperties , final Map < QName , ? extends PropertyDescription > expectations , boolean createConsumerIfNeeded ) throws RegistrationException ; Consumer createConsumer ( String name ) throws RegistrationException , InvalidConsumerDataException ; Consumer addConsumerToGroupNamed ( String consumerName , String groupName , boolean createGroupIfNeeded , boolean createConsumerIfNeeded ) throws RegistrationException ; ConsumerGroup createConsumerGroup ( String groupName ) throws RegistrationException ; void removeConsumer ( String identity ) throws RegistrationException , NoSuchRegistrationException ; void removeConsumer ( Consumer consumer ) throws RegistrationException , NoSuchRegistrationException ; Consumer getConsumerByIdentity ( String identity ) throws RegistrationException ; boolean isConsumerExisting ( String consumerId ) throws RegistrationException ; Consumer getConsumerFor ( String registrationHandle ) throws RegistrationException ; Registration getRegistration ( String registrationHandle ) throws RegistrationException ; Registration getNonRegisteredRegistration ( ) throws RegistrationException ; void removeRegistration ( String registrationHandle ) throws RegistrationException , NoSuchRegistrationException ; void removeRegistration ( Registration registration ) throws RegistrationException , NoSuchRegistrationException ; ConsumerGroup getConsumerGroup ( String groupName ) throws RegistrationException ; Collection < ? extends ConsumerGroup > getConsumerGroups ( ) throws RegistrationException ; void removeConsumerGroup ( ConsumerGroup group ) throws RegistrationException ; void removeConsumerGroup ( String name ) throws RegistrationException ; Collection < ? extends Consumer > getConsumers ( ) throws RegistrationException ; void clear ( ) throws RegistrationException ; void addRegistrationDestructionListener ( RegistrationDestructionListener listener ) ; void removeRegistrationDestructionListener ( RegistrationDestructionListener listener ) ; } </s>
<s> package org . gatein . registration ; import java . util . Collection ; public interface ConsumerGroup { String getName ( ) ; String getPersistentKey ( ) ; Collection < Consumer > getConsumers ( ) throws RegistrationException ; Consumer getConsumer ( String consumerId ) throws IllegalArgumentException , RegistrationException ; void addConsumer ( Consumer consumer ) throws RegistrationException ; void removeConsumer ( Consumer consumer ) throws RegistrationException ; boolean contains ( Consumer consumer ) ; boolean isEmpty ( ) ; RegistrationStatus getStatus ( ) ; void setStatus ( RegistrationStatus status ) ; } </s>
<s> package org . gatein . registration . spi ; import org . gatein . registration . Consumer ; import org . gatein . registration . RegistrationException ; public interface ConsumerSPI extends Consumer { void removeRegistration ( RegistrationSPI registration ) throws RegistrationException ; void addRegistration ( RegistrationSPI registration ) ; void setPersistentKey ( String key ) ; } </s>
<s> package org . gatein . registration . spi ; import org . gatein . registration . ConsumerGroup ; public interface ConsumerGroupSPI extends ConsumerGroup { void setPersistentKey ( String id ) ; } </s>
<s> package org . gatein . registration . spi ; import org . gatein . pc . api . PortletContext ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; public interface RegistrationSPI extends Registration { ConsumerSPI getConsumer ( ) ; void addPortletContext ( PortletContext portletContext ) throws RegistrationException ; void addPortletContext ( PortletContext portletContext , boolean needsSaving ) throws RegistrationException ; void removePortletContext ( PortletContext portletContext ) throws RegistrationException ; void removePortletContext ( PortletContext portletContext , boolean needsSaving ) throws RegistrationException ; void setPersistentKey ( String key ) ; } </s>
<s> package org . gatein . registration ; public class DuplicateRegistrationException extends RegistrationException { private final Registration registration ; public DuplicateRegistrationException ( ) { registration = null ; } public DuplicateRegistrationException ( String message ) { super ( message ) ; registration = null ; } public DuplicateRegistrationException ( String message , Throwable cause ) { super ( message , cause ) ; registration = null ; } public DuplicateRegistrationException ( Throwable cause ) { super ( cause ) ; registration = null ; } public DuplicateRegistrationException ( String message , Throwable cause , Registration registration ) { super ( message , cause ) ; this . registration = registration ; } public Registration getExistingRegistration ( ) { return registration ; } } </s>
<s> package org . gatein . registration ; import java . io . Serializable ; public enum RegistrationStatus implements Serializable { VALID ( "<STR_LIT>" ) , PENDING ( "<STR_LIT>" ) , INVALID ( "<STR_LIT>" ) ; private RegistrationStatus ( String humanReadable ) { this . humanReadable = humanReadable ; } public String toString ( ) { return "<STR_LIT>" + humanReadable ; } private String humanReadable ; } </s>
<s> package org . gatein . registration ; public class InvalidConsumerDataException extends RegistrationException { public InvalidConsumerDataException ( ) { } public InvalidConsumerDataException ( String message ) { super ( message ) ; } public InvalidConsumerDataException ( String message , Throwable cause ) { super ( message , cause ) ; } public InvalidConsumerDataException ( Throwable cause ) { super ( cause ) ; } } </s>
<s> package org . gatein . registration ; import java . util . Collection ; public interface Consumer { String getName ( ) ; RegistrationStatus getStatus ( ) ; Collection < Registration > getRegistrations ( ) throws RegistrationException ; Registration getRegistration ( String id ) throws RegistrationException ; ConsumerGroup getGroup ( ) ; String getId ( ) ; ConsumerCapabilities getCapabilities ( ) ; void setCapabilities ( ConsumerCapabilities capabilities ) ; void setGroup ( ConsumerGroup group ) throws RegistrationException , DuplicateRegistrationException ; String getConsumerAgent ( ) ; void setConsumerAgent ( String consumerAgent ) throws IllegalArgumentException , IllegalStateException ; String getPersistentKey ( ) ; } </s>
<s> package org . gatein . registration ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . WindowState ; import java . util . List ; public interface ConsumerCapabilities { boolean supportsGetMethod ( ) ; List < Mode > getSupportedModes ( ) ; List < WindowState > getSupportedWindowStates ( ) ; List < String > getSupportedUserScopes ( ) ; List < String > getSupportedUserProfileData ( ) ; void setSupportsGetMethod ( boolean supportsGetMethod ) ; void setSupportedModes ( List < Mode > supportedModes ) ; void setSupportedWindowStates ( List < WindowState > supportedWindowStates ) ; void setSupportedUserScopes ( List < String > supportedUserScopes ) ; void setSupportedUserProfileData ( List < String > supportedUserProfileData ) ; } </s>
<s> package org . gatein . registration . impl ; import org . gatein . common . util . ParameterValidation ; import org . gatein . registration . Consumer ; import org . gatein . registration . NoSuchRegistrationException ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationStatus ; import org . gatein . registration . spi . ConsumerGroupSPI ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; public class ConsumerGroupImpl implements ConsumerGroupSPI { private String key ; private String name ; private Map < String , Consumer > consumers ; private RegistrationStatus status ; private ConsumerGroupImpl ( ) { init ( ) ; } ConsumerGroupImpl ( String name ) { this . name = name ; init ( ) ; } private void init ( ) { this . consumers = new HashMap < String , Consumer > ( ) ; status = RegistrationStatus . PENDING ; } public String getName ( ) { return name ; } public String getPersistentKey ( ) { return key ; } public void setPersistentKey ( String id ) { this . key = id ; } public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } ConsumerGroupImpl that = ( ConsumerGroupImpl ) o ; return name . equals ( that . name ) ; } public int hashCode ( ) { return name . hashCode ( ) ; } public RegistrationStatus getStatus ( ) { return status ; } public void setStatus ( RegistrationStatus status ) { ParameterValidation . throwIllegalArgExceptionIfNull ( status , "<STR_LIT>" ) ; this . status = status ; } public Collection < Consumer > getConsumers ( ) throws RegistrationException { return Collections . unmodifiableCollection ( consumers . values ( ) ) ; } public Consumer getConsumer ( String consumerId ) throws IllegalArgumentException , RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; return consumers . get ( consumerId ) ; } public boolean isEmpty ( ) { return consumers . isEmpty ( ) ; } public void addConsumer ( Consumer consumer ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( consumer , "<STR_LIT>" ) ; String identity = consumer . getId ( ) ; if ( consumers . containsKey ( identity ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + name + "<STR_LIT>" + consumer . getName ( ) + "<STR_LIT>" + identity + "<STR_LIT>" ) ; } consumers . put ( identity , consumer ) ; consumer . setGroup ( this ) ; } public void removeConsumer ( Consumer consumer ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( consumer , "<STR_LIT>" ) ; if ( consumers . remove ( consumer . getId ( ) ) == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + name + "<STR_LIT>" + consumer . getName ( ) + "<STR_LIT>" + consumer . getId ( ) + "<STR_LIT>" ) ; } consumer . setGroup ( null ) ; } public boolean contains ( Consumer consumer ) { ParameterValidation . throwIllegalArgExceptionIfNull ( consumer , "<STR_LIT>" ) ; return consumers . containsKey ( consumer . getId ( ) ) ; } } </s>
<s> package org . gatein . registration . impl ; import org . gatein . common . util . ParameterValidation ; import org . gatein . registration . Consumer ; import org . gatein . registration . ConsumerGroup ; import org . gatein . registration . DuplicateRegistrationException ; import org . gatein . registration . NoSuchRegistrationException ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationPersistenceManager ; import org . gatein . registration . RegistrationStatus ; import org . gatein . registration . spi . ConsumerGroupSPI ; import org . gatein . registration . spi . ConsumerSPI ; import org . gatein . registration . spi . RegistrationSPI ; import javax . xml . namespace . QName ; import java . util . Map ; public abstract class AbstractRegistrationPersistenceManager implements RegistrationPersistenceManager { private long lastRegistrationId ; public Consumer createConsumer ( String consumerId , String consumerName ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerName , "<STR_LIT>" , null ) ; if ( isConsumerExisting ( consumerId ) ) { throw new DuplicateRegistrationException ( "<STR_LIT>" + consumerId + "<STR_LIT>" ) ; } else { ConsumerSPI consumer = internalCreateConsumer ( consumerId , consumerName ) ; internalAddConsumer ( consumer ) ; return consumer ; } } public void saveChangesTo ( Consumer consumer ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( consumer , "<STR_LIT>" ) ; if ( consumer . getPersistentKey ( ) == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + consumer + "<STR_LIT>" ) ; } internalSaveChangesTo ( consumer ) ; } public void saveChangesTo ( Registration registration ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( registration , "<STR_LIT>" ) ; if ( registration . getPersistentKey ( ) == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + registration + "<STR_LIT>" ) ; } internalSaveChangesTo ( registration ) ; } public ConsumerGroup createConsumerGroup ( String name ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT>" , null ) ; if ( isConsumerGroupExisting ( name ) ) { throw new DuplicateRegistrationException ( "<STR_LIT>" + name + "<STR_LIT>" ) ; } else { final ConsumerGroupSPI group = internalCreateConsumerGroup ( name ) ; internalAddConsumerGroup ( group ) ; return group ; } } public void removeConsumerGroup ( String name ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT>" , null ) ; if ( internalRemoveConsumerGroup ( name ) == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + name + "<STR_LIT>" ) ; } } public void removeConsumer ( String consumerId ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; if ( internalRemoveConsumer ( consumerId ) == null ) { throw new RegistrationException ( "<STR_LIT>" + consumerId + "<STR_LIT>" ) ; } } public void removeRegistration ( String registrationId ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( registrationId , "<STR_LIT>" , null ) ; RegistrationSPI registration = internalRemoveRegistration ( registrationId ) ; if ( registration == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + registrationId + "<STR_LIT:'>" ) ; } ConsumerSPI consumer = registration . getConsumer ( ) ; consumer . removeRegistration ( registration ) ; } public RegistrationSPI addRegistrationFor ( String consumerId , Map < QName , Object > registrationProperties ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( registrationProperties , "<STR_LIT>" ) ; ConsumerSPI consumer = getConsumerSPIById ( consumerId ) ; if ( consumer == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + consumerId + "<STR_LIT>" ) ; } return addRegistrationFor ( consumer , registrationProperties ) ; } public RegistrationSPI addRegistrationFor ( ConsumerSPI consumer , Map < QName , Object > registrationProperties ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( consumer , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( registrationProperties , "<STR_LIT>" ) ; RegistrationSPI registration = internalCreateRegistration ( consumer , registrationProperties ) ; consumer . addRegistration ( registration ) ; internalAddRegistration ( registration ) ; return registration ; } public Consumer addConsumerToGroupNamed ( String consumerId , String groupName ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( groupName , "<STR_LIT>" , null ) ; ConsumerGroup group = getConsumerGroup ( groupName ) ; if ( group == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + groupName + "<STR_LIT>" ) ; } ConsumerSPI consumer = getConsumerSPIById ( consumerId ) ; if ( consumer == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + consumerId + "<STR_LIT>" + groupName + "<STR_LIT>" ) ; } group . addConsumer ( consumer ) ; return consumer ; } public boolean isConsumerExisting ( String consumerId ) throws RegistrationException { return getConsumerById ( consumerId ) != null ; } public boolean isConsumerGroupExisting ( String consumerGroupId ) throws RegistrationException { return getConsumerGroup ( consumerGroupId ) != null ; } protected abstract void internalAddRegistration ( RegistrationSPI registration ) throws RegistrationException ; protected abstract RegistrationSPI internalRemoveRegistration ( String registrationId ) throws RegistrationException ; protected RegistrationSPI internalCreateRegistration ( ConsumerSPI consumer , Map < QName , Object > registrationProperties ) throws RegistrationException { RegistrationSPI registrationSPI = newRegistrationSPI ( consumer , registrationProperties ) ; registrationSPI . setPersistentKey ( "<STR_LIT>" + lastRegistrationId ++ ) ; return registrationSPI ; } protected abstract void internalAddConsumer ( ConsumerSPI consumer ) throws RegistrationException ; protected abstract ConsumerSPI internalRemoveConsumer ( String consumerId ) throws RegistrationException ; protected ConsumerSPI internalCreateConsumer ( String consumerId , String consumerName ) throws RegistrationException { ConsumerSPI consumerSPI = newConsumerSPI ( consumerId , consumerName ) ; consumerSPI . setPersistentKey ( consumerId ) ; return consumerSPI ; } protected abstract ConsumerSPI internalSaveChangesTo ( Consumer consumer ) throws RegistrationException ; protected abstract RegistrationSPI internalSaveChangesTo ( Registration registration ) throws RegistrationException ; protected abstract void internalAddConsumerGroup ( ConsumerGroupSPI group ) throws RegistrationException ; protected abstract ConsumerGroupSPI internalRemoveConsumerGroup ( String name ) throws RegistrationException ; protected ConsumerGroupSPI internalCreateConsumerGroup ( String name ) throws RegistrationException { ConsumerGroupSPI groupSPI = newConsumerGroupSPI ( name ) ; groupSPI . setPersistentKey ( name ) ; return groupSPI ; } protected abstract ConsumerSPI getConsumerSPIById ( String consumerId ) throws RegistrationException ; public RegistrationSPI newRegistrationSPI ( ConsumerSPI consumer , Map < QName , Object > registrationProperties ) { return new RegistrationImpl ( consumer , RegistrationStatus . PENDING , registrationProperties , this ) ; } public ConsumerSPI newConsumerSPI ( String consumerId , String consumerName ) { return new ConsumerImpl ( consumerId , consumerName ) ; } public ConsumerGroupSPI newConsumerGroupSPI ( String name ) { return new ConsumerGroupImpl ( name ) ; } } </s>
<s> package org . gatein . registration . impl ; import org . gatein . common . util . ParameterValidation ; import org . gatein . registration . ConsumerCapabilities ; import org . gatein . registration . ConsumerGroup ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationStatus ; import org . gatein . registration . RegistrationUtils ; import org . gatein . registration . spi . ConsumerSPI ; import org . gatein . registration . spi . RegistrationSPI ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; public class ConsumerImpl implements ConsumerSPI { private String name ; private String identity ; private String consumerAgent ; private Map < String , Registration > registrations ; private ConsumerGroup group ; private ConsumerCapabilities capabilities = new ConsumerCapabilitiesImpl ( ) ; private String key ; private ConsumerImpl ( ) { init ( ) ; throw new RuntimeException ( "<STR_LIT>" ) ; } ConsumerImpl ( String identity , String name ) { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT:name>" , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( identity , "<STR_LIT>" , "<STR_LIT>" ) ; this . name = name ; this . identity = identity ; init ( ) ; } private void init ( ) { registrations = new HashMap < String , Registration > ( <NUM_LIT:7> ) ; capabilities = new ConsumerCapabilitiesImpl ( ) ; } public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } ConsumerImpl consumer = ( ConsumerImpl ) o ; return identity . equals ( consumer . identity ) ; } public int hashCode ( ) { return identity . hashCode ( ) ; } public String getName ( ) { return name ; } public String getId ( ) { return identity ; } public String getConsumerAgent ( ) { return consumerAgent ; } public void setConsumerAgent ( String consumerAgent ) throws IllegalArgumentException , IllegalStateException { if ( consumerAgent != null && ! consumerAgent . equals ( this . consumerAgent ) ) { RegistrationUtils . validateConsumerAgent ( consumerAgent ) ; this . consumerAgent = consumerAgent ; } } public String getPersistentKey ( ) { return key ; } public ConsumerCapabilities getCapabilities ( ) { return capabilities ; } public void setCapabilities ( ConsumerCapabilities capabilities ) { this . capabilities = capabilities ; } public RegistrationStatus getStatus ( ) { if ( ParameterValidation . existsAndIsNotEmpty ( registrations ) ) { RegistrationStatus result = RegistrationStatus . VALID ; for ( Registration registration : registrations . values ( ) ) { RegistrationStatus status = registration . getStatus ( ) ; if ( RegistrationStatus . INVALID == status ) { return RegistrationStatus . INVALID ; } else if ( RegistrationStatus . PENDING == status ) { result = status ; } } return result ; } return RegistrationStatus . PENDING ; } public Collection < Registration > getRegistrations ( ) throws RegistrationException { return Collections . unmodifiableCollection ( registrations . values ( ) ) ; } public Registration getRegistration ( String id ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( id , "<STR_LIT>" , null ) ; return registrations . get ( id ) ; } public ConsumerGroup getGroup ( ) { return group ; } public void addRegistration ( RegistrationSPI registration ) { ParameterValidation . throwIllegalArgExceptionIfNull ( registration , "<STR_LIT>" ) ; registrations . put ( registration . getPersistentKey ( ) , registration ) ; } public void setPersistentKey ( String key ) { this . key = key ; } public void removeRegistration ( RegistrationSPI registration ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( registration , "<STR_LIT>" ) ; registrations . remove ( registration . getPersistentKey ( ) ) ; } public void setGroup ( ConsumerGroup group ) throws RegistrationException { if ( this . group != null ) { if ( this . group . equals ( group ) ) { return ; } if ( this . group . contains ( this ) ) { this . group . removeConsumer ( this ) ; } } this . group = group ; if ( group != null && ! this . group . contains ( this ) ) { group . addConsumer ( this ) ; } } } </s>
<s> package org . gatein . registration . impl ; import org . gatein . common . util . ParameterValidation ; import org . gatein . registration . Consumer ; import org . gatein . registration . ConsumerGroup ; import org . gatein . registration . InvalidConsumerDataException ; import org . gatein . registration . NoSuchRegistrationException ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationDestructionListener ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationManager ; import org . gatein . registration . RegistrationPersistenceManager ; import org . gatein . registration . RegistrationPolicy ; import org . gatein . registration . RegistrationStatus ; import org . gatein . registration . spi . ConsumerSPI ; import org . gatein . registration . spi . RegistrationSPI ; import org . gatein . wsrp . registration . PropertyDescription ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import javax . xml . namespace . QName ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import java . util . concurrent . CopyOnWriteArrayList ; import java . util . concurrent . atomic . AtomicBoolean ; import java . util . concurrent . atomic . AtomicReference ; public class RegistrationManagerImpl implements RegistrationManager { private static final Logger log = LoggerFactory . getLogger ( RegistrationManager . class ) ; private RegistrationPolicy policy ; private RegistrationPersistenceManager persistenceManager ; private AtomicReference < CopyOnWriteArrayList < RegistrationDestructionListener > > listeners = new AtomicReference < CopyOnWriteArrayList < RegistrationDestructionListener > > ( ) ; public static final String NON_REGISTERED_CONSUMER = "<STR_LIT>" ; public RegistrationManagerImpl ( ) { } public RegistrationPolicy getPolicy ( ) { return policy ; } public void setPolicy ( RegistrationPolicy policy ) { this . policy = policy ; } public RegistrationPersistenceManager getPersistenceManager ( ) { return persistenceManager ; } public void setPersistenceManager ( RegistrationPersistenceManager persistenceManager ) { this . persistenceManager = persistenceManager ; } public void addRegistrationDestructionListener ( RegistrationDestructionListener listener ) { ParameterValidation . throwIllegalArgExceptionIfNull ( listener , "<STR_LIT>" ) ; listeners . compareAndSet ( null , new CopyOnWriteArrayList < RegistrationDestructionListener > ( ) ) ; listeners . get ( ) . add ( listener ) ; } public void removeRegistrationDestructionListener ( RegistrationDestructionListener listener ) { ParameterValidation . throwIllegalArgExceptionIfNull ( listener , "<STR_LIT>" ) ; if ( listeners . get ( ) == null ) { return ; } listeners . get ( ) . remove ( listener ) ; } public Registration addRegistrationTo ( String consumerName , Map < QName , Object > registrationProperties , final Map < QName , ? extends PropertyDescription > expectations , boolean createConsumerIfNeeded ) throws RegistrationException { String identity = policy . getConsumerIdFrom ( consumerName , registrationProperties ) ; policy . validateRegistrationDataFor ( registrationProperties , identity , expectations , this ) ; Consumer consumer = getOrCreateConsumer ( identity , createConsumerIfNeeded , consumerName ) ; RegistrationSPI registration = persistenceManager . addRegistrationFor ( ( ConsumerSPI ) consumer , registrationProperties ) ; createAndSetRegistrationHandle ( registration ) ; return registration ; } private void createAndSetRegistrationHandle ( RegistrationSPI registration ) { String handle = policy . createRegistrationHandleFor ( registration . getPersistentKey ( ) ) ; registration . setRegistrationHandle ( handle ) ; } public Consumer createConsumer ( String name ) throws RegistrationException , InvalidConsumerDataException { policy . validateConsumerName ( name , this ) ; String identity = policy . getConsumerIdFrom ( name , Collections . < QName , Object > emptyMap ( ) ) ; Consumer consumer = persistenceManager . createConsumer ( identity , name ) ; String groupName = policy . getAutomaticGroupNameFor ( name ) ; if ( groupName != null ) { addConsumerToGroupNamed ( name , groupName , true , false ) ; } return consumer ; } public Consumer addConsumerToGroupNamed ( String consumerName , String groupName , boolean createGroupIfNeeded , boolean createConsumerIfNeeded ) throws RegistrationException { if ( createGroupIfNeeded ) { policy . validateConsumerGroupName ( groupName , this ) ; } if ( createConsumerIfNeeded ) { policy . validateConsumerName ( consumerName , this ) ; } ConsumerGroup group = getConsumerGroup ( groupName ) ; boolean justCreatedGroup = false ; if ( group == null ) { if ( createGroupIfNeeded ) { createConsumerGroup ( groupName ) ; justCreatedGroup = true ; } else { throw new NoSuchRegistrationException ( "<STR_LIT>" + groupName + "<STR_LIT>" ) ; } } String identity = policy . getConsumerIdFrom ( consumerName , Collections . EMPTY_MAP ) ; try { getOrCreateConsumer ( identity , createConsumerIfNeeded , consumerName ) ; } catch ( NoSuchRegistrationException e ) { if ( justCreatedGroup ) { removeConsumerGroup ( groupName ) ; } } return persistenceManager . addConsumerToGroupNamed ( identity , groupName ) ; } public ConsumerGroup createConsumerGroup ( String groupName ) throws RegistrationException { policy . validateConsumerGroupName ( groupName , this ) ; return persistenceManager . createConsumerGroup ( groupName ) ; } public void removeConsumer ( String identity ) throws RegistrationException , NoSuchRegistrationException { Consumer consumer = getOrCreateConsumer ( identity , false , null ) ; ConsumerGroup group = consumer . getGroup ( ) ; if ( group != null ) { group . removeConsumer ( consumer ) ; } ArrayList < Registration > registrations = new ArrayList < Registration > ( consumer . getRegistrations ( ) ) ; for ( Registration reg : registrations ) { removeRegistration ( reg ) ; } persistenceManager . removeConsumer ( identity ) ; } public void removeConsumer ( Consumer consumer ) throws RegistrationException , NoSuchRegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( consumer , "<STR_LIT>" ) ; removeConsumer ( consumer . getId ( ) ) ; } public Consumer getConsumerByIdentity ( String identity ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( identity , "<STR_LIT>" , null ) ; return persistenceManager . getConsumerById ( identity ) ; } public boolean isConsumerExisting ( String consumerId ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; return persistenceManager . isConsumerExisting ( consumerId ) ; } public Consumer getConsumerFor ( String registrationHandle ) throws RegistrationException { return ( Consumer ) getConsumerOrRegistration ( registrationHandle , true ) ; } public Registration getRegistration ( String registrationHandle ) throws RegistrationException { return ( Registration ) getConsumerOrRegistration ( registrationHandle , false ) ; } public Registration getNonRegisteredRegistration ( ) throws RegistrationException { Consumer unregConsumer = getConsumerByIdentity ( NON_REGISTERED_CONSUMER ) ; if ( unregConsumer == null ) { Registration registration = addRegistrationTo ( NON_REGISTERED_CONSUMER , new HashMap < QName , Object > ( ) , null , true ) ; registration . setStatus ( RegistrationStatus . VALID ) ; getPersistenceManager ( ) . saveChangesTo ( registration ) ; return registration ; } else { final Registration registration = unregConsumer . getRegistrations ( ) . iterator ( ) . next ( ) ; if ( registration . getRegistrationHandle ( ) == null || RegistrationStatus . PENDING == registration . getStatus ( ) ) { createAndSetRegistrationHandle ( ( RegistrationSPI ) registration ) ; registration . setStatus ( RegistrationStatus . VALID ) ; getPersistenceManager ( ) . saveChangesTo ( registration ) ; } return registration ; } } public void removeRegistration ( String registrationHandle ) throws RegistrationException , NoSuchRegistrationException { Registration registration = getRegistration ( registrationHandle ) ; if ( registration == null ) { throw new NoSuchRegistrationException ( "<STR_LIT>" + registrationHandle + "<STR_LIT:'>" ) ; } removeRegistration ( registration ) ; } public void removeRegistration ( Registration registration ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( registration , "<STR_LIT>" ) ; registration . setStatus ( RegistrationStatus . INVALID ) ; AtomicBoolean canRemove = new AtomicBoolean ( true ) ; if ( listeners . get ( ) != null ) { for ( RegistrationDestructionListener listener : listeners . get ( ) ) { RegistrationDestructionListener . Vote vote = listener . destructionScheduledFor ( registration ) ; if ( canRemove . compareAndSet ( false , vote . result ) ) { throw new RegistrationException ( "<STR_LIT>" + registration . getRegistrationHandle ( ) + "<STR_LIT>" + listener + "<STR_LIT>" + vote . reason ) ; } } } persistenceManager . removeRegistration ( registration . getPersistentKey ( ) ) ; } public ConsumerGroup getConsumerGroup ( String groupName ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( groupName , "<STR_LIT>" , null ) ; return persistenceManager . getConsumerGroup ( groupName ) ; } private Consumer getOrCreateConsumer ( String identity , boolean createConsumerIfNeeded , String consumerName ) throws RegistrationException { Consumer consumer = getConsumerByIdentity ( identity ) ; if ( consumer == null ) { if ( createConsumerIfNeeded ) { consumer = createConsumer ( consumerName ) ; } else { throw new NoSuchRegistrationException ( "<STR_LIT>" + consumerName + "<STR_LIT>" ) ; } } return consumer ; } private Object getConsumerOrRegistration ( String registrationHandle , boolean getConsumer ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( registrationHandle , "<STR_LIT>" , null ) ; Registration registration = persistenceManager . getRegistration ( registrationHandle ) ; if ( registration == null ) { return null ; } else { return getConsumer ? registration . getConsumer ( ) : registration ; } } public Collection < ? extends ConsumerGroup > getConsumerGroups ( ) throws RegistrationException { return persistenceManager . getConsumerGroups ( ) ; } public void removeConsumerGroup ( ConsumerGroup group ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( group , "<STR_LIT>" ) ; for ( Object consumer : group . getConsumers ( ) ) { removeConsumer ( ( Consumer ) consumer ) ; } persistenceManager . removeConsumerGroup ( group . getName ( ) ) ; } public void removeConsumerGroup ( String name ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNull ( name , "<STR_LIT>" ) ; removeConsumerGroup ( getConsumerGroup ( name ) ) ; } public Collection < ? extends Consumer > getConsumers ( ) throws RegistrationException { return persistenceManager . getConsumers ( ) ; } public void clear ( ) throws RegistrationException { Collection < Consumer > consumers = new ArrayList < Consumer > ( getConsumers ( ) ) ; for ( Consumer consumer : consumers ) { removeConsumer ( consumer ) ; } Collection < ConsumerGroup > groups = new ArrayList < ConsumerGroup > ( getConsumerGroups ( ) ) ; for ( ConsumerGroup group : groups ) { removeConsumerGroup ( group ) ; } } public void propertiesHaveChanged ( Map < QName , ? extends PropertyDescription > registrationProperties ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "<STR_LIT>" ) ; } try { Collection registrations = persistenceManager . getRegistrations ( ) ; for ( Object registration : registrations ) { Registration reg = ( Registration ) registration ; reg . setStatus ( RegistrationStatus . PENDING ) ; Consumer consumer = reg . getConsumer ( ) ; try { persistenceManager . saveChangesTo ( consumer ) ; } catch ( RegistrationException e ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "<STR_LIT>" + consumer . getId ( ) + "<STR_LIT:'>" , e ) ; } } } } catch ( RegistrationException e ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "<STR_LIT>" , e ) ; } } } public void policyUpdatedTo ( RegistrationPolicy policy ) { setPolicy ( policy ) ; } } </s>
<s> package org . gatein . registration . impl ; import org . gatein . common . util . ParameterValidation ; import org . gatein . registration . Consumer ; import org . gatein . registration . ConsumerGroup ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . spi . ConsumerGroupSPI ; import org . gatein . registration . spi . ConsumerSPI ; import org . gatein . registration . spi . RegistrationSPI ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; public class RegistrationPersistenceManagerImpl extends AbstractRegistrationPersistenceManager { private Map < String , ConsumerSPI > consumers = new HashMap < String , ConsumerSPI > ( ) ; private Map < String , ConsumerGroupSPI > groups = new HashMap < String , ConsumerGroupSPI > ( ) ; private Map < String , RegistrationSPI > registrations = new HashMap < String , RegistrationSPI > ( ) ; public Collection < ConsumerSPI > getConsumers ( ) throws RegistrationException { return Collections . unmodifiableCollection ( consumers . values ( ) ) ; } public Collection < RegistrationSPI > getRegistrations ( ) throws RegistrationException { return Collections . unmodifiableCollection ( registrations . values ( ) ) ; } public Collection < ConsumerGroupSPI > getConsumerGroups ( ) throws RegistrationException { return Collections . unmodifiableCollection ( groups . values ( ) ) ; } public Registration getRegistration ( String registrationId ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( registrationId , "<STR_LIT>" , null ) ; return registrations . get ( registrationId ) ; } public ConsumerGroup getConsumerGroup ( String name ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( name , "<STR_LIT>" , null ) ; return groups . get ( name ) ; } public Consumer getConsumerById ( String consumerId ) throws RegistrationException { ParameterValidation . throwIllegalArgExceptionIfNullOrEmpty ( consumerId , "<STR_LIT>" , null ) ; return consumers . get ( consumerId ) ; } @ Override protected void internalAddRegistration ( RegistrationSPI registration ) throws RegistrationException { registrations . put ( registration . getPersistentKey ( ) , registration ) ; } @ Override protected RegistrationSPI internalRemoveRegistration ( String registrationId ) throws RegistrationException { return registrations . remove ( registrationId ) ; } @ Override protected void internalAddConsumer ( ConsumerSPI consumer ) throws RegistrationException { consumers . put ( consumer . getId ( ) , consumer ) ; } @ Override protected ConsumerSPI internalRemoveConsumer ( String consumerId ) throws RegistrationException { return consumers . remove ( consumerId ) ; } @ Override protected void internalAddConsumerGroup ( ConsumerGroupSPI group ) throws RegistrationException { groups . put ( group . getName ( ) , group ) ; } @ Override protected ConsumerGroupSPI internalRemoveConsumerGroup ( String name ) throws RegistrationException { return groups . remove ( name ) ; } @ Override protected ConsumerSPI getConsumerSPIById ( String consumerId ) throws RegistrationException { return ( ConsumerSPI ) getConsumerById ( consumerId ) ; } @ Override protected ConsumerSPI internalSaveChangesTo ( Consumer consumer ) throws RegistrationException { return ( ConsumerSPI ) consumer ; } @ Override protected RegistrationSPI internalSaveChangesTo ( Registration registration ) throws RegistrationException { return ( RegistrationSPI ) registration ; } } </s>
<s> package org . gatein . registration . impl ; import org . gatein . pc . api . Mode ; import org . gatein . pc . api . WindowState ; import org . gatein . registration . ConsumerCapabilities ; import java . util . List ; public class ConsumerCapabilitiesImpl implements ConsumerCapabilities { private boolean supportsGetMethod ; private List < Mode > supportedModes ; private List < WindowState > supportedWindowStates ; private List < String > supportedUserScopes ; private List < String > supportedUserProfileData ; public boolean supportsGetMethod ( ) { return supportsGetMethod ; } public List < Mode > getSupportedModes ( ) { return supportedModes ; } public List < WindowState > getSupportedWindowStates ( ) { return supportedWindowStates ; } public List < String > getSupportedUserScopes ( ) { return supportedUserScopes ; } public List < String > getSupportedUserProfileData ( ) { return supportedUserProfileData ; } public void setSupportsGetMethod ( boolean supportsGetMethod ) { this . supportsGetMethod = supportsGetMethod ; } public void setSupportedModes ( List < Mode > supportedModes ) { this . supportedModes = supportedModes ; } public void setSupportedWindowStates ( List < WindowState > supportedWindowStates ) { this . supportedWindowStates = supportedWindowStates ; } public void setSupportedUserScopes ( List < String > supportedUserScopes ) { this . supportedUserScopes = supportedUserScopes ; } public void setSupportedUserProfileData ( List < String > supportedUserProfileData ) { this . supportedUserProfileData = supportedUserProfileData ; } } </s>
<s> package org . gatein . registration . impl ; import org . gatein . common . util . ParameterValidation ; import org . gatein . pc . api . PortletContext ; import org . gatein . registration . Registration ; import org . gatein . registration . RegistrationException ; import org . gatein . registration . RegistrationPersistenceManager ; import org . gatein . registration . RegistrationStatus ; import org . gatein . registration . spi . ConsumerSPI ; import org . gatein . registration . spi . RegistrationSPI ; import javax . xml . namespace . QName ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Set ; public class RegistrationImpl implements RegistrationSPI { private String key ; private ConsumerSPI consumer ; private RegistrationStatus status ; private Map < QName , Object > properties ; private String registrationHandle ; private Set < PortletContext > portletContexts ; private transient RegistrationPersistenceManager manager ; RegistrationImpl ( ConsumerSPI consumer , RegistrationStatus status , Map < QName , Object > properties , RegistrationPersistenceManager manager ) { this . consumer = consumer ; this . status = status ; this . properties = new HashMap < QName , Object > ( properties ) ; portletContexts = new HashSet < PortletContext > ( ) ; this . manager = manager ; } public String getPersistentKey ( ) { return key ; } public void setPersistentKey ( String key ) { this . key = key ; } @ Override public boolean equals ( Object o ) { if ( this == o ) { return true ; } if ( o == null || getClass ( ) != o . getClass ( ) ) { return false ; } RegistrationImpl that = ( RegistrationImpl ) o ; if ( ! key . equals ( that . key ) ) { return false ; } return true ; } @ Override public int hashCode ( ) { return key . hashCode ( ) ; } public void setRegistrationHandle ( String handle ) { this . registrationHandle = handle ; } public String getRegistrationHandle ( ) { return registrationHandle ; } public ConsumerSPI getConsumer ( ) { return consumer ; } public void addPortletContext ( PortletContext portletContext ) throws RegistrationException { addPortletContext ( portletContext , true ) ; } public void addPortletContext ( PortletContext portletContext , boolean needsSaving ) throws RegistrationException { portletContexts . add ( portletContext ) ; if ( needsSaving ) { manager . saveChangesTo ( this ) ; } } public void removePortletContext ( PortletContext portletContext ) throws RegistrationException { removePortletContext ( portletContext , true ) ; } public void removePortletContext ( PortletContext portletContext , boolean needsSaving ) throws RegistrationException { portletContexts . remove ( portletContext ) ; manager . saveChangesTo ( this ) ; } public Map < QName , Object > getProperties ( ) { return Collections . unmodifiableMap ( properties ) ; } public void setPropertyValueFor ( QName propertyName , Object value ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyName , "<STR_LIT>" ) ; ParameterValidation . throwIllegalArgExceptionIfNull ( value , "<STR_LIT>" ) ; Object oldValue = properties . get ( propertyName ) ; if ( ! value . equals ( oldValue ) ) { properties . put ( propertyName , value ) ; } } public void setPropertyValueFor ( String propertyName , Object value ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyName , "<STR_LIT>" ) ; setPropertyValueFor ( new QName ( propertyName ) , value ) ; } public Object getPropertyValueFor ( QName propertyName ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyName , "<STR_LIT>" ) ; return properties . get ( propertyName ) ; } public Object getPropertyValueFor ( String propertyName ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyName , "<STR_LIT>" ) ; return getPropertyValueFor ( new QName ( propertyName ) ) ; } public void removeProperty ( QName propertyName ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyName , "<STR_LIT>" ) ; properties . remove ( propertyName ) ; } public void removeProperty ( String propertyName ) { ParameterValidation . throwIllegalArgExceptionIfNull ( propertyName , "<STR_LIT>" ) ; removeProperty ( new QName ( propertyName ) ) ; } public boolean hasEqualProperties ( Registration registration ) { if ( registration == null ) { return false ; } Map other = registration . getProperties ( ) ; return hasEqualProperties ( other ) ; } public boolean hasEqualProperties ( Map registrationProperties ) { if ( registrationProperties == null ) { return false ; } if ( properties . size ( ) != registrationProperties . size ( ) ) { return false ; } for ( Map . Entry < QName , Object > entry : properties . entrySet ( ) ) { QName name = entry . getKey ( ) ; if ( ! entry . getValue ( ) . equals ( registrationProperties . get ( name ) ) ) { return false ; } } return true ; } public void setRegistrationPropertyValueFor ( String propertyName , Object value ) { setPropertyValueFor ( new QName ( propertyName ) , value ) ; } public RegistrationStatus getStatus ( ) { return status ; } public void setStatus ( RegistrationStatus status ) { ParameterValidation . throwIllegalArgExceptionIfNull ( status , "<STR_LIT>" ) ; this . status = status ; } public void updateProperties ( Map registrationProperties ) { properties = new HashMap ( registrationProperties ) ; } public boolean knows ( PortletContext portletContext ) { return portletContexts . contains ( portletContext ) ; } public boolean knows ( String portletContextId ) { return knows ( PortletContext . createPortletContext ( portletContextId ) ) ; } public Set < PortletContext > getKnownPortletContexts ( ) { return Collections . unmodifiableSet ( portletContexts ) ; } } </s>
<s> package org . gatein . registration ; public class RegistrationFailedException { } </s>