@Override protected ObjectConverter createInstance() throws Exception { List<Class<? extends HippoBean>> annotatedClasses = null; if (annotatedClassesResourcePath == null && servletContext != null) { annotatedClassesResourcePath = servletContext.getInitParameter(annotatedClassesInitParam); } if (annotatedClassesResourcePath != null) { try { annotatedClasses = ObjectConverterUtils.getAnnotatedClasses(classpathResourceScanner, StringUtils.split(annotatedClassesResourcePath, ", \t\r\n")); } catch (Exception e) { throw new IllegalStateException(e); } } if (annotatedClasses != null) { return ObjectConverterUtils.createObjectConverter(annotatedClasses); } return null; }
/** * Creates <CODE>ObjectConverter</CODE>. * @param annotatedClasses Annotated class mapping against jcr primary node types. * @param ignoreDuplicates Flag whether duplicate mapping for a node type is ignored or not. If it is false, it throws <CODE>IllegalArgumentException</CODE> on duplicate mappings. * @return the ObjectConverter for these<code>annotatedClasses</code> * @throws IllegalArgumentException when two annotatedClasses have the same {@link Node#jcrType()} and <code>ignoreDuplicates</code> is false */ @SuppressWarnings("unchecked") public static ObjectConverter createObjectConverter(final Collection<Class<? extends HippoBean>> annotatedClasses, boolean ignoreDuplicates) throws IllegalArgumentException { return createObjectConverter(annotatedClasses, (Class<? extends HippoBean> []) DEFAULT_BUILT_IN_MAPPING_CLASSES, DEFAULT_FALLBACK_NODE_TYPES, ignoreDuplicates); }
private List<Class<? extends HippoBean>> getAnnotatedClasses(final ClasspathResourceScanner classpathResourceScanner) { List<Class<? extends HippoBean>> annotatedClasses = null; String ocmAnnotatedClassesResourcePath = getAnnotatedClassesResourcePath(); // if not manually configured, then read it from servlet context init parameter. if (ocmAnnotatedClassesResourcePath == null) { ServletContext servletContext = HstServices.getComponentManager().getServletContext(); if (servletContext == null) { throw new IllegalStateException("ServletContext is not found."); } ocmAnnotatedClassesResourcePath = servletContext.getInitParameter(BEANS_ANNOTATED_CLASSES_CONF_PARAM); } if (ocmAnnotatedClassesResourcePath == null) { throw new IllegalStateException("No content bean annotation class resource path found."); } try { annotatedClasses = ObjectConverterUtils.getAnnotatedClasses(classpathResourceScanner, StringUtils.split(ocmAnnotatedClassesResourcePath, ", \t\r\n")); } catch (Exception e) { throw new IllegalStateException(e); } return annotatedClasses; }
/** * Creates <CODE>ObjectConverter</CODE>. * @param annotatedClasses Annotated class mapping against jcr primary node types. * @param builtInMappingClasses Built-in class mappings against the default built-in jcr primary node types. * @param fallbackNodeTypes If no bean found for the node type, a fallback node type is to be selected as ordered by using <CODE>node.isNodeType(fallbackNodeType)</CODE> * @param ignoreDuplicates Flag whether duplicate mapping for a node type is ignored or not. If it is false, it throws <CODE>IllegalArgumentException</CODE> on duplicate mappings. * @return */ public static ObjectConverter createObjectConverter(final Collection<Class<? extends HippoBean>> annotatedClasses, final Class<? extends HippoBean> [] builtInMappingClasses, final String [] fallbackNodeTypes, boolean ignoreDuplicates) throws IllegalArgumentException { Map<String, Class<? extends HippoBean>> jcrPrimaryNodeTypeClassPairs = new HashMap<String, Class<? extends HippoBean>>(); if (annotatedClasses != null && !annotatedClasses.isEmpty()) { for (Class<? extends HippoBean> c : annotatedClasses) { addJcrPrimaryNodeTypeClassPair(jcrPrimaryNodeTypeClassPairs, c, false, ignoreDuplicates) ; } } if (builtInMappingClasses != null) { for (Class<? extends HippoBean> clazz : builtInMappingClasses) { addJcrPrimaryNodeTypeClassPair(jcrPrimaryNodeTypeClassPairs, clazz, true, ignoreDuplicates); } } return new ObjectConverterImpl(jcrPrimaryNodeTypeClassPairs, fallbackNodeTypes); }
/** * Creates <CODE>ObjectConverter</CODE>, with ignoreDuplicates = false, which means that when there are two annotated beans with the same * value for {@link Node#jcrType()}, an IllegalArgumentException is thrown. * @param annotatedClasses Annotated class mapping against jcr primary node types. * @return the ObjectConverter for these<code>annotatedClasses</code> * @throws IllegalArgumentException when two annotatedClasses have the same {@link Node#jcrType()} */ public static ObjectConverter createObjectConverter(final Collection<Class<? extends HippoBean>> annotatedClasses) throws IllegalArgumentException { return createObjectConverter(annotatedClasses, false); }
public ObjectConverter getObjectConverter() { if (objectConverter == null) { synchronized (this) { if (objectConverter == null) { if (!HstServices.isAvailable()) { throw new IllegalStateException("HST Services are not available."); } ClasspathResourceScanner classpathResourceScanner = HstServices.getComponentManager().getComponent(ClasspathResourceScanner.class.getName()); List<Class<? extends HippoBean>> annotatedClasses = getAnnotatedClasses(classpathResourceScanner); objectConverter = ObjectConverterUtils.createObjectConverter(annotatedClasses); } } } return objectConverter; }