1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #include "commanddefinition.hxx"
28 #include "apitools.hxx"
29 #include "dbastrings.hrc"
30 #include "module_dba.hxx"
31 
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 
35 #include <tools/debug.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <comphelper/componentcontext.hxx>
38 
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::sdbc;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::container;
44 using namespace ::osl;
45 using namespace ::comphelper;
46 using namespace ::cppu;
47 
48 //........................................................................
49 namespace dbaccess
50 {
51 //........................................................................
52 
53 //==========================================================================
54 //= OCommandDefinition
55 //==========================================================================
createRegistryInfo_OCommandDefinition()56 extern "C" void SAL_CALL createRegistryInfo_OCommandDefinition()
57 {
58 	static ::dba::OAutoRegistration< OCommandDefinition > aAutoRegistration;
59 }
60 
61 //--------------------------------------------------------------------------
DBG_NAME(OCommandDefinition)62 DBG_NAME(OCommandDefinition)
63 //--------------------------------------------------------------------------
64 void OCommandDefinition::registerProperties()
65 {
66     OCommandDefinition_Impl& rCommandDefinition( getCommandDefinition() );
67 	registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
68 					&rCommandDefinition.m_sCommand, ::getCppuType(&rCommandDefinition.m_sCommand));
69 
70 	registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
71 					&rCommandDefinition.m_bEscapeProcessing, ::getBooleanCppuType());
72 
73 	registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
74 					&rCommandDefinition.m_sUpdateTableName, ::getCppuType(&rCommandDefinition.m_sUpdateTableName));
75 
76 	registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
77 					&rCommandDefinition.m_sUpdateSchemaName, ::getCppuType(&rCommandDefinition.m_sUpdateSchemaName));
78 
79 	registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
80 					&rCommandDefinition.m_sUpdateCatalogName, ::getCppuType(&rCommandDefinition.m_sUpdateCatalogName));
81 	registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
82 					&rCommandDefinition.m_aLayoutInformation, ::getCppuType(&rCommandDefinition.m_aLayoutInformation));
83 }
84 
85 //--------------------------------------------------------------------------
OCommandDefinition(const Reference<XMultiServiceFactory> & _xORB,const Reference<XInterface> & _rxContainer,const TContentPtr & _pImpl)86 OCommandDefinition::OCommandDefinition(const Reference< XMultiServiceFactory >& _xORB
87 									   ,const Reference< XInterface >& _rxContainer
88 									   ,const TContentPtr& _pImpl)
89 	:OComponentDefinition(_xORB,_rxContainer,_pImpl,sal_False)
90 {
91 	DBG_CTOR(OCommandDefinition, NULL);
92 	registerProperties();
93 }
94 //--------------------------------------------------------------------------
~OCommandDefinition()95 OCommandDefinition::~OCommandDefinition()
96 {
97 	DBG_DTOR(OCommandDefinition, NULL);
98 }
99 
100 //--------------------------------------------------------------------------
OCommandDefinition(const Reference<XInterface> & _rxContainer,const::rtl::OUString & _rElementName,const Reference<XMultiServiceFactory> & _xORB,const TContentPtr & _pImpl)101 OCommandDefinition::OCommandDefinition(	const Reference< XInterface >& _rxContainer
102 									   ,const ::rtl::OUString& _rElementName
103 									   ,const Reference< XMultiServiceFactory >& _xORB
104 									   ,const TContentPtr& _pImpl)
105 	:OComponentDefinition(_rxContainer,_rElementName,_xORB,_pImpl,sal_False)
106 {
107 	DBG_CTOR(OCommandDefinition, NULL);
108 	registerProperties();
109 }
110 
111 //--------------------------------------------------------------------------
112 IMPLEMENT_IMPLEMENTATION_ID(OCommandDefinition);
113 IMPLEMENT_GETTYPES2(OCommandDefinition,OCommandDefinition_Base,OComponentDefinition);
IMPLEMENT_FORWARD_XINTERFACE2(OCommandDefinition,OComponentDefinition,OCommandDefinition_Base)114 IMPLEMENT_FORWARD_XINTERFACE2( OCommandDefinition,OComponentDefinition,OCommandDefinition_Base)
115 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2(OCommandDefinition,OCommandDefinition_PROP)
116 //--------------------------------------------------------------------------
117 ::rtl::OUString OCommandDefinition::getImplementationName_static(  ) throw(RuntimeException)
118 {
119 	return ::rtl::OUString::createFromAscii("com.sun.star.comp.dba.OCommandDefinition");
120 }
121 
122 //--------------------------------------------------------------------------
getImplementationName()123 ::rtl::OUString SAL_CALL OCommandDefinition::getImplementationName(  ) throw(RuntimeException)
124 {
125 	return getImplementationName_static();
126 }
127 
128 //--------------------------------------------------------------------------
getSupportedServiceNames_static()129 Sequence< ::rtl::OUString > OCommandDefinition::getSupportedServiceNames_static(  ) throw(RuntimeException)
130 {
131 	Sequence< ::rtl::OUString > aServices(3);
132 	aServices.getArray()[0] = SERVICE_SDB_QUERYDEFINITION;
133 	aServices.getArray()[1] = SERVICE_SDB_COMMAND_DEFINITION;
134 	aServices.getArray()[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.Content"));
135 	return aServices;
136 }
137 
138 //--------------------------------------------------------------------------
getSupportedServiceNames()139 Sequence< ::rtl::OUString > SAL_CALL OCommandDefinition::getSupportedServiceNames(  ) throw(RuntimeException)
140 {
141 	return getSupportedServiceNames_static();
142 }
143 
144 //------------------------------------------------------------------------------
Create(const Reference<XComponentContext> & _rxContext)145 Reference< XInterface > OCommandDefinition::Create(const Reference< XComponentContext >& _rxContext)
146 {
147     ::comphelper::ComponentContext aContext( _rxContext );
148 	return *(new OCommandDefinition( aContext.getLegacyServiceFactory(), NULL, TContentPtr( new OCommandDefinition_Impl ) ) );
149 }
150 
151 // -----------------------------------------------------------------------------
rename(const::rtl::OUString & newName)152 void SAL_CALL OCommandDefinition::rename( const ::rtl::OUString& newName ) throw (SQLException, ElementExistException, RuntimeException)
153 {
154 	try
155 	{
156 		sal_Int32 nHandle = PROPERTY_ID_NAME;
157 		osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
158 		Any aOld = makeAny(m_pImpl->m_aProps.aTitle);
159 		aGuard.clear();
160 		Any aNew = makeAny(newName);
161 		fire(&nHandle, &aNew, &aOld, 1, sal_True );
162 
163 		m_pImpl->m_aProps.aTitle = newName;
164 		fire(&nHandle, &aNew, &aOld, 1, sal_False );
165 	}
166 	catch(const PropertyVetoException&)
167 	{
168 		throw ElementExistException(newName,*this);
169 	}
170 }
171 // -----------------------------------------------------------------------------
172 //........................................................................
173 }	// namespace dbaccess
174 //........................................................................
175 
176