Skip to content

Commit

Permalink
further improvements for CAMEL-165
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/activemq/camel/trunk@583073 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jstrachan committed Oct 9, 2007
1 parent 3e898ca commit 265cd63
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
@@ -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.camel.impl;

import org.apache.camel.spi.Binding;
import org.apache.camel.spi.Marshaller;
import org.apache.camel.spi.Unmarshaller;

/**
* @version $Revision: 1.1 $
*/
public class SerializationBinding implements Binding {

public Marshaller createMarshaller() {
return new SerializationMarshaller();
}

public Unmarshaller createUnmarshaller() {
return new SerializationUnmarshaller();
}
}
36 changes: 36 additions & 0 deletions camel-core/src/main/java/org/apache/camel/spi/Binding.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.camel.spi;

/**
* Represents a binding of an input/output stream to objects such as Java Serialization or
* using JAXB2 to encode/decode objects using XML
*
* @version $Revision: 1.1 $
*/
public interface Binding {
/**
* Creates a marshaller of objects into a binary stream
*/
Marshaller createMarshaller();

/**
* Creates an unmarshaller of objects from a binary stream
*/
Unmarshaller createUnmarshaller();
}
@@ -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.camel.converter.jaxb;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Binding;
import org.apache.camel.spi.Marshaller;
import org.apache.camel.spi.Unmarshaller;

/**
* @version $Revision: 1.1 $
*/
public class JaxbBinding implements Binding {
private JAXBContext context;
private boolean prettyPrint = true;

public JaxbBinding() {
}

public JaxbBinding(JAXBContext context) {
this.context = context;
}

public Marshaller createMarshaller() {
try {
javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint ? Boolean.TRUE : Boolean.FALSE);
return new JaxbMarshaller(marshaller);
}
catch (JAXBException e) {
throw new RuntimeCamelException(e);
}
}

public Unmarshaller createUnmarshaller() {
try {
javax.xml.bind.Unmarshaller unmarshaller = getContext().createUnmarshaller();
return new JaxbUnmarshaller(unmarshaller);
}
catch (JAXBException e) {
throw new RuntimeCamelException(e);
}
}

// Properties
//-------------------------------------------------------------------------
public JAXBContext getContext() throws JAXBException {
if (context == null) {
context = createContext();
}
return context;
}

public void setContext(JAXBContext context) {
this.context = context;
}

protected JAXBContext createContext() throws JAXBException {
return JAXBContext.newInstance();
}

}
Expand Up @@ -37,7 +37,6 @@ public JaxbUnmarshaller(javax.xml.bind.Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}


public Object unmarshal(InputStream stream) throws IOException, ClassNotFoundException {
try {
return unmarshaller.unmarshal(stream);
Expand Down

0 comments on commit 265cd63

Please sign in to comment.