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 The LDAP Service to use 048 */ 049 public StoredProcedureFactory( LdapApiService codec ) 050 { 051 this.codec = codec; 052 } 053 054 055 /** 056 * {@inheritDoc} 057 */ 058 @Override 059 public String getOid() 060 { 061 return StoredProcedureRequest.EXTENSION_OID; 062 } 063 064 065 /** 066 * {@inheritDoc} 067 */ 068 @Override 069 public StoredProcedureResponse newResponse( byte[] encodedValue ) throws DecoderException 070 { 071 StoredProcedureResponseDecorator response = new StoredProcedureResponseDecorator( codec, 072 new StoredProcedureResponseImpl() ); 073 response.setResponseValue( encodedValue ); 074 return response; 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public StoredProcedureRequest newRequest( byte[] value ) 083 { 084 StoredProcedureRequestDecorator req = new StoredProcedureRequestDecorator( codec ); 085 086 if ( value != null ) 087 { 088 req.setRequestValue( value ); 089 } 090 return req; 091 } 092 093 094 /** 095 * {@inheritDoc} 096 */ 097 @Override 098 public StoredProcedureRequestDecorator decorate( ExtendedRequest modelRequest ) 099 { 100 if ( modelRequest instanceof StoredProcedureRequestDecorator ) 101 { 102 return ( StoredProcedureRequestDecorator ) modelRequest; 103 } 104 105 return new StoredProcedureRequestDecorator( codec, ( StoredProcedureRequest ) modelRequest ); 106 } 107 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override 113 public StoredProcedureResponseDecorator decorate( ExtendedResponse decoratedMessage ) 114 { 115 if ( decoratedMessage instanceof StoredProcedureResponseDecorator ) 116 { 117 return ( StoredProcedureResponseDecorator ) decoratedMessage; 118 } 119 120 return new StoredProcedureResponseDecorator( codec, ( StoredProcedureResponse ) decoratedMessage ); 121 } 122}