http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/olingo-ext-spring/src/test/java/org/apache/olingo/ext/spring/integration/SpringOlingoNamespaceIntegrationTest.java ---------------------------------------------------------------------- diff --git a/ext/olingo-ext-spring/src/test/java/org/apache/olingo/ext/spring/integration/SpringOlingoNamespaceIntegrationTest.java b/ext/olingo-ext-spring/src/test/java/org/apache/olingo/ext/spring/integration/SpringOlingoNamespaceIntegrationTest.java deleted file mode 100644 index c2e91f8..0000000 --- a/ext/olingo-ext-spring/src/test/java/org/apache/olingo/ext/spring/integration/SpringOlingoNamespaceIntegrationTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.ext.spring.integration; - -import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.servlet.http.HttpServlet; - -import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; -import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; -import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; -import org.apache.olingo.client.api.v4.ODataClient; -import org.apache.olingo.client.core.ODataClientFactory; -import org.apache.olingo.commons.api.domain.ODataServiceDocument; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmSchema; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletHandler; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class SpringOlingoNamespaceIntegrationTest { - private static Server server; - - private static void configureAndStartupEmbeddedWebServer(Class<? extends HttpServlet> odataServletClass) throws Exception { - server = startupEmbeddedWebServer(); - ServletHandler handler = (ServletHandler) server.getHandler(); - handler.addServletWithMapping(odataServletClass, "/odata.svc/*"); - server.start(); - } - - private static Server startupEmbeddedWebServer() throws Exception { - Server server = new Server(8080); - ServletHandler handler = new ServletHandler(); - server.setHandler(handler); - //server.start(); - - return server; - } - - private static void shutdownEmbeddedWebServer() throws Exception { - if (server!=null) { - server.stop(); - server.join(); - server.destroy(); - } - } - - @BeforeClass - public static void setUp() throws Exception { - configureAndStartupEmbeddedWebServer(OlingoSpringTestServlet.class); - } - - @AfterClass - public static void tearDown() throws Exception { - shutdownEmbeddedWebServer(); - } - - //@Test - public void testServiceDocument() { - String serviceRoot = "http://localhost:8080/odata.svc"; - - ODataClient client = ODataClientFactory.getV4(); - ODataServiceDocumentRequest req = - client.getRetrieveRequestFactory().getServiceDocumentRequest(serviceRoot); - req.setContentType("application/json;odata.metadata=minimal"); - req.setAccept("application/json;odata.metadata=minimal"); - ODataRetrieveResponse<ODataServiceDocument> res = req.execute(); - - ODataServiceDocument serviceDocument = res.getBody(); - - Collection<String> entitySetNames = serviceDocument.getEntitySetNames(); - Assert.assertEquals(1, entitySetNames.size()); - String entitySetName = entitySetNames.iterator().next(); - Assert.assertEquals("sources1", entitySetName); - - Map<String,URI> entitySets = serviceDocument.getEntitySets(); - Assert.assertEquals(1, entitySets.size()); - Entry<String, URI> entitySet = entitySets.entrySet().iterator().next(); - Assert.assertEquals("sources1", entitySet.getKey()); - Assert.assertEquals("http://localhost:8080/odata.svc/sources1", entitySet.getValue().toString()); - - Map<String,URI> singletons = serviceDocument.getSingletons(); - Assert.assertEquals(0, singletons.size()); - - Map<String,URI> functionImports = serviceDocument.getFunctionImports(); - Assert.assertEquals(0, functionImports.size()); - } - - @Test - public void testMetadata() throws InterruptedException { - //Thread.sleep(60000); - String serviceRoot = "http://localhost:8080/odata.svc"; - - ODataClient client = ODataClientFactory.getV4(); - EdmMetadataRequest request = - client.getRetrieveRequestFactory().getMetadataRequest(serviceRoot); - ODataRetrieveResponse<Edm> response = request.execute(); - - Edm edm = response.getBody(); - - List<EdmSchema> schemas = edm.getSchemas(); - for (EdmSchema schema : schemas) { - System.out.println(schema.getNamespace()); - System.out.println(">> schema.getComplexTypes() size = "+schema.getComplexTypes().size()); - for (EdmComplexType complexType : schema.getComplexTypes()) { - System.out.println("- complex type = "+complexType); - } - System.out.println(">> schema.getEntityTypes() size = "+schema.getEntityTypes().size()); - for (EdmEntityType entityType : schema.getEntityTypes()) { - System.out.println("- entity type = "+entityType); - System.out.println(" >> qn = "+entityType.getFullQualifiedName()); - } - } - - //edm.get - EdmEntityType customerType = edm.getEntityType( - new FullQualifiedName("NorthwindModel", "Order")); - List<String> propertyNames = customerType.getPropertyNames(); - for (String propertyName : propertyNames) { - System.out.println(" - propertyName = "+propertyName); - EdmProperty property = customerType.getStructuralProperty(propertyName); - FullQualifiedName typeName = property.getType().getFullQualifiedName(); - System.out.println(" - type name = "+typeName); - } - } -}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-beans.xml ---------------------------------------------------------------------- diff --git a/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-beans.xml b/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-beans.xml deleted file mode 100644 index 3bebfed..0000000 --- a/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-beans.xml +++ /dev/null @@ -1,86 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:olingo="http://olingo.apache.org/schema/spring-olingo" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://olingo.apache.org/schema/spring-olingo - http://olingo.apache.org/schema/olingo/spring-olingo.xsd"> - - <!-- bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> - <property name="customEditors"> - <map> - <entry key="org.apache.olingo.commons.api.edm.FullQualifiedName" - value="org.apache.olingo.ext.spring.editor.FullQualifiedNameEditor" /> - </map> - </property> - </bean--> - - <bean id="edmProvider" class="org.apache.olingo.ext.spring.edm.GenericEdmProvider"> - <property name="schemas"> - <list> - <bean class="org.apache.olingo.server.api.edm.provider.Schema"> - <property name="namespace" value="test" /> - <property name="entityContainer"> - <bean class="org.apache.olingo.server.api.edm.provider.EntityContainer"> - <property name="entitySets"> - <list> - <bean class="org.apache.olingo.server.api.edm.provider.EntitySet"> - <property name="name" value="sources1" /> - <property name="type"> - <bean class="org.apache.olingo.commons.api.edm.FullQualifiedName"> - <constructor-arg value="ns.sources1"/> - </bean> - </property> - </bean> - </list> - </property> - </bean> - </property> - <property name="entityTypes"> - <list> - <bean class="org.apache.olingo.server.api.edm.provider.EntityType"> - <property name="name" value="sources1" /> - <property name="key"> - <list> - <bean class="org.apache.olingo.server.api.edm.provider.PropertyRef"> - <property name="propertyName" value="field1" /> - </bean> - </list> - </property> - <property name="properties"> - <list> - <bean class="org.apache.olingo.server.api.edm.provider.Property"> - <property name="name" value="field1" /> - <property name="type" value="Edm.String" /> - </bean> - </list> - </property> - </bean> - </list> - </property> - </bean> - </list> - </property> - </bean> - -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-namespace.xml ---------------------------------------------------------------------- diff --git a/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-namespace.xml b/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-namespace.xml deleted file mode 100644 index 32f86b1..0000000 --- a/ext/olingo-ext-spring/src/test/resources/applicationContext-edm-provider-namespace.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:olingo="http://olingo.apache.org/schema/olingo/spring-olingo" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://olingo.apache.org/schema/olingo/spring-olingo - http://olingo.apache.org/schema/olingo/spring-olingo.xsd"> - - <olingo:edm-provider id="edmProvider"> - <olingo:schema namespace="test" alias=""> - <olingo:entityContainer> - <olingo:entitySet name="sources1" type="sources1"/> - </olingo:entityContainer> - <!-- EnumType --> - <!-- getTypeDefinition --> - <olingo:entityType name="sources1"> - <olingo:key property-name="field1"/> - - <olingo:property name="field1" type="Edm.String"/> - <olingo:property name="field2" type="Edm.Int32"/> - <olingo:property name="field3" type="Edm.Int64"/> - <olingo:property name="field4" type="Edm.Double"/> - <olingo:property name="field5" type="Edm.Double"/> - <olingo:property name="field6" type="Edm.Boolean"/> - </olingo:entityType> - -<!-- <edm:complexType name="test"> --> -<!-- </edm:complexType> --> - - <!-- getActions --> - <!-- getFunctions --> - <!-- getTerm --> - <!-- getEntitySet --> - <!-- getSingleton --> - <!-- getActionImport --> - <!-- getFunctionImport --> - <!-- getEntityContainerInfo --> - <!-- getAliasInfos --> - <!-- getSchemas --> - <!-- getEntityContainer --> - </olingo:schema> - </olingo:edm-provider> -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-beans.xml ---------------------------------------------------------------------- diff --git a/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-beans.xml b/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-beans.xml deleted file mode 100644 index a33d539..0000000 --- a/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-beans.xml +++ /dev/null @@ -1,73 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:olingo="http://olingo.apache.org/schema/spring-olingo" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://olingo.apache.org/schema/spring-olingo - http://olingo.apache.org/schema/olingo/spring-olingo.xsd"> - - <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> - <property name="customEditors"> - <map> - <entry key="org.apache.olingo.commons.api.edm.FullQualifiedName" - value="org.apache.olingo.ext.spring.editor.FullQualifiedNameEditor" /> - </map> - </property> - </bean> - - <bean id="odata" class="org.apache.olingo.ext.spring.factory.ODataFactoryBean" /> - - <bean id="httpHandler" - class="org.apache.olingo.ext.spring.factory.ODataHttpHandlerFactoryBean"> - <property name="odata" ref="odata" /> - <property name="serviceMetadata"> - <bean class="org.apache.olingo.ext.spring.factory.ServiceMetadataFactoryBean"> - <property name="odata" ref="odata" /> - <property name="edmProvider" ref="edmProvider" /> - <property name="references"> - <list> - <bean class="org.apache.olingo.ext.spring.factory.EdmxReferenceFactoryBean"> - <property name="uri" - value="../v4.0/cs02/vocabularies/Org.OData.Core.V1.xml" /> - <property name="includes"> - <map> - <entry key="Org.OData.Core.V1" value="Core" /> - </map> - </property> - </bean> - </list> - </property> - </bean> - </property> - <property name="processors"> - <list> - <ref bean="testProcessor" /> - </list> - </property> - </bean> - - <bean id="edmProvider" class="org.apache.olingo.ext.spring.edm.GenericEdmProvider" /> - - <bean id="testProcessor" class="org.apache.olingo.ext.spring.config.TestProcessor" /> - -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-namespace.xml ---------------------------------------------------------------------- diff --git a/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-namespace.xml b/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-namespace.xml deleted file mode 100644 index 4e9de08..0000000 --- a/ext/olingo-ext-spring/src/test/resources/applicationContext-http-handler-namespace.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:olingo="http://olingo.apache.org/schema/olingo/spring-olingo" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://olingo.apache.org/schema/olingo/spring-olingo - http://olingo.apache.org/schema/olingo/spring-olingo.xsd"> - - <olingo:http-handler id="httpHandler" edm-provider="edmProvider"> - <olingo:reference uri="../v4.0/cs02/vocabularies/Org.OData.Core.V1.xml"> - <olingo:include key="Org.OData.Core.V1" value="Core"/> - </olingo:reference> - <olingo:processor ref="testProcessor"/> - </olingo:http-handler> - - <bean id="edmProvider" class="org.apache.olingo.ext.spring.edm.GenericEdmProvider" /> - - <bean id="testProcessor" class="org.apache.olingo.ext.spring.config.TestProcessor" /> -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/olingo-ext-spring/src/test/resources/applicationContext-namespace.xml ---------------------------------------------------------------------- diff --git a/ext/olingo-ext-spring/src/test/resources/applicationContext-namespace.xml b/ext/olingo-ext-spring/src/test/resources/applicationContext-namespace.xml deleted file mode 100644 index 73579b4..0000000 --- a/ext/olingo-ext-spring/src/test/resources/applicationContext-namespace.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:olingo="http://olingo.apache.org/schema/olingo/spring-olingo" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://olingo.apache.org/schema/olingo/spring-olingo - http://olingo.apache.org/schema/olingo/spring-olingo.xsd"> - - <olingo:http-handler id="httpHandler" edm-provider="edmProvider"> - <olingo:reference uri="../v4.0/cs02/vocabularies/Org.OData.Core.V1.xml"> - <olingo:include key="Org.OData.Core.V1" value="Core"/> - </olingo:reference> - <olingo:processor ref="testProcessor"/> - </olingo:http-handler> - - <olingo:edm-provider id="edmProvider"> - <olingo:schema namespace="test" alias=""> - <olingo:entityContainer> - <olingo:entitySet name="sources1" type="sources1"/> - </olingo:entityContainer> - <!-- EnumType --> - <!-- getTypeDefinition --> - <olingo:entityType name="sources1"> - <olingo:key property-name="field1"/> - - <olingo:property name="field1" type="Edm.String"/> - <olingo:property name="field2" type="Edm.Int32"/> - <olingo:property name="field3" type="Edm.Int64"/> - <olingo:property name="field4" type="Edm.Double"/> - <olingo:property name="field5" type="Edm.Double"/> - <olingo:property name="field6" type="Edm.Boolean"/> - </olingo:entityType> - </olingo:schema> - </olingo:edm-provider> - - <bean id="testProcessor" class="org.apache.olingo.ext.spring.config.TestProcessor" /> -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/pom.xml ---------------------------------------------------------------------- diff --git a/ext/pom.xml b/ext/pom.xml index b31bf67..f483789 100644 --- a/ext/pom.xml +++ b/ext/pom.xml @@ -40,4 +40,13 @@ <module>client-proxy</module> <module>client-android</module> </modules> + + <profiles> + <profile> + <id>spring</id> + <modules> + <module>spring</module> + </modules> + </profile> + </profiles> </project> http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/pom.xml ---------------------------------------------------------------------- diff --git a/ext/spring/pom.xml b/ext/spring/pom.xml new file mode 100644 index 0000000..b18e4b7 --- /dev/null +++ b/ext/spring/pom.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor + license agreements. See the NOTICE file distributed with this work for additional + information regarding copyright ownership. The ASF licenses this file to + you under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of + the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required + by applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied. See the License for the specific + language governing permissions and limitations under the License. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <artifactId>spring</artifactId> + <name>${project.artifactId}</name> + <packaging>jar</packaging> + + <parent> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-ext</artifactId> + <version>4.0.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <properties> + <spring.version>4.1.3.RELEASE</spring.version> + <javax.servlet.version>2.5</javax.servlet.version> + <jetty.version>7.5.4.v20111024</jetty.version> + <!--<jetty.version>9.3.0.M1</jetty.version>--> + </properties> + + <dependencies> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>${javax.servlet.version}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-server-api</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-server-core</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-commons-api</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-commons-core</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-client-core</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.olingo</groupId> + <artifactId>odata-client-api</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>${sl4j.version}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${spring.version}</version> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${jetty.version}</version> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-http</artifactId> + <version>${jetty.version}</version> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <version>${jetty.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/OlingoSpringServlet.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/OlingoSpringServlet.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/OlingoSpringServlet.java new file mode 100644 index 0000000..981bcfe --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/OlingoSpringServlet.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring; + +import java.io.IOException; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.http.HttpStatus; +import org.apache.olingo.server.api.ODataHttpHandler; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +public class OlingoSpringServlet extends HttpServlet { + + private ApplicationContext context; + + private ODataHttpHandler httpHandler; + + protected ODataHttpHandler getHttpHandler() throws ServletException { + Map<String, ODataHttpHandler> odatas = context + .getBeansOfType(ODataHttpHandler.class); + if (odatas.size() == 1) { + return odatas.values().iterator().next(); + } + + throw new ServletException( + "No OData HTTP handler can be found in the Spring container."); + } + + protected ApplicationContext initializeApplicationContext(ServletConfig config) + throws ServletException { + WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(config + .getServletContext()); + + if (context==null) { + throw new ServletException( + "No Spring container is configured within the Web application."); + } + + return context; + } + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(); + + context = initializeApplicationContext(config); + + httpHandler = getHttpHandler(); + } + + @Override + protected void service(final HttpServletRequest req, + final HttpServletResponse resp) throws ServletException, + IOException { + System.err.println(">> service - begin - req = "+req.getRequestURL()); + try { + httpHandler.process(req, resp); + } catch (RuntimeException e) { + // TODO: to be improved + throw new ServletException(e); + } + System.err.println(">> service - end"); + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmBeanDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmBeanDefinitionHelper.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmBeanDefinitionHelper.java new file mode 100644 index 0000000..a3c24dd --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmBeanDefinitionHelper.java @@ -0,0 +1,266 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.config; + +import java.util.List; + +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.ext.spring.edm.GenericEdmProvider; +import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer; +import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet; +import org.apache.olingo.commons.api.edm.provider.CsdlEntityType; +import org.apache.olingo.commons.api.edm.provider.CsdlProperty; +import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef; +import org.apache.olingo.commons.api.edm.provider.CsdlSchema; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedList; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +public abstract class OlingoEdmBeanDefinitionHelper { + private static final Class<?> EDM_PROVIDER_CLASS = GenericEdmProvider.class; + private static final Class<?> SCHEMA_CLASS = CsdlSchema.class; + private static final Class<?> ENTITY_CONTAINER_CLASS = CsdlEntityContainer.class; + private static final Class<?> ENTITY_SET_CLASS = CsdlEntitySet.class; + private static final Class<?> ENTITY_TYPE_CLASS = CsdlEntityType.class; + private static final Class<?> PROPERTY_REF_CLASS = CsdlPropertyRef.class; + private static final Class<?> PROPERTY_CLASS = CsdlProperty.class; + private static final Class<?> FULL_QUALIFIED_NAME_CLASS = FullQualifiedName.class; + + private static final String SCHEMA_ELEMENT = "schema"; + private static final String ENTITY_CONTAINER_ELEMENT = "entityContainer"; + private static final String ENTITY_TYPE_ELEMENT = "entityType"; + private static final String COMPLEX_TYPE_ELEMENT = "complexType"; + private static final String ENTITY_SET_ELEMENT = "entitySet"; + private static final String KEY_ELEMENT = "key"; + private static final String PROPERTY_ELEMENT = "property"; + + private static final String NAME_ATTR = "name"; + private static final String NAMESPACE_ATTR = "namespace"; + private static final String TYPE_ATTR = "type"; + private static final String PROPERTY_NAME_ATTR = "property-name"; + private static final String ALIAS_ATTR = "alias"; + + private static final String SCHEMA_LIST_PROPERTY = "schemas"; + private static final String ENTITY_TYPE_LIST_PROPERTY = "entityTypes"; + private static final String COMPLEX_TYPE_LIST_PROPERTY = "complexTypes"; + private static final String ENTITY_SET_LIST_PROPERTY = "entitySets"; + private static final String ENTITY_CONTAINER_PROPERTY = "entityContainer"; + private static final String NAME_PROPERTY = "name"; + private static final String NAMESPACE_PROPERTY = "namespace"; + private static final String ALIAS_PROPERTY = "alias"; + private static final String TYPE_PROPERTY = "type"; + private static final String KEY_LIST_PROPERTY = "key"; + private static final String PROPERTY_LIST_PROPERTY = "properties"; + private static final String PROPERTY_NAME_PROPERTY = "name"; + + private static String elementAttribute(Element element, String name) { + String value = element.getAttribute(name); + return value.length() == 0 ? null : value; + } + + private static BeanDefinitionBuilder createBeanDefinitionBuilder( + Class<?> beanClass) { + return BeanDefinitionBuilder.rootBeanDefinition(beanClass); + } + + public static BeanDefinition parseEdmProvider(Element element, + ParserContext parserContext) { + BeanDefinitionBuilder configuration = createBeanDefinitionBuilder(EDM_PROVIDER_CLASS); + + // Schemas + List<Element> schemaElements = DomUtils.getChildElementsByTagName( + element, SCHEMA_ELEMENT); + if (schemaElements.size() > 0) { + ManagedList<BeanDefinition> schemaList = new ManagedList<BeanDefinition>( + schemaElements.size()); + for (Element schemaElement : schemaElements) { + BeanDefinition schema = parseSchema(schemaElement, + parserContext); + schemaList.add(schema); + } + configuration.addPropertyValue(SCHEMA_LIST_PROPERTY, schemaList); + } + + return configuration.getBeanDefinition(); + } + + private static BeanDefinition parseSchema(Element element, + ParserContext parserContext) { + BeanDefinitionBuilder schema = createBeanDefinitionBuilder(SCHEMA_CLASS); + + String namespace = elementAttribute(element, NAMESPACE_ATTR); + schema.addPropertyValue(NAMESPACE_PROPERTY, namespace); + String alias = elementAttribute(element, ALIAS_ATTR); + if (alias != null && !alias.isEmpty()) { + schema.addPropertyValue(ALIAS_PROPERTY, alias); + } + + // Entity container + List<Element> entityContainerElements = DomUtils + .getChildElementsByTagName(element, ENTITY_CONTAINER_ELEMENT); + if (entityContainerElements.size() == 1) { + Element entityContainerElement = entityContainerElements.get(0); + BeanDefinition entityContainer = parseEntityContainer( + entityContainerElement, namespace, parserContext); + schema.addPropertyValue(ENTITY_CONTAINER_PROPERTY, entityContainer); + } + + // Entity types + List<Element> entityTypeElements = DomUtils.getChildElementsByTagName( + element, ENTITY_TYPE_ELEMENT); + if (entityTypeElements.size() > 0) { + List<BeanDefinition> entityTypeList = new ManagedList<BeanDefinition>( + entityTypeElements.size()); + for (Element entityTypeElement : entityTypeElements) { + BeanDefinition entityType = parseEntityType(entityTypeElement, + parserContext); + entityTypeList.add(entityType); + } + schema.addPropertyValue(ENTITY_TYPE_LIST_PROPERTY, entityTypeList); + } + + // Complex types + List<Element> complexTypeElements = DomUtils.getChildElementsByTagName( + element, COMPLEX_TYPE_ELEMENT); + if (complexTypeElements.size() > 0) { + ManagedList<BeanDefinition> complexTypeList = new ManagedList<BeanDefinition>( + complexTypeElements.size()); + for (Element complexTypeElement : complexTypeElements) { + BeanDefinition complexType = parseComplexType( + complexTypeElement, parserContext); + complexTypeList.add(complexType); + } + schema.addPropertyValue(COMPLEX_TYPE_LIST_PROPERTY, complexTypeList); + } + + return schema.getBeanDefinition(); + } + + private static BeanDefinition parseEntityContainer(Element element, + String namespace, ParserContext parserContext) { + BeanDefinitionBuilder entityContainer = createBeanDefinitionBuilder(ENTITY_CONTAINER_CLASS); + + // Name + entityContainer.addPropertyValue(NAME_PROPERTY, namespace + + "EntityContainer"); + + // Entity sets + List<Element> entitySetElements = DomUtils.getChildElementsByTagName( + element, ENTITY_SET_ELEMENT); + if (entitySetElements.size() > 0) { + ManagedList<BeanDefinition> entitySetList = new ManagedList<BeanDefinition>( + entitySetElements.size()); + for (Element entitySetElement : entitySetElements) { + BeanDefinition entitySet = parseEntitySet(entitySetElement, + namespace, parserContext); + entitySetList.add(entitySet); + } + entityContainer.addPropertyValue(ENTITY_SET_LIST_PROPERTY, + entitySetList); + } + + return entityContainer.getBeanDefinition(); + } + + private static BeanDefinition parseEntitySet(Element element, + String namespace, ParserContext parserContext) { + BeanDefinitionBuilder entitySet = createBeanDefinitionBuilder(ENTITY_SET_CLASS); + + String name = elementAttribute(element, NAME_ATTR); + String type = elementAttribute(element, TYPE_ATTR); + entitySet.addPropertyValue(NAME_PROPERTY, name); + + BeanDefinitionBuilder fqn = createBeanDefinitionBuilder(FULL_QUALIFIED_NAME_CLASS); + fqn.addConstructorArgValue(namespace); + fqn.addConstructorArgValue(type); + + entitySet.addPropertyValue(TYPE_PROPERTY, fqn.getBeanDefinition()); + + return entitySet.getBeanDefinition(); + } + + private static BeanDefinition parseEntityType(Element element, + ParserContext parserContext) { + BeanDefinitionBuilder entityType = createBeanDefinitionBuilder(ENTITY_TYPE_CLASS); + + String propertyName = elementAttribute(element, NAME_ATTR); + entityType.addPropertyValue(NAME_PROPERTY, propertyName); + + // Key + List<Element> keyElements = DomUtils.getChildElementsByTagName(element, + KEY_ELEMENT); + if (keyElements.size() > 0) { + ManagedList<BeanDefinition> keyList = new ManagedList<BeanDefinition>( + keyElements.size()); + for (Element keyElement : keyElements) { + BeanDefinition key = parseKey(keyElement, parserContext); + keyList.add(key); + } + entityType.addPropertyValue(KEY_LIST_PROPERTY, keyList); + } + + // Properties + List<Element> propertyElements = DomUtils.getChildElementsByTagName( + element, PROPERTY_ELEMENT); + if (propertyElements.size() > 0) { + ManagedList<BeanDefinition> entitySetList = new ManagedList<BeanDefinition>( + propertyElements.size()); + for (Element propertyElement : propertyElements) { + BeanDefinition property = parseProperty(propertyElement, + parserContext); + entitySetList.add(property); + } + entityType.addPropertyValue(PROPERTY_LIST_PROPERTY, entitySetList); + } + + return entityType.getBeanDefinition(); + } + + private static BeanDefinition parseKey(Element element, + ParserContext parserContext) { + BeanDefinitionBuilder property = createBeanDefinitionBuilder(PROPERTY_REF_CLASS); + + String propertyName = elementAttribute(element, PROPERTY_NAME_ATTR); + property.addPropertyValue(PROPERTY_NAME_PROPERTY, propertyName); + + return property.getBeanDefinition(); + } + + private static BeanDefinition parseProperty(Element element, + ParserContext parserContext) { + BeanDefinitionBuilder property = createBeanDefinitionBuilder(PROPERTY_CLASS); + + String name = elementAttribute(element, NAME_ATTR); + String type = elementAttribute(element, TYPE_ATTR); + property.addPropertyValue(NAME_PROPERTY, name); + property.addPropertyValue(TYPE_PROPERTY, type); + + return property.getBeanDefinition(); + } + + private static BeanDefinition parseComplexType(Element complexTypeElement, + ParserContext parserContext) { + // TODO to be implemented + return null; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmProviderBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmProviderBeanDefinitionParser.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmProviderBeanDefinitionParser.java new file mode 100644 index 0000000..b64ebd0 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoEdmProviderBeanDefinitionParser.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.config; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.w3c.dom.Element; + +public class OlingoEdmProviderBeanDefinitionParser extends AbstractBeanDefinitionParser { + + @Override + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + BeanDefinition configuration = OlingoEdmBeanDefinitionHelper.parseEdmProvider(element, parserContext); + return (AbstractBeanDefinition) configuration; + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHandlerBeanDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHandlerBeanDefinitionHelper.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHandlerBeanDefinitionHelper.java new file mode 100644 index 0000000..42f8889 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHandlerBeanDefinitionHelper.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.config; + +import java.util.List; + +import org.apache.olingo.ext.spring.factory.EdmxReferenceFactoryBean; +import org.apache.olingo.ext.spring.factory.ODataFactoryBean; +import org.apache.olingo.ext.spring.factory.ODataHttpHandlerFactoryBean; +import org.apache.olingo.ext.spring.factory.ServiceMetadataFactoryBean; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedList; +import org.springframework.beans.factory.support.ManagedMap; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +public abstract class OlingoHandlerBeanDefinitionHelper { + + private static final Class<?> ODATA_FACTORY_BEAN_CLASS = ODataFactoryBean.class; + private static final Class<?> HTTP_HANDLER_FACTORY_BEAN_CLASS = ODataHttpHandlerFactoryBean.class; + private static final Class<?> SERVICE_METADATA_FACTORY_BEAN_CLASS = ServiceMetadataFactoryBean.class; + private static final Class<?> EDMX_REFERENCE_FACTORY_BEAN = EdmxReferenceFactoryBean.class; + + private static final String REFERENCE_ELEMENT = "reference"; + private static final String PROCESSOR_ELEMENT = "processor"; + private static final String INCLUDE_ELEMENT = "include"; + + private static final String EDM_PROVIDER_ATTR = "edm-provider"; + private static final String REF_ATTR = "ref"; + private static final String URI_ATTR = "uri"; + private static final String KEY_ATTR = "key"; + private static final String VALUE_ATTR = "value"; + + private static final String ODATA_PROPERTY = "odata"; + private static final String SERVICE_METADATA_PROPERTY = "serviceMetadata"; + private static final String REFERENCES_LIST_PROPERTY = "references"; + private static final String PROCESSORS_LIST_PROPERTY = "processors"; + private static final String EDM_PROVIDER_PROPERTY = "edmProvider"; + private static final String URI_PROPERTY = "uri"; + private static final String INCLUDES_PROPERTY = "includes"; + + private static String elementAttribute(Element element, String name) { + String value = element.getAttribute(name); + return value.length() == 0 ? null : value; + } + + private static BeanDefinitionBuilder createBeanDefinitionBuilder( + Class<?> beanClass) { + return BeanDefinitionBuilder.rootBeanDefinition(beanClass); + } + + public static BeanDefinition parseHttpHandler(Element element, + ParserContext parserContext) { + BeanDefinitionBuilder httpHandler = createBeanDefinitionBuilder(HTTP_HANDLER_FACTORY_BEAN_CLASS); + + // OData + BeanDefinitionBuilder odataBuilder = createBeanDefinitionBuilder(ODATA_FACTORY_BEAN_CLASS); + BeanDefinition odata = odataBuilder.getBeanDefinition(); + + httpHandler.addPropertyValue(ODATA_PROPERTY, odata); + + // ServiceMetadata + BeanDefinitionBuilder serviceMetadata = + createBeanDefinitionBuilder(SERVICE_METADATA_FACTORY_BEAN_CLASS); + serviceMetadata.addPropertyValue(ODATA_PROPERTY, odata); + + String edmProviderRef = elementAttribute(element, EDM_PROVIDER_ATTR); + serviceMetadata.addPropertyValue(EDM_PROVIDER_PROPERTY, + new RuntimeBeanReference(edmProviderRef)); + + // References + List<Element> referenceElements = DomUtils.getChildElementsByTagName( + element, REFERENCE_ELEMENT); + if (referenceElements.size() > 0) { + ManagedList<BeanDefinition> referenceList = new ManagedList<BeanDefinition>( + referenceElements.size()); + for (Element referenceElement : referenceElements) { + BeanDefinition reference = parseReference(referenceElement, + parserContext); + referenceList.add(reference); + } + serviceMetadata.addPropertyValue(REFERENCES_LIST_PROPERTY, + referenceList); + } + + httpHandler.addPropertyValue(SERVICE_METADATA_PROPERTY, + serviceMetadata.getBeanDefinition()); + + // Processors + List<Element> processorElements = DomUtils.getChildElementsByTagName( + element, PROCESSOR_ELEMENT); + if (processorElements.size() > 0) { + ManagedList<RuntimeBeanReference> processorList = new ManagedList<RuntimeBeanReference>( + processorElements.size()); + for (Element processorElement : processorElements) { + RuntimeBeanReference processorRef = parseProcessor( + processorElement, parserContext); + processorList.add(processorRef); + } + httpHandler.addPropertyValue(PROCESSORS_LIST_PROPERTY, + processorList); + } + + AbstractBeanDefinition configurationDef = httpHandler + .getBeanDefinition(); + return configurationDef; + } + + private static BeanDefinition parseReference(Element referenceElement, + ParserContext parserContext) { + BeanDefinitionBuilder reference = createBeanDefinitionBuilder(EDMX_REFERENCE_FACTORY_BEAN); + + String uri = elementAttribute(referenceElement, URI_ATTR); + reference.addPropertyValue(URI_PROPERTY, uri); + + // Processors + List<Element> includeElements = DomUtils.getChildElementsByTagName( + referenceElement, INCLUDE_ELEMENT); + if (includeElements.size() > 0) { + ManagedMap<String, String> includeMap = new ManagedMap<String, String>( + includeElements.size()); + for (Element includeElement : includeElements) { + String key = elementAttribute(includeElement, KEY_ATTR); + String value = elementAttribute(includeElement, VALUE_ATTR); + includeMap.put(key, value); + } + reference.addPropertyValue(INCLUDES_PROPERTY, includeMap); + } + + return reference.getBeanDefinition(); + } + + private static RuntimeBeanReference parseProcessor( + Element processorElement, ParserContext parserContext) { + String ref = elementAttribute(processorElement, REF_ATTR); + return new RuntimeBeanReference(ref); + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHttpHandlerBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHttpHandlerBeanDefinitionParser.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHttpHandlerBeanDefinitionParser.java new file mode 100644 index 0000000..6414fc5 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoHttpHandlerBeanDefinitionParser.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.config; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.w3c.dom.Element; + +public class OlingoHttpHandlerBeanDefinitionParser extends AbstractBeanDefinitionParser { + + @Override + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + BeanDefinition configuration = OlingoHandlerBeanDefinitionHelper.parseHttpHandler(element, parserContext); + return (AbstractBeanDefinition) configuration; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoNamespaceHandler.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoNamespaceHandler.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoNamespaceHandler.java new file mode 100644 index 0000000..2dc64fa --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/config/OlingoNamespaceHandler.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.config; + +import org.springframework.beans.factory.xml.NamespaceHandlerSupport; + +/** + * Dedicated Spring namespace handler for Olingo. This namespace is directly + * usable within a Spring application context. + * + * This namespace can be configured in Spring XML configuration files using + * standard mechanisms of XML namespace, as following: + * + * <beans xmlns="http://www.springframework.org/schema/beans" + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + * xmlns:olingo="http://olingo.apache.org/schema/olingo/spring-olingo" + * xsi:schemaLocation="http://www.springframework.org/schema/beans + * http://www.springframework.org/schema/beans/spring-beans.xsd + * http://olingo.apache.org/schema/olingo/spring-olingo + * http://olingo.apache.org/schema/olingo/spring-olingo.xsd"> + * (...) + * </beans> + * + * @author Thierry Templier + */ +public class OlingoNamespaceHandler extends NamespaceHandlerSupport { + + public static final String EDM_PROVIDER_ELEMENT = "edm-provider"; + + public static final String HTTP_HANDLER_ELEMENT = "http-handler"; + + /** + * Registers bean definition parsers for the olingo namespace. + * + * @see OlingoEdmProviderBeanDefinitionParser + * @see OlingoHttpHandlerBeanDefinitionParser + */ + public void init() { + registerBeanDefinitionParser(EDM_PROVIDER_ELEMENT, + new OlingoEdmProviderBeanDefinitionParser()); + registerBeanDefinitionParser(HTTP_HANDLER_ELEMENT, + new OlingoHttpHandlerBeanDefinitionParser()); + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameConverter.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameConverter.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameConverter.java new file mode 100644 index 0000000..b1cdb7e --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameConverter.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.editor; + + +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.springframework.core.convert.converter.Converter; + +public class FullQualifiedNameConverter implements Converter<FullQualifiedName, String>{ + @Override + public String convert(FullQualifiedName fullQualifiedName) { + return fullQualifiedName.getFullQualifiedNameAsString(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameEditor.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameEditor.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameEditor.java new file mode 100644 index 0000000..71bf208 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/FullQualifiedNameEditor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.editor; + +import java.beans.PropertyEditorSupport; + +import org.apache.olingo.commons.api.edm.FullQualifiedName; + +public class FullQualifiedNameEditor extends PropertyEditorSupport { + public void setAsText(String text) { + String[] tokens = text.split("\\."); + if (tokens.length == 2) { + setValue(new FullQualifiedName(tokens[0], tokens[1])); + } else { + setValue(new FullQualifiedName(text)); + } + } + + @Override + public String getAsText() { + return super.getAsText(); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/ToFullQualifiedNameConverter.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/ToFullQualifiedNameConverter.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/ToFullQualifiedNameConverter.java new file mode 100644 index 0000000..bf2482a --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/editor/ToFullQualifiedNameConverter.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.editor; + + +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.springframework.core.convert.converter.Converter; + +public class ToFullQualifiedNameConverter implements Converter<String, FullQualifiedName> { + @Override + public FullQualifiedName convert(String s) { + return new FullQualifiedName(s); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/edm/GenericEdmProvider.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/edm/GenericEdmProvider.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/edm/GenericEdmProvider.java new file mode 100644 index 0000000..f8574da --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/edm/GenericEdmProvider.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.edm; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.olingo.commons.api.ODataException; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider; +import org.apache.olingo.commons.api.edm.provider.CsdlAction; +import org.apache.olingo.commons.api.edm.provider.CsdlActionImport; +import org.apache.olingo.commons.api.edm.provider.CsdlAliasInfo; +import org.apache.olingo.commons.api.edm.provider.CsdlComplexType; +import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer; +import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo; +import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet; +import org.apache.olingo.commons.api.edm.provider.CsdlEntityType; +import org.apache.olingo.commons.api.edm.provider.CsdlEnumType; +import org.apache.olingo.commons.api.edm.provider.CsdlFunction; +import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport; +import org.apache.olingo.commons.api.edm.provider.CsdlSchema; +import org.apache.olingo.commons.api.edm.provider.CsdlSingleton; +import org.apache.olingo.commons.api.edm.provider.CsdlTerm; +import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition; + +public class GenericEdmProvider extends CsdlAbstractEdmProvider { + + private String containerName = "default"; + + private List<CsdlSchema> schemas = new ArrayList<CsdlSchema>(); + + // OData + + @Override + public List<CsdlSchema> getSchemas() throws ODataException { + return schemas; + } + + @Override + public CsdlEntityContainer getEntityContainer() throws ODataException { + CsdlEntityContainer container = new CsdlEntityContainer(); + container.setName(containerName); + + // EntitySets + List<CsdlEntitySet> entitySets = new ArrayList<CsdlEntitySet>(); + container.setEntitySets(entitySets); + + // Load entity sets per index + for (CsdlSchema schema : schemas) { + + if (schema.getEntityContainer() != null + && schema.getEntityContainer().getEntitySets() != null) { + for (CsdlEntitySet schemaEntitySet : schema.getEntityContainer() + .getEntitySets()) { + CsdlEntitySet entitySet = new CsdlEntitySet().setName( + schemaEntitySet.getName()).setType( + new FullQualifiedName( + schemaEntitySet.getTypeFQN().getNamespace(), + schemaEntitySet.getTypeFQN().getName())); + entitySets.add(entitySet); + } + } + } + + return container; + } + + private CsdlSchema findSchema(String namespace) { + for (CsdlSchema schema : schemas) { + if (schema.getNamespace().equals(namespace)) { + return schema; + } + } + + return null; + } + + private CsdlEntityType findEntityType(CsdlSchema schema, String entityTypeName) { + for (CsdlEntityType entityType : schema.getEntityTypes()) { + if (entityType.getName().equals(entityTypeName)) { + return entityType; + } + } + + return null; + } + + @Override + public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) + throws ODataException { + CsdlSchema schema = findSchema(entityTypeName.getNamespace()); + return findEntityType(schema, entityTypeName.getName()); + } + + private CsdlEnumType findEnumType(CsdlSchema schema, String enumTypeName) { + for (CsdlEnumType enumType : schema.getEnumTypes()) { + if (enumType.getName().equals(enumTypeName)) { + return enumType; + } + } + + return null; + } + + @Override + public CsdlEnumType getEnumType(FullQualifiedName enumTypeName) + throws ODataException { + CsdlSchema schema = findSchema(enumTypeName.getNamespace()); + return findEnumType(schema, enumTypeName.getName()); + } + + @Override + public CsdlTypeDefinition getTypeDefinition(FullQualifiedName typeDefinitionName) + throws ODataException { + System.out.println(">> getTypeDefinition"); + // TODO Auto-generated method stub + return super.getTypeDefinition(typeDefinitionName); + } + + private CsdlComplexType findComplexType(CsdlSchema schema, String complexTypeName) { + for (CsdlComplexType complexType : schema.getComplexTypes()) { + if (complexType.getName().equals(complexTypeName)) { + return complexType; + } + } + + return null; + } + + @Override + public CsdlComplexType getComplexType(FullQualifiedName complexTypeName) + throws ODataException { + CsdlSchema schema = findSchema(complexTypeName.getNamespace()); + return findComplexType(schema, complexTypeName.getName()); + } + + @Override + public List<CsdlAction> getActions(FullQualifiedName actionName) + throws ODataException { + System.out.println(">> getActions"); + // TODO Auto-generated method stub + return super.getActions(actionName); + } + + @Override + public List<CsdlFunction> getFunctions(FullQualifiedName functionName) + throws ODataException { + System.out.println(">> getFunctions"); + // TODO Auto-generated method stub + return super.getFunctions(functionName); + } + + @Override + public CsdlTerm getTerm(FullQualifiedName termName) throws ODataException { + System.out.println(">> getTerm"); + // TODO Auto-generated method stub + return super.getTerm(termName); + } + + private CsdlEntitySet findEntitySetInSchemas(String entitySetName) + throws ODataException { + List<CsdlSchema> schemas = getSchemas(); + for (CsdlSchema schema : schemas) { + CsdlEntityContainer entityContainer = schema.getEntityContainer(); + List<CsdlEntitySet> entitySets = entityContainer.getEntitySets(); + for (CsdlEntitySet entitySet : entitySets) { + if (entitySet.getName().equals(entitySetName)) { + return entitySet; + } + } + } + return null; + } + + @Override + public CsdlEntitySet getEntitySet(FullQualifiedName entityContainer, + String entitySetName) throws ODataException { + return findEntitySetInSchemas(entitySetName); + } + + @Override + public CsdlSingleton getSingleton(FullQualifiedName entityContainer, + String singletonName) throws ODataException { + System.out.println(">> getSingleton"); + // TODO Auto-generated method stub + return super.getSingleton(entityContainer, singletonName); + } + + @Override + public CsdlActionImport getActionImport(FullQualifiedName entityContainer, + String actionImportName) throws ODataException { + System.out.println(">> getActionImport"); + // TODO Auto-generated method stub + return super.getActionImport(entityContainer, actionImportName); + } + + @Override + public CsdlFunctionImport getFunctionImport(FullQualifiedName entityContainer, + String functionImportName) throws ODataException { + System.out.println(">> getFunctionImport"); + // TODO Auto-generated method stub + return super.getFunctionImport(entityContainer, functionImportName); + } + + @Override + public CsdlEntityContainerInfo getEntityContainerInfo( + FullQualifiedName entityContainerName) throws ODataException { + CsdlEntityContainer container = getEntityContainer(); + FullQualifiedName fqName = new FullQualifiedName(container.getName(), + container.getName()); + CsdlEntityContainerInfo info = new CsdlEntityContainerInfo(); + info.setContainerName(fqName); + return info; + } + + @Override + public List<CsdlAliasInfo> getAliasInfos() throws ODataException { + System.out.println(">> getAliasInfos"); + // TODO Auto-generated method stub + return super.getAliasInfos(); + } + + // DI + + public void setSchemas(List<CsdlSchema> schemas) { + this.schemas = schemas; + } + + public String getContainerName() { + return containerName; + } + + public void setContainerName(String containerName) { + this.containerName = containerName; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/EdmxReferenceFactoryBean.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/EdmxReferenceFactoryBean.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/EdmxReferenceFactoryBean.java new file mode 100644 index 0000000..49684e4 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/EdmxReferenceFactoryBean.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.factory; + +import java.net.URI; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.olingo.server.api.edmx.EdmxReference; +import org.apache.olingo.server.api.edmx.EdmxReferenceInclude; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; + +public class EdmxReferenceFactoryBean implements FactoryBean<EdmxReference>, + InitializingBean { + private String uri; + private Map<String, String> includes; + + @Override + public void afterPropertiesSet() throws Exception { + if (uri == null) { + throw new IllegalArgumentException("The property uri is required."); + } + } + + @Override + public EdmxReference getObject() throws Exception { + EdmxReference reference = new EdmxReference(URI.create(uri)); + if (includes != null) { + for (Entry<String, String> include : includes.entrySet()) { + reference.addInclude(new EdmxReferenceInclude(include.getKey(), + include.getValue())); + } + } + return reference; + } + + @Override + public Class<?> getObjectType() { + return EdmxReference.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public Map<String, String> getIncludes() { + return includes; + } + + public void setIncludes(Map<String, String> includes) { + this.includes = includes; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataFactoryBean.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataFactoryBean.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataFactoryBean.java new file mode 100644 index 0000000..a310c7f --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataFactoryBean.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.factory; + +import org.apache.olingo.server.api.OData; +import org.springframework.beans.factory.FactoryBean; + +public class ODataFactoryBean implements FactoryBean<OData> { + + @Override + public OData getObject() throws Exception { + return OData.newInstance(); + } + + @Override + public Class<?> getObjectType() { + return OData.class; + } + + @Override + public boolean isSingleton() { + return true; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataHttpHandlerFactoryBean.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataHttpHandlerFactoryBean.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataHttpHandlerFactoryBean.java new file mode 100644 index 0000000..5456957 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ODataHttpHandlerFactoryBean.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.factory; + +import java.util.List; + +import org.apache.olingo.server.api.OData; +import org.apache.olingo.server.api.ODataHttpHandler; +import org.apache.olingo.server.api.ServiceMetadata; +import org.apache.olingo.server.api.processor.Processor; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; + +public class ODataHttpHandlerFactoryBean implements + FactoryBean<ODataHttpHandler>, InitializingBean { + private OData odata; + private ServiceMetadata serviceMetadata; + private List<Processor> processors; + + @Override + public ODataHttpHandler getObject() throws Exception { + ODataHttpHandler handler = odata.createHandler(serviceMetadata); + if (processors != null) { + for (Processor processor : processors) { + handler.register(processor); + } + } + return handler; + } + + @Override + public Class<?> getObjectType() { + return ODataHttpHandler.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public void afterPropertiesSet() throws Exception { + if (odata == null) { + throw new IllegalArgumentException( + "The property odata is required."); + } + + if (serviceMetadata == null) { + throw new IllegalArgumentException( + "The property serviceMetadata is required."); + } + } + + public OData getOdata() { + return odata; + } + + public void setOdata(OData odata) { + this.odata = odata; + } + + public ServiceMetadata getServiceMetadata() { + return serviceMetadata; + } + + public void setServiceMetadata(ServiceMetadata serviceMetadata) { + this.serviceMetadata = serviceMetadata; + } + + public List<Processor> getProcessors() { + return processors; + } + + public void setProcessors(List<Processor> processors) { + this.processors = processors; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ServiceMetadataFactoryBean.java ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ServiceMetadataFactoryBean.java b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ServiceMetadataFactoryBean.java new file mode 100644 index 0000000..0e5b754 --- /dev/null +++ b/ext/spring/src/main/java/org/apache/olingo/ext/spring/factory/ServiceMetadataFactoryBean.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.spring.factory; + +import java.util.List; + +import org.apache.olingo.server.api.OData; +import org.apache.olingo.server.api.ServiceMetadata; +import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider; +import org.apache.olingo.server.api.edmx.EdmxReference; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; + +public class ServiceMetadataFactoryBean implements + FactoryBean<ServiceMetadata>, InitializingBean { + private OData odata; + private CsdlEdmProvider edmProvider; + private List<EdmxReference> references; + + @Override + public void afterPropertiesSet() throws Exception { + if (odata == null) { + throw new IllegalArgumentException( + "The property odata is required."); + } + + if (edmProvider == null) { + throw new IllegalArgumentException( + "The property edmProvider is required."); + } + + if (references == null) { + throw new IllegalArgumentException( + "The property references is required."); + } + } + + @Override + public ServiceMetadata getObject() throws Exception { + return odata.createServiceMetadata(edmProvider, references); + } + + @Override + public Class<?> getObjectType() { + return ServiceMetadata.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + public OData getOdata() { + return odata; + } + + public void setOdata(OData odata) { + this.odata = odata; + } + + public CsdlEdmProvider getEdmProvider() { + return edmProvider; + } + + public void setEdmProvider(CsdlEdmProvider edmProvider) { + this.edmProvider = edmProvider; + } + + public List<EdmxReference> getReferences() { + return references; + } + + public void setReferences(List<EdmxReference> references) { + this.references = references; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/resources/META-INF/spring.handlers ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/resources/META-INF/spring.handlers b/ext/spring/src/main/resources/META-INF/spring.handlers new file mode 100644 index 0000000..13d1260 --- /dev/null +++ b/ext/spring/src/main/resources/META-INF/spring.handlers @@ -0,0 +1 @@ +http\://olingo.apache.org/schema/olingo/spring-olingo=org.apache.olingo.ext.spring.config.OlingoNamespaceHandler \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ec82a5d1/ext/spring/src/main/resources/META-INF/spring.schemas ---------------------------------------------------------------------- diff --git a/ext/spring/src/main/resources/META-INF/spring.schemas b/ext/spring/src/main/resources/META-INF/spring.schemas new file mode 100644 index 0000000..1eb42b2 --- /dev/null +++ b/ext/spring/src/main/resources/META-INF/spring.schemas @@ -0,0 +1 @@ +http\://olingo.apache.org/schema/olingo/spring-olingo.xsd=org/apache/olingo/ext/spring/config/spring-olingo.xsd \ No newline at end of file
