001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure; 021 022 023import org.apache.directory.api.asn1.DecoderException; 024import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory; 025import org.apache.directory.api.ldap.codec.api.LdapApiService; 026import org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureRequest; 027import org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureResponse; 028import org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureResponseImpl; 029import org.apache.directory.api.ldap.model.message.ExtendedRequest; 030import org.apache.directory.api.ldap.model.message.ExtendedResponse; 031 032 033/** 034 * An {@link ExtendedOperationFactory} for creating cancel extended request response 035 * pairs. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class StoredProcedureFactory implements ExtendedOperationFactory 040{ 041 private LdapApiService codec; 042 043 044 /** 045 * Creates a new instance of StoredProcedureFactory. 046 * 047 * @param codec 048 */ 049 public StoredProcedureFactory( LdapApiService codec ) 050 { 051 this.codec = codec; 052 } 053 054 055 /** 056 * {@inheritDoc} 057 */ 058 public String getOid() 059 { 060 return StoredProcedureRequest.EXTENSION_OID; 061 } 062 063 064 /** 065 * {@inheritDoc} 066 */ 067 public StoredProcedureResponse newResponse( byte[] encodedValue ) throws DecoderException 068 { 069 StoredProcedureResponseDecorator response = new StoredProcedureResponseDecorator( codec, 070 new StoredProcedureResponseImpl() ); 071 response.setResponseValue( encodedValue ); 072 return response; 073 } 074 075 076 /** 077 * {@inheritDoc} 078 */ 079 public StoredProcedureRequest newRequest( byte[] value ) 080 { 081 StoredProcedureRequestDecorator req = new StoredProcedureRequestDecorator( codec ); 082 083 if ( value != null ) 084 { 085 req.setRequestValue( value ); 086 } 087 return req; 088 } 089 090 091 /** 092 * {@inheritDoc} 093 */ 094 public StoredProcedureRequestDecorator decorate( ExtendedRequest modelRequest ) 095 { 096 if ( modelRequest instanceof StoredProcedureRequestDecorator ) 097 { 098 return ( StoredProcedureRequestDecorator ) modelRequest; 099 } 100 101 return new StoredProcedureRequestDecorator( codec, ( StoredProcedureRequest ) modelRequest ); 102 } 103 104 105 /** 106 * {@inheritDoc} 107 */ 108 public StoredProcedureResponseDecorator decorate( ExtendedResponse decoratedMessage ) 109 { 110 if ( decoratedMessage instanceof StoredProcedureResponseDecorator ) 111 { 112 return ( StoredProcedureResponseDecorator ) decoratedMessage; 113 } 114 115 return new StoredProcedureResponseDecorator( codec, ( StoredProcedureResponse ) decoratedMessage ); 116 } 117}